Update so it compiles

Fixed issue 4
Fixed issue 8
Fixed issue 9
Fixed issue 10
Fixed issue 11
This commit is contained in:
Stephen Weinberg 2011-06-27 11:04:32 -04:00
parent 63d75cbe77
commit f602e48a7b
5 changed files with 11 additions and 11 deletions

View File

@ -1,4 +1,4 @@
include $(GOROOT)/src/Make.$(GOARCH)
include $(GOROOT)/src/Make.inc
TARG=conf
GOFILES=\

10
conf.go
View File

@ -171,13 +171,13 @@ type GetError struct {
func (err GetError) String() string {
switch err.Reason {
case SectionNotFound:
return fmt.Sprintf("section '%s' not found", err.Section)
return fmt.Sprintf("section '%s' not found", string(err.Section))
case OptionNotFound:
return fmt.Sprintf("option '%s' not found in section '%s'", err.Option, err.Section)
return fmt.Sprintf("option '%s' not found in section '%s'", string(err.Option), string(err.Section))
case CouldNotParse:
return fmt.Sprintf("could not parse %s value '%s'", err.ValueType, err.Value)
return fmt.Sprintf("could not parse %s value '%s'", string(err.ValueType), string(err.Value))
case MaxDepthReached:
return fmt.Sprintf("possible cycle while unfolding variables: max depth of %d reached", DepthValues)
return fmt.Sprintf("possible cycle while unfolding variables: max depth of %d reached", int(DepthValues))
}
return "invalid get error"
@ -193,7 +193,7 @@ func (err ReadError) String() string {
case BlankSection:
return "empty section name not allowed"
case CouldNotParse:
return fmt.Sprintf("could not parse line: %s", err.Line)
return fmt.Sprintf("could not parse line: %s", string(err.Line))
}
return "invalid read error"

6
get.go
View File

@ -159,12 +159,12 @@ func (c *ConfigFile) GetInt(section string, option string) (value int, err os.Er
// GetFloat has the same behaviour as GetString but converts the response to float.
func (c *ConfigFile) GetFloat(section string, option string) (value float, err os.Error) {
func (c *ConfigFile) GetFloat64(section string, option string) (value float64, err os.Error) {
sv, err := c.GetString(section, option)
if err == nil {
value, err = strconv.Atof(sv)
value, err = strconv.Atof64(sv)
if err != nil {
err = GetError{CouldNotParse, "float", sv, section, option}
err = GetError{CouldNotParse, "float64", sv, section, option}
}
}

View File

@ -13,7 +13,7 @@ import (
func ReadConfigFile(fname string) (c *ConfigFile, err os.Error) {
var file *os.File
if file, err = os.Open(fname, os.O_RDONLY, 0); err != nil {
if file, err = os.Open(fname); err != nil {
return nil, err
}

View File

@ -12,7 +12,7 @@ import (
func (c *ConfigFile) WriteConfigFile(fname string, perm uint32, header string) (err os.Error) {
var file *os.File
if file, err = os.Open(fname, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, perm); err != nil {
if file, err = os.Create(fname); err != nil {
return err
}
if err = c.Write(file, header); err != nil {