Skip to content

Commit ff132f4

Browse files
committed
chore(go): add some comments
1 parent 15e8e63 commit ff132f4

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

openfeature-provider/go/demo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func main() {
7373
},
7474
)
7575

76-
// Run 10 concurrent threads continuously for at least 20 seconds
76+
// Run 20 concurrent threads continuously for at least 20 seconds
7777
var wg sync.WaitGroup
7878
numThreads := 20
7979
runDuration := 20 * time.Second

openfeature-provider/go/local_resolver_factory.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ func NewLocalResolverFactory(
116116
token, err := tokenHolder.GetToken(ctx)
117117
if err != nil {
118118
log.Printf("Warning: failed to get initial token, account name will be unknown: %v", err)
119+
// TODO should we return an error here?
120+
// return nil, fmt.Errorf("failed to get initial token: %w", err)
119121
}
120122
accountName := "unknown"
121123
if token != nil {
@@ -127,9 +129,11 @@ func NewLocalResolverFactory(
127129
stateProvider = stateFetcher
128130

129131
// Get initial state using StateProvider interface
130-
initialState, err = stateFetcher.Provide(ctx)
132+
initialState, err = stateProvider.Provide(ctx)
131133
if err != nil {
132134
log.Printf("Initial state fetch failed, using empty state: %v", err)
135+
// TODO should we return an error here?
136+
// return nil, fmt.Errorf("failed to get initial state: %w", err)
133137
}
134138
if initialState == nil {
135139
initialState = []byte{}
@@ -190,10 +194,10 @@ func (f *LocalResolverFactory) startScheduledTasks(parentCtx context.Context) {
190194
for {
191195
select {
192196
case <-ticker.C:
193-
// Fetch latest state using StateProvider interface
197+
// Fetch latest state
194198
state, err := f.stateProvider.Provide(ctx)
195199
if err != nil {
196-
log.Printf("State fetch from provider failed: %v", err)
200+
log.Printf("State fetch failed: %v", err)
197201
}
198202

199203
// Update state and flush logs (even if state fetch failed, use cached state)

openfeature-provider/go/provider_builder.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ type ProviderConfig struct {
2020
ClientSecret string
2121

2222
// Optional: Custom service addresses (for advanced use cases only)
23-
// If not provided, defaults to EU region
23+
// If not provided, defaults to global region
2424
ResolverStateServiceAddr string
2525
FlagLoggerServiceAddr string
2626
AuthServiceAddr string
27-
28-
// Optional: Custom WASM bytes (for advanced use cases only)
29-
// If not provided, loads from default location
30-
WasmBytes []byte
3127
}
3228

3329
// ProviderConfigWithStateProvider holds configuration for the Confidence provider with a custom StateProvider
30+
// WARNING: This configuration is intended for testing and advanced use cases ONLY.
31+
// For production deployments, use NewProvider() with ProviderConfig instead, which provides:
32+
// - Automatic state fetching from Confidence backend
33+
// - Built-in authentication and secure connections
34+
// - Exposure event logging for analytics
35+
//
36+
// Only use this when you need to provide a custom state source (e.g., local file cache for testing).
3437
type ProviderConfigWithStateProvider struct {
3538
// Required: Client secret for signing evaluations
3639
ClientSecret string
@@ -75,15 +78,10 @@ func NewProvider(ctx context.Context, config ProviderConfig) (*LocalResolverProv
7578
authServiceAddr = ConfidenceDomain
7679
}
7780

78-
// Load WASM bytes
79-
wasmBytes := config.WasmBytes
80-
if wasmBytes == nil {
81-
// Load from default filesystem location
82-
var err error
83-
wasmBytes, err = os.ReadFile("../../../wasm/confidence_resolver.wasm")
84-
if err != nil {
85-
return nil, fmt.Errorf("failed to load WASM module from ../../wasm/confidence_resolver.wasm: %w. Please provide WasmBytes in config or ensure WASM file exists", err)
86-
}
81+
// Load wasm from default filesystem location
82+
wasmBytes, err := os.ReadFile("../../../wasm/confidence_resolver.wasm")
83+
if err != nil {
84+
return nil, fmt.Errorf("failed to load WASM module from ../../../wasm/confidence_resolver.wasm: %w", err)
8785
}
8886

8987
runtimeConfig := wazero.NewRuntimeConfig()
@@ -114,6 +112,7 @@ func NewProvider(ctx context.Context, config ProviderConfig) (*LocalResolverProv
114112
}
115113

116114
// NewProviderWithStateProvider creates a new Confidence OpenFeature provider with a custom StateProvider
115+
// Should only be used for testing purposes. Will not emit exposure logging.
117116
func NewProviderWithStateProvider(ctx context.Context, config ProviderConfigWithStateProvider) (*LocalResolverProvider, error) {
118117
// Validate required fields
119118
if config.ClientSecret == "" {

openfeature-provider/go/resolver_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (r *ResolverApi) FlushLogs() error {
171171
return nil
172172
}
173173

174-
// Write logs via the flag logger if we have one
174+
// Write logs via the flag logger
175175
if r.flagLogger != nil && (len(logRequest.FlagAssigned) > 0 || len(logRequest.ClientResolveInfo) > 0 || len(logRequest.FlagResolveInfo) > 0) {
176176
if err := r.flagLogger.Write(ctx, logRequest); err != nil {
177177
log.Printf("Failed to write flushed logs: %v", err)

openfeature-provider/go/swap_wasm_resolver_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (s *SwapWasmResolverApi) UpdateStateAndFlushLogs(state []byte, accountId st
7474
// Atomically swap to the new instance
7575
oldInstance := s.currentInstance.Swap(newInstance).(*ResolverApi)
7676

77-
// Close the old instance
77+
// Close the old instance (which flushes logs)
7878
oldInstance.Close(ctx)
7979
return nil
8080
}

0 commit comments

Comments
 (0)