common

package
v0.0.0-...-1ae7566 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2017 License: MIT Imports: 14 Imported by: 3

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 AuthorizeRequest

func AuthorizeRequest(next http.Handler) http.Handler

AuthorizeRequest Middleware validates JWT tokens from incoming HTTP requests.

func AuthorizeRequestWithNegroni

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

AuthorizeRequestWithNegroni is a Negroni Middleware that validates JWT tokens

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