Debian Codegraph @

vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/convert.go

raw
1 package runtime
2
3 import (
4 "strconv"
5 )
6
7 // String just returns the given string.
8 // It is just for compatibility to other types.
9 func String(val string) (string, error) {
10 return val, nil
11 }
12
13 // Bool converts the given string representation of a boolean value into bool.
14 func Bool(val string) (bool, error) {
15 return strconv.ParseBool(val)
16 }
17
18 // Float64 converts the given string representation into representation of a floating point number into float64.
19 func Float64(val string) (float64, error) {
20 return strconv.ParseFloat(val, 64)
21 }
22
23 // Float32 converts the given string representation of a floating point number into float32.
24 func Float32(val string) (float32, error) {
25 f, err := strconv.ParseFloat(val, 32)
26 if err != nil {
27 return 0, err
28 }
29 return float32(f), nil
30 }
31
32 // Int64 converts the given string representation of an integer into int64.
33 func Int64(val string) (int64, error) {
34 return strconv.ParseInt(val, 0, 64)
35 }
36
37 // Int32 converts the given string representation of an integer into int32.
38 func Int32(val string) (int32, error) {
39 i, err := strconv.ParseInt(val, 0, 32)
40 if err != nil {
41 return 0, err
42 }
43 return int32(i), nil
44 }
45
46 // Uint64 converts the given string representation of an integer into uint64.
47 func Uint64(val string) (uint64, error) {
48 return strconv.ParseUint(val, 0, 64)
49 }
50
51 // Uint32 converts the given string representation of an integer into uint32.
52 func Uint32(val string) (uint32, error) {
53 i, err := strconv.ParseUint(val, 0, 32)
54 if err != nil {
55 return 0, err
56 }
57 return uint32(i), nil
58 }