Пример #1
// 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
// 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)

	defer templatesLock.Unlock()
	templates[language] = t
Пример #3
// 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)

	defer templatesLock.RUnlock()
	return templates[language]
Пример #4
// 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