Puchify

Go SDK

Zero-dependency Go SDK for infrastructure tooling and provider integrations.

Module: github.com/puchify/puchify-go

go get github.com/puchify/puchify-go

Quick start

package main

import (
    "context"
    "fmt"
    "github.com/puchify/puchify-go"
)

func main() {
    client := puchify.NewClient(
        puchify.WithAPIKey("pk_xxxx"),
    )

    servers, err := client.Servers.List(context.Background(), &puchify.ServerListParams{
        Status: puchify.String("running"),
    })
    if err != nil { panic(err) }

    for _, s := range servers.Items {
        fmt.Printf("%s: %s\n", s.Name, *s.IPv4)
    }
}

Resources

Servers

// List
list, err := client.Servers.List(ctx, &puchify.ServerListParams{Limit: 100})

// CRUD
server, err := client.Servers.Get(ctx, "svr_123")
created, err := client.Servers.Create(ctx, &puchify.CreateServerInput{
    Name: "web-01", Plan: "shared-2", Region: "us-east",
})
client.Servers.Update(ctx, "svr_123", &puchify.UpdateServerInput{Name: "renamed"})
client.Servers.Delete(ctx, "svr_123")

// Actions
client.Servers.Restart(ctx, "svr_123")
client.Servers.Destroy(ctx, "svr_123")

Pagination

paginator := puchify.NewPaginator(
    func(cursor string) (*puchify.ServerListResponse, error) {
        return client.Servers.List(ctx, &puchify.ServerListParams{
            Cursor: &cursor, Limit: 100,
        })
    },
)

for paginator.Next(ctx) {
    fmt.Println(paginator.Item().Name)
}
if err := paginator.Err(); err != nil { panic(err) }

Wait for state

server, err := puchify.WaitFor(ctx, client.Servers.Get, "svr_123", "running",
    puchify.WithTimeout(5*time.Minute),
    puchify.WithPollInterval(5*time.Second),
)

Retry

result, err := puchify.DoWithRetry(ctx, func(ctx context.Context) (string, error) {
    s, err := client.Servers.Get(ctx, "svr_123")
    return s.Name, err
}, puchify.WithMaxAttempts(5))

Client options

client := puchify.NewClient("pk_xxxx",
    puchify.WithBaseURL("https://api.puchify.com"),
    puchify.WithTimeout(30*time.Second),
    puchify.WithHTTPClient(&http.Client{Timeout: 10 * time.Second}),
)

Typed errors

server, err := client.Servers.Get(ctx, "bad-id")
if errors.Is(err, puchify.ErrNotFound) {
    // handle 404
}

On this page