Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
/ tog-go Public archive

Go client library that implements the Tog specification for feature flags over Redis

License

Notifications You must be signed in to change notification settings

escaletech/tog-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tog Go Client

CircleCI GitHub tag (latest SemVer) API reference Go Report Card Coveralls github branch

Go client library that implements the Tog specification for feature flags over Redis

Usage

For using sessions

See sessions docs.

$ go get github.com/escaletech/tog-node/sessions
package main

import (
  "context"
  "fmt"

  "github.com/escaletech/tog-node/sessions"
)

func main() {
  client, err := sessions.NewClient(flags.ClientOptions{
    Addr: "redis://localhost:6379/2",
    Cluster: false,
    OnError: func(ctx context.Context, err error) {
      // errors will always be sent here
      fmt.Println("Error:", err.Error())
    },
  })
  if err != nil {
    panic(err)
  }

  defer fc.Close()
  ctx := context.Background()

  // wherever you whish to retrieve a session
  sess := client.Session(ctx, "my_app", "the-session-id", nil)

  buttonColor := "red"
  if sess.IsSet("blue-button") {
    buttonColor = "blue"
  }

  fmt.Println("the button is", buttonColor)
}

For managing flags

See flags docs.

$ go get github.com/escaletech/tog-node/flags
package main

import (
  "context"
  "fmt"

  "github.com/escaletech/tog-node/flags"
)

func main() {
  client, err := flags.NewClient(flags.ClientOptions{
    Addr: "redis://localhost:6379/2",
    Cluster: false,
  })
  if err != nil {
    panic(err)
  }

  defer fc.Close()
  ctx := context.Background()

  // Save a flag
  flag, err := client.SaveFlag(ctx, flags.Flag{
    Namespace: "my_app",
    Name: "blue-button",
    Description: "Makes the call-to-action button blue",
    Rollout: []flags.Rollout{{ Percentage: 30, Value: true }},
  })
  fmt.Println(flag, err)

  // List flags
  allFlags, err := client.ListFlags(ctx, "my_app")
  fmt.Println(allFlags, err)
}

About

Go client library that implements the Tog specification for feature flags over Redis

Resources

License

Stars

Watchers

Forks

Packages

No packages published