hongbo-miao/hongbomiao.com

View on GitHub
api-go/cmd/decision_logger/main.go

Summary

Maintainability
A
0 mins
Test Coverage
package main

import (
    "github.com/gin-contrib/gzip"
    "github.com/gin-contrib/logger"
    "github.com/gin-gonic/gin"
    "github.com/hongbo-miao/hongbomiao.com/api-go/internal/decision_logger/controllers"
    "github.com/hongbo-miao/hongbomiao.com/api-go/internal/decision_logger/utils"
    sharedControllers "github.com/hongbo-miao/hongbomiao.com/api-go/internal/shared/controllers"
    sharedHandlers "github.com/hongbo-miao/hongbomiao.com/api-go/internal/shared/handlers"
    sharedUtils "github.com/hongbo-miao/hongbomiao.com/api-go/internal/shared/utils"
    "github.com/rs/zerolog/log"
    "go.elastic.co/apm/module/apmgin/v2"
)

func main() {
    sharedUtils.InitLogger()
    config := utils.GetConfig()
    log.Info().
        Str("AppEnv", config.AppEnv).
        Str("Port", config.Port).
        Msg("main")

    r := gin.New()
    r.Use(apmgin.Middleware(r))
    r.Use(logger.SetLogger())
    r.GET("/", sharedControllers.Health)
    r.GET("/metrics", sharedHandlers.PrometheusHandler())
    r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithDecompressFn(gzip.DefaultDecompressHandle)))
    r.POST("/logs", controllers.Logs)
    err := r.Run(":" + config.Port)
    if err != nil {
        log.Error().Err(err).Msg("r.Run")
    }
}