Files
houston-be/cmd/main.go

65 lines
1.6 KiB
Go

package main
import (
"houston/cmd/app"
"houston/config"
"houston/internal/clients"
"houston/log"
"houston/pkg/postgres"
"os"
"time"
"github.com/spf13/viper"
ginzap "github.com/gin-contrib/zap"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
func main() {
log.InitLogger()
logger, _ := zap.NewProduction()
config.LoadHoustonConfig(logger)
godotenv.Load()
command := &cobra.Command{
Use: "houston",
Short: "houston is replacement for blameless and incident management slackbot bot at Navi",
Long: "houston is replacement for blameless and incident management slackbot bot at Navi",
RunE: func(cmd *cobra.Command, args []string) error {
r := gin.New()
r.Use(ginzap.Ginzap(logger, time.RFC3339, true))
r.Use(ginzap.RecoveryWithZap(logger, true))
houston := r.Group("/houston")
db := postgres.NewGormClient(
viper.GetString("postgres.dsn"),
viper.GetString("postgres.connection.max.idle.time"),
viper.GetString("postgres.connection.max.lifetime"),
viper.GetInt("postgres.connections.max.idle"),
viper.GetInt("postgres.connections.max.open"),
logger,
)
httpClient := clients.NewHttpClient()
mjolnirClient := clients.NewMjolnirClient(httpClient.HttpClient, logger,
viper.GetString("mjolnir.service.url"), viper.GetString("mjolnir.realm.id"),
)
sv := app.NewServer(r, logger, db, mjolnirClient)
sv.Handler(houston)
sv.Start()
return nil
},
}
if err := command.Execute(); err != nil {
logger.Error("houston core command execution failed", zap.Error(err))
os.Exit(1)
}
}