package main import ( "context" "flag" "fmt" "net/http" "os" "os/signal" "path/filepath" "res/dbop" "time" "github.com/gin-gonic/gin" // "github.com/robfig/cron/v3" "github.com/shockliu/logger" ) const uploadhtml = ` upload file

` /* const uploadhtml = `
` */ func Mkdir(basePath string) string { // 1.获取当前时间,并且格式化时间 folderName := time.Now().Format("2006-01/") folderPath := filepath.Join(basePath, folderName) //使用mkdirall会创建多层级目录 os.MkdirAll(folderPath, os.ModePerm) return folderPath } func main() { version := "1.0.0" fmt.Printf("\n\n\n") fmt.Printf(" **************************************************\n") fmt.Printf(" * \033[1;34;42m豆曲咖资源|美团服务\033[0m *\n") fmt.Printf(" * ========================================= *\n") fmt.Printf(" * 版本: %v *\n", version) fmt.Printf(" * 技术支持:\033[1;32;40m豆曲咖莱(杭州)科技有限公司\033[0m *\n") fmt.Printf(" * Email: \033[1;32;40msales@daymele.com\033[0m *\n") fmt.Printf(" **************************************************\n") fmt.Printf("\n\n") port := flag.Int("port", 9000, "端口") conf := flag.String("conf", "/conf/daymele.conf", "配置文件") flag.Parse() logger.Debugf("端口参数%d\n", *port) dbop.DBinit(*conf) gin.SetMode(gin.ReleaseMode) r := gin.Default() gImg := r.Group("images") gMp4 := r.Group("mp4") gApk := r.Group("apk") gQr := r.Group("QrCode") gFile := r.Group("file") gImg.StaticFS("/", http.Dir("/data/images")) gMp4.StaticFS("/", http.Dir("/data/mp4")) gApk.StaticFS("/", http.Dir("/data/apk")) gQr.StaticFS("/", http.Dir("/data/QrCode")) gFile.StaticFS("/", http.Dir("/data/file")) //r.POST("/savefile",file.FileUpload) // r.POST("/savefile", file.FileUpload) // r.POST("/existfile", file.ExistFile) r.GET("/savefile", func(c *gin.Context) { c.Header("Content-Type", "text/html; charset=utf-8") c.String(200, uploadhtml) }) // 增加定时任务,晚上17点锁定馆所用户余额 // c := cron.New() // c.AddFunc("0 17 * * *", func() { // logger.Infof("锁定馆所员工余额\n") // _, err := dbop.MDb.Exec("update dqk_user a,dqk_enterprise_user b set a.activity=JSON_SET(activity, '$.lock',true) where a.mobile=b.mobile and b.enterprise_id='100001' and a.funds>0;") // if err != nil { // logger.Errorf("数据库操作失败%s\n", err) // } // }) // c.Start() // 美团接口 // g := r.Group("/client/trade") // { // g.POST("/queryBudget", meituan.QueryBudget) // g.POST("/queryPayBudget", meituan.QueryPayBudget) // g.POST("/payBudget", meituan.PayBudget) // g.POST("/refundBudget", meituan.RefundBudget) // g.POST("/queryRefundBudget", meituan.QueryRefundBudget) // } // logger.Debugf("7011\n") // r.Run(":7011") // listen and serve on 0.0.0.0:8080 // 使用http启动服务 srv := &http.Server{ Addr: fmt.Sprintf(":%d", *port), Handler: r, } go func() { // 服务连接 fmt.Printf("豆曲咖[资源/美团]服务端口:%d\n", *port) if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { logger.Fatalf("listen: %s\n", err) } }() // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间) quit := make(chan os.Signal) signal.Notify(quit, os.Interrupt) <-quit logger.Info("Shutdown Server ...") ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := srv.Shutdown(ctx); err != nil { logger.Fatal("Server Shutdown:", err) } logger.Info("Server exiting") }