Skip to content

Commit d348f80

Browse files
committed
adding documentation for custom context
1 parent cbe955e commit d348f80

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

go/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,46 @@ func main() {
118118
}
119119
}
120120
```
121+
### Custom Context
122+
123+
If you want even greater control over the lifecycle of the HTTP requests consider providing a [context](https://pkg.go.dev/context). Contexts can be set for all requests or per request.
124+
125+
#### Custom Context for all requests
126+
127+
Follow the example code snippet below if you want all requests to use the same context:
128+
129+
```go
130+
import "context"
131+
132+
func main() {
133+
// sets a timeout of 5 minutes
134+
ctx, cancel := context.WithTimout(context.Background(), 5*time.Minute)
135+
defer cancel()
136+
137+
cfg, err := rtl.NewSettingsFromFile("path/to/looker.ini", nil)
138+
cfg.Context = ctx
139+
140+
session := rtl.NewAuthSession(cfg)
141+
sdk := v4.NewLookerSDK(session)
142+
}
143+
```
144+
145+
#### Custom Context per request
146+
147+
Follow the example here to set a context for a specific request. **This will override any context set in the SDK config as outlined in the previous section.**
148+
149+
```go
150+
import "context"
151+
152+
func main() {
153+
// sets a timeout of 5 minutes
154+
ctx, cancel := context.WithTimout(context.Background(), 5*time.Minute)
155+
defer cancel()
156+
157+
cfg, err := rtl.NewSettingsFromFile("path/to/looker.ini", nil)
158+
session := rtl.NewAuthSession(cfg)
159+
sdk := v4.NewLookerSDK(session)
160+
161+
sdk.Me("", &ApiSettings{Context: ctx})
162+
}
163+
```

0 commit comments

Comments
 (0)