2023-01-18 15:04:12 +00:00
|
|
|
package theme
|
|
|
|
|
|
|
|
import (
|
2023-05-04 12:37:06 +00:00
|
|
|
"github.com/fthvgb1/wp-go/app/theme/wp"
|
2023-05-04 13:44:17 +00:00
|
|
|
"github.com/fthvgb1/wp-go/safety"
|
|
|
|
"net/http"
|
2023-01-18 15:04:12 +00:00
|
|
|
)
|
|
|
|
|
2023-05-04 13:44:17 +00:00
|
|
|
var themeMap = safety.NewMap[string, func(*wp.Handle)]()
|
2023-01-18 15:04:12 +00:00
|
|
|
|
2023-05-04 13:44:17 +00:00
|
|
|
func AddThemeHookFunc(name string, fn func(handle *wp.Handle)) {
|
|
|
|
if _, ok := themeMap.Load(name); ok {
|
2023-01-18 15:04:12 +00:00
|
|
|
panic("exists same name theme")
|
|
|
|
}
|
2023-05-04 13:44:17 +00:00
|
|
|
themeMap.Store(name, fn)
|
2023-01-18 15:04:12 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 13:44:17 +00:00
|
|
|
func Hook(themeName string, h *wp.Handle) {
|
|
|
|
fn, ok := themeMap.Load(themeName)
|
2023-01-18 15:04:12 +00:00
|
|
|
if ok && fn != nil {
|
2023-05-04 13:44:17 +00:00
|
|
|
fn(h)
|
2023-01-18 15:04:12 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-04 13:44:17 +00:00
|
|
|
h.C.String(http.StatusNotFound, "404")
|
2023-01-18 15:04:12 +00:00
|
|
|
}
|