VoidhashDocs
DocumentationAPI reference
Dashboard
Get started
Introduction
Quickstart
Setup
Setup overview
Create a project
Products and perks
Paywall locations
CLI
Paywall components
Components
Develop a component
Editor panels
Component definition
Publishing
Installing and capabilities
SDKs
Swift
Kotlin
React Native
Web
Store setup
Connect the App Store
Connect Google Play
Connect Stripe
Record payments from other sources
API libraries
Node.js
PHP
Rust
Go
Resources
MCP server
Ad measurement
Meta ads
Migrate in observer mode
Delete a person's data
Go library
Check access from your backend
Receive webhooks
Custom payment providers

Go library

A server-side client for the Voidhash REST API.

The mobile SDKs decide what to show on the device. They cannot protect anything a customer can reach by calling your API directly, such as an export endpoint or a paid model. Those checks belong on your server, and this library is how you make them.

voidhash-go is a client for the Voidhash REST API. It authenticates every request with a project secret key, and acts on the project the key belongs to.

Install the module

Add the module to your project with go get.

go get github.com/voidhashcom/voidhash-go

The module needs Go 1.22 or newer. The client uses only the standard library net/http, so there is no cgo and no extra dependencies.

Create a secret key

In Studio, open Settings → API keys and create a secret key. The raw value is shown only once.

Store the key in an environment variable or your secret manager. A secret key grants full access to the project. Never put it in a mobile app, a web bundle, or a repository.

Create the client

Create one client with your secret key at startup.

server/voidhash.go
import "github.com/voidhashcom/voidhash-go"

client, err := voidhash.New(os.Getenv("VOIDHASH_SECRET_KEY"))
if err != nil {
    log.Fatalf("create voidhash client: %v", err)
}

The client is configured through New and functional options.

OptionDefaultDescription
New(secretKey)noneRequired. The client sends it as Authorization: Bearer <secretKey>.
WithProjectID(id)the key's projectThe project every call acts on. Set it to skip looking it up.
WithBaseURL(url)https://api.voidhash.comOverrides the API origin. The scheme must be http: or https:.
WithHeader(key, value)noneAdds an extra header to every request from this client.

New validates its input right away rather than on the first request, and makes no request itself. It returns an error when the secret key is blank or WithHeader was given Authorization or x-secret-key in any casing.

A secret key belongs to one project, so you never pass the project's id to a method. Without WithProjectID, the client reads the key's project from GET /api/v1/session on the first call that needs it and keeps it for the client's lifetime. When the credential can use several projects, set WithProjectID; otherwise those calls return an error saying so.

The client is safe for concurrent use. Create one at startup and share it across your handlers.

With the client configured, continue with checking access or receiving webhooks.

Resource methods

Each API resource is a service on the client, and the services mirror the API reference. Every method takes a context.Context as its first argument. The example below checks a perk through the Persons.Entitlements service.

hasPremium, err := client.Persons.Entitlements.HasActivePerk(ctx, voidhash.HasActivePerkParams{
    DistinctID: "user_123",
    PerkSlug:   "premium",
})

Responses are typed structs generated from the API schemas, and optional fields are pointers.

PreviousCustom payment providersNextCheck access from your backend

On this page

Install the moduleCreate a secret keyCreate the clientResource methods