main.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "log"
  6. "lttc-go-adm-znaf/orm"
  7. "lttc-go-adm-znaf/pkg/logging"
  8. "lttc-go-adm-znaf/pkg/setting"
  9. "lttc-go-adm-znaf/routers"
  10. "net/http"
  11. )
  12. func init() {
  13. setting.Setup()
  14. orm.Setup()
  15. logging.Setup()
  16. }
  17. // @title Golang Gin API
  18. // @version 1.0
  19. // @description An example of gin
  20. // @termsOfService https://github.com/EDDYCJY/go-gin-example
  21. // @license.name MIT
  22. // @license.url https://github.com/EDDYCJY/go-gin-example/blob/master/LICENSE
  23. func main() {
  24. gin.SetMode(setting.ServerSetting.RunMode)
  25. routersInit := routers.InitRouter()
  26. readTimeout := setting.ServerSetting.ReadTimeout
  27. writeTimeout := setting.ServerSetting.WriteTimeout
  28. endPoint := fmt.Sprintf(":%d", setting.ServerSetting.HttpPort)
  29. maxHeaderBytes := 1 << 20
  30. server := &http.Server{
  31. Addr: endPoint,
  32. Handler: routersInit,
  33. ReadTimeout: readTimeout,
  34. WriteTimeout: writeTimeout,
  35. MaxHeaderBytes: maxHeaderBytes,
  36. }
  37. log.Printf("[info] start http server listening %s", endPoint)
  38. _ = server.ListenAndServe()
  39. }