zchpc-go
The Go client for ZCHPC: rent GPU slices,
and provision managed databases, caches and S3-compatible media buckets.
go get github.com/movella-systems/zchpc-go
Rent a GPU
Use destroys the rental on the way out, including when your callback returns
an error. A GPU bills by the second, and the usual way a box gets left running
is a failure between renting it and destroying it.
z := zchpc.New("gpv_YOUR_API_KEY") // or set ZCHPC_API_KEY
err := z.GPUs.Use(ctx, zchpc.RentSpec{GPUMemGB: 8, Hours: 1},
func(gpu *zchpc.Instance) error {
info, err := gpu.GPUInfo()
fmt.Println(info) // Tesla V100S-PCIE-32GB, 32768 MiB, 0 MiB
return err
})
Databases, caches and buckets
Go has no optional dependencies, so this client stops at the connection
details rather than pulling pgx, go-redis and aws-sdk into every build that
imports it. What it hands back is standard, so your usual driver takes it
unchanged.
db, _ := z.Databases.Create(ctx, zchpc.DatabaseSpec{Name: "notes"})
db, _ = db.Wait(ctx)
conn, _ := pgx.Connect(ctx, db.URI) // password already in the URI
For buckets, set path-style addressing. Amazon puts the bucket in the hostname
and every SDK defaults to that, but this endpoint serves buckets as a path.
b, _ := z.Buckets.Create(ctx, "media", zchpc.BucketSpec{})
client := s3.New(s3.Options{
BaseEndpoint: aws.String(b.EndpointURL()),
Credentials: credentials.NewStaticCredentialsProvider(b.AccessKey, b.SecretKey, ""),
UsePathStyle: true,
})
Errors
Typed by what you can do about them, so errors.Is is enough:
ErrAuth, ErrInsufficientCredit, ErrLimitReached, ErrNotFound,
ErrProvisioning, ErrWaitTimeout.
License
MIT