api

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package api provides access to the platform API, in all forms supported by the config context (aka access profile)

Package api provides access to the platform API, in all forms supported by the config context (aka access profile)

Package api provides access to the platform API, in all forms supported by the config context (aka access profile)

Index

Constants

View Source
const RESOLVER_HOST = "observe-tenant-lookup-api"

Variables

View Source
var FlagCurlifyRequests bool

Functions

func AddLocalAuthReqHeaders added in v0.50.0

func AddLocalAuthReqHeaders(req *http.Request, opt *config.LocalAuthOptions)

func HTTPGet

func HTTPGet(path string, out any, options *Options) error

HTTPGet performs a GET request with HTTP command and response - Accept and Content-Type headers are provided by the caller

func HTTPPost

func HTTPPost(path string, body []byte, out any, options *Options) error

HTTPPost performs a POST request with HTTP command and response - Accept and Content-Type headers are provided by the caller

func JSONDelete

func JSONDelete(path string, out any, options *Options) error

JSONDelete performs a DELETE request and parses the response as JSON

func JSONGet

func JSONGet(path string, out any, options *Options) error

JSONGet performs a GET request and parses the response as JSON

func JSONGetCollection

func JSONGetCollection[T any](path string, out *CollectionResult[T], options *Options) (err error)

JSONGetCollection performs a GET request and parses the response as JSON, handling pagination per https://www.rfc-editor.org/rfc/rfc5988, https://developer.cisco.com/api-guidelines/#rest-style/API.REST.STYLE.25 and https://developer.cisco.com/api-guidelines/#rest-style/API.REST.STYLE.24

func JSONPatch

func JSONPatch(path string, body any, out any, options *Options) error

JSONPatch performs a PATCH request and parses the response as JSON

func JSONPost

func JSONPost(path string, body any, out any, options *Options) error

JSONPost performs a POST request with JSON command and response

func JSONPut

func JSONPut(path string, body any, out any, options *Options) error

JSONPut performs a PUT request with JSON command and response

func JSONRequest

func JSONRequest(method string, path string, body any, out any, options *Options) error

JSONRequest performs an HTTP request and parses the response as JSON, allowing the http method to be specified

func Login

func Login() error

Login performs a login into the platform API and saves the provided access token. Login respects different access profile types (when supported) to provide the correct login mechanism for each.

func RunProxyServer added in v0.67.0

func RunProxyServer(port int, command []string, statusPrinter func(string), exitCode *int) error

Types

type CollectionResult added in v0.49.0

type CollectionResult[T any] struct {
	Items []T `json:"items"`
	Total int `json:"total"`
}

CollectionResult is a structure that wraps API collections of type T. See JSONGetCollection for reference to API collection RFC/standards

type HttpStatusError added in v0.57.1

type HttpStatusError struct {
	Message    string // used only if WrappedError is nil
	StatusCode int
	WrappedErr error
}

func (*HttpStatusError) Error added in v0.57.1

func (e *HttpStatusError) Error() string

func (*HttpStatusError) Unwrap added in v0.57.1

func (e *HttpStatusError) Unwrap() error

type Options

type Options struct {
	// Headers contains additional headers to be provided in the request
	Headers map[string]string

	// ResponseHeaders will be populated with the headers returned by the call
	ResponseHeaders map[string][]string

	// ExpectedErrors is a list of status codes that are expected and should be logged as Info rather than Error
	ExpectedErrors []int

	// Quiet suppresses the interactive spinner and display of request
	Quiet bool

	// Context provides a Go context for the API call (nil is accepted and will be replaced with a default context)
	Context context.Context
}

Options contains extra, optional parameters that modify the API call behavior

type Problem added in v0.25.0

type Problem struct {
	Type       string `json:"type"`
	Title      string `json:"title"`
	Detail     string `json:"detail"`
	Status     int    `json:"status"`
	Extensions map[string]any
}

Problem type is a json object returned for content-type application/problem+json according to the RFC-7807

func (Problem) Error added in v0.25.0

func (p Problem) Error() string

func (*Problem) UnmarshalJSON added in v0.25.0

func (p *Problem) UnmarshalJSON(bs []byte) (err error)

type Version added in v0.50.0

type Version string

Version defines an API version, as used in URI paths. Use NewVersion() to create/parse from a string value and String() to convert back to string

func NewVersion added in v0.50.0

func NewVersion(s string) (Version, error)

NewVersion parses a string value into an API version, ensuring that the string matches the required pattern

func (*Version) String added in v0.50.0

func (v *Version) String() string

String converts an API version to string, implementing the Stringer interface

Jump to

Keyboard shortcuts

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