From 46b96568775a57419c988a90f0aa195bb0fa5be3 Mon Sep 17 00:00:00 2001 From: Cookiery <2061803022@qq.com> Date: Sun, 29 May 2022 02:49:51 +0800 Subject: [PATCH] update framework --- .vscode/launch.json | 2 +- bootstrap.go | 26 ++++++++++++++++++++++++++ conf/app.toml | 7 ++++--- conf/mySQL.toml | 5 +++++ document/MySQL.md | 0 document/to_be_perfect.md | 8 ++++++++ main.go | 18 ++++-------------- model/service/MySQL/mysql.go | 22 ++++++++++++++++++++++ model/service/mysql.go | 1 - 9 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 bootstrap.go create mode 100644 conf/mySQL.toml create mode 100644 document/MySQL.md create mode 100644 document/to_be_perfect.md create mode 100644 model/service/MySQL/mysql.go delete mode 100644 model/service/mysql.go diff --git a/.vscode/launch.json b/.vscode/launch.json index 0f1bf98..97f4a32 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "go", "request": "launch", "mode": "auto", - "program": "${fileDirname}" + "program": "${workspaceFolder}" } ] } \ No newline at end of file diff --git a/bootstrap.go b/bootstrap.go new file mode 100644 index 0000000..1259b51 --- /dev/null +++ b/bootstrap.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + + "github.com/BurntSushi/toml" +) + +type Server struct { + AppMode string + HTTPPort string +} + +// InitServer 初始化服务变量 +func InitServer() *Server { + var server Server + if _, err := toml.DecodeFile("./conf/app.toml", &server); err != nil { + // 打日志 + fmt.Println(err) + } + return &server +} + +func initMySQL() { + +} diff --git a/conf/app.toml b/conf/app.toml index ba819a7..c44bf3f 100644 --- a/conf/app.toml +++ b/conf/app.toml @@ -1,4 +1,5 @@ - -[server] +# AppMode 服务模式 AppMode = "debug" -HttPPort = ":8080" \ No newline at end of file + +# 控制端口 +HttPPort = ":8081" \ No newline at end of file diff --git a/conf/mySQL.toml b/conf/mySQL.toml new file mode 100644 index 0000000..2115681 --- /dev/null +++ b/conf/mySQL.toml @@ -0,0 +1,5 @@ +[database] +Host = "localhost" +Port = 8808 +User = "admin" +PassWord = "admin123" \ No newline at end of file diff --git a/document/MySQL.md b/document/MySQL.md new file mode 100644 index 0000000..e69de29 diff --git a/document/to_be_perfect.md b/document/to_be_perfect.md new file mode 100644 index 0000000..9a05fc8 --- /dev/null +++ b/document/to_be_perfect.md @@ -0,0 +1,8 @@ +## to_be_perfect + +初始化加载 + +- 日志服务 +- 端口配置 +- 数据库配置 +- 后台配置 \ No newline at end of file diff --git a/main.go b/main.go index c8d24c9..bc0fda0 100644 --- a/main.go +++ b/main.go @@ -1,25 +1,15 @@ package main import ( - "fmt" - - "github.com/BurntSushi/toml" "github.com/gin-gonic/gin" ) -type Server struct { - AppMode string - HTTPPort string -} - func main() { - var app map[string]Server - if _, err := toml.DecodeFile("./conf/app.toml", &app); err != nil { - fmt.Println(app) - } - r := gin.Default() + server := InitServer() + // 启动服务 + r := gin.Default() // Default 带有 Logger 和 Recovery 中间件 r.GET("/hello", func(c *gin.Context) { c.JSON(200, gin.H{"msg": "hello"}) }) - r.Run() + r.Run(server.HTTPPort) } diff --git a/model/service/MySQL/mysql.go b/model/service/MySQL/mysql.go new file mode 100644 index 0000000..2cd5621 --- /dev/null +++ b/model/service/MySQL/mysql.go @@ -0,0 +1,22 @@ +package MySQL + +import ( + "fmt" + + "github.com/BurntSushi/toml" +) + +type DataBase struct { + Host string + Port int + User string + PassWord string +} + +func DB() { + var dataBase map[string]DataBase + if _, err := toml.DecodeFile("./conf/db.toml", &dataBase); err != nil { + fmt.Println(err) + } + fmt.Println(dataBase) +} diff --git a/model/service/mysql.go b/model/service/mysql.go deleted file mode 100644 index bb27ba5..0000000 --- a/model/service/mysql.go +++ /dev/null @@ -1 +0,0 @@ -package service