Debian Codegraph @

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

raw
1 package runtime
2
3 import (
4 "github.com/golang/protobuf/proto"
5 )
6
7 // StringP returns a pointer to a string whose pointee is same as the given string value.
8 func StringP(val string) (*string, error) {
9 return proto.String(val), nil
10 }
11
12 // BoolP parses the given string representation of a boolean value,
13 // and returns a pointer to a bool whose value is same as the parsed value.
14 func BoolP(val string) (*bool, error) {
15 b, err := Bool(val)
16 if err != nil {
17 return nil, err
18 }
19 return proto.Bool(b), nil
20 }
21
22 // Float64P parses the given string representation of a floating point number,
23 // and returns a pointer to a float64 whose value is same as the parsed number.
24 func Float64P(val string) (*float64, error) {
25 f, err := Float64(val)
26 if err != nil {
27 return nil, err
28 }
29 return proto.Float64(f), nil
30 }
31
32 // Float32P parses the given string representation of a floating point number,
33 // and returns a pointer to a float32 whose value is same as the parsed number.
34 func Float32P(val string) (*float32, error) {
35 f, err := Float32(val)
36 if err != nil {
37 return nil, err
38 }
39 return proto.Float32(f), nil
40 }
41
42 // Int64P parses the given string representation of an integer
43 // and returns a pointer to a int64 whose value is same as the parsed integer.
44 func Int64P(val string) (*int64, error) {
45 i, err := Int64(val)
46 if err != nil {
47 return nil, err
48 }
49 return proto.Int64(i), nil
50 }
51
52 // Int32P parses the given string representation of an integer
53 // and returns a pointer to a int32 whose value is same as the parsed integer.
54 func Int32P(val string) (*int32, error) {
55 i, err := Int32(val)
56 if err != nil {
57 return nil, err
58 }
59 return proto.Int32(i), err
60 }
61
62 // Uint64P parses the given string representation of an integer
63 // and returns a pointer to a uint64 whose value is same as the parsed integer.
64 func Uint64P(val string) (*uint64, error) {
65 i, err := Uint64(val)
66 if err != nil {
67 return nil, err
68 }
69 return proto.Uint64(i), err
70 }
71
72 // Uint32P parses the given string representation of an integer
73 // and returns a pointer to a uint32 whose value is same as the parsed integer.
74 func Uint32P(val string) (*uint32, error) {
75 i, err := Uint32(val)
76 if err != nil {
77 return nil, err
78 }
79 return proto.Uint32(i), err
80 }