app

package
v0.0.0-...-2abeed9 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2017 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config appConfig

Config stores the application-wide configurations

View Source
var Version = "1.0"

Version specifies the current version of the application. The value of this variable is replaced with the latest git tag by "make" while building or running the application.

Functions

func Init

func Init(logger *logrus.Logger) routing.Handler

Init returns a middleware that prepares the request context and processing environment. The middleware will populate RequestContext, handle possible panics and errors from the processing handlers, and add an access log entry.

func LoadConfig

func LoadConfig(configPaths ...string) error

LoadConfig loads configuration from the given list of paths and populates it into the Config variable. The configuration file(s) should be named as app.yaml. Environment variables with the prefix "RESTFUL_" in their names are also read automatically.

func Transactional

func Transactional(db *dbx.DB) routing.Handler

Transactional returns a handler that encloses the nested handlers with a DB transaction. If a nested handler returns an error or a panic happens, it will rollback the transaction. Otherwise it will commit the transaction after the nested handlers finish execution. By calling app.Context.SetRollback(true), you may also explicitly request to rollback the transaction.

Types

type Logger

type Logger interface {
	// adds a field that should be added to every message being logged
	SetField(name, value string)

	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
}

Logger defines the logger interface that is exposed via RequestScope.

func NewLogger

func NewLogger(l *logrus.Logger, fields logrus.Fields) Logger

NewLogger creates a logger object with the specified logrus.Logger and the fields that should be added to every message.

type RequestScope

type RequestScope interface {
	Logger
	// UserID returns the ID of the user for the current request
	UserID() string
	// SetUserID sets the ID of the currently authenticated user
	SetUserID(id string)
	// RequestID returns the ID of the current request
	RequestID() string
	// Tx returns the currently active database transaction that can be used for DB query purpose
	Tx() *dbx.Tx
	// SetTx sets the database transaction
	SetTx(tx *dbx.Tx)
	// Rollback returns a value indicating whether the current database transaction should be rolled back
	Rollback() bool
	// SetRollback sets a value indicating whether the current database transaction should be rolled back
	SetRollback(bool)
	// Now returns the timestamp representing the time when the request is being processed
	Now() time.Time
}

RequestScope contains the application-specific information that are carried around in a request.

func GetRequestScope

func GetRequestScope(c *routing.Context) RequestScope

GetRequestScope returns the RequestScope of the current request.

Jump to

Keyboard shortcuts

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