restful

package
v0.0.0-...-f7ae98d Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Apache-2.0 Imports: 14 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 logger.Logger

	Resource Resource
	// contains filtered or unexported fields
}

AbstractResource is base for resources

func NewAbstractResource

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

NewAbstractResource creates a new AbstractResource

func (*AbstractResource) Create

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

Create a resource

func (*AbstractResource) Delete

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

Delete a resource

func (*AbstractResource) GetAll

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

GetAll returns all instances for resources with multiple instances

func (*AbstractResource) GetByID

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

GetByID return specific instance by ID

func (*AbstractResource) GetCustomRoutes

func (ar *AbstractResource) GetCustomRoutes() ([]CustomRoute, error)

GetCustomRoutes returns a list of custom routes for the resource

func (*AbstractResource) GetRouter

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

GetRouter returns raw routes, those that don't return an attribute

func (*AbstractResource) GetServer

func (ar *AbstractResource) GetServer() Server

GetServer returns the server

func (*AbstractResource) Initialize

func (ar *AbstractResource) Initialize(parentLogger logger.Logger, server Server) (chi.Router, error)

Initialize initializes the resource

func (*AbstractResource) OnAfterInitialize

func (ar *AbstractResource) OnAfterInitialize() error

OnAfterInitialize is called after initialization

func (*AbstractResource) Register

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

Register registers a registry

func (*AbstractResource) Update

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

Update a resource

type AbstractServer

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

func NewAbstractServer

func NewAbstractServer(parentLogger logger.Logger,
	resourceRegistry *registry.Registry,
	server Server,
	configuration *platformconfig.WebServer) (*AbstractServer, error)

func (*AbstractServer) InstallMiddleware

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

func (*AbstractServer) Start

func (s *AbstractServer) Start() error

type Attributes

type Attributes map[string]interface{}

Attributes are resource attributes

type CustomRoute

type CustomRoute struct {
	Pattern   string
	Method    string
	RouteFunc CustomRouteFunc
}

CustomRoute is a custom route definition

type CustomRouteFunc

type CustomRouteFunc func(*http.Request) (*CustomRouteFuncResponse, error)

CustomRouteFunc is a handler function for a custom route

type CustomRouteFuncResponse

type CustomRouteFuncResponse struct {
	ResourceType string
	Resources    map[string]Attributes
	Headers      map[string]string
	// Whether or not the resources should be treated as a single resource (if
	// false, will be returned as list)
	Single     bool
	StatusCode int
}

CustomRouteFuncResponse is what CustomRouteFunc returns

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 ErrorContainsVerifier

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

ErrorContainsVerifier verifies contents of returned errors

func NewErrorContainsVerifier

func NewErrorContainsVerifier(logger logger.Logger, expectedStrings []string) *ErrorContainsVerifier

NewErrorContainsVerifier returns a new ErrorContainsVerifier

func (*ErrorContainsVerifier) Verify

func (ecv *ErrorContainsVerifier) Verify(response map[string]interface{}) bool

Verify verifies that the returned response contains the given errors

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 {

	// Initialize the concrete server
	Initialize(logger.Logger, Server) (chi.Router, error)

	// Called after initialization
	OnAfterInitialize() error

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

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

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

	// 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
	Delete(request *http.Request, id string) error
}

Resource interface

type ResourceMethod

type ResourceMethod int

ResourceMethod is the method of the resource

const (
	ResourceMethodGetList ResourceMethod = iota
	ResourceMethodGetDetail
	ResourceMethodCreate
	ResourceMethodUpdate
	ResourceMethodDelete
)

Possible resource methods

type Server

type Server interface {

	// InstallMiddleware installs middlewares on a router
	InstallMiddleware(router chi.Router) error
}

Server

Jump to

Keyboard shortcuts

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