main.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package main
  2. import (
  3. "go.uber.org/zap"
  4. "goiot-cronapi/common"
  5. "goiot-cronapi/global/orm"
  6. "goiot-cronapi/global/redis"
  7. "goiot-cronapi/pkg/logger"
  8. "goiot-cronapi/router"
  9. "goiot-pkg/tools"
  10. "net/http"
  11. )
  12. // @title LiHua Cloud Platform Server Api
  13. // @version 1.0
  14. // @description This is lihua cloud platform api
  15. func main() {
  16. engine := router.InitRouter()
  17. server := common.ConfigInfo.Server
  18. serverInfo := server.Host + ":" + server.Port
  19. logger.Info("Server Start Info: " + serverInfo)
  20. if err := engine.Run(serverInfo); err != nil && err != http.ErrServerClosed {
  21. logger.Fatal("Listen", zap.String("[FATAL]", err.Error()))
  22. }
  23. }
  24. func init() {
  25. var err error
  26. // 加载本地配置
  27. err = common.LoadConfigInformation()
  28. if err != nil {
  29. return
  30. }
  31. // 加载Apollo配置
  32. var apolloConf *tools.ApolloConfig
  33. apolloConf, err = common.LoadApolloConfig()
  34. if err != nil {
  35. return
  36. }
  37. orm.Eloquent = apolloConf.DB
  38. redis.Cacher = apolloConf.Redis
  39. // 日志初始化
  40. logger.Init(&logger.Config{
  41. Compress: common.ConfigInfo.Log.Compress == 1,
  42. ConsoleStdout: common.ConfigInfo.Log.ConsoleStdout == 1,
  43. FileStdout: common.ConfigInfo.Log.FileStdout == 1,
  44. Level: common.ConfigInfo.Log.Level,
  45. LocalTime: common.ConfigInfo.Log.LocalTime == 1,
  46. MaxAge: common.ConfigInfo.Log.MaxAge,
  47. MaxBackups: common.ConfigInfo.Log.MaxBackups,
  48. MaxSize: common.ConfigInfo.Log.MaxSize,
  49. Path: common.ConfigInfo.Log.Path,
  50. })
  51. }