@@ -5,26 +5,32 @@ func New() *Config {
5
5
return & Config {}
6
6
}
7
7
8
+ // Config contains all the sections, comments and includes from a config file.
8
9
type Config struct {
9
10
Comment * Comment
10
11
Sections Sections
11
12
Includes Includes
12
13
}
13
14
15
+ // Includes is a list of Includes in a config file.
14
16
type Includes []* Include
15
17
16
- // A reference to an included configuration .
18
+ // Include is a reference to an included config file .
17
19
type Include struct {
18
20
Path string
19
21
Config * Config
20
22
}
21
23
24
+ // Comment string without the prefix '#' or ';'.
22
25
type Comment string
23
26
24
27
const (
28
+ // NoSubsection token is passed to Config.Section and Config.SetSection to
29
+ // represent the absence of a section.
25
30
NoSubsection = ""
26
31
)
27
32
33
+ // Section returns a existing section with the given name or creates a new one.
28
34
func (c * Config ) Section (name string ) * Section {
29
35
for i := len (c .Sections ) - 1 ; i >= 0 ; i -- {
30
36
s := c .Sections [i ]
@@ -38,36 +44,31 @@ func (c *Config) Section(name string) *Section {
38
44
return s
39
45
}
40
46
41
- // AddOption is a convenience method to add an option to a given
42
- // section and subsection.
43
- //
44
- // Use the NoSubsection constant for the subsection argument
45
- // if no subsection is wanted.
46
- func (s * Config ) AddOption (section string , subsection string , key string , value string ) * Config {
47
+ // AddOption adds an option to a given section and subsection. Use the
48
+ // NoSubsection constant for the subsection argument if no subsection is wanted.
49
+ func (c * Config ) AddOption (section string , subsection string , key string , value string ) * Config {
47
50
if subsection == "" {
48
- s .Section (section ).AddOption (key , value )
51
+ c .Section (section ).AddOption (key , value )
49
52
} else {
50
- s .Section (section ).Subsection (subsection ).AddOption (key , value )
53
+ c .Section (section ).Subsection (subsection ).AddOption (key , value )
51
54
}
52
55
53
- return s
56
+ return c
54
57
}
55
58
56
- // SetOption is a convenience method to set an option to a given
57
- // section and subsection.
58
- //
59
- // Use the NoSubsection constant for the subsection argument
60
- // if no subsection is wanted.
61
- func (s * Config ) SetOption (section string , subsection string , key string , value string ) * Config {
59
+ // SetOption sets an option to a given section and subsection. Use the
60
+ // NoSubsection constant for the subsection argument if no subsection is wanted.
61
+ func (c * Config ) SetOption (section string , subsection string , key string , value string ) * Config {
62
62
if subsection == "" {
63
- s .Section (section ).SetOption (key , value )
63
+ c .Section (section ).SetOption (key , value )
64
64
} else {
65
- s .Section (section ).Subsection (subsection ).SetOption (key , value )
65
+ c .Section (section ).Subsection (subsection ).SetOption (key , value )
66
66
}
67
67
68
- return s
68
+ return c
69
69
}
70
70
71
+ // RemoveSection removes a section from a config file.
71
72
func (c * Config ) RemoveSection (name string ) * Config {
72
73
result := Sections {}
73
74
for _ , s := range c .Sections {
@@ -80,6 +81,7 @@ func (c *Config) RemoveSection(name string) *Config {
80
81
return c
81
82
}
82
83
84
+ // RemoveSubsection remove s a subsection from a config file.
83
85
func (c * Config ) RemoveSubsection (section string , subsection string ) * Config {
84
86
for _ , s := range c .Sections {
85
87
if s .IsName (section ) {
0 commit comments