github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/helper/fields/type.go (about)

     1  package fields
     2  
     3  // FieldType is the enum of types that a field can be.
     4  type FieldType uint
     5  
     6  const (
     7  	TypeInvalid FieldType = 0
     8  	TypeString  FieldType = iota
     9  	TypeInt
    10  	TypeBool
    11  	TypeMap
    12  	TypeArray
    13  )
    14  
    15  func (t FieldType) String() string {
    16  	switch t {
    17  	case TypeString:
    18  		return "string"
    19  	case TypeInt:
    20  		return "integer"
    21  	case TypeBool:
    22  		return "boolean"
    23  	case TypeMap:
    24  		return "map"
    25  	case TypeArray:
    26  		return "array"
    27  	default:
    28  		return "unknown type"
    29  	}
    30  }
    31  
    32  func (t FieldType) Zero() interface{} {
    33  	switch t {
    34  	case TypeString:
    35  		return ""
    36  	case TypeInt:
    37  		return 0
    38  	case TypeBool:
    39  		return false
    40  	case TypeMap:
    41  		return map[string]interface{}{}
    42  	case TypeArray:
    43  		return []interface{}{}
    44  	default:
    45  		panic("unknown type: " + t.String())
    46  	}
    47  }