Go SDK
Official Go client. Idiomatic: context.Context first, errors as
values, options pattern. Zero deps beyond the standard library.
Install
go get github.com/oligon/receipts-goRequires Go 1.22+.
Quickstart
package main
import (
"context"
"fmt"
"log"
"os"
oligon "github.com/oligon/receipts-go"
)
func main() {
client := oligon.NewClient(os.Getenv("OLIGON_API_KEY"))
f, err := os.Open("receipt.jpg")
if err != nil { log.Fatal(err) }
defer f.Close()
r, err := client.Extract(context.Background(), oligon.ExtractParams{
File: f, Type: oligon.ReceiptTypeNFe,
})
if err != nil { log.Fatal(err) }
fmt.Println(r.MerchantName, r.Total)
}Configuration (With… options)
| Option | Default | Description |
|---|---|---|
WithBaseURL(url) | https://api.receipts.oligontech.com | Override host. |
WithTimeout(d) | 30s | Per-request timeout. |
WithMaxRetries(n) | 5 | Auto-retries on 429/5xx. |
WithBackoff(min, max) | 300ms–8s | Exponential window. |
WithHTTPClient(c) | new client | Inject (proxies, mTLS, mocks). |
WithAPIKey(k) | — | When you prefer options-only. |
WithHeader(k,v) | — | Extra header on every request. |
Pagination
err := client.ListReceipts(ctx, oligon.ListReceiptsParams{
Type: oligon.ReceiptTypeNFe, Limit: 100,
}, func(r *oligon.Receipt) (bool, error) {
fmt.Println(r.ID)
return true, nil // false to stop early
})Or a single page with client.ListReceiptsPage(ctx, params).
Errors
import "errors"
r, err := client.Extract(ctx, params)
if err != nil {
var rate *oligon.RateLimitError
var auth *oligon.AuthError
switch {
case errors.As(err, &rate):
time.Sleep(rate.RetryAfter)
case errors.As(err, &auth):
rotateKey()
case oligon.IsRetryable(err):
// back off and retry yourself
default:
return err
}
}Webhook verification
ok := oligon.VerifyWebhook(rawBody, r.Header.Get("X-Oligon-Signature"), secret)Constant-time comparison via crypto/hmac.Equal.