Commit 637eef1e authored by xiaoguang.xu's avatar xiaoguang.xu

接入apollo 配置中心.

parent 83cc12bd
...@@ -17,11 +17,13 @@ func main() { ...@@ -17,11 +17,13 @@ func main() {
var port string var port string
var quartz bool var quartz bool
var denv string var denv string
var didc string
flag.StringVar(&port, "port", "10086", "端口") flag.StringVar(&port, "port", "10086", "端口")
flag.BoolVar(&quartz, "quartz", false, "quartz") flag.BoolVar(&quartz, "quartz", false, "quartz")
flag.StringVar(&denv, "env", "dev", "环境") flag.StringVar(&denv, "env", "dev", "环境")
flag.StringVar(&didc, "idc", "local", "机房")
flag.Parse() flag.Parse()
conf.Load(denv) conf.Load(denv, didc)
file, err := os.OpenFile("quantgroup.log", os.O_RDWR|os.O_CREATE, 0666) file, err := os.OpenFile("quantgroup.log", os.O_RDWR|os.O_CREATE, 0666)
defer func() { _ = file.Close() }() defer func() { _ = file.Close() }()
......
...@@ -4,16 +4,16 @@ import ( ...@@ -4,16 +4,16 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http"
) )
var GlobalConfig = Config{} var GlobalConfig = Config{}
func Load(denv string) { func Load(denv string, didc string) {
var filename = "service/conf/" + denv + "/conf.json" url := "http://apollo-" + denv + ".quantgroups.com/configfiles/real_json/enoch/" + didc + "/tech.config.json"
bytes, err := ioutil.ReadFile(filename) resp, err := http.Get(url)
if nil != err { defer func() { _ = resp.Body.Close() }()
fmt.Println("启动报错:未找到对应的环境变量配置。env: " + filename) bytes, err := ioutil.ReadAll(resp.Body)
}
err = json.Unmarshal(bytes, &GlobalConfig) err = json.Unmarshal(bytes, &GlobalConfig)
GlobalConfig.Env = denv GlobalConfig.Env = denv
if nil != err { if nil != err {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment