package auth import ( "fmt" "time" ) const ( // Maximum number of bytes in a username. MaxUnameSize = 64 // Number of bytes in a session ID. SessIdSize = 32 SessTimeout = 1 * time.Hour ) // User name. type Uname string // Session ID. type SessId [SessIdSize]byte func ParseUname(s string) (Uname, error) { if len(s) > MaxUnameSize { return "", fmt.Errorf("username longer than %d bytes: %q", MaxUnameSize, s) } return Uname(s), nil } func ParseSessId(s string) (SessId, error) { if len(s) != SessIdSize { return SessId{}, fmt.Errorf("wrong session ID size: %d (want %d): %q", len(s), SessIdSize, s) } var id SessId copy(id[:], s) return id, nil }