resourcemanager

package
v0.0.0-...-ed06964 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const FormatJSON = "json"
View Source
const FormatPretty = "pretty"
View Source
const FormatYAML = "yaml"

Variables

View Source
var ErrNotFound = requestError{
	Code:    http.StatusNotFound,
	Message: "Resource not found",
}
View Source
var ErrResourceNotFound = errors.New("resource not found")
View Source
var Formats = formatRegistry{
	jsonFormat{},
	yamlFormat{},
	prettyFormat{},
}

Functions

func SetRequestContextHeaders

func SetRequestContextHeaders(ctx context.Context, headers map[string]string) context.Context

func WithApplyPreProcessor

func WithApplyPreProcessor(preProcessor applyPreProcessorFn) option

func WithDeleteSuccessMessage

func WithDeleteSuccessMessage(deleteSuccessMssg string) option

func WithDeprecatedAlias

func WithDeprecatedAlias(resourceType string) option

func WithListPath

func WithListPath(path string) option

func WithPrefixGetter

func WithPrefixGetter(prefixGetterFn prefixGetterFn) option

func WithProxyResource

func WithProxyResource(proxyResource string) option

func WithResourceType

func WithResourceType(resourceType string) option

func WithTableConfig

func WithTableConfig(tableConfig TableConfig) option

Types

type Client

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

func NewClient

func NewClient(
	httpClient *HTTPClient,
	logger *zap.Logger,
	resourceName, resourceNamePlural string,
	opts ...option) Client

NewClient creates a new client for a resource managed by the resourceamanger. The tableConfig parameter configures how the table view should be rendered. This configuration work both for a single resource from a Get, or a ResourceList from a List

func (Client) Apply

func (c Client) Apply(ctx context.Context, inputFile fileutil.File, requestedFormat Format) (string, error)

func (Client) Delete

func (c Client) Delete(ctx context.Context, id string, format Format) (string, error)

func (Client) Get

func (c Client) Get(ctx context.Context, id string, format Format) (string, error)

func (Client) List

func (c Client) List(ctx context.Context, opt ListOption, format Format) (string, error)

func (Client) WithHttpClient

func (c Client) WithHttpClient(HTTPClient *HTTPClient) Client

func (Client) WithOptions

func (c Client) WithOptions(opts ...option) Client

type ContextOption

type ContextOption string
const (
	ContextHeadersKey ContextOption = "headers"
)

type Format

type Format interface {
	BuildRequest(req *http.Request, verb Verb) error
	ContentType() string
	Format(data string, opts ...any) (string, error)
	Unmarshal(data []byte, v interface{}) error
	ToJSON([]byte) ([]byte, error)
	String() string
}

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(baseURL string, extraHeaders http.Header) *HTTPClient

type ListOption

type ListOption struct {
	Take          int32
	Skip          int32
	SortDirection string
	SortBy        string
	All           bool
}

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Exists

func (r *Registry) Exists(resourceName string) bool

func (*Registry) Get

func (r *Registry) Get(resourceName string) (Client, error)

func (*Registry) List

func (r *Registry) List() []string

func (*Registry) Register

func (r *Registry) Register(c Client) *Registry

func (*Registry) Suggest

func (r *Registry) Suggest(input string) string

type TableCellConfig

type TableCellConfig struct {
	Header string
	Path   string
}

type TableConfig

type TableConfig struct {
	Cells        []TableCellConfig
	ItemModifier func(item *gabs.Container) error
}

TableConfig is a configuration for prettyFormat Cells is a list of mappings from JSON keys to table headers. See github.com/Jeffail/gabs. ItemModifier is an optional function that can modify each item before it's added to the table.

type Verb

type Verb string
const VerbApply Verb = "apply"
const VerbDelete Verb = "delete"
const VerbGet Verb = "get"
const VerbList Verb = "list"

Jump to

Keyboard shortcuts

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