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

Golang plugin.NewRegistry函数代码示例

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

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



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

示例1: TestNewCircuitBreakerSerializationCycle

func (s *SpecSuite) TestNewCircuitBreakerSerializationCycle(c *C) {
	cl, err := NewSpec(
		`LatencyAtQuantileMS(50.0) < 20`,
		`{"Type": "response", "Action": {"StatusCode": 400, "Body": "Come back later"}}`,
		`{"Type": "webhook", "Action": {"URL": "http://localhost", "Method": "POST", "Form": {"Key": ["Val"]}}}`,
		`{"Type": "webhook", "Action": {"URL": "http://localhost", "Method": "POST", "Form": {"Key": ["Val"]}}}`,
		defaultFallbackDuration,
		defaultRecoveryDuration,
		defaultCheckPeriod,
	)

	bytes, err := json.Marshal(cl)
	c.Assert(err, IsNil)

	r := plugin.NewRegistry()
	c.Assert(r.AddSpec(GetSpec()), IsNil)

	spec := r.GetSpec(GetSpec().Type)
	c.Assert(spec, NotNil)

	out, err := spec.FromJSON(bytes)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)

	spec2 := out.(*Spec)
	c.Assert(spec2.Fallback, NotNil)
	c.Assert(spec2.OnTripped, NotNil)
	c.Assert(spec2.OnStandby, NotNil)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:29,代码来源:spec_test.go


示例2: GetRegistry

func GetRegistry() (*plugin.Registry, error) {
	r := plugin.NewRegistry()

	specs := []*plugin.MiddlewareSpec{

		connlimit.GetSpec(),

		ratelimit.GetSpec(),

		rewrite.GetSpec(),

		cbreaker.GetSpec(),

		trace.GetSpec(),

		joblogger.GetSpec(),
	}

	for _, spec := range specs {
		if err := r.AddSpec(spec); err != nil {
			return nil, err
		}
	}
	return r, nil
}
开发者ID:octoblu,项目名称:vulcand-bundle,代码行数:25,代码来源:registry.go


示例3: TestNewCircuitBreakerFromJSONEmptyStrings

func (s *SpecSuite) TestNewCircuitBreakerFromJSONEmptyStrings(c *C) {
	r := plugin.NewRegistry()
	c.Assert(r.AddSpec(GetSpec()), IsNil)

	bytes := []byte(`{
                 "Condition":"LatencyAtQuantileMS(50.0) < 20",
                 "Fallback":{"Type": "response", "Action": {"StatusCode": 400, "Body": "Come back later"}},
                 "OnTripped": "",
                 "OnStandby": "",
                 "FallbackDuration": 10000000000,
                 "RecoveryDuration": 10000000000,
                 "CheckPeriod": 100000000}`)

	spec := r.GetSpec(GetSpec().Type)
	c.Assert(spec, NotNil)

	out, err := spec.FromJSON(bytes)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)

	spec2 := out.(*Spec)
	c.Assert(spec2.Fallback, NotNil)
	c.Assert(spec2.OnTripped, Equals, "")
	c.Assert(spec2.OnStandby, Equals, "")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:25,代码来源:spec_test.go


示例4: TestSpecIsOK

func TestSpecIsOK(t *testing.T) {
	t.Log("Add Locale Middleware spec to Vulcan registry")

	err := plugin.NewRegistry().AddSpec(GetSpec())
	if err != nil {
		t.Errorf("Expected to be able to add spec but got error %+v", err)
	}
}
开发者ID:uniqueusa,项目名称:vulcan-locale,代码行数:8,代码来源:locale_test.go


示例5: MiddlewareFromJSON

func (s *BackendSuite) MiddlewareFromJSON(c *C) {
	cl, err := connlimit.NewConnLimit(10, "client.ip")
	c.Assert(err, IsNil)

	m := &Middleware{Id: "c1", Type: "connlimit", Middleware: cl}

	bytes, err := json.Marshal(m)
	c.Assert(err, IsNil)

	out, err := MiddlewareFromJSON(bytes, plugin.NewRegistry().GetSpec)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)
	c.Assert(out, DeepEquals, m)
}
开发者ID:huhoo,项目名称:vulcand,代码行数:14,代码来源:model_test.go


示例6: TestFrontendsFromJSON

func (s *BackendSuite) TestFrontendsFromJSON(c *C) {
	f, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", `Path("/path")`, HTTPFrontendSettings{})
	c.Assert(err, IsNil)

	bytes, err := json.Marshal(f)

	fs := []Frontend{*f}

	bytes, err = json.Marshal(map[string]interface{}{"Frontends": fs})

	r := plugin.NewRegistry()
	c.Assert(r.AddSpec(connlimit.GetSpec()), IsNil)

	out, err := FrontendsFromJSON(route.NewMux(), bytes)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)
	c.Assert(out, DeepEquals, fs)
}
开发者ID:huhoo,项目名称:vulcand,代码行数:18,代码来源:model_test.go


示例7: GetRegistry

func GetRegistry() *plugin.Registry {
	r := plugin.NewRegistry()

	specs := []*plugin.MiddlewareSpec{
		ratelimit.GetSpec(),
		connlimit.GetSpec(),
		rewrite.GetSpec(),
		cbreaker.GetSpec(),
		trace.GetSpec(),
	}

	for _, spec := range specs {
		if err := r.AddSpec(spec); err != nil {
			panic(err)
		}
	}

	return r
}
开发者ID:huhoo,项目名称:vulcand,代码行数:19,代码来源:registry.go


示例8: TestNewCircuitBreakerFromJSONDefaults

func (s *SpecSuite) TestNewCircuitBreakerFromJSONDefaults(c *C) {
	r := plugin.NewRegistry()
	c.Assert(r.AddSpec(GetSpec()), IsNil)

	bytes := []byte(`{
                 "Condition":"LatencyAtQuantileMS(50.0) < 20",
                 "Fallback":{"Type": "response", "Action": {"StatusCode": 400, "Body": "Come back later"}}}`)

	spec := r.GetSpec(GetSpec().Type)
	c.Assert(spec, NotNil)

	out, err := spec.FromJSON(bytes)
	c.Assert(err, IsNil)
	c.Assert(out, NotNil)

	spec2 := out.(*Spec)
	c.Assert(spec2.Fallback, NotNil)
	c.Assert(spec2.OnTripped, IsNil)
	c.Assert(spec2.OnStandby, IsNil)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:20,代码来源:spec_test.go


示例9: TestSpecIsOK

// One of the most important tests:
// Make sure the RateLimit spec is compatible and will be accepted by middleware registry
func (s *ConnLimitSuite) TestSpecIsOK(c *C) {
	c.Assert(plugin.NewRegistry().AddSpec(GetSpec()), IsNil)
}
开发者ID:huhoo,项目名称:vulcand,代码行数:5,代码来源:connlimit_test.go


示例10: main

func main() {

	flag.Parse()
	log.Println("Connecting to kubernetes via url " + kServer)
	log.Println("Connecting to vulcand via url " + vServer)
	log.Println("Provided label query: " + labelQuery)
	log.Println("Observing endpoints within namespace: " + namespace)

	vClient := vClient.NewClient(vServer, vPlugin.NewRegistry())
	kClient, err := kClient.New(&kClient.Config{Host: kServer})

	if err != nil {
		log.Println("Error encountered when connecting to kubernetes api." + err.Error())
		panic(err)
	}

	var labelSelector labels.Selector = nil

	if labelQuery != "" {
		labelSelector, err = labels.Parse(labelQuery)
		if err != nil {
			log.Println("Error parsing the provided label query.")
			panic(err)
		}
	} else {
		labelSelector = labels.Everything()
	}

	socket, err := kClient.Endpoints(namespace).
		Watch(labelSelector, fields.Everything(), api.ListOptions{Watch: true})

	if err != nil {
		log.Println("Error obtaining a watch on the kubernetes endpoints.")
		panic(err)
	}

	// poll the channel indefinitely
	for {

		select {
		case event := <-socket.ResultChan():
			switch event.Type {
			case watch.Added:
				endpoint, _ := deserialize(event.Object)
				ensureEndpointConfiguredForVulcand(vClient, endpoint)
				log.Println("Endpoint was added: \n" + endpoint.Name)
			case watch.Modified:
				endpoint, _ := deserialize(event.Object)
				ensureEndpointConfiguredForVulcand(vClient, endpoint)
				log.Println("Endpoint was modified: \n" + endpoint.Name)
			case watch.Deleted:
				endpoint, _ := deserialize(event.Object)
				removeUnusedEndpointsFromVulcand(vClient, endpoint)
				log.Println("Endpoint was deleted: \n" + endpoint.Name)
			case watch.Error:
				log.Println("Encountered an error from the endpoints socket. Continuing...")
			}
		default:
			time.Sleep(1 * time.Second)
		}

	}

}
开发者ID:RutledgePaulV,项目名称:kube-vulcano,代码行数:64,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang registry.GetRegistry函数代码示例发布时间:2022-05-28
下一篇:
Golang context.Background函数代码示例发布时间: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