client

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    ErrCode `json:"code"`
	Message string  `json:"message"`
	Details any     `json:"details"`
}

APIError is the error type returned by the API

func (*APIError) Error

func (e *APIError) Error() string

type AuthWakfloAuthParams

type AuthWakfloAuthParams struct {

	// SessionCookie is set to the value of the "session" cookie.
	// If the cookie is not set it's nil.
	SessionCookie *HttpCookie `cookie:"wakflo"`

	// Authorization is the raw value of the "Authorization" header
	// without any parsing.
	Authorization string `header:"Authorization"`
}

type BaseURL

type BaseURL string

BaseURL is the base URL for calling the Encore application's API.

const Local BaseURL = "http://localhost:4000"

func Environment

func Environment(name string) BaseURL

Environment returns a BaseURL for calling the cloud environment with the given name.

func PreviewEnv

func PreviewEnv(pr int) BaseURL

PreviewEnv returns a BaseURL for calling the preview environment with the given PR number.

type Client

type Client struct {
	Rest RestClient
}

Client is an API client for the wakflo-vfd2 Encore application.

func New

func New(target BaseURL, options ...Option) (*Client, error)

New returns a Client for calling the public and authenticated APIs of your Encore application. You can customize the behaviour of the client using the given Option functions, such as WithHTTPClient or WithAuthFunc.

type ErrCode

type ErrCode int
const (
	// ErrOK indicates the operation was successful.
	ErrOK ErrCode = 0

	// ErrCanceled indicates the operation was canceled (typically by the caller).
	//
	// Encore will generate this error code when cancellation is requested.
	ErrCanceled ErrCode = 1

	// ErrUnknown error. An example of where this error may be returned is
	// if a Status value received from another address space belongs to
	// an error-space that is not known in this address space. Also
	// errors raised by APIs that do not return enough error information
	// may be converted to this error.
	//
	// Encore will generate this error code in the above two mentioned cases.
	ErrUnknown ErrCode = 2

	// ErrInvalidArgument indicates client specified an invalid argument.
	// Note that this differs from FailedPrecondition. It indicates arguments
	// that are problematic regardless of the state of the system
	// (e.g., a malformed file name).
	//
	// This error code will not be generated by the gRPC framework.
	ErrInvalidArgument ErrCode = 3

	// ErrDeadlineExceeded means operation expired before completion.
	// For operations that change the state of the system, this error may be
	// returned even if the operation has completed successfully. For
	// example, a successful response from a server could have been delayed
	// long enough for the deadline to expire.
	//
	// The gRPC framework will generate this error code when the deadline is
	// exceeded.
	ErrDeadlineExceeded ErrCode = 4

	// ErrNotFound means some requested entity (e.g., file or directory) was
	// not found.
	//
	// This error code will not be generated by the gRPC framework.
	ErrNotFound ErrCode = 5

	// ErrAlreadyExists means an attempt to create an entity failed because one
	// already exists.
	//
	// This error code will not be generated by the gRPC framework.
	ErrAlreadyExists ErrCode = 6

	// ErrPermissionDenied indicates the caller does not have permission to
	// execute the specified operation. It must not be used for rejections
	// caused by exhausting some resource (use ResourceExhausted
	// instead for those errors). It must not be
	// used if the caller cannot be identified (use Unauthenticated
	// instead for those errors).
	//
	// This error code will not be generated by the gRPC core framework,
	// but expect authentication middleware to use it.
	ErrPermissionDenied ErrCode = 7

	// ErrResourceExhausted indicates some resource has been exhausted, perhaps
	// a per-user quota, or perhaps the entire file system is out of space.
	//
	// This error code will be generated by the gRPC framework in
	// out-of-memory and server overload situations, or when a message is
	// larger than the configured maximum size.
	ErrResourceExhausted ErrCode = 8

	// ErrFailedPrecondition indicates operation was rejected because the
	// system is not in a state required for the operation's execution.
	// For example, directory to be deleted may be non-empty, an rmdir
	// operation is applied to a non-directory, etc.
	//
	// A litmus test that may help a service implementor in deciding
	// between FailedPrecondition, Aborted, and Unavailable:
	//
	//	(a) Use Unavailable if the client can retry just the failing call.
	//	(b) Use Aborted if the client should retry at a higher-level
	//	    (e.g., restarting a read-modify-write sequence).
	//	(c) Use FailedPrecondition if the client should not retry until
	//	    the system state has been explicitly fixed. E.g., if an "rmdir"
	//	    fails because the directory is non-empty, FailedPrecondition
	//	    should be returned since the client should not retry unless
	//	    they have first fixed up the directory by deleting files from it.
	//	(d) Use FailedPrecondition if the client performs conditional
	//	    REST Get/Update/Delete on a resource and the resource on the
	//	    server does not match the condition. E.g., conflicting
	//	    read-modify-write on the same resource.
	//
	// This error code will not be generated by the gRPC framework.
	ErrFailedPrecondition ErrCode = 9

	// ErrAborted indicates the operation was aborted, typically due to a
	// concurrency issue like sequencer check failures, transaction aborts,
	// etc.
	//
	// See litmus test above for deciding between FailedPrecondition,
	// ErrAborted, and Unavailable.
	ErrAborted ErrCode = 10

	// ErrOutOfRange means operation was attempted past the valid range.
	// E.g., seeking or reading past end of file.
	//
	// Unlike InvalidArgument, this error indicates a problem that may
	// be fixed if the system state changes. For example, a 32-bit file
	// may be rotated to a 64-bit file without error.
	//
	// There is a fair bit of overlap between FailedPrecondition and
	// ErrOutOfRange. We recommend using OutOfRange (the more specific
	// error) when it applies so that callers who are iterating through
	// a space can easily look for an OutOfRange error to detect when
	// they are done.
	//
	// This error code will not be generated by the gRPC framework.
	ErrOutOfRange ErrCode = 11

	// ErrUnimplemented indicates operation is not implemented or not
	// supported/enabled in this service.
	//
	// This is not an error, but a feature not available.
	//
	// This error code will not be generated by the gRPC framework.
	ErrUnimplemented ErrCode = 12

	// ErrInternal means some invariant expected by the underlying system has
	// been broken. This is not a per-message error, it is a global
	// conditions check.
	//
	// This error code will not be generated by the gRPC framework.
	ErrInternal ErrCode = 13

	// ErrUnavailable indicates the service is currently unavailable.
	// This is most likely a transient condition, which can be corrected by
	// retrying with a backoff.
	//
	// See litmus test above for deciding between FailedPrecondition,
	// Aborted, and Unavailable.
	ErrUnavailable ErrCode = 14

	// ErrDataLoss indicates unrecoverable data loss or corruption.
	//
	// This error code is only defined in the gRPC library, and only for
	// unrecoverable data loss (i.e., data loss resulting from errors
	// like hard disk corruption or bandwidth exceeded).
	//
	// This error code will not be generated by the gRPC framework.
	ErrDataLoss ErrCode = 15

	// ErrUnauthenticated indicates the request does not have valid
	// authentication credentials for the operation.
	//
	// The gRPC framework will generate this error code when the
	// authentication metadata is invalid or a Credentials callback fails,
	// but also expect authentication middleware to generate it.
	ErrUnauthenticated ErrCode = 16
)

func (ErrCode) MarshalJSON

func (c ErrCode) MarshalJSON() ([]byte, error)

MarshalJSON converts the error code to a human-readable string

func (ErrCode) String

func (c ErrCode) String() string

String returns the string representation of the error code

func (*ErrCode) UnmarshalJSON

func (c *ErrCode) UnmarshalJSON(b []byte) error

UnmarshalJSON converts the human-readable string to an error code

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is an interface which can be used to swap out the default HTTP client (http.DefaultClient) with your own custom implementation. This can be used to inject middleware or mock responses during unit tests.

type HttpCookie

type HttpCookie struct {
	Name       string
	Value      string
	Quoted     bool      // indicates whether the Value was originally quoted
	Path       string    // optional
	Domain     string    // optional
	Expires    time.Time // optional
	RawExpires string    // for reading cookies only

	// MaxAge=0 means no 'Max-Age' attribute specified.
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
	// MaxAge>0 means Max-Age attribute present and given in seconds
	MaxAge      int
	Secure      bool
	HttpOnly    bool
	SameSite    HttpSameSite
	Partitioned bool
	Raw         string
	Unparsed    []string // Raw text of unparsed attribute-value pairs
}

A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an HTTP response or the Cookie header of an HTTP request.

See https://tools.ietf.org/html/rfc6265 for details.

type HttpSameSite

type HttpSameSite = int

SameSite allows a server to define a cookie attribute making it impossible for the browser to send this cookie along with cross-site requests. The main goal is to mitigate the risk of cross-origin information leakage, and provide some protection against cross-site request forgery attacks.

See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details.

type Option

type Option = func(client *baseClient) error

Option allows you to customise the baseClient used by the Client

func WithAuth

func WithAuth(auth AuthWakfloAuthParams) Option

WithAuth allows you to set the authentication data to be used with each request

func WithAuthFunc

func WithAuthFunc(authGenerator func(ctx context.Context) (AuthWakfloAuthParams, error)) Option

WithAuthFunc allows you to pass a function which is called for each request to return the authentication data to be used with each request

func WithHTTPClient

func WithHTTPClient(client HTTPDoer) Option

WithHTTPClient can be used to configure the underlying HTTP client used when making API calls.

Defaults to http.DefaultClient

type RestClient

type RestClient interface {
	// CatchRawWebhook adds a new webhook to the list of monitored webwebhooks.
	CatchRawWebhook(ctx context.Context, hookId string, request *http.Request) (*http.Response, error)

	// CatchRawWebhookTest adds a new webhook to the list of monitored webwebhooks.
	CatchRawWebhookTest(ctx context.Context, hookId string, request *http.Request) (*http.Response, error)

	// CatchWebhook adds a new webhook to the list of monitored webwebhooks.
	CatchWebhook(ctx context.Context, hookId string, request *http.Request) (*http.Response, error)

	// CatchWebhookTest adds a new webhook to the list of monitored webwebhooks.
	CatchWebhookTest(ctx context.Context, hookId string, request *http.Request) (*http.Response, error)
	GenerateDescription(ctx context.Context, params RestGenerateDescriptionRequest) (RestGenerateResponse, error)

	// GenerateDocumentation This endpoint creates a new short URL for a given long URL.
	GenerateDocumentation(ctx context.Context, params RestGenerateDocumentationRequest) (RestGenerateResponse, error)
	ListCategories(ctx context.Context, params RestListCategoriesRequest) (RestListCategoriesResponse, error)
	SearchIcon(ctx context.Context, params RestSearchIconRequest) (RestSearchIconResponse, error)
}

RestClient Provides you access to call public and authenticated APIs on rest. The concrete implementation is restClient. It is setup as an interface allowing you to use GoMock to create mock implementations during tests.

type RestGenerateDescriptionRequest

type RestGenerateDescriptionRequest struct {
	Prompt string `json:"prompt"`
	Type   string `json:"type"`
}

GenerateDescriptionRequest contains data needed to generate a short URL

type RestGenerateDocumentationRequest

type RestGenerateDocumentationRequest struct {
	Prompt string `json:"prompt"`
	Type   string `json:"type"`
}

GenerateDocumentationRequest contains data needed to generate a short URL

type RestGenerateResponse

type RestGenerateResponse struct {
	Data string `json:"data"` // ShortUrl is the generated short URL for the provided long URL
}

GenerateResponse provides the shortened URL and its expiration

type RestListCategoriesRequest

type RestListCategoriesRequest struct {
	Limit int `json:"limit" query:"limit"`
}

ListCategoriesRequest contains data needed to generate a short URL

type RestListCategoriesResponse

type RestListCategoriesResponse struct {
	Keys []string `json:"icons"`
}

ListCategoriesResponse contains data needed to generate a short URL

type RestSearchIconRequest

type RestSearchIconRequest struct {
	Name  string `json:"name"`
	Limit int    `json:"limit" query:"limit"`
}

SearchIconRequest contains data needed to generate a short URL

type RestSearchIconResponse

type RestSearchIconResponse struct {
	Icons []string `json:"icons"`
}

SearchIconResponse contains data needed to generate a short URL

Jump to

Keyboard shortcuts

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