rest

package
v0.0.0-...-a4452f2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicatedResource = errors.New("duplicated resource")

ErrDuplicatedResource is returned when a resource is duplicated

View Source
var ErrNotFound = errors.New("resource not found")

ErrNotFound is returned when a resource could not be found

View Source
var ErrNotUpdatable = errors.New("resource not updatable")

ErrNotUpdatable is returned when an resource could not be modified

Functions

This section is empty.

Types

type BasicAPIHandler

type BasicAPIHandler struct {
	ResourceHandler ResourceHandler
	EtcdClient      *etcdclient.Client
}

BasicAPIHandler basic implementation of an Handler, should be used as embedded struct for the most part of the resource

func (*BasicAPIHandler) AsyncWatch

AsyncWatch registers a new resource watcher

func (*BasicAPIHandler) Create

func (h *BasicAPIHandler) Create(resource Resource, createOpts *CreateOptions) error

Create a new resource in Etcd

func (*BasicAPIHandler) Decorate

func (h *BasicAPIHandler) Decorate(resource Resource)

Decorate the resource

func (*BasicAPIHandler) Delete

func (h *BasicAPIHandler) Delete(id string) error

Delete a resource

func (*BasicAPIHandler) Get

func (h *BasicAPIHandler) Get(id string) (Resource, bool)

Get a specific resource

func (*BasicAPIHandler) Index

func (h *BasicAPIHandler) Index() map[string]Resource

Index returns the list of resource available in Etcd

func (*BasicAPIHandler) Name

func (h *BasicAPIHandler) Name() string

Name returns the resource name

func (*BasicAPIHandler) New

func (h *BasicAPIHandler) New() Resource

New creates a new resource

func (*BasicAPIHandler) Unmarshal

func (h *BasicAPIHandler) Unmarshal(b []byte) (resource Resource, err error)

Unmarshal deserialize a resource

func (*BasicAPIHandler) Update

func (h *BasicAPIHandler) Update(id string, resource Resource) (Resource, bool, error)

Update a resource

type BasicResource

type BasicResource struct {
	UUID string `yaml:"UUID"`
}

BasicResource is a resource with a unique identifier easyjson:json swagger:ignore

func (*BasicResource) GetID

func (b *BasicResource) GetID() string

GetID returns the resource ID

func (*BasicResource) GetName

func (b *BasicResource) GetName() string

GetName returns the resource name

func (*BasicResource) SetID

func (b *BasicResource) SetID(i string)

SetID sets the resource ID

func (*BasicResource) Validate

func (b *BasicResource) Validate() error

Validate integrity of the resource

type BasicStoppableWatcher

type BasicStoppableWatcher struct {
	StoppableWatcher
	// contains filtered or unexported fields
}

BasicStoppableWatcher basic implementation of a resource watcher

func (*BasicStoppableWatcher) Stop

func (s *BasicStoppableWatcher) Stop()

Stop the resource watcher

type CreateOptions

type CreateOptions struct {
	TTL time.Duration
}

CreateOptions describes the available options when creating a resource

type Handler

type Handler interface {
	Name() string
	New() Resource
	Index() map[string]Resource
	Get(id string) (Resource, bool)
	Decorate(resource Resource)
	Create(resource Resource, createOpts *CreateOptions) error
	Delete(id string) error
	Update(id string, resource Resource) (Resource, bool, error)
}

Handler describes resources for each API

type Resource

type Resource interface {
	GetID() string
	SetID(string)
	GetName() string
	Validate() error
}

Resource used as interface resources for each API

type ResourceHandler

type ResourceHandler interface {
	Name() string
	New() Resource
}

ResourceHandler aims to creates new resource of an API

type ResourceWatcher

type ResourceWatcher interface {
	AsyncWatch(f WatcherCallback) StoppableWatcher
}

ResourceWatcher asynchronous interface

type StoppableWatcher

type StoppableWatcher interface {
	Stop()
}

StoppableWatcher interface

type WatchableHandler

type WatchableHandler interface {
	Handler
	ResourceWatcher
}

WatchableHandler describes a handler that can watched for updates

type WatcherCallback

type WatcherCallback func(action string, id string, resource Resource)

WatcherCallback callback called by the resource watcher

Jump to

Keyboard shortcuts

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