adapter

package
v0.41.8 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: Apache-2.0 Imports: 16 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)

func ToString added in v0.35.0

func ToString(f any, useYAML bool) (s string, 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)
	GetWithHandler(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)
	PostWithHandler(ctxt context.Context, path string, body io.Reader, length int64, headers *map[string]string, respHandler ResponseHandler, 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)
	GetSSE(ctxt context.Context, path string, lastEventID *string, onEvent func(*sse.Event), headers *map[string]string, logger *log.Logger) error
	SetUrl(url string)
	GetPath(url string) (path string, err error)
}

func RestAdapter

func RestAdapter(opts ...Option) 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 Option added in v0.41.4

type Option func(adpr *restAdapter)

func WithConnContext added in v0.41.4

func WithConnContext(connCtxt *ConnectionCtxt) Option

func WithHttpClient added in v0.41.4

func WithHttpClient(client *http.Client) Option

type Payload

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

func JsonPayloadFromAny added in v0.41.8

func JsonPayloadFromAny(msg any, 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