| 52 | func (f *customFilter) Response(_ filters.FilterContext) {} |
| 53 | |
| 54 | func Example() { |
| 55 | // create registry |
| 56 | registry := builtin.MakeRegistry() |
| 57 | |
| 58 | // create and register the filter specification |
| 59 | spec := &customSpec{name: "customFilter"} |
| 60 | registry.Register(spec) |
| 61 | |
| 62 | // create simple data client, with route entries referencing 'customFilter', |
| 63 | // and clipping part of the request path: |
| 64 | dataClient, err := testdataclient.NewDoc(` |
| 65 | |
| 66 | ui: Path("/ui/*page") -> |
| 67 | customFilter("ui request") -> |
| 68 | modPath("^/[^/]*", "") -> |
| 69 | "https://ui.example.org"; |
| 70 | |
| 71 | api: Path("/api/*resource") -> |
| 72 | customFilter("api request") -> |
| 73 | modPath("^/[^/]*", "") -> |
| 74 | "https://api.example.org"`) |
| 75 | |
| 76 | if err != nil { |
| 77 | log.Fatal(err) |
| 78 | } |
| 79 | |
| 80 | // create routing object: |
| 81 | rt := routing.New(routing.Options{ |
| 82 | FilterRegistry: registry, |
| 83 | DataClients: []routing.DataClient{dataClient}}) |
| 84 | defer rt.Close() |
| 85 | |
| 86 | // create http.Handler: |
| 87 | p := proxy.New(rt, proxy.OptionsNone) |
| 88 | defer p.Close() |
| 89 | } |