// Paging perfoms paging operation for User collection
Paging perfoms paging operation for User collection
// Paging perfoms paging operation for User collection
func (r *ManagedDeviceUsersCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]User, error) {
	req, err := r.NewJSONRequest(method, path, obj)
	if err != nil {
		return nil, err
	}
	if ctx != nil {
		req = req.WithContext(ctx)
	}
	res, err := r.client.Do(req)
	if err != nil {
		return nil, err
	}
	var values []User
	for {
		if res.StatusCode != http.StatusOK {
			b, _ := ioutil.ReadAll(res.Body)
			res.Body.Close()
			errRes := &ErrorResponse{Response: res}
			err := jsonx.Unmarshal(b, errRes)
			if err != nil {
				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
			}
			return nil, errRes
		}
		var (
			paging Paging
			value  []User
		)
		err := jsonx.NewDecoder(res.Body).Decode(&paging)
		res.Body.Close()
		if err != nil {
			return nil, err
		}
		err = jsonx.Unmarshal(paging.Value, &value)
		if err != nil {
			return nil, err
		}
		values = append(values, value...)
		if n >= 0 {
			n--
		}
		if n == 0 || len(paging.NextLink) == 0 {
			return values, nil
		}
		req, err = http.NewRequest("GET", paging.NextLink, nil)
		if ctx != nil {
			req = req.WithContext(ctx)
		}
		res, err = r.client.Do(req)
		if err != nil {
			return nil, err
		}
	}
}
func ( r * ManagedDeviceUsersCollectionRequest ) Paging ( ctx context . Context , method , path string , obj interface { } , n int ) ( [ ] User , error ) { req , err := r . NewJSONRequest ( method , path , obj ) if err != nil { return nil , err } if ctx != nil { req = req . WithContext ( ctx ) } res , err := r . client . Do ( req ) if err != nil { return nil , err } var values [ ] User for { if res . StatusCode != http . StatusOK { b , _ := ioutil . ReadAll ( res . Body ) res . Body . Close ( ) errRes := & ErrorResponse { Response : res } err := jsonx . Unmarshal ( b , errRes ) if err != nil { return nil , fmt . Errorf ( " " , res . Status , string ( b ) ) } return nil , errRes } var ( paging Paging value [ ] User ) err := jsonx . NewDecoder ( res . Body ) . Decode ( & paging ) res . Body . Close ( ) if err != nil { return nil , err } err = jsonx . Unmarshal ( paging . Value , & value ) if err != nil { return nil , err } values = append ( values , value ... ) if n >= 0 { n -- } if n == 0 || len ( paging . NextLink ) == 0 { return values , nil } req , err = http . NewRequest ( " " , paging . NextLink , nil ) if ctx != nil { req = req . WithContext ( ctx ) } res , err = r . client . Do ( req ) if err != nil { return nil , err } } }
Paging perfoms paging operation for User collection
Paging perfoms paging operation for User collection