diff --git a/app/brahma/api/murder/internal/gorm_helper/connect.go b/app/brahma/api/murder/internal/gorm_helper/connect.go index 9c0c6d3..f297d02 100644 --- a/app/brahma/api/murder/internal/gorm_helper/connect.go +++ b/app/brahma/api/murder/internal/gorm_helper/connect.go @@ -1,7 +1,6 @@ package gorm_helper import ( - "fmt" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/config" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/error_process" "github.com/gofiber/fiber/v2" @@ -14,8 +13,8 @@ type MysqlMapType map[string]*gorm.DB var mysqlMap = make(MysqlMapType, 0) func GormMap(dsnPre string) error { - dsn := fmt.Sprintf("%v/%v?charset=utf8mb4&parseTime=True&loc=Local", dsnPre, config.TestDB) - db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) + //dsn := fmt.Sprintf("%v/%v?charset=utf8mb4&parseTime=True&loc=Local", dsnPre, config.TestDB) + db, err := gorm.Open(mysql.Open(dsnPre), &gorm.Config{}) if err != nil { return err } diff --git a/app/brahma/api/murder/main.go b/app/brahma/api/murder/main.go index 4801337..8ef9c66 100755 --- a/app/brahma/api/murder/main.go +++ b/app/brahma/api/murder/main.go @@ -2,11 +2,11 @@ package main import ( "fmt" - "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/config" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/error_process" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/gorm_helper" "git.icechen.cn/monorepo/backend/app/brahma/api/murder/internal/handler" "git.icechen.cn/monorepo/backend/pkg/api" + "git.icechen.cn/monorepo/backend/pkg/config" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/recover" "github.com/gofiber/fiber/v2/middleware/requestid" @@ -19,6 +19,7 @@ const ( tag = "/tag" category = "/category" scripts = "/scripts" + hello = "/hello" ) var ( @@ -36,10 +37,12 @@ func init() { // ResourceInit 读取配置初始化资源 func ResourceInit() { - - config.GetConfig() - - err = gorm_helper.GormMap(config.GetConfigMap()[config.GetConfigKey(config.DsnPre)]) + mysql, err := config.GetMysql() + if err != nil { + ctxLogger.FError(nil, "etcd读取mysql出错", zap.String("", err.Error())) + os.Exit(-1) + } + err = gorm_helper.GormMap(mysql) if err != nil { ctxLogger.FError(nil, error_process.GormError, zap.String("", err.Error())) os.Exit(-1) @@ -107,12 +110,15 @@ func routerInit() { scriptsGroup.Delete("", func(ctx *fiber.Ctx) error { return handler.DeleteScriptsH(ctx) }) + helloGroup := app.Group(hello) + helloGroup.Get("", func(ctx *fiber.Ctx) error { + return handler.HelloWorld() + }) } func serverStart() { - port := config.GetEnvDefault(config.Port, config.PortDefault) - err = app.Listen(fmt.Sprintf(":%v", port)) + err = app.Listen(fmt.Sprintf(":%v", 8080)) if err != nil { ctxLogger.Error(nil, "", zap.String("", err.Error())) os.Exit(-1) diff --git a/pkg/env/env.go b/pkg/env/env.go index 3c2f9c9..9692559 100644 --- a/pkg/env/env.go +++ b/pkg/env/env.go @@ -6,8 +6,8 @@ import ( ) func init() { - AppName = GetEnvDefault("APP_NAME", "default") - Namespace = GetEnvDefault("NAMESPACE", "default") + AppName = GetEnvDefault("APP_NAME", "murder") + Namespace = GetEnvDefault("NAMESPACE", "brahma") AppType = SAppType(GetEnvDefault("APP_TYPE", string(AppTypeAPI))) }