config has been changed
This commit is contained in:
parent
3b7c5aad87
commit
8abac7b46a
16
conf/conf.go
Normal file
16
conf/conf.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
ofc "git.loafle.net/overflow/overflow_config"
|
||||
)
|
||||
|
||||
var Config Conf
|
||||
|
||||
type Conf struct {
|
||||
Server ofc.Server `json:"server" yaml:"server" toml:"server"`
|
||||
Auth ofc.Auth `json:"auth" yaml:"auth" toml:"auth"`
|
||||
Websocket ofc.Websocket `json:"websocket" yaml:"websocket" toml:"websocket"`
|
||||
GRPC ofc.GRPC `json:"gRPC" yaml:"gRPC" toml:"gRPC"`
|
||||
Redis ofc.Redis `json:"redis" yaml:"redis" toml:"redis"`
|
||||
Handlers map[string]ofc.Handler `json:"handlers" yaml:"handlers" toml:"handlers"`
|
||||
}
|
29
config.json
29
config.json
|
@ -12,7 +12,7 @@
|
|||
"WriteBufferSize": 8192,
|
||||
"EnableCompression": false
|
||||
},
|
||||
"grpc": {
|
||||
"gRPC": {
|
||||
"addr": "192.168.1.50:50006",
|
||||
"tls": false,
|
||||
"pool": {
|
||||
|
@ -57,33 +57,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
},
|
||||
"logging": {
|
||||
"level": "debug",
|
||||
"development": true,
|
||||
"disableCaller": true,
|
||||
"disableStacktrace": true,
|
||||
"sampling": {
|
||||
"initial": 100,
|
||||
"thereafter": 100
|
||||
},
|
||||
"encoding": "console",
|
||||
"encoderConfig": {
|
||||
"messageKey": "message",
|
||||
"levelKey": "level",
|
||||
"timeKey": "time",
|
||||
"nameKey": "name",
|
||||
"callerKey": "caller",
|
||||
"stacktraceKey": "stacktrace",
|
||||
"lineEnding": "\n",
|
||||
"levelEncoder": "color",
|
||||
"timeEncoder": "ISO8601",
|
||||
"durationEncoder": "string",
|
||||
"callerEncoder": "full",
|
||||
"nameEncoder": "full"
|
||||
},
|
||||
"outputPaths": ["stdout", "/tmp/logs"],
|
||||
"errorOutputPaths": ["stderr"]
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,3 +28,4 @@ import:
|
|||
- package: google.golang.org/grpc
|
||||
subpackages:
|
||||
- metadata
|
||||
- package: git.loafle.net/overflow/overflow_config
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
cgp "git.loafle.net/commons_go/grpc_pool"
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
)
|
||||
|
||||
var _pool cgp.Pool
|
||||
|
@ -16,9 +16,8 @@ func InitializePool(ctx context.Context) {
|
|||
h := &poolHandlers{
|
||||
ctx: ctx,
|
||||
}
|
||||
h.cfg = config.Sub("grpc")
|
||||
h.MaxIdle = h.cfg.GetInt("pool.MaxIdle")
|
||||
h.MaxCapacity = h.cfg.GetInt("pool.MaxCapacity")
|
||||
h.MaxIdle = conf.Config.GRPC.Pool.MaxIdle
|
||||
h.MaxCapacity = conf.Config.GRPC.Pool.MaxCapacity
|
||||
|
||||
_pool, err = cgp.New(ctx, h)
|
||||
if nil != err {
|
||||
|
|
|
@ -5,20 +5,19 @@ import (
|
|||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
cgp "git.loafle.net/commons_go/grpc_pool"
|
||||
oas "git.loafle.net/overflow/overflow_api_server/golang"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
)
|
||||
|
||||
type poolHandlers struct {
|
||||
cgp.PoolHandlers
|
||||
ctx context.Context
|
||||
cfg config.Configurator
|
||||
}
|
||||
|
||||
func (h *poolHandlers) OnCreate() (*grpc.ClientConn, interface{}, error) {
|
||||
var err error
|
||||
conn, err := grpc.Dial(config.GetString("grpc.addr"), grpc.WithInsecure())
|
||||
conn, err := grpc.Dial(conf.Config.GRPC.Addr, grpc.WithInsecure())
|
||||
if nil != err {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -5,27 +5,28 @@ import (
|
|||
"time"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
ogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
)
|
||||
|
||||
type authSocketHandlers struct {
|
||||
ogw.SocketHandlers
|
||||
ctx context.Context
|
||||
cfg config.Configurator
|
||||
}
|
||||
|
||||
func NewAuthSocketHandler(ctx context.Context) ogw.SocketHandler {
|
||||
h := &authSocketHandlers{
|
||||
ctx: ctx,
|
||||
}
|
||||
h.cfg = config.Sub("handlers.auth")
|
||||
h.MaxMessageSize = h.cfg.GetInt64("socket.MaxMessageSize")
|
||||
h.WriteTimeout = h.cfg.GetDuration("socket.WriteTimeout") * time.Second
|
||||
h.ReadTimeout = h.cfg.GetDuration("socket.ReadTimeout") * time.Second
|
||||
h.PongTimeout = h.cfg.GetDuration("socket.PongTimeout") * time.Second
|
||||
h.PingTimeout = h.cfg.GetDuration("socket.PingTimeout") * time.Second
|
||||
h.PingPeriod = h.cfg.GetDuration("socket.PingPeriod") * time.Second
|
||||
h.BinaryMessage = h.cfg.GetBool("socket.BinaryMessage")
|
||||
cfg := conf.Config.Handlers["auth"]
|
||||
|
||||
h.MaxMessageSize = cfg.Socket.MaxMessageSize
|
||||
h.WriteTimeout = cfg.Socket.WriteTimeout * time.Second
|
||||
h.ReadTimeout = cfg.Socket.ReadTimeout * time.Second
|
||||
h.PongTimeout = cfg.Socket.PongTimeout * time.Second
|
||||
h.PingTimeout = cfg.Socket.PingTimeout * time.Second
|
||||
h.PingPeriod = cfg.Socket.PingPeriod * time.Second
|
||||
h.BinaryMessage = cfg.Socket.BinaryMessage
|
||||
|
||||
ph := newAuthJSONRpcHandler(ctx)
|
||||
|
||||
|
|
|
@ -5,27 +5,28 @@ import (
|
|||
"time"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
ogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
)
|
||||
|
||||
type probeSocketHandlers struct {
|
||||
ogw.SocketHandlers
|
||||
ctx context.Context
|
||||
cfg config.Configurator
|
||||
}
|
||||
|
||||
func NewProbeSocketHandler(ctx context.Context) ogw.SocketHandler {
|
||||
h := &probeSocketHandlers{
|
||||
ctx: ctx,
|
||||
}
|
||||
h.cfg = config.Sub("handlers.probe")
|
||||
h.MaxMessageSize = h.cfg.GetInt64("socket.MaxMessageSize")
|
||||
h.WriteTimeout = h.cfg.GetDuration("socket.WriteTimeout") * time.Second
|
||||
h.ReadTimeout = h.cfg.GetDuration("socket.ReadTimeout") * time.Second
|
||||
h.PongTimeout = h.cfg.GetDuration("socket.PongTimeout") * time.Second
|
||||
h.PingTimeout = h.cfg.GetDuration("socket.PingTimeout") * time.Second
|
||||
h.PingPeriod = h.cfg.GetDuration("socket.PingPeriod") * time.Second
|
||||
h.BinaryMessage = h.cfg.GetBool("socket.BinaryMessage")
|
||||
cfg := conf.Config.Handlers["probe"]
|
||||
|
||||
h.MaxMessageSize = cfg.Socket.MaxMessageSize
|
||||
h.WriteTimeout = cfg.Socket.WriteTimeout * time.Second
|
||||
h.ReadTimeout = cfg.Socket.ReadTimeout * time.Second
|
||||
h.PongTimeout = cfg.Socket.PongTimeout * time.Second
|
||||
h.PingTimeout = cfg.Socket.PingTimeout * time.Second
|
||||
h.PingPeriod = cfg.Socket.PingPeriod * time.Second
|
||||
h.BinaryMessage = cfg.Socket.BinaryMessage
|
||||
|
||||
ph := newProbeJSONRpcHandler(ctx)
|
||||
|
||||
|
|
22
main.go
22
main.go
|
@ -3,10 +3,10 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
"git.loafle.net/commons_go/logging"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/grpc"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/handler"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/redis"
|
||||
|
@ -19,7 +19,10 @@ func main() {
|
|||
|
||||
flag.Parse()
|
||||
|
||||
loadConfig(*configPath)
|
||||
config.SetConfigPath(*configPath)
|
||||
if err := config.Load(&conf.Config, "config.json"); nil != err {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
|
@ -34,17 +37,8 @@ func main() {
|
|||
|
||||
subscribe.Subscribe(ctx, rp.Get())
|
||||
|
||||
s.HandleSocket(config.GetString("handlers.probe.entry"), psh)
|
||||
s.HandleSocket(config.GetString("handlers.auth.entry"), ash)
|
||||
s.HandleSocket(conf.Config.Handlers["probe"].Entry, psh)
|
||||
s.HandleSocket(conf.Config.Handlers["auth"].Entry, ash)
|
||||
|
||||
s.ListenAndServe(config.GetString("server.addr"))
|
||||
}
|
||||
|
||||
func loadConfig(path string) {
|
||||
config.SetConfigName("config")
|
||||
config.AddConfigPath(path)
|
||||
err := config.ReadInConfig()
|
||||
if nil != err {
|
||||
log.Fatalf("config error: %v", err)
|
||||
}
|
||||
s.ListenAndServe(conf.Config.Server.Addr)
|
||||
}
|
||||
|
|
|
@ -4,17 +4,16 @@ import (
|
|||
"context"
|
||||
"time"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
rp "git.loafle.net/commons_go/redis_pool"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
)
|
||||
|
||||
func NewPool(ctx context.Context) rp.Pool {
|
||||
h := &poolHandlers{
|
||||
ctx: ctx,
|
||||
}
|
||||
h.cfg = config.Sub("redis")
|
||||
h.MaxIdle = h.cfg.GetInt("pool.MaxIdle")
|
||||
h.IdleTimeout = h.cfg.GetDuration("pool.IdleTimeout") * time.Second
|
||||
h.MaxIdle = conf.Config.Redis.Pool.MaxIdle
|
||||
h.IdleTimeout = conf.Config.Redis.Pool.IdleTimeout * time.Second
|
||||
|
||||
p := rp.NewPool(ctx, h)
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
"github.com/garyburd/redigo/redis"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
rp "git.loafle.net/commons_go/redis_pool"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
|
@ -15,11 +15,10 @@ type poolHandlers struct {
|
|||
rp.PoolHandlers
|
||||
ctx context.Context
|
||||
logger *zap.Logger
|
||||
cfg config.Configurator
|
||||
}
|
||||
|
||||
func (h *poolHandlers) Dial() (redis.Conn, error) {
|
||||
return redis.Dial(h.cfg.GetString("network"), h.cfg.GetString("addr"))
|
||||
return redis.Dial(conf.Config.Redis.Network, conf.Config.Redis.Addr)
|
||||
}
|
||||
|
||||
func (h *poolHandlers) TestOnBorrow(c redis.Conn, t time.Time) error {
|
||||
|
|
|
@ -3,7 +3,7 @@ package server
|
|||
import (
|
||||
"context"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
ogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||
)
|
||||
|
||||
|
@ -13,7 +13,7 @@ func NewServer(ctx context.Context) ogw.Server {
|
|||
h := newServerHandler(ctx)
|
||||
_s := ogw.NewServer(ctx, h)
|
||||
|
||||
ofSigningKey = []byte(config.GetString("auth.signingKey"))
|
||||
ofSigningKey = []byte(conf.Config.Auth.SigningKey)
|
||||
|
||||
return _s
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"git.loafle.net/commons_go/config"
|
||||
"git.loafle.net/overflow/overflow_gateway_probe/conf"
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
|
@ -18,11 +19,10 @@ func newServerHandler(ctx context.Context) ogw.ServerHandler {
|
|||
h := &serverHandlers{
|
||||
ctx: ctx,
|
||||
}
|
||||
h.cfg = config.Sub("websocket")
|
||||
h.HandshakeTimeout = h.cfg.GetDuration("HandshakeTimeout") * time.Second
|
||||
h.ReadBufferSize = h.cfg.GetInt("ReadBufferSize")
|
||||
h.WriteBufferSize = h.cfg.GetInt("WriteBufferSize")
|
||||
h.EnableCompression = h.cfg.GetBool("EnableCompression")
|
||||
h.HandshakeTimeout = conf.Config.Websocket.HandshakeTimeout * time.Second
|
||||
h.ReadBufferSize = conf.Config.Websocket.ReadBufferSize
|
||||
h.WriteBufferSize = conf.Config.Websocket.WriteBufferSize
|
||||
h.EnableCompression = conf.Config.Websocket.EnableCompression
|
||||
|
||||
return h
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user