go-micro.dev/v5@v5.12.0/config/source/nats/README.md (about) 1 # Nats Source 2 3 The nats source reads config from nats key/values 4 5 ## Nats Format 6 7 The nats source expects keys under the default bucket `default` default key `micro_config` 8 9 Values are expected to be json 10 11 ``` 12 nats kv put default micro_config '{"nats": {"address": "10.0.0.1", "port": 8488}}' 13 ``` 14 15 ``` 16 conf.Get("nats") 17 ``` 18 19 ## New Source 20 21 Specify source with data 22 23 ```go 24 natsSource := nats.NewSource( 25 nats.WithUrl("127.0.0.1:4222"), 26 nats.WithBucket("my_bucket"), 27 nats.WithKey("my_key"), 28 ) 29 ``` 30 31 ## Load Source 32 33 Load the source into config 34 35 ```go 36 // Create new config 37 conf := config.NewConfig() 38 39 // Load nats source 40 conf.Load(natsSource) 41 ``` 42 43 ## Watch 44 45 ```go 46 wh, _ := natsSource.Watch() 47 48 for { 49 v, err := watcher.Next() 50 if err != nil { 51 log.Fatalf("err %v", err) 52 } 53 54 log.Infof("data %v", string(v.Data)) 55 } 56 ```