From bf7cc3a37c3a2580a84fd5b5e0426e21e82efee5 Mon Sep 17 00:00:00 2001 From: Andreas Krennmair Date: Sun, 29 Jan 2012 01:52:54 +0100 Subject: [PATCH] make goconf compile with latest weekly. --- conf.go | 10 +++++----- get.go | 24 ++++++++---------------- read.go | 14 +++++++------- write.go | 8 ++++---- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/conf.go b/conf.go index 59d5f0a..0bc4477 100644 --- a/conf.go +++ b/conf.go @@ -105,9 +105,9 @@ func (c *ConfigFile) RemoveSection(section string) bool { return false // default section cannot be removed default: 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 @@ -142,7 +142,7 @@ func (c *ConfigFile) RemoveOption(section string, option string) bool { } _, ok := c.data[section][option] - c.data[section][option] = "", false + delete(c.data[section], option) return ok } @@ -168,7 +168,7 @@ type GetError struct { Option string } -func (err GetError) String() string { +func (err GetError) Error() string { switch err.Reason { case SectionNotFound: return fmt.Sprintf("section '%s' not found", string(err.Section)) @@ -188,7 +188,7 @@ type ReadError struct { Line string } -func (err ReadError) String() string { +func (err ReadError) Error() string { switch err.Reason { case BlankSection: return "empty section name not allowed" diff --git a/get.go b/get.go index 2fb10c6..a4a1000 100644 --- a/get.go +++ b/get.go @@ -1,9 +1,8 @@ package conf import ( - "os" - "strings" "strconv" + "strings" ) // GetSections returns the list of sections in the configuration. @@ -31,11 +30,10 @@ func (c *ConfigFile) HasSection(section string) bool { return ok } - // 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. // 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 == "" { section = "default" } @@ -59,7 +57,6 @@ func (c *ConfigFile) GetOptions(section string) (options []string, err os.Error) return options, nil } - // HasOption checks if the configuration has the given option in the section. // It returns false if either the option or section do not exist. 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 } - // 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. // 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 == "" { section = "default" } @@ -100,12 +96,11 @@ func (c *ConfigFile) GetRawString(section string, option string) (value string, return "", GetError{SectionNotFound, "", "", section, option} } - // 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), // 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. -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) if err != nil { return "", err @@ -143,9 +138,8 @@ func (c *ConfigFile) GetString(section string, option string) (value string, err return value, nil } - // 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) if err == nil { 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 } - // 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) if err == nil { - value, err = strconv.Atof64(sv) + value, err = strconv.ParseFloat(sv, 64) if err != nil { 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 } - // GetBool has the same behaviour as GetString but converts the response 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) if err != nil { return false, err diff --git a/read.go b/read.go index 82af45b..c9690f1 100644 --- a/read.go +++ b/read.go @@ -1,16 +1,16 @@ package conf import ( + "bufio" + "bytes" "io" "os" - "bytes" - "bufio" "strings" ) // ReadConfigFile reads a file and returns a new configuration representation. // 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 if file, err = os.Open(fname); err != nil { @@ -29,7 +29,7 @@ func ReadConfigFile(fname string) (c *ConfigFile, err os.Error) { return c, nil } -func ReadConfigBytes(conf []byte) (c *ConfigFile, err os.Error) { +func ReadConfigBytes(conf []byte) (c *ConfigFile, err error) { buf := bytes.NewBuffer(conf) 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 // 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) var section, option string @@ -52,7 +52,7 @@ func (c *ConfigFile) Read(reader io.Reader) (err os.Error) { l = strings.TrimSpace(l) if buferr != nil { - if buferr != os.EOF { + if buferr != io.EOF { return err } @@ -103,7 +103,7 @@ func (c *ConfigFile) Read(reader io.Reader) (err os.Error) { } // Reached end of file - if buferr == os.EOF { + if buferr == io.EOF { break } } diff --git a/write.go b/write.go index be3cc64..9cc7dd5 100644 --- a/write.go +++ b/write.go @@ -1,15 +1,15 @@ package conf import ( - "os" - "io" "bytes" + "io" + "os" ) // WriteConfigFile saves the configuration representation to a file. // 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. -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 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. -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) if header != "" {