|
|
@ -9,8 +9,8 @@ type SectionValue struct { |
|
|
Includes []string |
|
|
Includes []string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewNamedSection(name string) SectionValue { |
|
|
|
|
|
return SectionValue{ |
|
|
|
|
|
|
|
|
func NewNamedSection(name string) *SectionValue { |
|
|
|
|
|
return &SectionValue{ |
|
|
Name: name, |
|
|
Name: name, |
|
|
Value: make(map[string]ConfigValue), |
|
|
Value: make(map[string]ConfigValue), |
|
|
Comments: make([]string, 0), |
|
|
Comments: make([]string, 0), |
|
|
@ -18,8 +18,8 @@ func NewNamedSection(name string) SectionValue { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewAnonymousSection() SectionValue { |
|
|
|
|
|
return SectionValue{ |
|
|
|
|
|
|
|
|
func NewAnonymousSection() *SectionValue { |
|
|
|
|
|
return &SectionValue{ |
|
|
Value: make(map[string]ConfigValue), |
|
|
Value: make(map[string]ConfigValue), |
|
|
Comments: make([]string, 0), |
|
|
Comments: make([]string, 0), |
|
|
Includes: make([]string, 0), |
|
|
Includes: make([]string, 0), |
|
|
@ -29,48 +29,48 @@ func NewAnonymousSection() SectionValue { |
|
|
func (this SectionValue) GetType() ConfigType { return SECTION } |
|
|
func (this SectionValue) GetType() ConfigType { return SECTION } |
|
|
func (this SectionValue) GetValue() interface{} { return this.Value } |
|
|
func (this SectionValue) GetValue() interface{} { return this.Value } |
|
|
|
|
|
|
|
|
func (this SectionValue) AddComment(comment string) { |
|
|
|
|
|
|
|
|
func (this *SectionValue) AddComment(comment string) { |
|
|
this.Comments = append(this.Comments, comment) |
|
|
this.Comments = append(this.Comments, comment) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) AddInclude(include string) { |
|
|
|
|
|
|
|
|
func (this *SectionValue) AddInclude(include string) { |
|
|
this.Includes = append(this.Includes, include) |
|
|
this.Includes = append(this.Includes, include) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) Set(name string, value ConfigValue) { |
|
|
|
|
|
|
|
|
func (this *SectionValue) Set(name string, value ConfigValue) { |
|
|
this.Value[name] = value |
|
|
this.Value[name] = value |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) Get(name string) ConfigValue { |
|
|
|
|
|
|
|
|
func (this *SectionValue) Get(name string) ConfigValue { |
|
|
return this.Value[name] |
|
|
return this.Value[name] |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) GetSection(name string) SectionValue { |
|
|
|
|
|
|
|
|
func (this *SectionValue) GetSection(name string) SectionValue { |
|
|
value := this.Value[name] |
|
|
value := this.Value[name] |
|
|
return value.(SectionValue) |
|
|
return value.(SectionValue) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) GetString(name string) StringValue { |
|
|
|
|
|
|
|
|
func (this *SectionValue) GetString(name string) StringValue { |
|
|
value := this.Value[name] |
|
|
value := this.Value[name] |
|
|
return value.(StringValue) |
|
|
return value.(StringValue) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) GetInteger(name string) IntegerValue { |
|
|
|
|
|
|
|
|
func (this *SectionValue) GetInteger(name string) IntegerValue { |
|
|
value := this.Value[name] |
|
|
value := this.Value[name] |
|
|
return value.(IntegerValue) |
|
|
return value.(IntegerValue) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) GetFloat(name string) FloatValue { |
|
|
|
|
|
|
|
|
func (this *SectionValue) GetFloat(name string) FloatValue { |
|
|
value := this.Value[name] |
|
|
value := this.Value[name] |
|
|
return value.(FloatValue) |
|
|
return value.(FloatValue) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) Contains(name string) bool { |
|
|
|
|
|
|
|
|
func (this *SectionValue) Contains(name string) bool { |
|
|
_, ok := this.Value[name] |
|
|
_, ok := this.Value[name] |
|
|
return ok |
|
|
return ok |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) ToJSON() ([]byte, error) { |
|
|
|
|
|
|
|
|
func (this *SectionValue) ToJSON() ([]byte, error) { |
|
|
data, err := this.ToMap() |
|
|
data, err := this.ToMap() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
@ -78,11 +78,11 @@ func (this SectionValue) ToJSON() ([]byte, error) { |
|
|
return json.Marshal(data) |
|
|
return json.Marshal(data) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (this SectionValue) ToMap() (map[string]interface{}, error) { |
|
|
|
|
|
|
|
|
func (this *SectionValue) ToMap() (map[string]interface{}, error) { |
|
|
settings := make(map[string]interface{}) |
|
|
settings := make(map[string]interface{}) |
|
|
for name, value := range this.Value { |
|
|
for name, value := range this.Value { |
|
|
if value.GetType() == SECTION { |
|
|
if value.GetType() == SECTION { |
|
|
data, err := value.(SectionValue).ToMap() |
|
|
|
|
|
|
|
|
data, err := value.(*SectionValue).ToMap() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|