tog-go

module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2020 License: MIT

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

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL