package auth import ( "errors" "strings" ) var methods []Authenticator // Register a method func Register(method Authenticator) { methods = append(methods, method) } // FindAuthenticator finds the first Method that answers with // the ID(). func FindAuthenticator(id string) Authenticator { for _, method := range methods { if method.ID() == id { return method } } return nil } // ListAuthenticators gets a copy of the method list func ListAuthenticators() []Authenticator { dst := make([]Authenticator, len(methods)) copy(dst, methods) return dst } func FindUser(fullid string) (*User, error) { split := strings.SplitN(fullid, ":", 2) autherID := split[0] userID := split[1] auther := FindAuthenticator(autherID) if auther == nil { return nil, errors.New("auth: auther not found") } return auther.Find(userID), nil }