keen

package module
v0.0.0-...-f7cb123 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2017 License: MIT Imports: 6 Imported by: 6

README

Keen IO golang client SDK godoc reference

Community-Supported SDK

This is an unofficial community supported SDK. If you find any issues or have a request please post an issue.

API Stability

The master branch has no API stability guarantees. You can import the latest stable API with:

import "gopkg.in/inconshreveable/go-keen.v0"

Writing Events

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, especially querying data.

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Timestamp

func Timestamp(t time.Time) string

Timestamp formats a time.Time object in the ISO-8601 format keen expects

Types

type BatchClient

type BatchClient struct {
	*Client
	// contains filtered or unexported fields
}

func NewBatchClient

func NewBatchClient(client *Client, flushInterval time.Duration) *BatchClient

func (*BatchClient) AddEvent

func (c *BatchClient) AddEvent(collection string, event interface{}) error

func (*BatchClient) Flush

func (c *BatchClient) Flush()

type Client

type Client struct {
	WriteKey   string
	ProjectID  string
	HttpClient http.Client
}

func (*Client) AddEvent

func (c *Client) AddEvent(collection string, event interface{}) error

func (*Client) AddEvents

func (c *Client) AddEvents(events map[string][]interface{}) error

type KeenProperties

type KeenProperties struct {
	Timestamp string `json:"timestamp"`
}

Jump to

Keyboard shortcuts

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