utils

package
v0.0.0-...-52be0da Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyMongoSession = "mongoSession"
	ContextKeySelfBaseURL  = "selfBaseUrl"
	ContextKeyTheme        = "theme"
)
View Source
const (
	// ProductionEnv - a value that indicates about production env
	ProductionEnv = "production"
	// DevelopmentEnv - a value that indicates about development env
	DevelopmentEnv = "development"
	// TestEnv - a value that indicates about test env
	TestEnv = "test"
)
View Source
const (
	PassExpiresInMinutes          = 5
	ClaimedPassesToPurgeAfterDays = 7
)
View Source
const (
	MongoCollectionTeams     = "teams"
	MongoCollectionTimers    = "timers"
	MongoCollectionTeamUsers = "team_users"
	MongoCollectionPasses    = "passes"
)
View Source
const (
	// ConfigFile - path to YML config file
	ConfigFile string = "config.yml"
)

Variables

This section is empty.

Functions

func ConnectToDatabase

func ConnectToDatabase(cfg *config.Config) (*mgo.Session, error)

ConnectToDatabase todo

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats duration to be like HH:MMh regardless of days, months etc

func GetMongoSessionFromContext

func GetMongoSessionFromContext(ctx context.Context) *mgo.Session

func GetSelfBaseURLFromContext

func GetSelfBaseURLFromContext(ctx context.Context) string

func GetSelfURLFromRequest

func GetSelfURLFromRequest(r *http.Request) string

func GetThemeFromContext

func GetThemeFromContext(ctx context.Context) interface{}

func NormalizeSlackCustomCommand

func NormalizeSlackCustomCommand(cmd models.SlackCustomCommand) models.SlackCustomCommand

NormalizeSlackCustomCommand will extract the subcommand form command (see scheme below_) and update the original command: Say the command was: Text = "start Add MongoDB service to docker-compose.yml" The method will do this:

SubCommand = "start"
Text = "Add MongoDB service to docker-compose.yml"

func PT

func PT(value string) time.Time

stands for parse time

func PrintBanner

func PrintBanner(env *Environment)

PrintBanner just a bit of fun

func PutMongoSessionInContext

func PutMongoSessionInContext(parentContext context.Context, session *mgo.Session) context.Context

func PutSelfBaseURLInContext

func PutSelfBaseURLInContext(parentContext context.Context, url string) context.Context

func PutThemeInContext

func PutThemeInContext(parentContext context.Context, theme interface{}) context.Context

func TruncateTables

func TruncateTables(session *mgo.Session)

TruncateTables - clears database tables, supposed to be run in test's setup method

func WhichTimezoneIsMidnightAt

func WhichTimezoneIsMidnightAt(utcHour, utcMinute int) int

WhichTimezoneIsMidnightAt - based up on UTC hour it returns an offset (in seconds) for a timezone where midnight (00:00) is

Types

type Environment

type Environment struct {
	Config     *config.Config
	AppVersion string
	Name       string
	CreatedAt  time.Time
}

Environment is a thing that holds env. specific stuff

func NewEnvironment

func NewEnvironment(environment string, appVersion string) *Environment

NewEnvironment creates a new environment

func (*Environment) MigrateDatabase

func (env *Environment) MigrateDatabase(session *mgo.Session) error

MigrateDatabase - performs database migrations

Jump to

Keyboard shortcuts

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