aboutsummaryrefslogtreecommitdiffstats
path: root/util.go
blob: 78333f3635e8dc14e398eabb783214ddf3b195f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

// Minimal Error type... is there a better way?
type Error string

func (e Error) Error() string {
	return string(e)
}

type EmailAddress string
type Password string
type Url string

// "Slug" string with limited ASCII character set, good for URLs.
// Lowercase alphanumeric plus '_' allowed. 
type ShortName string

func isShortName(s string) bool {
	for i, r := range s {
		switch {
		case '0' <= r && '9' >= r && i > 0:
			continue
		case 'a' <= r && 'z' >= r:
			continue
		case r == '_' && i > 0:
			continue
		default:
			return false
		}
	}
	return len(s) > 0
}