package main import ( "flag" "sebclem/claptrapbot-go/api/router" "sebclem/claptrapbot-go/internal/config" "sebclem/claptrapbot-go/internal/database" "sebclem/claptrapbot-go/internal/discordbot" "time" "github.com/gin-contrib/cors" "github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions/cookie" "github.com/gin-contrib/pprof" ginzap "github.com/gin-contrib/zap" "github.com/gin-gonic/gin" ) var ( Token string ) func init() { flag.StringVar(&Token, "t", "", "Bot Token") flag.Parse() } func main() { appConf := config.LoadEnv() config.InitLogger() db := database.Init(appConf) dc := discordbot.NewDiscord(appConf.DiscordToken, db) r := gin.Default() corsConfig := cors.DefaultConfig() corsConfig.AllowOrigins = []string{"*"} corsConfig.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"} corsConfig.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "Authorization"} r.Use(cors.New(corsConfig)) store := cookie.NewStore([]byte("secret")) r.Use(sessions.Sessions("claptrapbot", store)) r.Use(ginzap.Ginzap(config.Logger, time.RFC3339, true)) r.Use(ginzap.RecoveryWithZap(config.Logger, true)) r.GET("/ping", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) router.RegisterRoutes(r, db, dc, appConf) pprof.Register(r) r.Run() // listen and serve on 0.0.0.0:8080 }