client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNextIP

func GetNextIP(ip *net.IP, inc uint) *net.IP

GetNextIP() returns the next IP address, but does not account for net masks.

func NewClient

func NewClient[T Client](opts ...func(T)) T

NewClient() creates a new client

func WithCertPool

func WithCertPool[T Client](certPool *x509.CertPool) func(T)

func WithSecureTLS

func WithSecureTLS[T Client](certPath string) func(T)

Types

type Client

type Client interface {
	Name() string
	GetClient() *http.Client
	RootEndpoint(endpoint string) string

	// functions needed to make request
	Add(data HTTPBody, headers HTTPHeader) error
	Update(data HTTPBody, headers HTTPHeader) error
}

The 'Client' struct is a wrapper around the default http.Client that provides an extended API to work with functional options. It also provides functions that work with `collect` data.

type HTTPBody

type HTTPBody []byte

func MakeRequest

func MakeRequest(client *http.Client, url string, httpMethod string, body HTTPBody, header HTTPHeader) (*http.Response, HTTPBody, error)

MakeRequest() is a wrapper function that condenses simple HTTP requests done to a single call. It expects an optional HTTP client, URL, HTTP method, request body, and request headers. This function is useful when making many requests where only these few arguments are changing.

Returns a HTTP response object, response body as byte array, and any error that may have occurred with making the request.

type HTTPHeader

type HTTPHeader map[string]string

HTTP aliases for readibility

func (HTTPHeader) Authorization

func (h HTTPHeader) Authorization(accessToken string) HTTPHeader

func (HTTPHeader) ContentType

func (h HTTPHeader) ContentType(contentType string) HTTPHeader

type MagellanClient

type MagellanClient struct {
	*http.Client
}

func (*MagellanClient) Add

func (c *MagellanClient) Add(data HTTPBody, headers HTTPHeader) error

Add() is the default function that is called with a client with no implementation. This function will simply make a HTTP request including all the data passed as the first argument with no data processing or manipulation. The function sends the data to a set callback URL (which may be changed to use a configurable value instead).

func (*MagellanClient) Name

func (c *MagellanClient) Name() string

func (*MagellanClient) Post

func (c *MagellanClient) Post(url string, data map[string]any, header HTTPHeader) (*http.Response, HTTPBody, error)

Post() is a simplified wrapper function that packages all of the that marshals a mapper into a JSON-formatted byte array, and then performs a request to the specified URL.

func (*MagellanClient) Update

func (c *MagellanClient) Update(data HTTPBody, headers HTTPHeader) error

type Option

type Option[T Client] func(client T)

type SmdClient

type SmdClient struct {
	*http.Client
	URI   string
	Xname string
}

func (SmdClient) Add

func (c SmdClient) Add(data HTTPBody, headers HTTPHeader) error

Add() has a similar function definition to that of the default implementation, but also allows further customization and data/header manipulation that would be specific and/or unique to SMD's API.

func (SmdClient) GetClient

func (c SmdClient) GetClient() *http.Client

func (SmdClient) Name

func (c SmdClient) Name() string

func (SmdClient) RootEndpoint

func (c SmdClient) RootEndpoint(endpoint string) string

func (SmdClient) Update

func (c SmdClient) Update(data HTTPBody, headers HTTPHeader) error

Jump to

Keyboard shortcuts

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