2020-12-26 15:17:20 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-01-20 21:28:48 +00:00
|
|
|
grpcConfig "github.com/asim/go-micro/plugins/config/source/grpc/v3"
|
2021-08-11 22:27:04 -07:00
|
|
|
"github.com/asim/go-micro/v3/config"
|
|
|
|
log "github.com/asim/go-micro/v3/logger"
|
2020-12-26 15:17:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Micro struct {
|
|
|
|
Info
|
|
|
|
}
|
|
|
|
|
|
|
|
type Info struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
Message string `json:"message,omitempty"`
|
|
|
|
Age int `json:"age,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// create new source
|
|
|
|
source := grpcConfig.NewSource(
|
|
|
|
grpcConfig.WithAddress("127.0.0.1:8600"),
|
|
|
|
grpcConfig.WithPath("/micro"),
|
|
|
|
)
|
|
|
|
|
|
|
|
// create new config
|
|
|
|
conf, _ := config.NewConfig()
|
|
|
|
|
|
|
|
// load the source into config
|
|
|
|
if err := conf.Load(source); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
configs := &Micro{}
|
|
|
|
if err := conf.Scan(configs); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 22:27:04 -07:00
|
|
|
log.Infof("Read config: %s", string(conf.Bytes()))
|
2020-12-26 15:17:20 +00:00
|
|
|
|
|
|
|
// watch the config for changes
|
|
|
|
watcher, err := conf.Watch()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 22:27:04 -07:00
|
|
|
log.Infof("Watching for changes ...")
|
2020-12-26 15:17:20 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
v, err := watcher.Next()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-08-11 22:27:04 -07:00
|
|
|
log.Infof("Watching for changes: %v", string(v.Bytes()))
|
2020-12-26 15:17:20 +00:00
|
|
|
}
|
|
|
|
}
|