Go Client
The Go client talks to the API over gRPC. Source: github.com/enumco/client-go.
Install
Section titled “Install”go get github.com/enumco/client-gopackage main
import ( "context" "fmt" "log" "os"
client "github.com/enumco/client-go" apiv1 "github.com/enumco/proto-gen-go/gen/enum/api/v1")
func main() { c, err := client.New(client.WithToken(os.Getenv("ENUM_TOKEN"))) if err != nil { log.Fatal(err) } defer c.Close()
resp, err := c.DNS.ListZones(context.Background(), &apiv1.ListZonesRequest{ ProjectId: "proj-01kmyy3t719crcnrrvk1mgyjd0", }) if err != nil { log.Fatal(err) }
for _, zone := range resp.GetZones() { fmt.Println(zone.GetName()) }}See Authentication for how to get a token.
Options
Section titled “Options”| Option | Description |
|---|---|
WithToken(token) | API token sent with every request |
WithAddr(addr) | API endpoint. Default: api.enum.co:443 |
WithTLS(creds) | Custom TLS configuration. Default: system root certificates |
Services
Section titled “Services”| Field | Service |
|---|---|
c.Organizations | OrganizationService |
c.Projects | ProjectService |
c.Users | UserService |
c.Regions | RegionService |
c.DNS | DnsService |
c.Kubernetes.Clusters | KubernetesClusterService |
c.Storage.Users | ObjectStorageUserService |
c.Storage.AccessKeys | ObjectStorageAccessKeyService |
c.Storage.Buckets | ObjectStorageBucketService |
c.Storage.Policies | ObjectStorageUserPolicyService |
c.ServiceAccounts | ServiceAccountService |
Each field is a generated gRPC client. The API reference lists the methods and fields.
Errors
Section titled “Errors”Errors are gRPC status errors. Check the code with status.Code:
import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status")
_, err := c.DNS.GetZone(ctx, req)if status.Code(err) == codes.NotFound { // ...}