From 2d2c6445e8563361d48b989b61b6313233f32383 Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 4 May 2023 21:06:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app/cmd/route/route.go | 1 + app/pkg/constraints/const.go | 2 ++ app/plugins/wphandle/handle.go | 12 ++++++------ config.example.yaml | 4 +++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b7bebf4..2daa37f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ wp-go.iml config.yaml err.log +plugins \ No newline at end of file diff --git a/app/cmd/route/route.go b/app/cmd/route/route.go index 0f2d5df..ef51684 100644 --- a/app/cmd/route/route.go +++ b/app/cmd/route/route.go @@ -77,6 +77,7 @@ func SetupRouter() *gin.Engine { r.GET("/p/:id/feed", actions.PostFeed) r.GET("/feed", actions.Feed) r.GET("/comments/feed", actions.CommentsFeed) + //r.NoRoute(actions.ThemeHook(constraints.NoRoute)) commentMiddleWare, _ := middleware.FlowLimit(c.MaxRequestSleepNum, 5, c.CacheTime.SleepTime) r.POST("/comment", commentMiddleWare, actions.PostComment) if c.Pprof != "" { diff --git a/app/pkg/constraints/const.go b/app/pkg/constraints/const.go index f8c9dd9..1b27ad0 100644 --- a/app/pkg/constraints/const.go +++ b/app/pkg/constraints/const.go @@ -9,6 +9,8 @@ const ( Author = "Author" Detail = "Detail" + NoRoute = "NoRoute" + Ok = "Ok" Error404 = "Error404" ParamError = "ParamError" diff --git a/app/plugins/wphandle/handle.go b/app/plugins/wphandle/handle.go index dfd8fb6..0dfd421 100644 --- a/app/plugins/wphandle/handle.go +++ b/app/plugins/wphandle/handle.go @@ -45,22 +45,22 @@ func LoadPlugins() { return } for _, entry := range glob { - f := filepath.Join(dirPath, entry) - p, err := plugin.Open(f) + p, err := plugin.Open(entry) if err != nil { - logs.Error(err, "读取插件错误", f) + logs.Error(err, "读取插件错误", entry) continue } name := filepath.Ext(entry) - name = str.FirstUpper(entry[0 : len(entry)-len(name)]) + name = filepath.Base(entry[0 : len(entry)-len(name)]) + name = str.FirstUpper(name) pl, err := p.Lookup(name) if err != nil { - logs.Error(err, "插件lookup错误", f) + logs.Error(err, "插件lookup错误", entry) continue } plu, ok := pl.(func(*wp.Handle)) if !ok { - logs.Error(errors.New("switch func(*wp.Handle) fail"), "插件转换错误", f) + logs.Error(errors.New("switch func(*wp.Handle) fail"), "插件转换错误", entry) continue } RegisterPlugin(name, plu) diff --git a/config.example.yaml b/config.example.yaml index feecad0..6e8fcd3 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -92,7 +92,9 @@ postOrder: "desc" uploadDir: "" # pprof route path 为空表示不开启pprof,否则为pprof的路由 pprof: "/debug/pprof" -# 程序插件 +# 要使用的程序插件名 plugins: ["enlightjs"] +# 插件存放路径 +pluginPath: "./plugins" # 列表页面post使用的插件 listPagePlugins: ["passwordProject","digest","twentyseventeen_postThumbnail"] \ No newline at end of file