Go
Overview
Go client for Bannerify
Get started with our Go SDK, bannerify-go, for a typed and efficient experience. This SDK allows you to interact with our API without having to make HTTP requests directly.
Install
Install via Go modules:
go get github.com/bannerify/bannerify-go
Instantiate
If you want to use SDK, you will need your API key — you can create a new one in the settings.
package main
import (
"github.com/bannerify/bannerify-go"
)
func main() {
client := bannerify.NewBannerifyClient("your-api-key")
}
Response format
To make error handling explicit and prevent forgotten error checks, we return errors as part of the response structure. Every method returns a Response struct with either a Result or an Error field, never both and never none.
type Response struct {
Result interface{} // The result (e.g., []byte for image data)
Error *ErrorResponse
}type ErrorResponse struct {
Error struct {
Code string // Machine readable error code
Message string // Human readable message
Docs string // Link to documentation
}
}Checking for errors
To check for errors, use the Error field in the response:
package main
import (
"context"
"fmt"
"os"
"github.com/bannerify/bannerify-go"
)
func main() {
client := bannerify.NewBannerifyClient("your-api-key")
result := client.CreateImage(context.Background(), "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
Modifications: []bannerify.Modification{
{Name: "title", Text: "Hello World"},
},
})
if result.Error != nil {
// Handle error
fmt.Printf("Error: %s\n", result.Error.Error.Message)
return
}
// Process result
imageData := result.Result.([]byte)
os.WriteFile("output.png", imageData, 0644)
}
Options
The client accepts options to customize the behavior:
API Key
client := bannerify.NewBannerifyClient("my-api-key")
Custom Configuration
import "github.com/bannerify/bannerify-go/option"
client := bannerify.NewBannerifyClient("my-api-key",
option.WithBaseURL("https://api.bannerify.co"),
option.WithMaxRetries(3),
)
Examples
Generate PNG Image
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
Modifications: []bannerify.Modification{
{Name: "title", Text: "Hello World"},
{Name: "subtitle", Text: "From Go SDK"},
},
})
if result.Error == nil {
imageData := result.Result.([]byte)
os.WriteFile("output.png", imageData, 0644)
}
Generate WebP Image
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
Format: "webp",
Modifications: []bannerify.Modification{
{Name: "title", Text: "Hello WebP"},
},
})
if result.Error == nil {
webpData := result.Result.([]byte)
os.WriteFile("output.webp", webpData, 0644)
}
Generate Signed URL
signedURL, err := client.GenerateImageSignedURL("tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
Modifications: []bannerify.Modification{
{Name: "title", Text: "Dynamic Title"},
},
})
if err == nil {
fmt.Printf("<img src='%s' alt='Generated Image' />", signedURL)
}