From cf6791fd449c9b99a876903c99fbc98d5520848e Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Fri, 7 Jan 2022 09:27:27 +0800 Subject: [PATCH] tree node style --- client/src/services.js | 3 +++ cmd/server/main.go | 1 + internal/pkg/lib/cron/cron.go | 2 +- internal/pkg/lib/i118/i118.go | 1 + internal/pkg/lib/log/print.go | 21 ++++++--------------- internal/pkg/lib/res/res.go | 6 ++++++ internal/server/config/init.go | 1 + internal/server/core/web/index.go | 22 ++-------------------- 8 files changed, 21 insertions(+), 36 deletions(-) diff --git a/client/src/services.js b/client/src/services.js index ecbceb34..1c8af093 100644 --- a/client/src/services.js +++ b/client/src/services.js @@ -39,6 +39,7 @@ export function startZtfServer() { const lines = dataString.split('\n'); for (let i = 0; i < lines.length; i++) { const line = lines[i]; + console.log('\t>', line); if (line.includes('Now listening on: http')) { resolve(line.split('Now listening on:')[1].trim()); break; @@ -73,6 +74,7 @@ export function startZtfServer() { const lines = dataString.split('\n'); for (let i = 0; i < lines.length; i++) { const line = lines[i]; + console.log('\t>', line); if (line.includes('Now listening on: http')) { resolve(line.split('Now listening on:')[1].trim()); break; @@ -152,6 +154,7 @@ export function getUIServerUrl() { const lines = dataString.split('\n'); for (let i = 0; i < lines.length; i++) { const line = lines[i]; + console.log('\t>', line); if (line.includes('App running at:')) { const nextLine = lines[i + 1] || lines[i + 2]; if (!nextLine) { diff --git a/cmd/server/main.go b/cmd/server/main.go index fca79ebd..613c6f3d 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -22,6 +22,7 @@ func main() { if webServer == nil { return } + injectModule(webServer) webServer.Run() diff --git a/internal/pkg/lib/cron/cron.go b/internal/pkg/lib/cron/cron.go index 095cf125..59df79db 100644 --- a/internal/pkg/lib/cron/cron.go +++ b/internal/pkg/lib/cron/cron.go @@ -21,7 +21,7 @@ func GetCrontabInstance() *cron.Cron { func AddTask(name string, schedule string, f func()) { if _, ok := taskFunc[name]; !ok { - fmt.Println("Add a new task:", name) + fmt.Printf("Add a new task %s", name) cInstance := GetCrontabInstance() cInstance.AddFunc(schedule, f) diff --git a/internal/pkg/lib/i118/i118.go b/internal/pkg/lib/i118/i118.go index 784be4aa..1c580898 100644 --- a/internal/pkg/lib/i118/i118.go +++ b/internal/pkg/lib/i118/i118.go @@ -13,6 +13,7 @@ import ( var I118Prt *message.Printer func Init(lang string, app string) { + langRes := filepath.Join("res", app, lang, "messages.json") bytes, _ := resUtils.ReadRes(langRes) diff --git a/internal/pkg/lib/log/print.go b/internal/pkg/lib/log/print.go index d98af0bd..0aa79ec0 100644 --- a/internal/pkg/lib/log/print.go +++ b/internal/pkg/lib/log/print.go @@ -12,41 +12,32 @@ var Logger *zap.Logger func Info(str string) { Logger.Info(str) - //log.Println(str) + log.Println(str) } func Infof(str string, args ...interface{}) { msg := fmt.Sprintf(str, args...) Logger.Info(msg) - //log.Printf(msg+"\n") + log.Println(msg) } func Warn(str string) { Logger.Warn(str) - //log.Println(str) + log.Println(str) } func Warnf(str string, args ...interface{}) { msg := fmt.Sprintf(str, args...) Logger.Warn(msg) - //log.Printf(msg+"\n") + log.Println(msg) } func Error(str string) { Logger.Error(str) - //log.Println(str) + log.Println(str) } func Errorf(str string, args ...interface{}) { msg := fmt.Sprintf(str, args...) Logger.Error(msg) - //log.Printf(msg+"\n") -} -func Debug(str string) { - Logger.Debug(str) - //log.Println(str) -} -func Debugf(str string, args ...interface{}) { - msg := fmt.Sprintf(str, args...) - Logger.Debug(msg) - //log.Printf(msg+"\n") + log.Printf(msg + "\n") } func PrintUnicode(str []byte) { diff --git a/internal/pkg/lib/res/res.go b/internal/pkg/lib/res/res.go index 44964e3d..48e57cf5 100644 --- a/internal/pkg/lib/res/res.go +++ b/internal/pkg/lib/res/res.go @@ -1,18 +1,24 @@ package resUtils import ( + "fmt" "github.com/aaronchen2k/deeptest/internal/pkg/lib/common" "github.com/aaronchen2k/deeptest/res" "io/ioutil" + "os" ) func ReadRes(path string) (ret []byte, err error) { isRelease := commonUtils.IsRelease() + if isRelease { ret, err = res.Asset(path) } else { ret, err = ioutil.ReadFile(path) } + dir, _ := os.Getwd() + fmt.Printf("isRelease=%t, path=%s, ret=%#v, dir=%s", isRelease, path, ret, dir) + return } diff --git a/internal/server/config/init.go b/internal/server/config/init.go index 38d74b7b..70da4a40 100644 --- a/internal/server/config/init.go +++ b/internal/server/config/init.go @@ -27,6 +27,7 @@ func Init() { VIPER.SetConfigType("yaml") configRes := filepath.Join("res", consts.AppServer+".yaml") + yamlDefault, _ := resUtils.ReadRes(configRes) if err := VIPER.ReadConfig(bytes.NewBuffer(yamlDefault)); err != nil { diff --git a/internal/server/core/web/index.go b/internal/server/core/web/index.go index d490b0b4..d6d6921a 100644 --- a/internal/server/core/web/index.go +++ b/internal/server/core/web/index.go @@ -60,7 +60,9 @@ type WebServer struct { func Init() *WebServer { serverConfig.Init() serverLog.Init() + i118Utils.Init(serverConfig.CONFIG.System.Language, consts.AppServer) + langUtils.GetExtToNameMap() app := iris.New() @@ -75,26 +77,6 @@ func Init() *WebServer { close(idleConnClosed) }) - if serverConfig.CONFIG.System.Addr == "" { // 默认 8085 - serverConfig.CONFIG.System.Addr = "127.0.0.1:8085" - } - - if serverConfig.CONFIG.System.StaticPath == "" { // 默认 /static/upload - serverConfig.CONFIG.System.StaticPath = "/static/upload" - } - - if serverConfig.CONFIG.System.StaticPrefix == "" { // 默认 /upload - serverConfig.CONFIG.System.StaticPrefix = "/upload" - } - - if serverConfig.CONFIG.System.WebPath == "" { // 默认 /./dist - serverConfig.CONFIG.System.WebPath = "./dist" - } - - if serverConfig.CONFIG.System.TimeFormat == "" { // 默认 80 - serverConfig.CONFIG.System.TimeFormat = time.RFC3339 - } - // init grpc mvc.New(app) -- GitLab