This commit is contained in:
gotoeasy 2022-09-22 12:13:41 +08:00
parent 7382d7efce
commit 289f94dbfa
3 changed files with 33 additions and 9 deletions

View File

@ -34,13 +34,14 @@ func Run() {
gweb.RegisterController(method.GET, "/**/*.png", html.StaticFileController)
// 控制器
gweb.RegisterController(method.POST, contextPath+"/v1/log/add", controller.JsonLogAddController) // 添加日志
gweb.RegisterController(method.POST, contextPath+"/v1/log/search", controller.LogSearchController) // 查询日志
gweb.RegisterController(method.POST, contextPath+"/v1/store/names", controller.StorageNamesController) // 查询日志仓名称列表
gweb.RegisterController(method.POST, contextPath+"/v1/store/list", controller.StorageListController) // 查询日志仓信息列表
gweb.RegisterController(method.POST, contextPath+"/v1/store/delete", controller.StorageDeleteController) // 删除日志仓
gweb.RegisterController(method.POST, contextPath+"/v1/user/enableLogin", controller.IsEnableLoginController) // 查询是否开启用户密码登录功能
gweb.RegisterController(method.POST, contextPath+"/v1/user/login", controller.LoginController) // Login
gweb.RegisterController(method.POST, contextPath+"/v1/log/add", controller.JsonLogAddController) // 添加日志
gweb.RegisterController(method.POST, contextPath+"/v1/log/transferAdd", controller.JsonLogTransferAddController) // 日志数据转发添加日志
gweb.RegisterController(method.POST, contextPath+"/v1/log/search", controller.LogSearchController) // 查询日志
gweb.RegisterController(method.POST, contextPath+"/v1/store/names", controller.StorageNamesController) // 查询日志仓名称列表
gweb.RegisterController(method.POST, contextPath+"/v1/store/list", controller.StorageListController) // 查询日志仓信息列表
gweb.RegisterController(method.POST, contextPath+"/v1/store/delete", controller.StorageDeleteController) // 删除日志仓
gweb.RegisterController(method.POST, contextPath+"/v1/user/enableLogin", controller.IsEnableLoginController) // 查询是否开启用户密码登录功能
gweb.RegisterController(method.POST, contextPath+"/v1/user/login", controller.LoginController) // Login
// 默认引擎空转一下,触发未建索引继续建
go ldb.NewDefaultEngine().AddTextLog("", "", "")

View File

@ -1,3 +1,3 @@
package onstart
const VERSION = "glogcenter 0.6.0"
const VERSION = "glogcenter 0.7.0"

View File

@ -38,11 +38,34 @@ func JsonLogAddController(req *gweb.HttpRequest) *gweb.HttpResult {
return gweb.Ok()
}
// 添加日志(来自数据转发)
func JsonLogTransferAddController(req *gweb.HttpRequest) *gweb.HttpResult {
// 开启API秘钥校验时才检查
if conf.IsEnableSecurityKey() {
auth := req.GetHeader(conf.GetHeaderSecurityKey())
if auth != conf.GetSecurityKey() {
return gweb.Error(403, "未经授权的访问,拒绝服务")
}
}
md := &logdata.LogDataModel{}
err := req.BindJSON(md)
if err != nil {
log.Println("请求参数有误", err)
return gweb.Error500(err.Error())
}
engine := ldb.NewDefaultEngine()
engine.AddTextLog(md.Date, md.Text, md.System)
return gweb.Ok()
}
// 转发其他GLC服务
func transferGlc(md *logdata.LogDataModel) {
hosts := conf.GetSlaveHosts()
for i := 0; i < len(hosts); i++ {
go httpPostJson(hosts[i]+conf.GetContextPath()+"/v1/log/add", md.ToJson())
go httpPostJson(hosts[i]+conf.GetContextPath()+"/v1/log/transferAdd", md.ToJson())
}
}