api

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Traceable
	Query(
		ctx context.Context,
		cfg RequestConfigRenderer,
		resp interface{}) (RespMeta, error)
	QueryParams() QueryParamsEncoder
	QueryParamsWithFields(provider FieldProvider) QueryParamsEncoder
	GetCustomHTTPHeaders() http.Header
	SetCustomHTTPHeaders(headers http.Header)
	SetLogger(logger Logger)
}

ApiClient is PowerStore API client interface

type ClientIMPL

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

ClientIMPL struct holds API client settings

func New

func New(apiURL string, username string,
	password string, insecure bool, defaultTimeout, rateLimit uint64, requestIDKey ContextKey,
) (*ClientIMPL, error)

New creates and initialize API client

func (*ClientIMPL) GetCustomHTTPHeaders added in v1.8.0

func (c *ClientIMPL) GetCustomHTTPHeaders() http.Header

GetCustomHTTPHeaders method retrieves http headers

func (*ClientIMPL) Query

func (c *ClientIMPL) Query(
	ctx context.Context,
	cfg RequestConfigRenderer,
	resp interface{},
) (RespMeta, error)

Query method do http request and reads response to provided struct

func (*ClientIMPL) QueryParams

func (c *ClientIMPL) QueryParams() QueryParamsEncoder

QueryParams method returns QueryParamsEncoder

func (*ClientIMPL) QueryParamsWithFields

func (c *ClientIMPL) QueryParamsWithFields(fp FieldProvider) QueryParamsEncoder

QueryParamsWithFields method returns QueryParamsEncoder with configured select values

func (*ClientIMPL) SetCustomHTTPHeaders

func (c *ClientIMPL) SetCustomHTTPHeaders(headers http.Header)

SetCustomHTTPHeaders method register headers which will be sent with every request

func (*ClientIMPL) SetLogger

func (c *ClientIMPL) SetLogger(logger Logger)

SetLogger set logger for use by gopowerstore

func (*ClientIMPL) SetTraceID

func (c *ClientIMPL) SetTraceID(ctx context.Context, traceID string) context.Context

SetTraceID set tracing id to context

func (*ClientIMPL) TraceID

func (c *ClientIMPL) TraceID(ctx context.Context) string

TraceID return tracing id for current context

type ContextKey added in v1.14.1

type ContextKey string

type ErrorMsg

type ErrorMsg struct {
	StatusCode int `json:"-"`
	Severity   string
	Message    string `json:"message_l10n"`
	Arguments  []string
}

ErrorMsg is internal error representation

func (*ErrorMsg) Error

func (err *ErrorMsg) Error() string

type FieldProvider

type FieldProvider interface {
	Fields() []string
}

FieldProvider provide method which return required fields list

type Logger

type Logger interface {
	Info(ctx context.Context, format string, args ...interface{})
	Debug(ctx context.Context, format string, args ...interface{})
	Error(ctx context.Context, format string, args ...interface{})
}

Logger interface for gopowerstore custom logger

type PaginationInfo

type PaginationInfo struct {
	// first element index in response
	First int
	// last element index in response
	Last int
	// total elements count
	Total int
	// indicate that response is paginated
	IsPaginate bool
}

PaginationInfo stores information about pagination

type QueryParams

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

QueryParams struct holds additional query options for PowerStore API

func (*QueryParams) Async

func (qp *QueryParams) Async(value bool) QueryParamsEncoder

Async set value of QueryParams.asyncParam

func (*QueryParams) Encode

func (qp *QueryParams) Encode() string

Encode encodes the values into “URL encoded” form ("bar=baz&foo=quux") sorted by key.

func (*QueryParams) Limit

func (qp *QueryParams) Limit(value int) QueryParamsEncoder

Limit set value of QueryParams.limitParam

func (*QueryParams) Offset

func (qp *QueryParams) Offset(value int) QueryParamsEncoder

Offset set value of QueryParams.offsetParam

func (*QueryParams) Order

func (qp *QueryParams) Order(fields ...string) QueryParamsEncoder

Order adds values to QueryParams.orderParam array

func (*QueryParams) RawArg

func (qp *QueryParams) RawArg(key string, value string) QueryParamsEncoder

RawArg allows to set query params in key/value form

func (*QueryParams) Select

func (qp *QueryParams) Select(fields ...string) QueryParamsEncoder

Select adds values to QueryParams.selectParam array

type QueryParamsEncoder

type QueryParamsEncoder interface {
	RawArg(string, string) QueryParamsEncoder
	Select(...string) QueryParamsEncoder
	Order(...string) QueryParamsEncoder
	Limit(int) QueryParamsEncoder
	Offset(int) QueryParamsEncoder
	Async(bool) QueryParamsEncoder
	Encode() string
}

QueryParamsEncoder interface provide ability to manipulate query string parameters

type RequestConfig

type RequestConfig struct {
	// http method Name
	Method string
	// target endpoint
	Endpoint string
	// id of the entity
	ID string
	// action which perform on entity
	Action string
	// addition query params
	QueryParams QueryParamsEncoder
	// request body
	Body interface{}
}

RequestConfig provide options for the request

func (RequestConfig) RenderRequestConfig

func (rc RequestConfig) RenderRequestConfig() RequestConfig

RenderRequestConfig is RequestConfigRenderer implementation

type RequestConfigRenderer

type RequestConfigRenderer interface {
	RenderRequestConfig() RequestConfig
}

RequestConfigRenderer provides methods for rendering request config

type RespMeta

type RespMeta struct {
	// http status
	Status int
	// pagination data
	Pagination PaginationInfo
}

RespMeta struct represents additional information about response

type TimeoutSemaphore added in v1.14.1

type TimeoutSemaphore struct {
	Timeout   time.Duration
	Semaphore chan struct{}
	Logger    Logger
}

func NewTimeoutSemaphore added in v1.3.0

func NewTimeoutSemaphore(timeout, rateLimit int, logger Logger) *TimeoutSemaphore

func (*TimeoutSemaphore) Acquire added in v1.14.1

func (ts *TimeoutSemaphore) Acquire(ctx context.Context) error

func (*TimeoutSemaphore) Release added in v1.14.1

func (ts *TimeoutSemaphore) Release(ctx context.Context)

func (*TimeoutSemaphore) SetLogger added in v1.14.1

func (ts *TimeoutSemaphore) SetLogger(logger Logger) TimeoutSemaphoreInterface

type TimeoutSemaphoreError added in v1.3.0

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

func (*TimeoutSemaphoreError) Error added in v1.3.0

func (e *TimeoutSemaphoreError) Error() string

type TimeoutSemaphoreInterface added in v1.3.0

type TimeoutSemaphoreInterface interface {
	Acquire(ctx context.Context) error
	Release(ctx context.Context)
	SetLogger(logger Logger) TimeoutSemaphoreInterface
}

TimeoutSemaphoreInterface gives ability to limit rate of requests to PowerStore API

type Traceable

type Traceable interface {
	SetTraceID(ctx context.Context, traceID string) context.Context
	TraceID(ctx context.Context) string
}

Traceable interface provide ability to set and read tracing info to/from context

Jump to

Keyboard shortcuts

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