generics

package
v0.0.0-...-785fa05 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenericObjectEndpoint

func GenericObjectEndpoint(w http.ResponseWriter, req *http.Request, processorFunc ObjectProcessorFunc, statuses ...int)

GenericObjectEndpoint takes a function that produces a (result, error) tuple and runs it.

statuses[0] may contain the success status code (optional, defaults to http.StatusOK). statuses[1] may contain the failure status code (optional, defaults to httpStatusInternalServerError).

func GenericObjectsEndpoint

func GenericObjectsEndpoint(w http.ResponseWriter, req *http.Request, processorFunc ObjectsProcessorFunc, statuses ...int)

GenericUserListEndpoint provides automatic pagination.

func RequestAlreadyHandled

func RequestAlreadyHandled() error

Types

type ApiMeta

type ApiMeta struct {
	Limit      int    `json:"limit,omitempty"`
	Next       string `json:"next,omitempty"`
	Previous   string `json:"previous,omitempty"`
	Offset     int    `json:"offset,omitempty"`
	TotalCount int    `json:"totalCount,omitempty"`
}

type ApiResponse

type ApiResponse struct {
	Meta    ApiMeta     `json:"meta,omitempty"`
	Objects interface{} `json:"objects"`
}

func NewApiResponse

func NewApiResponse(objects interface{}, totalCount int) ApiResponse

type ObjectProcessorFunc

type ObjectProcessorFunc func() (object interface{}, err error)

type ObjectsProcessorFunc

type ObjectsProcessorFunc func(limit int64, offset int64) (object interface{}, n int, err error)

Jump to

Keyboard shortcuts

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