github.com/Files-com/files-sdk-go/v2@v2.1.2/auto.go (about)

     1  package files_sdk
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	lib "github.com/Files-com/files-sdk-go/v2/lib"
     7  )
     8  
     9  type Auto struct {
    10  	Dynamic map[string]interface{} `json:"dynamic,omitempty" path:"dynamic,omitempty" url:"dynamic,omitempty"`
    11  }
    12  
    13  // Identifier no path or id
    14  
    15  type AutoCollection []Auto
    16  
    17  func (a *Auto) UnmarshalJSON(data []byte) error {
    18  	type auto Auto
    19  	var v auto
    20  	if err := json.Unmarshal(data, &v); err != nil {
    21  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{})
    22  	}
    23  
    24  	*a = Auto(v)
    25  	return nil
    26  }
    27  
    28  func (a *AutoCollection) UnmarshalJSON(data []byte) error {
    29  	type autos AutoCollection
    30  	var v autos
    31  	if err := json.Unmarshal(data, &v); err != nil {
    32  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{})
    33  	}
    34  
    35  	*a = AutoCollection(v)
    36  	return nil
    37  }
    38  
    39  func (a *AutoCollection) ToSlice() *[]interface{} {
    40  	ret := make([]interface{}, len(*a))
    41  	for i, v := range *a {
    42  		ret[i] = v
    43  	}
    44  
    45  	return &ret
    46  }