Documentation ¶
Index ¶
- Constants
- Variables
- func BodyLimiterMiddleware(maxBodySize int64) func(handler http.Handler) http.Handler
- func FileServerMiddleware(prefix, dir string) func(next http.Handler) http.Handler
- func GetAddressFromPubKey(k string) (sdk.AccAddress, error)
- func GetMessageToSign(r *http.Request) ([]byte, error)
- func GetSignature(r *http.Request) (crypto.PubKey, []byte, error)
- func LoggerMiddleware(next http.Handler) http.Handler
- func RecovererMiddleware(next http.Handler) http.Handler
- func RequestIDMiddleware(next http.Handler) http.Handler
- func Sign(r *http.Request, pk crypto.PrivKey) error
- func TimeoutMiddleware(timeout time.Duration) func(next http.Handler) http.Handler
- func Verify(r *http.Request) error
- func WriteError(w http.ResponseWriter, status int, message string)
- func WriteErrorf(w http.ResponseWriter, status int, format string, args ...interface{})
- func WriteInternalError(ctx context.Context, w http.ResponseWriter, err error, message string)
- func WriteInternalErrorf(ctx context.Context, w http.ResponseWriter, err error, format string, ...)
- func WriteOK(w http.ResponseWriter, status int, v interface{})
- func WriteVerifyError(ctx context.Context, w http.ResponseWriter, err error)
- type Error
Constants ¶
const PublicKeyHeader = "Public-Key"
PublicKeyHeader is name for public key http header.
const SignatureHeader = "Signature"
SignatureHeader is name for signature http header.
Variables ¶
var ErrInvalidPublicKey = fmt.Errorf("%w: public key is invalid", ErrInvalidRequest)
ErrInvalidPublicKey is returned when public key is invalid.
var ErrInvalidRequest = errors.New("invalid request")
ErrInvalidRequest is returned when request is invalid.
var ErrInvalidSignature = fmt.Errorf("%w: signature is invalid", ErrInvalidRequest)
ErrInvalidSignature is returned when signature is invalid.
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when object is not found.
var ErrNotVerified = errors.New("failed to verify message")
ErrNotVerified is returned when signature is wrong.
Functions ¶
func BodyLimiterMiddleware ¶
BodyLimiterMiddleware returns middleware which limits size of data read from request's body.
func FileServerMiddleware ¶
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
GetMessageToSign returns message to sign.
func GetSignature ¶ added in v0.0.5
func LoggerMiddleware ¶
LoggerMiddleware puts logger with client's info into context.
func RecovererMiddleware ¶
RecovererMiddleware handles panics.
func RequestIDMiddleware ¶
RequestIDMiddleware puts request-id to headers and adds it into a logger.
func TimeoutMiddleware ¶
TimeoutMiddleware puts timeout context into request.
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 ¶
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.