目录调整
This commit is contained in:
parent
4f58d86a59
commit
fc5e71d79d
|
@ -9,7 +9,7 @@ import (
|
|||
"github/fthvgb1/wp-go/config"
|
||||
"github/fthvgb1/wp-go/logs"
|
||||
"github/fthvgb1/wp-go/mail"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/cookiejar"
|
||||
|
@ -68,7 +68,7 @@ func PostComment(c *gin.Context) {
|
|||
logs.ErrPrintln(err, "获取文档", id)
|
||||
return
|
||||
}
|
||||
su := fmt.Sprintf("%s: %s[%s]发表了评论对文档[%v]的评论", models.Options["siteurl"], author, m, post.PostTitle)
|
||||
su := fmt.Sprintf("%s: %s[%s]发表了评论对文档[%v]的评论", wp.Options["siteurl"], author, m, post.PostTitle)
|
||||
err = mail.SendMail([]string{config.Conf.Mail.User}, su, comment)
|
||||
logs.ErrPrintln(err, "发送邮件")
|
||||
}()
|
||||
|
|
|
@ -5,11 +5,12 @@ import (
|
|||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/logs"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func RecentComments(ctx context.Context, n int) (r []models.WpComments) {
|
||||
func RecentComments(ctx context.Context, n int) (r []wp.WpComments) {
|
||||
r, err := recentCommentsCaches.GetCache(ctx, time.Second)
|
||||
if len(r) > n {
|
||||
r = r[0:n]
|
||||
|
@ -17,8 +18,8 @@ func RecentComments(ctx context.Context, n int) (r []models.WpComments) {
|
|||
logs.ErrPrintln(err, "get recent comment")
|
||||
return
|
||||
}
|
||||
func recentComments(...any) (r []models.WpComments, err error) {
|
||||
return models.Find[models.WpComments](models.SqlBuilder{
|
||||
func recentComments(...any) (r []wp.WpComments, err error) {
|
||||
return models.Find[wp.WpComments](models.SqlBuilder{
|
||||
{"comment_approved", "1"},
|
||||
{"post_status", "publish"},
|
||||
}, "comment_ID,comment_author,comment_post_ID,post_title", "", models.SqlBuilder{{"comment_date_gmt", "desc"}}, models.SqlBuilder{
|
||||
|
@ -26,7 +27,7 @@ func recentComments(...any) (r []models.WpComments, err error) {
|
|||
}, nil, 10)
|
||||
}
|
||||
|
||||
func PostComments(ctx context.Context, Id uint64) ([]models.WpComments, error) {
|
||||
func PostComments(ctx context.Context, Id uint64) ([]wp.WpComments, error) {
|
||||
ids, err := postCommentCaches.GetCache(ctx, Id, time.Second, Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -36,7 +37,7 @@ func PostComments(ctx context.Context, Id uint64) ([]models.WpComments, error) {
|
|||
|
||||
func postComments(args ...any) ([]uint64, error) {
|
||||
postId := args[0].(uint64)
|
||||
r, err := models.Find[models.WpComments](models.SqlBuilder{
|
||||
r, err := models.Find[wp.WpComments](models.SqlBuilder{
|
||||
{"comment_approved", "1"},
|
||||
{"comment_post_ID", "=", strconv.FormatUint(postId, 10), "int"},
|
||||
}, "comment_ID", "", models.SqlBuilder{
|
||||
|
@ -46,29 +47,29 @@ func postComments(args ...any) ([]uint64, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return helper.SliceMap(r, func(t models.WpComments) uint64 {
|
||||
return helper.SliceMap(r, func(t wp.WpComments) uint64 {
|
||||
return t.CommentId
|
||||
}), err
|
||||
}
|
||||
|
||||
func GetCommentById(ctx context.Context, id uint64) (models.WpComments, error) {
|
||||
func GetCommentById(ctx context.Context, id uint64) (wp.WpComments, error) {
|
||||
return commentsCache.GetCache(ctx, id, time.Second, id)
|
||||
}
|
||||
|
||||
func GetCommentByIds(ctx context.Context, ids []uint64) ([]models.WpComments, error) {
|
||||
func GetCommentByIds(ctx context.Context, ids []uint64) ([]wp.WpComments, error) {
|
||||
return commentsCache.GetCacheBatch(ctx, ids, time.Second, ids)
|
||||
}
|
||||
|
||||
func getCommentByIds(args ...any) (map[uint64]models.WpComments, error) {
|
||||
func getCommentByIds(args ...any) (map[uint64]wp.WpComments, error) {
|
||||
ids := args[0].([]uint64)
|
||||
m := make(map[uint64]models.WpComments)
|
||||
r, err := models.SimpleFind[models.WpComments](models.SqlBuilder{
|
||||
m := make(map[uint64]wp.WpComments)
|
||||
r, err := models.SimpleFind[wp.WpComments](models.SqlBuilder{
|
||||
{"comment_ID", "in", ""}, {"comment_approved", "1"},
|
||||
}, "*", helper.SliceMap(ids, helper.ToAny[uint64]))
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
return helper.SimpleSliceToMap(r, func(t models.WpComments) uint64 {
|
||||
return helper.SimpleSliceToMap(r, func(t wp.WpComments) uint64 {
|
||||
return t.CommentId
|
||||
}), err
|
||||
}
|
||||
|
|
|
@ -7,24 +7,25 @@ import (
|
|||
"github/fthvgb1/wp-go/config"
|
||||
"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[models.WpTermsMy]
|
||||
var recentPostsCaches *cache.SliceCache[models.WpPosts]
|
||||
var recentCommentsCaches *cache.SliceCache[models.WpComments]
|
||||
var categoryCaches *cache.SliceCache[wp.WpTermsMy]
|
||||
var recentPostsCaches *cache.SliceCache[wp.WpPosts]
|
||||
var recentCommentsCaches *cache.SliceCache[wp.WpComments]
|
||||
var postCommentCaches *cache.MapCache[uint64, []uint64]
|
||||
var postsCache *cache.MapCache[uint64, models.WpPosts]
|
||||
var postsCache *cache.MapCache[uint64, wp.WpPosts]
|
||||
var monthPostsCache *cache.MapCache[string, []uint64]
|
||||
var postListIdsCache *cache.MapCache[string, PostIds]
|
||||
var searchPostIdsCache *cache.MapCache[string, PostIds]
|
||||
var maxPostIdCache *cache.SliceCache[uint64]
|
||||
var TotalRaw int
|
||||
var usersCache *cache.MapCache[uint64, models.WpUsers]
|
||||
var commentsCache *cache.MapCache[uint64, models.WpComments]
|
||||
var usersCache *cache.MapCache[uint64, wp.WpUsers]
|
||||
var commentsCache *cache.MapCache[uint64, wp.WpComments]
|
||||
|
||||
func InitActionsCommonCache() {
|
||||
archivesCaches = &Arch{
|
||||
|
@ -40,21 +41,21 @@ func InitActionsCommonCache() {
|
|||
|
||||
postContextCache = cache.NewMapCacheByFn[uint64, PostContext](getPostContext, config.Conf.ContextPostCacheTime)
|
||||
|
||||
postsCache = cache.NewMapCacheByBatchFn[uint64, models.WpPosts](getPostsByIds, config.Conf.PostDataCacheTime)
|
||||
postsCache = cache.NewMapCacheByBatchFn[uint64, wp.WpPosts](getPostsByIds, config.Conf.PostDataCacheTime)
|
||||
|
||||
categoryCaches = cache.NewSliceCache[models.WpTermsMy](categories, config.Conf.CategoryCacheTime)
|
||||
categoryCaches = cache.NewSliceCache[wp.WpTermsMy](categories, config.Conf.CategoryCacheTime)
|
||||
|
||||
recentPostsCaches = cache.NewSliceCache[models.WpPosts](recentPosts, config.Conf.RecentPostCacheTime)
|
||||
recentPostsCaches = cache.NewSliceCache[wp.WpPosts](recentPosts, config.Conf.RecentPostCacheTime)
|
||||
|
||||
recentCommentsCaches = cache.NewSliceCache[models.WpComments](recentComments, config.Conf.RecentCommentsCacheTime)
|
||||
recentCommentsCaches = cache.NewSliceCache[wp.WpComments](recentComments, config.Conf.RecentCommentsCacheTime)
|
||||
|
||||
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, config.Conf.PostCommentsCacheTime)
|
||||
|
||||
maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, config.Conf.MaxPostIdCacheTime)
|
||||
|
||||
usersCache = cache.NewMapCacheByBatchFn[uint64, models.WpUsers](getUsers, config.Conf.UserInfoCacheTime)
|
||||
usersCache = cache.NewMapCacheByBatchFn[uint64, wp.WpUsers](getUsers, config.Conf.UserInfoCacheTime)
|
||||
|
||||
commentsCache = cache.NewMapCacheByBatchFn[uint64, models.WpComments](getCommentByIds, config.Conf.CommentsCacheTime)
|
||||
commentsCache = cache.NewMapCacheByBatchFn[uint64, wp.WpComments](getCommentByIds, config.Conf.CommentsCacheTime)
|
||||
}
|
||||
|
||||
func ClearCache() {
|
||||
|
@ -74,13 +75,13 @@ type PostIds struct {
|
|||
}
|
||||
|
||||
type Arch struct {
|
||||
data []models.PostArchive
|
||||
data []wp.PostArchive
|
||||
mutex *sync.Mutex
|
||||
setCacheFunc func() ([]models.PostArchive, error)
|
||||
setCacheFunc func() ([]wp.PostArchive, error)
|
||||
month time.Month
|
||||
}
|
||||
|
||||
func (c *Arch) getArchiveCache() []models.PostArchive {
|
||||
func (c *Arch) getArchiveCache() []wp.PostArchive {
|
||||
l := len(c.data)
|
||||
m := time.Now().Month()
|
||||
if l > 0 && c.month != m || l < 1 {
|
||||
|
@ -98,29 +99,29 @@ func (c *Arch) getArchiveCache() []models.PostArchive {
|
|||
}
|
||||
|
||||
type PostContext struct {
|
||||
prev models.WpPosts
|
||||
next models.WpPosts
|
||||
prev wp.WpPosts
|
||||
next wp.WpPosts
|
||||
}
|
||||
|
||||
func archives() ([]models.PostArchive, error) {
|
||||
return models.Find[models.PostArchive](models.SqlBuilder{
|
||||
func archives() ([]wp.PostArchive, error) {
|
||||
return models.Find[wp.PostArchive](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() (r []models.PostArchive) {
|
||||
func Archives() (r []wp.PostArchive) {
|
||||
return archivesCaches.getArchiveCache()
|
||||
}
|
||||
|
||||
func Categories(ctx context.Context) []models.WpTermsMy {
|
||||
func Categories(ctx context.Context) []wp.WpTermsMy {
|
||||
r, err := categoryCaches.GetCache(ctx, time.Second)
|
||||
logs.ErrPrintln(err, "get category ")
|
||||
return r
|
||||
}
|
||||
|
||||
func categories(...any) (terms []models.WpTermsMy, err error) {
|
||||
func categories(...any) (terms []wp.WpTermsMy, err error) {
|
||||
var in = []any{"category"}
|
||||
terms, err = models.Find[models.WpTermsMy](models.SqlBuilder{
|
||||
terms, err = models.Find[wp.WpTermsMy](models.SqlBuilder{
|
||||
{"tt.count", ">", "0", "int"},
|
||||
{"tt.taxonomy", "in", ""},
|
||||
}, "t.term_id", "", models.SqlBuilder{
|
||||
|
@ -129,23 +130,23 @@ func categories(...any) (terms []models.WpTermsMy, err error) {
|
|||
{"t", "inner join", "wp_term_taxonomy tt", "t.term_id = tt.term_id"},
|
||||
}, nil, 0, in)
|
||||
for i := 0; i < len(terms); i++ {
|
||||
if v, ok := models.Terms[terms[i].WpTerms.TermId]; ok {
|
||||
if v, ok := wp.Terms[terms[i].WpTerms.TermId]; ok {
|
||||
terms[i].WpTerms = v
|
||||
}
|
||||
if v, ok := models.TermTaxonomy[terms[i].WpTerms.TermId]; ok {
|
||||
if v, ok := wp.TermTaxonomy[terms[i].WpTerms.TermId]; ok {
|
||||
terms[i].WpTermTaxonomy = v
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func PasswordProjectTitle(post *models.WpPosts) {
|
||||
func PasswordProjectTitle(post *wp.WpPosts) {
|
||||
if post.PostPassword != "" {
|
||||
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
|
||||
}
|
||||
}
|
||||
|
||||
func PasswdProjectContent(post *models.WpPosts) {
|
||||
func PasswdProjectContent(post *wp.WpPosts) {
|
||||
if post.PostContent != "" {
|
||||
format := `
|
||||
<form action="/login" class="post-password-form" method="post">
|
||||
|
|
|
@ -8,19 +8,20 @@ import (
|
|||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/logs"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetPostById(ctx context.Context, id uint64) (models.WpPosts, error) {
|
||||
func GetPostById(ctx context.Context, id uint64) (wp.WpPosts, error) {
|
||||
return postsCache.GetCache(ctx, id, time.Second, id)
|
||||
}
|
||||
|
||||
func GetPostsByIds(ctx context.Context, ids []uint64) ([]models.WpPosts, error) {
|
||||
func GetPostsByIds(ctx context.Context, ids []uint64) ([]wp.WpPosts, error) {
|
||||
return postsCache.GetCacheBatch(ctx, ids, time.Second, ids)
|
||||
}
|
||||
|
||||
func SearchPost(ctx context.Context, key string, args ...any) (r []models.WpPosts, total int, err error) {
|
||||
func SearchPost(ctx context.Context, key string, args ...any) (r []wp.WpPosts, total int, err error) {
|
||||
ids, err := searchPostIdsCache.GetCache(ctx, key, time.Second, args...)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -30,11 +31,11 @@ func SearchPost(ctx context.Context, key string, args ...any) (r []models.WpPost
|
|||
return
|
||||
}
|
||||
|
||||
func getPostsByIds(ids ...any) (m map[uint64]models.WpPosts, err error) {
|
||||
m = make(map[uint64]models.WpPosts)
|
||||
func getPostsByIds(ids ...any) (m map[uint64]wp.WpPosts, err error) {
|
||||
m = make(map[uint64]wp.WpPosts)
|
||||
id := ids[0].([]uint64)
|
||||
arg := helper.SliceMap(id, helper.ToAny[uint64])
|
||||
rawPosts, err := models.Find[models.WpPosts](models.SqlBuilder{{
|
||||
rawPosts, err := models.Find[wp.WpPosts](models.SqlBuilder{{
|
||||
"Id", "in", "",
|
||||
}}, "a.*,ifnull(d.name,'') category_name,ifnull(taxonomy,'') `taxonomy`", "", nil, models.SqlBuilder{{
|
||||
"a", "left join", "wp_term_relationships b", "a.Id=b.object_id",
|
||||
|
@ -46,7 +47,7 @@ func getPostsByIds(ids ...any) (m map[uint64]models.WpPosts, err error) {
|
|||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
postsMap := make(map[uint64]models.WpPosts)
|
||||
postsMap := make(map[uint64]wp.WpPosts)
|
||||
for i, post := range rawPosts {
|
||||
v, ok := postsMap[post.Id]
|
||||
if !ok {
|
||||
|
@ -79,7 +80,7 @@ func getPostsByIds(ids ...any) (m map[uint64]models.WpPosts, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func PostLists(ctx context.Context, key string, args ...any) (r []models.WpPosts, total int, err error) {
|
||||
func PostLists(ctx context.Context, key string, args ...any) (r []wp.WpPosts, total int, err error) {
|
||||
ids, err := postListIdsCache.GetCache(ctx, key, time.Second, args...)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -97,7 +98,7 @@ func searchPostIds(args ...any) (ids PostIds, err error) {
|
|||
join := args[4].(models.SqlBuilder)
|
||||
postType := args[5].([]any)
|
||||
postStatus := args[6].([]any)
|
||||
res, total, err := models.SimplePagination[models.WpPosts](where, "ID", "", page, limit, order, join, nil, postType, postStatus)
|
||||
res, total, err := models.SimplePagination[wp.WpPosts](where, "ID", "", page, limit, order, join, nil, postType, postStatus)
|
||||
for _, posts := range res {
|
||||
ids.Ids = append(ids.Ids, posts.Id)
|
||||
}
|
||||
|
@ -109,7 +110,7 @@ func searchPostIds(args ...any) (ids PostIds, err error) {
|
|||
}
|
||||
|
||||
func getMaxPostId(...any) ([]uint64, error) {
|
||||
r, err := models.SimpleFind[models.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID")
|
||||
r, err := models.SimpleFind[wp.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID")
|
||||
var id uint64
|
||||
if len(r) > 0 {
|
||||
id = r[0].Id
|
||||
|
@ -122,7 +123,7 @@ func GetMaxPostId(ctx *gin.Context) (uint64, error) {
|
|||
return Id[0], err
|
||||
}
|
||||
|
||||
func RecentPosts(ctx context.Context, n int) (r []models.WpPosts) {
|
||||
func RecentPosts(ctx context.Context, n int) (r []wp.WpPosts) {
|
||||
r, err := recentPostsCaches.GetCache(ctx, time.Second)
|
||||
if n < len(r) {
|
||||
r = r[:n]
|
||||
|
@ -130,8 +131,8 @@ func RecentPosts(ctx context.Context, n int) (r []models.WpPosts) {
|
|||
logs.ErrPrintln(err, "get recent post")
|
||||
return
|
||||
}
|
||||
func recentPosts(...any) (r []models.WpPosts, err error) {
|
||||
r, err = models.Find[models.WpPosts](models.SqlBuilder{{
|
||||
func recentPosts(...any) (r []wp.WpPosts, err error) {
|
||||
r, err = models.Find[wp.WpPosts](models.SqlBuilder{{
|
||||
"post_type", "post",
|
||||
}, {"post_status", "publish"}}, "ID,post_title,post_password", "", models.SqlBuilder{{"post_date", "desc"}}, nil, nil, 10)
|
||||
for i, post := range r {
|
||||
|
@ -142,10 +143,10 @@ func recentPosts(...any) (r []models.WpPosts, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetContextPost(ctx context.Context, id uint64, date time.Time) (prev, next models.WpPosts, err error) {
|
||||
func GetContextPost(ctx context.Context, id uint64, date time.Time) (prev, next wp.WpPosts, err error) {
|
||||
postCtx, err := postContextCache.GetCache(ctx, id, time.Second, date)
|
||||
if err != nil {
|
||||
return models.WpPosts{}, models.WpPosts{}, err
|
||||
return wp.WpPosts{}, wp.WpPosts{}, err
|
||||
}
|
||||
prev = postCtx.prev
|
||||
next = postCtx.next
|
||||
|
@ -154,7 +155,7 @@ func GetContextPost(ctx context.Context, id uint64, date time.Time) (prev, next
|
|||
|
||||
func getPostContext(arg ...any) (r PostContext, err error) {
|
||||
t := arg[0].(time.Time)
|
||||
next, err := models.FirstOne[models.WpPosts](models.SqlBuilder{
|
||||
next, err := models.FirstOne[wp.WpPosts](models.SqlBuilder{
|
||||
{"post_date", ">", t.Format("2006-01-02 15:04:05")},
|
||||
{"post_status", "in", ""},
|
||||
{"post_type", "post"},
|
||||
|
@ -165,7 +166,7 @@ func getPostContext(arg ...any) (r PostContext, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
prev, err := models.FirstOne[models.WpPosts](models.SqlBuilder{
|
||||
prev, err := models.FirstOne[wp.WpPosts](models.SqlBuilder{
|
||||
{"post_date", "<", t.Format("2006-01-02 15:04:05")},
|
||||
{"post_status", "in", ""},
|
||||
{"post_type", "post"},
|
||||
|
@ -183,7 +184,7 @@ func getPostContext(arg ...any) (r PostContext, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetMonthPostIds(ctx context.Context, year, month string, page, limit int, order string) (r []models.WpPosts, total int, err error) {
|
||||
func GetMonthPostIds(ctx context.Context, year, month string, page, limit int, order string) (r []wp.WpPosts, total int, err error) {
|
||||
res, err := monthPostsCache.GetCache(ctx, fmt.Sprintf("%s%s", year, month), time.Second, year, month)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -207,7 +208,7 @@ func monthPost(args ...any) (r []uint64, err error) {
|
|||
}
|
||||
postType := []any{"post"}
|
||||
status := []any{"publish"}
|
||||
ids, err := models.Find[models.WpPosts](where, "ID", "", models.SqlBuilder{{"Id", "asc"}}, nil, nil, 0, postType, status)
|
||||
ids, err := models.Find[wp.WpPosts](where, "ID", "", models.SqlBuilder{{"Id", "asc"}}, nil, nil, 0, postType, status)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -4,19 +4,20 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/logs"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"time"
|
||||
)
|
||||
|
||||
func getUsers(...any) (m map[uint64]models.WpUsers, err error) {
|
||||
m = make(map[uint64]models.WpUsers)
|
||||
r, err := models.SimpleFind[models.WpUsers](nil, "*")
|
||||
func getUsers(...any) (m map[uint64]wp.WpUsers, err error) {
|
||||
m = make(map[uint64]wp.WpUsers)
|
||||
r, err := models.SimpleFind[wp.WpUsers](nil, "*")
|
||||
for _, user := range r {
|
||||
m[user.Id] = user
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetUser(ctx *gin.Context, uid uint64) models.WpUsers {
|
||||
func GetUser(ctx *gin.Context, uid uint64) wp.WpUsers {
|
||||
r, err := usersCache.GetCache(ctx, uid, time.Second, uid)
|
||||
logs.ErrPrintln(err, "get user", uid)
|
||||
return r
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github/fthvgb1/wp-go/actions/common"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/logs"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"github/fthvgb1/wp-go/plugins"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
|
@ -32,8 +32,8 @@ func Detail(c *gin.Context) {
|
|||
categoryItems := common.Categories(c)
|
||||
recentComments := common.RecentComments(c, 5)
|
||||
var h = gin.H{
|
||||
"title": models.Options["blogname"],
|
||||
"options": models.Options,
|
||||
"title": wp.Options["blogname"],
|
||||
"options": wp.Options,
|
||||
"recentPosts": recent,
|
||||
"archives": archive,
|
||||
"categories": categoryItems,
|
||||
|
@ -81,11 +81,11 @@ func Detail(c *gin.Context) {
|
|||
commentss := treeComments(comments)
|
||||
prev, next, err := common.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, models.Options["blogname"])
|
||||
h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wp.Options["blogname"])
|
||||
h["post"] = post
|
||||
h["showComment"] = showComment
|
||||
h["prev"] = prev
|
||||
depth := models.Options["thread_comments_depth"]
|
||||
depth := wp.Options["thread_comments_depth"]
|
||||
d, err := strconv.Atoi(depth)
|
||||
if err != nil {
|
||||
logs.ErrPrintln(err, "get comment depth")
|
||||
|
@ -96,7 +96,7 @@ func Detail(c *gin.Context) {
|
|||
}
|
||||
|
||||
type Comment struct {
|
||||
models.WpComments
|
||||
wp.WpComments
|
||||
Children []*Comment
|
||||
}
|
||||
|
||||
|
@ -163,10 +163,10 @@ func findComments(comments Comments) Comments {
|
|||
return r
|
||||
}
|
||||
|
||||
func treeComments(comments []models.WpComments) Comments {
|
||||
func treeComments(comments []wp.WpComments) Comments {
|
||||
var r = map[uint64]*Comment{
|
||||
0: {
|
||||
WpComments: models.WpComments{},
|
||||
WpComments: wp.WpComments{},
|
||||
},
|
||||
}
|
||||
var top []*Comment
|
||||
|
@ -190,7 +190,7 @@ func treeComments(comments []models.WpComments) Comments {
|
|||
return top
|
||||
}
|
||||
|
||||
func (d detailHandler) formatLi(comments models.WpComments, depth int, eo, parent string) string {
|
||||
func (d detailHandler) formatLi(comments wp.WpComments, depth int, eo, parent string) string {
|
||||
li := `
|
||||
<li id="comment-{{CommentId}}" class="comment {{eo}} thread-even depth-{{Depth}} {{parent}}">
|
||||
<article id="div-comment-{{CommentId}}" class="comment-body">
|
||||
|
@ -262,7 +262,7 @@ func gravatar(c *gin.Context, email string) (u string) {
|
|||
q := url.Values{}
|
||||
q.Add("s", "112")
|
||||
q.Add("d", "mm")
|
||||
q.Add("r", "g")
|
||||
q.Add("r", strings.ToLower(wp.Options["avatar_rating"]))
|
||||
u = fmt.Sprintf("%s?%s", u, q.Encode())
|
||||
return
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github/fthvgb1/wp-go/cache"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/logs"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"github/fthvgb1/wp-go/plugins"
|
||||
"github/fthvgb1/wp-go/rss2"
|
||||
"net/http"
|
||||
|
@ -25,14 +25,14 @@ var commentsFeedCache = cache.NewSliceCache(commentsFeed, time.Hour)
|
|||
|
||||
func InitFeed() {
|
||||
templateRss = rss2.Rss2{
|
||||
Title: models.Options["blogname"],
|
||||
AtomLink: fmt.Sprintf("%s/feed", models.Options["home"]),
|
||||
Link: models.Options["siteurl"],
|
||||
Description: models.Options["blogdescription"],
|
||||
Title: wp.Options["blogname"],
|
||||
AtomLink: fmt.Sprintf("%s/feed", wp.Options["home"]),
|
||||
Link: wp.Options["siteurl"],
|
||||
Description: wp.Options["blogdescription"],
|
||||
Language: "zh-CN",
|
||||
UpdatePeriod: "hourly",
|
||||
UpdateFrequency: 1,
|
||||
Generator: models.Options["home"],
|
||||
Generator: wp.Options["home"],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ 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 models.WpPosts) uint64 {
|
||||
ids := helper.SliceMap(r, func(t wp.WpPosts) uint64 {
|
||||
return t.Id
|
||||
})
|
||||
posts, err := common.GetPostsByIds(c, ids)
|
||||
|
@ -81,7 +81,7 @@ func feed(arg ...any) (xml []string, err error) {
|
|||
}
|
||||
rs := templateRss
|
||||
rs.LastBuildDate = time.Now().Format(timeFormat)
|
||||
rs.Items = helper.SliceMap(posts, func(t models.WpPosts) rss2.Item {
|
||||
rs.Items = helper.SliceMap(posts, func(t wp.WpPosts) rss2.Item {
|
||||
desc := "无法提供摘要。这是一篇受保护的文章。"
|
||||
common.PasswordProjectTitle(&t)
|
||||
if t.PostPassword != "" {
|
||||
|
@ -91,9 +91,9 @@ func feed(arg ...any) (xml []string, err error) {
|
|||
}
|
||||
l := ""
|
||||
if t.CommentStatus == "open" && t.CommentCount > 0 {
|
||||
l = fmt.Sprintf("%s/p/%d#comments", models.Options["siteurl"], t.Id)
|
||||
l = fmt.Sprintf("%s/p/%d#comments", wp.Options["siteurl"], t.Id)
|
||||
} else if t.CommentStatus == "open" && t.CommentCount == 0 {
|
||||
l = fmt.Sprintf("%s/p/%d#respond", models.Options["siteurl"], t.Id)
|
||||
l = fmt.Sprintf("%s/p/%d#respond", wp.Options["siteurl"], t.Id)
|
||||
}
|
||||
user := common.GetUser(c, t.PostAuthor)
|
||||
|
||||
|
@ -105,8 +105,8 @@ func feed(arg ...any) (xml []string, err error) {
|
|||
Content: t.PostContent,
|
||||
Category: strings.Join(t.Categories, "、"),
|
||||
CommentLink: l,
|
||||
CommentRss: fmt.Sprintf("%s/p/%d/feed", models.Options["siteurl"], t.Id),
|
||||
Link: fmt.Sprintf("%s/p/%d", models.Options["siteurl"], t.Id),
|
||||
CommentRss: fmt.Sprintf("%s/p/%d/feed", wp.Options["siteurl"], t.Id),
|
||||
Link: fmt.Sprintf("%s/p/%d", wp.Options["siteurl"], t.Id),
|
||||
Description: desc,
|
||||
PubDate: t.PostDateGmt.Format(timeFormat),
|
||||
}
|
||||
|
@ -168,8 +168,8 @@ func postFeed(arg ...any) (x string, err error) {
|
|||
rs := templateRss
|
||||
|
||||
rs.Title = fmt.Sprintf("《%s》的评论", post.PostTitle)
|
||||
rs.AtomLink = fmt.Sprintf("%s/p/%d/feed", models.Options["siteurl"], post.Id)
|
||||
rs.Link = fmt.Sprintf("%s/p/%d", models.Options["siteurl"], post.Id)
|
||||
rs.AtomLink = fmt.Sprintf("%s/p/%d/feed", wp.Options["siteurl"], post.Id)
|
||||
rs.Link = fmt.Sprintf("%s/p/%d", wp.Options["siteurl"], post.Id)
|
||||
rs.LastBuildDate = time.Now().Format(timeFormat)
|
||||
if post.PostPassword != "" {
|
||||
if len(comments) > 0 {
|
||||
|
@ -178,7 +178,7 @@ func postFeed(arg ...any) (x string, err error) {
|
|||
rs.Items = []rss2.Item{
|
||||
{
|
||||
Title: fmt.Sprintf("评价者:%s", t.CommentAuthor),
|
||||
Link: fmt.Sprintf("%s/p/%d#comment-%d", models.Options["siteurl"], post.Id, t.CommentId),
|
||||
Link: fmt.Sprintf("%s/p/%d#comment-%d", wp.Options["siteurl"], post.Id, t.CommentId),
|
||||
Creator: t.CommentAuthor,
|
||||
PubDate: t.CommentDateGmt.Format(timeFormat),
|
||||
Guid: fmt.Sprintf("%s#comment-%d", post.Guid, t.CommentId),
|
||||
|
@ -188,10 +188,10 @@ func postFeed(arg ...any) (x string, err error) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
rs.Items = helper.SliceMap(comments, func(t models.WpComments) rss2.Item {
|
||||
rs.Items = helper.SliceMap(comments, func(t wp.WpComments) rss2.Item {
|
||||
return rss2.Item{
|
||||
Title: fmt.Sprintf("评价者:%s", t.CommentAuthor),
|
||||
Link: fmt.Sprintf("%s/p/%d#comment-%d", models.Options["siteurl"], post.Id, t.CommentId),
|
||||
Link: fmt.Sprintf("%s/p/%d#comment-%d", wp.Options["siteurl"], post.Id, t.CommentId),
|
||||
Creator: t.CommentAuthor,
|
||||
PubDate: t.CommentDateGmt.Format(timeFormat),
|
||||
Guid: fmt.Sprintf("%s#comment-%d", post.Guid, t.CommentId),
|
||||
|
@ -223,16 +223,16 @@ func commentsFeed(args ...any) (r []string, err error) {
|
|||
c := args[0].(*gin.Context)
|
||||
commens := common.RecentComments(c, 10)
|
||||
rs := templateRss
|
||||
rs.Title = fmt.Sprintf("\"%s\"的评论", models.Options["blogname"])
|
||||
rs.Title = fmt.Sprintf("\"%s\"的评论", wp.Options["blogname"])
|
||||
rs.LastBuildDate = time.Now().Format(timeFormat)
|
||||
rs.AtomLink = fmt.Sprintf("%s/comments/feed", models.Options["siteurl"])
|
||||
com, err := common.GetCommentByIds(c, helper.SliceMap(commens, func(t models.WpComments) uint64 {
|
||||
rs.AtomLink = fmt.Sprintf("%s/comments/feed", wp.Options["siteurl"])
|
||||
com, err := common.GetCommentByIds(c, helper.SliceMap(commens, func(t wp.WpComments) uint64 {
|
||||
return t.CommentId
|
||||
}))
|
||||
if nil != err {
|
||||
return []string{}, err
|
||||
}
|
||||
rs.Items = helper.SliceMap(com, func(t models.WpComments) rss2.Item {
|
||||
rs.Items = helper.SliceMap(com, func(t wp.WpComments) rss2.Item {
|
||||
post, _ := common.GetPostById(c, t.CommentPostId)
|
||||
common.PasswordProjectTitle(&post)
|
||||
desc := "评论受保护:要查看请输入密码。"
|
||||
|
@ -246,7 +246,7 @@ func commentsFeed(args ...any) (r []string, err error) {
|
|||
}
|
||||
return rss2.Item{
|
||||
Title: fmt.Sprintf("%s对《%s》的评论", t.CommentAuthor, post.PostTitle),
|
||||
Link: fmt.Sprintf("%s/p/%d#comment-%d", models.Options["siteurl"], post.Id, t.CommentId),
|
||||
Link: fmt.Sprintf("%s/p/%d#comment-%d", wp.Options["siteurl"], post.Id, t.CommentId),
|
||||
Creator: t.CommentAuthor,
|
||||
Description: desc,
|
||||
PubDate: t.CommentDateGmt.Format(timeFormat),
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github/fthvgb1/wp-go/actions/common"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"github/fthvgb1/wp-go/plugins"
|
||||
"math"
|
||||
"net/http"
|
||||
|
@ -39,7 +40,7 @@ type indexHandle struct {
|
|||
}
|
||||
|
||||
func newIndexHandle(ctx *gin.Context) *indexHandle {
|
||||
size := models.Options["posts_per_page"]
|
||||
size := wp.Options["posts_per_page"]
|
||||
si, _ := strconv.Atoi(size)
|
||||
return &indexHandle{
|
||||
c: ctx,
|
||||
|
@ -47,8 +48,8 @@ func newIndexHandle(ctx *gin.Context) *indexHandle {
|
|||
page: 1,
|
||||
pageSize: si,
|
||||
paginationStep: 1,
|
||||
titleL: models.Options["blogname"],
|
||||
titleR: models.Options["blogdescription"],
|
||||
titleL: wp.Options["blogname"],
|
||||
titleR: wp.Options["blogdescription"],
|
||||
where: models.SqlBuilder{
|
||||
{"post_type", "in", ""},
|
||||
{"post_status", "in", ""},
|
||||
|
@ -92,7 +93,7 @@ func (h *indexHandle) parseParams() {
|
|||
})
|
||||
ss := fmt.Sprintf("%s年%s月", year, strings.TrimLeft(month, "0"))
|
||||
h.header = fmt.Sprintf("月度归档: <span>%s</span>", ss)
|
||||
h.setTitleLR(ss, models.Options["blogname"])
|
||||
h.setTitleLR(ss, wp.Options["blogname"])
|
||||
h.scene = plugins.Archive
|
||||
}
|
||||
category := h.c.Param("category")
|
||||
|
@ -119,7 +120,7 @@ func (h *indexHandle) parseParams() {
|
|||
}, []string{
|
||||
"left join", "wp_terms d", "c.term_id=d.term_id",
|
||||
})
|
||||
h.setTitleLR(category, models.Options["blogname"])
|
||||
h.setTitleLR(category, wp.Options["blogname"])
|
||||
h.scene = plugins.Category
|
||||
}
|
||||
s := h.c.Query("s")
|
||||
|
@ -132,7 +133,7 @@ func (h *indexHandle) parseParams() {
|
|||
}, []string{"post_password", ""})
|
||||
h.postType = append(h.postType, "page", "attachment")
|
||||
h.header = fmt.Sprintf("%s的搜索结果", s)
|
||||
h.setTitleLR(helper.StrJoin(`"`, s, `"`, "的搜索结果"), models.Options["blogname"])
|
||||
h.setTitleLR(helper.StrJoin(`"`, s, `"`, "的搜索结果"), wp.Options["blogname"])
|
||||
h.search = s
|
||||
h.scene = plugins.Search
|
||||
}
|
||||
|
@ -149,7 +150,7 @@ func (h *indexHandle) parseParams() {
|
|||
h.page = 1
|
||||
}
|
||||
if h.page > 1 && (h.category != "" || h.search != "" || month != "") {
|
||||
h.setTitleLR(fmt.Sprintf("%s-第%d页", h.titleL, h.page), models.Options["blogname"])
|
||||
h.setTitleLR(fmt.Sprintf("%s-第%d页", h.titleL, h.page), wp.Options["blogname"])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +167,7 @@ func Index(c *gin.Context) {
|
|||
categoryItems := common.Categories(c)
|
||||
recentComments := common.RecentComments(c, 5)
|
||||
ginH := gin.H{
|
||||
"options": models.Options,
|
||||
"options": wp.Options,
|
||||
"recentPosts": recent,
|
||||
"archives": archive,
|
||||
"categories": categoryItems,
|
||||
|
@ -175,7 +176,7 @@ func Index(c *gin.Context) {
|
|||
"title": h.getTitle(),
|
||||
"recentComments": recentComments,
|
||||
}
|
||||
var postIds []models.WpPosts
|
||||
var postIds []wp.WpPosts
|
||||
var totalRaw int
|
||||
var err error
|
||||
if c.Param("month") != "" {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"github/fthvgb1/wp-go/phpass"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -33,7 +33,7 @@ func Login(c *gin.Context) {
|
|||
c.Error(err)
|
||||
return
|
||||
}
|
||||
cohash := fmt.Sprintf("wp-postpass_%s", helper.StringMd5(models.Options["siteurl"]))
|
||||
cohash := fmt.Sprintf("wp-postpass_%s", helper.StringMd5(wp.Options["siteurl"]))
|
||||
c.SetCookie(cohash, pass, 24*3600, "/", "", false, false)
|
||||
|
||||
c.Redirect(http.StatusFound, ref)
|
||||
|
|
6
main.go
6
main.go
|
@ -5,7 +5,7 @@ import (
|
|||
"github/fthvgb1/wp-go/actions/common"
|
||||
"github/fthvgb1/wp-go/config"
|
||||
"github/fthvgb1/wp-go/db"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"github/fthvgb1/wp-go/plugins"
|
||||
"github/fthvgb1/wp-go/route"
|
||||
"math/rand"
|
||||
|
@ -24,12 +24,12 @@ func init() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
err = models.InitOptions()
|
||||
err = wp.InitOptions()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = models.InitTerms()
|
||||
err = wp.InitTerms()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github/fthvgb1/wp-go/config"
|
||||
"github/fthvgb1/wp-go/logs"
|
||||
"github/fthvgb1/wp-go/mail"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
@ -43,7 +43,7 @@ func RecoverAndSendMail(w io.Writer) func(ctx *gin.Context) {
|
|||
|
||||
er := mail.SendMail(
|
||||
[]string{config.Conf.Mail.User},
|
||||
fmt.Sprintf("%s%s %s 发生错误", fmt.Sprintf(models.Options["siteurl"]), c.FullPath(), time.Now().Format(time.RFC1123Z)), content)
|
||||
fmt.Sprintf("%s%s %s 发生错误", fmt.Sprintf(wp.Options["siteurl"]), c.FullPath(), time.Now().Format(time.RFC1123Z)), content)
|
||||
|
||||
if er != nil {
|
||||
logs.ErrPrintln(er, "recover send mail fail", fmt.Sprintf("%v", err))
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
package models
|
||||
package wp
|
||||
|
||||
import "github/fthvgb1/wp-go/models"
|
||||
|
||||
var Options = make(map[string]string)
|
||||
var Terms = map[uint64]WpTerms{}
|
||||
var TermTaxonomy = map[uint64]WpTermTaxonomy{}
|
||||
|
||||
func InitOptions() error {
|
||||
ops, err := SimpleFind[WpOptions](SqlBuilder{{"autoload", "yes"}}, "option_name, option_value")
|
||||
ops, err := models.SimpleFind[WpOptions](models.SqlBuilder{{"autoload", "yes"}}, "option_name, option_value")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(ops) == 0 {
|
||||
ops, err = SimpleFind[WpOptions](nil, "option_name, option_value")
|
||||
ops, err = models.SimpleFind[WpOptions](nil, "option_name, option_value")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -22,14 +24,14 @@ func InitOptions() error {
|
|||
}
|
||||
|
||||
func InitTerms() (err error) {
|
||||
terms, err := SimpleFind[WpTerms](nil, "*")
|
||||
terms, err := models.SimpleFind[WpTerms](nil, "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, wpTerms := range terms {
|
||||
Terms[wpTerms.TermId] = wpTerms
|
||||
}
|
||||
termTax, err := SimpleFind[WpTermTaxonomy](nil, "*")
|
||||
termTax, err := models.SimpleFind[WpTermTaxonomy](nil, "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package models
|
||||
package wp
|
||||
|
||||
import "time"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package models
|
||||
package wp
|
||||
|
||||
type WpOptions struct {
|
||||
OptionId uint64 `gorm:"column:option_id" db:"option_id" json:"option_id" form:"option_id"`
|
|
@ -1,4 +1,4 @@
|
|||
package models
|
||||
package wp
|
||||
|
||||
import "time"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package models
|
||||
package wp
|
||||
|
||||
type WpTermTaxonomy struct {
|
||||
TermTaxonomyId uint64 `gorm:"column:term_taxonomy_id" db:"term_taxonomy_id" json:"term_taxonomy_id" form:"term_taxonomy_id"`
|
|
@ -1,4 +1,4 @@
|
|||
package models
|
||||
package wp
|
||||
|
||||
type WpTerms struct {
|
||||
TermId uint64 `gorm:"column:term_id" db:"term_id" json:"term_id" form:"term_id"`
|
|
@ -1,4 +1,4 @@
|
|||
package models
|
||||
package wp
|
||||
|
||||
import "time"
|
||||
|
|
@ -13,6 +13,7 @@ import (
|
|||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// PasswordHash 目前还不完善,只有encode64 getRandomBytes CryptPrivate 方法能用
|
||||
type PasswordHash struct {
|
||||
itoa64 string
|
||||
iterationCountLog2 int
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github/fthvgb1/wp-go/cache"
|
||||
"github/fthvgb1/wp-go/config"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -116,7 +116,7 @@ func DigestRaw(str string, limit int, u string) string {
|
|||
return content
|
||||
}
|
||||
|
||||
func Digest(p *Plugin[models.WpPosts], c *gin.Context, post *models.WpPosts, scene uint) {
|
||||
func Digest(p *Plugin[wp.WpPosts], c *gin.Context, post *wp.WpPosts, scene uint) {
|
||||
if scene == Detail {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,16 +2,16 @@ package plugins
|
|||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/models"
|
||||
"github/fthvgb1/wp-go/models/wp"
|
||||
)
|
||||
|
||||
func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[models.WpPosts] {
|
||||
p := NewPlugin[models.WpPosts](nil, -1, nil, scene, ctx)
|
||||
func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[wp.WpPosts] {
|
||||
p := NewPlugin[wp.WpPosts](nil, -1, nil, scene, ctx)
|
||||
p.Push(Digest)
|
||||
return p
|
||||
}
|
||||
|
||||
func ApplyPlugin(p *Plugin[models.WpPosts], post *models.WpPosts) {
|
||||
func ApplyPlugin(p *Plugin[wp.WpPosts], post *wp.WpPosts) {
|
||||
p.post = post
|
||||
p.Next()
|
||||
p.index = -1
|
||||
|
|
Loading…
Reference in New Issue
Block a user