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