gitlab.com/evatix-go/core@v1.3.55/coredata/coreapi/GenericResponse.go (about)

     1  package coreapi
     2  
     3  import (
     4  	"gitlab.com/evatix-go/core/constants"
     5  	"gitlab.com/evatix-go/core/coredata/coredynamic"
     6  )
     7  
     8  type GenericResponse struct {
     9  	Attribute *ResponseAttribute `json:"Attribute,omitempty"`
    10  	Response  interface{}        `json:"Response,omitempty"`
    11  }
    12  
    13  func InvalidGenericResponse(attr *ResponseAttribute) *GenericResponse {
    14  	if attr == nil {
    15  		return &GenericResponse{
    16  			Attribute: InvalidResponseAttribute(constants.EmptyString),
    17  			Response:  nil,
    18  		}
    19  	}
    20  
    21  	return &GenericResponse{
    22  		Attribute: attr,
    23  		Response:  nil,
    24  	}
    25  }
    26  
    27  func (it *GenericResponse) GenericResponseResult() *GenericResponseResult {
    28  	return &GenericResponseResult{
    29  		Attribute: it.Attribute,
    30  		Response: coredynamic.NewSimpleResult(
    31  			it,
    32  			it.Attribute.IsValid,
    33  			it.Attribute.Message),
    34  	}
    35  }
    36  
    37  // Clone Cannot copy interface, just putting response in response field.
    38  func (it *GenericResponse) Clone() *GenericResponse {
    39  	if it == nil {
    40  		return nil
    41  	}
    42  
    43  	return &GenericResponse{
    44  		Attribute: it.Attribute.Clone(),
    45  		Response:  it.Response,
    46  	}
    47  }