广告平台(媒体使用)
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 2.4 KiB

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