genality

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

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

Go to latest
Published: Dec 25, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

genality

General analytics solution provided as a library or service.

Usage

package main

import (
	"context"
	"log"
	"time"

	"github.com/infiniteloopcloud/genality"
)

func main() {
	var connectionString = "postgres://genality:genality@localhost:5435/genality?sslmode=disable"
	var ctx = context.Background()
	// create new instance
	instance, _ := genality.New(genality.Opts{ConnectionString: connectionString})
	// handle err

	instance.Add(ctx, "random_record")

	// get apikey useage in a time period
	cnt, _ := instance.GetCountFrom(ctx, "random_record", time.Now().Add(-24*time.Hour))
	// handle err
	log.Print(cnt)

	// get certain buckets, where every bucket stores the corresponding count(apikey)
	res, _ := instance.GetCountBuckets(ctx, "random_record", time.Now().Add(-24*time.Hour), time.Hour)
	// handle err
	log.Print(res)
	// returns something like this:
    // [
    //      { bucket: 2021-11-19 04:00:00 +0000 UTC, count: 2 }
    //      { bucket: 2021-11-19 05:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 06:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 07:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 08:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 09:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 10:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 11:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 12:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 13:00:00 +0000 UTC, count: 4 }
    //      { bucket: 2021-11-19 14:00:00 +0000 UTC, count: 102 }
    // ]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketResponse

type BucketResponse struct {
	Bucket time.Time `json:"bucket"`
	Count  uint      `json:"count"`
}

type Descriptor

type Descriptor interface {
	Add(ctx context.Context, apiKey string) error
	GetCountFrom(ctx context.Context, record string, start time.Time) (int, error)
	GetCountBuckets(ctx context.Context, record string, start time.Time, bucketSize time.Duration) ([]BucketResponse, error)
}

func New

func New(opts Opts) (Descriptor, error)

type Opts

type Opts struct {
	ConnectionString string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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