mirror of
https://gitee.com/johng/gf
synced 2026-06-27 09:47:19 +08:00
完善gpage示例,README updates
This commit is contained in:
@ -51,6 +51,11 @@ gf是一款模块化、松耦合、轻量级、高性能的Web开发框架。开
|
||||
* [单例管理](http://gf.johng.cn/494377)
|
||||
* [数据校验](http://gf.johng.cn/494378)
|
||||
* [分页管理](http://gf.johng.cn/597381)
|
||||
* [基本介绍](http://gf.johng.cn/597431)
|
||||
* [动态分页](http://gf.johng.cn/597432)
|
||||
* [静态分页](http://gf.johng.cn/597433)
|
||||
* [Ajax分页](http://gf.johng.cn/597434)
|
||||
* [自定义分页](http://gf.johng.cn/597435)
|
||||
* [模板引擎](http://gf.johng.cn/494379)
|
||||
* [使用方法](http://gf.johng.cn/591642)
|
||||
* [基本语法](http://gf.johng.cn/591643)
|
||||
|
||||
@ -114,7 +114,7 @@ func GetServer(name...interface{}) (*Server) {
|
||||
closeQueue : gqueue.New(),
|
||||
logPath : gtype.NewString(),
|
||||
accessLogEnabled : gtype.NewBool(),
|
||||
errorLogEnabled : gtype.NewBool(),
|
||||
errorLogEnabled : gtype.NewBool(true),
|
||||
accessLogger : glog.New(),
|
||||
errorLogger : glog.New(),
|
||||
logHandler : gtype.NewInterface(),
|
||||
|
||||
@ -41,8 +41,7 @@ func (s *Server) handleErrorLog(error interface{}, r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
content := fmt.Sprintf(`"%s %s %s %s"`, r.Method, r.Host, r.URL.String(), r.Proto)
|
||||
content += fmt.Sprintf(`, %s, "%s", "%s"`, r.GetClientIp(), r.Referer(), r.UserAgent())
|
||||
content += fmt.Sprintf(`, %v`, error)
|
||||
content := fmt.Sprintf(`%v, "%s %s %s %s"`, error, r.Method, r.Host, r.URL.String(), r.Proto)
|
||||
content += fmt.Sprintf(`, %s, "%s", "%s"`, r.GetClientIp(), r.Referer(), r.UserAgent())
|
||||
s.errorLogger.Error(content)
|
||||
}
|
||||
|
||||
@ -47,10 +47,14 @@ func New(TotalSize, perPage int, CurrentPage interface{}, url string, route...s
|
||||
NextBar : ">>",
|
||||
TotalSize : TotalSize,
|
||||
TotalPage : int(math.Ceil(float64(TotalSize/perPage))),
|
||||
CurrentPage : gconv.Int(CurrentPage),
|
||||
CurrentPage : 1,
|
||||
PageBarNum : 10,
|
||||
Url : u,
|
||||
}
|
||||
curPage := gconv.Int(CurrentPage)
|
||||
if curPage > 0 {
|
||||
page.CurrentPage = curPage
|
||||
}
|
||||
if len(route) > 0 {
|
||||
page.Route = route[0]
|
||||
}
|
||||
@ -247,9 +251,12 @@ func (page *Page) GetUrl(pageNo int) string {
|
||||
}
|
||||
// 替换url.Path中的分页码
|
||||
if index != -1 {
|
||||
array := strings.Split(page.Url.Path, "/")
|
||||
array[index] = gconv.String(pageNo)
|
||||
url.Path = strings.Join(array, "/")
|
||||
pathArray := strings.Split(page.Url.Path, "/")
|
||||
for i := 0; i <= index - len(pathArray); i++ {
|
||||
pathArray = append(pathArray, "")
|
||||
}
|
||||
pathArray[index] = gconv.String(pageNo)
|
||||
url.Path = strings.TrimRight(strings.Join(pathArray, "/"), "/")
|
||||
return url.String()
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,14 @@ func main() {
|
||||
a,span {padding:8px; font-size:16px;}
|
||||
div{margin:5px 5px 20px 5px}
|
||||
</style>
|
||||
<script src="https://cdn.bootcss.com/jquery/2.0.3/jquery.min.js"></script>
|
||||
<script>
|
||||
function DoAjax(url) {
|
||||
$.get(url, function(data,status) {
|
||||
$("body").html(data);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div>{{.page}}</div>
|
||||
|
||||
@ -24,7 +24,7 @@ func pageContent(page *gpage.Page) string {
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.BindHandler("/page/custom/*page", func(r *ghttp.Request){
|
||||
page := gpage.New(100, 10, r.Get("page"), r.URL.String(), r.Router.Uri)
|
||||
page := gpage.New(100, 10, r.Get("page"), r.URL.String(), r.Router.Uri)
|
||||
buffer, _ := gview.ParseContent(`
|
||||
<html>
|
||||
<head>
|
||||
@ -42,6 +42,6 @@ func main() {
|
||||
})
|
||||
r.Response.Write(buffer)
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.SetPort(10000)
|
||||
s.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user