| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"log" |
| 6 |
"os" |
| 7 |
|
| 8 |
"github.com/knadh/koanf/parsers/json" |
| 9 |
"github.com/knadh/koanf/providers/s3" |
| 10 |
"github.com/knadh/koanf/v2" |
| 11 |
) |
| 12 |
|
| 13 |
// Global koanf instance. Use "." as the key path delimiter. This can be "/" or any character. |
| 14 |
var k = koanf.New(".") |
| 15 |
|
| 16 |
func main() { |
| 17 |
// Load JSON config from s3. |
| 18 |
if err := k.Load(s3.Provider(s3.Config{ |
| 19 |
AccessKey: os.Getenv("AWS_S3_ACCESS_KEY"), |
| 20 |
SecretKey: os.Getenv("AWS_S3_SECRET_KEY"), |
| 21 |
Region: os.Getenv("AWS_S3_REGION"), |
| 22 |
Bucket: os.Getenv("AWS_S3_BUCKET"), |
| 23 |
ObjectKey: "mock/mock.json", |
| 24 |
}), json.Parser()); err != nil { |
| 25 |
log.Fatalf("error loading config: %v", err) |
| 26 |
} |
| 27 |
|
| 28 |
fmt.Println("parent's name is = ", k.String("parent1.name")) |
| 29 |
fmt.Println("parent's ID is = ", k.Int("parent1.id")) |
| 30 |
} |