mirror of
https://github.com/astaxie/beego.git
synced 2024-11-27 20:11:28 +00:00
Merge pull request #4143 from flycash/fix/moveIni
Move init so it will be default implementation of config
This commit is contained in:
commit
26b016a3a4
@ -48,22 +48,39 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Configer defines how to get and set value from configuration raw data.
|
// Configer defines how to get and set value from configuration raw data.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type Configer interface {
|
type Configer interface {
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
Set(key, val string) error //support section::key type in given key when using ini type.
|
Set(key, val string) error //support section::key type in given key when using ini type.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
String(key string) string //support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
String(key string) string //support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
Strings(key string) []string //get string slice
|
Strings(key string) []string //get string slice
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
Int(key string) (int, error)
|
Int(key string) (int, error)
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
Int64(key string) (int64, error)
|
Int64(key string) (int64, error)
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
Bool(key string) (bool, error)
|
Bool(key string) (bool, error)
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
Float(key string) (float64, error)
|
Float(key string) (float64, error)
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
DefaultString(key string, defaultVal string) string // support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
DefaultString(key string, defaultVal string) string // support section::key type in key string when using ini and json type; Int,Int64,Bool,Float,DIY are same.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
DefaultStrings(key string, defaultVal []string) []string //get string slice
|
DefaultStrings(key string, defaultVal []string) []string //get string slice
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
DefaultInt(key string, defaultVal int) int
|
DefaultInt(key string, defaultVal int) int
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
DefaultInt64(key string, defaultVal int64) int64
|
DefaultInt64(key string, defaultVal int64) int64
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
DefaultBool(key string, defaultVal bool) bool
|
DefaultBool(key string, defaultVal bool) bool
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
DefaultFloat(key string, defaultVal float64) float64
|
DefaultFloat(key string, defaultVal float64) float64
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
DIY(key string) (interface{}, error)
|
DIY(key string) (interface{}, error)
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
GetSection(section string) (map[string]string, error)
|
GetSection(section string) (map[string]string, error)
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
SaveConfigFile(filename string) error
|
SaveConfigFile(filename string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
config/env/env.go
vendored
5
config/env/env.go
vendored
@ -36,6 +36,7 @@ func init() {
|
|||||||
|
|
||||||
// Get returns a value by key.
|
// Get returns a value by key.
|
||||||
// If the key does not exist, the default value will be returned.
|
// If the key does not exist, the default value will be returned.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func Get(key string, defVal string) string {
|
func Get(key string, defVal string) string {
|
||||||
if val := env.Get(key); val != nil {
|
if val := env.Get(key); val != nil {
|
||||||
return val.(string)
|
return val.(string)
|
||||||
@ -45,6 +46,7 @@ func Get(key string, defVal string) string {
|
|||||||
|
|
||||||
// MustGet returns a value by key.
|
// MustGet returns a value by key.
|
||||||
// If the key does not exist, it will return an error.
|
// If the key does not exist, it will return an error.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func MustGet(key string) (string, error) {
|
func MustGet(key string) (string, error) {
|
||||||
if val := env.Get(key); val != nil {
|
if val := env.Get(key); val != nil {
|
||||||
return val.(string), nil
|
return val.(string), nil
|
||||||
@ -54,12 +56,14 @@ func MustGet(key string) (string, error) {
|
|||||||
|
|
||||||
// Set sets a value in the ENV copy.
|
// Set sets a value in the ENV copy.
|
||||||
// This does not affect the child process environment.
|
// This does not affect the child process environment.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func Set(key string, value string) {
|
func Set(key string, value string) {
|
||||||
env.Set(key, value)
|
env.Set(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustSet sets a value in the ENV copy and the child process environment.
|
// MustSet sets a value in the ENV copy and the child process environment.
|
||||||
// It returns an error in case the set operation failed.
|
// It returns an error in case the set operation failed.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func MustSet(key string, value string) error {
|
func MustSet(key string, value string) error {
|
||||||
err := os.Setenv(key, value)
|
err := os.Setenv(key, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -70,6 +74,7 @@ func MustSet(key string, value string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAll returns all keys/values in the current child process environment.
|
// GetAll returns all keys/values in the current child process environment.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func GetAll() map[string]string {
|
func GetAll() map[string]string {
|
||||||
items := env.Items()
|
items := env.Items()
|
||||||
envs := make(map[string]string, env.Count())
|
envs := make(map[string]string, env.Count())
|
||||||
|
@ -27,16 +27,16 @@ type fakeConfigContainer struct {
|
|||||||
func (c *fakeConfigContainer) getData(key string) string {
|
func (c *fakeConfigContainer) getData(key string) string {
|
||||||
return c.data[strings.ToLower(key)]
|
return c.data[strings.ToLower(key)]
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) Set(key, val string) error {
|
func (c *fakeConfigContainer) Set(key, val string) error {
|
||||||
c.data[strings.ToLower(key)] = val
|
c.data[strings.ToLower(key)] = val
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) String(key string) string {
|
func (c *fakeConfigContainer) String(key string) string {
|
||||||
return c.getData(key)
|
return c.getData(key)
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) DefaultString(key string, defaultval string) string {
|
func (c *fakeConfigContainer) DefaultString(key string, defaultval string) string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -44,7 +44,7 @@ func (c *fakeConfigContainer) DefaultString(key string, defaultval string) strin
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) Strings(key string) []string {
|
func (c *fakeConfigContainer) Strings(key string) []string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -52,7 +52,7 @@ func (c *fakeConfigContainer) Strings(key string) []string {
|
|||||||
}
|
}
|
||||||
return strings.Split(v, ";")
|
return strings.Split(v, ";")
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
func (c *fakeConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
||||||
v := c.Strings(key)
|
v := c.Strings(key)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
@ -60,11 +60,11 @@ func (c *fakeConfigContainer) DefaultStrings(key string, defaultval []string) []
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) Int(key string) (int, error) {
|
func (c *fakeConfigContainer) Int(key string) (int, error) {
|
||||||
return strconv.Atoi(c.getData(key))
|
return strconv.Atoi(c.getData(key))
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) DefaultInt(key string, defaultval int) int {
|
func (c *fakeConfigContainer) DefaultInt(key string, defaultval int) int {
|
||||||
v, err := c.Int(key)
|
v, err := c.Int(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -72,11 +72,11 @@ func (c *fakeConfigContainer) DefaultInt(key string, defaultval int) int {
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) Int64(key string) (int64, error) {
|
func (c *fakeConfigContainer) Int64(key string) (int64, error) {
|
||||||
return strconv.ParseInt(c.getData(key), 10, 64)
|
return strconv.ParseInt(c.getData(key), 10, 64)
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
func (c *fakeConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
||||||
v, err := c.Int64(key)
|
v, err := c.Int64(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -84,11 +84,11 @@ func (c *fakeConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) Bool(key string) (bool, error) {
|
func (c *fakeConfigContainer) Bool(key string) (bool, error) {
|
||||||
return ParseBool(c.getData(key))
|
return ParseBool(c.getData(key))
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
func (c *fakeConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
||||||
v, err := c.Bool(key)
|
v, err := c.Bool(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -96,11 +96,11 @@ func (c *fakeConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) Float(key string) (float64, error) {
|
func (c *fakeConfigContainer) Float(key string) (float64, error) {
|
||||||
return strconv.ParseFloat(c.getData(key), 64)
|
return strconv.ParseFloat(c.getData(key), 64)
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
func (c *fakeConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
||||||
v, err := c.Float(key)
|
v, err := c.Float(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,18 +108,18 @@ func (c *fakeConfigContainer) DefaultFloat(key string, defaultval float64) float
|
|||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) DIY(key string) (interface{}, error) {
|
func (c *fakeConfigContainer) DIY(key string) (interface{}, error) {
|
||||||
if v, ok := c.data[strings.ToLower(key)]; ok {
|
if v, ok := c.data[strings.ToLower(key)]; ok {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("key not find")
|
return nil, errors.New("key not find")
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) GetSection(section string) (map[string]string, error) {
|
func (c *fakeConfigContainer) GetSection(section string) (map[string]string, error) {
|
||||||
return nil, errors.New("not implement in the fakeConfigContainer")
|
return nil, errors.New("not implement in the fakeConfigContainer")
|
||||||
}
|
}
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *fakeConfigContainer) SaveConfigFile(filename string) error {
|
func (c *fakeConfigContainer) SaveConfigFile(filename string) error {
|
||||||
return errors.New("not implement in the fakeConfigContainer")
|
return errors.New("not implement in the fakeConfigContainer")
|
||||||
}
|
}
|
||||||
@ -127,6 +127,7 @@ func (c *fakeConfigContainer) SaveConfigFile(filename string) error {
|
|||||||
var _ Configer = new(fakeConfigContainer)
|
var _ Configer = new(fakeConfigContainer)
|
||||||
|
|
||||||
// NewFakeConfig return a fake Configer
|
// NewFakeConfig return a fake Configer
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func NewFakeConfig() Configer {
|
func NewFakeConfig() Configer {
|
||||||
return &fakeConfigContainer{
|
return &fakeConfigContainer{
|
||||||
data: make(map[string]string),
|
data: make(map[string]string),
|
||||||
|
@ -41,10 +41,12 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// IniConfig implements Config to parse ini file.
|
// IniConfig implements Config to parse ini file.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type IniConfig struct {
|
type IniConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse creates a new Config and parses the file configuration from the named file.
|
// Parse creates a new Config and parses the file configuration from the named file.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (ini *IniConfig) Parse(name string) (Configer, error) {
|
func (ini *IniConfig) Parse(name string) (Configer, error) {
|
||||||
return ini.parseFile(name)
|
return ini.parseFile(name)
|
||||||
}
|
}
|
||||||
@ -208,6 +210,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
|
|||||||
// ParseData parse ini the data
|
// ParseData parse ini the data
|
||||||
// When include other.conf,other.conf is either absolute directory
|
// When include other.conf,other.conf is either absolute directory
|
||||||
// or under beego in default temporary directory(/tmp/beego[-username]).
|
// or under beego in default temporary directory(/tmp/beego[-username]).
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (ini *IniConfig) ParseData(data []byte) (Configer, error) {
|
func (ini *IniConfig) ParseData(data []byte) (Configer, error) {
|
||||||
dir := "beego"
|
dir := "beego"
|
||||||
currentUser, err := user.Current()
|
currentUser, err := user.Current()
|
||||||
@ -224,6 +227,7 @@ func (ini *IniConfig) ParseData(data []byte) (Configer, error) {
|
|||||||
|
|
||||||
// IniConfigContainer A Config represents the ini configuration.
|
// IniConfigContainer A Config represents the ini configuration.
|
||||||
// When set and get value, support key as section:name type.
|
// When set and get value, support key as section:name type.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type IniConfigContainer struct {
|
type IniConfigContainer struct {
|
||||||
data map[string]map[string]string // section=> key:val
|
data map[string]map[string]string // section=> key:val
|
||||||
sectionComment map[string]string // section : comment
|
sectionComment map[string]string // section : comment
|
||||||
@ -232,12 +236,14 @@ type IniConfigContainer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bool returns the boolean value for a given key.
|
// Bool returns the boolean value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) Bool(key string) (bool, error) {
|
func (c *IniConfigContainer) Bool(key string) (bool, error) {
|
||||||
return ParseBool(c.getdata(key))
|
return ParseBool(c.getdata(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultBool returns the boolean value for a given key.
|
// DefaultBool returns the boolean value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
func (c *IniConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
||||||
v, err := c.Bool(key)
|
v, err := c.Bool(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -247,12 +253,14 @@ func (c *IniConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int returns the integer value for a given key.
|
// Int returns the integer value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) Int(key string) (int, error) {
|
func (c *IniConfigContainer) Int(key string) (int, error) {
|
||||||
return strconv.Atoi(c.getdata(key))
|
return strconv.Atoi(c.getdata(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultInt returns the integer value for a given key.
|
// DefaultInt returns the integer value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) DefaultInt(key string, defaultval int) int {
|
func (c *IniConfigContainer) DefaultInt(key string, defaultval int) int {
|
||||||
v, err := c.Int(key)
|
v, err := c.Int(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -262,12 +270,14 @@ func (c *IniConfigContainer) DefaultInt(key string, defaultval int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int64 returns the int64 value for a given key.
|
// Int64 returns the int64 value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) Int64(key string) (int64, error) {
|
func (c *IniConfigContainer) Int64(key string) (int64, error) {
|
||||||
return strconv.ParseInt(c.getdata(key), 10, 64)
|
return strconv.ParseInt(c.getdata(key), 10, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultInt64 returns the int64 value for a given key.
|
// DefaultInt64 returns the int64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
func (c *IniConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
||||||
v, err := c.Int64(key)
|
v, err := c.Int64(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -277,12 +287,14 @@ func (c *IniConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Float returns the float value for a given key.
|
// Float returns the float value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) Float(key string) (float64, error) {
|
func (c *IniConfigContainer) Float(key string) (float64, error) {
|
||||||
return strconv.ParseFloat(c.getdata(key), 64)
|
return strconv.ParseFloat(c.getdata(key), 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultFloat returns the float64 value for a given key.
|
// DefaultFloat returns the float64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
func (c *IniConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
||||||
v, err := c.Float(key)
|
v, err := c.Float(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -292,12 +304,14 @@ func (c *IniConfigContainer) DefaultFloat(key string, defaultval float64) float6
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string value for a given key.
|
// String returns the string value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) String(key string) string {
|
func (c *IniConfigContainer) String(key string) string {
|
||||||
return c.getdata(key)
|
return c.getdata(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultString returns the string value for a given key.
|
// DefaultString returns the string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) DefaultString(key string, defaultval string) string {
|
func (c *IniConfigContainer) DefaultString(key string, defaultval string) string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -308,6 +322,7 @@ func (c *IniConfigContainer) DefaultString(key string, defaultval string) string
|
|||||||
|
|
||||||
// Strings returns the []string value for a given key.
|
// Strings returns the []string value for a given key.
|
||||||
// Return nil if config value does not exist or is empty.
|
// Return nil if config value does not exist or is empty.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) Strings(key string) []string {
|
func (c *IniConfigContainer) Strings(key string) []string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -318,6 +333,7 @@ func (c *IniConfigContainer) Strings(key string) []string {
|
|||||||
|
|
||||||
// DefaultStrings returns the []string value for a given key.
|
// DefaultStrings returns the []string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
func (c *IniConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
||||||
v := c.Strings(key)
|
v := c.Strings(key)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
@ -327,6 +343,7 @@ func (c *IniConfigContainer) DefaultStrings(key string, defaultval []string) []s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSection returns map for the given section
|
// GetSection returns map for the given section
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) GetSection(section string) (map[string]string, error) {
|
func (c *IniConfigContainer) GetSection(section string) (map[string]string, error) {
|
||||||
if v, ok := c.data[section]; ok {
|
if v, ok := c.data[section]; ok {
|
||||||
return v, nil
|
return v, nil
|
||||||
@ -337,6 +354,7 @@ func (c *IniConfigContainer) GetSection(section string) (map[string]string, erro
|
|||||||
// SaveConfigFile save the config into file.
|
// SaveConfigFile save the config into file.
|
||||||
//
|
//
|
||||||
// BUG(env): The environment variable config item will be saved with real value in SaveConfigFile Function.
|
// BUG(env): The environment variable config item will be saved with real value in SaveConfigFile Function.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
|
func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
|
||||||
// Write configuration file by filename.
|
// Write configuration file by filename.
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
@ -437,6 +455,7 @@ func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
|
|||||||
// Set writes a new value for key.
|
// Set writes a new value for key.
|
||||||
// if write to one section, the key need be "section::key".
|
// if write to one section, the key need be "section::key".
|
||||||
// if the section is not existed, it panics.
|
// if the section is not existed, it panics.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) Set(key, value string) error {
|
func (c *IniConfigContainer) Set(key, value string) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
@ -465,6 +484,7 @@ func (c *IniConfigContainer) Set(key, value string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DIY returns the raw value by a given key.
|
// DIY returns the raw value by a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *IniConfigContainer) DIY(key string) (v interface{}, err error) {
|
func (c *IniConfigContainer) DIY(key string) (v interface{}, err error) {
|
||||||
if v, ok := c.data[strings.ToLower(key)]; ok {
|
if v, ok := c.data[strings.ToLower(key)]; ok {
|
||||||
return v, nil
|
return v, nil
|
||||||
|
@ -26,10 +26,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// JSONConfig is a json config parser and implements Config interface.
|
// JSONConfig is a json config parser and implements Config interface.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type JSONConfig struct {
|
type JSONConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse returns a ConfigContainer with parsed json config map.
|
// Parse returns a ConfigContainer with parsed json config map.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (js *JSONConfig) Parse(filename string) (Configer, error) {
|
func (js *JSONConfig) Parse(filename string) (Configer, error) {
|
||||||
file, err := os.Open(filename)
|
file, err := os.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -45,6 +47,7 @@ func (js *JSONConfig) Parse(filename string) (Configer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseData returns a ConfigContainer with json string
|
// ParseData returns a ConfigContainer with json string
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (js *JSONConfig) ParseData(data []byte) (Configer, error) {
|
func (js *JSONConfig) ParseData(data []byte) (Configer, error) {
|
||||||
x := &JSONConfigContainer{
|
x := &JSONConfigContainer{
|
||||||
data: make(map[string]interface{}),
|
data: make(map[string]interface{}),
|
||||||
@ -66,12 +69,14 @@ func (js *JSONConfig) ParseData(data []byte) (Configer, error) {
|
|||||||
|
|
||||||
// JSONConfigContainer A Config represents the json configuration.
|
// JSONConfigContainer A Config represents the json configuration.
|
||||||
// Only when get value, support key as section:name type.
|
// Only when get value, support key as section:name type.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type JSONConfigContainer struct {
|
type JSONConfigContainer struct {
|
||||||
data map[string]interface{}
|
data map[string]interface{}
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bool returns the boolean value for a given key.
|
// Bool returns the boolean value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) Bool(key string) (bool, error) {
|
func (c *JSONConfigContainer) Bool(key string) (bool, error) {
|
||||||
val := c.getData(key)
|
val := c.getData(key)
|
||||||
if val != nil {
|
if val != nil {
|
||||||
@ -82,6 +87,7 @@ func (c *JSONConfigContainer) Bool(key string) (bool, error) {
|
|||||||
|
|
||||||
// DefaultBool return the bool value if has no error
|
// DefaultBool return the bool value if has no error
|
||||||
// otherwise return the defaultval
|
// otherwise return the defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
func (c *JSONConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
||||||
if v, err := c.Bool(key); err == nil {
|
if v, err := c.Bool(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -90,6 +96,7 @@ func (c *JSONConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int returns the integer value for a given key.
|
// Int returns the integer value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) Int(key string) (int, error) {
|
func (c *JSONConfigContainer) Int(key string) (int, error) {
|
||||||
val := c.getData(key)
|
val := c.getData(key)
|
||||||
if val != nil {
|
if val != nil {
|
||||||
@ -105,6 +112,7 @@ func (c *JSONConfigContainer) Int(key string) (int, error) {
|
|||||||
|
|
||||||
// DefaultInt returns the integer value for a given key.
|
// DefaultInt returns the integer value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) DefaultInt(key string, defaultval int) int {
|
func (c *JSONConfigContainer) DefaultInt(key string, defaultval int) int {
|
||||||
if v, err := c.Int(key); err == nil {
|
if v, err := c.Int(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -113,6 +121,7 @@ func (c *JSONConfigContainer) DefaultInt(key string, defaultval int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int64 returns the int64 value for a given key.
|
// Int64 returns the int64 value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) Int64(key string) (int64, error) {
|
func (c *JSONConfigContainer) Int64(key string) (int64, error) {
|
||||||
val := c.getData(key)
|
val := c.getData(key)
|
||||||
if val != nil {
|
if val != nil {
|
||||||
@ -126,6 +135,7 @@ func (c *JSONConfigContainer) Int64(key string) (int64, error) {
|
|||||||
|
|
||||||
// DefaultInt64 returns the int64 value for a given key.
|
// DefaultInt64 returns the int64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
func (c *JSONConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
||||||
if v, err := c.Int64(key); err == nil {
|
if v, err := c.Int64(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -134,6 +144,7 @@ func (c *JSONConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Float returns the float value for a given key.
|
// Float returns the float value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) Float(key string) (float64, error) {
|
func (c *JSONConfigContainer) Float(key string) (float64, error) {
|
||||||
val := c.getData(key)
|
val := c.getData(key)
|
||||||
if val != nil {
|
if val != nil {
|
||||||
@ -147,6 +158,7 @@ func (c *JSONConfigContainer) Float(key string) (float64, error) {
|
|||||||
|
|
||||||
// DefaultFloat returns the float64 value for a given key.
|
// DefaultFloat returns the float64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
func (c *JSONConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
||||||
if v, err := c.Float(key); err == nil {
|
if v, err := c.Float(key); err == nil {
|
||||||
return v
|
return v
|
||||||
@ -155,6 +167,7 @@ func (c *JSONConfigContainer) DefaultFloat(key string, defaultval float64) float
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string value for a given key.
|
// String returns the string value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) String(key string) string {
|
func (c *JSONConfigContainer) String(key string) string {
|
||||||
val := c.getData(key)
|
val := c.getData(key)
|
||||||
if val != nil {
|
if val != nil {
|
||||||
@ -167,6 +180,7 @@ func (c *JSONConfigContainer) String(key string) string {
|
|||||||
|
|
||||||
// DefaultString returns the string value for a given key.
|
// DefaultString returns the string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) DefaultString(key string, defaultval string) string {
|
func (c *JSONConfigContainer) DefaultString(key string, defaultval string) string {
|
||||||
// TODO FIXME should not use "" to replace non existence
|
// TODO FIXME should not use "" to replace non existence
|
||||||
if v := c.String(key); v != "" {
|
if v := c.String(key); v != "" {
|
||||||
@ -176,6 +190,7 @@ func (c *JSONConfigContainer) DefaultString(key string, defaultval string) strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strings returns the []string value for a given key.
|
// Strings returns the []string value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) Strings(key string) []string {
|
func (c *JSONConfigContainer) Strings(key string) []string {
|
||||||
stringVal := c.String(key)
|
stringVal := c.String(key)
|
||||||
if stringVal == "" {
|
if stringVal == "" {
|
||||||
@ -186,6 +201,7 @@ func (c *JSONConfigContainer) Strings(key string) []string {
|
|||||||
|
|
||||||
// DefaultStrings returns the []string value for a given key.
|
// DefaultStrings returns the []string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
func (c *JSONConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
||||||
if v := c.Strings(key); v != nil {
|
if v := c.Strings(key); v != nil {
|
||||||
return v
|
return v
|
||||||
@ -194,6 +210,7 @@ func (c *JSONConfigContainer) DefaultStrings(key string, defaultval []string) []
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSection returns map for the given section
|
// GetSection returns map for the given section
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) GetSection(section string) (map[string]string, error) {
|
func (c *JSONConfigContainer) GetSection(section string) (map[string]string, error) {
|
||||||
if v, ok := c.data[section]; ok {
|
if v, ok := c.data[section]; ok {
|
||||||
return v.(map[string]string), nil
|
return v.(map[string]string), nil
|
||||||
@ -202,6 +219,7 @@ func (c *JSONConfigContainer) GetSection(section string) (map[string]string, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SaveConfigFile save the config into file
|
// SaveConfigFile save the config into file
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) SaveConfigFile(filename string) (err error) {
|
func (c *JSONConfigContainer) SaveConfigFile(filename string) (err error) {
|
||||||
// Write configuration file by filename.
|
// Write configuration file by filename.
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
@ -218,6 +236,7 @@ func (c *JSONConfigContainer) SaveConfigFile(filename string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set writes a new value for key.
|
// Set writes a new value for key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) Set(key, val string) error {
|
func (c *JSONConfigContainer) Set(key, val string) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
@ -226,6 +245,7 @@ func (c *JSONConfigContainer) Set(key, val string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DIY returns the raw value by a given key.
|
// DIY returns the raw value by a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) DIY(key string) (v interface{}, err error) {
|
func (c *JSONConfigContainer) DIY(key string) (v interface{}, err error) {
|
||||||
val := c.getData(key)
|
val := c.getData(key)
|
||||||
if val != nil {
|
if val != nil {
|
||||||
@ -235,6 +255,7 @@ func (c *JSONConfigContainer) DIY(key string) (v interface{}, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// section.key or key
|
// section.key or key
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *JSONConfigContainer) getData(key string) interface{} {
|
func (c *JSONConfigContainer) getData(key string) interface{} {
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -46,9 +46,11 @@ import (
|
|||||||
// Config is a xml config parser and implements Config interface.
|
// Config is a xml config parser and implements Config interface.
|
||||||
// xml configurations should be included in <config></config> tag.
|
// xml configurations should be included in <config></config> tag.
|
||||||
// only support key/value pair as <key>value</key> as each item.
|
// only support key/value pair as <key>value</key> as each item.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type Config struct{}
|
type Config struct{}
|
||||||
|
|
||||||
// Parse returns a ConfigContainer with parsed xml config map.
|
// Parse returns a ConfigContainer with parsed xml config map.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (xc *Config) Parse(filename string) (config.Configer, error) {
|
func (xc *Config) Parse(filename string) (config.Configer, error) {
|
||||||
context, err := ioutil.ReadFile(filename)
|
context, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -59,6 +61,7 @@ func (xc *Config) Parse(filename string) (config.Configer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseData xml data
|
// ParseData xml data
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (xc *Config) ParseData(data []byte) (config.Configer, error) {
|
func (xc *Config) ParseData(data []byte) (config.Configer, error) {
|
||||||
x := &ConfigContainer{data: make(map[string]interface{})}
|
x := &ConfigContainer{data: make(map[string]interface{})}
|
||||||
|
|
||||||
@ -73,12 +76,14 @@ func (xc *Config) ParseData(data []byte) (config.Configer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConfigContainer A Config represents the xml configuration.
|
// ConfigContainer A Config represents the xml configuration.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type ConfigContainer struct {
|
type ConfigContainer struct {
|
||||||
data map[string]interface{}
|
data map[string]interface{}
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bool returns the boolean value for a given key.
|
// Bool returns the boolean value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Bool(key string) (bool, error) {
|
func (c *ConfigContainer) Bool(key string) (bool, error) {
|
||||||
if v := c.data[key]; v != nil {
|
if v := c.data[key]; v != nil {
|
||||||
return config.ParseBool(v)
|
return config.ParseBool(v)
|
||||||
@ -88,6 +93,7 @@ func (c *ConfigContainer) Bool(key string) (bool, error) {
|
|||||||
|
|
||||||
// DefaultBool return the bool value if has no error
|
// DefaultBool return the bool value if has no error
|
||||||
// otherwise return the defaultval
|
// otherwise return the defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
func (c *ConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
||||||
v, err := c.Bool(key)
|
v, err := c.Bool(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -97,12 +103,14 @@ func (c *ConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int returns the integer value for a given key.
|
// Int returns the integer value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Int(key string) (int, error) {
|
func (c *ConfigContainer) Int(key string) (int, error) {
|
||||||
return strconv.Atoi(c.data[key].(string))
|
return strconv.Atoi(c.data[key].(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultInt returns the integer value for a given key.
|
// DefaultInt returns the integer value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultInt(key string, defaultval int) int {
|
func (c *ConfigContainer) DefaultInt(key string, defaultval int) int {
|
||||||
v, err := c.Int(key)
|
v, err := c.Int(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -112,12 +120,14 @@ func (c *ConfigContainer) DefaultInt(key string, defaultval int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int64 returns the int64 value for a given key.
|
// Int64 returns the int64 value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Int64(key string) (int64, error) {
|
func (c *ConfigContainer) Int64(key string) (int64, error) {
|
||||||
return strconv.ParseInt(c.data[key].(string), 10, 64)
|
return strconv.ParseInt(c.data[key].(string), 10, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultInt64 returns the int64 value for a given key.
|
// DefaultInt64 returns the int64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
func (c *ConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
||||||
v, err := c.Int64(key)
|
v, err := c.Int64(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -128,12 +138,14 @@ func (c *ConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Float returns the float value for a given key.
|
// Float returns the float value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Float(key string) (float64, error) {
|
func (c *ConfigContainer) Float(key string) (float64, error) {
|
||||||
return strconv.ParseFloat(c.data[key].(string), 64)
|
return strconv.ParseFloat(c.data[key].(string), 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultFloat returns the float64 value for a given key.
|
// DefaultFloat returns the float64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
func (c *ConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
||||||
v, err := c.Float(key)
|
v, err := c.Float(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -143,6 +155,7 @@ func (c *ConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string value for a given key.
|
// String returns the string value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) String(key string) string {
|
func (c *ConfigContainer) String(key string) string {
|
||||||
if v, ok := c.data[key].(string); ok {
|
if v, ok := c.data[key].(string); ok {
|
||||||
return v
|
return v
|
||||||
@ -152,6 +165,7 @@ func (c *ConfigContainer) String(key string) string {
|
|||||||
|
|
||||||
// DefaultString returns the string value for a given key.
|
// DefaultString returns the string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -161,6 +175,7 @@ func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strings returns the []string value for a given key.
|
// Strings returns the []string value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Strings(key string) []string {
|
func (c *ConfigContainer) Strings(key string) []string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -171,6 +186,7 @@ func (c *ConfigContainer) Strings(key string) []string {
|
|||||||
|
|
||||||
// DefaultStrings returns the []string value for a given key.
|
// DefaultStrings returns the []string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
func (c *ConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
||||||
v := c.Strings(key)
|
v := c.Strings(key)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
@ -180,6 +196,7 @@ func (c *ConfigContainer) DefaultStrings(key string, defaultval []string) []stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSection returns map for the given section
|
// GetSection returns map for the given section
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
|
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
|
||||||
if v, ok := c.data[section].(map[string]interface{}); ok {
|
if v, ok := c.data[section].(map[string]interface{}); ok {
|
||||||
mapstr := make(map[string]string)
|
mapstr := make(map[string]string)
|
||||||
@ -192,6 +209,7 @@ func (c *ConfigContainer) GetSection(section string) (map[string]string, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SaveConfigFile save the config into file
|
// SaveConfigFile save the config into file
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) SaveConfigFile(filename string) (err error) {
|
func (c *ConfigContainer) SaveConfigFile(filename string) (err error) {
|
||||||
// Write configuration file by filename.
|
// Write configuration file by filename.
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
@ -208,6 +226,7 @@ func (c *ConfigContainer) SaveConfigFile(filename string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set writes a new value for key.
|
// Set writes a new value for key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Set(key, val string) error {
|
func (c *ConfigContainer) Set(key, val string) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
@ -216,6 +235,7 @@ func (c *ConfigContainer) Set(key, val string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DIY returns the raw value by a given key.
|
// DIY returns the raw value by a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DIY(key string) (v interface{}, err error) {
|
func (c *ConfigContainer) DIY(key string) (v interface{}, err error) {
|
||||||
if v, ok := c.data[key]; ok {
|
if v, ok := c.data[key]; ok {
|
||||||
return v, nil
|
return v, nil
|
||||||
|
@ -45,9 +45,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Config is a yaml config parser and implements Config interface.
|
// Config is a yaml config parser and implements Config interface.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type Config struct{}
|
type Config struct{}
|
||||||
|
|
||||||
// Parse returns a ConfigContainer with parsed yaml config map.
|
// Parse returns a ConfigContainer with parsed yaml config map.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (yaml *Config) Parse(filename string) (y config.Configer, err error) {
|
func (yaml *Config) Parse(filename string) (y config.Configer, err error) {
|
||||||
cnf, err := ReadYmlReader(filename)
|
cnf, err := ReadYmlReader(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -60,6 +62,7 @@ func (yaml *Config) Parse(filename string) (y config.Configer, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ParseData parse yaml data
|
// ParseData parse yaml data
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (yaml *Config) ParseData(data []byte) (config.Configer, error) {
|
func (yaml *Config) ParseData(data []byte) (config.Configer, error) {
|
||||||
cnf, err := parseYML(data)
|
cnf, err := parseYML(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,6 +76,7 @@ func (yaml *Config) ParseData(data []byte) (config.Configer, error) {
|
|||||||
|
|
||||||
// ReadYmlReader Read yaml file to map.
|
// ReadYmlReader Read yaml file to map.
|
||||||
// if json like, use json package, unless goyaml2 package.
|
// if json like, use json package, unless goyaml2 package.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func ReadYmlReader(path string) (cnf map[string]interface{}, err error) {
|
func ReadYmlReader(path string) (cnf map[string]interface{}, err error) {
|
||||||
buf, err := ioutil.ReadFile(path)
|
buf, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -117,12 +121,14 @@ func parseYML(buf []byte) (cnf map[string]interface{}, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConfigContainer A Config represents the yaml configuration.
|
// ConfigContainer A Config represents the yaml configuration.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
type ConfigContainer struct {
|
type ConfigContainer struct {
|
||||||
data map[string]interface{}
|
data map[string]interface{}
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bool returns the boolean value for a given key.
|
// Bool returns the boolean value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Bool(key string) (bool, error) {
|
func (c *ConfigContainer) Bool(key string) (bool, error) {
|
||||||
v, err := c.getData(key)
|
v, err := c.getData(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -133,6 +139,7 @@ func (c *ConfigContainer) Bool(key string) (bool, error) {
|
|||||||
|
|
||||||
// DefaultBool return the bool value if has no error
|
// DefaultBool return the bool value if has no error
|
||||||
// otherwise return the defaultval
|
// otherwise return the defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
func (c *ConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
||||||
v, err := c.Bool(key)
|
v, err := c.Bool(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -142,6 +149,7 @@ func (c *ConfigContainer) DefaultBool(key string, defaultval bool) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int returns the integer value for a given key.
|
// Int returns the integer value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Int(key string) (int, error) {
|
func (c *ConfigContainer) Int(key string) (int, error) {
|
||||||
if v, err := c.getData(key); err != nil {
|
if v, err := c.getData(key); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -155,6 +163,7 @@ func (c *ConfigContainer) Int(key string) (int, error) {
|
|||||||
|
|
||||||
// DefaultInt returns the integer value for a given key.
|
// DefaultInt returns the integer value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultInt(key string, defaultval int) int {
|
func (c *ConfigContainer) DefaultInt(key string, defaultval int) int {
|
||||||
v, err := c.Int(key)
|
v, err := c.Int(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -164,6 +173,7 @@ func (c *ConfigContainer) DefaultInt(key string, defaultval int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int64 returns the int64 value for a given key.
|
// Int64 returns the int64 value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Int64(key string) (int64, error) {
|
func (c *ConfigContainer) Int64(key string) (int64, error) {
|
||||||
if v, err := c.getData(key); err != nil {
|
if v, err := c.getData(key); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -175,6 +185,7 @@ func (c *ConfigContainer) Int64(key string) (int64, error) {
|
|||||||
|
|
||||||
// DefaultInt64 returns the int64 value for a given key.
|
// DefaultInt64 returns the int64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
func (c *ConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
||||||
v, err := c.Int64(key)
|
v, err := c.Int64(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -184,6 +195,7 @@ func (c *ConfigContainer) DefaultInt64(key string, defaultval int64) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Float returns the float value for a given key.
|
// Float returns the float value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Float(key string) (float64, error) {
|
func (c *ConfigContainer) Float(key string) (float64, error) {
|
||||||
if v, err := c.getData(key); err != nil {
|
if v, err := c.getData(key); err != nil {
|
||||||
return 0.0, err
|
return 0.0, err
|
||||||
@ -199,6 +211,7 @@ func (c *ConfigContainer) Float(key string) (float64, error) {
|
|||||||
|
|
||||||
// DefaultFloat returns the float64 value for a given key.
|
// DefaultFloat returns the float64 value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
func (c *ConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
||||||
v, err := c.Float(key)
|
v, err := c.Float(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -208,6 +221,7 @@ func (c *ConfigContainer) DefaultFloat(key string, defaultval float64) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String returns the string value for a given key.
|
// String returns the string value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) String(key string) string {
|
func (c *ConfigContainer) String(key string) string {
|
||||||
if v, err := c.getData(key); err == nil {
|
if v, err := c.getData(key); err == nil {
|
||||||
if vv, ok := v.(string); ok {
|
if vv, ok := v.(string); ok {
|
||||||
@ -219,6 +233,7 @@ func (c *ConfigContainer) String(key string) string {
|
|||||||
|
|
||||||
// DefaultString returns the string value for a given key.
|
// DefaultString returns the string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -228,6 +243,7 @@ func (c *ConfigContainer) DefaultString(key string, defaultval string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Strings returns the []string value for a given key.
|
// Strings returns the []string value for a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Strings(key string) []string {
|
func (c *ConfigContainer) Strings(key string) []string {
|
||||||
v := c.String(key)
|
v := c.String(key)
|
||||||
if v == "" {
|
if v == "" {
|
||||||
@ -238,6 +254,7 @@ func (c *ConfigContainer) Strings(key string) []string {
|
|||||||
|
|
||||||
// DefaultStrings returns the []string value for a given key.
|
// DefaultStrings returns the []string value for a given key.
|
||||||
// if err != nil return defaultval
|
// if err != nil return defaultval
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
func (c *ConfigContainer) DefaultStrings(key string, defaultval []string) []string {
|
||||||
v := c.Strings(key)
|
v := c.Strings(key)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
@ -247,6 +264,7 @@ func (c *ConfigContainer) DefaultStrings(key string, defaultval []string) []stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetSection returns map for the given section
|
// GetSection returns map for the given section
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
|
func (c *ConfigContainer) GetSection(section string) (map[string]string, error) {
|
||||||
|
|
||||||
if v, ok := c.data[section]; ok {
|
if v, ok := c.data[section]; ok {
|
||||||
@ -256,6 +274,7 @@ func (c *ConfigContainer) GetSection(section string) (map[string]string, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SaveConfigFile save the config into file
|
// SaveConfigFile save the config into file
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) SaveConfigFile(filename string) (err error) {
|
func (c *ConfigContainer) SaveConfigFile(filename string) (err error) {
|
||||||
// Write configuration file by filename.
|
// Write configuration file by filename.
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
@ -268,6 +287,7 @@ func (c *ConfigContainer) SaveConfigFile(filename string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set writes a new value for key.
|
// Set writes a new value for key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) Set(key, val string) error {
|
func (c *ConfigContainer) Set(key, val string) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
@ -276,6 +296,7 @@ func (c *ConfigContainer) Set(key, val string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DIY returns the raw value by a given key.
|
// DIY returns the raw value by a given key.
|
||||||
|
// Deprecated: using pkg/config, we will delete this in v2.1.0
|
||||||
func (c *ConfigContainer) DIY(key string) (v interface{}, err error) {
|
func (c *ConfigContainer) DIY(key string) (v interface{}, err error) {
|
||||||
return c.getData(key)
|
return c.getData(key)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package ini
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@ -26,8 +26,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/astaxie/beego/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -47,7 +45,7 @@ type IniConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse creates a new Config and parses the file configuration from the named file.
|
// Parse creates a new Config and parses the file configuration from the named file.
|
||||||
func (ini *IniConfig) Parse(name string) (config.Configer, error) {
|
func (ini *IniConfig) Parse(name string) (Configer, error) {
|
||||||
return ini.parseFile(name)
|
return ini.parseFile(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +195,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
|
|||||||
val = bytes.Trim(val, `"`)
|
val = bytes.Trim(val, `"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.data[section][key] = config.ExpandValueEnv(string(val))
|
cfg.data[section][key] = ExpandValueEnv(string(val))
|
||||||
if comment.Len() > 0 {
|
if comment.Len() > 0 {
|
||||||
cfg.keyComment[section+"."+key] = comment.String()
|
cfg.keyComment[section+"."+key] = comment.String()
|
||||||
comment.Reset()
|
comment.Reset()
|
||||||
@ -210,7 +208,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e
|
|||||||
// ParseData parse ini the data
|
// ParseData parse ini the data
|
||||||
// When include other.conf,other.conf is either absolute directory
|
// When include other.conf,other.conf is either absolute directory
|
||||||
// or under beego in default temporary directory(/tmp/beego[-username]).
|
// or under beego in default temporary directory(/tmp/beego[-username]).
|
||||||
func (ini *IniConfig) ParseData(data []byte) (config.Configer, error) {
|
func (ini *IniConfig) ParseData(data []byte) (Configer, error) {
|
||||||
dir := "beego"
|
dir := "beego"
|
||||||
currentUser, err := user.Current()
|
currentUser, err := user.Current()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -235,7 +233,7 @@ type IniConfigContainer struct {
|
|||||||
|
|
||||||
// Bool returns the boolean value for a given key.
|
// Bool returns the boolean value for a given key.
|
||||||
func (c *IniConfigContainer) Bool(key string) (bool, error) {
|
func (c *IniConfigContainer) Bool(key string) (bool, error) {
|
||||||
return config.ParseBool(c.getdata(key))
|
return ParseBool(c.getdata(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultBool returns the boolean value for a given key.
|
// DefaultBool returns the boolean value for a given key.
|
||||||
@ -502,5 +500,5 @@ func (c *IniConfigContainer) getdata(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
config.Register("ini", &IniConfig{})
|
Register("ini", &IniConfig{})
|
||||||
}
|
}
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package ini
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -20,8 +20,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/astaxie/beego/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIni(t *testing.T) {
|
func TestIni(t *testing.T) {
|
||||||
@ -94,7 +92,7 @@ password = ${GOPATH}
|
|||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
defer os.Remove("testini.conf")
|
defer os.Remove("testini.conf")
|
||||||
iniconf, err := config.NewConfig("ini", "testini.conf")
|
iniconf, err := NewConfig("ini", "testini.conf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -167,7 +165,7 @@ httpport=8080
|
|||||||
name=mysql
|
name=mysql
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
cfg, err := config.NewConfigData("ini", []byte(inicontext))
|
cfg, err := NewConfigData("ini", []byte(inicontext))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user