first commit
This commit is contained in:
63
internal/router/manage/cache/cache.go
vendored
Normal file
63
internal/router/manage/cache/cache.go
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"management/internal/pkg/redis"
|
||||
"management/internal/router/manage/util"
|
||||
"management/internal/tpl"
|
||||
)
|
||||
|
||||
func List(w http.ResponseWriter, r *http.Request) {
|
||||
tpl.HTML(w, r, "cache/list.tmpl", nil)
|
||||
}
|
||||
|
||||
type Key struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func PostList(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
keyword := strings.TrimSpace(r.PostFormValue("title"))
|
||||
pageID := util.ConvertInt(r.PostFormValue("page"), 1)
|
||||
pageSize := util.ConvertInt(r.PostFormValue("rows"), 10)
|
||||
if len(keyword) == 0 {
|
||||
keyword = "*"
|
||||
} else {
|
||||
keyword = keyword + "*"
|
||||
}
|
||||
|
||||
result, count, err := redis.ListKeys(ctx, keyword, pageID, pageSize)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
sort.Sort(sort.StringSlice(result))
|
||||
|
||||
var res []Key
|
||||
for _, key := range result {
|
||||
res = append(res, Key{
|
||||
Name: key,
|
||||
})
|
||||
}
|
||||
data := tpl.ResponseList{
|
||||
Code: 0,
|
||||
Message: "ok",
|
||||
Count: int64(count),
|
||||
Data: res,
|
||||
}
|
||||
tpl.JSON(w, data)
|
||||
}
|
||||
|
||||
func Refresh(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
name := strings.TrimSpace(r.PostFormValue("name"))
|
||||
err := redis.Del(ctx, name)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
tpl.JSON(w, tpl.Response{Success: true, Message: "刷新成功"})
|
||||
}
|
||||
Reference in New Issue
Block a user