文件目录调整

This commit is contained in:
xing 2023-01-13 14:04:32 +08:00
parent e48cf803bb
commit aa9362bc34
35 changed files with 103 additions and 103 deletions

View File

@ -8,9 +8,9 @@ import (
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
cache2 "github/fthvgb1/wp-go/internal/cache" 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/mail"
"github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"io" "io"
"net/http" "net/http"

View File

@ -6,8 +6,8 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/cache" "github/fthvgb1/wp-go/internal/cache"
"github/fthvgb1/wp-go/internal/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/internal/plugins" "github/fthvgb1/wp-go/internal/plugins"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"math/rand" "math/rand"

View File

@ -6,8 +6,8 @@ import (
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
cache2 "github/fthvgb1/wp-go/internal/cache" cache2 "github/fthvgb1/wp-go/internal/cache"
"github/fthvgb1/wp-go/internal/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/models" models2 "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/internal/plugins" "github/fthvgb1/wp-go/internal/plugins"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/plugin/digest" "github/fthvgb1/wp-go/plugin/digest"
@ -79,7 +79,7 @@ func Feed(c *gin.Context) {
func feed(arg ...any) (xml []string, err error) { func feed(arg ...any) (xml []string, err error) {
c := arg[0].(*gin.Context) c := arg[0].(*gin.Context)
r := cache2.RecentPosts(c, 10) 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 return t.Id
}) })
posts, err := cache2.GetPostsByIds(c, ids) posts, err := cache2.GetPostsByIds(c, ids)
@ -88,7 +88,7 @@ func feed(arg ...any) (xml []string, err error) {
} }
rs := templateRss rs := templateRss
rs.LastBuildDate = time.Now().Format(timeFormat) 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 := "无法提供摘要。这是一篇受保护的文章。" desc := "无法提供摘要。这是一篇受保护的文章。"
plugins.PasswordProjectTitle(&t) plugins.PasswordProjectTitle(&t)
if t.PostPassword != "" { if t.PostPassword != "" {
@ -195,7 +195,7 @@ func postFeed(arg ...any) (x string, err error) {
} }
} }
} else { } 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{ return rss2.Item{
Title: fmt.Sprintf("评价者:%s", t.CommentAuthor), Title: fmt.Sprintf("评价者:%s", t.CommentAuthor),
Link: fmt.Sprintf("%s/p/%d#comment-%d", wpconfig.Options.Value("siteurl"), post.Id, t.CommentId), 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.Title = fmt.Sprintf("\"%s\"的评论", wpconfig.Options.Value("blogname"))
rs.LastBuildDate = time.Now().Format(timeFormat) rs.LastBuildDate = time.Now().Format(timeFormat)
rs.AtomLink = fmt.Sprintf("%s/comments/feed", wpconfig.Options.Value("siteurl")) 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 return t.CommentId
})) }))
if nil != err { if nil != err {
return []string{}, 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) post, _ := cache2.GetPostById(c, t.CommentPostId)
plugins.PasswordProjectTitle(&post) plugins.PasswordProjectTitle(&post)
desc := "评论受保护:要查看请输入密码。" desc := "评论受保护:要查看请输入密码。"

View File

@ -7,7 +7,7 @@ import (
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/cache" "github/fthvgb1/wp-go/internal/cache"
dao "github/fthvgb1/wp-go/internal/dao" 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/plugins"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"

View File

@ -3,21 +3,21 @@ package cache
import ( import (
"context" "context"
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/internal/config"
dao "github/fthvgb1/wp-go/internal/dao" dao "github/fthvgb1/wp-go/internal/dao"
"github/fthvgb1/wp-go/internal/logs" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/logs"
models2 "github/fthvgb1/wp-go/internal/pkg/models"
"sync" "sync"
"time" "time"
) )
var postContextCache *cache.MapCache[uint64, dao.PostContext] var postContextCache *cache.MapCache[uint64, dao.PostContext]
var archivesCaches *Arch var archivesCaches *Arch
var categoryCaches *cache.SliceCache[models.TermsMy] var categoryCaches *cache.SliceCache[models2.TermsMy]
var recentPostsCaches *cache.SliceCache[models.Posts] var recentPostsCaches *cache.SliceCache[models2.Posts]
var recentCommentsCaches *cache.SliceCache[models.Comments] var recentCommentsCaches *cache.SliceCache[models2.Comments]
var postCommentCaches *cache.MapCache[uint64, []uint64] 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] 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 searchPostIdsCache *cache.MapCache[string, dao.PostIds]
var maxPostIdCache *cache.SliceCache[uint64] var maxPostIdCache *cache.SliceCache[uint64]
var usersCache *cache.MapCache[uint64, models.Users] var usersCache *cache.MapCache[uint64, models2.Users]
var usersNameCache *cache.MapCache[string, models.Users] var usersNameCache *cache.MapCache[string, models2.Users]
var commentsCache *cache.MapCache[uint64, models.Comments] var commentsCache *cache.MapCache[uint64, models2.Comments]
func InitActionsCommonCache() { func InitActionsCommonCache() {
c := config.Conf.Load() c := config.Conf.Load()
@ -45,25 +45,25 @@ func InitActionsCommonCache() {
postContextCache = cache.NewMapCacheByFn[uint64, dao.PostContext](dao.GetPostContext, c.ContextPostCacheTime) 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) 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) postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](dao.PostComments, c.PostCommentsCacheTime)
maxPostIdCache = cache.NewSliceCache[uint64](dao.GetMaxPostId, c.MaxPostIdCacheTime) 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() { func ClearCache() {
@ -89,18 +89,18 @@ func FlushCache() {
usersCache.Flush() usersCache.Flush()
} }
func Archives(ctx context.Context) (r []models.PostArchive) { func Archives(ctx context.Context) (r []models2.PostArchive) {
return archivesCaches.getArchiveCache(ctx) return archivesCaches.getArchiveCache(ctx)
} }
type Arch struct { type Arch struct {
data []models.PostArchive data []models2.PostArchive
mutex *sync.Mutex mutex *sync.Mutex
setCacheFunc func(context.Context) ([]models.PostArchive, error) setCacheFunc func(context.Context) ([]models2.PostArchive, error)
month time.Month 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) l := len(c.data)
m := time.Now().Month() m := time.Now().Month()
if l > 0 && c.month != m || l < 1 { if l > 0 && c.month != m || l < 1 {
@ -117,7 +117,7 @@ func (c *Arch) getArchiveCache(ctx context.Context) []models.PostArchive {
return c.data 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) r, err := categoryCaches.GetCache(ctx, time.Second, ctx)
logs.ErrPrintln(err, "get category ") logs.ErrPrintln(err, "get category ")
return r return r

View File

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

View File

@ -3,7 +3,7 @@ package cache
import ( import (
"context" "context"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
wp2 "github/fthvgb1/wp-go/internal/models" wp2 "github/fthvgb1/wp-go/internal/pkg/models"
"strconv" "strconv"
"time" "time"
) )

View File

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"time" "time"
) )

View File

@ -2,8 +2,8 @@ package cache
import ( import (
"context" "context"
"github/fthvgb1/wp-go/internal/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"time" "time"
) )

View File

@ -3,7 +3,7 @@ package common
import ( import (
"context" "context"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"strconv" "strconv"
) )

View File

@ -3,7 +3,7 @@ package common
import ( import (
"context" "context"
"fmt" "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/internal/wpconfig"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
) )
@ -16,20 +16,20 @@ type PostIds struct {
} }
type PostContext struct { type PostContext struct {
Prev models.Posts Prev models2.Posts
Next models.Posts Next models2.Posts
} }
func PasswordProjectTitle(post *models.Posts) { func PasswordProjectTitle(post *models2.Posts) {
if post.PostPassword != "" { if post.PostPassword != "" {
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle) 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) ctx := a[0].(context.Context)
var in = []any{"category"} 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.count", ">", "0", "int"},
{"tt.taxonomy", "in", ""}, {"tt.taxonomy", "in", ""},
}, "t.term_id", "", model.SqlBuilder{ }, "t.term_id", "", model.SqlBuilder{
@ -48,8 +48,8 @@ func Categories(a ...any) (terms []models.TermsMy, err error) {
return return
} }
func Archives(ctx context.Context) ([]models.PostArchive, error) { func Archives(ctx context.Context) ([]models2.PostArchive, error) {
return model.Find[models.PostArchive](ctx, model.SqlBuilder{ return model.Find[models2.PostArchive](ctx, model.SqlBuilder{
{"post_type", "post"}, {"post_status", "publish"}, {"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) }, "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)
} }

View File

@ -4,8 +4,8 @@ import (
"context" "context"
"github.com/leeqvip/gophp" "github.com/leeqvip/gophp"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/logs" "github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/models" models2 "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"strconv" "strconv"
) )
@ -14,7 +14,7 @@ func GetPostMetaByPostIds(args ...any) (r map[uint64]map[string]any, err error)
r = make(map[uint64]map[string]any) r = make(map[uint64]map[string]any)
ctx := args[0].(context.Context) ctx := args[0].(context.Context)
ids := args[1].([]uint64) 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", ""}, {"post_id", "in", ""},
}, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64])) }, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64]))
if err != nil { if err != nil {
@ -42,7 +42,7 @@ func GetPostMetaByPostIds(args ...any) (r map[uint64]map[string]any, err error)
return 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 { if meta != nil {
m, ok := meta["_thumbnail_id"] m, ok := meta["_thumbnail_id"]
if ok { if ok {

View File

@ -5,7 +5,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"strings" "strings"
"sync/atomic" "sync/atomic"

View File

@ -2,7 +2,7 @@ package common
import ( import (
"context" "context"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
) )

View File

@ -4,7 +4,7 @@ import (
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"github.com/soxfmr/gomail" "github.com/soxfmr/gomail"
"github/fthvgb1/wp-go/internal/config" "github/fthvgb1/wp-go/internal/pkg/config"
"mime" "mime"
"path" "path"
) )

View File

@ -1,7 +1,7 @@
package mail package mail
import ( import (
"github/fthvgb1/wp-go/internal/config" "github/fthvgb1/wp-go/internal/pkg/config"
"testing" "testing"
) )

View File

@ -4,9 +4,9 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/gin-gonic/gin" "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/mail"
"github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/pkg/logs"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"
"io" "io"
"io/ioutil" "io/ioutil"

View File

@ -2,7 +2,7 @@ package middleware
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/internal/config" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/safety" "github/fthvgb1/wp-go/safety"
"net/http" "net/http"
"strings" "strings"

View File

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github/fthvgb1/wp-go/internal/config" "github/fthvgb1/wp-go/internal/pkg/config"
"log" "log"
"os" "os"
"strconv" "strconv"

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/internal/config" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/plugin/digest" "github/fthvgb1/wp-go/plugin/digest"
"strings" "strings"
"time" "time"

View File

@ -3,7 +3,7 @@ package plugins
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "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] { func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[models.Posts] {

View File

@ -7,8 +7,8 @@ import (
"github.com/gin-contrib/sessions/cookie" "github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
actions2 "github/fthvgb1/wp-go/internal/actions" actions2 "github/fthvgb1/wp-go/internal/actions"
"github/fthvgb1/wp-go/internal/config"
middleware2 "github/fthvgb1/wp-go/internal/middleware" 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/static"
"github/fthvgb1/wp-go/internal/templates" "github/fthvgb1/wp-go/internal/templates"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"

View File

@ -2,7 +2,7 @@ package wpconfig
import ( import (
"context" "context"
"github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"github/fthvgb1/wp-go/safety" "github/fthvgb1/wp-go/safety"
) )

View File

@ -2,24 +2,24 @@ package wpconfig
import ( import (
"context" "context"
wp2 "github/fthvgb1/wp-go/internal/models" "github/fthvgb1/wp-go/internal/pkg/models"
"github/fthvgb1/wp-go/model" "github/fthvgb1/wp-go/model"
"github/fthvgb1/wp-go/safety" "github/fthvgb1/wp-go/safety"
) )
var Terms safety.Map[uint64, wp2.Terms] var Terms safety.Map[uint64, models.Terms]
var TermTaxonomies safety.Map[uint64, wp2.TermTaxonomy] var TermTaxonomies safety.Map[uint64, models.TermTaxonomy]
func InitTerms() (err error) { func InitTerms() (err error) {
ctx := context.Background() ctx := context.Background()
terms, err := model.SimpleFind[wp2.Terms](ctx, nil, "*") terms, err := model.SimpleFind[models.Terms](ctx, nil, "*")
if err != nil { if err != nil {
return err return err
} }
for _, wpTerms := range terms { for _, wpTerms := range terms {
Terms.Store(wpTerms.TermId, wpTerms) Terms.Store(wpTerms.TermId, wpTerms)
} }
termTax, err := model.SimpleFind[wp2.TermTaxonomy](ctx, nil, "*") termTax, err := model.SimpleFind[models.TermTaxonomy](ctx, nil, "*")
if err != nil { if err != nil {
return err return err
} }

View File

@ -5,10 +5,10 @@ import (
"fmt" "fmt"
"github/fthvgb1/wp-go/internal/actions" "github/fthvgb1/wp-go/internal/actions"
"github/fthvgb1/wp-go/internal/cache" "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/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/plugins"
"github/fthvgb1/wp-go/internal/route" "github/fthvgb1/wp-go/internal/route"
"github/fthvgb1/wp-go/internal/wpconfig" "github/fthvgb1/wp-go/internal/wpconfig"

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"database/sql" "database/sql"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/internal/config" "github/fthvgb1/wp-go/internal/pkg/config"
"github/fthvgb1/wp-go/internal/db" "github/fthvgb1/wp-go/internal/pkg/db"
"github/fthvgb1/wp-go/internal/models" models2 "github/fthvgb1/wp-go/internal/pkg/models"
"reflect" "reflect"
"testing" "testing"
) )
@ -36,7 +36,7 @@ func TestFind(t *testing.T) {
in [][]any in [][]any
} }
type posts struct { type posts struct {
models.Posts models2.Posts
N int `db:"n"` N int `db:"n"`
} }
tests := []struct { tests := []struct {
@ -107,7 +107,7 @@ func TestFind(t *testing.T) {
in: nil, in: nil,
}, },
wantR: func() []posts { 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 { if err != nil {
panic(err) panic(err)
} }
@ -152,10 +152,10 @@ func TestFind(t *testing.T) {
group: "a.post_author", group: "a.post_author",
order: SqlBuilder{{"n", "desc"}}, order: SqlBuilder{{"n", "desc"}},
join: SqlBuilder{ 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", "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", models2.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.Terms{}.Table() + " e", "d.term_id=e.term_id"},
}, },
having: SqlBuilder{{"n", ">", "0", "int"}}, having: SqlBuilder{{"n", ">", "0", "int"}},
limit: 10, limit: 10,
@ -193,7 +193,7 @@ func TestFindOneById(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want models.Posts want models2.Posts
wantErr bool wantErr bool
}{ }{
{ {
@ -201,8 +201,8 @@ func TestFindOneById(t *testing.T) {
args: args{ args: args{
1, 1,
}, },
want: func() models.Posts { want: func() models2.Posts {
r, err := Get[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where ID=?", 1) r, err := Get[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where ID=?", 1)
if err != nil && err != sql.ErrNoRows { if err != nil && err != sql.ErrNoRows {
panic(err) panic(err)
} else if err == sql.ErrNoRows { } else if err == sql.ErrNoRows {
@ -215,7 +215,7 @@ func TestFindOneById(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if err == sql.ErrNoRows {
err = nil err = nil
} }
@ -240,7 +240,7 @@ func TestFirstOne(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want models.Posts want models2.Posts
wantErr bool wantErr bool
}{ }{
{ {
@ -252,8 +252,8 @@ func TestFirstOne(t *testing.T) {
in: nil, in: nil,
}, },
wantErr: false, wantErr: false,
want: func() models.Posts { want: func() models2.Posts {
r, err := Get[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where post_status='publish' order by ID desc limit 1") 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 { if err != nil && err != sql.ErrNoRows {
panic(err) panic(err)
} else if err == sql.ErrNoRows { } else if err == sql.ErrNoRows {
@ -265,7 +265,7 @@ func TestFirstOne(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if (err != nil) != tt.wantErr {
t.Errorf("FirstOne() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("FirstOne() error = %v, wantErr %v", err, tt.wantErr)
return return
@ -286,7 +286,7 @@ func TestLastOne(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want models.Posts want models2.Posts
wantErr bool wantErr bool
}{ }{
{ {
@ -298,8 +298,8 @@ func TestLastOne(t *testing.T) {
fields: "*", fields: "*",
in: nil, in: nil,
}, },
want: func() models.Posts { want: func() models2.Posts {
r, err := Get[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where post_status='publish' order by "+models.Posts{}.PrimaryKey()+" desc limit 1") 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 { if err != nil {
panic(err) panic(err)
} }
@ -309,7 +309,7 @@ func TestLastOne(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if (err != nil) != tt.wantErr {
t.Errorf("LastOne() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("LastOne() error = %v, wantErr %v", err, tt.wantErr)
return return
@ -330,7 +330,7 @@ func TestSimpleFind(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
want []models.Posts want []models2.Posts
wantErr bool wantErr bool
}{ }{
{ {
@ -342,8 +342,8 @@ func TestSimpleFind(t *testing.T) {
fields: "*", fields: "*",
in: [][]any{{1, 2}}, in: [][]any{{1, 2}},
}, },
want: func() (r []models.Posts) { want: func() (r []models2.Posts) {
r, err := Select[models.Posts](ctx, "select * from "+models.Posts{}.Table()+" where ID in (?,?)", 1, 2) r, err := Select[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where ID in (?,?)", 1, 2)
if err != nil && err != sql.ErrNoRows { if err != nil && err != sql.ErrNoRows {
panic(err) panic(err)
} else if err == sql.ErrNoRows { } else if err == sql.ErrNoRows {
@ -356,7 +356,7 @@ func TestSimpleFind(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if (err != nil) != tt.wantErr {
t.Errorf("SimpleFind() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("SimpleFind() error = %v, wantErr %v", err, tt.wantErr)
return return
@ -383,7 +383,7 @@ func TestSimplePagination(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
args args args args
wantR []models.Posts wantR []models2.Posts
wantTotal int wantTotal int
wantErr bool wantErr bool
}{ }{
@ -402,8 +402,8 @@ func TestSimplePagination(t *testing.T) {
having: nil, having: nil,
in: [][]any{helper.SliceMap[int, any](helper.RangeSlice(431, 440, 1), helper.ToAny[int])}, in: [][]any{helper.SliceMap[int, any](helper.RangeSlice(431, 440, 1), helper.ToAny[int])},
}, },
wantR: func() (r []models.Posts) { wantR: func() (r []models2.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])...) 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 { if err != nil && err != sql.ErrNoRows {
panic(err) panic(err)
} else if err == sql.ErrNoRows { } else if err == sql.ErrNoRows {
@ -417,7 +417,7 @@ func TestSimplePagination(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { 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 { if (err != nil) != tt.wantErr {
t.Errorf("SimplePagination() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("SimplePagination() error = %v, wantErr %v", err, tt.wantErr)
return return