Browse Source

Update so it compiles

Fixed issue 4
Fixed issue 8
Fixed issue 9
Fixed issue 10
Fixed issue 11
master
Stephen Weinberg 11 years ago
parent
commit
f602e48a7b
  1. 2
      Makefile
  2. 10
      conf.go
  3. 6
      get.go
  4. 2
      read.go
  5. 2
      write.go

2
Makefile

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

10
conf.go

@ -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

@ -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}
}
}

2
read.go

@ -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
}

2
write.go

@ -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 {

Loading…
Cancel
Save