Documentation ¶
Overview ¶
Package oap is a library for loading Apollo configuration into a struct. It supports JSON/YAML/TOML format. You can also use custom unmarshal for struct type filed.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Example ¶
const ( appid = "SampleApp" addr = "http://81.68.181.139:8080" // http://81.68.181.139/app/access_key.html?#/appid=SampleApp secret = "" ) if secret == "" { return } type FooConfig struct { Foo string `apollo:"abc"` } config := struct { FooConfig `apollo_namespace:"proper"` }{} client := agollo.NewClient(&agollo.Conf{ AppID: appid, MetaAddr: addr, AccesskeySecret: secret, }) if err := client.Start(); err != nil { panic(err) } if err := client.SubscribeToNamespaces("proper"); err != nil { panic(err) } fmt.Println(client.GetAllKeys(agollo.WithNamespace("application"))) fmt.Println(client.GetAllKeys(agollo.WithNamespace("proper"))) if err := oap.Decode(&config, client, make(map[string][]agollo.OpOption)); err != nil { panic(err) } fmt.Println(config.Foo)
Output:
func SetUnmarshalFunc ¶
func SetUnmarshalFunc(name string, f UnmarshalFunc)
You can use custom unmarshal for struct type filed. Package oap provides built-in support for JSON/YAML/TOML.
Types ¶
type UnmarshalFunc ¶
Click to show internal directories.
Click to hide internal directories.