Title here
Summary here
The bouine Go SDK (pkg/bouineapi) provides typed methods for every
admin API endpoint. It shares wire types with the Cobra CLI and the
admin server, so there is no drift between the SDK and the API.
go get github.com/bouine-cache/bouine/pkg/bouineapi@latestpackage main
import (
"context"
"fmt"
"log"
"github.com/bouine-cache/bouine/pkg/api"
"github.com/bouine-cache/bouine/pkg/bouineapi"
)
func main() {
c := bouineapi.New("http://127.0.0.1:9000").WithToken("your-token")
ctx := context.Background()
// Health check
health, err := c.Healthz(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println("health:", health.Status)
// Purge a URL
result, err := c.Purge(ctx, "https://example.com/page")
if err != nil {
log.Fatal(err)
}
fmt.Println("purge:", result.Status)
}// Liveness probe
health, err := c.Healthz(ctx)
// Readiness probe
ready, err := c.Readyz(ctx)
// Build version
version, err := c.Version(ctx)
// List cluster peers
peers, err := c.Peers(ctx)// Purge a single URL
result, err := c.Purge(ctx, "https://example.com/page")
// Purge multiple URLs (max 1000 per batch)
batch, err := c.BatchPurge(ctx, []string{
"https://example.com/page1",
"https://example.com/page2",
})
// Ban by predicate (host and/or path regex, surrogate key)
ban, err := c.Ban(ctx, api.BanExpr{
HostRegex: "example.com",
PathRegex: "^/api/",
})
// Soft-purge (mark stale, revalidate on next request)
refresh, err := c.Refresh(ctx, "https://example.com/page")// Verify the admin token is valid
err := c.AuthCheck(ctx)c := bouineapi.New("http://127.0.0.1:9000").WithToken("your-token")WithToken returns a copy of the client with the token set. The
original is not mutated.
c := &bouineapi.Client{
BaseURL: "http://127.0.0.1:9000",
Token: "your-token",
HTTPClient: &http.Client{Timeout: 30 * time.Second},
}If HTTPClient is nil, a default client with a 10s timeout is used.
Non-2xx responses return an error containing the HTTP method, path, status code, and a sanitized body:
bouineapi: POST /v1/purge: status 401: unauthorizedcontext.Context for cancellation and timeouts.result, err := c.Purge(ctx, "https://example.com/page")
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
// context deadline hit
}
// other error
log.Fatal(err)
}A formal OpenAPI 3.0 specification is available at
api/openapi.yaml
in the repository. Use it with openapi-generator to produce SDKs
in Python, TypeScript, and other languages.