Documentation ¶
Index ¶
- Constants
- func DuplicatedSectionNameError(sectionName string) error
- func DuplicatedVariableNameError(variableName, sectionName string) error
- func Marshal(cfg *Config) string
- func WriteConfigFile(filename string, cfg *Config) error
- type BoolValue
- type Config
- type DecimalValue
- type IntegerValue
- type ListValue
- type Section
- type StringValue
- type Variable
- type VariableValue
Examples ¶
Constants ¶
View Source
const ( BoolType = iota StringType IntegerType DecimalType ListType )
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Example ¶
cfg := NewConfig() cfg.AddSection( NewSection("a"). AddVariable(NewVariable("name", "Joy")). AddVariable(NewVariable("age", 18))). AddSection( NewSection("b"). AddVariable(NewVariable("single", false)). AddVariable(NewVariable("money", 813.01))). AddSection( NewSection("c"). AddVariable(NewVariable("contact", []string{"12345", "123456"}))) fmt.Println(Marshal(cfg))
Output: [a] age = 18 name = "Joy" [b] money = 813.010000 single = no [c] contact = "12345", "123456"
func WriteConfigFile ¶
Types ¶
type Config ¶
func NewConfig ¶
func NewConfig() *Config
Example ¶
cfg := NewConfig() cfg.AddSection( NewSection("a"). AddVariable(NewVariable("name", "Joy")). AddVariable(NewVariable("age", 18))). AddSection( NewSection("b"). AddVariable(NewVariable("single", false)). AddVariable(NewVariable("money", 813.01))). AddSection( NewSection("c"). AddVariable(NewVariable("contact", []string{"12345", "123456"}))) fmt.Print(cfg.ToString())
Output: Config { Sections = [ Section(a) { Variables = { age = 18 name = "Joy" } } Section(b) { Variables = { money = 813.010000 single = no } } Section(c) { Variables = { contact = "12345", "123456" } } ] }
func ReadConfigFile ¶
func (*Config) AddSection ¶
func (*Config) CreateIfAbsent ¶
func (*Config) SetIfAbsent ¶
type DecimalValue ¶
type DecimalValue struct {
V float64
}
func NewDecimalValue ¶
func NewDecimalValue(v float64) *DecimalValue
func (*DecimalValue) ToString ¶
func (d *DecimalValue) ToString() string
func (*DecimalValue) Type ¶
func (d *DecimalValue) Type() int
func (*DecimalValue) Value ¶
func (d *DecimalValue) Value() interface{}
type IntegerValue ¶
type IntegerValue struct {
V int
}
func NewIntegerValue ¶
func NewIntegerValue(v int) *IntegerValue
func (*IntegerValue) ToString ¶
func (i *IntegerValue) ToString() string
func (*IntegerValue) Type ¶
func (i *IntegerValue) Type() int
func (*IntegerValue) Value ¶
func (i *IntegerValue) Value() interface{}
type ListValue ¶
type ListValue struct {
V []VariableValue
}
func NewListValue ¶
func NewListValue(v ...VariableValue) *ListValue
type Section ¶
func NewSection ¶
func (*Section) AddVariable ¶
func (*Section) CreateIfAbsent ¶
func (*Section) SetIfAbsent ¶
type StringValue ¶
type StringValue struct {
V string
}
func NewStringValue ¶
func NewStringValue(v string) *StringValue
func (*StringValue) ToString ¶
func (s *StringValue) ToString() string
func (*StringValue) Type ¶
func (s *StringValue) Type() int
func (*StringValue) Value ¶
func (s *StringValue) Value() interface{}
type Variable ¶
type Variable struct { Name string Value VariableValue }
func NewVariable ¶
NewVariable creates a new variable, supported value type are: bool, string, int, float64 and slice of these primitive types
func (*Variable) List ¶
func (v *Variable) List() []VariableValue
func (*Variable) SetValue ¶
func (v *Variable) SetValue(value VariableValue)
type VariableValue ¶
Click to show internal directories.
Click to hide internal directories.