Skip to content

Commit

Permalink
feat:支持从环境变量获取对应环境 apigw 后台服务地址
Browse files Browse the repository at this point in the history
  • Loading branch information
normal-wls committed May 16, 2024
1 parent 6a70e86 commit 1b22aea
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions conf/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var environment string
var port int
var apigwBackendHost string
var apigwSubPath string
var apigwScheme string

var redisAddr string
var redisPassword string
Expand Down Expand Up @@ -132,6 +133,7 @@ func initApigwBackendHost() {
subdomains := Settings.DefaultString("app_default_subdomains", "")
// 定义一个map来存储反序列化后的数据
var urls map[string]string
apigwScheme = "http"
apigwSubPath = ""
apigwBackendHost = ""
// 反序列化:把 JSON 字符串转换为 map
Expand All @@ -149,6 +151,7 @@ func initApigwBackendHost() {
}
// 域名部分包括 scheme 和 host
// 域名后的部分是 path
apigwScheme = parsedURL.Scheme
apigwSubPath = strings.TrimLeft(parsedURL.Path, "/")
apigwBackendHost = parsedURL.Host

Expand All @@ -158,6 +161,10 @@ func ApigwBackendHost() string {
return apigwBackendHost
}

func ApigwScheme() string {
return apigwScheme
}

func ApigwSubPath() string {
return apigwSubPath
}
Expand Down
2 changes: 1 addition & 1 deletion runner/data/api-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ stage:
upstreams:
loadbalance: "roundrobin"
hosts:
- host: http://{{ data.BK_PLUGIN_APIGW_BACKEND_HOST }}/
- host: {{ data.BK_PLUGIN_APIGW_BACKEND_SCHEME }}://{{ data.BK_PLUGIN_APIGW_BACKEND_HOST }}/
weight: 100

resource_version:
Expand Down
1 change: 1 addition & 0 deletions runner/syncapigw.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func runSyncApigw() {
"BK_PLUGIN_APIGW_NAME": conf.ApigwApiName(),
"BK_PLUGIN_APIGW_STAGE_NAME": conf.Environment(),
"BK_PLUGIN_APIGW_BACKEND_HOST": conf.ApigwBackendHost(),
"BK_PLUGIN_APIGW_BACKEND_SCHEME": conf.ApigwScheme(),
"BK_PLUGIN_APIGW_BACKEND_SUB_PATH": conf.ApigwSubPath(),
"BK_PLUGIN_APIGW_RESOURCE_VERSION": fmt.Sprintf("1.0.0+%v", time.Now().Unix()),
"RESOURCES_FILE_PATH": resourcesPath,
Expand Down

0 comments on commit 1b22aea

Please sign in to comment.