api

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

README

api

img img

Utility functions and middlewares shared across off-chain services

Documentation

Index

Constants

View Source
const PublicKeyHeader = "Public-Key"

PublicKeyHeader is name for public key http header.

View Source
const SignatureHeader = "Signature"

SignatureHeader is name for signature http header.

Variables

View Source
var ErrInvalidPublicKey = fmt.Errorf("%w: public key is invalid", ErrInvalidRequest)

ErrInvalidPublicKey is returned when public key is invalid.

View Source
var ErrInvalidRequest = errors.New("invalid request")

ErrInvalidRequest is returned when request is invalid.

View Source
var ErrInvalidSignature = fmt.Errorf("%w: signature is invalid", ErrInvalidRequest)

ErrInvalidSignature is returned when signature is invalid.

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when object is not found.

View Source
var ErrNotVerified = errors.New("failed to verify message")

ErrNotVerified is returned when signature is wrong.

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 GetAddressFromPubKey added in v0.1.0

func GetAddressFromPubKey(k string) (sdk.AccAddress, error)

func GetMessageToSign added in v0.0.5

func GetMessageToSign(r *http.Request) ([]byte, error)

GetMessageToSign returns message to sign.

func GetSignature added in v0.0.5

func GetSignature(r *http.Request) (crypto.PubKey, []byte, error)

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 Sign added in v0.0.5

func Sign(r *http.Request, pk crypto.PrivKey) error

Sign signs http request.

func TimeoutMiddleware

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

TimeoutMiddleware puts timeout context into request.

func Verify added in v0.0.5

func Verify(r *http.Request) error

Verify verifies request's signature with public key.

func WriteError

func WriteError(w http.ResponseWriter, status 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, err error, message string)

WriteInternalError logs error and writes internal error.

func WriteInternalErrorf added in v0.0.2

func WriteInternalErrorf(ctx context.Context, w http.ResponseWriter, err error, format string, args ...interface{})

WriteInternalErrorf logs formatted 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 sign verification(auth) error with proper status.

Types

type Error added in v0.0.3

type Error struct {
	Error string `json:"error"`
}

Error ... swagger:model

Directories

Path Synopsis
Package health contains code for health checks.
Package health contains code for health checks.

Jump to

Keyboard shortcuts

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