本文整理汇总了Golang中github.com/zalando/skipper/filters/builtin.MakeRegistry函数的典型用法代码示例。如果您正苦于以下问题:Golang MakeRegistry函数的具体用法?Golang MakeRegistry怎么用?Golang MakeRegistry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MakeRegistry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestOriginalRequestResponse
func TestOriginalRequestResponse(t *testing.T) {
s := startTestServer(nil, 0, func(r *http.Request) {
if th, ok := r.Header["X-Test-Header-Preserved"]; !ok || th[0] != "test value" {
t.Error("wrong request header")
}
})
defer s.Close()
u, _ := url.ParseRequestURI("https://www.example.org/hello")
r := &http.Request{
URL: u,
Method: "GET",
Header: http.Header{"X-Test-Header": []string{"test value"}}}
w := httptest.NewRecorder()
fr := builtin.MakeRegistry()
fr.Register(&preserveOriginalSpec{})
doc := fmt.Sprintf(`hello: Path("/hello") -> preserveOriginal() -> "%s"`, s.URL)
tp, err := newTestProxyWithFilters(fr, doc, PreserveOriginal)
if err != nil {
t.Error(err)
return
}
defer tp.close()
tp.proxy.ServeHTTP(w, r)
if th, ok := w.Header()["X-Test-Response-Header-Preserved"]; !ok || th[0] != "response header value" {
t.Error("wrong response header", ok)
}
}
示例2: Example
func Example() {
// create registry
registry := builtin.MakeRegistry()
// create and register the filter specification
spec := &customSpec{name: "customFilter"}
registry.Register(spec)
// create simple data client, with route entries referencing 'customFilter',
// and clipping part of the request path:
dataClient, err := testdataclient.NewDoc(`
ui: Path("/ui/*page") ->
customFilter("ui request") ->
modPath("^/[^/]*", "") ->
"https://ui.example.org";
api: Path("/api/*resource") ->
customFilter("api request") ->
modPath("^/[^/]*", "") ->
"https://api.example.org"`)
if err != nil {
log.Fatal(err)
}
// create http.Handler:
proxy.New(
routing.New(routing.Options{
FilterRegistry: registry,
DataClients: []routing.DataClient{dataClient}}),
proxy.OptionsNone)
}
示例3: Run
// Run skipper.
func Run(o Options) error {
// create authentication for Innkeeper
auth := createInnkeeperAuthentication(o)
// create data client
dataClients, err := createDataClients(o, auth)
if err != nil {
return err
}
if len(dataClients) == 0 {
log.Println("warning: no route source specified")
}
// create a filter registry with the available filter specs registered,
// and register the custom filters
registry := builtin.MakeRegistry()
for _, f := range o.CustomFilters {
registry.Register(f)
}
// create routing
// create the proxy instance
var mo routing.MatchingOptions
if o.IgnoreTrailingSlash {
mo = routing.IgnoreTrailingSlash
}
// ensure a non-zero poll timeout
if o.SourcePollTimeout <= 0 {
o.SourcePollTimeout = defaultSourcePollTimeout
}
// check for dev mode, and set update buffer of the routes
updateBuffer := defaultRoutingUpdateBuffer
if o.DevMode {
updateBuffer = 0
}
// create a routing engine
routing := routing.New(routing.Options{
registry,
mo,
o.SourcePollTimeout,
dataClients,
updateBuffer})
// create the proxy
proxy := proxy.New(routing, o.ProxyOptions, o.PriorityRoutes...)
// start the http server
log.Printf("listening on %v\n", o.Address)
return http.ListenAndServe(o.Address, proxy)
}
示例4: Example
func Example() {
// create etcd data client:
dataClient := etcd.New([]string{"https://etcd.example.org"}, "/skipper")
// create http.Handler:
proxy.New(
routing.New(routing.Options{
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{dataClient}}),
proxy.OptionsNone)
}
示例5: DisabledExample
func DisabledExample() {
// create a target backend server. It will return the value of the 'X-Echo' request header
// as the response body:
targetServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(r.Header.Get("X-Echo")))
}))
defer targetServer.Close()
// create a filter registry, and register the custom filter:
filterRegistry := builtin.MakeRegistry()
filterRegistry.Register(&setEchoHeader{})
// create a data client with a predefined route, referencing the filter and a path condition
// containing a wildcard called 'echo':
routeDoc := fmt.Sprintf(`Path("/return/:echo") -> setEchoHeader() -> "%s"`, targetServer.URL)
dataClient, err := testdataclient.NewDoc(routeDoc)
if err != nil {
log.Fatal(err)
}
// create routing object:
rt := routing.New(routing.Options{
FilterRegistry: filterRegistry,
DataClients: []routing.DataClient{dataClient}})
defer rt.Close()
// create a proxy instance, and start an http server:
proxy := proxy.New(rt, proxy.OptionsNone)
defer proxy.Close()
router := httptest.NewServer(proxy)
defer router.Close()
// make a request to the proxy:
rsp, err := http.Get(fmt.Sprintf("%s/return/Hello,+world!", router.URL))
if err != nil {
log.Fatal(err)
}
defer rsp.Body.Close()
// print out the response:
if _, err := io.Copy(os.Stdout, rsp.Body); err != nil {
log.Fatal(err)
}
// Output:
// Hello, world!
}
示例6: Example
func Example() {
// create etcd data client:
dataClient, err := etcd.New(etcd.Options{[]string{"https://etcd.example.org"}, "/skipper", 0, false})
if err != nil {
log.Fatal(err)
}
// create routing object:
rt := routing.New(routing.Options{
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{dataClient}})
defer rt.Close()
// create http.Handler:
p := proxy.New(rt, proxy.OptionsNone)
defer p.Close()
}
示例7: ExampleFilter
func ExampleFilter() {
// create a test filter and add to the registry:
fr := builtin.MakeRegistry()
fr.Register(&filtertest.Filter{FilterName: "testFilter"})
// create a data client, with a predefined route referencing the filter:
dc, err := testdataclient.NewDoc(`Path("/some/path/:param") -> testFilter(3.14, "Hello, world!") -> "https://www.example.org"`)
if err != nil {
log.Fatal(err)
}
// create an http.Handler:
proxy.New(
routing.New(routing.Options{
DataClients: []routing.DataClient{dc},
FilterRegistry: fr}),
proxy.OptionsNone)
}
示例8: ExamplePriorityRoute
func ExamplePriorityRoute() {
// create a routing doc forwarding all requests,
// and load it in a data client:
routeDoc := `* -> "https://www.example.org"`
dataClient, err := testdataclient.NewDoc(routeDoc)
if err != nil {
log.Fatal(err)
}
// create a priority route making exceptions:
pr := &priorityRoute{}
// create an http.Handler:
proxy.New(
routing.New(routing.Options{
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{dataClient}}),
proxy.OptionsNone,
pr)
}
示例9: TestHTTPSServer
// to run this test, set `-args listener` for the test command
func TestHTTPSServer(t *testing.T) {
// TODO: figure why sometimes cannot connect
if !testListener() {
t.Skip()
}
a, err := findAddress()
if err != nil {
t.Fatal(err)
}
o := Options{
Address: a,
CertPathTLS: "fixtures/test.crt",
KeyPathTLS: "fixtures/test.key",
}
rt := routing.New(routing.Options{
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{}})
defer rt.Close()
proxy := proxy.New(rt, proxy.OptionsNone)
defer proxy.Close()
go listenAndServe(proxy, &o)
r, err := waitConnGet("https://" + o.Address)
if r != nil {
defer r.Body.Close()
}
if err != nil {
t.Fatalf("Cannot connect to the local server for testing: %s ", err.Error())
}
if r.StatusCode != 404 {
t.Fatalf("Status code should be 404, instead got: %d\n", r.StatusCode)
}
_, err = ioutil.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to stream response body: %v", err)
}
}
示例10: TestOriginalRequestResponse
func TestOriginalRequestResponse(t *testing.T) {
s := startTestServer(nil, 0, func(r *http.Request) {
if th, ok := r.Header["X-Test-Header-Preserved"]; !ok || th[0] != "test value" {
t.Error("wrong request header")
}
})
defer s.Close()
u, _ := url.ParseRequestURI("https://www.example.org/hello")
r := &http.Request{
URL: u,
Method: "GET",
Header: http.Header{"X-Test-Header": []string{"test value"}}}
w := httptest.NewRecorder()
doc := fmt.Sprintf(`hello: Path("/hello") -> preserveOriginal() -> "%s"`, s.URL)
dc, err := testdataclient.NewDoc(doc)
if err != nil {
t.Error(err)
}
fr := builtin.MakeRegistry()
fr.Register(&preserveOriginalSpec{})
p := New(routing.New(routing.Options{
fr,
routing.MatchingOptionsNone,
sourcePollTimeout,
[]routing.DataClient{dc},
nil,
0}), OptionsPreserveOriginal)
delay()
p.ServeHTTP(w, r)
if th, ok := w.Header()["X-Test-Response-Header-Preserved"]; !ok || th[0] != "response header value" {
t.Error("wrong response header", ok)
}
}
示例11: TestWithWrongKeyPathFails
func TestWithWrongKeyPathFails(t *testing.T) {
a, err := findAddress()
if err != nil {
t.Fatal(err)
}
o := Options{Address: a,
CertPathTLS: "fixtures/test.crt",
KeyPathTLS: "fixtures/notFound.key",
}
rt := routing.New(routing.Options{
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{}})
defer rt.Close()
proxy := proxy.New(rt, proxy.OptionsNone)
defer proxy.Close()
err = listenAndServe(proxy, &o)
if err == nil {
t.Fatal(err)
}
}
示例12: newTestRoutingWithPredicates
func newTestRoutingWithPredicates(cps []routing.PredicateSpec, dc ...routing.DataClient) (*testRouting, error) {
return newTestRoutingWithFiltersPredicates(builtin.MakeRegistry(), cps, dc...)
}
示例13: newTestProxy
func newTestProxy(doc string, flags Flags, pr ...PriorityRoute) (*testProxy, error) {
return newTestProxyWithFilters(builtin.MakeRegistry(), doc, flags, pr...)
}
示例14: Run
// Run skipper.
func Run(o Options) error {
// init log
err := initLog(o)
if err != nil {
return err
}
// init metrics
metrics.Init(metrics.Options{
Listener: o.MetricsListener,
Prefix: o.MetricsPrefix,
EnableDebugGcMetrics: o.EnableDebugGcMetrics,
EnableRuntimeMetrics: o.EnableRuntimeMetrics,
})
// create authentication for Innkeeper
auth := innkeeper.CreateInnkeeperAuthentication(innkeeper.AuthOptions{
InnkeeperAuthToken: o.InnkeeperAuthToken,
OAuthCredentialsDir: o.OAuthCredentialsDir,
OAuthUrl: o.OAuthUrl,
OAuthScope: o.OAuthScope})
// create data client
dataClients, err := createDataClients(o, auth)
if err != nil {
return err
}
if len(dataClients) == 0 {
log.Warning("no route source specified")
}
// create a filter registry with the available filter specs registered,
// and register the custom filters
registry := builtin.MakeRegistry()
for _, f := range o.CustomFilters {
registry.Register(f)
}
// create routing
// create the proxy instance
var mo routing.MatchingOptions
if o.IgnoreTrailingSlash {
mo = routing.IgnoreTrailingSlash
}
// ensure a non-zero poll timeout
if o.SourcePollTimeout <= 0 {
o.SourcePollTimeout = defaultSourcePollTimeout
}
// check for dev mode, and set update buffer of the routes
updateBuffer := defaultRoutingUpdateBuffer
if o.DevMode {
updateBuffer = 0
}
// create a routing engine
routing := routing.New(routing.Options{
registry,
mo,
o.SourcePollTimeout,
dataClients,
o.CustomPredicates,
updateBuffer})
// create the proxy
proxy := proxy.New(routing, o.ProxyOptions, o.PriorityRoutes...)
// create the access log handler
loggingHandler := logging.NewHandler(proxy)
// start the http server
log.Infof("proxy listener on %v", o.Address)
return http.ListenAndServe(o.Address, loggingHandler)
}
示例15: newTestRouting
func newTestRouting(dc ...routing.DataClient) (*testRouting, error) {
return newTestRoutingWithFiltersPredicates(builtin.MakeRegistry(), nil, dc...)
}