代码拉取完成,页面将自动刷新
package components
import (
"gitee.com/nuokwan_backend_group/mvc/Base"
"github.com/tietang/props/kvs"
"regexp"
"strings"
"time"
)
type ConfigureWrapper struct {
instance kvs.ConfigSource
}
func (c *ConfigureWrapper) Strings(key string) []string {
return c.instance.Strings(key)
}
func (c *ConfigureWrapper) Ints(key string) []int {
return c.instance.Ints(key)
}
func (c *ConfigureWrapper) Float64s(key string) []float64 {
return c.instance.Float64s(key)
}
func (c *ConfigureWrapper) Durations(key string) []time.Duration {
return c.instance.Durations(key)
}
func (c *ConfigureWrapper) Get(key string) (string, error) {
return c.instance.Get(key)
}
func (c *ConfigureWrapper) GetDefault(key string, defaultValue string) string {
return c.instance.GetDefault(key, defaultValue)
}
func (c *ConfigureWrapper) GetInt(key string) (int, error) {
return c.instance.GetInt(key)
}
func (c *ConfigureWrapper) GetIntDefault(key string, defaultValue int) int {
return c.instance.GetIntDefault(key, defaultValue)
}
func (c *ConfigureWrapper) GetDuration(key string) (time.Duration, error) {
return c.instance.GetDuration(key)
}
func (c *ConfigureWrapper) GetDurationDefault(key string, defaultValue time.Duration) time.Duration {
return c.instance.GetDurationDefault(key, defaultValue)
}
func (c *ConfigureWrapper) GetBool(key string) (bool, error) {
return c.instance.GetBool(key)
}
func (c *ConfigureWrapper) GetBoolDefault(key string, defaultValue bool) bool {
return c.instance.GetBoolDefault(key, defaultValue)
}
func (c *ConfigureWrapper) GetFloat64(key string) (float64, error) {
return c.instance.GetFloat64(key)
}
func (c *ConfigureWrapper) GetFloat64Default(key string, defaultValue float64) float64 {
return c.instance.GetFloat64Default(key, defaultValue)
}
func (c *ConfigureWrapper) Set(key string, value string) {
c.instance.Set(key, value)
}
func (c *ConfigureWrapper) SetAll(data map[string]string) {
c.instance.SetAll(data)
}
func (c *ConfigureWrapper) Keys() []string {
return c.instance.Keys()
}
func (c *ConfigureWrapper) Unmarshal(t interface{}) error {
return c.instance.Unmarshal(t)
}
func (c *ConfigureWrapper) Create() interface{} {
return kvs.NewProperties()
}
func (c *ConfigureWrapper) Prefix(prefix string, withOutPrefix ...bool) Base.ConfigureFace {
var (
withOutPrefixBool = true
conf = c.Create().(kvs.ConfigSource)
reg, _ = regexp.Compile(`^` + prefix + `\.`)
face = Base.NewConfigure(NewConfigure(conf))
)
if len(withOutPrefix) > 0 {
withOutPrefixBool = withOutPrefix[0]
}
for _, key := range c.Keys() {
if !reg.MatchString(key) {
continue
}
if v, err := c.Get(key); err == nil {
if withOutPrefixBool {
if !strings.Contains(key, ".") {
key = strings.Replace(key, prefix, "", 1)
} else {
key = strings.Replace(key, prefix+".", "", 1)
}
}
// fmt.Println(prefix, key, v)
face.Set(key, v)
}
}
return face
}
func NewConfigure(instance ...kvs.ConfigSource) Base.IConfiguration {
if len(instance) == 0 {
return &ConfigureWrapper{instance: kvs.NewProperties()}
}
return &ConfigureWrapper{instance: instance[0]}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。