代码拉取完成,页面将自动刷新
同步操作将从 有理想的鸭子/go-iot 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package main
import (
"fmt"
_ "go-iot/pkg/api"
"go-iot/pkg/core"
"go-iot/pkg/core/es"
"go-iot/pkg/core/redis"
"go-iot/pkg/models"
_ "go-iot/pkg/network/clients/registry"
_ "go-iot/pkg/network/servers/registry"
_ "go-iot/pkg/notify/registry"
"net/http"
"runtime"
"strings"
"github.com/beego/beego/v2/core/config"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/server/web"
"github.com/beego/beego/v2/server/web/context"
)
func main() {
configLog()
setDefaultConfig()
getConfigString("db.url", func(s string) {
models.DefaultDbConfig.Url = s
})
models.InitDb()
web.BConfig.RecoverFunc = defaultRecoverPanic
web.ErrorHandler("404", func(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(404)
})
web.Run()
}
func defaultRecoverPanic(ctx *context.Context, cfg *web.Config) {
if err := recover(); err != nil {
if err == web.ErrAbort {
return
}
logs.Error("the request url is ", ctx.Input.URL())
var stack string
for i := 1; ; i++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
logs.Error(fmt.Sprintf("%s:%d", file, line))
stack = stack + fmt.Sprintf("%s:%d\n", file, line)
}
if ctx.Output.Status == 0 {
ctx.Output.Status = 500
}
ctx.Output.JSON(models.JsonRespError(fmt.Errorf("%v", err)), false, false)
}
}
func setDefaultConfig() {
{
getConfigString("device.manager.id", func(s string) {
core.DefaultManagerId = s
})
logs.Info("default device manager: ", core.DefaultManagerId)
}
es.Config(getConfigString)
redis.Config(getConfigString)
}
func configLog() {
logs.Async()
var logLevel string
getConfigString("logs.level", func(s string) {
logLevel = s
})
level := 7
switch logLevel {
case "info":
level = logs.LevelInfo
case "warn":
level = logs.LevelWarn
case "error":
level = logs.LevelError
}
var filename string = "go-iot.log"
getConfigString("logs.filename", func(s string) {
filename = "go-iot.log"
})
logs.GetBeeLogger().SetLevel(level)
err := logs.SetLogger(logs.AdapterFile, fmt.Sprintf(`{"filename":"%s","level":%d,"maxlines":0,
"maxsize":0,"daily":true,"maxdays":10,"color":false}`, filename, level))
if err != nil {
panic(err)
}
}
func getConfigString(key string, callback func(string)) {
data, err := config.String(key)
if err != nil {
panic(err)
}
val := strings.TrimSpace(data)
if len(val) > 0 {
callback(val)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。