• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang store.Store类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/weaveworks/flux/common/store.Store的典型用法代码示例。如果您正苦于以下问题:Golang Store类的具体用法?Golang Store怎么用?Golang Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Store类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: addGroup

func addGroup(st store.Store, serviceName string, addr *data.AddressSpec, labels ...string) {
	if len(labels)%2 != 0 {
		panic("Expected key value ... as arguments")
	}
	sel := make(map[string]string)
	for i := 0; i < len(labels); i += 2 {
		sel[labels[i]] = labels[i+1]
	}

	if addr == nil {
		addr = &data.AddressSpec{"fixed", 80}
	}

	st.SetContainerRule(serviceName, GROUP, data.ContainerRule{*addr, sel})
}
开发者ID:errordeveloper,项目名称:flux,代码行数:15,代码来源:listener_test.go


示例2: testRules

func testRules(s store.Store, t *testing.T) {
	require.Nil(t, s.AddService("svc", testService))
	require.Nil(t, s.SetContainerRule("svc", "group", testRule))

	svc, err := s.GetService("svc", store.QueryServiceOptions{WithContainerRules: true})
	require.Nil(t, err)

	require.Equal(t, []store.ContainerRuleInfo{
		store.ContainerRuleInfo{
			Name:          "group",
			ContainerRule: testRule,
		},
	}, svc.ContainerRules)

	require.Nil(t, s.RemoveContainerRule("svc", "group"))
	svc, err = s.GetService("svc", store.QueryServiceOptions{WithContainerRules: true})
	require.Nil(t, err)
	require.Empty(t, svc.ContainerRules)
}
开发者ID:errordeveloper,项目名称:flux,代码行数:19,代码来源:suite.go


示例3: testInstances

func testInstances(s store.Store, t *testing.T) {
	require.Nil(t, s.AddService("svc", testService))
	require.Nil(t, s.AddInstance("svc", "inst", testInst))

	instances := func() map[string]data.Instance {
		insts := make(map[string]data.Instance)
		require.Nil(t, store.ForeachInstance(s, "svc", func(_, n string, inst data.Instance) error {
			insts[n] = inst
			return nil
		}))
		return insts
	}

	require.Equal(t, map[string]data.Instance{"inst": testInst}, instances())

	serviceInstances := func() map[string]data.Instance {
		insts := make(map[string]data.Instance)
		require.Nil(t, store.ForeachServiceInstance(s, nil, func(sn string, in string, inst data.Instance) error {
			insts[sn+" "+in] = inst
			return nil
		}))
		return insts
	}

	require.Equal(t, map[string]data.Instance{"svc inst": testInst}, serviceInstances())

	require.Nil(t, s.RemoveInstance("svc", "inst"))
	require.Equal(t, map[string]data.Instance{}, instances())
	require.Equal(t, map[string]data.Instance{}, serviceInstances())
}
开发者ID:errordeveloper,项目名称:flux,代码行数:30,代码来源:suite.go


示例4: newWatcher

func newWatcher(s store.Store, opts store.QueryServiceOptions) *watcher {
	w := &watcher{stopCh: make(chan struct{}), done: make(chan struct{})}
	changes := make(chan data.ServiceChange)

	ctx, cancel := context.WithCancel(context.Background())
	s.WatchServices(ctx, changes, daemon.NewErrorSink(), opts)

	go func() {
		defer close(w.done)
		for {
			select {
			case change := <-changes:
				w.changes = append(w.changes, change)
			case <-w.stopCh:
				cancel()
				return
			}
		}
	}()

	return w
}
开发者ID:errordeveloper,项目名称:flux,代码行数:22,代码来源:suite.go


示例5: allServices

func allServices(t *testing.T, st store.Store) []*store.ServiceInfo {
	services, err := st.GetAllServices(store.QueryServiceOptions{})
	require.NoError(t, err)
	return services
}
开发者ID:errordeveloper,项目名称:flux,代码行数:5,代码来源:service_test.go


示例6: testServices

func testServices(s store.Store, t *testing.T) {
	require.Nil(t, s.AddService("svc", testService))
	svc2, err := s.GetService("svc", store.QueryServiceOptions{})
	require.Nil(t, err)
	require.Equal(t, "svc", svc2.Name)
	require.Equal(t, testService, svc2.Service)

	require.Nil(t, s.CheckRegisteredService("svc"))

	services := func() map[string]data.Service {
		svcs := make(map[string]data.Service)
		ss, err := s.GetAllServices(store.QueryServiceOptions{})
		require.Nil(t, err)
		for _, svc := range ss {
			svcs[svc.Name] = svc.Service
		}
		return svcs
	}

	require.Equal(t, map[string]data.Service{"svc": testService}, services())

	require.Nil(t, s.RemoveService("svc"))
	require.Equal(t, map[string]data.Service{}, services())

	require.Nil(t, s.AddService("svc", testService))
	require.Nil(t, s.RemoveAllServices())
	require.Equal(t, map[string]data.Service{}, services())
}
开发者ID:errordeveloper,项目名称:flux,代码行数:28,代码来源:suite.go


示例7: testPing

func testPing(s store.Store, t *testing.T) {
	require.Nil(t, s.Ping())
}
开发者ID:errordeveloper,项目名称:flux,代码行数:3,代码来源:suite.go


示例8: testWatchServices

func testWatchServices(s store.Store, t *testing.T) {
	check := func(opts store.QueryServiceOptions, body func(w *watcher), changes ...data.ServiceChange) {
		w := newWatcher(s, opts)
		body(w)
		// Yuck.  There's a race between making a change in
		// etcd, and hearing about it via the watch, and I
		// haven't found a nicer way to avoid it.
		time.Sleep(100 * time.Millisecond)
		w.stop()
		require.Equal(t, changes, w.changes)
		require.Nil(t, s.RemoveAllServices())
	}

	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.AddService("svc", testService))
	}, data.ServiceChange{"svc", false})

	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.RemoveAllServices())
		require.Nil(t, s.AddService("svc", testService))
		require.Nil(t, s.RemoveService("svc"))
	}, data.ServiceChange{"svc", true}, data.ServiceChange{"svc", false},
		data.ServiceChange{"svc", true})

	// WithInstances false, so adding an instance should not
	// cause an event
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.AddInstance("svc", "inst", testInst))
	})

	// WithInstances true, so instance changes should
	// cause events
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{WithInstances: true},
		func(w *watcher) {
			require.Nil(t, s.AddInstance("svc", "inst", testInst))
			require.Nil(t, s.RemoveInstance("svc", "inst"))
		}, data.ServiceChange{"svc", false},
		data.ServiceChange{"svc", false})

	// WithContainerRules false, so adding a rule should not
	// cause an event
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{}, func(w *watcher) {
		require.Nil(t, s.SetContainerRule("svc", "group", testRule))
	})

	// WithContainerRules true, so instance changes should
	// cause events
	require.Nil(t, s.AddService("svc", testService))
	check(store.QueryServiceOptions{WithContainerRules: true},
		func(w *watcher) {
			require.Nil(t, s.SetContainerRule("svc", "group", testRule))
			require.Nil(t, s.RemoveContainerRule("svc", "group"))
		}, data.ServiceChange{"svc", false},
		data.ServiceChange{"svc", false})
}
开发者ID:errordeveloper,项目名称:flux,代码行数:59,代码来源:suite.go



注:本文中的github.com/weaveworks/flux/common/store.Store类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang odp.NewDpif函数代码示例发布时间:2022-05-28
下一篇:
Golang api.FluxService类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap