-
Notifications
You must be signed in to change notification settings - Fork 199
/
urlParams.go
60 lines (47 loc) · 1.27 KB
/
urlParams.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package groups
import (
"encoding/hex"
"strconv"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/gin-gonic/gin"
)
func parseBoolUrlParam(c *gin.Context, name string) (bool, error) {
param := c.Request.URL.Query().Get(name)
if param == "" {
return false, nil
}
return strconv.ParseBool(param)
}
func parseUint32UrlParam(c *gin.Context, name string) (core.OptionalUint32, error) {
param := c.Request.URL.Query().Get(name)
if param == "" {
return core.OptionalUint32{}, nil
}
value, err := strconv.ParseUint(param, 10, 32)
if err != nil {
return core.OptionalUint32{}, err
}
return core.OptionalUint32{Value: uint32(value), HasValue: true}, nil
}
func parseUint64UrlParam(c *gin.Context, name string) (core.OptionalUint64, error) {
param := c.Request.URL.Query().Get(name)
if param == "" {
return core.OptionalUint64{}, nil
}
value, err := strconv.ParseUint(param, 10, 64)
if err != nil {
return core.OptionalUint64{}, err
}
return core.OptionalUint64{Value: value, HasValue: true}, nil
}
func parseHexBytesUrlParam(c *gin.Context, name string) ([]byte, error) {
param := c.Request.URL.Query().Get(name)
if param == "" {
return nil, nil
}
decoded, err := hex.DecodeString(param)
if err != nil {
return nil, err
}
return decoded, nil
}