getEmptyValueForType is a helper function that takes a string representation of a type and returns an "empty" value for that type. An empty value is a value that is generally considered a default or initial state for a variable of a given type. The purpose of this function is to be able to initializ
(typ base.AttributeType)
| 115 | // The purpose of this function is to be able to initialize a variable of a given type without knowing the type in advance. |
| 116 | // The function uses a switch statement to handle different possible type values and returns a corresponding empty value. |
| 117 | func getEmptyValueForType(typ base.AttributeType) interface{} { |
| 118 | switch typ { |
| 119 | case base.AttributeType_ATTRIBUTE_TYPE_STRING: |
| 120 | // In the case of a string type, an empty string "" is considered the empty value. |
| 121 | return "" |
| 122 | case base.AttributeType_ATTRIBUTE_TYPE_STRING_ARRAY: |
| 123 | // In the case of a string type, an empty string "" is considered the empty value. |
| 124 | return []string{} |
| 125 | case base.AttributeType_ATTRIBUTE_TYPE_INTEGER: |
| 126 | // In the case of an integer type, zero (0) is considered the empty value. |
| 127 | return 0 |
| 128 | case base.AttributeType_ATTRIBUTE_TYPE_INTEGER_ARRAY: |
| 129 | // In the case of an integer type, zero (0) is considered the empty value. |
| 130 | return []int32{} |
| 131 | case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE: |
| 132 | // In the case of a double (or floating point) type, zero (0.0) is considered the empty value. |
| 133 | return 0.0 |
| 134 | case base.AttributeType_ATTRIBUTE_TYPE_DOUBLE_ARRAY: |
| 135 | // In the case of a double (or floating point) type, zero (0.0) is considered the empty value. |
| 136 | return []float64{} |
| 137 | case base.AttributeType_ATTRIBUTE_TYPE_BOOLEAN: |
| 138 | // In the case of a boolean type, false is considered the empty value. |
| 139 | return false |
| 140 | case base.AttributeType_ATTRIBUTE_TYPE_BOOLEAN_ARRAY: |
| 141 | // In the case of a boolean type, false is considered the empty value. |
| 142 | return []bool{} |
| 143 | default: |
| 144 | // For any other types that are not explicitly handled, the function returns nil. |
| 145 | // This may need to be adjusted if there are other types that need specific empty values. |
| 146 | return nil |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // getEmptyProtoValueForType returns an empty protobuf value of the specified type. |
| 151 | // It takes a base.AttributeType as input and generates an empty protobuf Any message |
no outgoing calls
no test coverage detected