-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmisc.go
51 lines (42 loc) · 942 Bytes
/
misc.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
package main
import (
"fmt"
"strconv"
"strings"
"time"
)
type User struct {
path string
id string
username string
email string
token string
}
type UserData struct {
ID string
Username string
Email string
}
func printUser(user User) {
fmt.Printf("%v\n========================\n", user.path)
if user.id != "" {
fmt.Printf("%-10s%v\n", "User ID", user.id)
}
if user.username != "" {
fmt.Printf("%-10s%v\n", "Username", user.username)
}
if user.email != "" {
fmt.Printf("%-10s%v\n", "Email", user.email)
}
if user.token != "" {
fmt.Printf("%-10s%v\n", "Token", user.token)
fmt.Printf("%-10s%v\n", "Token Exp", getTokenExpiration(user.token))
}
}
func getTokenExpiration(token string) string {
tokenParts := strings.Split(token, ":")
expirationTime, err := strconv.ParseInt(tokenParts[2][2:], 16, 64)
panicFail(err)
tm := time.Unix(expirationTime/1000, 0)
return tm.String()
}