httpclient

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPClient

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

HTTPClient represents a client for interaction with a ONTAP REST API

func NewClient

func NewClient(ctx context.Context, cxProfile HTTPProfile, tag string) HTTPClient

NewClient creates a new HTTP client

func (*HTTPClient) Do

func (c *HTTPClient) Do(baseURL string, req *Request) (int, []byte, error)

Do sends the API Request, parses the response as JSON, and returns the HTTP status code as int, the "result" value as byte possible errors:

no response body:
	failed to build HTTP request - statusCode forced to -1
	failed to send HTTP request - statusCode forced to -1 unless it is present in the response
	failed to read HTTP response body - statusCode from response if present, otherwise -1
	empty response body (check with POST/PATCH/DELETE if this is really a problem)  - statusCode from response if present, otherwise -1

type HTTPProfile

type HTTPProfile struct {
	APIRoot       string
	Hostname      string
	Username      string
	Password      string
	ValidateCerts bool
}

HTTPProfile defines the connection attributes to build the base URL and authentication header

type Request

type Request struct {
	Method string                 `json:"method"`
	Body   map[string]interface{} `json:"body"`
	Query  url.Values             `json:"query"`
}

Request represents a request to a REST API

func (*Request) BuildHTTPReq

func (r *Request) BuildHTTPReq(c *HTTPClient, baseURL string) (*http.Request, error)

BuildHTTPReq builds an HTTP request to carry out the REST request

func (*Request) BuildURL

func (r *Request) BuildURL(c *HTTPClient, baseURL string, uuid string) (string, error)

BuildURL using Host, ApiRoot, baseURL, uuid, any query element

Jump to

Keyboard shortcuts

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