Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ func (c *ConfigFile) DeleteKey(section, key string) bool {
// It returns an error and empty string value if the section does not exist,
// or key does not exist in DEFAULT and current sections.
func (c *ConfigFile) GetValue(section, key string) (string, error) {
unLocked := false
if c.BlockMode {
c.lock.RLock()
defer c.lock.RUnlock()
defer func() {
if !unLocked {
c.lock.RUnlock()
}
}()
}

// Blank section name represents DEFAULT section.
Expand All @@ -185,6 +190,10 @@ func (c *ConfigFile) GetValue(section, key string) (string, error) {
if !ok {
// Check if it is a sub-section.
if i := strings.LastIndex(section, "."); i > -1 {
if c.BlockMode {
unLocked = true
c.lock.RUnlock()
}
return c.GetValue(section[:i], key)
}

Expand All @@ -205,6 +214,10 @@ func (c *ConfigFile) GetValue(section, key string) (string, error) {
noption = strings.TrimRight(noption, ")s")

// Search variable in default section.
if c.BlockMode {
unLocked = true
c.lock.RUnlock()
}
nvalue, err := c.GetValue(DEFAULT_SECTION, noption)
if err != nil && section != DEFAULT_SECTION {
// Search in the same section.
Expand Down