Code Monkey home page Code Monkey logo

split-go-serializer's Introduction

split-go-serializer

A Go module which fetches split definitions and segments from Split.io and serializes them into a set of strings that the GO SDK can consume.

Setting Up Dev Environment

  1. Setup Go on your local machine by following these docs
  2. Clone this repo
    $ git clone https://github.com/godaddy/split-go-serializer.git
    
  3. Install Dependencies in the project directory
    $ go get ./...
    $ go get golang.org/x/lint/golint
    $ go get github.com/axw/gocov/gocov
    $ GO111MODULE=off go get gopkg.in/matm/v1/gocov-html
    $ go mod tidy
    

Usage

Use this Go module in your server-side Go environment. The serializer exposes:

  1. a Poller that periodically requests raw experiment configuration data from Split.io. Requests happen in the background and the poller caches the latest data in local memory.

Instantiation

Create an instance of Poller by importing the poller package of this module and calling the NewPoller function with some parameters :

import (
    "github.com/godaddy/split-go-serializer/poller"
)

poller := poller.NewPoller("YOUR_API_KEY", 600, false, nil)

The following option properties are available to the Poller:

Property Description
splitioApiKey The Split.io SDK key for the environment your app is running in. (required)
pollingRateSeconds The interval at which to poll Split.io. Defaults to 300 (5 minutes).
serializeSegments Whether or not to fetch segment configuration data. Defaults to false.

Serializing segments

Segments are pre-defined groups of customers that features can be targeted to. More info here.

Note: Requesting serialized segments will increase the size of your response. Segments can be very large if they include all company employees, for example.

Methods

Start

Make an initial request for changes and start polling for raw configuration data every pollingRateSeconds:

poller.Start()

Stop

To stop the poller:

poller.Stop()

The poller sends an error message to poller.Error channel when getting errors from the Split.io API.

GetSerializedData

GetSerializedData will read the latest data from the cache and return a script that adds serialized data to the window.__splitCachePreload object. The serialized data will be used to determine cohort allocations.

GetSerializedData accepts the following arguments:

Property Description
splitNames Array of strings that, if non-empty, filters the splitsData
serializedDataScript := poller.GetSerializedData([]string{})
fmt.Println(serializedDataScript)

//<script>
//  window.__splitCachePreload = {
//    splitsData: {
//      "split-1-name":"{\"name\":\"split-1-name\",\"status\":\"bar\"}",
//      "split-2-name":"{\"name\":\"split-2-name\",\"status\":\"baz\"}"
//    },
//    since: 1,
//    segmentsData: {
//       "test-segment":"{\"name\":\"test-segment\",\"added\":[\"foo\",\"bar\"],\"removed\":null,\"since\":20,\"till\":20}"
//    },
//    usingSegmentsCount: 2
//  }
//</script>

serializedDataScript = poller.GetSerializedData([]string{"split-1-name"})
fmt.Println(serializedDataScript)

//<script>
//  window.__splitCachePreload = {
//    splitsData: {
//      "split-1-name":"{\"name\":\"split-1-name\",\"status\":\"bar\"}"
//    },
//    since: 1,
//    segmentsData: {
//       "test-segment":"{\"name\":\"test-segment\",\"added\":[\"foo\",\"bar\"],\"removed\":null,\"since\":20,\"till\":20}"
//    },
//    usingSegmentsCount: 2
//  }
//</script>

Testing

Use this script to run linting, vetting, unit tests, and coverage check:

$ ./scripts/test.sh

After running the above script, run this script to generate coverage HTML file:

$ ./scripts/coverage-html.sh cover.out > coverage.html

This HTML file is useful because it highlights exact lines of code that aren't covered by tests.

Module Versioning

We utilize git-chglog to maintain our CHANGELOG. Please follow these steps on the master branch of this repository to update the Go module version with changes made since the prior version.

  1. Ensure git-chglog is installed correctly: docs
  2. Fetch all version tags
    $ git fetch --tags
    
  3. Tag with the new version based on semvar conventions
    $ git tag v{MAJOR}.{MINOR}.{PATCH}
    
  4. Run git-chglog to generate new CHANGELOG.md file
    $ git-chglog -o CHANGELOG.md
    
  5. Stage and commit changes to the CHANGELOG
  6. Re-tag to accomodate commit created in the previous step
    $ git tag -d v{MAJOR}.{MINOR}.{PATCH}
    $ git tag v{MAJOR}.{MINOR}.{PATCH}
    
  7. Push to origin tag and origin master
    $ git push origin v{MAJOR}.{MINOR}.{PATCH}
    $ git push origin master
    

License

MIT

split-go-serializer's People

Contributors

agerard-godaddy avatar celiawaggoner avatar cwaggoner-godaddy avatar pchiang-godaddy avatar silasbw avatar stevemcquaid avatar wendychiang avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

stevemcquaid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.