Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
enoch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
enoch
Commits
637eef1e
Commit
637eef1e
authored
Mar 15, 2019
by
xiaoguang.xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接入apollo 配置中心.
parent
83cc12bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
main.go
main.go
+3
-1
load_conf.go
service/conf/load_conf.go
+6
-6
No files found.
main.go
View file @
637eef1e
...
@@ -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
()
}()
...
...
service/conf/load_conf.go
View file @
637eef1e
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment