Docs / Go SDK

Go SDK

Official Go client for the Nitrozen.io changelog API.

pkg.go.dev GitHub

Installation

Requires Go 1.22 or later.

shell
go get github.com/nitrozenio/nitrozen-go

Quick Start

go
package main

import (
    "context"
    "fmt"

    nitrozen "github.com/nitrozenio/nitrozen-go"
)

func main() {
    cfg := nitrozen.NewConfiguration()
    client := nitrozen.NewAPIClient(cfg)
    ctx := context.WithValue(context.Background(), nitrozen.ContextAccessToken, "YOUR_API_TOKEN")

    // List your projects
    resp, _, err := client.ProjectsAPI.ProjectsGet(ctx).Execute()
    if err != nil {
        panic(err)
    }
    for _, p := range resp.Data {
        fmt.Printf("%d  %s  (%s)\n", p.GetId(), p.GetName(), p.GetSlug())
    }

    // Create a changelog entry
    input := nitrozen.NewEntryInput()
    input.SetTitle("New feature")
    input.SetContent("We shipped something great.")
    input.SetCategory("new")

    entry, _, err := client.EntriesAPI.
        ProjectsProjectEntriesPost(ctx, resp.Data[0].GetId()).
        EntryInput(*input).
        Execute()
    if err != nil {
        panic(err)
    }
    fmt.Println(entry.Data.GetTitle())
}

Authentication

Create an API token on the API Tokens page. Pass it via context.WithValue using the ContextAccessToken key:

go
cfg := nitrozen.NewConfiguration()
client := nitrozen.NewAPIClient(cfg)

// Attach the token via context — pass this ctx to every API call
ctx := context.WithValue(
    context.Background(),
    nitrozen.ContextAccessToken,
    "YOUR_API_TOKEN",
)

The context can be enriched with deadlines and cancellation as usual:

go
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

resp, _, err := client.UsersAPI.UserGet(ctx).Execute()

Error Handling

Every Execute() call returns (response, *http.Response, error). Cast the error to *nitrozen.GenericOpenAPIError to inspect the raw response body:

go
resp, httpResp, err := client.ProjectsAPI.ProjectsProjectGet(ctx, 999).Execute()
if err != nil {
    if apiErr, ok := err.(*nitrozen.GenericOpenAPIError); ok {
        fmt.Println(httpResp.StatusCode) // e.g. 404
        fmt.Println(string(apiErr.Body())) // raw JSON error body
    }
    return
}

Pagination

List endpoints accept .Page() and .PerPage() builder methods. The response includes a Meta field with pagination details:

go
resp, _, err := client.EntriesAPI.
    ProjectsProjectEntriesGet(ctx, projectId).
    Page(2).
    PerPage(20).
    Execute()
if err != nil {
    panic(err)
}

meta := resp.GetMeta()
fmt.Printf("page %d of %d  (%d total)\n",
    meta.GetCurrentPage(), meta.GetLastPage(), meta.GetTotal())

for _, e := range resp.Data {
    fmt.Printf("[%d] %s\n", e.GetId(), e.GetTitle())
}

API Reference

All methods follow the builder pattern ending with .Execute(). All URIs are relative to https://nitrozen.io/api/v1.

Authentication

Method HTTP Description
AuthenticationAPI.TokensGet(ctx).Execute()GET /tokensList API tokens
AuthenticationAPI.TokensPost(ctx).TokensPostRequest(r).Execute()POST /tokensCreate an API token
AuthenticationAPI.TokensTokenDelete(ctx, id).Execute()DELETE /tokens/{token}Revoke an API token

Projects

Method HTTP Description
ProjectsAPI.ProjectsGet(ctx).Execute()GET /projectsList projects
ProjectsAPI.ProjectsPost(ctx).ProjectInput(p).Execute()POST /projectsCreate a project
ProjectsAPI.ProjectsProjectGet(ctx, id).Execute()GET /projects/{project}Get a project
ProjectsAPI.ProjectsProjectPut(ctx, id).ProjectInput(p).Execute()PUT /projects/{project}Update a project
ProjectsAPI.ProjectsProjectDelete(ctx, id).Execute()DELETE /projects/{project}Delete a project

Entries

Method HTTP Description
EntriesAPI.ProjectsProjectEntriesGet(ctx, id).Page(n).PerPage(n).Execute()GET /projects/{project}/entriesList entries
EntriesAPI.ProjectsProjectEntriesPost(ctx, id).EntryInput(e).Execute()POST /projects/{project}/entriesCreate an entry
EntriesAPI.ProjectsProjectEntriesEntryGet(ctx, pid, eid).Execute()GET …/entries/{entry}Get an entry
EntriesAPI.ProjectsProjectEntriesEntryPut(ctx, pid, eid).EntryInput(e).Execute()PUT …/entries/{entry}Update an entry
EntriesAPI.ProjectsProjectEntriesEntryDelete(ctx, pid, eid).Execute()DELETE …/entries/{entry}Delete an entry

Users

Method HTTP Description
UsersAPI.UserGet(ctx).Execute()GET /userGet current user
UsersAPI.UserUsageGet(ctx).Execute()GET /user/usageGet usage statistics

Public

Method HTTP Description
PublicAPI.PublicProjectsSlugEntriesGet(ctx, slug).Execute()GET /public/projects/{slug}/entriesList published entries (no auth)
Every project starts with these built-in category values: new improvement fix announcement Projects on a plan with custom categories enabled can define additional category slugs from the dashboard — any of those slugs are valid here too.