mirror of
https://github.com/go-micro/go-micro.git
synced 2025-05-19 21:23:04 +02:00
35 lines
600 B
Go
35 lines
600 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/micro/go-micro/v2/config"
|
||
|
"github.com/micro/go-micro/v2/config/source/file"
|
||
|
)
|
||
|
|
||
|
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)
|
||
|
}
|