MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / convertToInt

Function convertToInt

structure/types.go:126–164  ·  view source on GitHub ↗

convertToInt converts an interface to an int

(Value interface{})

Source from the content-addressed store, hash-verified

124
125// convertToInt converts an interface to an int
126func convertToInt(Value interface{}) (int, error) {
127 switch value := Value.(type) {
128 case int:
129 return value, nil
130 case int32:
131 return int(value), nil
132 case int64:
133 return int(value), nil
134 case float32:
135 return int(value), nil
136 case float64:
137 return int(value), nil
138 case uint:
139 return int(value), nil
140 case uint8:
141 return int(value), nil
142 case uint16:
143 return int(value), nil
144 case uint32:
145 return int(value), nil
146 case uint64:
147 return int(value), nil
148 case string:
149 intValue, err := strconv.Atoi(value)
150 if err != nil {
151 return 0, err
152 }
153 return intValue, nil
154 case []byte:
155 strValue := string(value)
156 intValue, err := strconv.Atoi(strValue)
157 if err != nil {
158 return 0, err
159 }
160 return intValue, nil
161 default:
162 return 0, errors.New("unsupported type")
163 }
164}
165
166// convertToFloat converts an interface to a float64
167func convertToFloat(Value interface{}) (float64, error) {

Callers 4

IncrMethod · 0.85
IncrByMethod · 0.85
DecrMethod · 0.85
DecrByMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected