Ejemplo n.º 1
0
// With layout by given name
func (t Tmpl) With(name string, context interface{}) *Layout {
	logr.Debugf("Layout: %s", name)
	l := t.Templates()
	for _, lt := range l {
		logr.Debug(lt.Name())
	}
	return &Layout{
		tmpl:    t,
		context: context,
		name:    name,
	}
}
Ejemplo n.º 2
0
// ToOID converts any given value into the internal OID type
func ToOID(id interface{}) OID {
	switch t := id.(type) {
	case string:
		id := id.(string)
		if bson.IsObjectIdHex(id) {
			return OID(bson.ObjectIdHex(id))
		}
	case bson.ObjectId:
		id := id.(bson.ObjectId)
		return OID(id)
	case OID:
		id := id.(OID)
		return id
	default:
		logr.Debugf("Unable to convert type: %T to mongo.OID", t)
	}
	return nil
}
Ejemplo n.º 3
0
// Load TOML config files from given root dir into conf interface{}. Load loads prod.toml, stage.toml, test.toml,
// and dev.toml in this order so configurations can be inherited and overriden. Load stops after loading the file
// matching the given env value: prod|stage|test|dev.
func Load(root, env string, conf interface{}) {
	file := fmt.Sprintf("%s.toml", env)
	avail := []string{"prod.toml", "stage.toml", "test.toml", "dev.toml"}
	// default to prod
	if !slice.Strings(avail).Contains(file) {
		file = avail[0]
	}
	logr.Infof("Loading config for env %s", env)
	for _, f := range avail {
		f = path.Join(root, f)
		toml.DecodeFile(f, conf)
		// break after
		if f == file {
			break
		}
	}
	logr.Debugf("%+v", conf)
}
Ejemplo n.º 4
0
// Render a template into the layout with the given context
func (l *Layout) Render(name string, w io.Writer) error {
	logr.Debugf("Render: %s", name)
	err := l.tmpl.ExecuteTemplate(w, l.name, name, l.context)
	return err
}