Skip to content
/ evenq-go Public

Easily send events and query data with this official Golang client for evenq.io

License

Notifications You must be signed in to change notification settings

evenq/evenq-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc Go Report Card

The official Evenq client for go

Installation

go get github.com/evenq/evenq-go

Full Example

package main

import "github.com/evenq/evenq-go"

func init() {
  // Initialize the Evenq client with your API key.
  evenq.Init(evenq.Options{
    ApiKey: "YOUR_API_KEY"
  })
}

func main() {
  // Send an event with any JSON data
  evenq.Event("hello.world", evenq.Data{
    "string": "hello world",
    "number": 42,
    "boolean": true
  })
  
  // Query your data. Keep in mind that if you just sent your first event,
  // it can take up to a minute until you can query your data
  res, err := evenq.Query([]QueryRequest{
    {
        ID: "test.event",
        From:    time.Now().UTC().Add(-time.Hour * 24),
        To:      time.Now().UTC(),
        Items: []Item{
            {
                Type:        TypeNumber,
                Aggregation: AggCount,
            },
        },
    },
  })
  
  if err != nil {
    panic(err)
  }
    
  js, _ := json.MarshalIndent(res, "", " ")
  log.Println(string(js))
}

Setup

Initialize with your API key before sending events. You'll only have to do this once in your app lifecycle.

evenq.Init(evenq.Options{
    ApiKey:       "YOUR_API_KEY",
    MaxBatchSize: 500,   
    MaxBatchWait: 5,    
    BatchWorkers: 1,     
    Verbose:      true, 
})

Send events

Send a single event with any data in map[string]interface{} format.

// event timestamped to current time
evenq.Event("your.event", evenq.Data{})

// event with custom timestamp
evenq.EventAt("your.event", time.Now(), evenq.Data{})

... Or send an event with a partition key if you want to split up your data.

// event with partition key timestamped to current time
evenq.PartitionedEvent("eventName", "somePartition", evenq.Data)

// event with partition key and custom timestamp
evenq.PartitionedEventAt("eventName", "somePartition", time.Now(), evenq.Data)

For more info on naming conventions and examples check out our docs at https://app.evenq.io/docs

Query Events

You can query your data easily with your query helper.

  // Query your data. Keep in mind that if you just sent your first event,
  // it can take up to a minute until you can query your data
  res, err := evenq.Query([]QueryRequest{
    {
        ID: "test.event",
        From:    time.Now().UTC().Add(-time.Hour * 24),
        To:      time.Now().UTC(),
        Items: []Item{
            {
                Type:        TypeNumber,
                Aggregation: AggCount,
            },
        },
    },
  })
  
  if err != nil {
    panic(err)
  }
    
  js, _ := json.MarshalIndent(res, "", " ")
  log.Println(string(js))
}

About

Easily send events and query data with this official Golang client for evenq.io

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages