79 lines
1.6 KiB
Go
79 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"flag"
|
|
"log"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"git.loafle.net/commons_go/config"
|
|
"git.loafle.net/commons_go/logging"
|
|
"git.loafle.net/overflow/overflow_gateway_probe/grpc"
|
|
"git.loafle.net/overflow/overflow_gateway_probe/handler"
|
|
"git.loafle.net/overflow/overflow_gateway_probe/redis"
|
|
"git.loafle.net/overflow/overflow_gateway_probe/server"
|
|
"git.loafle.net/overflow/overflow_gateway_probe/subscribe"
|
|
)
|
|
|
|
var logger *zap.Logger
|
|
|
|
func main() {
|
|
configPath := flag.String("config", ".", "The path of config file")
|
|
|
|
flag.Parse()
|
|
|
|
loadConfig(*configPath)
|
|
ctx := newContext()
|
|
|
|
defer logger.Sync()
|
|
|
|
s := server.NewServer(ctx)
|
|
rp := redis.NewPool(ctx)
|
|
grpc.InitializePool(ctx)
|
|
|
|
psh := handler.NewProbeSocketHandler(ctx)
|
|
ash := handler.NewAuthSocketHandler(ctx)
|
|
|
|
subscribe.Subscribe(ctx, rp.Get())
|
|
|
|
s.HandleSocket(config.GetString("handlers.probe.entry"), psh)
|
|
s.HandleSocket(config.GetString("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)
|
|
}
|
|
}
|
|
|
|
func newContext() context.Context {
|
|
var err error
|
|
ctx := context.Background()
|
|
logConfig := config.Sub("logging")
|
|
|
|
buf, err := logConfig.Marshal("json")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var cfg zap.Config
|
|
if err = json.Unmarshal(buf, &cfg); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
logger, err = cfg.Build()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
ctx = logging.NewContext(ctx, logger)
|
|
|
|
return ctx
|
|
}
|