Skip to content

Commit 5aa8ea2

Browse files
committed
update docs
1 parent c2f3f71 commit 5aa8ea2

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

chainmap/chainmap.go

+7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package chainmap
22

3+
// Dict is a simple string->string map.
34
type Dict map[string]string
45

6+
// ChainMap contains a slice of Dicts for interpolation values.
57
type ChainMap struct {
68
maps []Dict
79
}
810

11+
// New creates a new ChainMap.
912
func New(dicts ...Dict) *ChainMap {
1013
chainMap := &ChainMap{
1114
maps: make([]Dict, 0),
@@ -15,14 +18,18 @@ func New(dicts ...Dict) *ChainMap {
1518
return chainMap
1619
}
1720

21+
// Add adds given dicts to the ChainMap.
1822
func (c *ChainMap) Add(dicts ...Dict) {
1923
c.maps = append(c.maps, dicts...)
2024
}
2125

26+
// Len returns the ammount of Dicts in the ChainMap.
2227
func (c *ChainMap) Len() int {
2328
return len(c.maps)
2429
}
2530

31+
// Get gets the last value with the given key from the ChainMap.
32+
// If key does not exist returns empty string.
2633
func (c *ChainMap) Get(key string) string {
2734
var value string
2835

methods.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func (p *ConfigParser) Options(section string) ([]string, error) {
7979

8080
// Get returns string value for the named option.
8181
//
82-
// Returns an error if a section does not exist
82+
// Returns an error if a section does not exist.
8383
// Returns an error if the option does not exist either in the section or in
84-
// the defaults
84+
// the defaults.
8585
func (p *ConfigParser) Get(section, option string) (string, error) {
8686
fn, ok := p.opt.converters["string"]
8787
returnFunc := func(v string) (string, error) {
@@ -174,6 +174,11 @@ func (p *ConfigParser) Set(section, option, value string) error {
174174
return setSection.Add(option, value)
175175
}
176176

177+
// GetInt64 returns int64 representation of the named option.
178+
//
179+
// Returns an error if a section does not exist.
180+
// Returns an error if the option does not exist either in the section or in
181+
// the defaults.
177182
func (p *ConfigParser) GetInt64(section, option string) (int64, error) {
178183
result, err := p.get(section, option)
179184
if err != nil {
@@ -198,6 +203,11 @@ func (p *ConfigParser) GetInt64(section, option string) (int64, error) {
198203
return int64(value.(int)), nil
199204
}
200205

206+
// GetFloat64 returns float64 representation of the named option.
207+
//
208+
// Returns an error if a section does not exist.
209+
// Returns an error if the option does not exist either in the section or in
210+
// the defaults.
201211
func (p *ConfigParser) GetFloat64(section, option string) (float64, error) {
202212
result, err := p.get(section, option)
203213
if err != nil {
@@ -221,6 +231,11 @@ func (p *ConfigParser) GetFloat64(section, option string) (float64, error) {
221231
return value.(float64), nil
222232
}
223233

234+
// GetBool returns bool representation of the named option.
235+
//
236+
// Returns an error if a section does not exist.
237+
// Returns an error if the option does not exist either in the section or in
238+
// the defaults.
224239
func (p *ConfigParser) GetBool(section, option string) (bool, error) {
225240
result, err := p.get(section, option)
226241
if err != nil {
@@ -245,6 +260,7 @@ func (p *ConfigParser) GetBool(section, option string) (bool, error) {
245260
return value.(bool), nil
246261
}
247262

263+
// RemoveSection removes given section from the ConfigParser.
248264
func (p *ConfigParser) RemoveSection(section string) error {
249265
if !p.HasSection(section) {
250266
return getNoSectionError(section)
@@ -254,6 +270,7 @@ func (p *ConfigParser) RemoveSection(section string) error {
254270
return nil
255271
}
256272

273+
// HasOption checks if section contains option.
257274
func (p *ConfigParser) HasOption(section, option string) (bool, error) {
258275
var s *Section
259276
if p.isDefaultSection(section) {
@@ -268,6 +285,7 @@ func (p *ConfigParser) HasOption(section, option string) (bool, error) {
268285
return err == nil, nil
269286
}
270287

288+
// RemoveOption removes option from the section.
271289
func (p *ConfigParser) RemoveOption(section, option string) error {
272290
var s *Section
273291
if p.isDefaultSection(section) {

section.go

+12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package configparser
22

33
import "strings"
44

5+
// Section represent each section of the configuration file.
56
type Section struct {
67
Name string
78
options Dict
89
lookup Dict
910
}
1011

12+
// Add adds new key-value pair to the section.
1113
func (s *Section) Add(key, value string) error {
1214
lookupKey := s.safeKey(key)
1315
s.options[key] = s.safeValue(value)
@@ -16,6 +18,10 @@ func (s *Section) Add(key, value string) error {
1618
return nil
1719
}
1820

21+
// Get returns value of an option with the given key.
22+
//
23+
// Returns an error if the option does not exist either in the section or in
24+
// the defaults.
1925
func (s *Section) Get(key string) (string, error) {
2026
lookupKey, present := s.lookup[s.safeKey(key)]
2127
if !present {
@@ -28,10 +34,12 @@ func (s *Section) Get(key string) (string, error) {
2834
return "", getNoOptionError(s.Name, key)
2935
}
3036

37+
// Options returns a slice of option names.
3138
func (s *Section) Options() []string {
3239
return s.options.Keys()
3340
}
3441

42+
// Items returns a Dict with the key-value pairs.
3543
func (s *Section) Items() Dict {
3644
return s.options
3745
}
@@ -44,6 +52,10 @@ func (s *Section) safeKey(in string) string {
4452
return strings.ToLower(strings.TrimSpace(in))
4553
}
4654

55+
// Remove removes option with the given name from the section.
56+
//
57+
// Returns an error if the option does not exist either in the section or in
58+
// the defaults.
4759
func (s *Section) Remove(key string) error {
4860
_, present := s.options[key]
4961
if !present {

0 commit comments

Comments
 (0)