From fa25d64ef0dbf9ab78343d81625af0ab0afb11f6 Mon Sep 17 00:00:00 2001 From: liuhaotian Date: Fri, 14 Jan 2022 19:54:40 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20brahma=20=E9=80=82=E9=85=8D=E6=96=B0?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../murder/internal/gorm_helper/connect.go | 5 ++--- app/brahma/api/murder/main.go | 20 ++++++++++++------- pkg/env/env.go | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) 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))) }