apiserver

package
v0.0.0-...-6eef5cf Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2014 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package apiserver contains the code that provides a RESTful api service

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound determines if the err is an error which indicates that a specified resource was not found.

func MakeAsync

func MakeAsync(fn WorkFunc) <-chan interface{}

MakeAsync takes a function and executes it, delivering the result in the way required by RESTStorage's Update, Delete, and Create methods.

func NewNotFoundErr

func NewNotFoundErr(kind, name string) error

NewNotFoundErr returns a new error which indicates that the resource of the kind and the name was not found.

Types

type APIServer

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

APIServer is an HTTPHandler that delegates to RESTStorage objects. It handles URLs of the form: ${prefix}/${storage_key}[/${object_name}] Where 'prefix' is an arbitrary string, and 'storage_key' points to a RESTStorage object stored in storage.

TODO: consider migrating this to go-restful which is a more full-featured version of the same thing.

func New

func New(storage map[string]RESTStorage, prefix string) *APIServer

New creates a new APIServer object. 'storage' contains a map of handlers. 'prefix' is the hosting path prefix.

func (*APIServer) ServeHTTP

func (server *APIServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

HTTP Handler interface

func (*APIServer) ServeREST

func (server *APIServer) ServeREST(w http.ResponseWriter, req *http.Request)

ServeREST handles requests to all our RESTStorage objects.

type Operation

type Operation struct {
	ID string
	// contains filtered or unexported fields
}

Operation represents an ongoing action which the server is performing.

func (*Operation) StatusOrResult

func (op *Operation) StatusOrResult() (description interface{}, finished bool)

StatusOrResult returns status information or the result of the operation if it is complete, with a bool indicating true in the latter case.

func (*Operation) WaitFor

func (op *Operation) WaitFor(timeout time.Duration)

WaitFor waits for the specified duration, or until the operation finishes, whichever happens first.

type Operations

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

Operations tracks all the ongoing operations.

func NewOperations

func NewOperations() *Operations

NewOperations returns a new Operations repository.

func (*Operations) Get

func (ops *Operations) Get(id string) *Operation

Get returns the operation with the given ID, or nil

func (*Operations) List

func (ops *Operations) List() api.ServerOpList

List operations for an API client.

func (*Operations) NewOperation

func (ops *Operations) NewOperation(from <-chan interface{}) *Operation

NewOperation adds a new operation. It is lock-free.

type RESTStorage

type RESTStorage interface {
	// List selects resources in the storage which match to the selector.
	List(labels.Selector) (interface{}, error)

	// Get finds a resource in the storage by id and returns it.
	// Although it can return an arbitrary error value, IsNotFound(err) is true for the returned error value err when the specified resource is not found.
	Get(id string) (interface{}, error)

	// Delete finds a resource in the storage and deletes it.
	// Although it can return an arbitrary error value, IsNotFound(err) is true for the returned error value err when the specified resource is not found.
	Delete(id string) (<-chan interface{}, error)

	Extract(body []byte) (interface{}, error)
	Create(interface{}) (<-chan interface{}, error)
	Update(interface{}) (<-chan interface{}, error)
}

RESTStorage is a generic interface for RESTful storage services Resources whicih are exported to the RESTful API of apiserver need to implement this interface.

type ResourceWatcher

type ResourceWatcher interface {
	WatchAll() (watch.Interface, error)
	WatchSingle(id string) (watch.Interface, error)
}

ResourceWatcher should be implemented by all RESTStorage objects that want to offer the ability to watch for changes through the watch api.

type WatchServer

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

WatchServer serves a watch.Interface over a websocket or vanilla HTTP.

func (*WatchServer) HandleWS

func (w *WatchServer) HandleWS(ws *websocket.Conn)

HandleWS implements a websocket handler.

func (*WatchServer) ServeHTTP

func (self *WatchServer) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP serves a series of JSON encoded events via straight HTTP with Transfer-Encoding: chunked.

type WorkFunc

type WorkFunc func() (result interface{}, err error)

WorkFunc is used to perform any time consuming work for an api call, after the input has been validated. Pass one of these to MakeAsync to create an appropriate return value for the Update, Delete, and Create methods.

Jump to

Keyboard shortcuts

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