Edited comments
This commit is contained in:
parent
0db041f3a4
commit
dbe859620b
45
conf.go
45
conf.go
|
@ -1,49 +1,8 @@
|
||||||
// This package implements a parser for configuration files.
|
// This package implements a parser for configuration files.
|
||||||
// This allows easy reading and writing of structured configuration files.
|
// This allows easy reading and writing of structured configuration files.
|
||||||
//
|
//
|
||||||
// Given a sample configuration file:
|
// You can get some example configuration files and documentation at
|
||||||
//
|
// http://code.google.com/p/goconf/
|
||||||
// [default]
|
|
||||||
// host=www.example.com
|
|
||||||
// protocol=http://
|
|
||||||
// base-url=%(protocol)s%(host)s
|
|
||||||
//
|
|
||||||
// [service-1]
|
|
||||||
// url=%(base-url)s/some/path
|
|
||||||
// delegation : on
|
|
||||||
// maxclients=200 # do not set this higher
|
|
||||||
// comments=This is a multi-line
|
|
||||||
// entry ; And this is a comment
|
|
||||||
//
|
|
||||||
// To read this configuration file, do:
|
|
||||||
//
|
|
||||||
// c, err := conf.ReadConfigFile("config.cfg");
|
|
||||||
// c.GetString("service-1", "url"); // result is string :http://www.example.com/some/path"
|
|
||||||
// c.GetInt("service-1", "maxclients"); // result is int 200
|
|
||||||
// c.GetBool("service-1", "delegation"); // result is bool true
|
|
||||||
// c.GetString("service-1", "comments"); // result is string "This is a multi-line\nentry"
|
|
||||||
//
|
|
||||||
// Note the support for unfolding variables (such as %(base-url)s), which are read from the special
|
|
||||||
// (reserved) section name [default].
|
|
||||||
//
|
|
||||||
// A new configuration file can also be created with:
|
|
||||||
//
|
|
||||||
// c := conf.NewConfigFile();
|
|
||||||
// c.AddSection("section");
|
|
||||||
// c.AddOption("section", "option", "value");
|
|
||||||
// c.WriteConfigFile("config.cfg", 0644, "A header for this file"); // use 0644 as file permission
|
|
||||||
//
|
|
||||||
// This results in the file:
|
|
||||||
//
|
|
||||||
// # A header for this file
|
|
||||||
// [section]
|
|
||||||
// option=value
|
|
||||||
//
|
|
||||||
// Note that sections and options are case-insensitive (values are case-sensitive)
|
|
||||||
// and are converted to lowercase when saved to a file.
|
|
||||||
//
|
|
||||||
// The functionality and workflow is loosely based on the configparser.py package
|
|
||||||
// of the Python Standard Library.
|
|
||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
2
write.go
2
write.go
|
@ -22,6 +22,7 @@ func (c *ConfigFile) WriteConfigFile(fname string, perm int, header string) (err
|
||||||
return file.Close();
|
return file.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteConfigBytes returns the configuration file.
|
||||||
func (c *ConfigFile) WriteConfigBytes(header string) (config []byte) {
|
func (c *ConfigFile) WriteConfigBytes(header string) (config []byte) {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ func (c *ConfigFile) WriteConfigBytes(header string) (config []byte) {
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 os.Error) {
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue