1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package main
- import (
- "log"
- "net"
- "os"
- "strings"
- gamelangpb "git.alfi.li/gamelang/protobuf/gamelang"
- um "git.alfi.li/gamelang/systems/usermanager"
- "google.golang.org/grpc"
- gcfg "gopkg.in/gcfg.v1"
- )
- type Config struct {
- Grpc struct {
- Listen string // ip:port
- }
- Kafka struct {
- Enabled bool
- Broker string
- }
- }
- func main() {
- var config Config
- err := gcfg.ReadFileInto(&config, "config")
- if err != nil {
- log.Print(err)
- log.Print("reading config from env")
- config.Grpc.Listen = os.Getenv("GRPC_LISTEN")
- config.Kafka.Enabled = os.Getenv("KAFKA_ENABLED") == "true"
- config.Kafka.Broker = os.Getenv("KAFKA_BROKER")
- }
- log.Print("config read")
- log.Printf("%+v", config)
- // init usermanager
- brokers := []string{}
- if config.Kafka.Enabled {
- brokers = strings.Split(config.Kafka.Broker, ",")
- }
- usermanager := um.NewUserManager(brokers)
- log.Print("usermanager initialized")
- // init GrpcServer
- lis, err := net.Listen("tcp", config.Grpc.Listen)
- if err != nil {
- log.Fatalf("failed to listen: %v", err)
- }
- grpcServer := grpc.NewServer()
- gamelangpb.RegisterUserServiceServer(grpcServer, um.NewUserServer(usermanager))
- grpcServer.Serve(lis)
- }
|