-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
39 lines (34 loc) · 1.11 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
package main
import (
"flag"
"github.com/axengine/cache"
"github.com/gin-contrib/cache/persistence"
"github.com/gin-gonic/gin"
"log"
"strconv"
"time"
)
func PanicIfError(err error) {
if err != nil {
log.Panicln(err)
}
}
func main() {
cliPath := flag.String("source", "./source", "source 仓库路径")
port := flag.Int("port", 10001, "listening port")
flag.Parse()
BasePath = *cliPath
if *port <= 1 || *port > 65535 {
log.Fatalln("invalid port")
}
PanicIfError(UpdateData())
cacheTime := time.Minute * 5
store := persistence.NewInMemoryStore(time.Minute * 5)
router := gin.Default()
router.GET("/metadata", cache.CachePage(store, cacheTime, APIMetadata))
router.GET("/problem-set-list", cache.CachePage(store, cacheTime, APIProblemSetList))
router.GET("/problem-set/:problemset/metadata", cache.CachePage(store, cacheTime, APIProblemSetMetadata))
router.GET("/problem-list/:problemset/:page", cache.CachePage(store, cacheTime, APIProblemSetPage))
router.GET("/problem/:problemset/:problem", cache.CachePage(store, cacheTime, APIProblem))
PanicIfError(router.Run("0.0.0.0:" + strconv.Itoa(*port)))
}