crud

package
v0.0.0-...-7b599ff Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonError

func JsonError(w http.ResponseWriter, err error)

JsonError writes an error to the response

func NewHandler

func NewHandler(crud Frontend) http.Handler

func Next

func Next(filters []Filter, outerOp OuterOperation, innerOp InnerOperation, sort []string, ascending bool, offset, limit int) string

Next build Next URL for filtering

func Prev

func Prev(filters []Filter, outerOp OuterOperation, innerOp InnerOperation, sort []string, ascending bool, offset, limit int) string

Next build Next URL for filtering

Types

type Error

type Error int

Static error type

const (
	NoError Error = iota
	ErrInvalidFilter
	ErrInvalidColumn
	ErrInvalidOperator
	ErrNotFound
	ErrEmptyBody
	ErrInvalidJson
	ErrMissingResourceId
	ErrUnsupportedMethod
	ErrUnauthorized
	ErrMultipartName
	ErrMultipartNeedsContentType
	ErrMultipartTooManyFiles
	ErrMultipartNoFile
	ErrMimeNotSupported
	ErrUnsupportedMediaType
	ErrorMisingAuthHeader
	ErrorInvalidAuthHeader
	ErrorUnexpectedSigningMethod
	ErrorInvalidToken
	ErrorInvalidRole
	ErrorMissingRole
)

func (Error) Error

func (err Error) Error() string

Error implements error

func (Error) HttpError

func (err Error) HttpError() (int, string)

Error implements error

type Filter

type Filter struct {
	Field    string
	Operator Operator
	Values   []string
}

Filter

type Frontend

type Frontend interface {
	Get(r *http.Request) (io.ReadCloser, error)
	Post(r *http.Request) (io.ReadCloser, error)
	Put(r *http.Request) error
	Delete(r *http.Request) error
}

Frontend implements a CRUD frontend service

type InnerOperation

type InnerOperation string
const (
	INNER_AND     InnerOperation = "AND"
	INNER_OR      InnerOperation = "OR"
	INNER_DEFAULT InnerOperation = INNER_AND
)

Operations to merge several values within a single filter

type MediaFrontend

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

func FromMedia

func FromMedia(r Resource, unpoliced Resource, tmpFolder, finalFolder string, mimeTypes map[string]string, ffmpegPath string) MediaFrontend

FromMedia creates a new MediaFrontend

func (MediaFrontend) Delete

func (h MediaFrontend) Delete(r *http.Request) error

Delete handler

func (MediaFrontend) Get

Get handler

func (MediaFrontend) MediaFolder

func (h MediaFrontend) MediaFolder() string

MediaFolder returns the root media folder

func (MediaFrontend) Post

func (h MediaFrontend) Post(r *http.Request) (io.ReadCloser, error)

Post handler

func (MediaFrontend) Put

func (h MediaFrontend) Put(r *http.Request) error

Put handler

type Operator

type Operator string
const (
	OP_EQ   Operator = "eq"
	OP_NE   Operator = "ne"
	OP_GT   Operator = "gt"
	OP_GE   Operator = "ge"
	OP_LT   Operator = "lt"
	OP_LE   Operator = "le"
	OP_LIKE Operator = "like"
)

func (Operator) Valid

func (op Operator) Valid() bool

type OuterOperation

type OuterOperation string
const (
	OUTER_AND     OuterOperation = "AND"
	OUTER_OR      OuterOperation = "OR"
	OUTER_DEFAULT OuterOperation = OUTER_AND
)

Operations to merge several separate filters

type Resource

type Resource interface {
	// Get resource by id
	GetById(context.Context, string) (io.ReadCloser, error)
	// Get resource by filter
	Get(ctx context.Context, filter []Filter, outerOp OuterOperation, innerOp InnerOperation, sort []string, ascending bool, offset, limit int, count bool) (io.ReadCloser, error)
	// Post (create) new resource
	Post(context.Context, io.Reader) (io.ReadCloser, error)
	// Put (update) resource
	Put(context.Context, string, io.Reader) error
	// Delete resource by id
	Delete(context.Context, string) error
}

Resource implements the CRUD operations

type ResourceFrontend

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

ResourceFrontend implements Frontend

func FromResource

func FromResource(r Resource) ResourceFrontend

NewResourceHandler for a given kind of Resource

func (ResourceFrontend) Delete

func (h ResourceFrontend) Delete(r *http.Request) error

Delete handler

func (ResourceFrontend) Get

func (ResourceFrontend) Post

Post handler

func (ResourceFrontend) Put

func (h ResourceFrontend) Put(r *http.Request) error

Put handler

Jump to

Keyboard shortcuts

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