mirror of
https://github.com/gotoeasy/glogcenter.git
synced 2025-09-15 12:58:34 +08:00
重定向、日志接口(简单添加、查询)
This commit is contained in:
parent
3464249f76
commit
7467414299
@ -1,6 +1,7 @@
|
||||
package gweb
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -54,3 +55,7 @@ func (r *HttpRequest) GetUrlParameter(name string) string {
|
||||
func (r *HttpRequest) GetFormParameter(name string) string {
|
||||
return r.ginCtx.Request.PostFormValue(name)
|
||||
}
|
||||
|
||||
func (r *HttpRequest) Redirect(url string) {
|
||||
r.ginCtx.Redirect(http.StatusMovedPermanently, url)
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package gweb
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"glc/ldb/conf"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@ -22,9 +24,11 @@ func Run() {
|
||||
}
|
||||
|
||||
rs := handle.Controller(req)
|
||||
c.JSON(rs.Code, rs)
|
||||
if rs != nil {
|
||||
c.JSON(rs.Code, rs)
|
||||
}
|
||||
})
|
||||
|
||||
server.Run(":8080")
|
||||
server.Run(fmt.Sprintf(":%d", conf.GetServerPort()))
|
||||
|
||||
}
|
||||
|
||||
16
glc/web/controller/log_add_controller.go
Normal file
16
glc/web/controller/log_add_controller.go
Normal file
@ -0,0 +1,16 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"glc/gweb"
|
||||
"glc/ldb"
|
||||
)
|
||||
|
||||
// 添加日志(表单提交方式)
|
||||
func LogAddController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
storeNmae := req.GetFormParameter("name")
|
||||
text := req.GetFormParameter("text")
|
||||
|
||||
engine := ldb.NewEngine(storeNmae)
|
||||
engine.AddTextLog(text)
|
||||
return gweb.Ok()
|
||||
}
|
||||
@ -4,20 +4,25 @@ import (
|
||||
"glc/cmn"
|
||||
"glc/gweb"
|
||||
"glc/ldb"
|
||||
"glc/ldb/conf"
|
||||
"glc/ldb/tokenizer"
|
||||
)
|
||||
|
||||
// 日志检索(表单提交方式)
|
||||
func LogSearchController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
storeNmae := req.GetUrlParameter("name")
|
||||
if storeNmae == "" {
|
||||
storeNmae = "default"
|
||||
}
|
||||
searchKey := tokenizer.GetSearchKey(req.GetUrlParameter("searchKey"))
|
||||
pageSize := cmn.StringToInt(req.GetUrlParameter("pageSize"), 20)
|
||||
currentId := cmn.StringToUint64(req.GetUrlParameter("currentId"), 36, 0)
|
||||
forward := cmn.StringToBool(req.GetUrlParameter("forward"), true)
|
||||
storeNmae := req.GetFormParameter("name")
|
||||
searchKey := tokenizer.GetSearchKey(req.GetFormParameter("searchKey"))
|
||||
pageSize := cmn.StringToInt(req.GetFormParameter("pageSize"), 20)
|
||||
currentId := cmn.StringToUint64(req.GetFormParameter("currentId"), 36, 0)
|
||||
forward := cmn.StringToBool(req.GetFormParameter("forward"), true)
|
||||
|
||||
eng := ldb.NewEngine(storeNmae)
|
||||
rs := eng.Search(searchKey, pageSize, currentId, forward)
|
||||
return gweb.Result(rs)
|
||||
}
|
||||
|
||||
// 重定向
|
||||
func RedirectToSearchController(req *gweb.HttpRequest) *gweb.HttpResult {
|
||||
defer req.Redirect(conf.GetContextPath() + "/search")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -3,9 +3,19 @@ package router
|
||||
import (
|
||||
"glc/gweb"
|
||||
"glc/gweb/method"
|
||||
"glc/ldb/conf"
|
||||
"glc/web/controller"
|
||||
)
|
||||
|
||||
func Register() {
|
||||
gweb.RegisterController(method.GET, "/glc/list", controller.LogSearchController)
|
||||
|
||||
contextPath := conf.GetContextPath()
|
||||
|
||||
gweb.RegisterController(method.GET, "/", controller.RedirectToSearchController)
|
||||
gweb.RegisterController(method.GET, contextPath, controller.RedirectToSearchController)
|
||||
gweb.RegisterController(method.GET, contextPath+"/", controller.RedirectToSearchController)
|
||||
|
||||
gweb.RegisterController(method.POST, contextPath+"/search", controller.LogSearchController)
|
||||
gweb.RegisterController(method.POST, contextPath+"/add", controller.LogAddController)
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user