optimize code and update package version
This commit is contained in:
parent
e592a753bf
commit
58d3e4f645
|
@ -2,12 +2,29 @@ package apply
|
||||||
|
|
||||||
import "github.com/fthvgb1/wp-go/safety"
|
import "github.com/fthvgb1/wp-go/safety"
|
||||||
|
|
||||||
var fn safety.Var[any]
|
var contains = safety.NewMap[string, any]()
|
||||||
|
|
||||||
func SetFn(f any) {
|
func SetVal(key string, val any) {
|
||||||
fn.Store(f)
|
contains.Store(key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UsePlugins() any {
|
func DelVal(key string) {
|
||||||
return fn.Load()
|
contains.Delete(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetVal[V any](key string) (V, bool) {
|
||||||
|
v, ok := contains.Load(key)
|
||||||
|
if !ok {
|
||||||
|
var vv V
|
||||||
|
return vv, ok
|
||||||
|
}
|
||||||
|
return v.(V), ok
|
||||||
|
}
|
||||||
|
func GetRawVal(key string) (any, bool) {
|
||||||
|
return contains.Load(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPlugins() any {
|
||||||
|
v, _ := contains.Load("wp-plugins")
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ func LoadPlugins() {
|
||||||
}
|
}
|
||||||
RegisterPlugin(name, plu)
|
RegisterPlugin(name, plu)
|
||||||
}
|
}
|
||||||
apply.SetFn(func(h *wp.Handle) {
|
apply.SetVal("wp-plugins", func(h *wp.Handle) {
|
||||||
UsePlugins(h)
|
UsePlugins(h)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,6 @@ import (
|
||||||
var themeMap = safety.NewMap[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.Load(name); ok {
|
|
||||||
panic("exists same name theme")
|
|
||||||
}
|
|
||||||
themeMap.Store(name, fn)
|
themeMap.Store(name, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ func SetConfigHandle(a ...any) Handle {
|
||||||
h.C = hh.C
|
h.C = hh.C
|
||||||
h.theme = hh.theme
|
h.theme = hh.theme
|
||||||
configFn(h)
|
configFn(h)
|
||||||
v := apply.UsePlugins()
|
v := apply.GetPlugins()
|
||||||
pluginFn, ok := v.(func(*Handle))
|
pluginFn, ok := v.(func(*Handle))
|
||||||
if ok {
|
if ok {
|
||||||
pluginFn(h)
|
pluginFn(h)
|
||||||
|
|
28
go.mod
28
go.mod
|
@ -3,7 +3,7 @@ module github.com/fthvgb1/wp-go
|
||||||
go 1.20
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dlclark/regexp2 v1.11.0
|
github.com/dlclark/regexp2 v1.11.4
|
||||||
github.com/elliotchance/phpserialize v1.4.0
|
github.com/elliotchance/phpserialize v1.4.0
|
||||||
github.com/gin-contrib/gzip v1.0.1
|
github.com/gin-contrib/gzip v1.0.1
|
||||||
github.com/gin-contrib/pprof v1.5.0
|
github.com/gin-contrib/pprof v1.5.0
|
||||||
|
@ -11,29 +11,29 @@ require (
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/go-playground/locales v0.14.1
|
github.com/go-playground/locales v0.14.1
|
||||||
github.com/go-playground/universal-translator v0.18.1
|
github.com/go-playground/universal-translator v0.18.1
|
||||||
github.com/go-playground/validator/v10 v10.21.0
|
github.com/go-playground/validator/v10 v10.22.0
|
||||||
github.com/go-sql-driver/mysql v1.8.1
|
github.com/go-sql-driver/mysql v1.8.1
|
||||||
github.com/goccy/go-json v0.10.3
|
github.com/goccy/go-json v0.10.3
|
||||||
github.com/jmoiron/sqlx v1.4.0
|
github.com/jmoiron/sqlx v1.4.0
|
||||||
golang.org/x/crypto v0.24.0
|
golang.org/x/crypto v0.26.0
|
||||||
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
|
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
|
||||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/bytedance/sonic v1.11.8 // indirect
|
github.com/bytedance/sonic v1.12.1 // indirect
|
||||||
github.com/bytedance/sonic/loader v0.1.1 // indirect
|
github.com/bytedance/sonic/loader v0.2.0 // indirect
|
||||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
|
||||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
github.com/gorilla/context v1.1.2 // indirect
|
github.com/gorilla/context v1.1.2 // indirect
|
||||||
github.com/gorilla/securecookie v1.1.2 // indirect
|
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||||
github.com/gorilla/sessions v1.2.2 // indirect
|
github.com/gorilla/sessions v1.3.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
@ -41,11 +41,11 @@ require (
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||||
golang.org/x/arch v0.8.0 // indirect
|
golang.org/x/arch v0.9.0 // indirect
|
||||||
golang.org/x/net v0.26.0 // indirect
|
golang.org/x/net v0.28.0 // indirect
|
||||||
golang.org/x/sys v0.21.0 // indirect
|
golang.org/x/sys v0.24.0 // indirect
|
||||||
golang.org/x/text v0.16.0 // indirect
|
golang.org/x/text v0.17.0 // indirect
|
||||||
google.golang.org/protobuf v1.34.1 // indirect
|
google.golang.org/protobuf v1.34.2 // indirect
|
||||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -71,9 +71,6 @@ func NewFsTemplates(f embed.FS, m maps) *MultipleFsTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MultipleFileTemplate) SetTemplate(name string, templ *template.Template) *MultipleFileTemplate {
|
func (t *MultipleFileTemplate) SetTemplate(name string, templ *template.Template) *MultipleFileTemplate {
|
||||||
if _, ok := t.Template.Load(name); ok {
|
|
||||||
panic("exists same template " + name)
|
|
||||||
}
|
|
||||||
t.Template.Store(name, templ)
|
t.Template.Store(name, templ)
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
@ -105,9 +102,6 @@ func (t *MultipleFsTemplate) AddTemplate(mainTemplatePattern string, fnMap templ
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
for _, mainTemplate := range mainTemplates {
|
for _, mainTemplate := range mainTemplates {
|
||||||
if _, ok := t.Template.Load(mainTemplate); ok {
|
|
||||||
panic("exists same Template " + mainTemplate)
|
|
||||||
}
|
|
||||||
file := filepath.Base(mainTemplate)
|
file := filepath.Base(mainTemplate)
|
||||||
pattern := append([]string{mainTemplate}, layoutTemplatePattern...)
|
pattern := append([]string{mainTemplate}, layoutTemplatePattern...)
|
||||||
t.Template.Store(mainTemplate, template.Must(template.New(file).Funcs(fnMap).ParseFS(t.Fs, pattern...)))
|
t.Template.Store(mainTemplate, template.Must(template.New(file).Funcs(fnMap).ParseFS(t.Fs, pattern...)))
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (v *RWMap[K, V]) Load(key K) (V, bool) {
|
||||||
return val, ok
|
return val, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *RWMap[K, V]) Del(keys ...K) {
|
func (v *RWMap[K, V]) Delete(keys ...K) {
|
||||||
v.mux.Lock()
|
v.mux.Lock()
|
||||||
defer v.mux.Unlock()
|
defer v.mux.Unlock()
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user