1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
package main
import ( "fmt" "github.com/go-akka/configuration" )
var configText = ` #################################### # Typesafe HOCON # ####################################
config { # Comment version = "0.0.1" one-second = 1s one-day = 1day array = ["one", "two", "three"] #comment bar = "bar" foo = foo.${config.bar} number = 1 object { a = "a" b = "b" c = { d = ${config.object.a} //comment } } } // fallback config.object.a="newA" config.object.c.f="valueF"
// self reference self-ref=1 self-ref=[${self-ref}][2]
// byte size byte-size=10MiB
// system envs home:${HOME}
plus-equal=foo plus-equal+=bar
plus-equal-array=[foo] plus-equal-array+=[bar, ${HOME}] `
func main() { conf := configuration.ParseString(configText)
fmt.Println("config.one-second:", conf.GetTimeDuration("config.one-second")) fmt.Println("config.one-day:", conf.GetTimeDuration("config.one-day")) fmt.Println("config.array:", conf.GetStringList("config.array")) fmt.Println("config.bar:", conf.GetString("config.bar")) fmt.Println("config.foo:", conf.GetString("config.foo")) fmt.Println("config.number:", conf.GetInt64("config.number")) fmt.Println("config.object.a:", conf.GetString("config.object.a")) fmt.Println("config.object.c.d:", conf.GetString("config.object.c.d")) fmt.Println("config.object.c.f:", conf.GetString("config.object.c.f")) fmt.Println("self-ref:", conf.GetInt64List("self-ref")) fmt.Println("byte-size:", conf.GetByteSize("byte-size")) fmt.Println("home:", conf.GetString("home")) fmt.Println("default:", conf.GetString("none", "default-value")) fmt.Println("plus-equal:", conf.GetString("plus-equal")) fmt.Println("plus-equal-array:", conf.GetStringList("plus-equal-array")) }
|