...

Source file src/github.com/redhat-developer/odo/pkg/apiserver-gen/go/helpers.go

Documentation: github.com/redhat-developer/odo/pkg/apiserver-gen/go

     1  /*
     2   * odo dev
     3   *
     4   * API interface for 'odo dev'
     5   *
     6   * API version: 0.1
     7   * Generated by: OpenAPI Generator (https://openapi-generator.tech)
     8   */
     9  
    10  package openapi
    11  
    12  import (
    13  	"reflect"
    14  )
    15  
    16  // Response return a ImplResponse struct filled
    17  func Response(code int, body interface{}) ImplResponse {
    18  	return ImplResponse{
    19  		Code: code,
    20  		Body: body,
    21  	}
    22  }
    23  
    24  // IsZeroValue checks if the val is the zero-ed value.
    25  func IsZeroValue(val interface{}) bool {
    26  	return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface())
    27  }
    28  
    29  // AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback.
    30  // This method traverse nested slices in a preorder fashion.
    31  func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
    32  	return AssertRecurseValueRequired(reflect.ValueOf(obj), callback)
    33  }
    34  
    35  // AssertRecurseValueRequired checks each struct in the nested slice against the callback.
    36  // This method traverse nested slices in a preorder fashion.
    37  func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
    38  	switch value.Kind() {
    39  	// If it is a struct we check using callback
    40  	case reflect.Struct:
    41  		if err := callback(value.Interface()); err != nil {
    42  			return err
    43  		}
    44  
    45  	// If it is a slice we continue recursion
    46  	case reflect.Slice:
    47  		for i := 0; i < value.Len(); i += 1 {
    48  			if err := AssertRecurseValueRequired(value.Index(i), callback); err != nil {
    49  				return err
    50  			}
    51  		}
    52  	}
    53  	return nil
    54  }
    55  

View as plain text