BuildIntegral builds an integral type from a string representaion. The type will be Int64 or Uint64. Int64 will be preferred where possible.
(val string)
| 172 | // BuildIntegral builds an integral type from a string representaion. |
| 173 | // The type will be Int64 or Uint64. Int64 will be preferred where possible. |
| 174 | func BuildIntegral(val string) (n Value, err error) { |
| 175 | signed, err := strconv.ParseInt(val, 0, 64) |
| 176 | if err == nil { |
| 177 | return MakeTrusted(Int64, strconv.AppendInt(nil, signed, 10)), nil |
| 178 | } |
| 179 | unsigned, err := strconv.ParseUint(val, 0, 64) |
| 180 | if err != nil { |
| 181 | return Value{}, err |
| 182 | } |
| 183 | return MakeTrusted(Uint64, strconv.AppendUint(nil, unsigned, 10)), nil |
| 184 | } |
| 185 | |
| 186 | // Type returns the type of Value. |
| 187 | func (v Value) Type() querypb.Type { |