()
| 39 | } |
| 40 | |
| 41 | func ExampleIsNotModifiedError() { |
| 42 | // Assume that the server from NewNotModifiedError's example is running on |
| 43 | // localhost:8080. |
| 44 | client := pingv1connect.NewPingServiceClient( |
| 45 | http.DefaultClient, |
| 46 | "http://localhost:8080", |
| 47 | // Enable client-side support for HTTP GETs. |
| 48 | connect.WithHTTPGet(), |
| 49 | ) |
| 50 | req := &pingv1.PingRequest{Number: 42} |
| 51 | ctx, callInfo := connect.NewClientContext(context.Background()) |
| 52 | _, err := client.Ping(ctx, req) |
| 53 | if err != nil { |
| 54 | fmt.Println(err) |
| 55 | return |
| 56 | } |
| 57 | // If the server set an Etag, we can use it to cache the response. |
| 58 | etag := callInfo.ResponseHeader().Get("Etag") |
| 59 | if etag == "" { |
| 60 | fmt.Println("no Etag in response headers") |
| 61 | return |
| 62 | } |
| 63 | fmt.Println("cached response with Etag", etag) |
| 64 | // Now we'd like to make the same request again, but avoid re-fetching the |
| 65 | // response if possible. |
| 66 | callInfo.RequestHeader().Set("If-None-Match", etag) |
| 67 | _, err = client.Ping(context.Background(), req) |
| 68 | if connect.IsNotModifiedError(err) { |
| 69 | fmt.Println("can reuse cached response") |
| 70 | } |
| 71 | } |
nothing calls this directly
no test coverage detected