rest

package module
v0.0.0-...-1f17819 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, v interface{}) error

func NewRequestID

func NewRequestID(ctx context.Context) context.Context

func RequestID

func RequestID(ctx context.Context) string

func WithAddr

func WithAddr(addr string) func(*API)

func WithCORS

func WithCORS(origins []string, methods []string, headers []string) func(*API)

func WithTracing

func WithTracing() func(*API)

func WriteBadRequest

func WriteBadRequest(w http.ResponseWriter, msg string) error

func WriteForbidden

func WriteForbidden(w http.ResponseWriter, msg string) error

func WriteInternal

func WriteInternal(w http.ResponseWriter, msg string) error

func WriteNotAuthorized

func WriteNotAuthorized(w http.ResponseWriter, msg string) error

func WriteNotFound

func WriteNotFound(w http.ResponseWriter, msg string) error

Types

type API

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

func New

func New(logger *zap.Logger, opts ...func(*API)) *API

func (API) Listen

func (a API) Listen() error

func (API) Route

func (a API) Route(prefix string) *mux.Route

type Error

type Error struct {
	StatusCode int    `json:"code"`
	Status     error  `json:"error"`
	Msg        string `json:"message"`
}

func BadRequest

func BadRequest(err string, args ...interface{}) *Error

func Forbidden

func Forbidden(err string, args ...interface{}) *Error

func Internal

func Internal(err string, args ...interface{}) *Error

func NewError

func NewError(code int, msg string, args ...interface{}) *Error

func NotAuthorized

func NotAuthorized(err string, args ...interface{}) *Error

func NotFound

func NotFound(err string, args ...interface{}) *Error

func (Error) Code

func (e Error) Code() int

func (Error) Err

func (e Error) Err() error

func (Error) String

func (e Error) String() string

func (*Error) WithMessage

func (e *Error) WithMessage(msg string) *Error

func (Error) Write

func (e Error) Write(w http.ResponseWriter) error

type Response

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

func NoContent

func NoContent() Response

func Ok

func Ok(msg string) Response

func (Response) Code

func (r Response) Code() int

func (Response) Message

func (r Response) Message() string

func (Response) WithCookie

func (r Response) WithCookie(cookie *http.Cookie) Response

func (Response) WithData

func (r Response) WithData(d interface{}) Response

func (Response) Write

func (r Response) Write(w http.ResponseWriter) error

Jump to

Keyboard shortcuts

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