You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
944 B
55 lines
944 B
package json_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"gitoa.ru/go-4devs/config"
|
|
"gitoa.ru/go-4devs/config/provider/json"
|
|
"gitoa.ru/go-4devs/config/test"
|
|
)
|
|
|
|
func ExampleClient_Value() {
|
|
ctx := context.Background()
|
|
|
|
// read json config
|
|
jsonConfig, jerr := fixture.ReadFile("fixture/config.json")
|
|
if jerr != nil {
|
|
log.Printf("failed load file:%v", jerr)
|
|
|
|
return
|
|
}
|
|
|
|
config, err := config.New(
|
|
json.New(jsonConfig),
|
|
)
|
|
if err != nil {
|
|
log.Print(err)
|
|
|
|
return
|
|
}
|
|
|
|
title, err := config.Value(ctx, "app.name.title")
|
|
if err != nil {
|
|
log.Print("app.name.title", err)
|
|
|
|
return
|
|
}
|
|
|
|
cfgValue, err := config.Value(ctx, "cfg")
|
|
if err != nil {
|
|
log.Print("cfg ", err)
|
|
|
|
return
|
|
}
|
|
|
|
cfg := test.Config{}
|
|
_ = cfgValue.Unmarshal(&cfg)
|
|
|
|
fmt.Printf("title from json: %v\n", title.String())
|
|
fmt.Printf("struct from json: %+v\n", cfg)
|
|
// Output:
|
|
// title from json: config title
|
|
// struct from json: {Duration:21m0s Enabled:true}
|
|
}
|
|
|