rewrite
This commit is contained in:
@@ -15,21 +15,11 @@ bool0=0
|
||||
booltrue = true
|
||||
distance=13.42
|
||||
iamsure = hopefully you're not mistaken
|
||||
float = 13.1984
|
||||
color`)
|
||||
float = 13.1984`)
|
||||
|
||||
func main() {
|
||||
r := bytes.NewReader(testConf) // creating io.Reader from []byte()
|
||||
config := conf.ParseReader(r) // we could call conf.ParseFile("filename") here
|
||||
|
||||
// First of all we can access parsed values directly:
|
||||
for key, value := range config.Settings {
|
||||
fmt.Println(key, value)
|
||||
}
|
||||
for opt := range config.Options {
|
||||
fmt.Println(opt)
|
||||
}
|
||||
fmt.Println()
|
||||
config, _ := conf.Read(r) // we could call conf.ParseFile("filename") here
|
||||
|
||||
// Find( key string) returns instance of Setting and an
|
||||
// error if key was not found
|
||||
@@ -39,8 +29,8 @@ func main() {
|
||||
// }
|
||||
//
|
||||
// You can access Setting's Value field (type string) directly.
|
||||
port, err := config.Find("port")
|
||||
fmt.Printf("variable port has type: %T, port.Value == %v, type of port.Value is: %T, error returned: %v\n", port, port.Value, port.Value, err)
|
||||
port, ok := config.Find("port")
|
||||
fmt.Printf("variable port has type: %T, port.Value == %v, type of port.Value is: %T, error returned: %v\n", port, port.Value, port.Value, ok)
|
||||
|
||||
// We can cast Setting.Value to a desired type including int, float64,
|
||||
// bool and string. Method will return an error if Setting Value field
|
||||
@@ -75,13 +65,6 @@ func main() {
|
||||
def := config.GetDefault("non-existant-key", "myvalue")
|
||||
fmt.Println(def.Value) // "myvalue"
|
||||
|
||||
// You can use HasOption method to find whether single-word options were
|
||||
// present in the the config
|
||||
if config.HasOption("color") {
|
||||
fmt.Println("Hooray, we've found option \"color\"!")
|
||||
// do something useful
|
||||
}
|
||||
|
||||
// Below code finds two keys with bool values in the Config
|
||||
// and outputs those.
|
||||
var t, f bool
|
||||
|
Reference in New Issue
Block a user