-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
41 lines (36 loc) · 1.01 KB
/
query.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
package hyper
import (
"net/url"
"strconv"
"time"
"github.com/volatiletech/null/v9"
)
// GetQueryStringParam getting a query param if exist or return with null.String{Valid: false}
func GetQueryStringParam(query url.Values, param string) null.String {
if query.Has(param) {
return null.StringFrom(query.Get(param))
}
return null.String{}
}
// GetQueryUint64Param getting a query param if exist or return with null.Uint64{Valid: false}
func GetQueryUint64Param(query url.Values, param string) null.Uint64 {
if query.Has(param) {
res, err := strconv.Atoi(query.Get(param))
if err != nil {
return null.Uint64{}
}
return null.Uint64From(uint64(res))
}
return null.Uint64{}
}
// GetQueryTimeParam getting a query param if exist or return with null.Time{Valid: false}
func GetQueryTimeParam(query url.Values, param, format string) null.Time {
if query.Has(param) {
res, err := time.Parse(format, query.Get(param))
if err != nil {
return null.Time{}
}
return null.TimeFrom(res)
}
return null.Time{}
}