Feature flags
Evaluate OpenFeature flags from Go, with the behaviour of the official Web SDK.
OpenFeature is a vendor-neutral API for feature flags. The
openfeature
package is a Go port of its Web SDK: one global API, clients per domain, hooks, events and an evaluation context. A provider connects it to a flag service.
There is no live demo on this page, because a real one needs a running Flipt server.
ยง1 Setup
List the Flipt modules on the handler, then create the provider and bind it. Binding waits for the provider to initialize, so do it inside
ctx.Async
:
h
:=
&
app
.
Handler
{
Imports
:
flipt
.
Modules
(
)
}
func
(
c
*
nav
)
OnMount
(
ctx
app
.
Context
)
{
p
,
ok
:=
flipt
.
New
(
ctx
,
flipt
.
Options
{
URL
:
"https://flags.example.com"
,
ClientToken
:
token
}
)
if
!
ok
{
return
}
ctx
.
Async
(
func
(
)
{
err
:=
openfeature
.
SetProviderAndWait
(
p
,
openfeature
.
WithContext
(
openfeature
.
Context
{
TargetingKey
:
userID
}
)
)
ctx
.
Dispatch
(
func
(
app
.
Context
)
{
c
.
err
=
err
}
)
}
)
}
flipt.New
reports
false
on the server and when the module did not load.
flipt.LocalModules(dir)
serves the same four files from
/web/<dir>/
for self-hosting.
SetProvider
is the non-blocking form. It returns only validation errors and logs an initialization failure.