restful

package
v0.0.0-...-2f10389 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbstractResource

type AbstractResource struct {
	Logger nuclio.Logger

	Resource Resource
	// contains filtered or unexported fields
}

func NewAbstractResource

func NewAbstractResource(name string, resourceMethods []ResourceMethod) *AbstractResource

func (*AbstractResource) Create

func (ar *AbstractResource) Create(request *http.Request) (string, Attributes, error)

create a resource

func (*AbstractResource) GetAll

func (ar *AbstractResource) GetAll(request *http.Request) map[string]Attributes

return all instances for resources with multiple instances

func (*AbstractResource) GetByID

func (ar *AbstractResource) GetByID(request *http.Request, id string) Attributes

return specific instance by ID

func (*AbstractResource) GetCustomRoutes

func (ar *AbstractResource) GetCustomRoutes() map[string]CustomRoute

returns a list of custom routes for the resource

func (*AbstractResource) GetRouter

func (ar *AbstractResource) GetRouter() chi.Router

for raw routes, those that don't return an attribute

func (*AbstractResource) GetServer

func (ar *AbstractResource) GetServer() interface{}

func (*AbstractResource) GetSingle

func (ar *AbstractResource) GetSingle(request *http.Request) (string, Attributes)

return all instances for resources with single instances

func (*AbstractResource) Initialize

func (ar *AbstractResource) Initialize(parentLogger nuclio.Logger, server interface{}) (chi.Router, error)

func (*AbstractResource) OnAfterInitialize

func (ar *AbstractResource) OnAfterInitialize()

called after initialization

func (*AbstractResource) Register

func (ar *AbstractResource) Register(registry *registry.Registry)

func (*AbstractResource) Remove

func (ar *AbstractResource) Remove(request *http.Request, id string) error

func (*AbstractResource) Update

func (ar *AbstractResource) Update(request *http.Request, id string) (Attributes, error)

type Attributes

type Attributes map[string]interface{}

type CustomRoute

type CustomRoute struct {
	Method    string
	RouteFunc CustomRouteFunc
}

type CustomRouteFunc

type CustomRouteFunc func(*http.Request) (string, map[string]Attributes, bool, int, error)

A custom route returns: resource type: string resources: a map of resource ID, resource attributes single: whether or not the resources should be treated as a single resource (if false, will be returned as list) status code: status code to return error: an error, if something went wrong

type Encoder

type Encoder interface {

	// encode a single resource
	EncodeResource(string, Attributes)

	// encode multiple resources
	EncodeResources(map[string]Attributes)
}

type EncoderFactory

type EncoderFactory interface {

	// create an encoder
	NewEncoder(http.ResponseWriter, string) Encoder
}

type JSONAPIEncoderFactory

type JSONAPIEncoderFactory struct{}

func (*JSONAPIEncoderFactory) NewEncoder

func (jaef *JSONAPIEncoderFactory) NewEncoder(responseWriter http.ResponseWriter, resourceType string) Encoder

type JSONEncoderFactory

type JSONEncoderFactory struct{}

func (*JSONEncoderFactory) NewEncoder

func (jef *JSONEncoderFactory) NewEncoder(responseWriter http.ResponseWriter, resourceType string) Encoder

type Resource

type Resource interface {

	// Called after initialization
	OnAfterInitialize()

	// returns a list of custom routes for the resource
	GetCustomRoutes() map[string]CustomRoute

	// return all instances for resources with multiple instances
	GetAll(request *http.Request) map[string]Attributes

	// return all instances for resources with single instances
	GetSingle(request *http.Request) (string, Attributes)

	// return specific instance by ID
	GetByID(request *http.Request, id string) Attributes

	// returns resource ID, attributes
	Create(request *http.Request) (string, Attributes, error)

	// returns attributes (optionally)
	Update(request *http.Request, id string) (Attributes, error)

	// delete an entity
	Remove(request *http.Request, id string) error
}

type ResourceMethod

type ResourceMethod int
const (
	ResourceMethodGetList ResourceMethod = iota
	ResourceMethodGetDetail
	ResourceMethodCreate
	ResourceMethodUpdate
	ResourceMethodDelete
)

type Server

type Server struct {
	Logger        nuclio.Logger
	Enabled       bool
	ListenAddress string
	Router        chi.Router
	// contains filtered or unexported fields
}

func NewServer

func NewServer(parentLogger nuclio.Logger,
	resourceRegistry *registry.Registry,
	conreteServer interface{}) (*Server, error)

func (*Server) InstallMiddleware

func (s *Server) InstallMiddleware(router chi.Router) error

func (*Server) Start

func (s *Server) Start() error

Jump to

Keyboard shortcuts

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