handlerfactory

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package handlerfactory allows creating HTTP handlers for services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHandler

func MakeHandler(s storage.Store, opts *Options) http.HandlerFunc

MakeHandler created a HTTP handler wrapper around a given service.

func Process added in v0.8.6

func Process(s storage.Store, opts *Options, r *http.Request) (_ proto.Message, ferr error)

Process computes the response for a request.

func RunRMWTx

func RunRMWTx(
	r *http.Request,
	tx storage.Tx,
	op func(*http.Request, string) (proto.Message, error),
	check func(*http.Request) *status.Status,
	save func(*http.Request, storage.Tx, string, map[string]string, string, string) error,
	name string,
	vars map[string]string,
	typ string,
	desc string,
) (proto.Message, error)

RunRMWTx performs a RMW operation. Saves the transaction after performing integraty check. Rolls back the transaction on any failure. TODO: move outside this package. Service handlers should call it.

func ValidateResourceName

func ValidateResourceName(r *http.Request, field string, nameRE map[string]*regexp.Regexp) (string, map[string]string, error)

ValidateResourceName checks if the resource name is valid. Returns the resource name and vars in it.

Types

type Empty added in v0.8.9

type Empty struct {
}

Empty is a empty Service implementation for mixin.

func (*Empty) CheckIntegrity added in v0.8.9

func (s *Empty) CheckIntegrity(r *http.Request) *status.Status

CheckIntegrity empty impl

func (*Empty) Get added in v0.8.9

func (s *Empty) Get(r *http.Request, name string) (proto.Message, error)

Get return 404

func (*Empty) LookupItem added in v0.8.9

func (s *Empty) LookupItem(r *http.Request, name string, vars map[string]string) bool

LookupItem empty impl

func (*Empty) NormalizeInput added in v0.8.9

func (s *Empty) NormalizeInput(r *http.Request, name string, vars map[string]string) error

NormalizeInput empty impl

func (*Empty) Patch added in v0.8.9

func (s *Empty) Patch(r *http.Request, name string) (proto.Message, error)

Patch return 404

func (*Empty) Post added in v0.8.9

func (s *Empty) Post(r *http.Request, name string) (proto.Message, error)

Post return 404

func (*Empty) Put added in v0.8.9

func (s *Empty) Put(r *http.Request, name string) (proto.Message, error)

Put return 404

func (*Empty) Remove added in v0.8.9

func (s *Empty) Remove(r *http.Request, name string) (proto.Message, error)

Remove return 404

func (*Empty) Save added in v0.8.9

func (s *Empty) Save(r *http.Request, tx storage.Tx, name string, vars map[string]string, desc, typeName string) error

Save empty impl

func (*Empty) Setup added in v0.8.9

func (s *Empty) Setup(r *http.Request, tx storage.Tx) (int, error)

Setup empty impl

type Options added in v0.8.6

type Options struct {
	TypeName            string
	NameField           string
	PathPrefix          string
	HasNamedIdentifiers bool
	NameChecker         map[string]*regexp.Regexp
	Service             func() Service
}

Options contains the information about a handler service. Essentially the service interface + some options to the HTTP wrapper for it.

type Service added in v0.8.6

type Service interface {
	Setup(r *http.Request, tx storage.Tx) (int, error)
	// TODO: Have LookupItem() return an error instead, so different errors can be handled
	// properly, e.g. permission denied error vs. lookup error.
	LookupItem(r *http.Request, name string, vars map[string]string) bool
	NormalizeInput(r *http.Request, name string, vars map[string]string) error
	Get(r *http.Request, name string) (proto.Message, error)
	Post(r *http.Request, name string) (proto.Message, error)
	Put(r *http.Request, name string) (proto.Message, error)
	Patch(r *http.Request, name string) (proto.Message, error)
	Remove(r *http.Request, name string) (proto.Message, error)
	CheckIntegrity(r *http.Request) *status.Status
	Save(r *http.Request, tx storage.Tx, name string, vars map[string]string, desc, typeName string) error
}

Service is the role interface for a service that will be wrapped.

Jump to

Keyboard shortcuts

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