2020-12-26 15:17:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-10-12 12:55:53 +01:00
|
|
|
"go-micro.dev/v4/config"
|
|
|
|
"go-micro.dev/v4/config/source/file"
|
2020-12-26 15:17:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// load the config from a file source
|
|
|
|
if err := config.Load(file.NewSource(
|
|
|
|
file.WithPath("./config.json"),
|
|
|
|
)); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// define our own host type
|
|
|
|
type Host struct {
|
|
|
|
Address string `json:"address"`
|
|
|
|
Port int `json:"port"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var host Host
|
|
|
|
|
|
|
|
// read a database host
|
|
|
|
if err := config.Get("hosts", "database").Scan(&host); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(host.Address, host.Port)
|
|
|
|
}
|