api

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Unsuccessful = Reply{Success: false, Version: pkg.Version()}
	NotFound     = Reply{Success: false, Error: "resource not found", Version: pkg.Version()}
	NotAllowed   = Reply{Success: false, Error: "method not allowed", Version: pkg.Version()}
)

Functions

func ContextWithRequestID

func ContextWithRequestID(parent context.Context, requestID string) context.Context

Adds a request ID to the context which is sent with the request in the X-Request-ID header.

func ErrorStatus

func ErrorStatus(err error) int

ErrorStatus returns the HTTP status code from an error or 500 if the error is not a StatusError.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (string, bool)

Extracts a request ID from the context.

Types

type APIv1

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

APIv1 implements the v1 Client interface for making requests to the TRISA SHN.

func (*APIv1) Do

func (s *APIv1) Do(req *http.Request, data interface{}, checkStatus bool) (rep *http.Response, err error)

Do executes an http request against the server, performs error checking, and deserializes the response data into the specified struct.

func (*APIv1) NewRequest

func (s *APIv1) NewRequest(ctx context.Context, method, path string, data interface{}, params *url.Values) (req *http.Request, err error)

func (*APIv1) Status

func (s *APIv1) Status(ctx context.Context) (out *StatusReply, err error)

type Client

type Client interface {
	Status(context.Context) (*StatusReply, error)
}

Client defines the service interface for interacting with the Exchequer service internal API (e.g. the API that users can integrate with).

func New

func New(endpoint string, opts ...ClientOption) (_ Client, err error)

New creates a new APIv1 client that implements the Client interface.

type ClientOption

type ClientOption func(c *APIv1) error

ClientOption allows us to configure the APIv1 client when it is created.

func WithClient

func WithClient(client *http.Client) ClientOption

type PageQuery

type PageQuery struct {
	PageSize      int    `json:"page_size,omitempty" url:"page_size,omitempty" form:"page_size"`
	NextPageToken string `json:"next_page_token" url:"next_page_token,omitempty" form:"next_page_token"`
	PrevPageToken string `json:"prev_page_token" url:"prev_page_token,omitempty" form:"prev_page_token"`
}

PageQuery manages paginated list requests.

type Reply

type Reply struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
	Version string `json:"version,omitempty"`
}

Reply contains standard fields that are used for generic API responses and errors.

func Error

func Error(err interface{}) Reply

Construct a new response for an error or simply return unsuccessful.

type StatusError

type StatusError struct {
	StatusCode int
	Reply      Reply
}

StatusError decodes an error response from the TRISA API.

func (*StatusError) Error

func (e *StatusError) Error() string

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
}

Returned on status requests.

Jump to

Keyboard shortcuts

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