蛋蛋星球-客户端
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.

1 maand geleden
2 weken geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if err := db.InitImDB(cfg.IMDB); err != nil { // IM主数据库初始化
  28. panic(err)
  29. }
  30. }
  31. fmt.Println("init success")
  32. }
  33. // @title 蛋蛋星球-APP客户端
  34. // @version 1.0
  35. // @description APP客户端-Api接口
  36. // @termsOfService http://swagger.io/terms/
  37. // @contact.name dengbiao
  38. // @contact.url http://www.swagger.io/support
  39. // @contact.email 1239118001@qq.com
  40. // @license.name Apache 2.0
  41. // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
  42. // @host ddxq.izhim.com
  43. // @BasePath /api/v1
  44. func main() {
  45. r := router.Init() // 创建路由
  46. srv := &http.Server{ // 设置http服务参数
  47. Addr: cfg.SrvAddr, // 指定ip和端口
  48. Handler: r, // 指定路由
  49. }
  50. go func() { // 协程启动监听http服务
  51. fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
  52. if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
  53. log.Fatalf("listen: %s\n", err)
  54. }
  55. }()
  56. // 退出go守护进程
  57. quit := make(chan os.Signal)
  58. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  59. <-quit
  60. log.Println("Shutting down server...")
  61. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  62. defer cancel()
  63. if err := srv.Shutdown(ctx); err != nil {
  64. log.Fatal("Server forced to shutdown:", err)
  65. }
  66. log.Println("Server exiting")
  67. }