本文整理汇总了Golang中github.com/vulcand/route.NewMux函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMux函数的具体用法?Golang NewMux怎么用?Golang NewMux使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMux函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFrontendBadParams
func (s *BackendSuite) TestFrontendBadParams(c *C) {
// Bad route
_, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", "/home -- afawf \\~", HTTPFrontendSettings{})
c.Assert(err, NotNil)
// Empty params
_, err = NewHTTPFrontend(route.NewMux(), "", "", "", HTTPFrontendSettings{})
c.Assert(err, NotNil)
}
示例2: TestNotFound
func TestNotFound(t *testing.T) {
combinedRouter := NewMux(Routers{
RouterEntry{
Name: "vulcanrouter",
Router: route.NewMux(),
},
})
if err := combinedRouter.Handle("Path(\"/\")", &testHandler{respCode: 1}); err != nil {
t.Logf("Error when adding path: %v", err)
}
if err := combinedRouter.Handle("Path(\"/foo\")", &testHandler{respCode: 2}); err != nil {
t.Logf("Error when adding path: %v", err)
}
if err := combinedRouter.Handle("Path(\"/bar\")", &testHandler{respCode: 3}); err != nil {
t.Logf("Error when adding path: %v", err)
}
{
req, _ := http.NewRequest("GET", "http://localhost/obviously bad route def", strings.NewReader(""))
rec := httptest.NewRecorder()
combinedRouter.ServeHTTP(rec, req)
assert.Equal(t, http.StatusNotFound, rec.Code, "Test failed")
}
}
示例3: SetCName
func (r *vulcandRouter) SetCName(cname, name string) error {
usedName, err := router.Retrieve(name)
if err != nil {
return err
}
if !router.ValidCName(cname, r.domain) {
return router.ErrCNameNotAllowed
}
frontendName := r.frontendName(cname)
if found, _ := r.client.GetFrontend(engine.FrontendKey{Id: frontendName}); found != nil {
return router.ErrCNameExists
}
frontend, err := engine.NewHTTPFrontend(
route.NewMux(),
frontendName,
r.backendName(usedName),
fmt.Sprintf(`Host(%q)`, cname),
engine.HTTPFrontendSettings{},
)
if err != nil {
return &router.RouterError{Err: err, Op: "set-cname"}
}
err = r.client.UpsertFrontend(*frontend, engine.NoTTL)
if err != nil {
return &router.RouterError{Err: err, Op: "set-cname"}
}
return nil
}
示例4: TestFrontendDefaults
func (s *BackendSuite) TestFrontendDefaults(c *C) {
f, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", `Path("/home")`, HTTPFrontendSettings{})
c.Assert(err, IsNil)
c.Assert(f.GetId(), Equals, "f1")
c.Assert(f.String(), Not(Equals), "")
c.Assert(f.Route, Equals, `Path("/home")`)
}
示例5: NewFrontend
func (v *vulcan) NewFrontend(rsc *kubernetes.Resource) (loadbalancer.Frontend, error) {
s := engine.HTTPFrontendSettings{}
if val, ok := rsc.GetAnnotation(loadbalancer.PassHostHeaderKey); ok {
b, _ := strconv.ParseBool(val)
s.PassHostHeader = b
}
if val, ok := rsc.GetAnnotation(loadbalancer.TrustForwardHeadersKey); ok {
b, _ := strconv.ParseBool(val)
s.TrustForwardHeader = b
}
if val, ok := rsc.GetAnnotation(loadbalancer.FailoverExpressionKey); ok {
s.FailoverPredicate = val
}
if val, ok := rsc.GetAnnotation(loadbalancer.FrontendSettingsKey); ok {
if er := json.Unmarshal([]byte(val), &s); er != nil {
logger.Warnf("Failed to parse settings for frontend %q: %v", rsc.ID, er)
}
}
f, er := engine.NewHTTPFrontend(vroute.NewMux(), rsc.ID(), rsc.ID(), NewRoute(rsc.Route).String(), s)
if er != nil {
return nil, er
}
return newFrontend(f), nil
}
示例6: MakeFrontend
func MakeFrontend(route string, backendId string) engine.Frontend {
f, err := engine.NewHTTPFrontend(routelib.NewMux(), UID("frontend"), backendId, route, engine.HTTPFrontendSettings{})
if err != nil {
panic(err)
}
return *f
}
示例7: 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)
}
示例8: scopedHandler
func scopedHandler(scope string, proxy http.Handler) (http.Handler, error) {
if scope == "" {
return proxy, nil
}
mux := route.NewMux()
mux.SetNotFound(&DefaultNotFound{})
if err := mux.Handle(scope, proxy); err != nil {
return nil, err
}
return mux, nil
}
示例9: TestFrontendBadOptions
func (s *BackendSuite) TestFrontendBadOptions(c *C) {
settings := []HTTPFrontendSettings{
HTTPFrontendSettings{
FailoverPredicate: "bad predicate",
},
}
for _, s := range settings {
f, err := NewHTTPFrontend(route.NewMux(), "f1", "b", `Path("/home")`, s)
c.Assert(err, NotNil)
c.Assert(f, IsNil)
}
}
示例10: setDefaults
func setDefaults(o Options) Options {
if o.MetricsClient == nil {
o.MetricsClient = metrics.NewNop()
}
if o.TimeProvider == nil {
o.TimeProvider = &timetools.RealTime{}
}
if o.Router == nil {
o.Router = route.NewMux()
}
return o
}
示例11: setDefaults
func setDefaults(o Options) Options {
if o.MetricsClient == nil {
o.MetricsClient = metrics.NewNop()
}
if o.TimeProvider == nil {
o.TimeProvider = &timetools.RealTime{}
}
if o.Router == nil {
o.Router = route.NewMux()
}
if o.IncomingConnectionTracker == nil {
o.IncomingConnectionTracker = newDefaultConnTracker()
}
return o
}
示例12: upsertFrontendAction
func (cmd *Command) upsertFrontendAction(c *cli.Context) error {
settings, err := getFrontendSettings(c)
if err != nil {
return err
}
f, err := engine.NewHTTPFrontend(route.NewMux(), c.String("id"), c.String("b"), c.String("route"), settings)
if err != nil {
return err
}
if err := cmd.client.UpsertFrontend(*f, c.Duration("ttl")); err != nil {
return err
}
cmd.printOk("frontend upserted")
return nil
}
示例13: TestRejectedRoute
func TestRejectedRoute(t *testing.T) {
combinedRouter := NewMux(Routers{
RouterEntry{
Name: "vulcanrouter",
Router: route.NewMux(),
},
RouterEntry{
Name: "jsrouter",
Router: jsroute.NewMux(),
},
})
if err := combinedRouter.Handle("Path(\"\"); && Host(\"\")", &testHandler{respCode: 1}); err != nil {
t.Logf("Error when adding path: %v", err)
} else {
assert.Fail(t, "This path should have produced an error, but was accepted.")
}
}
示例14: TestNoRouter
func TestNoRouter(t *testing.T) {
combinedRouter := NewMux(Routers{
RouterEntry{
Name: "vulcanrouter",
Router: route.NewMux(),
},
})
if err := combinedRouter.Handle("Path(\"/\")", &testHandler{respCode: 1}); err != nil {
t.Logf("Error when adding path: %v", err)
}
if err := combinedRouter.Handle("Path(\"/foo\")", &testHandler{respCode: 2}); err != nil {
t.Logf("Error when adding path: %v", err)
}
if err := combinedRouter.Handle("Path(\"/bar\")", &testHandler{respCode: 3}); err != nil {
t.Logf("Error when adding path: %v", err)
}
if err := combinedRouter.Handle("Obviously bad route def", &testHandler{respCode: 3}); err == nil {
t.Logf("No error when adding path: Obviously bad route def. An error was expected")
}
}
示例15: AddBackend
func (r *vulcandRouter) AddBackend(name string) error {
backendName := r.backendName(name)
frontendName := r.frontendName(r.frontendHostname(name))
backendKey := engine.BackendKey{Id: backendName}
frontendKey := engine.FrontendKey{Id: frontendName}
if found, _ := r.client.GetBackend(backendKey); found != nil {
return router.ErrBackendExists
}
if found, _ := r.client.GetFrontend(frontendKey); found != nil {
return router.ErrBackendExists
}
backend, err := engine.NewHTTPBackend(
backendName,
engine.HTTPBackendSettings{},
)
if err != nil {
return &router.RouterError{Err: err, Op: "add-backend"}
}
err = r.client.UpsertBackend(*backend)
if err != nil {
return err
}
frontend, err := engine.NewHTTPFrontend(
route.NewMux(),
frontendName,
backend.Id,
fmt.Sprintf(`Host(%q)`, r.frontendHostname(name)),
engine.HTTPFrontendSettings{},
)
if err != nil {
return &router.RouterError{Err: err, Op: "add-backend"}
}
err = r.client.UpsertFrontend(*frontend, engine.NoTTL)
if err != nil {
r.client.DeleteBackend(backendKey)
return &router.RouterError{Err: err, Op: "add-backend"}
}
return router.Store(name, name, routerName)
}