文件目录调整
This commit is contained in:
parent
e48cf803bb
commit
aa9362bc34
|
@ -8,9 +8,9 @@ import (
|
|||
"github/fthvgb1/wp-go/cache"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
cache2 "github/fthvgb1/wp-go/internal/cache"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/mail"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/internal/cache"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/internal/plugins"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
"math/rand"
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github/fthvgb1/wp-go/cache"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
cache2 "github/fthvgb1/wp-go/internal/cache"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
models2 "github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/internal/plugins"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
"github/fthvgb1/wp-go/plugin/digest"
|
||||
|
@ -79,7 +79,7 @@ func Feed(c *gin.Context) {
|
|||
func feed(arg ...any) (xml []string, err error) {
|
||||
c := arg[0].(*gin.Context)
|
||||
r := cache2.RecentPosts(c, 10)
|
||||
ids := helper.SliceMap(r, func(t models.Posts) uint64 {
|
||||
ids := helper.SliceMap(r, func(t models2.Posts) uint64 {
|
||||
return t.Id
|
||||
})
|
||||
posts, err := cache2.GetPostsByIds(c, ids)
|
||||
|
@ -88,7 +88,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.Posts) rss2.Item {
|
||||
rs.Items = helper.SliceMap(posts, func(t models2.Posts) rss2.Item {
|
||||
desc := "无法提供摘要。这是一篇受保护的文章。"
|
||||
plugins.PasswordProjectTitle(&t)
|
||||
if t.PostPassword != "" {
|
||||
|
@ -195,7 +195,7 @@ func postFeed(arg ...any) (x string, err error) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
rs.Items = helper.SliceMap(comments, func(t models.Comments) rss2.Item {
|
||||
rs.Items = helper.SliceMap(comments, func(t models2.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),
|
||||
|
@ -233,13 +233,13 @@ func commentsFeed(args ...any) (r []string, err error) {
|
|||
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 := cache2.GetCommentByIds(c, helper.SliceMap(commens, func(t models.Comments) uint64 {
|
||||
com, err := cache2.GetCommentByIds(c, helper.SliceMap(commens, func(t models2.Comments) uint64 {
|
||||
return t.CommentId
|
||||
}))
|
||||
if nil != err {
|
||||
return []string{}, err
|
||||
}
|
||||
rs.Items = helper.SliceMap(com, func(t models.Comments) rss2.Item {
|
||||
rs.Items = helper.SliceMap(com, func(t models2.Comments) rss2.Item {
|
||||
post, _ := cache2.GetPostById(c, t.CommentPostId)
|
||||
plugins.PasswordProjectTitle(&post)
|
||||
desc := "评论受保护:要查看请输入密码。"
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/internal/cache"
|
||||
dao "github/fthvgb1/wp-go/internal/dao"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/internal/plugins"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
|
|
44
internal/cache/cache.go
vendored
44
internal/cache/cache.go
vendored
|
@ -3,21 +3,21 @@ package cache
|
|||
import (
|
||||
"context"
|
||||
"github/fthvgb1/wp-go/cache"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
dao "github/fthvgb1/wp-go/internal/dao"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
models2 "github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var postContextCache *cache.MapCache[uint64, dao.PostContext]
|
||||
var archivesCaches *Arch
|
||||
var categoryCaches *cache.SliceCache[models.TermsMy]
|
||||
var recentPostsCaches *cache.SliceCache[models.Posts]
|
||||
var recentCommentsCaches *cache.SliceCache[models.Comments]
|
||||
var categoryCaches *cache.SliceCache[models2.TermsMy]
|
||||
var recentPostsCaches *cache.SliceCache[models2.Posts]
|
||||
var recentCommentsCaches *cache.SliceCache[models2.Comments]
|
||||
var postCommentCaches *cache.MapCache[uint64, []uint64]
|
||||
var postsCache *cache.MapCache[uint64, models.Posts]
|
||||
var postsCache *cache.MapCache[uint64, models2.Posts]
|
||||
|
||||
var postMetaCache *cache.MapCache[uint64, map[string]any]
|
||||
|
||||
|
@ -26,9 +26,9 @@ var postListIdsCache *cache.MapCache[string, dao.PostIds]
|
|||
var searchPostIdsCache *cache.MapCache[string, dao.PostIds]
|
||||
var maxPostIdCache *cache.SliceCache[uint64]
|
||||
|
||||
var usersCache *cache.MapCache[uint64, models.Users]
|
||||
var usersNameCache *cache.MapCache[string, models.Users]
|
||||
var commentsCache *cache.MapCache[uint64, models.Comments]
|
||||
var usersCache *cache.MapCache[uint64, models2.Users]
|
||||
var usersNameCache *cache.MapCache[string, models2.Users]
|
||||
var commentsCache *cache.MapCache[uint64, models2.Comments]
|
||||
|
||||
func InitActionsCommonCache() {
|
||||
c := config.Conf.Load()
|
||||
|
@ -45,25 +45,25 @@ func InitActionsCommonCache() {
|
|||
|
||||
postContextCache = cache.NewMapCacheByFn[uint64, dao.PostContext](dao.GetPostContext, c.ContextPostCacheTime)
|
||||
|
||||
postsCache = cache.NewMapCacheByBatchFn[uint64, models.Posts](dao.GetPostsByIds, c.PostDataCacheTime)
|
||||
postsCache = cache.NewMapCacheByBatchFn[uint64, models2.Posts](dao.GetPostsByIds, c.PostDataCacheTime)
|
||||
|
||||
postMetaCache = cache.NewMapCacheByBatchFn[uint64, map[string]any](dao.GetPostMetaByPostIds, c.PostDataCacheTime)
|
||||
|
||||
categoryCaches = cache.NewSliceCache[models.TermsMy](dao.Categories, c.CategoryCacheTime)
|
||||
categoryCaches = cache.NewSliceCache[models2.TermsMy](dao.Categories, c.CategoryCacheTime)
|
||||
|
||||
recentPostsCaches = cache.NewSliceCache[models.Posts](dao.RecentPosts, c.RecentPostCacheTime)
|
||||
recentPostsCaches = cache.NewSliceCache[models2.Posts](dao.RecentPosts, c.RecentPostCacheTime)
|
||||
|
||||
recentCommentsCaches = cache.NewSliceCache[models.Comments](dao.RecentComments, c.RecentCommentsCacheTime)
|
||||
recentCommentsCaches = cache.NewSliceCache[models2.Comments](dao.RecentComments, c.RecentCommentsCacheTime)
|
||||
|
||||
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](dao.PostComments, c.PostCommentsCacheTime)
|
||||
|
||||
maxPostIdCache = cache.NewSliceCache[uint64](dao.GetMaxPostId, c.MaxPostIdCacheTime)
|
||||
|
||||
usersCache = cache.NewMapCacheByFn[uint64, models.Users](dao.GetUserById, c.UserInfoCacheTime)
|
||||
usersCache = cache.NewMapCacheByFn[uint64, models2.Users](dao.GetUserById, c.UserInfoCacheTime)
|
||||
|
||||
usersNameCache = cache.NewMapCacheByFn[string, models.Users](dao.GetUserByName, c.UserInfoCacheTime)
|
||||
usersNameCache = cache.NewMapCacheByFn[string, models2.Users](dao.GetUserByName, c.UserInfoCacheTime)
|
||||
|
||||
commentsCache = cache.NewMapCacheByBatchFn[uint64, models.Comments](dao.GetCommentByIds, c.CommentsCacheTime)
|
||||
commentsCache = cache.NewMapCacheByBatchFn[uint64, models2.Comments](dao.GetCommentByIds, c.CommentsCacheTime)
|
||||
}
|
||||
|
||||
func ClearCache() {
|
||||
|
@ -89,18 +89,18 @@ func FlushCache() {
|
|||
usersCache.Flush()
|
||||
}
|
||||
|
||||
func Archives(ctx context.Context) (r []models.PostArchive) {
|
||||
func Archives(ctx context.Context) (r []models2.PostArchive) {
|
||||
return archivesCaches.getArchiveCache(ctx)
|
||||
}
|
||||
|
||||
type Arch struct {
|
||||
data []models.PostArchive
|
||||
data []models2.PostArchive
|
||||
mutex *sync.Mutex
|
||||
setCacheFunc func(context.Context) ([]models.PostArchive, error)
|
||||
setCacheFunc func(context.Context) ([]models2.PostArchive, error)
|
||||
month time.Month
|
||||
}
|
||||
|
||||
func (c *Arch) getArchiveCache(ctx context.Context) []models.PostArchive {
|
||||
func (c *Arch) getArchiveCache(ctx context.Context) []models2.PostArchive {
|
||||
l := len(c.data)
|
||||
m := time.Now().Month()
|
||||
if l > 0 && c.month != m || l < 1 {
|
||||
|
@ -117,7 +117,7 @@ func (c *Arch) getArchiveCache(ctx context.Context) []models.PostArchive {
|
|||
return c.data
|
||||
}
|
||||
|
||||
func Categories(ctx context.Context) []models.TermsMy {
|
||||
func Categories(ctx context.Context) []models2.TermsMy {
|
||||
r, err := categoryCaches.GetCache(ctx, time.Second, ctx)
|
||||
logs.ErrPrintln(err, "get category ")
|
||||
return r
|
||||
|
|
4
internal/cache/comments.go
vendored
4
internal/cache/comments.go
vendored
|
@ -2,8 +2,8 @@ package cache
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
2
internal/cache/postmeta.go
vendored
2
internal/cache/postmeta.go
vendored
|
@ -3,7 +3,7 @@ package cache
|
|||
import (
|
||||
"context"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
wp2 "github/fthvgb1/wp-go/internal/models"
|
||||
wp2 "github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
|
4
internal/cache/posts.go
vendored
4
internal/cache/posts.go
vendored
|
@ -5,8 +5,8 @@ import (
|
|||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
4
internal/cache/users.go
vendored
4
internal/cache/users.go
vendored
|
@ -2,8 +2,8 @@ package cache
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
"time"
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ package common
|
|||
import (
|
||||
"context"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
"strconv"
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ package common
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
models2 "github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
)
|
||||
|
@ -16,20 +16,20 @@ type PostIds struct {
|
|||
}
|
||||
|
||||
type PostContext struct {
|
||||
Prev models.Posts
|
||||
Next models.Posts
|
||||
Prev models2.Posts
|
||||
Next models2.Posts
|
||||
}
|
||||
|
||||
func PasswordProjectTitle(post *models.Posts) {
|
||||
func PasswordProjectTitle(post *models2.Posts) {
|
||||
if post.PostPassword != "" {
|
||||
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
|
||||
}
|
||||
}
|
||||
|
||||
func Categories(a ...any) (terms []models.TermsMy, err error) {
|
||||
func Categories(a ...any) (terms []models2.TermsMy, err error) {
|
||||
ctx := a[0].(context.Context)
|
||||
var in = []any{"category"}
|
||||
terms, err = model.Find[models.TermsMy](ctx, model.SqlBuilder{
|
||||
terms, err = model.Find[models2.TermsMy](ctx, model.SqlBuilder{
|
||||
{"tt.count", ">", "0", "int"},
|
||||
{"tt.taxonomy", "in", ""},
|
||||
}, "t.term_id", "", model.SqlBuilder{
|
||||
|
@ -48,8 +48,8 @@ func Categories(a ...any) (terms []models.TermsMy, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func Archives(ctx context.Context) ([]models.PostArchive, error) {
|
||||
return model.Find[models.PostArchive](ctx, model.SqlBuilder{
|
||||
func Archives(ctx context.Context) ([]models2.PostArchive, error) {
|
||||
return model.Find[models2.PostArchive](ctx, model.SqlBuilder{
|
||||
{"post_type", "post"}, {"post_status", "publish"},
|
||||
}, "YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts", "year,month", model.SqlBuilder{{"year", "desc"}, {"month", "desc"}}, nil, nil, 0)
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"context"
|
||||
"github.com/leeqvip/gophp"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
models2 "github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -14,7 +14,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 := model.Find[models.Postmeta](ctx, model.SqlBuilder{
|
||||
rr, err := model.Find[models2.Postmeta](ctx, model.SqlBuilder{
|
||||
{"post_id", "in", ""},
|
||||
}, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64]))
|
||||
if err != nil {
|
||||
|
@ -42,7 +42,7 @@ func GetPostMetaByPostIds(args ...any) (r map[uint64]map[string]any, err error)
|
|||
return
|
||||
}
|
||||
|
||||
func ToPostThumb(c context.Context, meta map[string]any, postId uint64) (r models.PostThumbnail) {
|
||||
func ToPostThumb(c context.Context, meta map[string]any, postId uint64) (r models2.PostThumbnail) {
|
||||
if meta != nil {
|
||||
m, ok := meta["_thumbnail_id"]
|
||||
if ok {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
|
|
@ -2,7 +2,7 @@ package common
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/soxfmr/gomail"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"mime"
|
||||
"path"
|
||||
)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package mail
|
||||
|
||||
import (
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/mail"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
|
|
@ -2,7 +2,7 @@ package middleware
|
|||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/safety"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/cache"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/plugin/digest"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
|
@ -3,7 +3,7 @@ package plugins
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
)
|
||||
|
||||
func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[models.Posts] {
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-gonic/gin"
|
||||
actions2 "github/fthvgb1/wp-go/internal/actions"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
middleware2 "github/fthvgb1/wp-go/internal/middleware"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/internal/static"
|
||||
"github/fthvgb1/wp-go/internal/templates"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
|
|
|
@ -2,7 +2,7 @@ package wpconfig
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
"github/fthvgb1/wp-go/safety"
|
||||
)
|
||||
|
|
|
@ -2,24 +2,24 @@ package wpconfig
|
|||
|
||||
import (
|
||||
"context"
|
||||
wp2 "github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github/fthvgb1/wp-go/model"
|
||||
"github/fthvgb1/wp-go/safety"
|
||||
)
|
||||
|
||||
var Terms safety.Map[uint64, wp2.Terms]
|
||||
var TermTaxonomies safety.Map[uint64, wp2.TermTaxonomy]
|
||||
var Terms safety.Map[uint64, models.Terms]
|
||||
var TermTaxonomies safety.Map[uint64, models.TermTaxonomy]
|
||||
|
||||
func InitTerms() (err error) {
|
||||
ctx := context.Background()
|
||||
terms, err := model.SimpleFind[wp2.Terms](ctx, nil, "*")
|
||||
terms, err := model.SimpleFind[models.Terms](ctx, nil, "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, wpTerms := range terms {
|
||||
Terms.Store(wpTerms.TermId, wpTerms)
|
||||
}
|
||||
termTax, err := model.SimpleFind[wp2.TermTaxonomy](ctx, nil, "*")
|
||||
termTax, err := model.SimpleFind[models.TermTaxonomy](ctx, nil, "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
6
main.go
6
main.go
|
@ -5,10 +5,10 @@ import (
|
|||
"fmt"
|
||||
"github/fthvgb1/wp-go/internal/actions"
|
||||
"github/fthvgb1/wp-go/internal/cache"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/db"
|
||||
"github/fthvgb1/wp-go/internal/logs"
|
||||
"github/fthvgb1/wp-go/internal/mail"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/db"
|
||||
"github/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github/fthvgb1/wp-go/internal/plugins"
|
||||
"github/fthvgb1/wp-go/internal/route"
|
||||
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"github/fthvgb1/wp-go/helper"
|
||||
"github/fthvgb1/wp-go/internal/config"
|
||||
"github/fthvgb1/wp-go/internal/db"
|
||||
"github/fthvgb1/wp-go/internal/models"
|
||||
"github/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github/fthvgb1/wp-go/internal/pkg/db"
|
||||
models2 "github/fthvgb1/wp-go/internal/pkg/models"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
@ -36,7 +36,7 @@ func TestFind(t *testing.T) {
|
|||
in [][]any
|
||||
}
|
||||
type posts struct {
|
||||
models.Posts
|
||||
models2.Posts
|
||||
N int `db:"n"`
|
||||
}
|
||||
tests := []struct {
|
||||
|
@ -107,7 +107,7 @@ func TestFind(t *testing.T) {
|
|||
in: nil,
|
||||
},
|
||||
wantR: func() []posts {
|
||||
r, err := Select[posts](ctx, "select post_status,count(*) n from "+models.Posts{}.Table()+" where ID<1000 group by post_status having n>1")
|
||||
r, err := Select[posts](ctx, "select post_status,count(*) n from "+models2.Posts{}.Table()+" where ID<1000 group by post_status having n>1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -152,10 +152,10 @@ func TestFind(t *testing.T) {
|
|||
group: "a.post_author",
|
||||
order: SqlBuilder{{"n", "desc"}},
|
||||
join: SqlBuilder{
|
||||
{"a", "left join", models.Users{}.Table() + " b", "a.post_author=b.ID"},
|
||||
{"a", "left join", models2.Users{}.Table() + " b", "a.post_author=b.ID"},
|
||||
{"left join", "wp_term_relationships c", "a.Id=c.object_id"},
|
||||
{"left join", models.TermTaxonomy{}.Table() + " d", "c.term_taxonomy_id=d.term_taxonomy_id"},
|
||||
{"left join", models.Terms{}.Table() + " e", "d.term_id=e.term_id"},
|
||||
{"left join", models2.TermTaxonomy{}.Table() + " d", "c.term_taxonomy_id=d.term_taxonomy_id"},
|
||||
{"left join", models2.Terms{}.Table() + " e", "d.term_id=e.term_id"},
|
||||
},
|
||||
having: SqlBuilder{{"n", ">", "0", "int"}},
|
||||
limit: 10,
|
||||
|
@ -193,7 +193,7 @@ func TestFindOneById(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want models.Posts
|
||||
want models2.Posts
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -201,8 +201,8 @@ func TestFindOneById(t *testing.T) {
|
|||
args: args{
|
||||
1,
|
||||
},
|
||||
want: func() models.Posts {
|
||||
r, err := Get[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where ID=?", 1)
|
||||
want: func() models2.Posts {
|
||||
r, err := Get[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where ID=?", 1)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
panic(err)
|
||||
} else if err == sql.ErrNoRows {
|
||||
|
@ -215,7 +215,7 @@ func TestFindOneById(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := FindOneById[models.Posts](ctx, tt.args.id)
|
||||
got, err := FindOneById[models2.Posts](ctx, tt.args.id)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ func TestFirstOne(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want models.Posts
|
||||
want models2.Posts
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -252,8 +252,8 @@ func TestFirstOne(t *testing.T) {
|
|||
in: nil,
|
||||
},
|
||||
wantErr: false,
|
||||
want: func() models.Posts {
|
||||
r, err := Get[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where post_status='publish' order by ID desc limit 1")
|
||||
want: func() models2.Posts {
|
||||
r, err := Get[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where post_status='publish' order by ID desc limit 1")
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
panic(err)
|
||||
} else if err == sql.ErrNoRows {
|
||||
|
@ -265,7 +265,7 @@ func TestFirstOne(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := FirstOne[models.Posts](ctx, tt.args.where, tt.args.fields, tt.args.order, tt.args.in...)
|
||||
got, err := FirstOne[models2.Posts](ctx, tt.args.where, tt.args.fields, tt.args.order, tt.args.in...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("FirstOne() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
|
@ -286,7 +286,7 @@ func TestLastOne(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want models.Posts
|
||||
want models2.Posts
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -298,8 +298,8 @@ func TestLastOne(t *testing.T) {
|
|||
fields: "*",
|
||||
in: nil,
|
||||
},
|
||||
want: func() models.Posts {
|
||||
r, err := Get[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where post_status='publish' order by "+models.Posts{}.PrimaryKey()+" desc limit 1")
|
||||
want: func() models2.Posts {
|
||||
r, err := Get[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where post_status='publish' order by "+models2.Posts{}.PrimaryKey()+" desc limit 1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ func TestLastOne(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := LastOne[models.Posts](ctx, tt.args.where, tt.args.fields, tt.args.in...)
|
||||
got, err := LastOne[models2.Posts](ctx, tt.args.where, tt.args.fields, tt.args.in...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("LastOne() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
|
@ -330,7 +330,7 @@ func TestSimpleFind(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []models.Posts
|
||||
want []models2.Posts
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -342,8 +342,8 @@ func TestSimpleFind(t *testing.T) {
|
|||
fields: "*",
|
||||
in: [][]any{{1, 2}},
|
||||
},
|
||||
want: func() (r []models.Posts) {
|
||||
r, err := Select[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where ID in (?,?)", 1, 2)
|
||||
want: func() (r []models2.Posts) {
|
||||
r, err := Select[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where ID in (?,?)", 1, 2)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
panic(err)
|
||||
} else if err == sql.ErrNoRows {
|
||||
|
@ -356,7 +356,7 @@ func TestSimpleFind(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := SimpleFind[models.Posts](ctx, tt.args.where, tt.args.fields, tt.args.in...)
|
||||
got, err := SimpleFind[models2.Posts](ctx, tt.args.where, tt.args.fields, tt.args.in...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("SimpleFind() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
|
@ -383,7 +383,7 @@ func TestSimplePagination(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantR []models.Posts
|
||||
wantR []models2.Posts
|
||||
wantTotal int
|
||||
wantErr bool
|
||||
}{
|
||||
|
@ -402,8 +402,8 @@ func TestSimplePagination(t *testing.T) {
|
|||
having: nil,
|
||||
in: [][]any{helper.SliceMap[int, any](helper.RangeSlice(431, 440, 1), helper.ToAny[int])},
|
||||
},
|
||||
wantR: func() (r []models.Posts) {
|
||||
r, err := Select[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where ID in (?,?,?,?,?)", helper.SliceMap[int, any](helper.RangeSlice(431, 435, 1), helper.ToAny[int])...)
|
||||
wantR: func() (r []models2.Posts) {
|
||||
r, err := Select[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where ID in (?,?,?,?,?)", helper.SliceMap[int, any](helper.RangeSlice(431, 435, 1), helper.ToAny[int])...)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
panic(err)
|
||||
} else if err == sql.ErrNoRows {
|
||||
|
@ -417,7 +417,7 @@ func TestSimplePagination(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotR, gotTotal, err := SimplePagination[models.Posts](ctx, tt.args.where, tt.args.fields, tt.args.group, tt.args.page, tt.args.pageSize, tt.args.order, tt.args.join, tt.args.having, tt.args.in...)
|
||||
gotR, gotTotal, err := SimplePagination[models2.Posts](ctx, tt.args.where, tt.args.fields, tt.args.group, tt.args.page, tt.args.pageSize, tt.args.order, tt.args.join, tt.args.having, tt.args.in...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("SimplePagination() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user