api

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

api

img img

Utility functions and middlewares shared across off-chain services

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyLimiterMiddleware

func BodyLimiterMiddleware(maxBodySize int64) func(handler http.Handler) http.Handler

BodyLimiterMiddleware returns middleware which limits size of data read from request's body.

func FileServerMiddleware

func FileServerMiddleware(prefix, dir string) func(next http.Handler) http.Handler

FileServerMiddleware serves requests with prefix into directory.

func LoggerMiddleware

func LoggerMiddleware(next http.Handler) http.Handler

LoggerMiddleware puts logger with client's info into context.

func RecovererMiddleware

func RecovererMiddleware(next http.Handler) http.Handler

RecovererMiddleware handles panics.

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

RequestIDMiddleware puts request-id to headers and adds it into a logger.

func TimeoutMiddleware

func TimeoutMiddleware(timeout time.Duration) func(next http.Handler) http.Handler

TimeoutMiddleware puts timeout context into request.

func WriteError

func WriteError(w http.ResponseWriter, s int, message string)

WriteError writes error.

func WriteErrorf

func WriteErrorf(w http.ResponseWriter, status int, format string, args ...interface{})

WriteErrorf writes formatted error.

func WriteInternalError

func WriteInternalError(ctx context.Context, w http.ResponseWriter, message string)

WriteInternalError logs error and writes internal error.

func WriteOK

func WriteOK(w http.ResponseWriter, status int, v interface{})

WriteOK writes json body.

func WriteVerifyError

func WriteVerifyError(ctx context.Context, w http.ResponseWriter, err error)

WriteVerifyError writes proper error into w. Possible status codes: 400, 401, 500

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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