segops

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 9 Imported by: 0

README

SegOps Go SDK

Behavioral segmentation SDK for Go services.

Install

go get github.com/segops/sdk-go

Usage

The Go SDK is server-side and authenticates directly with a secret key (sk_…). Public keys and the browser session handshake are intended for client SDKs (browser, iOS, Android); a Go service should use a secret key kept in its environment.

import "github.com/segops/sdk-go"

client := segops.New(segops.Options{
    APIURL: "https://api.segops.ai",
    APIKey: "sk_...",
})

client.Track(segops.Event{
    UserID:    "u-123",
    EventType: "order_placed",
    Payload:   map[string]any{"total": 42},
})

// On shutdown (flushes pending events):
client.Shutdown(context.Background())

License

MIT

Documentation

Overview

Package segops is the official Go SDK for SegOps behavioral segmentation.

Usage:

client := segops.New(segops.Options{
    APIURL: "https://api.segops.ai",
    APIKey: "sk_...",
})
defer client.Shutdown(context.Background())

client.Track(segops.Event{
    UserID:    "user-123",
    EventType: "page_viewed",
    Payload:   map[string]any{"path": "/home"},
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client sends user events to SegOps asynchronously. All methods are safe for concurrent use.

func New

func New(opts Options) *Client

New creates and starts a SegOps client with the given options. Call Shutdown when the process exits to flush remaining events.

func (*Client) Flush

func (c *Client) Flush(ctx context.Context) error

Flush sends all buffered events immediately. Blocks until complete.

func (*Client) Identify

func (c *Client) Identify(ctx Context)

Identify records user trait updates as a context_identified event.

func (*Client) Shutdown

func (c *Client) Shutdown(ctx context.Context) error

Shutdown flushes remaining events and stops the background goroutine. Always call this before the process exits.

func (*Client) Track

func (c *Client) Track(e Event)

Track enqueues a user event. The event is sent in the background.

type Context

type Context struct {
	UserID string         `json:"user_id"`
	Traits map[string]any `json:"traits"`
}

Context represents a user identity / trait update. It is translated to a context_identified event.

type Event

type Event struct {
	UserID     string         `json:"user_id"`
	EventType  string         `json:"event_type"`
	OccurredAt string         `json:"occurred_at,omitempty"` // RFC3339; defaults to now
	Payload    map[string]any `json:"payload,omitempty"`
}

Event is a single user event in the canonical SegOps schema.

type Options

type Options struct {
	// APIURL is the base URL of your SegOps deployment, e.g. "https://api.segops.ai".
	APIURL string
	// APIKey is the API key with ingest permission (sk_…).
	APIKey string
	// BatchSize is the maximum number of events queued before an automatic flush. Default: 20.
	BatchSize int
	// FlushEvery is the periodic flush interval. Default: 5s.
	FlushEvery time.Duration
	// MaxRetries is the number of retry attempts on transient failures. Default: 3.
	MaxRetries int
	// Logger is used for error output. Defaults to the standard logger.
	Logger *log.Logger
}

Options configures the SegOps client.

Jump to

Keyboard shortcuts

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