api/auth.go
func teamList(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	permsForTeam := permission.PermissionRegistry.PermissionsWithContextType(permTypes.CtxTeam)
	teams, err := servicemanager.Team.List()
	if err != nil {
		return err
	}
	teamsMap := map[string]authTypes.Team{}
	permsMap := map[string][]string{}
	perms, err := t.Permissions()
	if err != nil {
		return err
	}
	for _, team := range teams {
		teamsMap[team.Name] = team
		teamCtx := permission.Context(permTypes.CtxTeam, team.Name)
		var parent *permission.PermissionScheme
		for _, p := range permsForTeam {
			if parent != nil && parent.IsParent(p) {
				continue
			}
			if permission.CheckFromPermList(perms, p, teamCtx) {
				parent = p
				permsMap[team.Name] = append(permsMap[team.Name], p.FullName())
			}
		}
	}
	if len(permsMap) == 0 {
		w.WriteHeader(http.StatusNoContent)
		return nil
	}
	var result []map[string]interface{}
	for name, permissions := range permsMap {
		result = append(result, map[string]interface{}{
			"name":        name,
			"tags":        teamsMap[name].Tags,
			"permissions": permissions,
		})
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(result)
}
func teamList(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	permsForTeam := permission.PermissionRegistry.PermissionsWithContextType(permTypes.CtxTeam)
	teams, err := servicemanager.Team.List()
	if err != nil {
		return err
	}
	teamsMap := map[string]authTypes.Team{}
	permsMap := map[string][]string{}
	perms, err := t.Permissions()
	if err != nil {
		return err
	}
	for _, team := range teams {
		teamsMap[team.Name] = team
		teamCtx := permission.Context(permTypes.CtxTeam, team.Name)
		var parent *permission.PermissionScheme
		for _, p := range permsForTeam {
			if parent != nil && parent.IsParent(p) {
				continue
			}
			if permission.CheckFromPermList(perms, p, teamCtx) {
				parent = p
				permsMap[team.Name] = append(permsMap[team.Name], p.FullName())
			}
		}
	}
	if len(permsMap) == 0 {
		w.WriteHeader(http.StatusNoContent)
		return nil
	}
	var result []map[string]interface{}
	for name, permissions := range permsMap {
		result = append(result, map[string]interface{}{
			"name":        name,
			"tags":        teamsMap[name].Tags,
			"permissions": permissions,
		})
	}
	w.Header().Set("Content-Type", "application/json")
	return json.NewEncoder(w).Encode(result)
}
// title: team list
// path: /teams
// method: GET
// produce: application/json
// responses:
//   200: List teams
//   204: No content
//   401: Unauthorized