handlers

package
v0.0.0-...-bcc45f8 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrorTokenInvalid error if token is invalid
	ErrorTokenInvalid error = errors.New("Token invalid")
	//ErrorTokenEmpty error if token is empty
	ErrorTokenEmpty error = errors.New("Token empty")
)
View Source
var AllowedSchemes = []string{"http", "https"}

AllowedSchemes schemes that are allowed in urls

Functions

func LogError

func LogError(err error, context ...map[string]interface{}) bool

LogError returns true on error

func Login

func Login(handlerData HandlerData, w http.ResponseWriter, r *http.Request)

Login login handler -> /user/login

func NewRouter

func NewRouter(config *models.Config, db *gorm.DB) *mux.Router

NewRouter create new router

func Ping

func Ping(handlerData HandlerData, w http.ResponseWriter, r *http.Request)

Ping handles ping request

func Register

func Register(handlerData HandlerData, w http.ResponseWriter, r *http.Request)

Register register handler -> /user/create

func RouteHandler

func RouteHandler(requestType requestType, handlerData *HandlerData, inner RouteFunction, name string) http.Handler

RouteHandler logs stuff

Types

type AuthHandler

type AuthHandler struct {
	Request *http.Request
}

AuthHandler handler for http auth

func NewAuthHandler

func NewAuthHandler(request *http.Request) *AuthHandler

NewAuthHandler returns a new AuthHandler

func (AuthHandler) GetBearer

func (authHandler AuthHandler) GetBearer() string

GetBearer return the bearer token

func (AuthHandler) IsInvalid

func (authHandler AuthHandler) IsInvalid(err error) bool

IsInvalid return true if err is invalid

type HTTPMethod

type HTTPMethod string

HTTPMethod http method. GET, POST, DELETE, HEADER, etc...

const (
	GetMethod    HTTPMethod = "GET"
	POSTMethod   HTTPMethod = "POST"
	PUTMethod    HTTPMethod = "PUT"
	DeleteMethod HTTPMethod = "DELETE"
)

HTTP methods

type HandlerData

type HandlerData struct {
	Config *models.Config
	Db     *gorm.DB
	User   *models.User
}

HandlerData handlerData for web

type Route

type Route struct {
	Name        string
	Method      HTTPMethod
	Pattern     string
	HandlerFunc RouteFunction
	HandlerType requestType
}

Route for REST

type RouteFunction

type RouteFunction func(HandlerData, http.ResponseWriter, *http.Request)

RouteFunction function for handling a route

type Routes

type Routes []Route

Routes all REST routes

Jump to

Keyboard shortcuts

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