@@ -9,16 +9,16 @@ This content has been automatically generated from go-sdk.
99Edits should be made here: https://github.com/open-feature/go-sdk
1010Once a repo has been updated, docs can be generated by running: yarn update :sdk-docs
1111
12- Last updated at Mon Jun 02 2025 17:42:11 GMT+0000 (Coordinated Universal Time)
12+ Last updated at Thu Jun 12 2025 08:10:57 GMT+0000 (Coordinated Universal Time)
1313-->
1414
1515<p align = " center" class = " github-badges" >
1616 <a href = " https://github.com/open-feature/spec/releases/tag/v0.7.0" >
1717 <img alt = " Specification" src = " https://img.shields.io/static/v1?label=specification&message=v0.7.0&color=yellow&style=for-the-badge" />
1818 </a >
1919
20- <a href = " https://github.com/open-feature/go-sdk/releases/tag/v1.14.1 " >
21- <img alt = " Release" src = " https://img.shields.io/static/v1?label=release&message=v1.14.1 &color=blue&style=for-the-badge" />
20+ <a href = " https://github.com/open-feature/go-sdk/releases/tag/v1.15.0 " >
21+ <img alt = " Release" src = " https://img.shields.io/static/v1?label=release&message=v1.15.0 &color=blue&style=for-the-badge" />
2222 </a >
2323
2424 <br />
@@ -69,7 +69,7 @@ func main() {
6969 client := openfeature.NewClient (" app" )
7070 // Evaluate your feature flag
7171 v2Enabled := client.Boolean (
72- context.Background (), " v2_enabled" , true , openfeature.EvaluationContext {},
72+ context.TODO (), " v2_enabled" , true , openfeature.EvaluationContext {},
7373 )
7474 // Use the returned flag value
7575 if v2Enabled {
@@ -166,7 +166,7 @@ client.AddHooks(ExampleClientHook{})
166166
167167// add a hook for this evaluation only
168168value , err := client.BooleanValue (
169- context.Background (), " boolFlag" , false , openfeature.EvaluationContext {}, WithHooks (ExampleInvocationHook{}),
169+ context.TODO (), " boolFlag" , false , openfeature.EvaluationContext {}, WithHooks (ExampleInvocationHook{}),
170170)
171171```
172172
@@ -182,7 +182,7 @@ client := openfeature.NewClient('my-app')
182182
183183// trigger tracking event action
184184client.Track (
185- context.Background (),
185+ context.TODO (),
186186 ' visited-promo-page' ,
187187 openfeature.EvaluationContext {},
188188 openfeature.NewTrackingEventDetails (99.77 ).Add (" currencyCode" , " USD" ),
@@ -203,29 +203,43 @@ This hook can be particularly helpful for troubleshooting and debugging; simply
203203##### Usage example
204204
205205``` go
206- // configure slog
207- var programLevel = new (slog.LevelVar )
208- programLevel.Set (slog.LevelDebug )
209- h := slog.NewJSONHandler (os.Stderr , &slog.HandlerOptions {Level: programLevel})
210- slog.SetDefault (slog.New (h))
211-
212- // add a hook globally to run on all evaluations
213- hook , err := NewLoggingHook (false )
214- if err != nil {
215- // handle error
216- }
206+ package main
207+
208+ import (
209+ " context"
210+ " log/slog"
211+ " os"
212+
213+ " github.com/open-feature/go-sdk/openfeature"
214+ " github.com/open-feature/go-sdk/openfeature/hooks"
215+ " github.com/open-feature/go-sdk/openfeature/memprovider"
216+ )
217+
218+ func main () {
219+ // Register an in-memory provider with no flags
220+ openfeature.SetNamedProviderAndWait (" example" , memprovider.NewInMemoryProvider (map [string ]memprovider.InMemoryFlag {}))
217221
218- openfeature.AddHooks (hook)
222+ // Configure slog
223+ handler := slog.NewJSONHandler (os.Stderr , &slog.HandlerOptions {Level: slog.LevelDebug })
224+ logger := slog.New (handler)
219225
220- client.BooleanValueDetails (context.Background (), " not-exist" , true , openfeature.EvaluationContext {})
226+ // Register a logging hook globally to run on all evaluations
227+ loggingHook := hooks.NewLoggingHook (false , logger)
228+ openfeature.AddHooks (loggingHook)
221229
230+ // Create a new client
231+ client := openfeature.NewClient (" example" )
232+
233+ // Attempt to evaluate a flag that doesn't exist
234+ _ = client.Boolean (context.TODO (), " not-exist" , true , openfeature.EvaluationContext {})
235+ }
222236```
223237
224238###### Output
225239
226240``` sh
227- {" time" :" 2024-10-23T13:33:09.8870867+03 :00" ," level" :" DEBUG" ," msg" :" Before stage" ," domain" :" test-client " ," provider_name" :" InMemoryProvider" ," flag_key" :" not-exist" ," default_value" :true}
228- {" time" :" 2024-10-23T13:33:09.8968242+03 :00" ," level" :" ERROR" ," msg" :" Error stage" ," domain" :" test-client " ," provider_name" :" InMemoryProvider" ," flag_key" :" not-exist" ," default_value" :true," error_message" :" error code: FLAG_NOT_FOUND: flag for key not-exist not found" }
241+ {" time" :" 2025-06-03T10:49:23.100783-04 :00" ," level" :" DEBUG" ," msg" :" Before stage" ," domain" :" example " ," provider_name" :" InMemoryProvider" ," flag_key" :" not-exist" ," default_value" :true, " stage " : " before " }
242+ {" time" :" 2025-06-03T10:49:23.101037-04 :00" ," level" :" ERROR" ," msg" :" Error stage" ," domain" :" example " ," provider_name" :" InMemoryProvider" ," flag_key" :" not-exist" ," default_value" :true," error_message" :" error code: FLAG_NOT_FOUND: flag for key not-exist not found" , " stage " : " error " }
229243```
230244
231245See [ hooks] ( #hooks ) for more information on configuring hooks.
@@ -299,7 +313,7 @@ Transaction context can be set where specific data is available (e.g. an auth se
299313import " github.com/open-feature/go-sdk/openfeature"
300314
301315// set the TransactionContext
302- ctx := openfeature.WithTransactionContext (context.Background (), openfeature.EvaluationContext {})
316+ ctx := openfeature.WithTransactionContext (context.TODO (), openfeature.EvaluationContext {})
303317
304318// get the TransactionContext from a context
305319ec := openfeature.TransactionContext (ctx)
0 commit comments