func main() { myFlagSet.Parse(os.Args[1:]) logger := log.New(os.Stderr, "wr ", log.LstdFlags) client, err := etcd.New(etcd.Config{Endpoints: []string{"http://localhost:2379"}}) if err != nil { logger.Fatalf("Failed setting up %v", err) } w, err := watcher.New(myFlagSet, etcd.NewKeysAPI(client), "/example/flagz", logger) if err != nil { logger.Fatalf("Failed setting up %v", err) } err = w.Initialize() if err != nil { logger.Fatalf("Failed setting up %v", err) } w.Start() for true { logger.Printf("staticint: %v dynint: %v dynstring: %v", *staticInt, dynInt.Get(), dynStr.Get()) time.Sleep(1500 * time.Millisecond) } }
func main() { logger := log.New(os.Stderr, "server", log.LstdFlags) if err := serverFlags.Parse(os.Args[1:]); err != nil { logger.Fatalf("%v", err) } client, err := etcd.New(etcd.Config{Endpoints: *etcdEndpoints}) if err != nil { logger.Fatalf("Failed setting up etcd %v", err) } w, err := watcher.New(serverFlags, etcd.NewKeysAPI(client), *etcdFlagzPath, logger) if err != nil { logger.Fatalf("Failed setting up watcher %v", err) } err = w.Initialize() if err != nil { logger.Fatalf("Failed initializing watcher %v", err) } w.Start() logger.Printf("etcd flag value watching initialized") flagzEndpoint := flagz.NewStatusEndpoint(serverFlags) http.HandleFunc("/debug/flagz", flagzEndpoint.ListFlags) http.HandleFunc("/", handleDefaultPage) addr := fmt.Sprintf("%s:%d", *listenHost, *listenPort) logger.Printf("Serving at: %v", addr) if err := http.ListenAndServe(addr, http.DefaultServeMux); err != nil { logger.Fatalf("Failed serving: %v", err) } logger.Printf("Done, bye.") }
// Clean up the etcd state before each test. func (s *watcherTestSuite) SetupTest() { s.keys.Delete(newCtx(), prefix, &etcd.DeleteOptions{Dir: true, Recursive: true}) _, err := s.keys.Set(newCtx(), prefix, "", &etcd.SetOptions{Dir: true}) if err != nil { s.T().Fatalf("cannot create empty dir %v: %v", prefix, err) } s.flagSet = flag.NewFlagSet("updater_test", flag.ContinueOnError) s.watcher, err = watcher.New(s.flagSet, s.keys, prefix, &testingLog{T: s.T()}) if err != nil { s.T().Fatalf("cannot create updater: %v", err) } }