-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·90 lines (79 loc) · 2.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
//go:generate go-bindata -pkg views -o asset/views/views_gen.go views/...
//go:generate go-bindata-assetfs -pkg static -o asset/static/static_gen.go static/...
import (
"flag"
"html/template"
"net/http"
"strings"
staticinternal "walksmile/asset/static"
"walksmile/asset/views"
"walksmile/conf"
"walksmile/controllers"
"walksmile/helpers/baiduyun"
"walksmile/models"
"github.com/DeanThompson/ginpprof"
"github.com/claudiu/gocron"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
)
func main() {
cfgFile := flag.String("conf", "conf/config.toml", "config file")
flag.Parse()
conf.CfgFile = *cfgFile
conf.InitConfig()
models.InitDB()
controllers.InitDATA()
gocron.Every(1).Day().At("01:00").Do(controllers.FetchHotword)
gocron.Every(1).Hours().Do(controllers.Last24Update)
gocron.Every(3).Minutes().Do(baiduyun.Fetcher)
gocron.Start()
r := gin.Default()
r.SetFuncMap(template.FuncMap{
"isActive": controllers.IsActive,
"stringInSlice": controllers.StringInSlice,
"dateTime": controllers.DateTime,
"pagetofrom": controllers.PageToFrom,
"GoodPageToFrom": controllers.GoodPageToFrom,
"ToTemplate": controllers.ToTemplate,
})
if gin.Mode() == gin.DebugMode {
views.InitTemplate(true, r.FuncMap)
} else {
views.InitTemplate(false, r.FuncMap)
}
r.SetHTMLTemplate(views.Temp)
r.Use(controllers.Domain(), controllers.IsMobile())
r.Use(static.Serve("/static", BinaryFileSystem("static")))
r.Static("/static", "./static")
r.GET("/", controllers.Home)
r.GET("/search", controllers.FileList)
//r.GET("/last24", controllers.Last24hour)
r.GET("/sharedfile/:id", controllers.FileDetail)
r.GET("/wallpaper/:id", controllers.Wallpaper)
r.POST("/comment", controllers.Comment)
ginpprof.Wrapper(r)
r.Run(":8080") // listen and serve on 0.0.0.0:8080
}
type binaryFileSystem struct {
fs http.FileSystem
}
func (b *binaryFileSystem) Open(name string) (http.File, error) {
return b.fs.Open(name)
}
func (b *binaryFileSystem) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
if _, err := b.fs.Open(p); err != nil {
return false
}
return true
}
return false
}
func BinaryFileSystem(root string) *binaryFileSystem {
fs := &assetfs.AssetFS{staticinternal.Asset, staticinternal.AssetDir, staticinternal.AssetInfo, root}
return &binaryFileSystem{
fs,
}
}