本文整理汇总了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)
}
示例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
}
示例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, "")
}
示例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)
}
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
}
}