示例#1
0
文件: source.go 项目: mo-gr/skipper
// creates a skipper.SettingsSource instance.
// expects an instance of the etcd client, a filter registry and a settings dispatcher.
func MakeSource(
	dc skipper.DataClient,
	mwr skipper.FilterRegistry,
	sd skipper.SettingsDispatcher) skipper.SettingsSource {

	// create initial empty settings:
	sd.Push() <- &settings{route.New()}

	s := &source{sd}
	go func() {
		for {
			data := <-dc.Receive()

			ss, err := processRaw(data, mwr)
			if err != nil {
				log.Println(err)
				continue
			}

			s.dispatcher.Push() <- ss
		}
	}()

	return s
}
示例#2
0
func waitForEtcd(dc skipper.DataClient, test func(skipper.RawData) bool) bool {
	for {
		select {
		case d := <-dc.Receive():
			if test(d) {
				return true
			}
		case <-time.After(15 * time.Millisecond):
			return false
		}
	}
}
示例#3
0
文件: source.go 项目: hafizh/skipper
// creates a skipper.SettingsSource instance.
// expects an instance of the etcd client, a filter registry and a settings dispatcher.
func MakeSource(
	dc skipper.DataClient,
	mwr skipper.FilterRegistry,
	sd skipper.SettingsDispatcher) skipper.SettingsSource {

	s := &source{sd}
	go func() {
		for {
			data := <-dc.Receive()

			settings, err := processRaw(data, mwr)
			if err != nil {
				log.Println(err)
				continue
			}

			s.dispatcher.Push() <- settings
		}
	}()

	return s
}