common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2016 License: MIT Imports: 14 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Trace   *log.Logger
	Info    *log.Logger
	Warning *log.Logger
	Error   *log.Logger
)

Package level variables, which are pointer to log.Logger.

View Source
var AppConfig configuration

AppConfig holds the configuration values from config.json file

Functions

func Authorize

func Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

Authorize Middleware for validating JWT tokens

func DisplayAppError

func DisplayAppError(w http.ResponseWriter, handlerError error, message string, code int)

func GenerateJWT

func GenerateJWT(name, role string) (string, error)

GenerateJWT generates a new JWT token

func GetSession

func GetSession() *mgo.Session

func TokenFromAuthHeader

func TokenFromAuthHeader(r *http.Request) (string, error)

TokenFromAuthHeader is a "TokenExtractor" that takes a given request and extracts the JWT token from the Authorization header.

Types

type AppClaims

type AppClaims struct {
	UserName string `json:"username"`
	Role     string `json:"role"`
	jwt.StandardClaims
}

AppClaims provides custom claim for JWT

type Level

type Level int

Level holds the log level.

const (
	// UNSPECIFIED logs nothing
	UNSPECIFIED Level = iota // 0 :
	// TRACE logs everything
	TRACE // 1
	// INFO logs Info, Warnings and Errors
	INFO // 2
	// WARNING logs Warning and Errors
	WARNING // 3
	// ERROR just logs Errors
	ERROR // 4
)

Jump to

Keyboard shortcuts

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