types

package
v0.0.0-...-844817b Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 108

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ChangeAPIEvent = "resource.change"
	RemoveAPIEvent = "resource.remove"
	CreateAPIEvent = "resource.create"
)
View Source
var ReservedFields = map[string]bool{
	"id":      true,
	"type":    true,
	"links":   true,
	"actions": true,
}

Functions

func APIChan

func APIChan(c <-chan APIEvent, f func(APIObject) APIObject) chan APIEvent

func JSONEncoder

func JSONEncoder(writer io.Writer, v interface{}) error

func JSONLinesEncoder

func JSONLinesEncoder(writer io.Writer, v interface{}) error

func Name

func Name(d map[string]interface{}) string

func Namespace

func Namespace(d map[string]interface{}) string

func YAMLEncoder

func YAMLEncoder(writer io.Writer, v interface{}) error

Types

type APIEvent

type APIEvent struct {
	Name         string    `json:"name,omitempty"`
	Namespace    string    `json:"namespace,omitempty"`
	ResourceType string    `json:"resourceType,omitempty"`
	ID           string    `json:"id,omitempty"`
	Selector     string    `json:"selector,omitempty"`
	Revision     string    `json:"revision,omitempty"`
	Object       APIObject `json:"-"`
	Error        error     `json:"-"`
	// Data is the output format of the object
	Data interface{} `json:"data,omitempty"`
}

type APIObject

type APIObject struct {
	Type     string
	ID       string
	Object   interface{}
	Warnings []Warning
}

func DefaultByID

func DefaultByID(store Store, apiOp *APIRequest, schema *APISchema, id string) (APIObject, error)

func (*APIObject) Data

func (a *APIObject) Data() data.Object

func (*APIObject) Name

func (a *APIObject) Name() string

func (*APIObject) Namespace

func (a *APIObject) Namespace() string

type APIObjectList

type APIObjectList struct {
	Revision string
	Continue string
	Pages    int
	Count    int
	Objects  []APIObject
	Warnings []Warning
}

type APIRequest

type APIRequest struct {
	Action         string
	Name           string
	Type           string
	Link           string
	Method         string
	Namespace      string
	Schema         *APISchema
	Schemas        *APISchemas
	Query          url.Values
	ResponseFormat string
	ResponseWriter ResponseWriter
	ErrorHandler   ErrorHandler
	URLPrefix      string
	URLBuilder     URLBuilder
	AccessControl  AccessControl

	Request  *http.Request
	Response http.ResponseWriter
}

func GetAPIContext

func GetAPIContext(ctx context.Context) *APIRequest

func StoreAPIContext

func StoreAPIContext(apiOp *APIRequest) *APIRequest

func (*APIRequest) Clone

func (r *APIRequest) Clone() *APIRequest

func (*APIRequest) Context

func (r *APIRequest) Context() context.Context

func (*APIRequest) GetUser

func (r *APIRequest) GetUser() string

func (*APIRequest) GetUserInfo

func (r *APIRequest) GetUserInfo() (user.Info, bool)

func (*APIRequest) Option

func (r *APIRequest) Option(key string) string

func (*APIRequest) WithContext

func (r *APIRequest) WithContext(ctx context.Context) *APIRequest

func (*APIRequest) WriteError

func (r *APIRequest) WriteError(err error)

func (*APIRequest) WriteResponse

func (r *APIRequest) WriteResponse(code int, obj APIObject)

func (*APIRequest) WriteResponseList

func (r *APIRequest) WriteResponseList(code int, list APIObjectList)

type APISchema

type APISchema struct {
	*schemas.Schema

	ActionHandlers      map[string]http.Handler `json:"-"`
	LinkHandlers        map[string]http.Handler `json:"-"`
	ListHandler         RequestListHandler      `json:"-"`
	ByIDHandler         RequestHandler          `json:"-"`
	CreateHandler       RequestHandler          `json:"-"`
	DeleteHandler       RequestHandler          `json:"-"`
	UpdateHandler       RequestHandler          `json:"-"`
	Formatter           Formatter               `json:"-"`
	RequestModifier     RequestModifier         `json:"-"`
	CollectionFormatter CollectionFormatter     `json:"-"`
	ErrorHandler        ErrorHandler            `json:"-"`
	Store               Store                   `json:"-"`
}

func (*APISchema) DeepCopy

func (a *APISchema) DeepCopy() *APISchema

type APISchemas

type APISchemas struct {
	InternalSchemas *schemas.Schemas
	Schemas         map[string]*APISchema

	Attributes map[string]interface{}
	// contains filtered or unexported fields
}

func EmptyAPISchemas

func EmptyAPISchemas() *APISchemas

func (*APISchemas) AddSchema

func (a *APISchemas) AddSchema(schema APISchema) error

func (*APISchemas) AddSchemas

func (a *APISchemas) AddSchemas(schema *APISchemas) error

func (*APISchemas) Import

func (a *APISchemas) Import(obj interface{}) (*APISchema, error)

func (*APISchemas) LookupSchema

func (a *APISchemas) LookupSchema(name string) *APISchema

func (*APISchemas) MustAddSchema

func (a *APISchemas) MustAddSchema(obj APISchema) *APISchemas

func (*APISchemas) MustAddSchemas

func (a *APISchemas) MustAddSchemas(schemas *APISchemas) *APISchemas

func (*APISchemas) MustImportAndCustomize

func (a *APISchemas) MustImportAndCustomize(obj interface{}, f func(*APISchema))

func (*APISchemas) ShallowCopy

func (a *APISchemas) ShallowCopy() *APISchemas

type AccessControl

type AccessControl interface {
	CanAction(apiOp *APIRequest, schema *APISchema, name string) error
	CanCreate(apiOp *APIRequest, schema *APISchema) error
	CanList(apiOp *APIRequest, schema *APISchema) error
	CanGet(apiOp *APIRequest, schema *APISchema) error
	CanUpdate(apiOp *APIRequest, obj APIObject, schema *APISchema) error
	CanDelete(apiOp *APIRequest, obj APIObject, schema *APISchema) error
	CanWatch(apiOp *APIRequest, schema *APISchema) error
	CanDo(apiOp *APIRequest, resource, verb, namespace, name string) error
}

type Collection

type Collection struct {
	Type         string            `json:"type,omitempty"`
	Links        map[string]string `json:"links"`
	CreateTypes  map[string]string `json:"createTypes,omitempty"`
	Actions      map[string]string `json:"actions"`
	ResourceType string            `json:"resourceType"`
	Pagination   *Pagination       `json:"pagination,omitempty"`
	Revision     string            `json:"revision,omitempty"`
	Continue     string            `json:"continue,omitempty"`
	Pages        int               `json:"pages,omitempty"`
	Count        int               `json:"count,omitempty"`
}

func (*Collection) AddAction

func (c *Collection) AddAction(apiOp *APIRequest, name string)

type CollectionFormatter

type CollectionFormatter func(request *APIRequest, collection *GenericCollection)

type Condition

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

type ErrorHandler

type ErrorHandler func(request *APIRequest, err error)

type Formatter

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

func FormatterChain

func FormatterChain(formatter Formatter, next Formatter) Formatter

type GenericCollection

type GenericCollection struct {
	Collection
	Data []*RawResource `json:"data"`
}

type ModifierType

type ModifierType string
var (
	ModifierEQ      ModifierType = "eq"
	ModifierNE      ModifierType = "ne"
	ModifierNull    ModifierType = "null"
	ModifierNotNull ModifierType = "notnull"
	ModifierIn      ModifierType = "in"
	ModifierNotIn   ModifierType = "notin"
)

type NamedResource

type NamedResource struct {
	Resource
	Name        string `json:"name"`
	Description string `json:"description"`
}

type NamedResourceCollection

type NamedResourceCollection struct {
	Collection
	Data []NamedResource `json:"data,omitempty"`
}

type Pagination

type Pagination struct {
	Limit   int    `json:"limit,omitempty"`
	First   string `json:"first,omitempty"`
	Next    string `json:"next,omitempty"`
	Partial bool   `json:"partial,omitempty"`
}

type RawResource

type RawResource struct {
	ID          string            `json:"id,omitempty" yaml:"id,omitempty"`
	Type        string            `json:"type,omitempty" yaml:"type,omitempty"`
	Schema      *APISchema        `json:"-" yaml:"-"`
	Links       map[string]string `json:"links" yaml:"links,omitempty"`
	Actions     map[string]string `json:"actions,omitempty" yaml:"actions,omitempty"`
	ActionLinks bool              `json:"-" yaml:"-"`
	APIObject   APIObject         `json:"-" yaml:"-"`
}

func (*RawResource) AddAction

func (r *RawResource) AddAction(apiOp *APIRequest, name string)

func (*RawResource) MarshalJSON

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

type RequestHandler

type RequestHandler func(request *APIRequest) (APIObject, error)

type RequestListHandler

type RequestListHandler func(request *APIRequest) (APIObjectList, error)

type RequestModifier

type RequestModifier func(request *APIRequest, schema *APISchema) *APISchema

type Resource

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

type ResponseWriter

type ResponseWriter interface {
	Write(apiOp *APIRequest, code int, obj APIObject)
	WriteList(apiOp *APIRequest, code int, obj APIObjectList)
}

type Store

type Store interface {
	ByID(apiOp *APIRequest, schema *APISchema, id string) (APIObject, error)
	List(apiOp *APIRequest, schema *APISchema) (APIObjectList, error)
	Create(apiOp *APIRequest, schema *APISchema, data APIObject) (APIObject, error)
	Update(apiOp *APIRequest, schema *APISchema, data APIObject, id string) (APIObject, error)
	Delete(apiOp *APIRequest, schema *APISchema, id string) (APIObject, error)
	Watch(apiOp *APIRequest, schema *APISchema, w WatchRequest) (chan APIEvent, error)
}

type URLBuilder

type URLBuilder interface {
	Current() string

	Collection(schema *APISchema) string
	CollectionAction(schema *APISchema, action string) string
	ResourceLink(schema *APISchema, id string) string
	Link(schema *APISchema, id string, linkName string) string
	Action(schema *APISchema, id string, action string) string
	Marker(marker string) string

	RelativeToRoot(path string) string
}

type Warning

type Warning struct {
	Code  int
	Agent string
	Text  string
}

type WatchRequest

type WatchRequest struct {
	Revision string
	ID       string
	Selector string
}

Jump to

Keyboard shortcuts

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