package main import ( "embed" "flag" "gin-article/handler" "html/template" "io/fs" "log" "net/http" "os" "strconv" "sync" "time" "github.com/joho/godotenv" ) //go:embed tmpl/* statics/**/* var f embed.FS func main() { err := godotenv.Load(".env") if err != nil { log.Fatal("Error loading .env file") os.Exit(1) } r := Router() // 静态文件也打包 tmpl, _ := template.ParseFS(f, "tmpl/*") r.SetHTMLTemplate(tmpl) staticsFS, _ := fs.Sub(f, "statics") r.StaticFS("/statics", http.FS(staticsFS)) //r.LoadHTMLGlob("tmpl/*") //r.Static("/statics", "./statics") port := flag.Int("p", 88, "the port to listen on") // 解析命令行参数 flag.Parse() var wg sync.WaitGroup wg.Add(1) go func() { r.Run(":" + strconv.Itoa(*port)) }() wg.Add(1) go func() { for { handler.MakeArticleOrder() time.Sleep(10 * time.Second) } }() wg.Wait() }