Categorygithub.com/escaletech/tog-go
module
0.1.3
Repository: https://github.com/escaletech/tog-go.git
Documentation: pkg.go.dev

# README

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)
}

# Packages

No description provided by the author
No description provided by the author