目录调整

This commit is contained in:
xing 2023-01-12 18:17:34 +08:00
parent 8c59a9fdac
commit 9a288a4861
160 changed files with 160 additions and 160 deletions

View File

@ -5,11 +5,11 @@ import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/actions/common"
"github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/config/wpconfig"
"github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/actions/common"
"github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/mail"
"io"

View File

@ -3,9 +3,9 @@ package common
import (
"context"
"github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"strconv"
"time"
)

View File

@ -5,21 +5,21 @@ import (
"fmt"
"github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/config/wpconfig"
wp2 "github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"sync"
"time"
)
var postContextCache *cache.MapCache[uint64, PostContext]
var archivesCaches *Arch
var categoryCaches *cache.SliceCache[wp.TermsMy]
var recentPostsCaches *cache.SliceCache[wp.Posts]
var recentCommentsCaches *cache.SliceCache[wp.Comments]
var categoryCaches *cache.SliceCache[wp2.TermsMy]
var recentPostsCaches *cache.SliceCache[wp2.Posts]
var recentCommentsCaches *cache.SliceCache[wp2.Comments]
var postCommentCaches *cache.MapCache[uint64, []uint64]
var postsCache *cache.MapCache[uint64, wp.Posts]
var postsCache *cache.MapCache[uint64, wp2.Posts]
var postMetaCache *cache.MapCache[uint64, map[string]any]
@ -28,9 +28,9 @@ var postListIdsCache *cache.MapCache[string, PostIds]
var searchPostIdsCache *cache.MapCache[string, PostIds]
var maxPostIdCache *cache.SliceCache[uint64]
var TotalRaw int64
var usersCache *cache.MapCache[uint64, wp.Users]
var usersNameCache *cache.MapCache[string, wp.Users]
var commentsCache *cache.MapCache[uint64, wp.Comments]
var usersCache *cache.MapCache[uint64, wp2.Users]
var usersNameCache *cache.MapCache[string, wp2.Users]
var commentsCache *cache.MapCache[uint64, wp2.Comments]
func InitActionsCommonCache() {
c := config.Conf.Load()
@ -47,25 +47,25 @@ func InitActionsCommonCache() {
postContextCache = cache.NewMapCacheByFn[uint64, PostContext](getPostContext, c.ContextPostCacheTime)
postsCache = cache.NewMapCacheByBatchFn[uint64, wp.Posts](getPostsByIds, c.PostDataCacheTime)
postsCache = cache.NewMapCacheByBatchFn[uint64, wp2.Posts](getPostsByIds, c.PostDataCacheTime)
postMetaCache = cache.NewMapCacheByBatchFn[uint64, map[string]any](getPostMetaByPostIds, c.PostDataCacheTime)
categoryCaches = cache.NewSliceCache[wp.TermsMy](categories, c.CategoryCacheTime)
categoryCaches = cache.NewSliceCache[wp2.TermsMy](categories, c.CategoryCacheTime)
recentPostsCaches = cache.NewSliceCache[wp.Posts](recentPosts, c.RecentPostCacheTime)
recentPostsCaches = cache.NewSliceCache[wp2.Posts](recentPosts, c.RecentPostCacheTime)
recentCommentsCaches = cache.NewSliceCache[wp.Comments](recentComments, c.RecentCommentsCacheTime)
recentCommentsCaches = cache.NewSliceCache[wp2.Comments](recentComments, c.RecentCommentsCacheTime)
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, c.PostCommentsCacheTime)
maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, c.MaxPostIdCacheTime)
usersCache = cache.NewMapCacheByFn[uint64, wp.Users](getUserById, c.UserInfoCacheTime)
usersCache = cache.NewMapCacheByFn[uint64, wp2.Users](getUserById, c.UserInfoCacheTime)
usersNameCache = cache.NewMapCacheByFn[string, wp.Users](getUserByName, c.UserInfoCacheTime)
usersNameCache = cache.NewMapCacheByFn[string, wp2.Users](getUserByName, c.UserInfoCacheTime)
commentsCache = cache.NewMapCacheByBatchFn[uint64, wp.Comments](getCommentByIds, c.CommentsCacheTime)
commentsCache = cache.NewMapCacheByBatchFn[uint64, wp2.Comments](getCommentByIds, c.CommentsCacheTime)
}
func ClearCache() {
@ -97,13 +97,13 @@ type PostIds struct {
}
type Arch struct {
data []wp.PostArchive
data []wp2.PostArchive
mutex *sync.Mutex
setCacheFunc func(context.Context) ([]wp.PostArchive, error)
setCacheFunc func(context.Context) ([]wp2.PostArchive, error)
month time.Month
}
func (c *Arch) getArchiveCache(ctx context.Context) []wp.PostArchive {
func (c *Arch) getArchiveCache(ctx context.Context) []wp2.PostArchive {
l := len(c.data)
m := time.Now().Month()
if l > 0 && c.month != m || l < 1 {
@ -121,30 +121,30 @@ func (c *Arch) getArchiveCache(ctx context.Context) []wp.PostArchive {
}
type PostContext struct {
prev wp.Posts
next wp.Posts
prev wp2.Posts
next wp2.Posts
}
func archives(ctx context.Context) ([]wp.PostArchive, error) {
return models.Find[wp.PostArchive](ctx, models.SqlBuilder{
func archives(ctx context.Context) ([]wp2.PostArchive, error) {
return models.Find[wp2.PostArchive](ctx, models.SqlBuilder{
{"post_type", "post"}, {"post_status", "publish"},
}, "YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts", "year,month", models.SqlBuilder{{"year", "desc"}, {"month", "desc"}}, nil, nil, 0)
}
func Archives(ctx context.Context) (r []wp.PostArchive) {
func Archives(ctx context.Context) (r []wp2.PostArchive) {
return archivesCaches.getArchiveCache(ctx)
}
func Categories(ctx context.Context) []wp.TermsMy {
func Categories(ctx context.Context) []wp2.TermsMy {
r, err := categoryCaches.GetCache(ctx, time.Second, ctx)
logs.ErrPrintln(err, "get category ")
return r
}
func categories(a ...any) (terms []wp.TermsMy, err error) {
func categories(a ...any) (terms []wp2.TermsMy, err error) {
ctx := a[0].(context.Context)
var in = []any{"category"}
terms, err = models.Find[wp.TermsMy](ctx, models.SqlBuilder{
terms, err = models.Find[wp2.TermsMy](ctx, models.SqlBuilder{
{"tt.count", ">", "0", "int"},
{"tt.taxonomy", "in", ""},
}, "t.term_id", "", models.SqlBuilder{
@ -163,13 +163,13 @@ func categories(a ...any) (terms []wp.TermsMy, err error) {
return
}
func PasswordProjectTitle(post *wp.Posts) {
func PasswordProjectTitle(post *wp2.Posts) {
if post.PostPassword != "" {
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
}
}
func PasswdProjectContent(post *wp.Posts) {
func PasswdProjectContent(post *wp2.Posts) {
if post.PostContent != "" {
format := `
<form action="/login" class="post-password-form" method="post">

View File

@ -4,9 +4,9 @@ import (
"context"
"github.com/leeqvip/gophp"
"github/fthvgb1/wp-go/helper"
wp2 "github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"strconv"
"time"
)
@ -20,7 +20,7 @@ func GetPostMetaByPostId(ctx context.Context, id uint64) (r map[string]any, err
return
}
func ToPostThumbnail(c context.Context, postId uint64) (r wp.PostThumbnail) {
func ToPostThumbnail(c context.Context, postId uint64) (r wp2.PostThumbnail) {
meta, err := GetPostMetaByPostId(c, postId)
if err == nil {
m, ok := meta["_thumbnail_id"]
@ -64,7 +64,7 @@ func getPostMetaByPostIds(args ...any) (r map[uint64]map[string]any, err error)
r = make(map[uint64]map[string]any)
ctx := args[0].(context.Context)
ids := args[1].([]uint64)
rr, err := models.Find[wp.Postmeta](ctx, models.SqlBuilder{
rr, err := models.Find[wp2.Postmeta](ctx, models.SqlBuilder{
{"post_id", "in", ""},
}, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64]))
if err != nil {

View File

@ -6,9 +6,9 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"strings"
"sync/atomic"
"time"

View File

@ -2,9 +2,9 @@ package common
import (
"context"
"github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"time"
)

View File

@ -4,11 +4,11 @@ import (
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/actions/common"
"github/fthvgb1/wp-go/config/wpconfig"
"github/fthvgb1/wp-go/helper"
common2 "github/fthvgb1/wp-go/internal/actions/common"
"github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/plugins"
"math/rand"
"net/http"
@ -28,10 +28,10 @@ func Detail(c *gin.Context) {
hh := detailHandler{
c,
}
recent := common.RecentPosts(c, 5)
archive := common.Archives(c)
categoryItems := common.Categories(c)
recentComments := common.RecentComments(c, 5)
recent := common2.RecentPosts(c, 5)
archive := common2.Archives(c)
categoryItems := common2.Categories(c)
recentComments := common2.RecentComments(c, 5)
var h = gin.H{
"title": wpconfig.Options.Value("blogname"),
"options": wpconfig.Options,
@ -62,12 +62,12 @@ func Detail(c *gin.Context) {
}
}
ID := uint64(Id)
maxId, err := common.GetMaxPostId(c)
maxId, err := common2.GetMaxPostId(c)
logs.ErrPrintln(err, "get max post id")
if ID > maxId || err != nil {
return
}
post, err := common.GetPostById(c, ID)
post, err := common2.GetPostById(c, ID)
if post.Id == 0 || err != nil {
return
}
@ -76,10 +76,10 @@ func Detail(c *gin.Context) {
if post.CommentCount > 0 || post.CommentStatus == "open" {
showComment = true
}
user := common.GetUserById(c, post.PostAuthor)
common.PasswordProjectTitle(&post)
user := common2.GetUserById(c, post.PostAuthor)
common2.PasswordProjectTitle(&post)
if post.PostPassword != "" && pw != post.PostPassword {
common.PasswdProjectContent(&post)
common2.PasswdProjectContent(&post)
showComment = false
} else if s, ok := commentCache.Get(c.Request.URL.RawQuery); ok && s != "" && (post.PostPassword == "" || post.PostPassword != "" && pw == post.PostPassword) {
c.Writer.WriteHeader(http.StatusOK)
@ -89,10 +89,10 @@ func Detail(c *gin.Context) {
return
}
plugins.ApplyPlugin(plugins.NewPostPlugin(c, plugins.Detail), &post)
comments, err := common.PostComments(c, post.Id)
comments, err := common2.PostComments(c, post.Id)
logs.ErrPrintln(err, "get post comment", post.Id)
commentss := treeComments(comments)
prev, next, err := common.GetContextPost(c, post.Id, post.PostDate)
prev, next, err := common2.GetContextPost(c, post.Id, post.PostDate)
logs.ErrPrintln(err, "get pre and next post", post.Id, post.PostDate)
h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wpconfig.Options.Value("blogname"))
h["post"] = post

View File

@ -3,12 +3,12 @@ package actions
import (
"fmt"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/actions/common"
"github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/config/wpconfig"
"github/fthvgb1/wp-go/helper"
common2 "github/fthvgb1/wp-go/internal/actions/common"
wp2 "github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/plugins"
"github/fthvgb1/wp-go/rss2"
"net/http"
@ -77,21 +77,21 @@ func Feed(c *gin.Context) {
func feed(arg ...any) (xml []string, err error) {
c := arg[0].(*gin.Context)
r := common.RecentPosts(c, 10)
ids := helper.SliceMap(r, func(t wp.Posts) uint64 {
r := common2.RecentPosts(c, 10)
ids := helper.SliceMap(r, func(t wp2.Posts) uint64 {
return t.Id
})
posts, err := common.GetPostsByIds(c, ids)
posts, err := common2.GetPostsByIds(c, ids)
if err != nil {
return
}
rs := templateRss
rs.LastBuildDate = time.Now().Format(timeFormat)
rs.Items = helper.SliceMap(posts, func(t wp.Posts) rss2.Item {
rs.Items = helper.SliceMap(posts, func(t wp2.Posts) rss2.Item {
desc := "无法提供摘要。这是一篇受保护的文章。"
common.PasswordProjectTitle(&t)
common2.PasswordProjectTitle(&t)
if t.PostPassword != "" {
common.PasswdProjectContent(&t)
common2.PasswdProjectContent(&t)
} else {
desc = plugins.DigestRaw(t.PostContent, 55, fmt.Sprintf("/p/%d", t.Id))
}
@ -101,7 +101,7 @@ func feed(arg ...any) (xml []string, err error) {
} else if t.CommentStatus == "open" && t.CommentCount == 0 {
l = fmt.Sprintf("%s/p/%d#respond", wpconfig.Options.Value("siteurl"), t.Id)
}
user := common.GetUserById(c, t.PostAuthor)
user := common2.GetUserById(c, t.PostAuthor)
return rss2.Item{
Title: t.PostTitle,
@ -157,17 +157,17 @@ func postFeed(arg ...any) (x string, err error) {
}
}
ID := uint64(Id)
maxId, err := common.GetMaxPostId(c)
maxId, err := common2.GetMaxPostId(c)
logs.ErrPrintln(err, "get max post id")
if ID > maxId || err != nil {
return
}
post, err := common.GetPostById(c, ID)
post, err := common2.GetPostById(c, ID)
if post.Id == 0 || err != nil {
return
}
common.PasswordProjectTitle(&post)
comments, err := common.PostComments(c, post.Id)
common2.PasswordProjectTitle(&post)
comments, err := common2.PostComments(c, post.Id)
if err != nil {
return
}
@ -179,7 +179,7 @@ func postFeed(arg ...any) (x string, err error) {
rs.LastBuildDate = time.Now().Format(timeFormat)
if post.PostPassword != "" {
if len(comments) > 0 {
common.PasswdProjectContent(&post)
common2.PasswdProjectContent(&post)
t := comments[len(comments)-1]
rs.Items = []rss2.Item{
{
@ -194,7 +194,7 @@ func postFeed(arg ...any) (x string, err error) {
}
}
} else {
rs.Items = helper.SliceMap(comments, func(t wp.Comments) rss2.Item {
rs.Items = helper.SliceMap(comments, func(t wp2.Comments) rss2.Item {
return rss2.Item{
Title: fmt.Sprintf("评价者:%s", t.CommentAuthor),
Link: fmt.Sprintf("%s/p/%d#comment-%d", wpconfig.Options.Value("siteurl"), post.Id, t.CommentId),
@ -227,24 +227,24 @@ func CommentsFeed(c *gin.Context) {
func commentsFeed(args ...any) (r []string, err error) {
c := args[0].(*gin.Context)
commens := common.RecentComments(c, 10)
commens := common2.RecentComments(c, 10)
rs := templateRss
rs.Title = fmt.Sprintf("\"%s\"的评论", wpconfig.Options.Value("blogname"))
rs.LastBuildDate = time.Now().Format(timeFormat)
rs.AtomLink = fmt.Sprintf("%s/comments/feed", wpconfig.Options.Value("siteurl"))
com, err := common.GetCommentByIds(c, helper.SliceMap(commens, func(t wp.Comments) uint64 {
com, err := common2.GetCommentByIds(c, helper.SliceMap(commens, func(t wp2.Comments) uint64 {
return t.CommentId
}))
if nil != err {
return []string{}, err
}
rs.Items = helper.SliceMap(com, func(t wp.Comments) rss2.Item {
post, _ := common.GetPostById(c, t.CommentPostId)
common.PasswordProjectTitle(&post)
rs.Items = helper.SliceMap(com, func(t wp2.Comments) rss2.Item {
post, _ := common2.GetPostById(c, t.CommentPostId)
common2.PasswordProjectTitle(&post)
desc := "评论受保护:要查看请输入密码。"
content := t.CommentContent
if post.PostPassword != "" {
common.PasswdProjectContent(&post)
common2.PasswdProjectContent(&post)
content = post.PostContent
} else {
desc = plugins.ClearHtml(t.CommentContent)

View File

@ -4,11 +4,11 @@ import (
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/actions/common"
"github/fthvgb1/wp-go/config/wpconfig"
"github/fthvgb1/wp-go/helper"
common2 "github/fthvgb1/wp-go/internal/actions/common"
"github/fthvgb1/wp-go/internal/wp"
"github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/models"
"github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/plugins"
"math"
"net/http"
@ -113,7 +113,7 @@ func (h *indexHandle) parseParams() (err error) {
h.category = category
username := h.c.Param("author")
if username != "" {
user, er := common.GetUserByName(h.c, username)
user, er := common2.GetUserByName(h.c, username)
if er != nil {
err = er
return
@ -160,7 +160,7 @@ func (h *indexHandle) parseParams() (err error) {
h.page = pa
}
}
total := int(atomic.LoadInt64(&common.TotalRaw))
total := int(atomic.LoadInt64(&common2.TotalRaw))
if total > 0 && total < (h.page-1)*h.pageSize {
h.page = 1
}
@ -180,10 +180,10 @@ func Index(c *gin.Context) {
var postIds []wp.Posts
var totalRaw int
var err error
archive := common.Archives(c)
recent := common.RecentPosts(c, 5)
categoryItems := common.Categories(c)
recentComments := common.RecentComments(c, 5)
archive := common2.Archives(c)
recent := common2.RecentPosts(c, 5)
categoryItems := common2.Categories(c)
recentComments := common2.RecentComments(c, 5)
ginH := gin.H{
"options": wpconfig.Options,
"recentPosts": recent,
@ -208,14 +208,14 @@ func Index(c *gin.Context) {
}
ginH["title"] = h.getTitle()
if c.Param("month") != "" {
postIds, totalRaw, err = common.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order)
postIds, totalRaw, err = common2.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order)
if err != nil {
return
}
} else if h.search != "" {
postIds, totalRaw, err = common.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
postIds, totalRaw, err = common2.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
} else {
postIds, totalRaw, err = common.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
postIds, totalRaw, err = common2.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
}
if err != nil {
return
@ -227,16 +227,16 @@ func Index(c *gin.Context) {
pw := h.session.Get("post_password")
plug := plugins.NewPostPlugin(c, h.scene)
for i, post := range postIds {
common.PasswordProjectTitle(&postIds[i])
common2.PasswordProjectTitle(&postIds[i])
if post.PostPassword != "" && pw != post.PostPassword {
common.PasswdProjectContent(&postIds[i])
common2.PasswdProjectContent(&postIds[i])
} else {
plugins.ApplyPlugin(plug, &postIds[i])
}
}
for i, post := range recent {
if post.PostPassword != "" && pw != post.PostPassword {
common.PasswdProjectContent(&recent[i])
common2.PasswdProjectContent(&recent[i])
}
}
q := c.Request.URL.Query().Encode()

View File

@ -4,8 +4,8 @@ import (
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/config/wpconfig"
"github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/phpass"
"net/http"
"strings"

View File

@ -5,7 +5,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/config/wpconfig"
"github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/mail"
"io"

View File

@ -6,12 +6,12 @@ import (
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/actions"
"github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/config/wpconfig"
"github/fthvgb1/wp-go/middleware"
"github/fthvgb1/wp-go/static"
"github/fthvgb1/wp-go/templates"
actions2 "github/fthvgb1/wp-go/internal/actions"
middleware2 "github/fthvgb1/wp-go/internal/middleware"
"github/fthvgb1/wp-go/internal/static"
"github/fthvgb1/wp-go/internal/templates"
"github/fthvgb1/wp-go/internal/wpconfig"
"html/template"
"net/http"
"time"
@ -40,14 +40,14 @@ func SetupRouter() (*gin.Engine, func()) {
return wpconfig.Options.Value(k)
},
}).SetTemplate()
validServerName, reloadValidServerNameFn := middleware.ValidateServerNames()
fl, flReload := middleware.FlowLimit(c.MaxRequestSleepNum, c.MaxRequestNum, c.SleepTime)
validServerName, reloadValidServerNameFn := middleware2.ValidateServerNames()
fl, flReload := middleware2.FlowLimit(c.MaxRequestSleepNum, c.MaxRequestNum, c.SleepTime)
r.Use(
gin.Logger(),
validServerName,
middleware.RecoverAndSendMail(gin.DefaultErrorWriter),
middleware2.RecoverAndSendMail(gin.DefaultErrorWriter),
fl,
middleware.SetStaticFileCache,
middleware2.SetStaticFileCache,
)
//gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用
if c.Gzip {
@ -65,24 +65,24 @@ func SetupRouter() (*gin.Engine, func()) {
}))
store := cookie.NewStore([]byte("secret"))
r.Use(sessions.Sessions("go-wp", store))
sl, slRload := middleware.SearchLimit(c.SingleIpSearchNum)
r.GET("/", sl, actions.Index)
r.GET("/page/:page", actions.Index)
r.GET("/p/category/:category", actions.Index)
r.GET("/p/category/:category/page/:page", actions.Index)
r.GET("/p/tag/:tag", actions.Index)
r.GET("/p/tag/:tag/page/:page", actions.Index)
r.GET("/p/date/:year/:month", actions.Index)
r.GET("/p/date/:year/:month/page/:page", actions.Index)
r.GET("/p/author/:author", actions.Index)
r.GET("/p/author/:author/page/:page", actions.Index)
r.POST("/login", actions.Login)
r.GET("/p/:id", actions.Detail)
r.GET("/p/:id/feed", actions.PostFeed)
r.GET("/feed", actions.Feed)
r.GET("/comments/feed", actions.CommentsFeed)
cfl, _ := middleware.FlowLimit(c.MaxRequestSleepNum, 5, c.SleepTime)
r.POST("/comment", cfl, actions.PostComment)
sl, slRload := middleware2.SearchLimit(c.SingleIpSearchNum)
r.GET("/", sl, actions2.Index)
r.GET("/page/:page", actions2.Index)
r.GET("/p/category/:category", actions2.Index)
r.GET("/p/category/:category/page/:page", actions2.Index)
r.GET("/p/tag/:tag", actions2.Index)
r.GET("/p/tag/:tag/page/:page", actions2.Index)
r.GET("/p/date/:year/:month", actions2.Index)
r.GET("/p/date/:year/:month/page/:page", actions2.Index)
r.GET("/p/author/:author", actions2.Index)
r.GET("/p/author/:author/page/:page", actions2.Index)
r.POST("/login", actions2.Login)
r.GET("/p/:id", actions2.Detail)
r.GET("/p/:id/feed", actions2.PostFeed)
r.GET("/feed", actions2.Feed)
r.GET("/comments/feed", actions2.CommentsFeed)
cfl, _ := middleware2.FlowLimit(c.MaxRequestSleepNum, 5, c.SleepTime)
r.POST("/comment", cfl, actions2.PostComment)
if gin.Mode() != gin.ReleaseMode {
pprof.Register(r, "dev/pprof")
}

View File

Before

Width:  |  Height:  |  Size: 7.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

Before

Width:  |  Height:  |  Size: 322 KiB

After

Width:  |  Height:  |  Size: 322 KiB

View File

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 256 KiB

View File

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 134 KiB

View File

Before

Width:  |  Height:  |  Size: 77 KiB

After

Width:  |  Height:  |  Size: 77 KiB

View File

@ -27,7 +27,7 @@
@media screen and (-webkit-min-device-pixel-ratio:0) {
@font-face {
font-family: "Genericons";
src: url("./Genericons.svg#Genericons") format("svg");
src: url("Genericons.svg#Genericons") format("svg");
}
}

Some files were not shown because too many files have changed in this diff Show More