本文整理汇总了Golang中github.com/vulcand/route.NewMux函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMux函数的具体用法?Golang NewMux怎么用?Golang NewMux使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMux函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:9,代码来源:model_test.go
示例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")
}
}
开发者ID:polyverse-security,项目名称:combine-route,代码行数:26,代码来源:combine-route_test.go
示例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
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:28,代码来源:router.go
示例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")`)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:7,代码来源:model_test.go
示例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
}
开发者ID:albertrdixon,项目名称:romulus,代码行数:25,代码来源:vulcand.go
示例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
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:7,代码来源:testutils.go
示例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)
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:18,代码来源:model_test.go
示例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
}
开发者ID:vulcand,项目名称:vulcand,代码行数:11,代码来源:srv.go
示例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)
}
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:12,代码来源:model_test.go
示例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
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:12,代码来源:mux.go
示例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
}
开发者ID:vulcand,项目名称:vulcand,代码行数:15,代码来源:mux.go
示例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
}
开发者ID:vulcand,项目名称:vulcand,代码行数:15,代码来源:frontend.go
示例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.")
}
}
开发者ID:polyverse-security,项目名称:combine-route,代码行数:19,代码来源:combine-route_test.go
示例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")
}
}
开发者ID:polyverse-security,项目名称:combine-route,代码行数:22,代码来源:combine-route_test.go
示例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)
}
开发者ID:pedrosnk,项目名称:tsuru,代码行数:39,代码来源:router.go
示例16: TestNewFrontendWithOptions
func (s *BackendSuite) TestNewFrontendWithOptions(c *C) {
settings := HTTPFrontendSettings{
Limits: HTTPFrontendLimits{
MaxMemBodyBytes: 12,
MaxBodyBytes: 400,
},
FailoverPredicate: "IsNetworkError() && Attempts() <= 1",
Hostname: "host1",
TrustForwardHeader: true,
}
f, err := NewHTTPFrontend(route.NewMux(), "f1", "b1", `Path("/home")`, settings)
c.Assert(err, IsNil)
c.Assert(f.Id, Equals, "f1")
o := f.HTTPSettings()
c.Assert(o.Limits.MaxMemBodyBytes, Equals, int64(12))
c.Assert(o.Limits.MaxBodyBytes, Equals, int64(400))
c.Assert(o.FailoverPredicate, NotNil)
c.Assert(o.TrustForwardHeader, Equals, true)
c.Assert(o.Hostname, Equals, "host1")
}
开发者ID:vnadgir-ef,项目名称:vulcand,代码行数:23,代码来源:model_test.go
示例17: newBackend
package main
import (
"strings"
router "github.com/vulcand/route"
"github.com/vulcand/vulcand/engine"
)
var validateRoute = router.NewMux().IsValid
type vulcandEngine interface {
basePath(ID string) string
engineType() string
path(ID string) string
}
type backend struct {
engine.Backend
}
func newBackend(ID string) *backend {
return &backend{engine.Backend{Id: ID, Type: backendType}}
}
func (b *backend) engineType() string {
return "backend"
}
func (b *backend) basePath(ID string) string {
return vulcandPath("backends", ID)
开发者ID:lucmichalski,项目名称:kube2vulcand,代码行数:31,代码来源:vulcand.go
示例18: NewRegistry
func NewRegistry() *Registry {
return &Registry{
specs: []*MiddlewareSpec{},
router: route.NewMux(),
}
}
开发者ID:vulcand,项目名称:vulcand,代码行数:6,代码来源:middleware.go
示例19: TestMultipleRouters
func TestMultipleRouters(t *testing.T) {
combinedRouter := NewMux(Routers{
RouterEntry{
Name: "vulcanrouter",
Router: route.NewMux(),
},
RouterEntry{
Name: "jsrouter",
Router: jsroute.NewMux(),
},
RouterEntry{
Name: "testrouter",
Router: &testRouter{routedef: "Obviously bad routedef"},
},
})
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 routedef", &testHandler{respCode: 4}); err != nil {
t.Logf("Error when adding path: %v", err)
}
if err := combinedRouter.Handle("Request.Header[\"User-Agent\"] == \"fakeagent\"", &testHandler{respCode: 5}); err != nil {
t.Logf("Error when adding path: %v", err)
}
{
req, _ := http.NewRequest("GET", "http://localhost/", strings.NewReader(""))
rec := httptest.NewRecorder()
combinedRouter.ServeHTTP(rec, req)
assert.Equal(t, 1, rec.Code, "Test failed")
}
{
req, _ := http.NewRequest("GET", "http://localhost/foo", strings.NewReader(""))
rec := httptest.NewRecorder()
combinedRouter.ServeHTTP(rec, req)
assert.Equal(t, 2, rec.Code, "Test failed")
}
{
req, _ := http.NewRequest("GET", "http://localhost/bar", strings.NewReader(""))
rec := httptest.NewRecorder()
combinedRouter.ServeHTTP(rec, req)
assert.Equal(t, 3, rec.Code, "Test failed")
}
{
req, _ := http.NewRequest("GET", "http://localhost/obviously bad route def", strings.NewReader(""))
rec := httptest.NewRecorder()
combinedRouter.ServeHTTP(rec, req)
assert.Equal(t, 4, rec.Code, "Test failed")
}
{
req, _ := http.NewRequest("GET", "http://localhost/obviously bad route def", strings.NewReader(""))
req.Header.Add("User-Agent", "fakeagent")
rec := httptest.NewRecorder()
combinedRouter.ServeHTTP(rec, req)
assert.Equal(t, 5, rec.Code, "Test failed")
}
}
开发者ID:polyverse-security,项目名称:combine-route,代码行数:69,代码来源:combine-route_test.go
注:本文中的github.com/vulcand/route.NewMux函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论