Update to match codegen (#10)
diff --git a/client_option.go b/client_option.go
index 10ccc98..27c206a 100644
--- a/client_option.go
+++ b/client_option.go
@@ -14,37 +14,39 @@
}
type ClientSettings struct {
- APIName string
- APIVersion string
- Endpoint string
- Scopes []string
+ AppName string
+ AppVersion string
+ Endpoint string
+ Scopes []string
+ CallOptions map[string][]CallOption
}
func (w ClientSettings) Resolve(s *ClientSettings) {
- s.APIName = w.APIName
- s.APIVersion = w.APIVersion
+ s.AppName = w.AppName
+ s.AppVersion = w.AppVersion
s.Endpoint = w.Endpoint
- s.Scopes = append([]string{}, w.Scopes...)
+ WithScopes(w.Scopes...).Resolve(s)
+ WithCallOptions(w.CallOptions).Resolve(s)
}
-type withAPIName string
+type withAppName string
-func (w withAPIName) Resolve(s *ClientSettings) {
- s.APIName = string(w)
+func (w withAppName) Resolve(s *ClientSettings) {
+ s.AppName = string(w)
}
-func WithAPIName(apiName string) ClientOption {
- return withAPIName(apiName)
+func WithAppName(appName string) ClientOption {
+ return withAppName(appName)
}
-type withAPIVersion string
+type withAppVersion string
-func (w withAPIVersion) Resolve(s *ClientSettings) {
- s.APIVersion = string(w)
+func (w withAppVersion) Resolve(s *ClientSettings) {
+ s.AppVersion = string(w)
}
-func WithAPIVersion(apiVersion string) ClientOption {
- return withAPIVersion(apiVersion)
+func WithAppVersion(appVersion string) ClientOption {
+ return withAppVersion(appVersion)
}
type withEndpoint string
@@ -60,9 +62,22 @@
type withScopes []string
func (w withScopes) Resolve(s *ClientSettings) {
- s.Scopes = append(s.Scopes[:0], w...)
+ s.Scopes = append([]string{}, w...)
}
func WithScopes(scopes ...string) ClientOption {
return withScopes(scopes)
}
+
+type withCallOptions map[string][]CallOption
+
+func (w withCallOptions) Resolve(s *ClientSettings) {
+ s.CallOptions = make(map[string][]CallOption, len(w))
+ for key, value := range w {
+ s.CallOptions[key] = value
+ }
+}
+
+func WithCallOptions(callOptions map[string][]CallOption) ClientOption {
+ return withCallOptions(callOptions)
+}
diff --git a/client_option_test.go b/client_option_test.go
index 2394054..c1a78bc 100644
--- a/client_option_test.go
+++ b/client_option_test.go
@@ -3,6 +3,7 @@
import (
"reflect"
"testing"
+ "time"
)
func TestClientOptionsPieceByPiece(t *testing.T) {
@@ -11,14 +12,16 @@
"v0.1.0",
"https://example.com:443",
[]string{"https://example.com/auth/helloworld", "https://example.com/auth/otherthing"},
+ map[string][]CallOption{"ListWorlds": []CallOption{WithTimeout(3 * time.Second)}},
}
settings := &ClientSettings{}
opts := []ClientOption{
- WithAPIName("myapi"),
- WithAPIVersion("v0.1.0"),
+ WithAppName("myapi"),
+ WithAppVersion("v0.1.0"),
WithEndpoint("https://example.com:443"),
WithScopes("https://example.com/auth/helloworld", "https://example.com/auth/otherthing"),
+ WithCallOptions(map[string][]CallOption{"ListWorlds": []CallOption{WithTimeout(3 * time.Second)}}),
}
clientOptions(opts).Resolve(settings)
@@ -37,4 +40,8 @@
if settings.Scopes[0] == expected.Scopes[0] {
t.Errorf("unexpected modification in Scopes array")
}
+ expected.CallOptions["Impossible"] = []CallOption{WithTimeout(42 * time.Second)}
+ if _, ok := settings.CallOptions["Impossible"]; ok {
+ t.Errorf("unexpected modification in CallOptions map")
+ }
}