wp-go/internal/wpconfig/options.go

38 lines
793 B
Go
Raw Permalink Normal View History

2022-11-17 08:29:39 +00:00
package wpconfig
2022-11-15 03:11:08 +00:00
import (
"context"
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/model"
"github.com/fthvgb1/wp-go/safety"
2023-01-19 06:12:59 +00:00
"strings"
2022-11-15 03:11:08 +00:00
)
var Options safety.Map[string, string]
func InitOptions() error {
ctx := context.Background()
2023-01-12 12:42:16 +00:00
ops, err := model.SimpleFind[models.Options](ctx, model.SqlBuilder{{"autoload", "yes"}}, "option_name, option_value")
2022-11-15 03:11:08 +00:00
if err != nil {
return err
}
if len(ops) == 0 {
2023-01-12 12:42:16 +00:00
ops, err = model.SimpleFind[models.Options](ctx, nil, "option_name, option_value")
2022-11-15 03:11:08 +00:00
if err != nil {
return err
}
}
for _, options := range ops {
Options.Store(options.OptionName, options.OptionValue)
}
return nil
}
2023-01-19 06:12:59 +00:00
func GetLang() string {
s, ok := Options.Load("WPLANG")
if !ok {
s = "zh-CN"
}
return strings.Replace(s, "_", "-", 1)
}