client

package
v0.0.0-...-545e1df Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SELF       = "self"
	COLLECTION = "collection"
)

Variables

View Source
var (
	COND_EQ      = QueryConditionType{"eq", 1}
	COND_NE      = QueryConditionType{"ne", 1}
	COND_NULL    = QueryConditionType{"null", 0}
	COND_NOTNULL = QueryConditionType{"notnull", 0}
	COND_IN      = QueryConditionType{"in", -1}
	COND_NOTIN   = QueryConditionType{"notin", -1}
	COND_OR      = QueryConditionType{"or", 1}
	COND_AND     = QueryConditionType{"and", 1}
)
View Source
var (
	ASC  = SortOrder("asc")
	DESC = SortOrder("desc")
)

Functions

func GuessPluralName

func GuessPluralName(name string) string

func IsNotFound

func IsNotFound(err error) bool

func NewErrors

func NewErrors(errors []error) error

func NormalizeUrl

func NormalizeUrl(existingUrl string) (string, error)

func ValidMod

func ValidMod(mod string) bool

Types

type APIContext

type APIContext struct {
	Action             string
	ID                 string
	Type               string
	Link               string
	Method             string
	Schema             *Schema
	Schemas            *Schemas
	Version            *APIVersion
	ResponseFormat     string
	ReferenceValidator ReferenceValidator
	ResponseWriter     ResponseWriter
	QueryOptions       *QueryOptions
	Body               map[string]interface{}
	URLBuilder         URLBuilder
	AccessControl      AccessControl

	Request  *http.Request
	Response http.ResponseWriter
}

func (*APIContext) WriteResponse

func (r *APIContext) WriteResponse(code int, obj interface{})

type APIVersion

type APIVersion struct {
	Group   string `json:"group,omitempty" yaml:"group,omitempty"`
	Version string `json:"version,omitempty" yaml:"version,omitempty"`
	Path    string `json:"path,omitempty" yaml:"path,omitempty"`
}

type AccessControl

type AccessControl interface {
	CanCreate(schema *Schema) bool
	CanList(schema *Schema) bool
}

type Action

type Action struct {
	Input  string `json:"input,omitempty" yaml:"input,omitempty"`
	Output string `json:"output,omitempty" yaml:"output,omitempty"`
}

type ActionHandler

type ActionHandler func(actionName string, action *Action, request *APIContext) error

type ApiError

type ApiError struct {
	StatusCode int
	Url        string
	Msg        string
	Status     string
	Body       string
}

func (*ApiError) Error

func (e *ApiError) Error() string

type ClientOpts

type ClientOpts struct {
	Url       string
	AccessKey string
	SecretKey string
	Timeout   time.Duration
}

type Collection

type Collection struct {
	Type        string                 `json:"type,omitempty" yaml:"type,omitempty"`
	Links       map[string]string      `json:"links" yaml:"links,omitempty"`
	CreateTypes map[string]string      `json:"createTypes,omitempty" yaml:"create_types,omitempty"`
	Actions     map[string]string      `json:"actions" yaml:"actions,omitempty"`
	Pagination  *Pagination            `json:"pagination,omitempty" yaml:"pagination,omitempty"`
	Sort        *Sort                  `json:"sort,omitempty" yaml:"sort,omitempty"`
	Filters     map[string][]Condition `json:"filters,omitempty" yaml:"filters,omitempty"`

	//TODO: remove
	ResourceType string `json:"resourceType"`
}

type Condition

type Condition struct {
	Modifier string      `json:"modifier,omitempty" yaml:"modifier,omitempty"`
	Value    interface{} `json:"value,omitempty" yaml:"value,omitempty"`
}

type ErrorHandler

type ErrorHandler func(request *APIContext, err error)

type Field

type Field struct {
	Type         string      `json:"type,omitempty" yaml:"type,omitempty"`
	Default      interface{} `json:"default,omitempty" yaml:"default,omitempty"`
	Nullable     bool        `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	Create       bool        `json:"create,omitempty" yaml:"create,omitempty"`
	WriteOnly    bool        `json:"writeOnly,omitempty" yaml:"write_only,omitempty"`
	Required     bool        `json:"required,omitempty" yaml:"required,omitempty"`
	Update       bool        `json:"update,omitempty" yaml:"update,omitempty"`
	MinLength    *int        `json:"minLength,omitempty" yaml:"min_length,omitempty"`
	MaxLength    *int        `json:"maxLength,omitempty" yaml:"max_length,omitempty"`
	Min          *int64      `json:"min,omitempty" yaml:"min,omitempty"`
	Max          *int64      `json:"max,omitempty" yaml:"max,omitempty"`
	Options      []string    `json:"options,omitempty" yaml:"options,omitempty"`
	ValidChars   string      `json:"validChars,omitempty" yaml:"valid_chars,omitempty"`
	InvalidChars string      `json:"invalidChars,omitempty" yaml:"invalid_chars,omitempty"`
	Description  string      `json:"description,omitempty" yaml:"description,omitempty"`
}

type Filter

type Filter struct {
	Modifiers []string `json:"modifiers,omitempty" yaml:"modifiers,omitempty"`
}

type Formatter

type Formatter func(request *APIContext, resource *RawResource)

type GenericCollection

type GenericCollection struct {
	Collection
	Data []interface{} `json:"data" yaml:"data"`
}

type ListOpts

type ListOpts struct {
	Filters map[string]interface{}
}

func NewListOpts

func NewListOpts() *ListOpts

type Pagination

type Pagination struct {
	Marker   string `json:"marker,omitempty" yaml:"marker,omitempty"`
	First    string `json:"first,omitempty" yaml:"first,omitempty"`
	Previous string `json:"previous,omitempty" yaml:"previous,omitempty"`
	Next     string `json:"next,omitempty" yaml:"next,omitempty"`
	Limit    *int64 `json:"limit,omitempty" yaml:"limit,omitempty"`
	Total    *int64 `json:"total,omitempty" yaml:"total,omitempty"`
	Partial  bool   `json:"partial,omitempty" yaml:"partial,omitempty"`
}

type QueryCondition

type QueryCondition struct {
	Field string
	// contains filtered or unexported fields
}

func EQ

func EQ(value interface{}) *QueryCondition

func IN

func IN(values ...interface{}) *QueryCondition

func NE

func NE(value interface{}) *QueryCondition

func NOTIN

func NOTIN(values ...interface{}) *QueryCondition

func NOTNULL

func NOTNULL(value interface{}) *QueryCondition

func NULL

func NULL(value interface{}) *QueryCondition

func NewCondition

func NewCondition(mod QueryConditionType, values ...interface{}) *QueryCondition

func NewConditionFromString

func NewConditionFromString(field, mod string, values ...interface{}) *QueryCondition

func (*QueryCondition) AND

func (*QueryCondition) OR

func (*QueryCondition) ToCondition

func (q *QueryCondition) ToCondition() Condition

type QueryConditionType

type QueryConditionType struct {
	Name string
	Args int
}

type QueryOptions

type QueryOptions struct {
	Sort       Sort
	Pagination *Pagination
	Conditions []*QueryCondition
}

type RancherBaseClient

type RancherBaseClient interface {
	Websocket(string, map[string][]string) (*websocket.Conn, *http.Response, error)
	List(string, *ListOpts, interface{}) error
	Post(string, interface{}, interface{}) error
	GetLink(Resource, string, interface{}) error
	Create(string, interface{}, interface{}) error
	Update(string, *Resource, interface{}, interface{}) error
	ById(string, string, interface{}) error
	Delete(*Resource) error
	Reload(*Resource, interface{}) error
	Action(string, string, *Resource, interface{}, interface{}) error
	GetOpts() *ClientOpts
	GetTypes() map[string]Schema
	// contains filtered or unexported methods
}

type RancherBaseClientImpl

type RancherBaseClientImpl struct {
	Opts    *ClientOpts
	Schemas *Schemas
	Types   map[string]Schema
}

func (*RancherBaseClientImpl) Action

func (rancherClient *RancherBaseClientImpl) Action(schemaType string, action string,
	existing *Resource, inputObject, respObject interface{}) error

func (*RancherBaseClientImpl) ById

func (rancherClient *RancherBaseClientImpl) ById(schemaType string, id string, respObject interface{}) error

func (*RancherBaseClientImpl) Create

func (rancherClient *RancherBaseClientImpl) Create(schemaType string, createObj interface{}, respObject interface{}) error

func (*RancherBaseClientImpl) Delete

func (rancherClient *RancherBaseClientImpl) Delete(existing *Resource) error
func (rancherClient *RancherBaseClientImpl) GetLink(resource Resource, link string, respObject interface{}) error

func (*RancherBaseClientImpl) GetOpts

func (rancherClient *RancherBaseClientImpl) GetOpts() *ClientOpts

func (*RancherBaseClientImpl) GetTypes

func (rancherClient *RancherBaseClientImpl) GetTypes() map[string]Schema

func (*RancherBaseClientImpl) List

func (rancherClient *RancherBaseClientImpl) List(schemaType string, opts *ListOpts, respObject interface{}) error

func (*RancherBaseClientImpl) Post

func (rancherClient *RancherBaseClientImpl) Post(url string, createObj interface{}, respObject interface{}) error

func (*RancherBaseClientImpl) Reload

func (rancherClient *RancherBaseClientImpl) Reload(existing *Resource, output interface{}) error

func (*RancherBaseClientImpl) Update

func (rancherClient *RancherBaseClientImpl) Update(schemaType string, existing *Resource, updates interface{}, respObject interface{}) error

func (*RancherBaseClientImpl) Websocket

func (rancherClient *RancherBaseClientImpl) Websocket(url string, headers map[string][]string) (*websocket.Conn, *http.Response, error)

type RawResource

type RawResource struct {
	ID      string                 `json:"id,omitempty" yaml:"id,omitempty"`
	Type    string                 `json:"type,omitempty" yaml:"type,omitempty"`
	Schema  *Schema                `json:"-" yaml:"-"`
	Links   map[string]string      `json:"links" yaml:"links"`
	Actions map[string]string      `json:"actions" yaml:"actions"`
	Values  map[string]interface{} `json:",inline"`
}

func (*RawResource) MarshalJSON

func (r *RawResource) MarshalJSON() ([]byte, error)

type ReferenceValidator

type ReferenceValidator interface {
	Validate(resourceType, resourceID string) bool
	Lookup(resourceType, resourceID string) *RawResource
}

type RequestHandler

type RequestHandler func(request *APIContext) error

type Resource

type Resource struct {
	ID      string            `json:"id,omitempty" yaml:"id,omitempty"`
	Type    string            `json:"type,omitempty" yaml:"type,omitempty"`
	Links   map[string]string `json:"links" yaml:"links"`
	Actions map[string]string `json:"actions" yaml:"actions"`
}

type ResourceCollection

type ResourceCollection struct {
	Collection
	Data []Resource `json:"data,omitempty" yaml:"data,omitempty"`
}

type ResponseWriter

type ResponseWriter interface {
	Write(apiContext *APIContext, code int, obj interface{})
}

type Schema

type Schema struct {
	ID                string             `json:"id,omitempty" yaml:"id,omitempty"`
	Type              string             `json:"type,omitempty" yaml:"type,omitempty"`
	Links             map[string]string  `json:"links" yaml:"links"`
	Version           APIVersion         `json:"version" yaml:"version"`
	PluralName        string             `json:"pluralName,omitempty" yaml:"plural_name,omitempty"`
	ResourceMethods   []string           `json:"resourceMethods,omitempty" yaml:"resource_methods,omitempty"`
	ResourceFields    map[string]*Field  `json:"resourceFields,omitempty" yaml:"resource_fields,omitempty"`
	ResourceActions   map[string]*Action `json:"resourceActions,omitempty" yaml:"resource_actions,omitempty"`
	CollectionMethods []string           `json:"collectionMethods,omitempty" yaml:"collection_methods,omitempty"`
	CollectionFields  map[string]*Field  `json:"collectionFields,omitempty" yaml:"collection_fields,omitempty"`
	CollectionActions map[string]*Action `json:"collectionActions,omitempty" yaml:"collection_actions,omitempty"`
	CollectionFilters map[string]*Filter `json:"collectionFilters,omitempty" yaml:"collection_filters,omitempty"`

	ActionHandler ActionHandler  `json:"-" yaml:"-"`
	ListHandler   RequestHandler `json:"-" yaml:"-"`
	CreateHandler RequestHandler `json:"-" yaml:"-"`
	DeleteHandler RequestHandler `json:"-" yaml:"-"`
	UpdateHandler RequestHandler `json:"-" yaml:"-"`
	Formatter     Formatter      `json:"-" yaml:"-"`
	ErrorHandler  ErrorHandler   `json:"-" yaml:"-"`
	Validator     Validator      `json:"-" yaml:"-"`
	Store         Store          `json:"-" yaml:"-"`
}

type SchemaCollection

type SchemaCollection struct {
	Data []Schema
}

type Schemas

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

func NewSchemas

func NewSchemas() *Schemas

func (*Schemas) AddSchema

func (s *Schemas) AddSchema(schema *Schema) *Schemas

func (*Schemas) Err

func (s *Schemas) Err() error

func (*Schemas) Schema

func (s *Schemas) Schema(version *APIVersion, name string) *Schema

func (*Schemas) Schemas

func (s *Schemas) Schemas() []*Schema

func (*Schemas) SchemasForVersion

func (s *Schemas) SchemasForVersion(version APIVersion) map[string]*Schema

func (*Schemas) Versions

func (s *Schemas) Versions() []APIVersion

type Sort

type Sort struct {
	Name    string            `json:"name,omitempty" yaml:"name,omitempty"`
	Order   SortOrder         `json:"order,omitempty" yaml:"order,omitempty"`
	Reverse string            `json:"reverse,omitempty" yaml:"reverse,omitempty"`
	Links   map[string]string `json:"sortLinks,omitempty" yaml:"sort_links,omitempty"`
}

type SortOrder

type SortOrder string

type Store

type Store interface {
	ByID(apiContext *APIContext, schema *Schema, id string) (map[string]interface{}, error)
	List(apiContext *APIContext, schema *Schema, opt *QueryOptions) ([]map[string]interface{}, error)
	Create(apiContext *APIContext, schema *Schema, data map[string]interface{}) (map[string]interface{}, error)
	Update(apiContext *APIContext, schema *Schema, data map[string]interface{}, id string) (map[string]interface{}, error)
	Delete(apiContext *APIContext, schema *Schema, id string) error
}

type URLBuilder

type URLBuilder interface {
	Current() string
	Collection(schema *Schema) string
	RelativeToRoot(path string) string
	//Link(resource Resource, name string) string
	//ReferenceLink(resource Resource) string
	//ReferenceByIdLink(resourceType string, id string) string
	Version(version string) string
	ReverseSort(order SortOrder) string
}

type Validator

type Validator func(request *APIContext, data map[string]interface{}) error

type ValuesMap

type ValuesMap struct {
	Foo map[string]interface{}
}

Jump to

Keyboard shortcuts

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