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

接入apollo 配置中心.

parent 83cc12bd
......@@ -17,11 +17,13 @@ func main() {
var port string
var quartz bool
var denv string
var didc string
flag.StringVar(&port, "port", "10086", "端口")
flag.BoolVar(&quartz, "quartz", false, "quartz")
flag.StringVar(&denv, "env", "dev", "环境")
flag.StringVar(&didc, "idc", "local", "机房")
flag.Parse()
conf.Load(denv)
conf.Load(denv, didc)
file, err := os.OpenFile("quantgroup.log", os.O_RDWR|os.O_CREATE, 0666)
defer func() { _ = file.Close() }()
......
......@@ -4,16 +4,16 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
var GlobalConfig = Config{}
func Load(denv string) {
var filename = "service/conf/" + denv + "/conf.json"
bytes, err := ioutil.ReadFile(filename)
if nil != err {
fmt.Println("启动报错:未找到对应的环境变量配置。env: " + filename)
}
func Load(denv string, didc string) {
url := "http://apollo-" + denv + ".quantgroups.com/configfiles/real_json/enoch/" + didc + "/tech.config.json"
resp, err := http.Get(url)
defer func() { _ = resp.Body.Close() }()
bytes, err := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(bytes, &GlobalConfig)
GlobalConfig.Env = denv
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