hop

package module
v1.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 18 Imported by: 0

README

hop-go

View Hop Documentation | View Source Documentation

Hop's Go library. Requires Go 1.18+.

package main

import (
	"context"
	"fmt"

	"go.hop.io/sdk"
)

func main() {
	myToken := "ptk_xxx"
	c, err := hop.NewClient(myToken)
	if err != nil {
		// Handle errors how you wish here.
		panic(err)
	}

	s, err := c.Projects.Secrets.Create(
		context.Background(),
		"SECRET_NAME",
		"SECRET_VALUE",
		hop.WithProjectID("PROJECT_ID"), // If not using a project token, you will need to specify the project ID.
	)
	if err != nil {
		// Handle errors how you wish here.
		panic(err)
	}
	fmt.Println(s)
}

Client options (such as the project ID) can be set either at a client level like c.AddClientOptions(hop.WithProjectID("PROJECT_ID")) or at a functional level like shown above. If options are provided to the function, they override the client level option configuration.

Documentation

Index

Constants

View Source
const DefaultAPIBase = "https://api.hop.io/v1"

DefaultAPIBase is used to define the default base API URL.

View Source
const Version = "1.12.1"

Version is used to define a tagged version. This will be updated when a new version is released.

Variables

View Source
var IDPrefixes = []string{
	"user", "project", "pm", "role", "pi", "ptk", "pat", "container", "pipe_room", "deployment", "bearer",
	"ptkid", "secret", "gateway", "domain", "leap_token", "build", "rollout", "health_check", "session",
}

IDPrefixes are allowed ID prefixes.

Functions

func ValidateToken

func ValidateToken(authorization string) (string, error)

ValidateToken is used to validate a authentication token. Returns an error if the token is invalid.

Types

type Client

type Client struct {
	Pipe     *ClientCategoryPipe
	Projects *ClientCategoryProjects
	Ignite   *ClientCategoryIgnite
	Users    *ClientCategoryUsers
	Registry *ClientCategoryRegistry
	Channels *ClientCategoryChannels
	// contains filtered or unexported fields
}

Client is used to define the Hop client. Please use the NewClient function to create this!

func NewClient

func NewClient(authorization string, opts ...ClientOption) (*Client, error)

NewClient is used to make a new Hop client.

func (*Client) AddClientOptions

func (c *Client) AddClientOptions(opts ...ClientOption)

AddClientOptions is used to add any client options. These will be added before any others specified in functions.

func (*Client) SetAPIBase deprecated

func (c *Client) SetAPIBase(apiBase string) *Client

SetAPIBase is used to set the base API URL. This is probably something you do not need to use, however it is useful in testing the SDK. The base URL contains the domain and ends with /v1.

Deprecated: Use AddClientOptions with WithCustomAPIURL instead.

type ClientArgs added in v1.10.0

type ClientArgs struct {
	// Method is used to define the request method.
	Method string

	// Path is used to define the path (with the URL suffix including /api/vX removed).
	Path string

	// ResultKey is the key inside the "data" part of the JSON where the data is.
	ResultKey string

	// Query is any HTTP query parameters that should be sent.
	Query map[string]string

	// Body is the body to send. This should be json marshalled except for the PlainText type.
	Body any

	// Result is a pointer to where the result should be unmarshalled. Note that if this is nil, the
	// result body should be ignored.
	// *SPECIAL CASE:* If PassRequest is not nil, ignore this field and pass it to that.
	Result any

	// Ignore404 is whether a 404 should not be treated as an error.
	Ignore404 bool

	// PassRequest is a function used to pass a OK request to instead of closing it.
	// This is used for the filesystem since we need to pass around a context that constantly pulls more
	// information in some cases.
	PassRequest func(r *http.Response)
}

ClientArgs is used to define the arguments from the function to the client.

type ClientCategoryChannels

type ClientCategoryChannels struct {
	Tokens *ClientCategoryChannelsTokens
	// contains filtered or unexported fields
}

ClientCategoryChannels is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Channels.

func (ClientCategoryChannels) Create

func (c ClientCategoryChannels) Create(
	ctx context.Context, channelType types.ChannelType, state map[string]any, id string,
	opts ...ClientOption,
) (*types.Channel, error)

Create is used to create a channel. The channelType argument should be the type of channel that you want to create, state should be a map that you want to associate with the channel, and id should be the ID you wish to specify (oe a blank string if you wish for this to be auto-generated).

func (ClientCategoryChannels) Delete

func (c ClientCategoryChannels) Delete(ctx context.Context, id string, opts ...ClientOption) error

Delete is used to delete a channel.

func (ClientCategoryChannels) Get

Get is used to get a channel. Will throw types.NotFound if it was not found.

func (ClientCategoryChannels) GetAll

GetAll returns a paginator to get all the channels.

func (ClientCategoryChannels) GetStats

func (c ClientCategoryChannels) GetStats(ctx context.Context, id string, opts ...ClientOption) (*types.Stats, error)

GetStats is used to get the stats of a channel.

func (ClientCategoryChannels) PatchState

func (c ClientCategoryChannels) PatchState(ctx context.Context, id string, state map[string]any, opts ...ClientOption) error

PatchState is used to patch the state of a channel.

func (ClientCategoryChannels) PublishMessage

func (c ClientCategoryChannels) PublishMessage(ctx context.Context, channelId, eventName string, data any, opts ...ClientOption) error

PublishMessage is used to publish an event to the channel.

func (ClientCategoryChannels) SetState

func (c ClientCategoryChannels) SetState(ctx context.Context, id string, state map[string]any, opts ...ClientOption) error

SetState is used to set the state of a channel.

func (ClientCategoryChannels) SubscribeToken

func (c ClientCategoryChannels) SubscribeToken(ctx context.Context, channelId, token string, opts ...ClientOption) error

SubscribeToken is used to subscribe a token to a channel.

func (ClientCategoryChannels) SubscribeTokens

func (c ClientCategoryChannels) SubscribeTokens(ctx context.Context, channelId string, tokens []string, opts ...ClientOption) error

SubscribeTokens is used to subscribe many tokens to a channel.

type ClientCategoryChannelsTokens

type ClientCategoryChannelsTokens struct {
	// contains filtered or unexported fields
}

ClientCategoryChannelsTokens is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Channels.Tokens.

func (ClientCategoryChannelsTokens) Create

Create is used to create a new channel token. State is the map of the state of the token (this can be nil), and projectId is the project ID to associate the token with (this can be empty unless it is bearer or PAT auth).

func (ClientCategoryChannelsTokens) Delete

Delete is used to delete a channel token.

func (ClientCategoryChannelsTokens) Get

Get is used to get a token by its ID.

func (ClientCategoryChannelsTokens) GetAll

GetAll gets all the tokens.

func (ClientCategoryChannelsTokens) IsOnline

func (t ClientCategoryChannelsTokens) IsOnline(ctx context.Context, id string, opts ...ClientOption) (bool, error)

IsOnline is used to check if a token is online.

func (ClientCategoryChannelsTokens) PublishDirectMessage

func (t ClientCategoryChannelsTokens) PublishDirectMessage(
	ctx context.Context, id, eventName string, data any, opts ...ClientOption,
) error

PublishDirectMessage is used to publish an event to the channel token.

func (ClientCategoryChannelsTokens) SetState

func (t ClientCategoryChannelsTokens) SetState(ctx context.Context, id string, state map[string]any, opts ...ClientOption) error

SetState is used to set the state of a channel token.

type ClientCategoryIgnite

type ClientCategoryIgnite struct {
	Gateways    *ClientCategoryIgniteGateways
	Deployments *ClientCategoryIgniteDeployments
	Containers  *ClientCategoryIgniteContainers
	// contains filtered or unexported fields
}

ClientCategoryIgnite is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Ignite.

type ClientCategoryIgniteContainers

type ClientCategoryIgniteContainers struct {
	// contains filtered or unexported fields
}

ClientCategoryIgniteContainers is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Ignite.Containers.

func (ClientCategoryIgniteContainers) Create

func (c ClientCategoryIgniteContainers) Create(ctx context.Context, deploymentId string, opts ...ClientOption) (*types.Container, error)

Create is used to create a container.

func (ClientCategoryIgniteContainers) Delete

Delete is used to delete a container by its ID.

func (ClientCategoryIgniteContainers) DeleteAndRecreate added in v1.11.0

func (c ClientCategoryIgniteContainers) DeleteAndRecreate(ctx context.Context, id string, opts ...ClientOption) error

DeleteAndRecreate is used to delete a container by its ID and then recreate it. This is another function to avoid a breaking change.

func (ClientCategoryIgniteContainers) GetLogs

func (c ClientCategoryIgniteContainers) GetLogs(id string, limit int, ascOrder bool) *Paginator[*types.ContainerLog]

GetLogs is used to get a paginator for the logs of a container.

func (ClientCategoryIgniteContainers) Start

Start is used to start a container by its ID.

func (ClientCategoryIgniteContainers) Stop

Stop is used to stop a container by its ID.

type ClientCategoryIgniteDeployments

type ClientCategoryIgniteDeployments struct {
	// contains filtered or unexported fields
}

ClientCategoryIgniteDeployments is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Ignite.Deployments.

func (ClientCategoryIgniteDeployments) Create

Create is used to create a deployment.

func (ClientCategoryIgniteDeployments) CreateGateway

CreateGateway is used to create a gateway attached to a deployment.

func (ClientCategoryIgniteDeployments) Delete

Delete is used to delete a deployment by its ID.

func (ClientCategoryIgniteDeployments) DeleteHealthCheck added in v1.8.0

func (c ClientCategoryIgniteDeployments) DeleteHealthCheck(
	ctx context.Context, deploymentId, healthCheckId string, opts ...ClientOption,
) error

DeleteHealthCheck is used to delete a health check by its ID.

func (ClientCategoryIgniteDeployments) Get

Get is used to get a deployment by its ID.

func (ClientCategoryIgniteDeployments) GetAll

GetAll is used to get all deployments.

func (ClientCategoryIgniteDeployments) GetAllGateways

func (c ClientCategoryIgniteDeployments) GetAllGateways(ctx context.Context, id string, opts ...ClientOption) ([]*types.Gateway, error)

GetAllGateways is used to get all gateways attached to a deployment.

func (ClientCategoryIgniteDeployments) GetByName

GetByName is used to get a deployment by its name.

func (ClientCategoryIgniteDeployments) GetContainers

func (c ClientCategoryIgniteDeployments) GetContainers(ctx context.Context, id string, opts ...ClientOption) ([]*types.Container, error)

GetContainers is used to get the containers of a deployment.

func (ClientCategoryIgniteDeployments) GetHealthChecks added in v1.8.0

func (c ClientCategoryIgniteDeployments) GetHealthChecks(
	ctx context.Context, deploymentId string, opts ...ClientOption,
) ([]*types.HealthCheck, error)

GetHealthChecks is used to get the health checks attached to a deployment ID.

func (ClientCategoryIgniteDeployments) GetStorageStats added in v1.8.0

func (c ClientCategoryIgniteDeployments) GetStorageStats(
	ctx context.Context, deploymentId string, opts ...ClientOption,
) (types.DeploymentStorageInfo, error)

GetStorageStats is used to get stats about storage.

func (ClientCategoryIgniteDeployments) HealthCheckStates added in v1.8.0

func (c ClientCategoryIgniteDeployments) HealthCheckStates(
	ctx context.Context, deploymentId string, opts ...ClientOption,
) ([]*types.HealthCheckState, error)

HealthCheckStates is used to get the state of health checks for a deployment.

func (ClientCategoryIgniteDeployments) NewHealthCheck added in v1.8.0

NewHealthCheck is used to set a health check on a deployment. Returns the health check ID.

func (ClientCategoryIgniteDeployments) Patch deprecated

Patch is used to patch a deployment by its ID.

Deprecated: use Update instead.

func (ClientCategoryIgniteDeployments) Scale added in v1.4.0

func (c ClientCategoryIgniteDeployments) Scale(
	ctx context.Context, deploymentId string, containerCount uint, opts ...ClientOption,
) ([]*types.Container, error)

Scale is used to scale the container count of a deployment.

func (ClientCategoryIgniteDeployments) Update added in v1.4.0

Update is used to update a deployment by its ID.

func (ClientCategoryIgniteDeployments) UpdateHealthCheck added in v1.8.0

func (c ClientCategoryIgniteDeployments) UpdateHealthCheck(
	ctx context.Context, updateOpts types.HealthCheckUpdateOpts, opts ...ClientOption,
) (*types.HealthCheck, error)

UpdateHealthCheck is used to update a health check.

func (ClientCategoryIgniteDeployments) VolumeVirtualFS added in v1.12.1

func (c ClientCategoryIgniteDeployments) VolumeVirtualFS(
	ctx context.Context, deploymentId, volumeId string, opts ...ClientOption,
) fs.FS

VolumeVirtualFS is used to make a fs.FS compatible virtual filesystem. Note that the context should live as long as the filesystem in this instance.

type ClientCategoryIgniteGateways

type ClientCategoryIgniteGateways struct {
	// contains filtered or unexported fields
}

ClientCategoryIgniteGateways is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Ignite.Gateways.

func (ClientCategoryIgniteGateways) AddDomain

func (c ClientCategoryIgniteGateways) AddDomain(ctx context.Context, gatewayId string, domain string, opts ...ClientOption) error

AddDomain is used to add a domain to the gateway. The parameter gatewayId is the ID of the gateway to add the domain to, and domain is the full name of the domain.

func (ClientCategoryIgniteGateways) Delete added in v1.6.0

Delete is used to delete a gateway by its ID.

func (ClientCategoryIgniteGateways) DeleteDomain added in v1.9.0

func (c ClientCategoryIgniteGateways) DeleteDomain(ctx context.Context, domainId string, opts ...ClientOption) error

DeleteDomain is used to delete a domain by its ID.

func (ClientCategoryIgniteGateways) Get

Get is used to get a gateway by its ID.

func (ClientCategoryIgniteGateways) GetDomain added in v1.9.0

func (c ClientCategoryIgniteGateways) GetDomain(
	ctx context.Context, domainId string, opts ...ClientOption,
) (*types.Domain, error)

GetDomain is used to get a domain by its ID.

func (ClientCategoryIgniteGateways) Update added in v1.7.0

Update is used to update a gateway by its ID.

type ClientCategoryPipe

type ClientCategoryPipe struct {
	Rooms *ClientCategoryPipeRooms
	// contains filtered or unexported fields
}

ClientCategoryPipe is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Pipe.

type ClientCategoryPipeRooms

type ClientCategoryPipeRooms struct {
	// contains filtered or unexported fields
}

ClientCategoryPipeRooms is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Pipe.Rooms.

func (ClientCategoryPipeRooms) Create

func (c ClientCategoryPipeRooms) Create(
	ctx context.Context, opts types.RoomCreationOptions, clientOpts ...ClientOption,
) (*types.Room, error)

Create is used to create a room.

func (ClientCategoryPipeRooms) Delete

func (c ClientCategoryPipeRooms) Delete(ctx context.Context, id string, opts ...ClientOption) error

Delete is used to delete a room.

func (ClientCategoryPipeRooms) GetAll

func (c ClientCategoryPipeRooms) GetAll(ctx context.Context, opts ...ClientOption) ([]*types.Room, error)

GetAll is used to get all rooms associated with a pipe.

type ClientCategoryProjects

type ClientCategoryProjects struct {
	Tokens  *ClientCategoryProjectsTokens
	Secrets *ClientCategoryProjectsSecrets
	// contains filtered or unexported fields
}

ClientCategoryProjects is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Projects.

func (ClientCategoryProjects) GetAllMembers

func (c ClientCategoryProjects) GetAllMembers(ctx context.Context, opts ...ClientOption) ([]*types.ProjectMember, error)

GetAllMembers is used to get all members associated with a project. The project ID MUST be specified in client options (either at a client or function level).

func (ClientCategoryProjects) GetCurrentMember

func (c ClientCategoryProjects) GetCurrentMember(ctx context.Context, opts ...ClientOption) (*types.ProjectMember, error)

GetCurrentMember is used to get the current member associated with a project. You cannot use this method with a project token. The project ID MUST be specified in client options (either at a client or function level).

type ClientCategoryProjectsSecrets

type ClientCategoryProjectsSecrets struct {
	// contains filtered or unexported fields
}

ClientCategoryProjectsSecrets is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Projects.Secrets.

func (ClientCategoryProjectsSecrets) Create

Create is used to create a project secret. The project ID MUST be specified in client options (either at a client or function level).

func (ClientCategoryProjectsSecrets) Delete

Delete is used to delete a project secret.

func (ClientCategoryProjectsSecrets) GetAll

GetAll is used to get all project secrets. The project ID MUST be specified in client options (either at a client or function level).

type ClientCategoryProjectsTokens

type ClientCategoryProjectsTokens struct {
	// contains filtered or unexported fields
}

ClientCategoryProjectsTokens is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Projects.Tokens.

func (ClientCategoryProjectsTokens) Create

Create is used to create a token. The project ID MUST be specified in client options (either at a client or function level).

func (ClientCategoryProjectsTokens) Delete

Delete is used to delete a token. The project ID MUST be specified in client options (either at a client or function level).

func (ClientCategoryProjectsTokens) GetAll

GetAll is used to get all tokens associated with a project. The project ID MUST be specified in client options (either at a client or function level).

type ClientCategoryRegistry

type ClientCategoryRegistry struct {
	Images *ClientCategoryRegistryImages
	// contains filtered or unexported fields
}

ClientCategoryRegistry is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Registry.

type ClientCategoryRegistryImages

type ClientCategoryRegistryImages struct {
	// contains filtered or unexported fields
}

ClientCategoryRegistryImages is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Registry.Images.

func (ClientCategoryRegistryImages) Delete

func (c ClientCategoryRegistryImages) Delete(ctx context.Context, image string, opts ...ClientOption) error

Delete is used to delete an image.

func (ClientCategoryRegistryImages) GetAll

GetAll is used to get all images in a project.

func (ClientCategoryRegistryImages) GetManifest

func (c ClientCategoryRegistryImages) GetManifest(ctx context.Context, image string, opts ...ClientOption) ([]*types.ImageManifest, error)

GetManifest is used to get the manifest for an image.

type ClientCategoryUsers

type ClientCategoryUsers struct {
	Me *ClientCategoryUsersMe
	// contains filtered or unexported fields
}

ClientCategoryUsers is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Users.

type ClientCategoryUsersMe

type ClientCategoryUsersMe struct {
	// contains filtered or unexported fields
}

ClientCategoryUsersMe is an auto-generated struct which is used to allow for simple categorisation of the APIs. It is public since it may be desired to store a reference to this somewhere, however, do NOT create a instance of this directly. Instead, call NewClient and then go to the field Users.Me.

func (ClientCategoryUsersMe) CreatePat

func (c ClientCategoryUsersMe) CreatePat(ctx context.Context, name string, opts ...ClientOption) (*types.UserPat, error)

CreatePat is used to create a personal access token for the current user.

func (ClientCategoryUsersMe) DeletePat

func (c ClientCategoryUsersMe) DeletePat(ctx context.Context, id string, opts ...ClientOption) error

DeletePat is used to delete a personal access token for the current user.

func (ClientCategoryUsersMe) Get

Get is used to get the current user.

func (ClientCategoryUsersMe) GetAllPats

func (c ClientCategoryUsersMe) GetAllPats(ctx context.Context, opts ...ClientOption) ([]*types.UserPat, error)

GetAllPats is used to get all personal access tokens for the current user.

type ClientOption

type ClientOption interface {
	// contains filtered or unexported methods
}

ClientOption is used to define am option that the client will consume when it is ran. You should not and cannot implement this interface. This is only designed as a signature for other options.

func WithCurlDebugWriter added in v1.9.0

func WithCurlDebugWriter(w io.Writer) ClientOption

WithCurlDebugWriter is used to write what the curl command for the request specified would be and a new line to an io.Writer.

func WithCustomAPIURL added in v1.4.0

func WithCustomAPIURL(apiBase string) ClientOption

WithCustomAPIURL Is used to return a ClientOption for calling the API with a specific API URL. By default, this is https://api.hop.io/v1.

func WithCustomHandler added in v1.10.0

func WithCustomHandler(fn CustomHandler) ClientOption

WithCustomHandler is used to define a custom Hop request handler.

func WithProjectID

func WithProjectID(projectId string) ClientOption

WithProjectID Is used to return a ClientOption for calling the API with a specific project ID.

type CustomHandler added in v1.10.0

type CustomHandler func(ctx context.Context, a ClientArgs, opts ProcessedClientOpts) error

CustomHandler is used to define a custom handler for Hop requests.

type Paginator

type Paginator[T any] struct {
	// contains filtered or unexported fields
}

Paginator is used to create a way to access paginated API routes.

func (*Paginator[T]) ForChunk

func (p *Paginator[T]) ForChunk(ctx context.Context, f func([]T) error, opts ...ClientOption) error

ForChunk is basically the shorthand for calling a function everytime there is a new result. Any errors are passed to the root error result.

func (*Paginator[T]) Next

func (p *Paginator[T]) Next(ctx context.Context, opts ...ClientOption) ([]T, error)

Next is used to get the next page.

type PlainText added in v1.10.0

type PlainText []byte

PlainText is a special case for a body that should be sent as text/plain.

type ProcessedClientOpts added in v1.10.0

type ProcessedClientOpts struct {
	// ProjectID is the project iD this is relating to. Blank if not set.
	ProjectID string

	// CustomAPIURL is the last API URL that was swt. Blank if not set.
	CustomAPIURL string

	// CurlDebugWriters are writers that the curl command and new line of a request should be sent to.
	CurlDebugWriters []io.Writer

	// CustomHandler is used to define the custom handler for Hop requests. Nil if not set.
	CustomHandler CustomHandler
}

ProcessedClientOpts is the result of all the client options that were passed in.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL