π Getting Started
Overviewβ
In this page, we will guide you in your first experience with GO Feature Flag and OpenFeature.
OpenFeature is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.
Let's have a working solution in 5 minutes. We will follow those steps:
- Create your first flag in a configuration file.
- Configure and start the relay-proxy.
- Import OpenFeature SDK and GO Feature Flag into your GO API.
- Configure the GO Feature Flag provider to connect with the relay proxy.
- Rollout a change based on the flag value.
If you are not interested to use GO Feature Flag with OpenFeature and prefer to use GO Feature Flag as a go module, check this getting started page.
Video Tutorialβ
1. Create your first flag in a configuration fileβ
Create a new yaml file named flags.goff.yaml, it will be the place where all your feature flags will be stored.
We will create our first flag to control if we display the contact button in our React page. By default, we will hide it for everyone.
show-email-contact:
variations:
enabled: true
disabled: false
defaultRule:
variation: disabled
π You have successfully learned how to create feature flags using GO Feature Flag.
2. Configure and start the relay-proxyβ
Now that we have a configuration file, we will run GO Feature Flag to use it. We will use the docker image for this tutorial.
Create a new yaml file named goff-proxy.yaml which will be the configuration file for the relay-proxy.
The GO Feature Flag Relay Proxy serves as the backend for your feature flag solution, housing all the necessary logic for feature flag management.
pollingInterval: 1000 # The relay-proxy will poll the file every second to check for changes
retrievers:
- kind: file
path: /goff/flags.goff.yaml # Location of the flags configuration file in your docker container.
Here we store our configuration as a local file, but you can use a remote file or a database to store your flags.
Check Store your feature flag file to see all the available options.
Let's start GO Feature Flag relay-proxy:
docker run \
-p 1031:1031 \
-v $(pwd)/flags.goff.yaml:/goff/flags.goff.yaml \
-v $(pwd)/goff-proxy.yaml:/goff/goff-proxy.yaml \
gofeatureflag/go-feature-flag:latest
GO Feature Flag has started on port 1031 and is ready to be used π.
π You have successfully learned how to configure and start GO Feature Flag relay-proxy.
3. Import OpenFeature SDK and GO Feature Flag into your GO API.β
- In this example, we are using a GO API to demonstrate how GO Feature Flag works, but you can check all the SDK available here.
- GO Feature Flag supports both
clientandserverparadigms for feature flagging, see SDK paradigms.
Considering that you have a simple 1-file GO APIβ
In this example, we will build a simple user info API that will return a JSON response with some user information.
package main
import (
"net/http"
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
response := map[string]any{
"firstname": "Mike",
"lastname": "Wazowski",
"organization": "Monsters, Inc.",
"jobFunction": "Scare assistant",
}
return c.JSON(http.StatusOK, response)
})
e.Logger.Fatal(e.Start(":1323"))
}
Install the dependencies:β
go get github.com/open-feature/go-sdk # Official OpenFeature SDK for GO
go get github.com/open-feature/go-sdk-contrib/providers/go-feature-flag # OpenFeature provider for GO Feature Flag