mirror of https://github.com/open-feature/cli.git
65 lines
2.6 KiB
Cheetah
65 lines
2.6 KiB
Cheetah
// AUTOMATICALLY GENERATED BY OPENFEATURE CLI, DO NOT EDIT.
|
|
package {{ .Params.Custom.JavaPackage }};
|
|
|
|
import dev.openfeature.sdk.Client;
|
|
import dev.openfeature.sdk.EvaluationContext;
|
|
import dev.openfeature.sdk.FlagEvaluationDetails;
|
|
import dev.openfeature.sdk.OpenFeatureAPI;
|
|
|
|
public final class OpenFeature {
|
|
|
|
private OpenFeature() {} // prevent instantiation
|
|
|
|
public interface GeneratedClient {
|
|
{{ range .Flagset.Flags }}
|
|
/**
|
|
* {{ .Description }}
|
|
* Details:
|
|
* - Flag key: {{ .Key }}
|
|
* - Type: {{ .Type | OpenFeatureType }}
|
|
* - Default value: {{ if eq (.Type | OpenFeatureType) "Object" }}{{ .DefaultValue | ToMapLiteral }}{{ else }}{{ .DefaultValue }}{{ end }}
|
|
* Returns the flag value
|
|
*/
|
|
{{ .Type | OpenFeatureType }} {{ .Key | ToCamel }}(EvaluationContext ctx);
|
|
|
|
/**
|
|
* {{ .Description }}
|
|
* Details:
|
|
* - Flag key: {{ .Key }}
|
|
* - Type: {{ .Type | OpenFeatureType }}
|
|
* - Default value: {{ if eq (.Type | OpenFeatureType) "Object" }}{{ .DefaultValue | ToMapLiteral }}{{ else }}{{ .DefaultValue }}{{ end }}
|
|
* Returns the evaluation details containing the flag value and metadata
|
|
*/
|
|
FlagEvaluationDetails<{{ .Type | OpenFeatureType }}> {{ .Key | ToCamel }}Details(EvaluationContext ctx);
|
|
{{ end }}
|
|
}
|
|
|
|
private static final class OpenFeatureGeneratedClient implements GeneratedClient {
|
|
private final Client client;
|
|
|
|
private OpenFeatureGeneratedClient(Client client) {
|
|
this.client = client;
|
|
}
|
|
|
|
{{ range .Flagset.Flags }}
|
|
@Override
|
|
public {{ .Type | OpenFeatureType }} {{ .Key | ToCamel }}(EvaluationContext ctx) {
|
|
return client.get{{ .Type | OpenFeatureType | ToPascal }}Value("{{ .Key }}", {{ if eq (.Type | OpenFeatureType) "Object" }}{{ .DefaultValue | ToMapLiteral }}{{ else }}{{ . | FormatDefaultValue }}{{ end }}, ctx);
|
|
}
|
|
|
|
@Override
|
|
public FlagEvaluationDetails<{{ .Type | OpenFeatureType }}> {{ .Key | ToCamel }}Details(EvaluationContext ctx) {
|
|
return client.get{{ .Type | OpenFeatureType | ToPascal }}Details("{{ .Key }}", {{ if eq (.Type | OpenFeatureType) "Object" }}{{ .DefaultValue | ToMapLiteral }}{{ else }}{{ . | FormatDefaultValue }}{{ end }}, ctx);
|
|
}
|
|
{{ end }}
|
|
}
|
|
|
|
public static GeneratedClient getClient() {
|
|
return new OpenFeatureGeneratedClient(OpenFeatureAPI.getInstance().getClient());
|
|
}
|
|
|
|
public static GeneratedClient getClient(String domain) {
|
|
return new OpenFeatureGeneratedClient(OpenFeatureAPI.getInstance().getClient(domain));
|
|
}
|
|
}
|