common

package
v0.0.0-...-a433b9e Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidData  = "Could not decode data"
	FetchError   = "Could not fetch data"
	JwtHTTPError = "No valid JWT attached"
)

Functions

func DisplayAppError

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

Writes common errors, only displays message field back to the user

func WithAuth

func WithAuth(a Authorizer) negroni.Handler

Middleware that makes sure each request has a valid JWT from this server.

func WriteJson

func WriteJson(w http.ResponseWriter, message string, data interface{}, code int)

Writes common json responses.

Types

type AppClaims

type AppClaims struct {
	UserClaims
	jwt.StandardClaims
}

type AppResponse

type AppResponse struct {
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

type Auth

type Auth struct {
	Secret        []byte
	SigningMethod jwt.SigningMethod
}

Implements the Authorizer interface

func (*Auth) Authorize

func (a *Auth) Authorize(jwtStr string) (*jwt.Token, error)

Processes jwtString and returns process token if valid

func (*Auth) GenerateJWT

func (a *Auth) GenerateJWT(name string, userId bson.ObjectId) (string, error)

generates a new JWT token

type Authorizer

type Authorizer interface {
	GenerateJWT(string, bson.ObjectId) (string, error)
	Authorize(string) (*jwt.Token, error)
}

type Config

type Config struct {
	Server        string
	MongoServer   string
	MongoUsername string
	MongoPassword string
	DbName        string
	JwtSecret     []byte
}
var AppConfig *Config

Global for common package is the AppConfig

type UserClaims

type UserClaims struct {
	Username string
	UserId   bson.ObjectId
}

Used in middleware and attached to the context

Jump to

Keyboard shortcuts

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