Skip to content

matzhouse/go-keen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

go-keen: A Keen IO client SDK in Go

This is the very beginnings of a Keen IO client SDK in Go. Currently, only adding events to collections is supported.

The simplest API is to create a client object and then call AddEvent:

package main

import (
        "github.com/inconshreveable/go-keen"
)

type ExampleEvent struct {
        UserId int
        Amount int
        Type string
        Tags []string
}

func main() {
        keenClient := &keen.Client{ ApiKey: "XXX", ProjectToken: "XXX" }
        keenClient.AddEvent("collection_name", &ExampleEvent{
                UserId: 102,
                Amount: 39,
                Type: "ball",
                Tags: []string{ "red", "bouncy" },
        })
}

Batch event reporting

For production use, it makes more sense to add events to an internal buffer which is flushed to Keen at a regular interval in a single batch upload call. The go-keen library provides a BatchClient which allows you to do just that while keeping the same, simple API for adding events. Do note that it does mean that you could lose events if your program exits or crashes before it flushes the events to Keen.

package main

import (
        "github.com/inconshreveable/go-keen"
        "time"
)

const keenFlushInterval = 10 * time.Second

type ExampleEvent struct {
        UserId int
        Amount int
        Type string
        Tags []string
}

func main() {
        keenClient := &keen.Client{ ApiKey: "XXX", ProjectToken: "XXX" }
        keenBatchClient := keen.NewBatchClient(keenClient, keenFlushInterval)
        keenBatchClient.AddEvent("collection_name", &ExampleEvent{
            UserId: 102,
            Amount: 39,
            Type: "ball",
            Tags: []string{ "red", "bouncy" },
        })
}

TODO

Add support for all other Keen IO API endpoints, espeically querying data.

About

Keen IO Client SDK in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published