蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 1.7 KiB

1 kuukausi sitten
1 kuukausi sitten
1 kuukausi sitten
1 kuukausi sitten
1 kuukausi sitten
1 kuukausi sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package main
  2. import (
  3. "applet/app/db"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "log"
  8. "net/http"
  9. "os"
  10. "os/signal"
  11. "syscall"
  12. "time"
  13. "applet/app/cfg"
  14. "applet/app/router"
  15. )
  16. // 系统初始化
  17. func init() {
  18. cfg.InitCfg() // 配置初始化
  19. cfg.InitLog() // 日志初始化
  20. cfg.InitCache() // 缓存初始化
  21. cfg.InitMq() // 队列初始化
  22. cfg.InitEs() //ElasticSearch初始化
  23. if cfg.Debug { // 判断是否是debug
  24. if err := db.InitDB(cfg.DB); err != nil { // 主数据库初始化
  25. panic(err)
  26. }
  27. }
  28. fmt.Println("init success")
  29. }
  30. // @title 蛋蛋星球-APP客户端
  31. // @version 1.0
  32. // @description APP客户端-Api接口
  33. // @termsOfService http://swagger.io/terms/
  34. // @contact.name dengbiao
  35. // @contact.url http://www.swagger.io/support
  36. // @contact.email 1239118001@qq.com
  37. // @license.name Apache 2.0
  38. // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
  39. // @host ddxq.izhim.com
  40. // @BasePath /api/v1
  41. func main() {
  42. r := router.Init() // 创建路由
  43. srv := &http.Server{ // 设置http服务参数
  44. Addr: cfg.SrvAddr, // 指定ip和端口
  45. Handler: r, // 指定路由
  46. }
  47. go func() { // 协程启动监听http服务
  48. fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
  49. if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
  50. log.Fatalf("listen: %s\n", err)
  51. }
  52. }()
  53. // 退出go守护进程
  54. quit := make(chan os.Signal)
  55. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  56. <-quit
  57. log.Println("Shutting down server...")
  58. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  59. defer cancel()
  60. if err := srv.Shutdown(ctx); err != nil {
  61. log.Fatal("Server forced to shutdown:", err)
  62. }
  63. log.Println("Server exiting")
  64. }