-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_opts.go
More file actions
62 lines (52 loc) · 1.19 KB
/
client_opts.go
File metadata and controls
62 lines (52 loc) · 1.19 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
package radiant
import (
"context"
"fmt"
"time"
"github.com/gogo/protobuf/types"
api "github.com/stellarproject/radiant/api/v1"
)
type AddOpts func(ctx context.Context, srv *api.Server) error
func WithPath(path string) AddOpts {
return func(ctx context.Context, srv *api.Server) error {
if path == "" {
return fmt.Errorf("path cannot be empty")
}
srv.Path = path
return nil
}
}
func WithTLS(ctx context.Context, srv *api.Server) error {
srv.TLS = true
return nil
}
func WithPolicy(p api.Policy) AddOpts {
return func(ctx context.Context, srv *api.Server) error {
srv.Policy = p
return nil
}
}
func WithUpstreams(upstreams ...string) AddOpts {
return func(ctx context.Context, srv *api.Server) error {
srv.Upstreams = upstreams
return nil
}
}
func WithTimeouts(d time.Duration) AddOpts {
return func(ctx context.Context, srv *api.Server) error {
srv.Timeouts = types.DurationProto(d)
return nil
}
}
func WithPreset(preset string) AddOpts {
return func(ctx context.Context, srv *api.Server) error {
srv.Preset = preset
return nil
}
}
func WithServer(s *api.Server) AddOpts {
return func(ctx context.Context, srv *api.Server) error {
srv = s
return nil
}
}