httpcommand

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

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

Go to latest
Published: Aug 8, 2021 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Generic command dispatcher boilerplate. Takes in POST /api/command/... request and dispatches it to the command handler, and submits possible events to an event log.

Index

Constants

View Source
const (
	CreatedRecordIdHeaderKey = "x-created-record-id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpError

type HttpError struct {
	StatusCode  int // if 0, means errored but error response already sent by middleware
	ErrorCode   string
	Description string
}

error that is sent as a JSON-formatted error

func InvokeSkippingAuthorization

func InvokeSkippingAuthorization(
	cmdStruct command.Command,
	ctx *command.Ctx,
	invoker command.Invoker,
	eventLog eventlog.Log,
) *HttpError

validates command, invokes it and pushes raised events to event log

"SkippingAuthorization" suffix to warn that no authorization checks are performed (i.e. this should only be used for events not triggered by user)

func NewHttpError

func NewHttpError(statusCode int, errorCode string, description string) *HttpError

func Serve

func Serve(
	w http.ResponseWriter,
	r *http.Request,
	mwares httpauth.MiddlewareChainMap,
	commandName string,
	allocators command.Allocators,
	invoker command.Invoker,
	eventLog eventlog.Log,
) *HttpError

func (*HttpError) Error

func (r *HttpError) Error() string

func (*HttpError) ErrorResponseAlreadySentByMiddleware

func (r *HttpError) ErrorResponseAlreadySentByMiddleware() bool

Jump to

Keyboard shortcuts

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