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

2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 蛋蛋星球-管理后台
  31. // @version 1.0
  32. // @description 管理后台接口文档
  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 localhost:4001
  40. // @securityDefinitions.apikey MasterID
  41. // @in header
  42. // @name MasterID
  43. // @BasePath /api
  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. }