Go
Official Go client for the Zernio API. Install zernio-go and publish to 14+ social platforms with context-first, builder-style requests.
The official Go client for the Zernio API. Requests are context-first and built fluently, so timeouts and cancellation work the way Go code expects.
- Module:
github.com/zernio-dev/zernio-go - Source: github.com/zernio-dev/zernio-go
Install
go get github.com/zernio-dev/zernio-goUpgrading from v0.0.x? v0.1.0 switches to a new code generator and is a breaking change. The import path is unchanged, but client construction and method calls differ. See MIGRATION.md.
Quick start
Authentication uses your Bearer API key, passed through the request context:
package main
import (
"context"
"fmt"
"log"
"os"
zernio "github.com/zernio-dev/zernio-go/zernio"
)
func main() {
// Defaults to the https://zernio.com/api base URL.
client := zernio.NewAPIClient(zernio.NewConfiguration())
// Authenticate with your Bearer API key via the request context.
ctx := context.WithValue(context.Background(), zernio.ContextAccessToken, os.Getenv("ZERNIO_API_KEY"))
// List connected accounts
accounts, _, err := client.AccountsAPI.ListAccounts(ctx).Execute()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Accounts: %+v\n", accounts)
}Get your API key from the dashboard, or see Getting started for the full setup walkthrough.
Create a post
Request bodies are built with typed models and setters:
req := zernio.NewCreatePostRequest()
req.SetContent("Hello world from Zernio!")
req.SetPublishNow(true)
req.SetPlatforms([]zernio.CreatePostRequestPlatformsInner{
*zernio.NewCreatePostRequestPlatformsInner("twitter", "acc_xxx"),
*zernio.NewCreatePostRequestPlatformsInner("linkedin", "acc_yyy"),
})
post, _, err := client.PostsAPI.CreatePost(ctx).
CreatePostRequest(*req).
Execute()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created post: %+v\n", post)For safe retries, CreatePost also accepts an idempotency key via .XRequestId("<uuid>"). Requests that reuse the same ID within ~5 minutes return the original post instead of double-posting.
Error handling
Failed calls return a *zernio.GenericOpenAPIError carrying the raw response body:
post, httpRes, err := client.PostsAPI.CreatePost(ctx).CreatePostRequest(*req).Execute()
if err != nil {
var apiErr *zernio.GenericOpenAPIError
if errors.As(err, &apiErr) {
log.Printf("API error (status %d): %s", httpRes.StatusCode, string(apiErr.Body()))
} else {
log.Printf("transport error: %v", err)
}
return
}See the error handling guide for the API's error codes and retry semantics.
Full reference
The client exposes every API namespace as a service: PostsAPI, AccountsAPI, ProfilesAPI, AnalyticsAPI, QueueAPI, MediaAPI, WebhooksAPI, MessagesAPI, AdsAPI, PhoneNumbersAPI, WhatsAppAPI, WorkflowsAPI, and more. Each method maps 1:1 to an API Reference operation.