adapter

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Program to create, update & delete aspect schemas in cayp Adapted from https://github.com/maxott/cayp-cli/blob/main/pkg/adapter/adapter.go

Adapted from https://github.com/maxott/magda-cli/blob/main/pkg/adapter/payload.go

Adapted from https://github.com/maxott/magda-cli/blob/main/pkg/adapter/adapter.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessErrorResponse

func ProcessErrorResponse(resp *http.Response, path string, pyld Payload, logger *log.Logger) (err error)

func ReplyPrinter

func ReplyPrinter(pld Payload, useYAML bool) (err error)

Types

type Adapter

type Adapter interface {
	Head(ctxt context.Context, path string, headers *map[string]string, logger *log.Logger) (Payload, error)
	Get(ctxt context.Context, path string, logger *log.Logger) (Payload, error)
	Get2(ctxt context.Context, path string, headers *map[string]string, respHandler ResponseHandler, logger *log.Logger) error
	Post(ctxt context.Context, path string, body io.Reader, length int64, headers *map[string]string, logger *log.Logger) (Payload, error)
	PostForm(ctxt context.Context, path string, data url.Values, headers *map[string]string, logger *log.Logger) (Payload, error)
	Put(ctxt context.Context, path string, body io.Reader, length int64, headers *map[string]string, logger *log.Logger) (Payload, error)
	Patch(ctxt context.Context, path string, body io.Reader, length int64, headers *map[string]string, logger *log.Logger) (Payload, error)
	Delete(ctxt context.Context, path string, logger *log.Logger) (Payload, error)
	SetUrl(url string)
	GetPath(url string) (path string, err error)
}

func RestAdapter

func RestAdapter(connCtxt ConnectionCtxt) Adapter

type AdapterError

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

func (*AdapterError) Error

func (e *AdapterError) Error() string

func (*AdapterError) Path

func (e *AdapterError) Path() string

type ApiError

type ApiError struct {
	AdapterError
	StatusCode int
	Payload    Payload
}

func (*ApiError) Error

func (e *ApiError) Error() string

type ClientError

type ClientError struct {
	AdapterError
	// contains filtered or unexported fields
}

func (*ClientError) Error

func (e *ClientError) Error() string

type ConnectionCtxt

type ConnectionCtxt struct {
	URL         string
	AccessToken string
	TimeoutSec  int
	Headers     *map[string]string // default headers
}

type IAdapterError

type IAdapterError interface {
	Error() string
	Path() string
}

type MissingUrlError

type MissingUrlError struct {
	AdapterError
}

func (MissingUrlError) Error

func (e MissingUrlError) Error() string

type Payload

type Payload interface {
	// IsObject() bool
	AsType(r interface{}) error
	AsObject() (map[string]interface{}, error)
	AsArray() ([]interface{}, error)
	AsBytes() []byte
	IsEmpty() bool
	Header(key string) string
	StatusCode() int
}

func Connect

func Connect(
	ctxt context.Context,
	method string,
	path string,
	body io.Reader,
	length int64,
	headers *map[string]string,
	connCtxt *ConnectionCtxt,
	respHandler ResponseHandler,
	logger *log.Logger,
) (Payload, error)

func LoadPayloadFromBytes

func LoadPayloadFromBytes(data []byte, isYAML bool) (pyld Payload, err error)

func LoadPayloadFromFile

func LoadPayloadFromFile(fileName string, isYAML bool) (Payload, error)

func LoadPayloadFromStdin

func LoadPayloadFromStdin(isYAML bool) (Payload, error)

func ToPayload

func ToPayload(body []byte, resp *http.Response, logger *log.Logger) Payload

type ResourceNotFoundError

type ResourceNotFoundError struct {
	AdapterError
}

func (ResourceNotFoundError) Error

func (e ResourceNotFoundError) Error() string

type ResponseHandler

type ResponseHandler func(response *http.Response, path string, logger *log.Logger) (err error)

type UnauthorizedError

type UnauthorizedError struct {
	AdapterError
}

func (*UnauthorizedError) Error

func (e *UnauthorizedError) Error() string

Jump to

Keyboard shortcuts

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