xml

package
v2.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package xml for config provider.

depend on github.com/beego/x2j.

go install github.com/beego/x2j.

Usage:

import(
  _ "github.com/whiliang/beego-multi-schema/v2/core/config/xml"
    "github.com/whiliang/beego-multi-schema/v2/core/config"
)

cnf, err := config.NewConfig("xml", "config.xml")

More docs http://beego.vip/docs/module/config.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct{}

Config is a xml config parser and implements Config interface. xml configurations should be included in <config></config> tag. only support key/value pair as <key>value</key> as each item.

func (*Config) Parse

func (xc *Config) Parse(filename string) (config.Configer, error)

Parse returns a ConfigContainer with parsed xml config map.

func (*Config) ParseData

func (xc *Config) ParseData(data []byte) (config.Configer, error)

ParseData xml data

type ConfigContainer

type ConfigContainer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ConfigContainer is a Config which represents the xml configuration.

func (*ConfigContainer) Bool

func (c *ConfigContainer) Bool(key string) (bool, error)

Bool returns the boolean value for a given key.

func (*ConfigContainer) DIY

func (c *ConfigContainer) DIY(key string) (v interface{}, err error)

DIY returns the raw value by a given key.

func (*ConfigContainer) DefaultBool

func (c *ConfigContainer) DefaultBool(key string, defaultVal bool) bool

DefaultBool return the bool value if has no error otherwise return the defaultVal

func (*ConfigContainer) DefaultFloat

func (c *ConfigContainer) DefaultFloat(key string, defaultVal float64) float64

DefaultFloat returns the float64 value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultInt

func (c *ConfigContainer) DefaultInt(key string, defaultVal int) int

DefaultInt returns the integer value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultInt64

func (c *ConfigContainer) DefaultInt64(key string, defaultVal int64) int64

DefaultInt64 returns the int64 value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultString

func (c *ConfigContainer) DefaultString(key string, defaultVal string) string

DefaultString returns the string value for a given key. if err != nil return defaultVal

func (*ConfigContainer) DefaultStrings

func (c *ConfigContainer) DefaultStrings(key string, defaultVal []string) []string

DefaultStrings returns the []string value for a given key. if err != nil return defaultVal

func (*ConfigContainer) Float

func (c *ConfigContainer) Float(key string) (float64, error)

Float returns the float value for a given key.

func (*ConfigContainer) GetSection

func (c *ConfigContainer) GetSection(section string) (map[string]string, error)

GetSection returns map for the given section

func (*ConfigContainer) Int

func (c *ConfigContainer) Int(key string) (int, error)

Int returns the integer value for a given key.

func (*ConfigContainer) Int64

func (c *ConfigContainer) Int64(key string) (int64, error)

Int64 returns the int64 value for a given key.

func (*ConfigContainer) OnChange

func (c *ConfigContainer) OnChange(key string, fn func(value string))

func (*ConfigContainer) SaveConfigFile

func (c *ConfigContainer) SaveConfigFile(filename string) (err error)

SaveConfigFile save the config into file

func (*ConfigContainer) Set

func (c *ConfigContainer) Set(key, val string) error

Set writes a new value for key.

func (*ConfigContainer) String

func (c *ConfigContainer) String(key string) (string, error)

String returns the string value for a given key.

func (*ConfigContainer) Strings

func (c *ConfigContainer) Strings(key string) ([]string, error)

Strings returns the []string value for a given key.

func (*ConfigContainer) Sub

func (c *ConfigContainer) Sub(key string) (config.Configer, error)

func (*ConfigContainer) Unmarshaler

func (c *ConfigContainer) Unmarshaler(prefix string, obj interface{}, opt ...config.DecodeOption) error

Unmarshaler is a little be inconvenient since the xml library doesn't know type. So when you use <id>1</id> The "1" is a string, not int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL