GetInt64 gets an int64 parameter from the input If the parameter isn't found then error will be of type ErrParamNotFound and the returned value will be 0.
(key string)
| 157 | // If the parameter isn't found then error will be of type |
| 158 | // ErrParamNotFound and the returned value will be 0. |
| 159 | func (p Params) GetInt64(key string) (int64, error) { |
| 160 | value, err := p.Get(key) |
| 161 | if err != nil { |
| 162 | return 0, err |
| 163 | } |
| 164 | switch x := value.(type) { |
| 165 | case int: |
| 166 | return int64(x), nil |
| 167 | case int64: |
| 168 | return x, nil |
| 169 | case float64: |
| 170 | if x > math.MaxInt64 || x < math.MinInt64 { |
| 171 | return 0, ErrParamInvalid{fmt.Errorf("key %q (%v) overflows int64 ", key, value)} |
| 172 | } |
| 173 | return int64(x), nil |
| 174 | case string: |
| 175 | i, err := strconv.ParseInt(x, 10, 0) |
| 176 | if err != nil { |
| 177 | return 0, ErrParamInvalid{fmt.Errorf("couldn't parse key %q (%v) as int64: %w", key, value, err)} |
| 178 | } |
| 179 | return i, nil |
| 180 | } |
| 181 | return 0, ErrParamInvalid{fmt.Errorf("expecting int64 value for key %q (was %T)", key, value)} |
| 182 | } |
| 183 | |
| 184 | // GetFloat64 gets a float64 parameter from the input |
| 185 | // |