Home
Softono
axiom-go

axiom-go

Open source MIT Go
71
Stars
13
Forks
15
Issues
10
Watchers
1 week
Last Commit

About axiom-go

Official Go bindings for the Axiom API

Platforms

Web Self-hosted

Languages

Go

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")
    }

    for row := range res.Tables[0].Rows() {
      _, _ = fmt.Println(row)
    }
}

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.

Edge Ingestion

For improved data locality, you can configure the client to use regional edge endpoints for ingest and query operations. All other API operations continue to use the main Axiom API endpoint.

// Using a regional edge domain
client, err := axiom.NewClient(
    axiom.SetEdge("eu-central-1.aws.edge.axiom.co"),
)

// Or using an explicit edge URL
client, err := axiom.NewClient(
    axiom.SetEdgeURL("https://custom-edge.example.com"),
)

You can also configure via environment variables:

  • AXIOM_EDGE - Regional edge domain (e.g., eu-central-1.aws.edge.axiom.co)
  • AXIOM_EDGE_URL - Explicit edge URL (takes precedence over AXIOM_EDGE)

Note: Edge endpoints require API tokens (xaat-), not personal tokens.

Install

go get github.com/axiomhq/axiom-go

Documentation

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

License

MIT