diff --git a/internal/actions/comment.go b/internal/actions/comment.go index ce7633e..16cd4af 100644 --- a/internal/actions/comment.go +++ b/internal/actions/comment.go @@ -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" diff --git a/internal/actions/detail.go b/internal/actions/detail.go index ba1a410..d2be751 100644 --- a/internal/actions/detail.go +++ b/internal/actions/detail.go @@ -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" diff --git a/internal/actions/feed.go b/internal/actions/feed.go index bcff47d..769517a 100644 --- a/internal/actions/feed.go +++ b/internal/actions/feed.go @@ -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 := "评论受保护:要查看请输入密码。" diff --git a/internal/actions/index.go b/internal/actions/index.go index b7b539d..680c915 100644 --- a/internal/actions/index.go +++ b/internal/actions/index.go @@ -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" diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 5e020bd..ed9eee2 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -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 diff --git a/internal/cache/comments.go b/internal/cache/comments.go index c22b9bf..ae29a81 100644 --- a/internal/cache/comments.go +++ b/internal/cache/comments.go @@ -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" ) diff --git a/internal/cache/postmeta.go b/internal/cache/postmeta.go index faa0ae0..e061db9 100644 --- a/internal/cache/postmeta.go +++ b/internal/cache/postmeta.go @@ -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" ) diff --git a/internal/cache/posts.go b/internal/cache/posts.go index f97809c..1eb79ee 100644 --- a/internal/cache/posts.go +++ b/internal/cache/posts.go @@ -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" ) diff --git a/internal/cache/users.go b/internal/cache/users.go index a6fe103..a5c12d6 100644 --- a/internal/cache/users.go +++ b/internal/cache/users.go @@ -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" ) diff --git a/internal/dao/comments.go b/internal/dao/comments.go index cc9e975..4624c59 100644 --- a/internal/dao/comments.go +++ b/internal/dao/comments.go @@ -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" ) diff --git a/internal/dao/common.go b/internal/dao/common.go index f43d8ec..24de4ca 100644 --- a/internal/dao/common.go +++ b/internal/dao/common.go @@ -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) } diff --git a/internal/dao/postmeta.go b/internal/dao/postmeta.go index 9683ee4..e8d6237 100644 --- a/internal/dao/postmeta.go +++ b/internal/dao/postmeta.go @@ -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 { diff --git a/internal/dao/posts.go b/internal/dao/posts.go index d6cfb69..65c1f88 100644 --- a/internal/dao/posts.go +++ b/internal/dao/posts.go @@ -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" diff --git a/internal/dao/users.go b/internal/dao/users.go index 93e8249..f411d6c 100644 --- a/internal/dao/users.go +++ b/internal/dao/users.go @@ -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" ) diff --git a/internal/mail/mail.go b/internal/mail/mail.go index 9990372..6edf2f6 100644 --- a/internal/mail/mail.go +++ b/internal/mail/mail.go @@ -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" ) diff --git a/internal/mail/mail_test.go b/internal/mail/mail_test.go index d86c5df..eb5b268 100644 --- a/internal/mail/mail_test.go +++ b/internal/mail/mail_test.go @@ -1,7 +1,7 @@ package mail import ( - "github/fthvgb1/wp-go/internal/config" + "github/fthvgb1/wp-go/internal/pkg/config" "testing" ) diff --git a/internal/middleware/sendmail.go b/internal/middleware/sendmail.go index b644b25..5ecd8a5 100644 --- a/internal/middleware/sendmail.go +++ b/internal/middleware/sendmail.go @@ -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" diff --git a/internal/middleware/validateservername.go b/internal/middleware/validateservername.go index 2d56966..88941e5 100644 --- a/internal/middleware/validateservername.go +++ b/internal/middleware/validateservername.go @@ -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" diff --git a/internal/config/config.go b/internal/pkg/config/config.go similarity index 100% rename from internal/config/config.go rename to internal/pkg/config/config.go diff --git a/internal/db/db.go b/internal/pkg/db/db.go similarity index 97% rename from internal/db/db.go rename to internal/pkg/db/db.go index 0eb5f98..791fe53 100644 --- a/internal/db/db.go +++ b/internal/pkg/db/db.go @@ -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" diff --git a/internal/logs/log.go b/internal/pkg/logs/log.go similarity index 100% rename from internal/logs/log.go rename to internal/pkg/logs/log.go diff --git a/internal/models/wp_comments.go b/internal/pkg/models/wp_comments.go similarity index 100% rename from internal/models/wp_comments.go rename to internal/pkg/models/wp_comments.go diff --git a/internal/models/wp_options.go b/internal/pkg/models/wp_options.go similarity index 100% rename from internal/models/wp_options.go rename to internal/pkg/models/wp_options.go diff --git a/internal/models/wp_postmeta.go b/internal/pkg/models/wp_postmeta.go similarity index 100% rename from internal/models/wp_postmeta.go rename to internal/pkg/models/wp_postmeta.go diff --git a/internal/models/wp_posts.go b/internal/pkg/models/wp_posts.go similarity index 100% rename from internal/models/wp_posts.go rename to internal/pkg/models/wp_posts.go diff --git a/internal/models/wp_term_taxonomy.go b/internal/pkg/models/wp_term_taxonomy.go similarity index 100% rename from internal/models/wp_term_taxonomy.go rename to internal/pkg/models/wp_term_taxonomy.go diff --git a/internal/models/wp_terms.go b/internal/pkg/models/wp_terms.go similarity index 100% rename from internal/models/wp_terms.go rename to internal/pkg/models/wp_terms.go diff --git a/internal/models/wp_users.go b/internal/pkg/models/wp_users.go similarity index 100% rename from internal/models/wp_users.go rename to internal/pkg/models/wp_users.go diff --git a/internal/plugins/digest.go b/internal/plugins/digest.go index 1cc88ec..258db7e 100644 --- a/internal/plugins/digest.go +++ b/internal/plugins/digest.go @@ -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" diff --git a/internal/plugins/posts.go b/internal/plugins/posts.go index 0004e45..d5ab416 100644 --- a/internal/plugins/posts.go +++ b/internal/plugins/posts.go @@ -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] { diff --git a/internal/route/route.go b/internal/route/route.go index 50e2744..9cbce7c 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -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" diff --git a/internal/wpconfig/options.go b/internal/wpconfig/options.go index 4ec373c..0e89d61 100644 --- a/internal/wpconfig/options.go +++ b/internal/wpconfig/options.go @@ -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" ) diff --git a/internal/wpconfig/term.go b/internal/wpconfig/term.go index 015b428..626b326 100644 --- a/internal/wpconfig/term.go +++ b/internal/wpconfig/term.go @@ -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 } diff --git a/main.go b/main.go index a91e225..436f1a3 100644 --- a/main.go +++ b/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" diff --git a/model/query_test.go b/model/query_test.go index e6d60d6..9f5213e 100644 --- a/model/query_test.go +++ b/model/query_test.go @@ -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