-
Notifications
You must be signed in to change notification settings - Fork 6
/
router.go
51 lines (45 loc) · 1.24 KB
/
router.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
package main
import (
"embed"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"html/template"
"net/http"
"note/service"
"note/util"
)
func index(ctx *gin.Context) {
ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
ctx.Header("Pragma", "no-cache")
ctx.Header("Expires", "0")
ctx.Redirect(http.StatusMovedPermanently, ctx.Request.URL.EscapedPath()+util.RandChar(viper.GetInt("note.keylength"))) //url path长度
}
//go:embed static
var FS embed.FS
// NewRoutes 路由
func NewRoutes(r *gin.Engine) *gin.Engine {
tmpl := template.Must(template.New("").ParseFS(FS, "static/*.html"))
class := viper.GetInt("note.type")
if class == 0 {
api := service.NewNoteApi()
r.GET("/", index)
r.POST("/:id", service.ProcessHandleMysql)
r.GET("/:id", service.ProcessHandleMysql)
apiRouter := r.Group("/api")
apiRouter.POST("/create", api.Create)
apiRouter.POST("/update", api.Update)
r.SetHTMLTemplate(tmpl)
return r
}
if class == 1 {
r.GET("/", index)
r.POST("/:id", service.ProcessHandleRedis)
r.GET("/:id", service.ProcessHandleRedis)
apiRouter := r.Group("/api")
apiRouter.POST("/create", service.CreateRedis)
apiRouter.POST("/update", service.UpdateRedis)
r.SetHTMLTemplate(tmpl)
return r
}
return r
}