蛋蛋星球 后台端
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.9 KiB

1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
3 weeks ago
1 month ago
1 day ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
3 weeks ago
1 month ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 蛋蛋星球-管理后台
  34. // @version 1.0
  35. // @description 管理后台接口文档
  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 localhost:4001
  43. // @securityDefinitions.apikey MasterID
  44. // @in header
  45. // @name MasterID
  46. // @BasePath /api
  47. func main() {
  48. r := router.Init() // 创建路由
  49. srv := &http.Server{ // 设置http服务参数
  50. Addr: cfg.SrvAddr, // 指定ip和端口
  51. Handler: r, // 指定路由
  52. }
  53. go func() { // 协程启动监听http服务
  54. fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
  55. if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
  56. log.Fatalf("listen: %s\n", err)
  57. }
  58. }()
  59. // 退出go守护进程
  60. quit := make(chan os.Signal)
  61. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  62. <-quit
  63. log.Println("Shutting down server...")
  64. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  65. defer cancel()
  66. if err := srv.Shutdown(ctx); err != nil {
  67. log.Fatal("Server forced to shutdown:", err)
  68. }
  69. log.Println("Server exiting")
  70. }