make goconf compile with latest weekly.
This commit is contained in:
parent
f602e48a7b
commit
bf7cc3a37c
10
conf.go
10
conf.go
|
@ -105,9 +105,9 @@ func (c *ConfigFile) RemoveSection(section string) bool {
|
||||||
return false // default section cannot be removed
|
return false // default section cannot be removed
|
||||||
default:
|
default:
|
||||||
for o, _ := range c.data[section] {
|
for o, _ := range c.data[section] {
|
||||||
c.data[section][o] = "", false
|
delete(c.data[section], o)
|
||||||
}
|
}
|
||||||
c.data[section] = nil, false
|
delete(c.data, section)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -142,7 +142,7 @@ func (c *ConfigFile) RemoveOption(section string, option string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := c.data[section][option]
|
_, ok := c.data[section][option]
|
||||||
c.data[section][option] = "", false
|
delete(c.data[section], option)
|
||||||
|
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ type GetError struct {
|
||||||
Option string
|
Option string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err GetError) String() string {
|
func (err GetError) Error() string {
|
||||||
switch err.Reason {
|
switch err.Reason {
|
||||||
case SectionNotFound:
|
case SectionNotFound:
|
||||||
return fmt.Sprintf("section '%s' not found", string(err.Section))
|
return fmt.Sprintf("section '%s' not found", string(err.Section))
|
||||||
|
@ -188,7 +188,7 @@ type ReadError struct {
|
||||||
Line string
|
Line string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err ReadError) String() string {
|
func (err ReadError) Error() string {
|
||||||
switch err.Reason {
|
switch err.Reason {
|
||||||
case BlankSection:
|
case BlankSection:
|
||||||
return "empty section name not allowed"
|
return "empty section name not allowed"
|
||||||
|
|
24
get.go
24
get.go
|
@ -1,9 +1,8 @@
|
||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetSections returns the list of sections in the configuration.
|
// GetSections returns the list of sections in the configuration.
|
||||||
|
@ -31,11 +30,10 @@ func (c *ConfigFile) HasSection(section string) bool {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetOptions returns the list of options available in the given section.
|
// GetOptions returns the list of options available in the given section.
|
||||||
// It returns an error if the section does not exist and an empty list if the section is empty.
|
// It returns an error if the section does not exist and an empty list if the section is empty.
|
||||||
// Options within the default section are also included.
|
// Options within the default section are also included.
|
||||||
func (c *ConfigFile) GetOptions(section string) (options []string, err os.Error) {
|
func (c *ConfigFile) GetOptions(section string) (options []string, err error) {
|
||||||
if section == "" {
|
if section == "" {
|
||||||
section = "default"
|
section = "default"
|
||||||
}
|
}
|
||||||
|
@ -59,7 +57,6 @@ func (c *ConfigFile) GetOptions(section string) (options []string, err os.Error)
|
||||||
return options, nil
|
return options, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HasOption checks if the configuration has the given option in the section.
|
// HasOption checks if the configuration has the given option in the section.
|
||||||
// It returns false if either the option or section do not exist.
|
// It returns false if either the option or section do not exist.
|
||||||
func (c *ConfigFile) HasOption(section string, option string) bool {
|
func (c *ConfigFile) HasOption(section string, option string) bool {
|
||||||
|
@ -79,11 +76,10 @@ func (c *ConfigFile) HasOption(section string, option string) bool {
|
||||||
return okd || oknd
|
return okd || oknd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetRawString gets the (raw) string value for the given option in the section.
|
// GetRawString gets the (raw) string value for the given option in the section.
|
||||||
// The raw string value is not subjected to unfolding, which was illustrated in the beginning of this documentation.
|
// The raw string value is not subjected to unfolding, which was illustrated in the beginning of this documentation.
|
||||||
// It returns an error if either the section or the option do not exist.
|
// It returns an error if either the section or the option do not exist.
|
||||||
func (c *ConfigFile) GetRawString(section string, option string) (value string, err os.Error) {
|
func (c *ConfigFile) GetRawString(section string, option string) (value string, err error) {
|
||||||
if section == "" {
|
if section == "" {
|
||||||
section = "default"
|
section = "default"
|
||||||
}
|
}
|
||||||
|
@ -100,12 +96,11 @@ func (c *ConfigFile) GetRawString(section string, option string) (value string,
|
||||||
return "", GetError{SectionNotFound, "", "", section, option}
|
return "", GetError{SectionNotFound, "", "", section, option}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetString gets the string value for the given option in the section.
|
// GetString gets the string value for the given option in the section.
|
||||||
// If the value needs to be unfolded (see e.g. %(host)s example in the beginning of this documentation),
|
// If the value needs to be unfolded (see e.g. %(host)s example in the beginning of this documentation),
|
||||||
// then GetString does this unfolding automatically, up to DepthValues number of iterations.
|
// then GetString does this unfolding automatically, up to DepthValues number of iterations.
|
||||||
// It returns an error if either the section or the option do not exist, or the unfolding cycled.
|
// It returns an error if either the section or the option do not exist, or the unfolding cycled.
|
||||||
func (c *ConfigFile) GetString(section string, option string) (value string, err os.Error) {
|
func (c *ConfigFile) GetString(section string, option string) (value string, err error) {
|
||||||
value, err = c.GetRawString(section, option)
|
value, err = c.GetRawString(section, option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -143,9 +138,8 @@ func (c *ConfigFile) GetString(section string, option string) (value string, err
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetInt has the same behaviour as GetString but converts the response to int.
|
// GetInt has the same behaviour as GetString but converts the response to int.
|
||||||
func (c *ConfigFile) GetInt(section string, option string) (value int, err os.Error) {
|
func (c *ConfigFile) GetInt(section string, option string) (value int, err error) {
|
||||||
sv, err := c.GetString(section, option)
|
sv, err := c.GetString(section, option)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
value, err = strconv.Atoi(sv)
|
value, err = strconv.Atoi(sv)
|
||||||
|
@ -157,12 +151,11 @@ func (c *ConfigFile) GetInt(section string, option string) (value int, err os.Er
|
||||||
return value, err
|
return value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetFloat has the same behaviour as GetString but converts the response to float.
|
// GetFloat has the same behaviour as GetString but converts the response to float.
|
||||||
func (c *ConfigFile) GetFloat64(section string, option string) (value float64, err os.Error) {
|
func (c *ConfigFile) GetFloat64(section string, option string) (value float64, err error) {
|
||||||
sv, err := c.GetString(section, option)
|
sv, err := c.GetString(section, option)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
value, err = strconv.Atof64(sv)
|
value, err = strconv.ParseFloat(sv, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = GetError{CouldNotParse, "float64", sv, section, option}
|
err = GetError{CouldNotParse, "float64", sv, section, option}
|
||||||
}
|
}
|
||||||
|
@ -171,10 +164,9 @@ func (c *ConfigFile) GetFloat64(section string, option string) (value float64, e
|
||||||
return value, err
|
return value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// GetBool has the same behaviour as GetString but converts the response to bool.
|
// GetBool has the same behaviour as GetString but converts the response to bool.
|
||||||
// See constant BoolStrings for string values converted to bool.
|
// See constant BoolStrings for string values converted to bool.
|
||||||
func (c *ConfigFile) GetBool(section string, option string) (value bool, err os.Error) {
|
func (c *ConfigFile) GetBool(section string, option string) (value bool, err error) {
|
||||||
sv, err := c.GetString(section, option)
|
sv, err := c.GetString(section, option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
14
read.go
14
read.go
|
@ -1,16 +1,16 @@
|
||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"bytes"
|
|
||||||
"bufio"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadConfigFile reads a file and returns a new configuration representation.
|
// ReadConfigFile reads a file and returns a new configuration representation.
|
||||||
// This representation can be queried with GetString, etc.
|
// This representation can be queried with GetString, etc.
|
||||||
func ReadConfigFile(fname string) (c *ConfigFile, err os.Error) {
|
func ReadConfigFile(fname string) (c *ConfigFile, err error) {
|
||||||
var file *os.File
|
var file *os.File
|
||||||
|
|
||||||
if file, err = os.Open(fname); err != nil {
|
if file, err = os.Open(fname); err != nil {
|
||||||
|
@ -29,7 +29,7 @@ func ReadConfigFile(fname string) (c *ConfigFile, err os.Error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadConfigBytes(conf []byte) (c *ConfigFile, err os.Error) {
|
func ReadConfigBytes(conf []byte) (c *ConfigFile, err error) {
|
||||||
buf := bytes.NewBuffer(conf)
|
buf := bytes.NewBuffer(conf)
|
||||||
|
|
||||||
c = NewConfigFile()
|
c = NewConfigFile()
|
||||||
|
@ -42,7 +42,7 @@ func ReadConfigBytes(conf []byte) (c *ConfigFile, err os.Error) {
|
||||||
|
|
||||||
// Read reads an io.Reader and returns a configuration representation. This
|
// Read reads an io.Reader and returns a configuration representation. This
|
||||||
// representation can be queried with GetString, etc.
|
// representation can be queried with GetString, etc.
|
||||||
func (c *ConfigFile) Read(reader io.Reader) (err os.Error) {
|
func (c *ConfigFile) Read(reader io.Reader) (err error) {
|
||||||
buf := bufio.NewReader(reader)
|
buf := bufio.NewReader(reader)
|
||||||
|
|
||||||
var section, option string
|
var section, option string
|
||||||
|
@ -52,7 +52,7 @@ func (c *ConfigFile) Read(reader io.Reader) (err os.Error) {
|
||||||
l = strings.TrimSpace(l)
|
l = strings.TrimSpace(l)
|
||||||
|
|
||||||
if buferr != nil {
|
if buferr != nil {
|
||||||
if buferr != os.EOF {
|
if buferr != io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ func (c *ConfigFile) Read(reader io.Reader) (err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reached end of file
|
// Reached end of file
|
||||||
if buferr == os.EOF {
|
if buferr == io.EOF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
8
write.go
8
write.go
|
@ -1,15 +1,15 @@
|
||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"io"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WriteConfigFile saves the configuration representation to a file.
|
// WriteConfigFile saves the configuration representation to a file.
|
||||||
// The desired file permissions must be passed as in os.Open.
|
// The desired file permissions must be passed as in os.Open.
|
||||||
// The header is a string that is saved as a comment in the first line of the file.
|
// The header is a string that is saved as a comment in the first line of the file.
|
||||||
func (c *ConfigFile) WriteConfigFile(fname string, perm uint32, header string) (err os.Error) {
|
func (c *ConfigFile) WriteConfigFile(fname string, perm uint32, header string) (err error) {
|
||||||
var file *os.File
|
var file *os.File
|
||||||
|
|
||||||
if file, err = os.Create(fname); err != nil {
|
if file, err = os.Create(fname); err != nil {
|
||||||
|
@ -32,7 +32,7 @@ func (c *ConfigFile) WriteConfigBytes(header string) (config []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes the configuration file to the io.Writer.
|
// Writes the configuration file to the io.Writer.
|
||||||
func (c *ConfigFile) Write(writer io.Writer, header string) (err os.Error) {
|
func (c *ConfigFile) Write(writer io.Writer, header string) (err error) {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
if header != "" {
|
if header != "" {
|
||||||
|
|
Loading…
Reference in New Issue