-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriter.go
More file actions
50 lines (46 loc) · 1.48 KB
/
writer.go
File metadata and controls
50 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package ini
// Add a new section to the config. If a section with this name already exists,
// the error DuplicateSectionError is returned and the section won't be added.
func (c *Config) AddSection(section string) error {
if c.HasSection(section) {
return DuplicateSectionError
}
(*c)[section] = make(map[string]string)
return nil
}
// Remove the given section from the config. If the section does not exist, the
// error NoSectionError is returned.
func (c *Config) RemoveSection(section string) error {
if !c.HasSection(section) {
return NoSectionError
}
delete(*c, section)
return nil
}
// Remove the given property from the passed section. If noch such section
// exists, NoSectionError will be returned. If the section exists but not the
// property, NoPropertyError will be returned.
func (c *Config) RemoveProperty(section, property string) error {
items, err := c.GetItems(section)
if err != nil {
return err
}
for _, item := range items {
if item.Property == property {
delete((*c)[section], item.Property)
return nil
}
}
return NoPropertyError{property}
}
// Set the given property in the given section to the passed value. Attempting
// to set values in non-existing sections will return NoSectionError. If the
// property does not exist yet, it will be created; otherwise its value will be
// overwritten.
func (c *Config) Set(section, property, value string) error {
if !c.HasSection(section) {
return NoSectionError
}
(*c)[section][property] = value
return nil
}