revise reload package
This commit is contained in:
parent
7978e9ee74
commit
a5294e2e20
|
@ -3,7 +3,6 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/route"
|
||||
"github.com/fthvgb1/wp-go/app/mail"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
|
@ -15,6 +14,7 @@ import (
|
|||
"github.com/fthvgb1/wp-go/app/theme"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/cachemanager"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/model"
|
||||
"log"
|
||||
"os"
|
||||
|
|
|
@ -2,12 +2,12 @@ package route
|
|||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/actions"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/middleware"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/theme"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/gin-contrib/gzip"
|
||||
"github.com/gin-contrib/pprof"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package twentyfifteen
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
)
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package twentyseventeen
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
||||
|
@ -12,6 +11,7 @@ import (
|
|||
"github.com/fthvgb1/wp-go/app/theme/wp/components"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp/components/widget"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package wp
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -27,15 +27,15 @@ func (h *Handle) HookComponents(scene string, fn func(Components[string]) (Compo
|
|||
}
|
||||
|
||||
func CalComponents(h *Handle) {
|
||||
componentss := reload.GetAnyValMapBy("scene-components", str.Join("allScene-", h.scene), h, func(h *Handle) map[string][]Components[string] {
|
||||
componentss := reload.GetAnyValMapBy("scene-components", str.Join("allScene-", h.scene), h, func(h *Handle) (map[string][]Components[string], bool) {
|
||||
return maps.MergeBy(func(k string, v1, v2 []Components[string]) ([]Components[string], bool) {
|
||||
vv := append(v1, v2...)
|
||||
return vv, vv != nil
|
||||
}, nil, h.components[h.scene], h.components[constraints.AllScene])
|
||||
}, nil, h.components[h.scene], h.components[constraints.AllScene]), true
|
||||
})
|
||||
for k, components := range componentss {
|
||||
key := str.Join("calComponents-", h.scene, "-", k)
|
||||
ss := reload.GetAnyValMapBy("calComponents", key, h, func(h *Handle) []Components[string] {
|
||||
ss := reload.GetAnyValMapBy("calComponents", key, h, func(h *Handle) ([]Components[string], bool) {
|
||||
r := slice.FilterAndMap(components, func(t Components[string]) (Components[string], bool) {
|
||||
fns, ok := h.componentHook[k]
|
||||
if !ok {
|
||||
|
@ -53,7 +53,7 @@ func CalComponents(h *Handle) {
|
|||
slice.Sort(r, func(i, j Components[string]) bool {
|
||||
return i.Order > j.Order
|
||||
})
|
||||
return r
|
||||
return r, true
|
||||
})
|
||||
var s = make([]string, 0, len(ss))
|
||||
for _, component := range ss {
|
||||
|
@ -64,7 +64,9 @@ func CalComponents(h *Handle) {
|
|||
if component.Fn != nil {
|
||||
v := ""
|
||||
if component.Cached {
|
||||
v = reload.GetAnyValMapBy("cacheComponents", component.Name, h, component.Fn)
|
||||
v = reload.GetAnyValMapBy("cacheComponents", component.Name, h, func(a *Handle) (string, bool) {
|
||||
return component.Fn(h), true
|
||||
})
|
||||
} else {
|
||||
v = component.Fn(h)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
constraints2 "github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
|
@ -12,6 +11,7 @@ import (
|
|||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp/components/widget"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/number"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -40,7 +40,7 @@ func categoryDefaultArgs() map[string]string {
|
|||
}
|
||||
}
|
||||
|
||||
func parseAttr(attr map[any]any) string {
|
||||
func parseAttr(attr map[any]any) (string, bool) {
|
||||
var attrs []string
|
||||
class := maps.GetAnyAnyValWithDefaults(attr, "", "className")
|
||||
classes := strings.Split(class, " ")
|
||||
|
@ -68,18 +68,18 @@ func parseAttr(attr map[any]any) string {
|
|||
attrs = append(attrs, fmt.Sprintf(`style="%s;"`, strings.Join(styles, ";")))
|
||||
}
|
||||
attrs = append(attrs, fmt.Sprintf(`class="%s"`, strings.Join(classes, " ")))
|
||||
return strings.Join(attrs, " ")
|
||||
return strings.Join(attrs, " "), true
|
||||
}
|
||||
|
||||
func Category(h *wp.Handle, id string, blockParser ParserBlock) (func() string, error) {
|
||||
counter := number.Counters[int]()
|
||||
var err error
|
||||
conf := reload.GetAnyValBys("block-category-conf", h, func(h *wp.Handle) map[any]any {
|
||||
conf := reload.GetAnyValBy("block-category-conf", h, func(h *wp.Handle) (map[any]any, bool) {
|
||||
var con any
|
||||
err = json.Unmarshal([]byte(blockParser.Attrs), &con)
|
||||
if err != nil {
|
||||
logs.Error(err, "解析category attr错误", blockParser.Attrs)
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
var conf map[any]any
|
||||
switch con.(type) {
|
||||
|
@ -111,8 +111,8 @@ func Category(h *wp.Handle, id string, blockParser ParserBlock) (func() string,
|
|||
classes = append(classes, "wp-block-categories-list")
|
||||
conf["className"] = strings.Join(classes, " ")
|
||||
}
|
||||
return conf
|
||||
})
|
||||
return conf, true
|
||||
}, 5)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -127,9 +127,9 @@ func Category(h *wp.Handle, id string, blockParser ParserBlock) (func() string,
|
|||
if maps.GetAnyAnyValWithDefaults(conf, false, "showOnlyTopLevel") {
|
||||
h.C.Set("showOnlyTopLevel", true)
|
||||
}
|
||||
args := reload.GetAnyValBys("block-category-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("block-category-args", h, func(h *wp.Handle) (map[string]string, bool) {
|
||||
args := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
return maps.FilterZeroMerge(categoryDefaultArgs(), args)
|
||||
return maps.FilterZeroMerge(categoryDefaultArgs(), args), true
|
||||
})
|
||||
|
||||
return func() string {
|
||||
|
|
|
@ -2,11 +2,11 @@ package widget
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -42,7 +42,7 @@ var archivesConfig = map[any]any{
|
|||
|
||||
func Archive(h *wp.Handle, id string) string {
|
||||
conf := configs(archivesConfig, "widget_archives", int64(2))
|
||||
args := reload.GetAnyValBys("widget-archive-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("widget-archive-args", h, func(h *wp.Handle) (map[string]string, bool) {
|
||||
archiveArgs := archiveArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, CommonArgs())
|
||||
args := wp.GetComponentsArgs(h, widgets.Archive, archiveArgs)
|
||||
|
@ -53,7 +53,7 @@ func Archive(h *wp.Handle, id string) string {
|
|||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, conf["title"].(string))
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
return args, true
|
||||
})
|
||||
|
||||
s := archiveTemplate
|
||||
|
|
|
@ -2,12 +2,12 @@ package widget
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -48,7 +48,7 @@ func categoryArgs() map[string]string {
|
|||
func Category(h *wp.Handle, id string) string {
|
||||
conf := configs(categoryConfig, "widget_categories", int64(2))
|
||||
|
||||
args := reload.GetAnyValBys("widget-category-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("widget-category-args", h, func(h *wp.Handle) (map[string]string, bool) {
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.Categories, categoryArgs())
|
||||
args = maps.FilterZeroMerge(categoryArgs(), CommonArgs(), commonArgs, args)
|
||||
|
@ -58,7 +58,7 @@ func Category(h *wp.Handle, id string) string {
|
|||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, args["{title}"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
return args, true
|
||||
})
|
||||
|
||||
t := categoryTemplate
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package widget
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
)
|
||||
|
@ -15,8 +15,8 @@ func Fn(id string, fn func(*wp.Handle, string) string) func(h *wp.Handle) string
|
|||
}
|
||||
|
||||
func configs[M ~map[K]V, K comparable, V any](m M, key string, a ...any) M {
|
||||
return reload.GetAnyValBys(str.Join("widget-config-", key), key, func(_ string) M {
|
||||
return reload.GetAnyValBys(str.Join("widget-config-", key), key, func(_ string) (M, bool) {
|
||||
c := wpconfig.GetPHPArrayVal[M](key, nil, a...)
|
||||
return maps.FilterZeroMerge(maps.Copy(m), c)
|
||||
return maps.FilterZeroMerge(maps.Copy(m), c), true
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ package widget
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -29,7 +29,7 @@ func metaArgs() map[string]string {
|
|||
}
|
||||
|
||||
func Meta(h *wp.Handle, id string) string {
|
||||
args := reload.GetAnyValBys("widget-meta-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("widget-meta-args", h, func(h *wp.Handle) (map[string]string, bool) {
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
metaArgs := metaArgs()
|
||||
args := wp.GetComponentsArgs(h, widgets.Meta, metaArgs)
|
||||
|
@ -46,7 +46,7 @@ func Meta(h *wp.Handle, id string) string {
|
|||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, args["{$title}"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
return args, true
|
||||
})
|
||||
|
||||
ss := str.NewBuilder()
|
||||
|
|
|
@ -2,11 +2,11 @@ package widget
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -42,7 +42,7 @@ var recentCommentsTemplate = `{$before_widget}
|
|||
func RecentComments(h *wp.Handle, id string) string {
|
||||
conf := configs(recentCommentConf, "widget_recent-comments", int64(2))
|
||||
|
||||
args := reload.GetAnyValBys("widget-recent-comment-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("widget-recent-comment-args", h, func(h *wp.Handle) (map[string]string, bool) {
|
||||
commentsArgs := recentCommentsArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.RecentComments, commentsArgs)
|
||||
|
@ -53,7 +53,7 @@ func RecentComments(h *wp.Handle, id string) string {
|
|||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, conf["title"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
return args, true
|
||||
})
|
||||
|
||||
comments := slice.Map(cache.RecentComments(h.C, int(conf["number"].(int64))), func(t models.Comments) string {
|
||||
|
|
|
@ -2,13 +2,13 @@ package widget
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -44,14 +44,14 @@ func recentConf() map[any]any {
|
|||
}
|
||||
|
||||
func RecentPosts(h *wp.Handle, id string) string {
|
||||
conf := reload.GetAnyValBys("widget-recent-posts-conf", h, func(h *wp.Handle) map[any]any {
|
||||
conf := reload.GetAnyValBys("widget-recent-posts-conf", h, func(h *wp.Handle) (map[any]any, bool) {
|
||||
recent := recentConf()
|
||||
conf := wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-posts", recent, int64(2))
|
||||
conf = maps.FilterZeroMerge(recent, conf)
|
||||
return conf
|
||||
return conf, true
|
||||
})
|
||||
|
||||
args := reload.GetAnyValBys("widget-recent-posts-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("widget-recent-posts-args", h, func(h *wp.Handle) (map[string]string, bool) {
|
||||
recent := recentPostsArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.RecentPosts, recent)
|
||||
|
@ -62,7 +62,7 @@ func RecentPosts(h *wp.Handle, id string) string {
|
|||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, conf["title"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
return args, true
|
||||
})
|
||||
|
||||
currentPostId := uint64(0)
|
||||
|
|
|
@ -2,11 +2,11 @@ package widget
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/html"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
|
@ -48,7 +48,7 @@ func searchArgs() map[string]string {
|
|||
var form = html5SearchForm
|
||||
|
||||
func Search(h *wp.Handle, id string) string {
|
||||
args := reload.GetAnyValBys("widget-search-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("widget-search-args", h, func(h *wp.Handle) (map[string]string, bool) {
|
||||
search := searchArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.Search, search)
|
||||
|
@ -69,7 +69,7 @@ func Search(h *wp.Handle, id string) string {
|
|||
form = xmlSearchForm
|
||||
}
|
||||
|
||||
return args
|
||||
return args, true
|
||||
})
|
||||
s := strings.ReplaceAll(searchTemplate, "{$form}", form)
|
||||
val := ""
|
||||
|
|
|
@ -3,11 +3,11 @@ package wp
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/model"
|
||||
|
@ -20,14 +20,14 @@ func (h *Handle) DisplayHeaderText() bool {
|
|||
|
||||
func (h *Handle) GetCustomHeaderImg() (r models.PostThumbnail, isRand bool) {
|
||||
var err error
|
||||
img := reload.GetAnyValBys("headerImages", h.theme, func(theme string) []models.PostThumbnail {
|
||||
img := reload.GetAnyValBy("headerImages", h.theme, func(theme string) ([]models.PostThumbnail, bool) {
|
||||
hs, er := h.GetHeaderImages(h.theme)
|
||||
if er != nil {
|
||||
err = er
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
return hs
|
||||
})
|
||||
return hs, true
|
||||
}, 5)
|
||||
if err != nil {
|
||||
logs.Error(err, "获取页眉背景图失败")
|
||||
return
|
||||
|
|
|
@ -2,9 +2,9 @@ package wp
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
)
|
||||
|
@ -44,8 +44,8 @@ func CalCustomLogo(h *Handle) (r string) {
|
|||
|
||||
func customLogo(h *Handle) func() string {
|
||||
return func() string {
|
||||
return reload.GetAnyValBys("customLogo", h, func(h *Handle) string {
|
||||
return CalCustomLogo(h)
|
||||
return reload.GetAnyValBys("customLogo", h, func(h *Handle) (string, bool) {
|
||||
return CalCustomLogo(h), true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/plugins"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/number"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"github.com/fthvgb1/wp-go/model"
|
||||
|
@ -141,8 +141,8 @@ func (i *IndexHandle) BuildIndexData(parm *IndexParams) (err error) {
|
|||
func (i *IndexHandle) ExecPostsPlugin() {
|
||||
fn := i.postsPlugin
|
||||
if fn == nil {
|
||||
fn = reload.GetAnyValBys("postPlugins", i, func(a *IndexHandle) PostsPlugin {
|
||||
return UsePostsPlugins()
|
||||
fn = reload.GetAnyValBys("postPlugins", i, func(a *IndexHandle) (PostsPlugin, bool) {
|
||||
return UsePostsPlugins(), true
|
||||
})
|
||||
}
|
||||
for j := range i.Posts {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package wp
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/plugins"
|
||||
"github.com/fthvgb1/wp-go/app/plugins/wpposts"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package wp
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
|
@ -68,7 +68,7 @@ func (h *Handle) PushDataHandler(scene string, fns ...HandleCall) {
|
|||
func BuildPipe(pipeScene string, keyFn func(*Handle, string) string, fn func(*Handle, map[string][]HandleCall, string) []HandleCall) func(HandleFn[*Handle], *Handle) {
|
||||
return func(next HandleFn[*Handle], h *Handle) {
|
||||
key := keyFn(h, pipeScene)
|
||||
handlers := reload.GetAnyValMapBy("pipeHandlers", key, h, func(h *Handle) []HandleCall {
|
||||
handlers := reload.GetAnyValMapBy("pipeHandlers", key, h, func(h *Handle) ([]HandleCall, bool) {
|
||||
conf := h.handleHook[pipeScene]
|
||||
calls := fn(h, h.handlers[pipeScene], key)
|
||||
calls = slice.FilterAndMap(calls, func(call HandleCall) (HandleCall, bool) {
|
||||
|
@ -84,7 +84,7 @@ func BuildPipe(pipeScene string, keyFn func(*Handle, string) string, fn func(*Ha
|
|||
slice.Sort(calls, func(i, j HandleCall) bool {
|
||||
return i.Order > j.Order
|
||||
})
|
||||
return calls
|
||||
return calls, true
|
||||
})
|
||||
for _, handler := range handlers {
|
||||
handler.Fn(h)
|
||||
|
@ -107,7 +107,7 @@ func Run(h *Handle, conf func(*Handle)) {
|
|||
if !helper.GetContextVal(h.C, "inited", false) {
|
||||
InitHandle(conf, h)
|
||||
}
|
||||
reload.GetAnyValBys(str.Join("pipeInit-", h.scene), h, func(h *Handle) func(*Handle) {
|
||||
reload.GetAnyValBys(str.Join("pipeInit-", h.scene), h, func(h *Handle) (func(*Handle), bool) {
|
||||
p := GetFn[Pipe]("pipe", constraints.AllScene)
|
||||
p = append(p, GetFn[Pipe]("pipe", h.scene)...)
|
||||
pipes := slice.FilterAndMap(p, func(pipe Pipe) (Pipe, bool) {
|
||||
|
@ -128,7 +128,7 @@ func Run(h *Handle, conf func(*Handle)) {
|
|||
arr := slice.Map(pipes, func(t Pipe) HandlePipeFn[*Handle] {
|
||||
return t.Fn
|
||||
})
|
||||
return HandlePipe(NothingToDo, arr...)
|
||||
return HandlePipe(NothingToDo, arr...), true
|
||||
})(h)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package route
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"regexp"
|
||||
|
@ -74,7 +74,7 @@ func ResolveRoute(h *wp.Handle) {
|
|||
requestURI := h.C.Request.RequestURI
|
||||
rs, rrs := reload.GetAnyValBys("route",
|
||||
struct{}{},
|
||||
func(_ struct{}) func() (map[string]Route, map[string]*regexp.Regexp) {
|
||||
func(_ struct{}) (func() (map[string]Route, map[string]*regexp.Regexp), bool) {
|
||||
m := map[string]Route{}
|
||||
rrs := map[string]*regexp.Regexp{}
|
||||
routes.Range(func(key string, value Route) bool {
|
||||
|
@ -82,19 +82,21 @@ func ResolveRoute(h *wp.Handle) {
|
|||
if len(routeHook) > 0 {
|
||||
for _, fn := range routeHook {
|
||||
v, ok := fn(value)
|
||||
if ok {
|
||||
m[v.Path] = v
|
||||
if v.Type == "reg" {
|
||||
if v.Path != key {
|
||||
vvv, err := regexp.Compile(v.Path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
vv = vvv
|
||||
}
|
||||
rrs[v.Path] = vv
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
m[v.Path] = v
|
||||
if v.Type != "reg" {
|
||||
continue
|
||||
}
|
||||
if v.Path != key {
|
||||
vvv, err := regexp.Compile(v.Path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
vv = vvv
|
||||
}
|
||||
rrs[v.Path] = vv
|
||||
}
|
||||
} else {
|
||||
m[key] = value
|
||||
|
@ -105,7 +107,7 @@ func ResolveRoute(h *wp.Handle) {
|
|||
})
|
||||
return func() (map[string]Route, map[string]*regexp.Regexp) {
|
||||
return m, rrs
|
||||
}
|
||||
}, true
|
||||
})()
|
||||
v, ok := rs[requestURI]
|
||||
if ok && slice.IsContained(v.Method, h.C.Request.Method) {
|
||||
|
|
|
@ -3,18 +3,18 @@ package wp
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/elliotchance/phpserialize"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
)
|
||||
|
||||
func (h *Handle) StickPosts() []models.Posts {
|
||||
return reload.GetAnyValBys("stickPostsSlice", h, func(h *Handle) (r []models.Posts) {
|
||||
return reload.GetAnyValBys("stickPostsSlice", h, func(h *Handle) (r []models.Posts, ok bool) {
|
||||
v := wpconfig.GetOption("sticky_posts")
|
||||
if v == "" {
|
||||
return
|
||||
|
@ -30,15 +30,16 @@ func (h *Handle) StickPosts() []models.Posts {
|
|||
post.IsSticky = true
|
||||
return post, err == nil
|
||||
})
|
||||
ok = true
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handle) StickMapPosts() map[uint64]models.Posts {
|
||||
return reload.GetAnyValBys("stickPostsMap", h, func(h *Handle) map[uint64]models.Posts {
|
||||
return reload.GetAnyValBys("stickPostsMap", h, func(h *Handle) (map[uint64]models.Posts, bool) {
|
||||
return slice.SimpleToMap(h.StickPosts(), func(v models.Posts) uint64 {
|
||||
return v.Id
|
||||
})
|
||||
}), true
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@ package wp
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
||||
"github.com/fthvgb1/wp-go/app/plugins/wphandle/apply"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/gin-contrib/sessions"
|
||||
|
@ -100,7 +100,7 @@ type HandleCall struct {
|
|||
|
||||
func InitHandle(fn func(*Handle), h *Handle) {
|
||||
var inited = false
|
||||
hh := reload.GetAnyValBys("themeArgAndConfig", h, func(h *Handle) Handle {
|
||||
hh := reload.GetAnyValBys("themeArgAndConfig", h, func(h *Handle) (Handle, bool) {
|
||||
h.components = make(map[string]map[string][]Components[string])
|
||||
h.componentsArgs = make(map[string]any)
|
||||
h.componentFilterFn = make(map[string][]func(*Handle, string, ...any) string)
|
||||
|
@ -117,7 +117,7 @@ func InitHandle(fn func(*Handle), h *Handle) {
|
|||
}
|
||||
h.C.Set("inited", true)
|
||||
inited = true
|
||||
return *h
|
||||
return *h, true
|
||||
})
|
||||
h.ginH = maps.Copy(hh.ginH)
|
||||
h.ginH["calPostClass"] = postClass(h)
|
||||
|
|
|
@ -3,10 +3,10 @@ package wpconfig
|
|||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/phphelper"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"path/filepath"
|
||||
|
|
2
cache/cachemanager/manger.go
vendored
2
cache/cachemanager/manger.go
vendored
|
@ -3,8 +3,8 @@ package cachemanager
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/cache"
|
||||
"github.com/fthvgb1/wp-go/cache/reload"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"time"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package reload
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/helper"
|
||||
"github.com/fthvgb1/wp-go/helper/number"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
|
@ -63,14 +64,13 @@ func GetAnyMapFnBys[K comparable, V, A any](namespace string, fn func(A) V) func
|
|||
return v
|
||||
}
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
v, ok = m.val.Load(key)
|
||||
if ok {
|
||||
m.mutex.Unlock()
|
||||
return v
|
||||
}
|
||||
v = fn(a)
|
||||
m.val.Store(key, v)
|
||||
m.mutex.Unlock()
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ func safetyMapFn[K comparable, V, A any](namespace string, args ...any) *safetyM
|
|||
m = vv.(*safetyMap[K, V, A])
|
||||
} else {
|
||||
safetyMapLock.Lock()
|
||||
defer safetyMapLock.Unlock()
|
||||
vv, ok = safetyMaps.Load(namespace)
|
||||
if ok {
|
||||
m = vv.(*safetyMap[K, V, A])
|
||||
|
@ -102,26 +103,26 @@ func safetyMapFn[K comparable, V, A any](namespace string, args ...any) *safetyM
|
|||
}, ord, namespace)
|
||||
safetyMaps.Store(namespace, m)
|
||||
}
|
||||
safetyMapLock.Unlock()
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func GetAnyValMapBy[K comparable, V, A any](namespace string, key K, a A, fn func(A) V, args ...any) V {
|
||||
func GetAnyValMapBy[K comparable, V, A any](namespace string, key K, a A, fn func(A) (V, bool), args ...any) V {
|
||||
m := safetyMapFn[K, V, A](namespace, args...)
|
||||
v, ok := m.val.Load(key)
|
||||
if ok {
|
||||
return v
|
||||
}
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
v, ok = m.val.Load(key)
|
||||
if ok {
|
||||
m.mutex.Unlock()
|
||||
return v
|
||||
}
|
||||
v = fn(a)
|
||||
m.val.Store(key, v)
|
||||
m.mutex.Unlock()
|
||||
v, ok = fn(a)
|
||||
if ok {
|
||||
m.val.Store(key, v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
|
@ -132,6 +133,7 @@ func anyVal[T, A any](namespace string, counter bool, args ...any) *safetyVar[T,
|
|||
vv = vvv.(*safetyVar[T, A])
|
||||
} else {
|
||||
safetyMapLock.Lock()
|
||||
defer safetyMapLock.Unlock()
|
||||
vvv, ok = safetyMaps.Load(namespace)
|
||||
if ok {
|
||||
vv = vvv.(*safetyVar[T, A])
|
||||
|
@ -147,12 +149,11 @@ func anyVal[T, A any](namespace string, counter bool, args ...any) *safetyVar[T,
|
|||
}, ord, namespace)
|
||||
safetyMaps.Store(namespace, vv)
|
||||
}
|
||||
safetyMapLock.Unlock()
|
||||
}
|
||||
return vv
|
||||
}
|
||||
|
||||
func GetAnyValBy[T, A any](namespace string, tryTimes int, a A, fn func(A) (T, bool), args ...any) T {
|
||||
func GetAnyValBy[T, A any](namespace string, a A, fn func(A) (T, bool), args ...any) T {
|
||||
var vv = anyVal[T, A](namespace, true, args...)
|
||||
var ok bool
|
||||
v := vv.Val.Load()
|
||||
|
@ -160,37 +161,38 @@ func GetAnyValBy[T, A any](namespace string, tryTimes int, a A, fn func(A) (T, b
|
|||
return v.v
|
||||
}
|
||||
vv.mutex.Lock()
|
||||
defer vv.mutex.Unlock()
|
||||
v = vv.Val.Load()
|
||||
if v.ok {
|
||||
vv.mutex.Unlock()
|
||||
return v.v
|
||||
}
|
||||
v.v, ok = fn(a)
|
||||
if v.counter == nil {
|
||||
v.counter = number.Counters[int]()
|
||||
}
|
||||
times := v.counter()
|
||||
tryTimes := helper.ParseArgs(1, args...)
|
||||
if ok || times >= tryTimes {
|
||||
v.ok = true
|
||||
vv.Val.Store(v)
|
||||
}
|
||||
vv.mutex.Unlock()
|
||||
return v.v
|
||||
}
|
||||
|
||||
func GetAnyValBys[T, A any](namespace string, a A, fn func(A) T, args ...any) T {
|
||||
func GetAnyValBys[T, A any](namespace string, a A, fn func(A) (T, bool), args ...any) T {
|
||||
var vv = anyVal[T, A](namespace, false, args...)
|
||||
v := vv.Val.Load()
|
||||
if v.ok {
|
||||
return v.v
|
||||
}
|
||||
vv.mutex.Lock()
|
||||
defer vv.mutex.Unlock()
|
||||
v = vv.Val.Load()
|
||||
if v.ok {
|
||||
vv.mutex.Unlock()
|
||||
return v.v
|
||||
}
|
||||
v.v = fn(a)
|
||||
v.ok = true
|
||||
v.v, v.ok = fn(a)
|
||||
vv.Val.Store(v)
|
||||
vv.mutex.Unlock()
|
||||
return v.v
|
||||
}
|
||||
|
||||
|
@ -253,7 +255,6 @@ func SafeMap[K comparable, T any](args ...any) *safety.Map[K, T] {
|
|||
func Push(fn func(), a ...any) {
|
||||
ord, name := parseArgs(a...)
|
||||
calls.Append(queue{fn, ord, name})
|
||||
//calls = append(calls, queue{fn, ord, name})
|
||||
if name != "" {
|
||||
callsM.Store(name, fn)
|
||||
}
|
||||
|
@ -261,7 +262,6 @@ func Push(fn func(), a ...any) {
|
|||
|
||||
func Reload() {
|
||||
anyMap.Flush()
|
||||
//safetyMaps.Flush()
|
||||
callsM.Flush()
|
||||
flushMapFn.Flush()
|
||||
callll := calls.Load()
|
|
@ -134,3 +134,13 @@ func GetAnyVal[T any](v any, defaults T) T {
|
|||
}
|
||||
return vv
|
||||
}
|
||||
|
||||
func ParseArgs[T any](defaults T, a ...any) T {
|
||||
for _, aa := range a {
|
||||
v, ok := aa.(T)
|
||||
if ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return defaults
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ func NewSlice[T any](a []T) *Slice[T] {
|
|||
|
||||
func (r *Slice[T]) Append(t ...T) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
ts := append(r.Load(), t...)
|
||||
r.Store(ts)
|
||||
r.mu.Unlock()
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user