广告平台(站长使用)
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

main.go 2.4 KiB

1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
2 tygodni temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package main
  2. import (
  3. db "code.fnuoos.com/zhimeng/model.git/src"
  4. "context"
  5. "fmt"
  6. "log"
  7. "net/http"
  8. "os"
  9. "os/signal"
  10. "syscall"
  11. "time"
  12. "applet/app/cfg"
  13. "applet/app/router"
  14. "applet/app/utils"
  15. )
  16. // 系统初始化
  17. func init() {
  18. cfg.InitCfg() //配置初始化
  19. cfg.InitMq() //配置初始化
  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:1002 or xxxx.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 && 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. }