func FetchGateways(token string) (map[string]int, error) {

	auth := "Bearer " + token
	resp := fetch("https://api.waziup.io/api/v2/auth/permissions/gateways", fetchInit{
		method: http.MethodGet,
		headers: map[string]string{
			"Authorization": auth,
		},
	})
	if !resp.ok {
		return nil, fmt.Errorf("fetch %d: %s", resp.status, resp.statusText)
	}

	var body []struct {
		Scopes   []string `json:"scopes"`
		Resource string   `json:"resource"`
	}

	if err := resp.json(&body); err != nil {
		return nil, fmt.Errorf("fetch decode: %s", err.Error())
	}

	gws := make(map[string]int, len(body))

	for _, gw := range body {
		perm := 0
		for _, scope := range gw.Scopes {
			switch scope {
			case "gateways:view":
				perm |= PermView
			case "gateways:update":
				perm |= PermUpdate
			case "gateways:delete":
				perm |= PermDelete
			}
		}
		if perm != 0 {
			gws[gw.Resource] = perm
		}
	}

	return gws, nil
}
// FetchGateways lists all gateways and permissions for this token.
FetchGateways lists all gateways and permissions for this token.
// FetchGateways lists all gateways and permissions for this token .
func FetchGateways(token string) (map[string]int, error) {
	auth := "Bearer " + token
	resp := fetch("https://api.waziup.io/api/v2/auth/permissions/gateways", fetchInit{
		method: http.MethodGet,
		headers: map[string]string{
			"Authorization": auth,
		},
	})
	if !resp.ok {
		return nil, fmt.Errorf("fetch %d: %s", resp.status, resp.statusText)
	}
	var body []struct {
		Scopes   []string `json:"scopes"`
		Resource string   `json:"resource"`
	}
	if err := resp.json(&body); err != nil {
		return nil, fmt.Errorf("fetch decode: %s", err.Error())
	}
	gws := make(map[string]int, len(body))
	for _, gw := range body {
		perm := 0
		for _, scope := range gw.Scopes {
			switch scope {
			case "gateways:view":
				perm |= PermView
			case "gateways:update":
				perm |= PermUpdate
			case "gateways:delete":
				perm |= PermDelete
			}
		}
		if perm != 0 {
			gws[gw.Resource] = perm
		}
	}
	return gws, nil
}
func FetchGateways ( token string ) ( map [ string ] int , error ) { auth := " " + token resp := fetch ( " " , fetchInit { method : http . MethodGet , headers : map [ string ] string { " " : auth , } , } ) if ! resp . ok { return nil , fmt . Errorf ( " " , resp . status , resp . statusText ) } var body [ ] struct { Scopes [ ] string `json:"scopes"` Resource string `json:"resource"` } if err := resp . json ( & body ) ; err != nil { return nil , fmt . Errorf ( " " , err . Error ( ) ) } gws := make ( map [ string ] int , len ( body ) ) for _ , gw := range body { perm := 0 for _ , scope := range gw . Scopes { switch scope { case " " : perm |= PermView case " " : perm |= PermUpdate case " " : perm |= PermDelete } } if perm != 0 { gws [ gw . Resource ] = perm } } return gws , nil }
FetchGateways lists all gateways and permissions for this token.
FetchGateways lists all gateways and permissions for this token .