Usage

Reference the Hop Go API client in your imports:

GO
import (
	hop "go.hop.io/sdk"
)

Once you run any Go command, the Go toolchain will fetch and install the SDK automatically.

Creating a Client Instance

To use the SDK, you must first create a project token. You can also use a PAT (personal access token), however this is not recommended as it has access to all of your projects.

GO
import (
	"context"
	"fmt"

	hop "go.hop.io/sdk"

	// types is a package that contains all of the types used by the Hop API
	// and other utility helper functions
 	t   "go.hop.io/sdk/types"
)

const HopToken = "ptk_xxx"

func main() {
	c, err := hop.NewClient(HopToken)
	if err != nil {
		// Handle your error here!
		panic(err)
	}

 	// Example: Creating a deployment
	deployment, err := c.Ignite.Deployments.Create(context.Background(), &t.DeploymentConfig{
		Name: "postgres",
		DeploymentConfigPartial: t.DeploymentConfigPartial{
			Type:              t.RuntimeTypePersistent,
			RestartPolicy:     t.RestartPolicyAlways,
			ContainerStrategy: t.ContainerStrategyManual,
			Image: t.Image{
				Name: "postgres",
			},
			Resources: t.Resources{
				VCPU: 0.5,

				// Use the t.Megabytes helper function to convert
				// megabytes to a string
				RAM:  t.Megabytes(128),
			},
			Env: map[string]string{
				"POSTGRES_PASSWORD": "mysecretpassword",
				"POSTGRES_USER":     "postgres",
				"POSTGRES_DB":       "postgres",
			},
		},
	})

	if err != nil {
		panic(err)
	}

	fmt.Println(deployment)
}

Specifying the Project ID

If you do not use a project token, you must also specify the project ID. You can do this in 1 of 2 ways:

  1. You can set this at a client level:
GO
c.AddClientOptions(hop.WithProjectID("project_id"))
  1. You can set this at a request level:
GO
ch, err := c.Channels.Get(context.Background(), "test", hop.WithProjectID("project_id"))

hop-go will prefer options which are set at a functional level.