MCPcopy Create free account
hub / github.com/amp-labs/connectors / GetInt

Method GetInt

common/stringMap.go:130–145  ·  view source on GitHub ↗

GetInt extracts an integer from the map.

(key string)

Source from the content-addressed store, hash-verified

128
129// GetInt extracts an integer from the map.
130func (m StringMap) GetInt(key string) (int64, error) {
131 val, err := m.Get(key)
132 if err != nil {
133 return 0, err
134 }
135
136 t := reflect.TypeOf(val)
137
138 //nolint:exhaustive
139 switch t.Kind() {
140 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
141 return reflect.ValueOf(val).Int(), nil
142 default:
143 return 0, fmt.Errorf("%w: expected an integer, but received %T", errFieldTypeMismatch, val)
144 }
145}
146
147// GetFloat extracts a float from the map.
148func (m StringMap) GetFloat(key string) (float64, error) {

Callers 1

TestStringMapFunction · 0.95

Calls 1

GetMethod · 0.95

Tested by 1

TestStringMapFunction · 0.76