當前位置: 首頁>>代碼示例>>Golang>>正文


Golang plugin.NewRegistry函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。