pub.go 415 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "time"
  7. "github.com/tal-tech/go-zero/core/discov"
  8. )
  9. var value = flag.String("v", "value", "the value")
  10. func main() {
  11. flag.Parse()
  12. client := discov.NewPublisher([]string{"etcd.discovery:2379"}, "028F2C35852D", *value)
  13. if err := client.KeepAlive(); err != nil {
  14. log.Fatal(err)
  15. }
  16. defer client.Stop()
  17. for {
  18. time.Sleep(time.Second)
  19. fmt.Println(*value)
  20. }
  21. }