63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
|
||
|
"git.coopgo.io/coopgo-platform/carpool-service/handler"
|
||
|
grpcserver "git.coopgo.io/coopgo-platform/carpool-service/servers/grpc/server"
|
||
|
ocssapi "git.coopgo.io/coopgo-platform/carpool-service/servers/ocss-api"
|
||
|
"git.coopgo.io/coopgo-platform/carpool-service/storage"
|
||
|
"github.com/rs/zerolog"
|
||
|
"github.com/rs/zerolog/log"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||
|
|
||
|
cfg, err := ReadConfig()
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
var (
|
||
|
service_name = cfg.GetString("name")
|
||
|
grpc_enable = cfg.GetBool("services.grpc.enable")
|
||
|
ocss_enable = cfg.GetBool("services.ocss_api.enable")
|
||
|
dev_env = cfg.GetBool("dev_env")
|
||
|
)
|
||
|
|
||
|
if dev_env {
|
||
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||
|
fmt.Printf("\033]0;%s\007", service_name)
|
||
|
}
|
||
|
log.Info().Msg("Running " + service_name)
|
||
|
|
||
|
storage, err := storage.NewStorage(cfg)
|
||
|
if err != nil {
|
||
|
log.Fatal().Err(err).Msg("could not initiate storage")
|
||
|
}
|
||
|
|
||
|
handler, err := handler.NewCarpoolServiceHandler(cfg, storage)
|
||
|
if err != nil {
|
||
|
log.Fatal().Err(err).Msg("could not initiate incentives handler")
|
||
|
return
|
||
|
}
|
||
|
|
||
|
failed := make(chan error)
|
||
|
|
||
|
if grpc_enable {
|
||
|
log.Info().Msg("Running gRPC server")
|
||
|
go grpcserver.Run(failed, cfg, handler)
|
||
|
}
|
||
|
|
||
|
if ocss_enable {
|
||
|
log.Info().Msg("Running OCSS REST API")
|
||
|
go ocssapi.Run(failed, cfg, handler)
|
||
|
}
|
||
|
|
||
|
err = <-failed
|
||
|
|
||
|
log.Fatal().Err(err).Msg("Terminating")
|
||
|
}
|