From 86adc60c51d6245c80b167e9082c68d36d4cd38c Mon Sep 17 00:00:00 2001 From: xing Date: Wed, 18 Jan 2023 23:02:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E8=B0=83=E6=95=B4=E5=8F=8A?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=8C=85=E5=90=8D=E8=B0=83=E6=95=B4=20github?= =?UTF-8?q?=3D>github.com=20=3D=3D!........?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache/map.go | 2 +- cache/slice.go | 2 +- go.mod | 6 +- internal/actions/comment.go | 14 +- internal/actions/detail.go | 12 +- internal/actions/feed.go | 44 ++--- internal/actions/login.go | 6 +- internal/cmd/route/route.go | 12 +- internal/mail/mail.go | 2 +- internal/mail/mail_test.go | 2 +- internal/middleware/flowLimit.go | 4 +- internal/middleware/sendmail.go | 8 +- internal/middleware/staticFileCache.go | 2 +- internal/middleware/validateservername.go | 4 +- internal/pkg/cache/cache.go | 10 +- internal/pkg/cache/comments.go | 4 +- internal/pkg/cache/posts.go | 6 +- internal/pkg/cache/users.go | 6 +- internal/pkg/config/config.go | 2 +- internal/pkg/dao/comments.go | 6 +- internal/pkg/dao/common.go | 6 +- internal/pkg/dao/postmeta.go | 8 +- internal/pkg/dao/posts.go | 8 +- internal/pkg/dao/users.go | 4 +- internal/pkg/db/db.go | 2 +- internal/pkg/models/wp_postmeta.go | 2 +- internal/plugins/digest.go | 8 +- internal/plugins/posts.go | 2 +- .../{templates/templatefs.go => theme/fs.go} | 4 +- .../{templates => theme}/templateFuncs.go | 14 +- .../twentyfifteen/layout/base.gohtml | 0 .../twentyfifteen/layout/empty.gohtml | 0 .../twentyfifteen/layout/footer.gohtml | 0 .../twentyfifteen/layout/head.gohtml | 0 .../twentyfifteen/layout/message.gohtml | 0 .../twentyfifteen/layout/pagination.gohtml | 0 .../twentyfifteen/layout/sidebar.gohtml | 0 .../twentyfifteen/layout/svg.gohtml | 0 .../twentyfifteen/posts/detail.gohtml | 0 .../twentyfifteen/posts/index.gohtml | 0 .../twentyseventeen/layout/base.gohtml | 6 +- .../twentyseventeen/layout/empty.gohtml | 0 .../twentyseventeen/layout/footer.gohtml | 0 .../twentyseventeen/layout/footersvg.gohtml | 0 .../twentyseventeen/layout/head.gohtml | 0 .../twentyseventeen/layout/message.gohtml | 0 .../twentyseventeen/layout/pagination.gohtml | 0 .../twentyseventeen/layout/sidebar.gohtml | 0 .../twentyseventeen/layout/svg.gohtml | 0 .../twentyseventeen/posts/detail.gohtml | 0 .../twentyseventeen/posts/index.gohtml | 0 .../twentyseventeen/twentyseventeen.go} | 34 +++- internal/wpconfig/options.go | 6 +- internal/wpconfig/term.go | 6 +- model/parse.go | 2 +- model/query.go | 2 +- model/query_test.go | 167 ++++++++++++++---- phpass/phpass.go | 2 +- plugin/digest/digest.go | 2 +- rss2/rss2.go | 2 +- safety/slice_test.go | 2 +- stream/simpleMapStream.go | 4 +- stream/simpleMapStream_test.go | 2 +- stream/simpleStream.go | 6 +- stream/simpleStream_test.go | 2 +- 65 files changed, 283 insertions(+), 174 deletions(-) rename internal/{templates/templatefs.go => theme/fs.go} (96%) rename internal/{templates => theme}/templateFuncs.go (65%) rename internal/{templates => theme}/twentyfifteen/layout/base.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/layout/empty.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/layout/footer.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/layout/head.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/layout/message.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/layout/pagination.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/layout/sidebar.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/layout/svg.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/posts/detail.gohtml (100%) rename internal/{templates => theme}/twentyfifteen/posts/index.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/base.gohtml (92%) rename internal/{templates => theme}/twentyseventeen/layout/empty.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/footer.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/footersvg.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/head.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/message.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/pagination.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/sidebar.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/layout/svg.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/posts/detail.gohtml (100%) rename internal/{templates => theme}/twentyseventeen/posts/index.gohtml (100%) rename internal/{templates/twentyseventeen/theme.go => theme/twentyseventeen/twentyseventeen.go} (59%) diff --git a/cache/map.go b/cache/map.go index af39271..50e661a 100644 --- a/cache/map.go +++ b/cache/map.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "github/fthvgb1/wp-go/safety" + "github.com/fthvgb1/wp-go/safety" "sync" "time" ) diff --git a/cache/slice.go b/cache/slice.go index f43bede..e19ba89 100644 --- a/cache/slice.go +++ b/cache/slice.go @@ -4,7 +4,7 @@ import ( "context" "errors" "fmt" - "github/fthvgb1/wp-go/safety" + "github.com/fthvgb1/wp-go/safety" "sync" "time" ) diff --git a/go.mod b/go.mod index dde91cd..0d0215e 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,23 @@ -module github/fthvgb1/wp-go +module github.com/fthvgb1/wp-go go 1.18 require ( github.com/dlclark/regexp2 v1.7.0 + github.com/elliotchance/phpserialize v1.3.3 github.com/gin-contrib/gzip v0.0.6 github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/sessions v0.0.5 github.com/gin-gonic/gin v1.8.1 github.com/go-sql-driver/mysql v1.6.0 github.com/jmoiron/sqlx v1.3.5 + github.com/leeqvip/gophp v1.0.0 github.com/soxfmr/gomail v0.0.0-20200806033254-80bf84e583f0 golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 gopkg.in/yaml.v2 v2.4.0 ) require ( - github.com/elliotchance/phpserialize v1.3.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect @@ -26,7 +27,6 @@ require ( github.com/gorilla/securecookie v1.1.1 // indirect github.com/gorilla/sessions v1.2.1 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/leeqvip/gophp v1.0.0 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/mattn/go-isatty v0.0.16 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/internal/actions/comment.go b/internal/actions/comment.go index 5436d89..2b86d7b 100644 --- a/internal/actions/comment.go +++ b/internal/actions/comment.go @@ -4,14 +4,14 @@ import ( "bytes" "errors" "fmt" + "github.com/fthvgb1/wp-go/cache" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/internal/mail" + cache2 "github.com/fthvgb1/wp-go/internal/pkg/cache" + "github.com/fthvgb1/wp-go/internal/pkg/config" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/cache" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/mail" - cache2 "github/fthvgb1/wp-go/internal/pkg/cache" - "github/fthvgb1/wp-go/internal/pkg/config" - "github/fthvgb1/wp-go/internal/pkg/logs" - "github/fthvgb1/wp-go/internal/wpconfig" "io" "net/http" "net/url" diff --git a/internal/actions/detail.go b/internal/actions/detail.go index 98dea0c..9489d7d 100644 --- a/internal/actions/detail.go +++ b/internal/actions/detail.go @@ -2,14 +2,14 @@ package actions import ( "fmt" + "github.com/fthvgb1/wp-go/helper" + cache2 "github.com/fthvgb1/wp-go/internal/pkg/cache" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/internal/plugins" + "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/helper" - cache2 "github/fthvgb1/wp-go/internal/pkg/cache" - "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" "net/http" "net/url" diff --git a/internal/actions/feed.go b/internal/actions/feed.go index 857d39e..0e67077 100644 --- a/internal/actions/feed.go +++ b/internal/actions/feed.go @@ -2,16 +2,16 @@ package actions import ( "fmt" + "github.com/fthvgb1/wp-go/cache" + "github.com/fthvgb1/wp-go/helper" + cache2 "github.com/fthvgb1/wp-go/internal/pkg/cache" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/internal/plugins" + "github.com/fthvgb1/wp-go/internal/wpconfig" + "github.com/fthvgb1/wp-go/plugin/digest" + "github.com/fthvgb1/wp-go/rss2" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/cache" - "github/fthvgb1/wp-go/helper" - cache3 "github/fthvgb1/wp-go/internal/pkg/cache" - "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" - "github/fthvgb1/wp-go/rss2" "net/http" "strconv" "strings" @@ -78,17 +78,17 @@ func Feed(c *gin.Context) { func feed(arg ...any) (xml []string, err error) { c := arg[0].(*gin.Context) - r := cache3.RecentPosts(c, 10) - ids := helper.SliceMap(r, func(t models2.Posts) uint64 { + r := cache2.RecentPosts(c, 10) + ids := helper.SliceMap(r, func(t models.Posts) uint64 { return t.Id }) - posts, err := cache3.GetPostsByIds(c, ids) + posts, err := cache2.GetPostsByIds(c, ids) if err != nil { return } rs := templateRss rs.LastBuildDate = time.Now().Format(timeFormat) - rs.Items = helper.SliceMap(posts, func(t models2.Posts) rss2.Item { + rs.Items = helper.SliceMap(posts, func(t models.Posts) rss2.Item { desc := "无法提供摘要。这是一篇受保护的文章。" plugins.PasswordProjectTitle(&t) if t.PostPassword != "" { @@ -102,7 +102,7 @@ func feed(arg ...any) (xml []string, err error) { } else if t.CommentStatus == "open" && t.CommentCount == 0 { l = fmt.Sprintf("%s/p/%d#respond", wpconfig.Options.Value("siteurl"), t.Id) } - user := cache3.GetUserById(c, t.PostAuthor) + user := cache2.GetUserById(c, t.PostAuthor) return rss2.Item{ Title: t.PostTitle, @@ -158,17 +158,17 @@ func postFeed(arg ...any) (x string, err error) { } } ID := uint64(Id) - maxId, err := cache3.GetMaxPostId(c) + maxId, err := cache2.GetMaxPostId(c) logs.ErrPrintln(err, "get max post id") if ID > maxId || err != nil { return } - post, err := cache3.GetPostById(c, ID) + post, err := cache2.GetPostById(c, ID) if post.Id == 0 || err != nil { return } plugins.PasswordProjectTitle(&post) - comments, err := cache3.PostComments(c, post.Id) + comments, err := cache2.PostComments(c, post.Id) if err != nil { return } @@ -195,7 +195,7 @@ func postFeed(arg ...any) (x string, err error) { } } } else { - rs.Items = helper.SliceMap(comments, func(t models2.Comments) rss2.Item { + rs.Items = helper.SliceMap(comments, func(t models.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), @@ -228,19 +228,19 @@ func CommentsFeed(c *gin.Context) { func commentsFeed(args ...any) (r []string, err error) { c := args[0].(*gin.Context) - commens := cache3.RecentComments(c, 10) + commens := cache2.RecentComments(c, 10) rs := templateRss rs.Title = fmt.Sprintf("\"%s\"的评论", wpconfig.Options.Value("blogname")) rs.LastBuildDate = time.Now().Format(timeFormat) rs.AtomLink = fmt.Sprintf("%s/comments/feed", wpconfig.Options.Value("siteurl")) - com, err := cache3.GetCommentByIds(c, helper.SliceMap(commens, func(t models2.Comments) uint64 { + com, err := cache2.GetCommentByIds(c, helper.SliceMap(commens, func(t models.Comments) uint64 { return t.CommentId })) if nil != err { return []string{}, err } - rs.Items = helper.SliceMap(com, func(t models2.Comments) rss2.Item { - post, _ := cache3.GetPostById(c, t.CommentPostId) + rs.Items = helper.SliceMap(com, func(t models.Comments) rss2.Item { + post, _ := cache2.GetPostById(c, t.CommentPostId) plugins.PasswordProjectTitle(&post) desc := "评论受保护:要查看请输入密码。" content := t.CommentContent diff --git a/internal/actions/login.go b/internal/actions/login.go index 2c0b597..2bd1f32 100644 --- a/internal/actions/login.go +++ b/internal/actions/login.go @@ -2,11 +2,11 @@ package actions import ( "fmt" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/internal/wpconfig" + "github.com/fthvgb1/wp-go/phpass" "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/wpconfig" - "github/fthvgb1/wp-go/phpass" "net/http" "strings" ) diff --git a/internal/cmd/route/route.go b/internal/cmd/route/route.go index 25ad503..052eec5 100644 --- a/internal/cmd/route/route.go +++ b/internal/cmd/route/route.go @@ -1,16 +1,16 @@ package route import ( + "github.com/fthvgb1/wp-go/internal/actions" + "github.com/fthvgb1/wp-go/internal/middleware" + "github.com/fthvgb1/wp-go/internal/pkg/config" + "github.com/fthvgb1/wp-go/internal/static" + "github.com/fthvgb1/wp-go/internal/theme" "github.com/gin-contrib/gzip" "github.com/gin-contrib/pprof" "github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions/cookie" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/internal/actions" - "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" "net/http" ) @@ -26,7 +26,7 @@ func SetupRouter() (*gin.Engine, func()) { } } - r.HTMLRender = templates.NewFsTemplate(templates.FuncMap()).SetTemplate() + r.HTMLRender = theme.NewFsTemplate(theme.FuncMap()).SetTemplate() validServerName, reloadValidServerNameFn := middleware.ValidateServerNames() fl, flReload := middleware.FlowLimit(c.MaxRequestSleepNum, c.MaxRequestNum, c.SleepTime) r.Use( diff --git a/internal/mail/mail.go b/internal/mail/mail.go index 6edf2f6..81595aa 100644 --- a/internal/mail/mail.go +++ b/internal/mail/mail.go @@ -3,8 +3,8 @@ package mail import ( "crypto/tls" "fmt" + "github.com/fthvgb1/wp-go/internal/pkg/config" "github.com/soxfmr/gomail" - "github/fthvgb1/wp-go/internal/pkg/config" "mime" "path" ) diff --git a/internal/mail/mail_test.go b/internal/mail/mail_test.go index eb5b268..76fbf32 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/pkg/config" + "github.com/fthvgb1/wp-go/internal/pkg/config" "testing" ) diff --git a/internal/middleware/flowLimit.go b/internal/middleware/flowLimit.go index 80ad034..82aeaee 100644 --- a/internal/middleware/flowLimit.go +++ b/internal/middleware/flowLimit.go @@ -1,9 +1,9 @@ package middleware import ( + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/safety" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/safety" "net/http" "strings" "sync/atomic" diff --git a/internal/middleware/sendmail.go b/internal/middleware/sendmail.go index 5ecd8a5..2653a52 100644 --- a/internal/middleware/sendmail.go +++ b/internal/middleware/sendmail.go @@ -3,11 +3,11 @@ package middleware import ( "bytes" "fmt" + "github.com/fthvgb1/wp-go/internal/mail" + "github.com/fthvgb1/wp-go/internal/pkg/config" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/gin-gonic/gin" - "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" "net/http" diff --git a/internal/middleware/staticFileCache.go b/internal/middleware/staticFileCache.go index 022392c..3e13e23 100644 --- a/internal/middleware/staticFileCache.go +++ b/internal/middleware/staticFileCache.go @@ -1,8 +1,8 @@ package middleware import ( + "github.com/fthvgb1/wp-go/helper" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/helper" "strings" ) diff --git a/internal/middleware/validateservername.go b/internal/middleware/validateservername.go index 88941e5..444b80d 100644 --- a/internal/middleware/validateservername.go +++ b/internal/middleware/validateservername.go @@ -1,9 +1,9 @@ package middleware import ( + "github.com/fthvgb1/wp-go/internal/pkg/config" + "github.com/fthvgb1/wp-go/safety" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/internal/pkg/config" - "github/fthvgb1/wp-go/safety" "net/http" "strings" ) diff --git a/internal/pkg/cache/cache.go b/internal/pkg/cache/cache.go index 090ec3a..4f4029b 100644 --- a/internal/pkg/cache/cache.go +++ b/internal/pkg/cache/cache.go @@ -2,11 +2,11 @@ package cache import ( "context" - "github/fthvgb1/wp-go/cache" - "github/fthvgb1/wp-go/internal/pkg/config" - "github/fthvgb1/wp-go/internal/pkg/dao" - "github/fthvgb1/wp-go/internal/pkg/logs" - "github/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/cache" + "github.com/fthvgb1/wp-go/internal/pkg/config" + "github.com/fthvgb1/wp-go/internal/pkg/dao" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" "sync" "time" ) diff --git a/internal/pkg/cache/comments.go b/internal/pkg/cache/comments.go index ae29a81..2a25eaa 100644 --- a/internal/pkg/cache/comments.go +++ b/internal/pkg/cache/comments.go @@ -2,8 +2,8 @@ package cache import ( "context" - "github/fthvgb1/wp-go/internal/pkg/logs" - "github/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" "time" ) diff --git a/internal/pkg/cache/posts.go b/internal/pkg/cache/posts.go index 1eb79ee..6784b9a 100644 --- a/internal/pkg/cache/posts.go +++ b/internal/pkg/cache/posts.go @@ -3,10 +3,10 @@ package cache import ( "context" "fmt" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/pkg/logs" - "github/fthvgb1/wp-go/internal/pkg/models" "time" ) diff --git a/internal/pkg/cache/users.go b/internal/pkg/cache/users.go index a5c12d6..348578b 100644 --- a/internal/pkg/cache/users.go +++ b/internal/pkg/cache/users.go @@ -2,9 +2,9 @@ package cache import ( "context" - "github/fthvgb1/wp-go/internal/pkg/logs" - "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/model" "time" ) diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index ff4b312..d3370d0 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -2,7 +2,7 @@ package config import ( "fmt" - "github/fthvgb1/wp-go/safety" + "github.com/fthvgb1/wp-go/safety" "gopkg.in/yaml.v2" "os" "time" diff --git a/internal/pkg/dao/comments.go b/internal/pkg/dao/comments.go index 4624c59..6d289e0 100644 --- a/internal/pkg/dao/comments.go +++ b/internal/pkg/dao/comments.go @@ -2,9 +2,9 @@ package common import ( "context" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/model" "strconv" ) diff --git a/internal/pkg/dao/common.go b/internal/pkg/dao/common.go index 24de4ca..23d1189 100644 --- a/internal/pkg/dao/common.go +++ b/internal/pkg/dao/common.go @@ -3,9 +3,9 @@ package common import ( "context" "fmt" - models2 "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/internal/wpconfig" - "github/fthvgb1/wp-go/model" + models2 "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/internal/wpconfig" + "github.com/fthvgb1/wp-go/model" ) var TotalRaw int64 diff --git a/internal/pkg/dao/postmeta.go b/internal/pkg/dao/postmeta.go index 8fefefd..d9a92f6 100644 --- a/internal/pkg/dao/postmeta.go +++ b/internal/pkg/dao/postmeta.go @@ -3,10 +3,10 @@ package common import ( "context" "fmt" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/pkg/logs" - "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/model" "strconv" "strings" ) diff --git a/internal/pkg/dao/posts.go b/internal/pkg/dao/posts.go index aabc8da..cea3b28 100644 --- a/internal/pkg/dao/posts.go +++ b/internal/pkg/dao/posts.go @@ -4,10 +4,10 @@ import ( "context" "database/sql" "fmt" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/internal/wpconfig" - "github/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/internal/wpconfig" + "github.com/fthvgb1/wp-go/model" "strings" "sync/atomic" "time" diff --git a/internal/pkg/dao/users.go b/internal/pkg/dao/users.go index f411d6c..6da26de 100644 --- a/internal/pkg/dao/users.go +++ b/internal/pkg/dao/users.go @@ -2,8 +2,8 @@ package common import ( "context" - "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/model" ) func GetUserById(a ...any) (r models.Users, err error) { diff --git a/internal/pkg/db/db.go b/internal/pkg/db/db.go index 791fe53..a7196c9 100644 --- a/internal/pkg/db/db.go +++ b/internal/pkg/db/db.go @@ -3,9 +3,9 @@ package db import ( "context" "fmt" + "github.com/fthvgb1/wp-go/internal/pkg/config" _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" - "github/fthvgb1/wp-go/internal/pkg/config" "log" "os" "strconv" diff --git a/internal/pkg/models/wp_postmeta.go b/internal/pkg/models/wp_postmeta.go index c4ef3aa..d4a1544 100644 --- a/internal/pkg/models/wp_postmeta.go +++ b/internal/pkg/models/wp_postmeta.go @@ -1,8 +1,8 @@ package models import ( + "github.com/fthvgb1/wp-go/helper" "github.com/leeqvip/gophp" - "github/fthvgb1/wp-go/helper" ) type Postmeta struct { diff --git a/internal/plugins/digest.go b/internal/plugins/digest.go index 258db7e..79162ec 100644 --- a/internal/plugins/digest.go +++ b/internal/plugins/digest.go @@ -2,11 +2,11 @@ package plugins import ( "fmt" + "github.com/fthvgb1/wp-go/cache" + "github.com/fthvgb1/wp-go/internal/pkg/config" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/plugin/digest" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/cache" - "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 d5ab416..e31a16e 100644 --- a/internal/plugins/posts.go +++ b/internal/plugins/posts.go @@ -2,8 +2,8 @@ package plugins import ( "fmt" + "github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/internal/pkg/models" ) func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[models.Posts] { diff --git a/internal/templates/templatefs.go b/internal/theme/fs.go similarity index 96% rename from internal/templates/templatefs.go rename to internal/theme/fs.go index a88662d..d0dbe7e 100644 --- a/internal/templates/templatefs.go +++ b/internal/theme/fs.go @@ -1,4 +1,4 @@ -package templates +package theme import ( "embed" @@ -9,7 +9,7 @@ import ( "strings" ) -//go:embed *[^templatefs.go] +//go:embed *[^.go] var TemplateFs embed.FS type FsTemplate struct { diff --git a/internal/templates/templateFuncs.go b/internal/theme/templateFuncs.go similarity index 65% rename from internal/templates/templateFuncs.go rename to internal/theme/templateFuncs.go index 3c941a2..6c8a814 100644 --- a/internal/templates/templateFuncs.go +++ b/internal/theme/templateFuncs.go @@ -1,8 +1,7 @@ -package templates +package theme import ( - "errors" - "github/fthvgb1/wp-go/internal/wpconfig" + "github.com/fthvgb1/wp-go/internal/wpconfig" "html/template" "time" ) @@ -23,14 +22,9 @@ func FuncMap() template.FuncMap { return funcs } -func InitTemplateFunc() { - -} - -func AddTemplateFunc(fnName string, fn any) error { +func AddTemplateFunc(fnName string, fn any) { if _, ok := funcs[fnName]; ok { - return errors.New("a same name func exists") + panic("exists same name func") } funcs[fnName] = fn - return nil } diff --git a/internal/templates/twentyfifteen/layout/base.gohtml b/internal/theme/twentyfifteen/layout/base.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/base.gohtml rename to internal/theme/twentyfifteen/layout/base.gohtml diff --git a/internal/templates/twentyfifteen/layout/empty.gohtml b/internal/theme/twentyfifteen/layout/empty.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/empty.gohtml rename to internal/theme/twentyfifteen/layout/empty.gohtml diff --git a/internal/templates/twentyfifteen/layout/footer.gohtml b/internal/theme/twentyfifteen/layout/footer.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/footer.gohtml rename to internal/theme/twentyfifteen/layout/footer.gohtml diff --git a/internal/templates/twentyfifteen/layout/head.gohtml b/internal/theme/twentyfifteen/layout/head.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/head.gohtml rename to internal/theme/twentyfifteen/layout/head.gohtml diff --git a/internal/templates/twentyfifteen/layout/message.gohtml b/internal/theme/twentyfifteen/layout/message.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/message.gohtml rename to internal/theme/twentyfifteen/layout/message.gohtml diff --git a/internal/templates/twentyfifteen/layout/pagination.gohtml b/internal/theme/twentyfifteen/layout/pagination.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/pagination.gohtml rename to internal/theme/twentyfifteen/layout/pagination.gohtml diff --git a/internal/templates/twentyfifteen/layout/sidebar.gohtml b/internal/theme/twentyfifteen/layout/sidebar.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/sidebar.gohtml rename to internal/theme/twentyfifteen/layout/sidebar.gohtml diff --git a/internal/templates/twentyfifteen/layout/svg.gohtml b/internal/theme/twentyfifteen/layout/svg.gohtml similarity index 100% rename from internal/templates/twentyfifteen/layout/svg.gohtml rename to internal/theme/twentyfifteen/layout/svg.gohtml diff --git a/internal/templates/twentyfifteen/posts/detail.gohtml b/internal/theme/twentyfifteen/posts/detail.gohtml similarity index 100% rename from internal/templates/twentyfifteen/posts/detail.gohtml rename to internal/theme/twentyfifteen/posts/detail.gohtml diff --git a/internal/templates/twentyfifteen/posts/index.gohtml b/internal/theme/twentyfifteen/posts/index.gohtml similarity index 100% rename from internal/templates/twentyfifteen/posts/index.gohtml rename to internal/theme/twentyfifteen/posts/index.gohtml diff --git a/internal/templates/twentyseventeen/layout/base.gohtml b/internal/theme/twentyseventeen/layout/base.gohtml similarity index 92% rename from internal/templates/twentyseventeen/layout/base.gohtml rename to internal/theme/twentyseventeen/layout/base.gohtml index 6da1c53..e94255f 100644 --- a/internal/templates/twentyseventeen/layout/base.gohtml +++ b/internal/theme/twentyseventeen/layout/base.gohtml @@ -52,8 +52,10 @@ diff --git a/internal/templates/twentyseventeen/layout/empty.gohtml b/internal/theme/twentyseventeen/layout/empty.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/empty.gohtml rename to internal/theme/twentyseventeen/layout/empty.gohtml diff --git a/internal/templates/twentyseventeen/layout/footer.gohtml b/internal/theme/twentyseventeen/layout/footer.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/footer.gohtml rename to internal/theme/twentyseventeen/layout/footer.gohtml diff --git a/internal/templates/twentyseventeen/layout/footersvg.gohtml b/internal/theme/twentyseventeen/layout/footersvg.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/footersvg.gohtml rename to internal/theme/twentyseventeen/layout/footersvg.gohtml diff --git a/internal/templates/twentyseventeen/layout/head.gohtml b/internal/theme/twentyseventeen/layout/head.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/head.gohtml rename to internal/theme/twentyseventeen/layout/head.gohtml diff --git a/internal/templates/twentyseventeen/layout/message.gohtml b/internal/theme/twentyseventeen/layout/message.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/message.gohtml rename to internal/theme/twentyseventeen/layout/message.gohtml diff --git a/internal/templates/twentyseventeen/layout/pagination.gohtml b/internal/theme/twentyseventeen/layout/pagination.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/pagination.gohtml rename to internal/theme/twentyseventeen/layout/pagination.gohtml diff --git a/internal/templates/twentyseventeen/layout/sidebar.gohtml b/internal/theme/twentyseventeen/layout/sidebar.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/sidebar.gohtml rename to internal/theme/twentyseventeen/layout/sidebar.gohtml diff --git a/internal/templates/twentyseventeen/layout/svg.gohtml b/internal/theme/twentyseventeen/layout/svg.gohtml similarity index 100% rename from internal/templates/twentyseventeen/layout/svg.gohtml rename to internal/theme/twentyseventeen/layout/svg.gohtml diff --git a/internal/templates/twentyseventeen/posts/detail.gohtml b/internal/theme/twentyseventeen/posts/detail.gohtml similarity index 100% rename from internal/templates/twentyseventeen/posts/detail.gohtml rename to internal/theme/twentyseventeen/posts/detail.gohtml diff --git a/internal/templates/twentyseventeen/posts/index.gohtml b/internal/theme/twentyseventeen/posts/index.gohtml similarity index 100% rename from internal/templates/twentyseventeen/posts/index.gohtml rename to internal/theme/twentyseventeen/posts/index.gohtml diff --git a/internal/templates/twentyseventeen/theme.go b/internal/theme/twentyseventeen/twentyseventeen.go similarity index 59% rename from internal/templates/twentyseventeen/theme.go rename to internal/theme/twentyseventeen/twentyseventeen.go index 9a95de0..fea710a 100644 --- a/internal/templates/twentyseventeen/theme.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -2,13 +2,15 @@ package twentyseventeen import ( "github.com/elliotchance/phpserialize" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/internal/pkg/cache" + "github.com/fthvgb1/wp-go/internal/pkg/logs" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/internal/plugins" + "github.com/fthvgb1/wp-go/internal/wpconfig" + "github.com/fthvgb1/wp-go/plugin/pagination" "github.com/gin-gonic/gin" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/pkg/cache" - "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" + "strings" ) const ThemeName = "twentyseventeen" @@ -28,13 +30,27 @@ type ImageData struct { Width int64 `json:"width,omitempty"` } -func Hook(c *gin.Context, h gin.H, scene int) (r string) { +func Hook(status int, c *gin.Context, h gin.H, scene int) { + templ := "twentyseventeen/posts/index.gohtml" if _, ok := plugins.IndexSceneMap[scene]; ok { - r = "twentyseventeen/posts/index.gohtml" h["HeaderImage"] = getHeaderImage(c) + p, ok := h["pagination"] + if ok { + pp, ok := p.(pagination.ParsePagination) + if ok { + f := plugins.TwentyFifteenPagination() + f.PrevEle = `` + f.NextEle = strings.Replace(f.NextEle, "下一页", `下一页 +`, 1) + h["pagination"] = pagination.Paginate(f, pp) + } + } } else if _, ok := plugins.DetailSceneMap[scene]; ok { - r = "twentyseventeen/posts/detail.gohtml" + templ = "twentyseventeen/posts/detail.gohtml" } + c.HTML(status, templ, h) return } diff --git a/internal/wpconfig/options.go b/internal/wpconfig/options.go index 0e89d61..7b51d98 100644 --- a/internal/wpconfig/options.go +++ b/internal/wpconfig/options.go @@ -2,9 +2,9 @@ package wpconfig import ( "context" - "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/model" - "github/fthvgb1/wp-go/safety" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/safety" ) var Options safety.Map[string, string] diff --git a/internal/wpconfig/term.go b/internal/wpconfig/term.go index 626b326..6a4cf6b 100644 --- a/internal/wpconfig/term.go +++ b/internal/wpconfig/term.go @@ -2,9 +2,9 @@ package wpconfig import ( "context" - "github/fthvgb1/wp-go/internal/pkg/models" - "github/fthvgb1/wp-go/model" - "github/fthvgb1/wp-go/safety" + "github.com/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/model" + "github.com/fthvgb1/wp-go/safety" ) var Terms safety.Map[uint64, models.Terms] diff --git a/model/parse.go b/model/parse.go index 79352a9..9fdbd9a 100644 --- a/model/parse.go +++ b/model/parse.go @@ -2,7 +2,7 @@ package model import ( "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "strconv" "strings" ) diff --git a/model/query.go b/model/query.go index 365df1a..8dd0ff4 100644 --- a/model/query.go +++ b/model/query.go @@ -3,7 +3,7 @@ package model import ( "context" "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "math/rand" "strings" "time" diff --git a/model/query_test.go b/model/query_test.go index 9f5213e..5796b0c 100644 --- a/model/query_test.go +++ b/model/query_test.go @@ -3,26 +3,123 @@ package model import ( "context" "database/sql" - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/internal/pkg/config" - "github/fthvgb1/wp-go/internal/pkg/db" - models2 "github/fthvgb1/wp-go/internal/pkg/models" + "github.com/fthvgb1/wp-go/helper" + _ "github.com/go-sql-driver/mysql" + "github.com/jmoiron/sqlx" "reflect" "testing" + "time" ) +type post struct { + Id uint64 `gorm:"column:ID" db:"ID" json:"ID" form:"ID"` + PostAuthor uint64 `gorm:"column:post_author" db:"post_author" json:"post_author" form:"post_author"` + PostDate time.Time `gorm:"column:post_date" db:"post_date" json:"post_date" form:"post_date"` + PostDateGmt time.Time `gorm:"column:post_date_gmt" db:"post_date_gmt" json:"post_date_gmt" form:"post_date_gmt"` + PostContent string `gorm:"column:post_content" db:"post_content" json:"post_content" form:"post_content"` + PostTitle string `gorm:"column:post_title" db:"post_title" json:"post_title" form:"post_title"` + PostExcerpt string `gorm:"column:post_excerpt" db:"post_excerpt" json:"post_excerpt" form:"post_excerpt"` + PostStatus string `gorm:"column:post_status" db:"post_status" json:"post_status" form:"post_status"` + CommentStatus string `gorm:"column:comment_status" db:"comment_status" json:"comment_status" form:"comment_status"` + PingStatus string `gorm:"column:ping_status" db:"ping_status" json:"ping_status" form:"ping_status"` + PostPassword string `gorm:"column:post_password" db:"post_password" json:"post_password" form:"post_password"` + PostName string `gorm:"column:post_name" db:"post_name" json:"post_name" form:"post_name"` + ToPing string `gorm:"column:to_ping" db:"to_ping" json:"to_ping" form:"to_ping"` + Pinged string `gorm:"column:pinged" db:"pinged" json:"pinged" form:"pinged"` + PostModified time.Time `gorm:"column:post_modified" db:"post_modified" json:"post_modified" form:"post_modified"` + PostModifiedGmt time.Time `gorm:"column:post_modified_gmt" db:"post_modified_gmt" json:"post_modified_gmt" form:"post_modified_gmt"` + PostContentFiltered string `gorm:"column:post_content_filtered" db:"post_content_filtered" json:"post_content_filtered" form:"post_content_filtered"` + PostParent uint64 `gorm:"column:post_parent" db:"post_parent" json:"post_parent" form:"post_parent"` + Guid string `gorm:"column:guid" db:"guid" json:"guid" form:"guid"` + MenuOrder int `gorm:"column:menu_order" db:"menu_order" json:"menu_order" form:"menu_order"` + PostType string `gorm:"column:post_type" db:"post_type" json:"post_type" form:"post_type"` + PostMimeType string `gorm:"column:post_mime_type" db:"post_mime_type" json:"post_mime_type" form:"post_mime_type"` + CommentCount int64 `gorm:"column:comment_count" db:"comment_count" json:"comment_count" form:"comment_count"` +} + +type user struct { + Id uint64 `gorm:"column:ID" db:"ID" json:"ID"` + UserLogin string `gorm:"column:user_login" db:"user_login" json:"user_login"` + UserPass string `gorm:"column:user_pass" db:"user_pass" json:"user_pass"` + UserNicename string `gorm:"column:user_nicename" db:"user_nicename" json:"user_nicename"` + UserEmail string `gorm:"column:user_email" db:"user_email" json:"user_email"` + UserUrl string `gorm:"column:user_url" db:"user_url" json:"user_url"` + UserRegistered time.Time `gorm:"column:user_registered" db:"user_registered" json:"user_registered"` + UserActivationKey string `gorm:"column:user_activation_key" db:"user_activation_key" json:"user_activation_key"` + UserStatus int `gorm:"column:user_status" db:"user_status" json:"user_status"` + DisplayName string `gorm:"column:display_name" db:"display_name" json:"display_name"` +} + +type termTaxonomy struct { + TermTaxonomyId uint64 `gorm:"column:term_taxonomy_id" db:"term_taxonomy_id" json:"term_taxonomy_id" form:"term_taxonomy_id"` + TermId uint64 `gorm:"column:term_id" db:"term_id" json:"term_id" form:"term_id"` + Taxonomy string `gorm:"column:taxonomy" db:"taxonomy" json:"taxonomy" form:"taxonomy"` + Description string `gorm:"column:description" db:"description" json:"description" form:"description"` + Parent uint64 `gorm:"column:parent" db:"parent" json:"parent" form:"parent"` + Count int64 `gorm:"column:count" db:"count" json:"count" form:"count"` +} + +type terms struct { + TermId uint64 `gorm:"column:term_id" db:"term_id" json:"term_id" form:"term_id"` + Name string `gorm:"column:name" db:"name" json:"name" form:"name"` + Slug string `gorm:"column:slug" db:"slug" json:"slug" form:"slug"` + TermGroup int64 `gorm:"column:term_group" db:"term_group" json:"term_group" form:"term_group"` +} + +func (t terms) PrimaryKey() string { + return "term_id" +} +func (t terms) Table() string { + return "wp_terms" +} + +func (w termTaxonomy) PrimaryKey() string { + return "term_taxonomy_id" +} + +func (w termTaxonomy) Table() string { + return "wp_term_taxonomy" +} + +func (u user) Table() string { + return "wp_users" +} + +func (u user) PrimaryKey() string { + return "ID" +} + +func (p post) PrimaryKey() string { + return "ID" +} + +func (p post) Table() string { + return "wp_posts" +} + +type SqlxDb struct { + sqlx *sqlx.DB +} + +var Db *SqlxDb + +func (r SqlxDb) Select(ctx context.Context, dest any, sql string, params ...any) error { + return r.sqlx.Select(dest, sql, params...) +} + +func (r SqlxDb) Get(ctx context.Context, dest any, sql string, params ...any) error { + return r.sqlx.Get(dest, sql, params...) +} + var ctx = context.Background() func init() { - err := config.InitConfig("../config.yaml") + db, err := sqlx.Open("mysql", "root:root@tcp(192.168.66.47:3306)/wordpress?charset=utf8mb4&parseTime=True&loc=Local") if err != nil { panic(err) } - err = db.InitDb() - if err != nil { - panic(err) - } - InitDB(db.NewSqlxDb(db.Db)) + Db = &SqlxDb{db} + InitDB(Db) } func TestFind(t *testing.T) { type args struct { @@ -36,7 +133,7 @@ func TestFind(t *testing.T) { in [][]any } type posts struct { - models2.Posts + post N int `db:"n"` } tests := []struct { @@ -107,7 +204,7 @@ func TestFind(t *testing.T) { in: nil, }, wantR: func() []posts { - r, err := Select[posts](ctx, "select post_status,count(*) n from "+models2.Posts{}.Table()+" where ID<1000 group by post_status having n>1") + r, err := Select[posts](ctx, "select post_status,count(*) n from "+post{}.Table()+" where ID<1000 group by post_status having n>1") if err != nil { panic(err) } @@ -152,10 +249,10 @@ func TestFind(t *testing.T) { group: "a.post_author", order: SqlBuilder{{"n", "desc"}}, join: SqlBuilder{ - {"a", "left join", models2.Users{}.Table() + " b", "a.post_author=b.ID"}, + {"a", "left join", user{}.Table() + " b", "a.post_author=b.ID"}, {"left join", "wp_term_relationships c", "a.Id=c.object_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"}, + {"left join", termTaxonomy{}.Table() + " d", "c.term_taxonomy_id=d.term_taxonomy_id"}, + {"left join", terms{}.Table() + " e", "d.term_id=e.term_id"}, }, having: SqlBuilder{{"n", ">", "0", "int"}}, limit: 10, @@ -193,7 +290,7 @@ func TestFindOneById(t *testing.T) { tests := []struct { name string args args - want models2.Posts + want post wantErr bool }{ { @@ -201,8 +298,8 @@ func TestFindOneById(t *testing.T) { args: args{ 1, }, - want: func() models2.Posts { - r, err := Get[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where ID=?", 1) + want: func() post { + r, err := Get[post](ctx, "select * from "+post{}.Table()+" where ID=?", 1) if err != nil && err != sql.ErrNoRows { panic(err) } else if err == sql.ErrNoRows { @@ -215,7 +312,7 @@ func TestFindOneById(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := FindOneById[models2.Posts](ctx, tt.args.id) + got, err := FindOneById[post](ctx, tt.args.id) if err == sql.ErrNoRows { err = nil } @@ -240,7 +337,7 @@ func TestFirstOne(t *testing.T) { tests := []struct { name string args args - want models2.Posts + want post wantErr bool }{ { @@ -252,8 +349,8 @@ func TestFirstOne(t *testing.T) { in: nil, }, wantErr: false, - 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") + want: func() post { + r, err := Get[post](ctx, "select * from "+post{}.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 +362,7 @@ func TestFirstOne(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := FirstOne[models2.Posts](ctx, tt.args.where, tt.args.fields, tt.args.order, tt.args.in...) + got, err := FirstOne[post](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 +383,7 @@ func TestLastOne(t *testing.T) { tests := []struct { name string args args - want models2.Posts + want post wantErr bool }{ { @@ -298,8 +395,8 @@ func TestLastOne(t *testing.T) { fields: "*", in: nil, }, - 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") + want: func() post { + r, err := Get[post](ctx, "select * from "+post{}.Table()+" where post_status='publish' order by "+post{}.PrimaryKey()+" desc limit 1") if err != nil { panic(err) } @@ -309,7 +406,7 @@ func TestLastOne(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := LastOne[models2.Posts](ctx, tt.args.where, tt.args.fields, tt.args.in...) + got, err := LastOne[post](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 +427,7 @@ func TestSimpleFind(t *testing.T) { tests := []struct { name string args args - want []models2.Posts + want []post wantErr bool }{ { @@ -342,8 +439,8 @@ func TestSimpleFind(t *testing.T) { fields: "*", in: [][]any{{1, 2}}, }, - want: func() (r []models2.Posts) { - r, err := Select[models2.Posts](ctx, "select * from "+models2.Posts{}.Table()+" where ID in (?,?)", 1, 2) + want: func() (r []post) { + r, err := Select[post](ctx, "select * from "+post{}.Table()+" where ID in (?,?)", 1, 2) if err != nil && err != sql.ErrNoRows { panic(err) } else if err == sql.ErrNoRows { @@ -356,7 +453,7 @@ func TestSimpleFind(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := SimpleFind[models2.Posts](ctx, tt.args.where, tt.args.fields, tt.args.in...) + got, err := SimpleFind[post](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 +480,7 @@ func TestSimplePagination(t *testing.T) { tests := []struct { name string args args - wantR []models2.Posts + wantR []post wantTotal int wantErr bool }{ @@ -402,8 +499,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 []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])...) + wantR: func() (r []post) { + r, err := Select[post](ctx, "select * from "+post{}.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 +514,7 @@ func TestSimplePagination(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - 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...) + gotR, gotTotal, err := SimplePagination[post](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 diff --git a/phpass/phpass.go b/phpass/phpass.go index 59af774..3ba6af8 100644 --- a/phpass/phpass.go +++ b/phpass/phpass.go @@ -3,7 +3,7 @@ package phpass import ( "crypto/md5" "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "golang.org/x/crypto/bcrypt" "io" "os" diff --git a/plugin/digest/digest.go b/plugin/digest/digest.go index cb04b03..44a136e 100644 --- a/plugin/digest/digest.go +++ b/plugin/digest/digest.go @@ -2,7 +2,7 @@ package digest import ( "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "regexp" "strings" "unicode/utf8" diff --git a/rss2/rss2.go b/rss2/rss2.go index 9c2efe8..332846b 100644 --- a/rss2/rss2.go +++ b/rss2/rss2.go @@ -2,7 +2,7 @@ package rss2 import ( "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "strconv" "strings" ) diff --git a/safety/slice_test.go b/safety/slice_test.go index 55cf272..bce2512 100644 --- a/safety/slice_test.go +++ b/safety/slice_test.go @@ -2,7 +2,7 @@ package safety import ( "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "testing" "time" ) diff --git a/stream/simpleMapStream.go b/stream/simpleMapStream.go index 1beddee..86c1e10 100644 --- a/stream/simpleMapStream.go +++ b/stream/simpleMapStream.go @@ -1,8 +1,8 @@ package stream import ( - "github/fthvgb1/wp-go/safety" - "github/fthvgb1/wp-go/taskPools" + "github.com/fthvgb1/wp-go/safety" + "github.com/fthvgb1/wp-go/taskPools" "sync" ) diff --git a/stream/simpleMapStream_test.go b/stream/simpleMapStream_test.go index 54e08bd..25e22c4 100644 --- a/stream/simpleMapStream_test.go +++ b/stream/simpleMapStream_test.go @@ -2,7 +2,7 @@ package stream import ( "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "reflect" "strconv" "testing" diff --git a/stream/simpleStream.go b/stream/simpleStream.go index c65c495..efa3ddb 100644 --- a/stream/simpleStream.go +++ b/stream/simpleStream.go @@ -1,9 +1,9 @@ package stream import ( - "github/fthvgb1/wp-go/helper" - "github/fthvgb1/wp-go/safety" - "github/fthvgb1/wp-go/taskPools" + "github.com/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/safety" + "github.com/fthvgb1/wp-go/taskPools" ) func SimpleParallelFilterAndMap[R, T any](a SimpleSliceStream[T], fn func(T) (R, bool), c int) SimpleSliceStream[R] { diff --git a/stream/simpleStream_test.go b/stream/simpleStream_test.go index c1502d0..b74e077 100644 --- a/stream/simpleStream_test.go +++ b/stream/simpleStream_test.go @@ -2,7 +2,7 @@ package stream import ( "fmt" - "github/fthvgb1/wp-go/helper" + "github.com/fthvgb1/wp-go/helper" "reflect" "strconv" "testing"