Compare commits
4 Commits
f9b565294f
...
7c571654a6
Author | SHA1 | Date | |
---|---|---|---|
7c571654a6 | |||
90d2432575 | |||
972ff7d815 | |||
2d2c6445e8 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
wp-go.iml
|
wp-go.iml
|
||||||
config.yaml
|
config.yaml
|
||||||
err.log
|
err.log
|
||||||
|
plugins
|
|
@ -77,6 +77,7 @@ func SetupRouter() *gin.Engine {
|
||||||
r.GET("/p/:id/feed", actions.PostFeed)
|
r.GET("/p/:id/feed", actions.PostFeed)
|
||||||
r.GET("/feed", actions.Feed)
|
r.GET("/feed", actions.Feed)
|
||||||
r.GET("/comments/feed", actions.CommentsFeed)
|
r.GET("/comments/feed", actions.CommentsFeed)
|
||||||
|
//r.NoRoute(actions.ThemeHook(constraints.NoRoute))
|
||||||
commentMiddleWare, _ := middleware.FlowLimit(c.MaxRequestSleepNum, 5, c.CacheTime.SleepTime)
|
commentMiddleWare, _ := middleware.FlowLimit(c.MaxRequestSleepNum, 5, c.CacheTime.SleepTime)
|
||||||
r.POST("/comment", commentMiddleWare, actions.PostComment)
|
r.POST("/comment", commentMiddleWare, actions.PostComment)
|
||||||
if c.Pprof != "" {
|
if c.Pprof != "" {
|
||||||
|
|
|
@ -9,6 +9,8 @@ const (
|
||||||
Author = "Author"
|
Author = "Author"
|
||||||
Detail = "Detail"
|
Detail = "Detail"
|
||||||
|
|
||||||
|
NoRoute = "NoRoute"
|
||||||
|
|
||||||
Ok = "Ok"
|
Ok = "Ok"
|
||||||
Error404 = "Error404"
|
Error404 = "Error404"
|
||||||
ParamError = "ParamError"
|
ParamError = "ParamError"
|
||||||
|
|
36
app/plugins/devexample/plugintt/go.mod.dev
Normal file
36
app/plugins/devexample/plugintt/go.mod.dev
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
module plugintt
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require github.com/fthvgb1/wp-go latest
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/dlclark/regexp2 v1.7.0 // indirect
|
||||||
|
github.com/elliotchance/phpserialize v1.3.3 // indirect
|
||||||
|
github.com/gin-contrib/sessions v0.0.5 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/gin-gonic/gin v1.8.1 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.11.1 // indirect
|
||||||
|
github.com/goccy/go-json v0.9.11 // indirect
|
||||||
|
github.com/gorilla/context v1.1.1 // indirect
|
||||||
|
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||||
|
github.com/gorilla/sessions v1.2.1 // indirect
|
||||||
|
github.com/jmoiron/sqlx v1.3.5 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // 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
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||||
|
github.com/shopspring/decimal v1.3.1 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||||
|
golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9 // indirect
|
||||||
|
golang.org/x/net v0.5.0 // indirect
|
||||||
|
golang.org/x/sys v0.4.0 // indirect
|
||||||
|
golang.org/x/text v0.6.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.28.1 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
)
|
24
app/plugins/devexample/plugintt/main.go.dev
Normal file
24
app/plugins/devexample/plugintt/main.go.dev
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||||
|
"github.com/fthvgb1/wp-go/app/theme"
|
||||||
|
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||||
|
"plugintt/xx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// here can register theme
|
||||||
|
theme.AddThemeHookFunc("xxx", Xo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Xo(h *wp.Handle) {
|
||||||
|
// action or hook or config theme
|
||||||
|
h.PushHandler(constraints.PipeRender, constraints.Home, wp.HandleCall{
|
||||||
|
Fn: func(handle *wp.Handle) {
|
||||||
|
xx.Xo()
|
||||||
|
},
|
||||||
|
Order: 100,
|
||||||
|
Name: "xxxx",
|
||||||
|
})
|
||||||
|
}
|
6
app/plugins/devexample/plugintt/make.sh
Normal file
6
app/plugins/devexample/plugintt/make.sh
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#/bin/bash
|
||||||
|
|
||||||
|
# copy plugintt to other dir and remove .dev suffix
|
||||||
|
# note the go version and build tool flag must same to server build
|
||||||
|
# eg: -gcflags all="-N -l" may used in ide debug
|
||||||
|
go build -buildmode=plugin -o xx.so main.go
|
11
app/plugins/devexample/plugintt/xx/oo.go.dev
Normal file
11
app/plugins/devexample/plugintt/xx/oo.go.dev
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package xx
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Xo() {
|
||||||
|
fmt.Println("xxoo")
|
||||||
|
fmt.Println(decimal.Max(decimal.NewFromFloat(32.3333333333333), decimal.NewFromFloat(32.33333333333331)).String())
|
||||||
|
}
|
|
@ -45,22 +45,22 @@ func LoadPlugins() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, entry := range glob {
|
for _, entry := range glob {
|
||||||
f := filepath.Join(dirPath, entry)
|
p, err := plugin.Open(entry)
|
||||||
p, err := plugin.Open(f)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err, "读取插件错误", f)
|
logs.Error(err, "读取插件错误", entry)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name := filepath.Ext(entry)
|
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)
|
pl, err := p.Lookup(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err, "插件lookup错误", f)
|
logs.Error(err, "插件lookup错误", entry)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
plu, ok := pl.(func(*wp.Handle))
|
plu, ok := pl.(func(*wp.Handle))
|
||||||
if !ok {
|
if !ok {
|
||||||
logs.Error(errors.New("switch func(*wp.Handle) fail"), "插件转换错误", f)
|
logs.Error(errors.New("switch func(*wp.Handle) fail"), "插件转换错误", entry)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
RegisterPlugin(name, plu)
|
RegisterPlugin(name, plu)
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
package theme
|
package theme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fthvgb1/wp-go/app/theme/twentyfifteen"
|
|
||||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||||
|
"github.com/fthvgb1/wp-go/safety"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
var themeMap = map[string]func(*wp.Handle){}
|
var themeMap = safety.NewMap[string, func(*wp.Handle)]()
|
||||||
|
|
||||||
func addThemeHookFunc(name string, fn func(handle *wp.Handle)) {
|
func AddThemeHookFunc(name string, fn func(handle *wp.Handle)) {
|
||||||
if _, ok := themeMap[name]; ok {
|
if _, ok := themeMap.Load(name); ok {
|
||||||
panic("exists same name theme")
|
panic("exists same name theme")
|
||||||
}
|
}
|
||||||
themeMap[name] = fn
|
themeMap.Store(name, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Hook(themeName string, handle *wp.Handle) {
|
func Hook(themeName string, h *wp.Handle) {
|
||||||
fn, ok := themeMap[themeName]
|
fn, ok := themeMap.Load(themeName)
|
||||||
if ok && fn != nil {
|
if ok && fn != nil {
|
||||||
fn(handle)
|
fn(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
themeMap[twentyfifteen.ThemeName](handle)
|
h.C.String(http.StatusNotFound, "404")
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitTheme() {
|
func InitTheme() {
|
||||||
addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
|
AddThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
|
||||||
twentyfifteen.Init(TemplateFs)
|
twentyfifteen.Init(TemplateFs)
|
||||||
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
|
AddThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
|
||||||
twentyseventeen.Init(TemplateFs)
|
twentyseventeen.Init(TemplateFs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,9 @@ postOrder: "desc"
|
||||||
uploadDir: ""
|
uploadDir: ""
|
||||||
# pprof route path 为空表示不开启pprof,否则为pprof的路由
|
# pprof route path 为空表示不开启pprof,否则为pprof的路由
|
||||||
pprof: "/debug/pprof"
|
pprof: "/debug/pprof"
|
||||||
# 程序插件
|
# 要使用的程序插件名
|
||||||
plugins: ["enlightjs"]
|
plugins: ["enlightjs"]
|
||||||
|
# 插件存放路径
|
||||||
|
pluginPath: "./plugins"
|
||||||
# 列表页面post使用的插件
|
# 列表页面post使用的插件
|
||||||
listPagePlugins: ["passwordProject","digest","twentyseventeen_postThumbnail"]
|
listPagePlugins: ["passwordProject","digest","twentyseventeen_postThumbnail"]
|
Loading…
Reference in New Issue
Block a user