コード例 #1
0
ファイル: language.go プロジェクト: rafaeljusto/shelter
// Return the language name to be add to HTTP header response. We are going to normalize
// all the names in lower case
func (l *LanguagePack) Name() string {
	if len(l.SpecificName) > 0 {
		return model.NormalizeLanguage(l.SpecificName)
	}

	return model.NormalizeLanguage(l.GenericName)
}
コード例 #2
0
ファイル: templates.go プロジェクト: rafaeljusto/shelter
// Safe way to add a template concurrently. In reallity we don't have concurrent problems
// while adding templates because there's only one synchronous function that add templates
// (LoadTemplates) and there's no read while we add them, but for consistency we are using
// it
func addTemplate(language string, t *template.Template) {
	language = model.NormalizeLanguage(language)

	templatesLock.Lock()
	defer templatesLock.Unlock()
	templates[language] = t
}
コード例 #3
0
ファイル: templates.go プロジェクト: rafaeljusto/shelter
// While notifing we will use a specific template to send an e-mail for the owner. To
// allow concurrent access over the templates map we should use this function
func getTemplate(language string) *template.Template {
	language = model.NormalizeLanguage(language)

	templatesLock.RLock()
	defer templatesLock.RUnlock()
	return templates[language]
}
コード例 #4
0
ファイル: owner.go プロジェクト: rafaeljusto/shelter
// Convert a owner request object into a owner model object. It can return errors related
// to the e-mail format
func (o *OwnerRequest) toOwnerModel() (model.Owner, error) {
	var owner model.Owner

	email, err := mail.ParseAddress(o.Email)
	if err != nil {
		return owner, err
	}

	if !model.IsValidLanguage(o.Language) {
		return owner, ErrInvalidLanguage
	}

	owner = model.Owner{
		Email:    email,
		Language: model.NormalizeLanguage(o.Language),
	}

	return owner, nil
}