/
config.go
90 lines (83 loc) · 2.68 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2018 github.com/xiaoenai. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gateway
import (
"time"
"github.com/henrylee2cn/cfgo"
micro "github.com/xiaoenai/tp-micro"
"github.com/xiaoenai/tp-micro/model/etcd"
short "github.com/xiaoenai/tp-micro/gateway/logic/http"
)
// Config app config
type Config struct {
EnableHttp bool `yaml:"enable_http"`
EnableSocket bool `yaml:"enable_socket"`
OuterHttpServer short.HttpSrvConfig `yaml:"outer_http_server"`
OuterSocketServer micro.SrvConfig `yaml:"outer_socket_server"`
InnerSocketServer micro.SrvConfig `yaml:"inner_socket_server"`
InnerSocketClient micro.CliConfig `yaml:"inner_socket_client"`
Etcd etcd.EasyConfig `yaml:"etcd"`
}
// NewConfig creates a default config.
func NewConfig() *Config {
return &Config{
EnableHttp: true,
EnableSocket: true,
OuterHttpServer: short.HttpSrvConfig{
ListenAddress: "0.0.0.0:5000",
AllowCross: false,
},
OuterSocketServer: micro.SrvConfig{
ListenAddress: "0.0.0.0:5020",
EnableHeartbeat: true,
PrintDetail: true,
CountTime: true,
SlowCometDuration: time.Millisecond * 500,
},
InnerSocketServer: micro.SrvConfig{
ListenAddress: "0.0.0.0:5030",
EnableHeartbeat: true,
PrintDetail: true,
CountTime: true,
SlowCometDuration: time.Millisecond * 500,
},
InnerSocketClient: micro.CliConfig{
Failover: 3,
HeartbeatSecond: 60,
DefaultContextAge: time.Second * 5,
},
Etcd: etcd.EasyConfig{
Endpoints: []string{"http://127.0.0.1:2379"},
},
}
}
// Reload Bi-directionally synchronizes config between YAML file and memory.
func (c *Config) Reload(bind cfgo.BindFunc) error {
err := bind()
if err == nil {
c.OuterHttpServer.OuterIpPort()
}
c.OuterHttpServer.PrintDetail = c.OuterSocketServer.PrintDetail
c.OuterHttpServer.CountTime = c.OuterSocketServer.CountTime
c.OuterHttpServer.SlowCometDuration = c.OuterSocketServer.SlowCometDuration
return err
}
// check the config
func (c *Config) check() error {
err := c.InnerSocketClient.Check()
if err != nil {
return err
}
return nil
}