Commit 2c573b8f authored by AlexStocks's avatar AlexStocks

Mod: use yml config instead of toml

parent 222f82f0
......@@ -13,6 +13,7 @@
- 2018/08/19
> Feature
* use multiple service config
* Config using yml file instead toml
- 2018/08/13
> Init
......
......@@ -11,6 +11,7 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"path"
)
......@@ -20,7 +21,7 @@ import (
"github.com/AlexStocks/getty/rpc"
log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
config "github.com/koding/multiconfig"
"gopkg.in/yaml.v2"
)
const (
......@@ -29,8 +30,8 @@ const (
)
type microConfig struct {
rpc.ClientConfig
Registry micro.RegistryConfig
rpc.ClientConfig `yaml:"core" json:"core, omitempty"`
Registry micro.ConsumerRegistryConfig `yaml:"registry" json:"registry, omitempty"`
}
var (
......@@ -44,13 +45,24 @@ func initConf() {
panic(fmt.Sprintf("application configure file name is nil"))
return // I know it is of no usage. Just Err Protection.
}
if path.Ext(confFile) != ".toml" {
if path.Ext(confFile) != ".yml" {
panic(fmt.Sprintf("application configure file name{%v} suffix must be .toml", confFile))
return
}
conf = &microConfig{}
config.MustLoadWithPath(confFile, conf)
confFileStream, err := ioutil.ReadFile(confFile)
if err != nil {
panic(fmt.Sprintf("ioutil.ReadFile(file:%s) = error:%s", confFile, jerrors.ErrorStack(err)))
return
}
err = yaml.Unmarshal(confFileStream, conf)
if err != nil {
panic(fmt.Sprintf("yaml.Unmarshal() = error:%s", jerrors.ErrorStack(err)))
return
}
if err := conf.ClientConfig.CheckValidity(); err != nil {
panic(jerrors.ErrorStack(err))
return
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "1.0.1"
Version = "1.0.2"
)
......@@ -12,6 +12,6 @@
export TARGET_EXEC_NAME="micro_client"
export BUILD_PACKAGE="app"
export TARGET_CONF_FILE="conf/config.toml"
export TARGET_CONF_FILE="conf/config.yml"
export TARGET_LOG_CONF_FILE="conf/log.xml"
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "MICRO-CLIENT"
# host
LocalHost = "127.0.0.1"
# server
ServerHost = "127.0.0.1"
ServerPort = 10000
ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# session
# client与server之间连接的心跳周期
HeartbeatPeriod = "10s"
# client与server之间连接的超时时间
SessionTimeout = "20s"
# app fail fast
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
KeepAlivePeriod = "120s"
TcpRBufSize = 262144
TcpWBufSize = 65536
PkgRQSize = 512
PkgWQSize = 256
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 1024
SessionName = "getty-micro-client"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "clt-node1"
Codec = "protobuf"
core:
app_name : "MICRO-CLIENT"
host : "127.0.0.1"
profile_port : 20086
# client 与 server单个peer与peer之间连接数目 
connection_number : 2
# session
# client与server之间连接的心跳周期
heartbeat_period : "10s"
# client与server之间连接的超时时间
session_timeout : "20s"
# app fail fast
fail_fast_timeout : "3s"
# connection pool
pool_size : 64
pool_ttl : 600
# tcp
getty_session_param:
compress_encoding : true
tcp_no_delay : true
tcp_keep_alive : true
keep_alive_period : "120s"
tcp_r_buf_size : 262144
tcp_w_buf_size : 65536
pkg_rq_size : 1024
pkg_wq_size : 512
tcp_read_timeout : "1s"
tcp_write_timeout : "5s"
wait_timeout : "1s"
max_msg_len : 1024
session_name : "getty-micro-server"
registry:
basic:
type : "zookeeper"
reg_addr : "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
keepalive_timeout : 10
root : "/getty"
group : "bj-yizhuang"
\ No newline at end of file
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "MICRO-CLIENT"
# host
LocalHost = "127.0.0.1"
# server
ServerHost = "127.0.0.1"
ServerPort = 10000
ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# session
# client与server之间连接的心跳周期
HeartbeatPeriod = "10s"
# client与server之间连接的超时时间
SessionTimeout = "20s"
# app fail fast
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
KeepAlivePeriod = "120s"
TcpRBufSize = 262144
TcpWBufSize = 65536
PkgRQSize = 512
PkgWQSize = 256
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 1024
SessionName = "getty-micro-client"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "clt-node1"
Codec = "protobuf"
core:
app_name : "MICRO-CLIENT"
host : "127.0.0.1"
profile_port : 20086
# client 与 server单个peer与peer之间连接数目 
connection_number : 2
# session
# client与server之间连接的心跳周期
heartbeat_period : "10s"
# client与server之间连接的超时时间
session_timeout : "20s"
# app fail fast
fail_fast_timeout : "3s"
# connection pool
pool_size : 64
pool_ttl : 600
# tcp
getty_session_param:
compress_encoding : true
tcp_no_delay : true
tcp_keep_alive : true
keep_alive_period : "120s"
tcp_r_buf_size : 262144
tcp_w_buf_size : 65536
pkg_rq_size : 1024
pkg_wq_size : 512
tcp_read_timeout : "1s"
tcp_write_timeout : "5s"
wait_timeout : "1s"
max_msg_len : 1024
session_name : "getty-micro-server"
registry:
basic:
type : "zookeeper"
reg_addr : "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
keepalive_timeout : 10
root : "/getty"
group : "bj-yizhuang"
\ No newline at end of file
# toml configure file
# toml中key的首字母可以小写,但是对应的golang中的struct成员首字母必须大写
AppName = "MICRO-CLIENT"
# host
LocalHost = "127.0.0.1"
# server
ServerHost = "127.0.0.1"
ServerPort = 10000
ProfilePort = 10080
# connection pool
# 连接池连接数目
ConnectionNum = 2
# session
# client与server之间连接的心跳周期
HeartbeatPeriod = "10s"
# client与server之间连接的超时时间
SessionTimeout = "20s"
# app fail fast
FailFastTimeout = "3s"
# tcp
[GettySessionParam]
CompressEncoding = true
TcpNoDelay = true
TcpKeepAlive = true
KeepAlivePeriod = "120s"
TcpRBufSize = 262144
TcpWBufSize = 65536
PkgRQSize = 512
PkgWQSize = 256
TcpReadTimeout = "1s"
TcpWriteTimeout = "5s"
WaitTimeout = "1s"
MaxMsgLen = 1024
SessionName = "getty-micro-client"
[Registry]
Type = "zookeeper"
Addr = "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
KeepaliveTimeout = 10
Root = "/getty-root"
IDC = "bj-yizhuang"
NodeID = "clt-node1"
Codec = "protobuf"
core:
app_name : "MICRO-CLIENT"
host : "127.0.0.1"
profile_port : 20086
# client 与 server单个peer与peer之间连接数目 
connection_number : 2
# session
# client与server之间连接的心跳周期
heartbeat_period : "10s"
# client与server之间连接的超时时间
session_timeout : "20s"
# app fail fast
fail_fast_timeout : "3s"
# connection pool
pool_size : 64
pool_ttl : 600
# tcp
getty_session_param:
compress_encoding : true
tcp_no_delay : true
tcp_keep_alive : true
keep_alive_period : "120s"
tcp_r_buf_size : 262144
tcp_w_buf_size : 65536
pkg_rq_size : 1024
pkg_wq_size : 512
tcp_read_timeout : "1s"
tcp_write_timeout : "5s"
wait_timeout : "1s"
max_msg_len : 1024
session_name : "getty-micro-server"
registry:
basic:
type : "zookeeper"
reg_addr : "127.0.0.1:2181"
# 与 registry 之间的 lease 时长
keepalive_timeout : 10
root : "/getty"
group : "bj-yizhuang"
\ No newline at end of file
......@@ -19,7 +19,6 @@ import (
import (
"github.com/AlexStocks/getty/micro"
"github.com/AlexStocks/getty/rpc"
"github.com/AlexStocks/goext/log"
log "github.com/AlexStocks/log4go"
jerrors "github.com/juju/errors"
"gopkg.in/yaml.v2"
......@@ -63,8 +62,6 @@ func initConf() {
return
}
gxlog.CError("conf:%#v", conf)
if err := conf.ServerConfig.CheckValidity(); err != nil {
panic(jerrors.ErrorStack(err))
return
......
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