Beispiel #1
0
func GetConfig(c context.Context) Config {
	if v, ok := c.GetGlobal(CtxKey("config")); ok {
		return v.(Config)
	}

	return Config{}
}
Beispiel #2
0
func GetRepo(c context.Context) content.Repo {
	if v, ok := c.GetGlobal(CtxKey("repo")); ok {
		return v.(content.Repo)
	}

	return nil
}
Beispiel #3
0
// GetLogger returns the error logger, to be used if an error occurs during
// a request.
func GetLogger(c context.Context) Logger {
	if val, ok := c.GetGlobal(context.BaseCtxKey("logger")); ok {
		return val.(Logger)
	}

	return NewStandardLogger(os.Stderr, "", 0)
}
Beispiel #4
0
// GetRenderer returns the current raw renderer from the context.
func GetRenderer(c context.Context) renderer.Renderer {
	if val, ok := c.GetGlobal(context.BaseCtxKey("renderer")); ok {
		return val.(renderer.Renderer)
	}

	return renderer.NewRenderer("template", "base.tmpl")
}
Beispiel #5
0
// GetConfig is a helper function for getting the current config
// from the request context.
func GetConfig(c context.Context) Config {
	if val, ok := c.GetGlobal(context.BaseCtxKey("config")); ok {
		return val.(Config)
	}

	return Config{}
}
Beispiel #6
0
func GetDB(c context.Context) DB {
	if v, ok := c.GetGlobal(CtxKey("db")); ok {
		return v.(DB)
	}

	conf := GetConfig(c)

	db := NewDB(conf.DB.Driver, conf.DB.Connect)

	if err := db.Connect(); err != nil {
		panic(err)
	}

	return db
}
Beispiel #7
0
// GetDispatcher returns the request dispatcher.
func GetDispatcher(c context.Context) *Dispatcher {
	if val, ok := c.GetGlobal(context.BaseCtxKey("dispatcher")); ok {
		return val.(*Dispatcher)
	}
	return &Dispatcher{}
}