File: request_option.go

package info (click to toggle)
golang-github-scaleway-scaleway-sdk-go 1.0.0~beta12-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,000 kB
  • sloc: javascript: 160; sh: 70; makefile: 3
file content (50 lines) | stat: -rw-r--r-- 1,552 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package scw

import (
	"context"

	"github.com/scaleway/scaleway-sdk-go/internal/auth"
)

// RequestOption is a function that applies options to a ScalewayRequest.
type RequestOption func(*ScalewayRequest)

// WithContext request option sets the context of a ScalewayRequest
func WithContext(ctx context.Context) RequestOption {
	return func(s *ScalewayRequest) {
		s.ctx = ctx
	}
}

// WithAllPages aggregate all pages in the response of a List request.
// Will error when pagination is not supported on the request.
func WithAllPages() RequestOption {
	return func(s *ScalewayRequest) {
		s.allPages = true
	}
}

// WithAuthRequest overwrites the client access key and secret key used in the request.
func WithAuthRequest(accessKey, secretKey string) RequestOption {
	return func(s *ScalewayRequest) {
		s.auth = auth.NewToken(accessKey, secretKey)
	}
}

// WithZones aggregate results from requested zones in the response of a List request.
// response rows are sorted by zone using order of given zones
// Will error when pagination is not supported on the request.
func WithZones(zones ...Zone) RequestOption {
	return func(s *ScalewayRequest) {
		s.zones = append(s.zones, zones...)
	}
}

// WithRegions aggregate results from requested regions in the response of a List request.
// response rows are sorted by region using order of given regions
// Will error when pagination is not supported on the request.
func WithRegions(regions ...Region) RequestOption {
	return func(s *ScalewayRequest) {
		s.regions = append(s.regions, regions...)
	}
}