コード例 #1
0
ファイル: zk.go プロジェクト: cep21/goinjection-examples
func (back *zkConfig) reregisterWatch(path string, logger log.Logger) error {
	logger = log.NewContext(logger).With(logkey.ZkPath, path)
	logger.Log("Reregistering watch")
	_, _, _, err := back.conn.ExistsW(path)
	if err != nil {
		logger.Log(log.Err, err, "Unable to reregistering watch")
		return errors.Annotatef(err, "unable to reregister watch for node %s", path)
	}
	return nil
}
コード例 #2
0
ファイル: zk.go プロジェクト: cep21/goinjection-examples
func (back *zkConfig) logInfoState(logger log.Logger, e zk.Event) bool {
	if e.State == zk.StateDisconnected {
		logger.Log("Disconnected from zookeeper.  Will attempt to remake connection.")
		return true
	}
	if e.State == zk.StateConnecting {
		logger.Log("Server is now attempting to reconnect.")
		return true
	}
	return false
}
コード例 #3
0
ファイル: main.go プロジェクト: cep21/goinjection-examples
func main() {
	graph := inject.NewGraph()
	var (
		logger    log.Logger
		server    *app.Server
		a         *A
		b         *B
		mux       *http.ServeMux
		dconf     *distconf.Distconf
		authCheck *app.AuthorizationCheck
		tk        timekeeper.TimeKeeper
		auth      app.Authentication
	)

	graph.Define(&logger, inject.NewProvider(func() log.Logger {
		return log.DefaultLogger
	}))
	graph.Define(&tk, inject.NewProvider(func() timekeeper.RealTime {
		return timekeeper.RealTime{}
	}))
	graph.Define(&auth, inject.NewProvider(func() *app.StrictCheck {
		return &app.StrictCheck{
			Username: "******",
			Password: "******",
		}
	}))

	graph.Define(&dconf, inject.NewProvider(distconf.New, &[]distconf.Reader{distconf.Env()}))
	graph.Define(&mux, inject.NewProvider(http.NewServeMux))
	graph.Define(&authCheck, inject.NewAutoProvider(app.NewAuthorizationCheck))
	graph.Define(&a, inject.NewAutoProvider(NewA))
	graph.Define(&b, inject.NewAutoProvider(NewB))
	graph.Define(&server, inject.NewAutoProvider(app.NewServer))

	graph.Resolve(&logger)
	graph.Resolve(&server)
	graph.Resolve(&a)
	fmt.Println(a)
	logger.Log("Setting up")
	if err := server.Setup(); err != nil {
		logger.Log("Cannot setup!")
		panic(err)
	}
	err := server.Start(context.Background())
	fmt.Println(err)
}