3
0
corteza/cmd/compose/main.go
Denis Arh aea9741a2b Improve logging, migrate to zap, use requestID
- migrate from log to go.uber.org/zap package
 - add requestID header with sticky log field
 - push logging via context to REST controllers & HTTP middleware
 - enhance request/resnpose logging
 - add service logging framework
 - add ZapProfiler for db query profiling
2019-05-07 21:18:23 +02:00

63 lines
1.5 KiB
Go

package main
import (
"os"
context "github.com/SentimensRG/ctx"
"github.com/SentimensRG/ctx/sigctx"
_ "github.com/joho/godotenv/autoload"
"github.com/namsral/flag"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
compose "github.com/crusttech/crust/compose"
"github.com/crusttech/crust/internal/logger"
"github.com/crusttech/crust/internal/subscription"
system "github.com/crusttech/crust/system"
)
func main() {
// Initialize default logger
logger.Init(zapcore.DebugLevel)
log := logger.Default().Named("compose")
// New signal-bond context that we will use and
// will get terminated (Done()) on SIGINT or SIGTERM
ctx := context.AsContext(sigctx.New())
// Bind default logger to context
ctx = logger.ContextWithValue(ctx, log)
compose.Flags("compose")
system.Flags("system")
subscription.Flags()
flag.Parse()
if err := system.Init(ctx); err != nil {
log.Fatal("failed to initialize system", zap.Error(err))
}
if err := compose.Init(ctx); err != nil {
log.Fatal("failed to initialize compose", zap.Error(err))
}
var command string
if len(os.Args) > 1 {
command = os.Args[1]
}
switch command {
case "help":
flag.PrintDefaults()
default:
// Checks subscription, will os.Exit(1) if there is an error
// Disabled for now, system service is the only one that validates subscription
// ctx = subscription.Monitor(ctx)
if err := compose.StartRestAPI(ctx); err != nil {
log.Fatal("failed to start compose REST API", zap.Error(err))
}
}
}