From 10aeac3e8515f78b08e0079367573b725515296f Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Sat, 13 Apr 2024 22:58:17 +0800 Subject: [PATCH] y --- config.yaml | 8 ++++---- initialize/initialize.go | 19 +++---------------- main.go | 13 ++++++++----- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/config.yaml b/config.yaml index d5d282a..9feaca7 100644 --- a/config.yaml +++ b/config.yaml @@ -4,10 +4,10 @@ server: storage: storage-type: "cos" cos: - bucket-url: "https://elf-1304437394.cos.ap-nanjing.myqcloud.com" - secret-id: "AKIDlRuAEGGE1c6Ys24uWu42oMhsqfIZbWDg" - secret-key: "LVSFoAICrU2NWXLycO4azNYWWTJwRYZW" - domain: + bucket-url: "https://platform-1320353837.cos.ap-nanjing.myqcloud.com" + secret-id: "AKIDSp7KMCsMk140xgAQSL6lVElChR8wn8hC" + secret-key: "RpAQXQOAmz40pXAf1TqANNA3tY7Z7iJi" + domain: "https://platform-1320353837.cos.ap-nanjing.myqcloud.com" obs: endpoint: access-key: diff --git a/initialize/initialize.go b/initialize/initialize.go index d2b2890..84f162b 100644 --- a/initialize/initialize.go +++ b/initialize/initialize.go @@ -9,22 +9,9 @@ import ( "uploader/utils/storage" ) -const FilePath = "config.yaml" - -func InitConfig() *config.Config { - currentDir, err := os.Getwd() - if err != nil { - panic(err) - } - - fmt.Println("currentDir: " + currentDir) - - filePath := currentDir + "/" + FilePath - //filePath := "/var/www/gold-shop/" + FilePath - - fmt.Println("filepath: " + filePath) - - content, err := os.ReadFile(filePath) +func InitConfig(configFilePath string) *config.Config { + fmt.Println("configFilePath: " + configFilePath) + content, err := os.ReadFile(configFilePath) if err != nil { fmt.Printf("err: %v\n", err) panic(err) diff --git a/main.go b/main.go index f494528..282d270 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "flag" "github.com/fvbock/endless" "github.com/gin-gonic/gin" "net/http" @@ -11,13 +12,15 @@ import ( ) func main() { - RunServer() -} - -func RunServer() { - global.Config = initialize.InitConfig() + var configFilePath string + flag.StringVar(&configFilePath, "config", "./config.yaml", "配置文件") + flag.Parse() + global.Config = initialize.InitConfig(configFilePath) global.Storage = initialize.InitStorage() + RunHttpServer() +} +func RunHttpServer() { r := gin.Default() s := &http.Server{ Addr: ":8080",