common

package
v0.0.0-...-ffa69d3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2016 License: MIT Imports: 14 Imported by: 0

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 validates JWT tokens if incoming HTTP requests.

func DisplayAppError

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

DisplayAppError provides app specific error in JSON

func GenerateJWT

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

GenerateJWT generates a new JWT token for authenticated user.

func StartUp

func StartUp()

StartUp bootstrapps the application

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 DataStore

type DataStore struct {
	MongoSession *mgo.Session
}

DataStore for MongoDB

func NewDataStore

func NewDataStore() *DataStore

NewDataStore creates a new DataStore object to be used for each HTTP request.

func (*DataStore) Close

func (ds *DataStore) Close()

Close closes a mgo.Session value. Used to add defer statements for closing the copied session.

func (*DataStore) Collection

func (ds *DataStore) Collection(name string) *mgo.Collection

Collection returns mgo.collection for the given name

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