diff --git a/app/admin/apis/shopee_product.go b/app/admin/apis/shopee_product.go index f550d32..afac10f 100644 --- a/app/admin/apis/shopee_product.go +++ b/app/admin/apis/shopee_product.go @@ -7,6 +7,7 @@ import ( "github.com/go-admin-team/go-admin-core/sdk" "github.com/go-admin-team/go-admin-core/sdk/api" "go-admin/app/admin/models" + ext "go-admin/config" "gorm.io/gorm" "io" "net/http" @@ -34,12 +35,12 @@ func (e ShopeeProduct) GetByShopeeID(c *gin.Context) { e.Error(400, fmt.Errorf("shopeeId is required"), "参数错误") return } - configured := os.Getenv("ERP_API_KEY") + configured := ext.ExtConfig.Huohanhan.APIKey if configured != "" && apiKey(c) != configured { e.Error(401, fmt.Errorf("invalid api key"), "未授权") return } - base := strings.TrimRight(os.Getenv("HUOHANHAN_BASE_URL"), "/") + base := strings.TrimRight(ext.ExtConfig.Huohanhan.BaseURL, "/") if base == "" { base = "https://www.huohanhan.com" } diff --git a/config.example.yaml b/config.example.yaml index 8e7ed87..d754fa1 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -45,7 +45,7 @@ settings: dbname: dbname # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 frontpath: ../go-admin-ui/src - extend: # 扩展项使用说明 + extend: # 扩展项使用说明`r`n huohanhan:`r`n base_url: https://www.huohanhan.com`r`n account: ""`r`n password: ""`r`n ocr_url: https://ocr.ilapage.cn/ocr`r`n state_db: ./huohanhan-state.db`r`n api_key: change-me demo: name: data cache: @@ -71,4 +71,4 @@ settings: # blockingTimeout: 5 # reclaimInterval: 1 locker: - redis: \ No newline at end of file + redis: diff --git a/config/extend.go b/config/extend.go index bd06e03..d7b8b4e 100644 --- a/config/extend.go +++ b/config/extend.go @@ -2,15 +2,18 @@ package config var ExtConfig Extend -// Extend 扩展配置 -// extend: -// demo: -// name: demo-name -// 使用方法: config.ExtConfig......即可!! type Extend struct { - AMap AMap // 这里配置对应配置文件的结构即可 + AMap AMap `yaml:"demo"` + Huohanhan HuohanhanConfig `yaml:"huohanhan"` } - type AMap struct { - Key string + Key string `yaml:"key"` +} +type HuohanhanConfig struct { + BaseURL string `yaml:"base_url"` + Account string `yaml:"account"` + Password string `yaml:"password"` + OCRURL string `yaml:"ocr_url"` + StateDB string `yaml:"state_db"` + APIKey string `yaml:"api_key"` }