()
| 229 | } |
| 230 | |
| 231 | func ExampleForwardBackend() { |
| 232 | backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 233 | w.WriteHeader(http.StatusOK) |
| 234 | })) |
| 235 | defer backend.Close() |
| 236 | |
| 237 | doc := `r: * -> <forward>;` |
| 238 | routes := eskip.MustParse(doc) |
| 239 | |
| 240 | spec := builtin.NewStatus() |
| 241 | fr := make(filters.Registry) |
| 242 | fr.Register(spec) |
| 243 | |
| 244 | dc := testdataclient.New(routes) |
| 245 | defer dc.Close() |
| 246 | |
| 247 | proxy := proxytest.WithRoutingOptions(fr, routing.Options{ |
| 248 | DataClients: []routing.DataClient{dc}, |
| 249 | PreProcessors: []routing.PreProcessor{eskip.ForwardPreProcessor(backend.URL)}, |
| 250 | }) |
| 251 | defer proxy.Close() |
| 252 | |
| 253 | client := proxy.Client() |
| 254 | req, err := http.NewRequest("GET", proxy.URL, nil) |
| 255 | if err != nil { |
| 256 | fmt.Printf("Failed to create request: %v\n", err) |
| 257 | } |
| 258 | |
| 259 | rsp, err := client.Do(req) |
| 260 | if err != nil { |
| 261 | fmt.Printf("Failed to GET hello.example: %v\n", err) |
| 262 | return |
| 263 | } |
| 264 | defer rsp.Body.Close() |
| 265 | if rsp.StatusCode != http.StatusOK { |
| 266 | fmt.Printf("Failed to GET OK from http://hello.example, got: %v\n", rsp.StatusCode) |
| 267 | return |
| 268 | } |
| 269 | fmt.Println("hello skipper") |
| 270 | |
| 271 | // output: |
| 272 | // hello skipper |
| 273 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…