helper

package module
v0.0.0-...-fc9c494 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2020 License: MIT Imports: 13 Imported by: 0

README

go_helper

Golang Helper Library

Contains HTTP, AMQP, WebSocket middlewares

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyErr          = errors.New("")
	ErrInvalidToken   = errors.New("invalid token")
	ErrUnexpiredToken = errors.New("can't generate, unexpired token")
)

Functions

func Err

func Err(err error) *amqp.Message

func GenerateToken

func GenerateToken(claims *Claims) (string, error)

func ListenAndServe

func ListenAndServe(srv amqp.Server) error

func OK

func OK(body interface{}) *amqp.Message

func UnmarshalJSON

func UnmarshalJSON(r *http.Request, item interface{}) error

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

func WebSocketMDW

func WebSocketMDW(conn *websocket.Conn, ticker time.Duration, cmd interface{}, fn func(interface{}) (interface{}, error))

Types

type AMQPResponse

type AMQPResponse struct {
	Message string      `json:"msg,omitempty"`
	Error   error       `json:"err,omitempty"`
	Body    interface{} `json:"body,omitempty"`
}

func (*AMQPResponse) AMQP

func (amqpResp *AMQPResponse) AMQP() *amqp.Message

type Claims

type Claims struct {
	PhoneNumber string `json:"phone"`
	IsManager   bool   `json:"mng"`
	jwt.StandardClaims
}

type Handler

type Handler struct {
	Tkn bool
	H   func(w http.ResponseWriter, r *http.Request) (*Response, error)
}

func NewHandler

func NewHandler(H func(w http.ResponseWriter, r *http.Request) (*Response, error)) Handler

func NewHandlerWithACL

func NewHandlerWithACL(H func(w http.ResponseWriter, r *http.Request) (*Response, error)) Handler

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HttpError

type HttpError interface {
	error
	Status() int
}

type MiddleHttpError

type MiddleHttpError struct {
	Code int
	Err  error
}

func (MiddleHttpError) Error

func (se MiddleHttpError) Error() string

func (MiddleHttpError) Status

func (se MiddleHttpError) Status() int

type Response

type Response struct {
	Body       interface{}
	StatusCode int
}

func Middleware

func Middleware(w http.ResponseWriter, r *http.Request, next func(w http.ResponseWriter, r *http.Request) (*Response, error)) (*Response, error)

Jump to

Keyboard shortcuts

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