Skip to content

Official Go bindings for the Axiom API

License

Notifications You must be signed in to change notification settings

axiomhq/axiom-go

Folders and files

NameName
Last commit message
Last commit date
Feb 13, 2025
Jan 27, 2025
Mar 7, 2025
Jan 27, 2025
Feb 21, 2024
Sep 8, 2021
Sep 9, 2024
Sep 9, 2024
Feb 16, 2023
Sep 17, 2024
Nov 12, 2024
Sep 19, 2023
Mar 18, 2025
Mar 18, 2025
Mar 19, 2022

Repository files navigation

axiom-go Go Reference Workflow Latest Release License

If you use the Axiom CLI, run eval $(axiom config export -f) to configure your environment variables.

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/axiomhq/axiom-go/axiom"
    "github.com/axiomhq/axiom-go/axiom/ingest"
)

func main() {
    ctx := context.Background()

    client, err := axiom.NewClient(
        // If you don't want to configure your client using the environment,
        // pass credentials explicitly:
        // axiom.SetToken("xaat-xyz"),
    )
    if err != nil {
        log.Fatal(err)
    }
    
    if _, err = client.IngestEvents(ctx, "my-dataset", []axiom.Event{
        {ingest.TimestampField: time.Now(), "foo": "bar"},
        {ingest.TimestampField: time.Now(), "bar": "foo"},
    }); err != nil {
        log.Fatal(err)
    }

    res, err := client.Query(ctx, "['my-dataset'] | where foo == 'bar' | limit 100")
    if err != nil {
        log.Fatal(err)
    } else if res.Status.RowsMatched == 0 {
        log.Fatal("No matches found")
    }

    rows := res.Tables[0].Rows()
    if err := rows.Range(ctx, func(_ context.Context, row query.Row) error {
        _, err := fmt.Println(row)
        return err
    }); err != nil {
        log.Fatal(err)
    }
}

For further examples, head over to the examples directory.

If you want to use a logging package, check if there is already an adapter in the adapters directory. We happily accept contributions for new adapters.

Install

go get github.com/axiomhq/axiom-go

Documentation

Read documentation on axiom.co/docs/guides/go.

License

MIT