generic

package
v0.0.0-...-0600186 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessDeniedErr = errors.New("access denied")
View Source
var BadCredentialsErr = errors.New("bad credentials")
View Source
var ErrorContentType = "application/vnd.com.nsn.cumulocity.error+json"

Functions

func AcceptAndContentTypeHeader

func AcceptAndContentTypeHeader(accept string, contentType string) map[string][]string

func AcceptHeader

func AcceptHeader(accept string) map[string][]string

Returns a pre filled header map with an "Accept" header.

func ContentTypeHeader

func ContentTypeHeader(contentType string) map[string][]string

func ContentTypeHeaderAndContentLength

func ContentTypeHeaderAndContentLength(contentType string, contentLength int) map[string][]string

func EmptyHeader

func EmptyHeader() map[string][]string

Returns an empty header map

func JsonFromObject

func JsonFromObject(o interface{}) ([]byte, error)

func ObjectFromJson

func ObjectFromJson(j []byte, targetStruct interface{}) error

Takes a json as []byte and a pointer of the target struct Returns an error, otherwise fills the `targetStruct` reference with values.

func PageSizeParameter

func PageSizeParameter(pageSize int, params *url.Values) error

Appends the query param 'pageSize' to the provided parameter values for a request. When provided values is nil an error will be created

Types

type Client

type Client struct {
	HTTPClient *http.Client
	BaseURL    string
	Username   string
	Password   string
}

func (*Client) Delete

func (client *Client) Delete(path string, header map[string][]string) ([]byte, int, error)

func (*Client) Get

func (client *Client) Get(path string, header map[string][]string) ([]byte, int, error)

func (*Client) Post

func (client *Client) Post(path string, body []byte, header map[string][]string) ([]byte, int, error)

func (*Client) Put

func (client *Client) Put(path string, body []byte, header map[string][]string) ([]byte, int, error)

type Error

type Error struct {
	ErrorType string `json:"error"`
	Message   string `json:"message"`
	Info      string `json:"info"`
}

Error represent cumulocity's 'application/vnd.com.nsn.cumulocity.error+json' without 'Error details'. See: https://cumulocity.com/guides/reference/rest-implementation/#error-application-vnd-com-nsn-cumulocity-error-json

func ClientError

func ClientError(message string, info string) *Error

func CreateErrorFromResponse

func CreateErrorFromResponse(responseBody []byte, status int) *Error

func (Error) Error

func (e Error) Error() string

type PagingStatistics

type PagingStatistics struct {
	TotalRecords int `json:"totalRecords,omitempty"`
	TotalPages   int `json:"totalPages,omitempty"`
	PageSize     int `json:"pageSize"`
	CurrentPage  int `json:"currentPage"`
}

PagingStatistics represent cumulocity's 'application/vnd.com.nsn.cumulocity.pagingStatistics+json'. See: https://cumulocity.com/guides/reference/rest-implementation/#pagingstatistics-application-vnd-com-nsn-cumulocity-pagingstatistics-json

type Tag

type Tag struct {
	Type      string
	Field     string
	Name      string
	OmitEmpty bool
}

Jump to

Keyboard shortcuts

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