diff --git a/.gitignore b/.gitignore index 4f0ee923..2efb1967 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ Cargo.lock tmp .envrc .vscode -staging \ No newline at end of file +staging +*.h \ No newline at end of file diff --git a/flipt-client-dart/lib/src/models.dart b/flipt-client-dart/lib/src/models.dart index bae4f07e..b9c3f821 100644 --- a/flipt-client-dart/lib/src/models.dart +++ b/flipt-client-dart/lib/src/models.dart @@ -2,6 +2,14 @@ import 'package:json_annotation/json_annotation.dart'; part 'models.g.dart'; +enum FetchMode { + @JsonValue('polling') + polling, + @JsonValue('streaming') + streaming, +} + +/// Options for the Flipt client @JsonSerializable() class Options { final String? url; @@ -9,11 +17,15 @@ class Options { final int? updateInterval; final Map? authentication; + /// Note: Streaming is currently only supported when using the SDK with Flipt Cloud (https://flipt.io/cloud). + final FetchMode? fetchMode; + Options({ this.url = 'http://localhost:8080', this.reference, this.updateInterval = 120, this.authentication, + this.fetchMode = FetchMode.polling, }); factory Options.fromJson(Map json) => @@ -25,6 +37,7 @@ class Options { String? url, String? reference, int? updateInterval, + FetchMode? fetchMode, }) { return Options( url: url, @@ -33,6 +46,7 @@ class Options { authentication: { 'client_token': token, }, + fetchMode: fetchMode, ); } @@ -41,6 +55,7 @@ class Options { String? url, String? reference, int? updateInterval, + FetchMode? fetchMode, }) { return Options( url: url, @@ -49,6 +64,7 @@ class Options { authentication: { 'jwt_token': token, }, + fetchMode: fetchMode, ); } } diff --git a/flipt-client-dart/lib/src/models.g.dart b/flipt-client-dart/lib/src/models.g.dart index d34f22e8..9145d6ce 100644 --- a/flipt-client-dart/lib/src/models.g.dart +++ b/flipt-client-dart/lib/src/models.g.dart @@ -11,6 +11,8 @@ Options _$OptionsFromJson(Map json) => Options( reference: json['reference'] as String?, updateInterval: (json['update_interval'] as num?)?.toInt() ?? 120, authentication: json['authentication'] as Map?, + fetchMode: $enumDecodeNullable(_$FetchModeEnumMap, json['fetch_mode']) ?? + FetchMode.polling, ); Map _$OptionsToJson(Options instance) => { @@ -18,8 +20,14 @@ Map _$OptionsToJson(Options instance) => { 'reference': instance.reference, 'update_interval': instance.updateInterval, 'authentication': instance.authentication, + 'fetch_mode': _$FetchModeEnumMap[instance.fetchMode], }; +const _$FetchModeEnumMap = { + FetchMode.polling: 'polling', + FetchMode.streaming: 'streaming', +}; + Flag _$FlagFromJson(Map json) => Flag( key: json['key'] as String, enabled: json['enabled'] as bool, diff --git a/flipt-client-go/evaluation.go b/flipt-client-go/evaluation.go index 39c76fb5..f9bc2711 100644 --- a/flipt-client-go/evaluation.go +++ b/flipt-client-go/evaluation.go @@ -29,6 +29,7 @@ type EvaluationClient struct { authentication any ref string updateInterval int + fetchMode FetchMode } // NewEvaluationClient constructs a Client. @@ -46,6 +47,7 @@ func NewEvaluationClient(opts ...clientOption) (*EvaluationClient, error) { UpdateInterval: client.updateInterval, Authentication: &client.authentication, Reference: client.ref, + FetchMode: client.fetchMode, } b, err := json.Marshal(clientOpts) @@ -106,6 +108,14 @@ func WithJWTAuthentication(token string) clientOption { } } +// WithFetchMode allows for specifying the fetch mode for the Flipt client (e.g. polling, streaming). +// Note: Streaming is currently only supported when using the SDK with Flipt Cloud (https://flipt.io/cloud). +func WithFetchMode(fetchMode FetchMode) clientOption { + return func(c *EvaluationClient) { + c.fetchMode = fetchMode + } +} + // EvaluateVariant performs evaluation for a variant flag. func (e *EvaluationClient) EvaluateVariant(_ context.Context, flagKey, entityID string, evalContext map[string]string) (*VariantEvaluationResponse, error) { ereq, err := json.Marshal(evaluationRequest{ diff --git a/flipt-client-go/models.go b/flipt-client-go/models.go index 3a9ed577..e47622aa 100644 --- a/flipt-client-go/models.go +++ b/flipt-client-go/models.go @@ -21,11 +21,19 @@ type jwtAuthentication struct { Token string `json:"jwt_token"` } +type FetchMode string + +const ( + FetchModeStreaming FetchMode = "streaming" + FetchModePolling FetchMode = "polling" +) + type clientOptions[T any] struct { - URL string `json:"url,omitempty"` - Authentication *T `json:"authentication,omitempty"` - UpdateInterval int `json:"update_interval,omitempty"` - Reference string `json:"reference,omitempty"` + URL string `json:"url,omitempty"` + Authentication *T `json:"authentication,omitempty"` + UpdateInterval int `json:"update_interval,omitempty"` + Reference string `json:"reference,omitempty"` + FetchMode FetchMode `json:"fetch_mode,omitempty"` } type Flag struct { diff --git a/flipt-client-java/.idea/gradle.xml b/flipt-client-java/.idea/gradle.xml index 2a65317e..1ace7cf4 100644 --- a/flipt-client-java/.idea/gradle.xml +++ b/flipt-client-java/.idea/gradle.xml @@ -5,7 +5,7 @@