Compare commits
No commits in common. "7c571654a65aff5f3bef16bdbdbe7a0d5095fdbb" and "f9b565294f0b5feb2948ab9b631dde4a27150f16" have entirely different histories.
7c571654a6
...
f9b565294f
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,4 +2,3 @@
|
||||||
wp-go.iml
|
wp-go.iml
|
||||||
config.yaml
|
config.yaml
|
||||||
err.log
|
err.log
|
||||||
plugins
|
|
|
@ -77,7 +77,6 @@ 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,8 +9,6 @@ const (
|
||||||
Author = "Author"
|
Author = "Author"
|
||||||
Detail = "Detail"
|
Detail = "Detail"
|
||||||
|
|
||||||
NoRoute = "NoRoute"
|
|
||||||
|
|
||||||
Ok = "Ok"
|
Ok = "Ok"
|
||||||
Error404 = "Error404"
|
Error404 = "Error404"
|
||||||
ParamError = "ParamError"
|
ParamError = "ParamError"
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
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
|
|
||||||
)
|
|
|
@ -1,24 +0,0 @@
|
||||||
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",
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
#/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
|
|
|
@ -1,11 +0,0 @@
|
||||||
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 {
|
||||||
p, err := plugin.Open(entry)
|
f := filepath.Join(dirPath, entry)
|
||||||
|
p, err := plugin.Open(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Error(err, "读取插件错误", entry)
|
logs.Error(err, "读取插件错误", f)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name := filepath.Ext(entry)
|
name := filepath.Ext(entry)
|
||||||
name = filepath.Base(entry[0 : len(entry)-len(name)])
|
name = str.FirstUpper(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错误", entry)
|
logs.Error(err, "插件lookup错误", f)
|
||||||
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"), "插件转换错误", entry)
|
logs.Error(errors.New("switch func(*wp.Handle) fail"), "插件转换错误", f)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
RegisterPlugin(name, plu)
|
RegisterPlugin(name, plu)
|
||||||
|
|
|
@ -1,25 +1,24 @@
|
||||||
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 = safety.NewMap[string, func(*wp.Handle)]()
|
var themeMap = map[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.Load(name); ok {
|
if _, ok := themeMap[name]; ok {
|
||||||
panic("exists same name theme")
|
panic("exists same name theme")
|
||||||
}
|
}
|
||||||
themeMap.Store(name, fn)
|
themeMap[name] = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
func Hook(themeName string, h *wp.Handle) {
|
func Hook(themeName string, handle *wp.Handle) {
|
||||||
fn, ok := themeMap.Load(themeName)
|
fn, ok := themeMap[themeName]
|
||||||
if ok && fn != nil {
|
if ok && fn != nil {
|
||||||
fn(h)
|
fn(handle)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h.C.String(http.StatusNotFound, "404")
|
themeMap[twentyfifteen.ThemeName](handle)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,9 +92,7 @@ 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