广告平台(总站长使用)
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

97 satır
2.4 KiB

  1. package main
  2. import (
  3. db "code.fnuoos.com/zhimeng/model.git/src"
  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. "applet/app/utils"
  16. )
  17. // 系统初始化
  18. func init() {
  19. cfg.InitCfg() //配置初始化
  20. cfg.InitLog() //日志初始化
  21. cfg.InitCache() //缓存初始化
  22. if cfg.Debug { //判断是否是debug
  23. if err := db.InitDB(cfg.DB); err != nil { //主数据库初始化
  24. panic(err)
  25. }
  26. channel := make(chan int, 0) //开辟管道,缓冲为
  27. go db.InitDBs(channel)
  28. <-channel
  29. }
  30. fmt.Println("init success")
  31. }
  32. // @title 广告联盟-总站长平台
  33. // @version 1.0
  34. // @description 总站长后台接口
  35. // @termsOfService http://swagger.io/terms/
  36. // @contact.name dengbiao
  37. // @contact.url http://www.swagger.io/support
  38. // @contact.email 1239118001@qq.com
  39. // @license.name Apache 2.0
  40. // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
  41. // @host localhost:1001 or advertisement.dengbiao.top
  42. // @securityDefinitions.apikey MasterID
  43. // @in header
  44. // @name MasterID
  45. // @BasePath /api
  46. func main() {
  47. // 启动获取所有品牌
  48. //go taoke.GetAllBrand()
  49. r := router.Init() //创建路由
  50. // arkid.Init()
  51. srv := &http.Server{ //设置http服务参数
  52. Addr: cfg.SrvAddr, //指定ip和端口
  53. Handler: r, //指定路由
  54. }
  55. // 读取默认站长的推广位 并写进redis
  56. // master, err := db.UserProfileFindByID(,"1")
  57. // if err != nil {
  58. // panic(err)
  59. // }
  60. if cfg.CurlDebug {
  61. utils.CurlDebug = true
  62. }
  63. //
  64. // if has := cache.SetJson(svc.SysCfgGet(nil, "app_name")+"_default_pid_user", master, 0); has != true {
  65. // panic(errors.New("设置默认pid缓存失败"))
  66. // }
  67. // Initializing the server in a goroutine so that it won't block the graceful shutdown handling below
  68. go func() { //协程启动监听http服务
  69. fmt.Println("Listening and serving HTTP on " + cfg.SrvAddr)
  70. if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
  71. log.Fatalf("listen: %s\n", err)
  72. }
  73. }()
  74. // graceful shutdown
  75. //退出go守护进程
  76. quit := make(chan os.Signal)
  77. signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
  78. <-quit
  79. log.Println("Shutting down server...")
  80. ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  81. defer cancel()
  82. if err := srv.Shutdown(ctx); err != nil {
  83. log.Fatal("Server forced to shutdown:", err)
  84. }
  85. log.Println("Server exiting")
  86. }