package gin import ( "fmt" "io" "log" "net/http" "os" "strconv" "time" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" ) var ( addr string port int ssl string sslPem string sslKey string ) func Service() { addr = os.Getenv("GIN_ADDR") if addr == "" { addr = "0.0.0.0" } port, _ = strconv.Atoi(os.Getenv("GIN_PORT")) if port == 0 { port = 8080 } go func() { gin.DefaultWriter = io.Discard router := gin.New() routerSetup(router) s := &http.Server{ Addr: fmt.Sprintf("%s:%d", addr, port), Handler: router, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } logrus.WithFields(logrus.Fields{ "func": "Service", }).Infof("start service on %s:%d", addr, port) if ssl == "true" { log.Fatal(s.ListenAndServeTLS(sslPem, sslKey)) } else { log.Fatal(s.ListenAndServe()) } }() }