-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.go
48 lines (40 loc) · 804 Bytes
/
utils.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
package vcodeHMAC
import (
"crypto/rand"
"encoding/hex"
"fmt"
"net/url"
"time"
)
func getCurrentTimestamp() int64 {
return time.Now().UnixNano() / 1000000
}
func generateNonce() string {
token := make([]byte, 16)
rand.Read(token)
return hex.EncodeToString(token)
}
func getHost(urlString string) (string, error) {
u, err := url.Parse(urlString)
if err != nil {
return "", err
}
return u.Host, nil
}
func getPathParams(urlString string) (string, error) {
u, err := url.Parse(urlString)
if err != nil {
return "", err
}
if len(u.RawQuery) > 0 {
return fmt.Sprintf("%s?%s", u.Path, u.RawQuery), nil
}
return string(u.Path), nil
}
func getScheme(urlString string) (string, error) {
u, err := url.Parse(urlString)
if err != nil {
return "", err
}
return u.Scheme, nil
}