github.com/aeternity/aepp-sdk-go/v4@v4.0.1/swagguard/node/models/ttl.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package models
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"encoding/json"
    10  
    11  	strfmt "github.com/go-openapi/strfmt"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/swag"
    15  	"github.com/go-openapi/validate"
    16  )
    17  
    18  // TTL TTL
    19  // swagger:model TTL
    20  type TTL struct {
    21  
    22  	// type
    23  	// Required: true
    24  	// Enum: [delta block]
    25  	Type *string `json:"type"`
    26  
    27  	// value
    28  	// Required: true
    29  	Value *uint64 `json:"value"`
    30  }
    31  
    32  // Validate validates this TTL
    33  func (m *TTL) Validate(formats strfmt.Registry) error {
    34  	var res []error
    35  
    36  	if err := m.validateType(formats); err != nil {
    37  		res = append(res, err)
    38  	}
    39  
    40  	if err := m.validateValue(formats); err != nil {
    41  		res = append(res, err)
    42  	}
    43  
    44  	if len(res) > 0 {
    45  		return errors.CompositeValidationError(res...)
    46  	}
    47  	return nil
    48  }
    49  
    50  var ttlTypeTypePropEnum []interface{}
    51  
    52  func init() {
    53  	var res []string
    54  	if err := json.Unmarshal([]byte(`["delta","block"]`), &res); err != nil {
    55  		panic(err)
    56  	}
    57  	for _, v := range res {
    58  		ttlTypeTypePropEnum = append(ttlTypeTypePropEnum, v)
    59  	}
    60  }
    61  
    62  const (
    63  
    64  	// TTLTypeDelta captures enum value "delta"
    65  	TTLTypeDelta string = "delta"
    66  
    67  	// TTLTypeBlock captures enum value "block"
    68  	TTLTypeBlock string = "block"
    69  )
    70  
    71  // prop value enum
    72  func (m *TTL) validateTypeEnum(path, location string, value string) error {
    73  	if err := validate.Enum(path, location, value, ttlTypeTypePropEnum); err != nil {
    74  		return err
    75  	}
    76  	return nil
    77  }
    78  
    79  func (m *TTL) validateType(formats strfmt.Registry) error {
    80  
    81  	if err := validate.Required("type", "body", m.Type); err != nil {
    82  		return err
    83  	}
    84  
    85  	// value enum
    86  	if err := m.validateTypeEnum("type", "body", *m.Type); err != nil {
    87  		return err
    88  	}
    89  
    90  	return nil
    91  }
    92  
    93  func (m *TTL) validateValue(formats strfmt.Registry) error {
    94  
    95  	if err := validate.Required("value", "body", m.Value); err != nil {
    96  		return err
    97  	}
    98  
    99  	return nil
   100  }
   101  
   102  // MarshalBinary interface implementation
   103  func (m *TTL) MarshalBinary() ([]byte, error) {
   104  	if m == nil {
   105  		return nil, nil
   106  	}
   107  	return swag.WriteJSON(m)
   108  }
   109  
   110  // UnmarshalBinary interface implementation
   111  func (m *TTL) UnmarshalBinary(b []byte) error {
   112  	var res TTL
   113  	if err := swag.ReadJSON(b, &res); err != nil {
   114  		return err
   115  	}
   116  	*m = res
   117  	return nil
   118  }