-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
52 lines (42 loc) · 796 Bytes
/
types.go
File metadata and controls
52 lines (42 loc) · 796 Bytes
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
package api
import (
"fmt"
"net/http"
"time"
"github.com/acoshift/arpc/v2"
)
type Empty struct{}
func (*Empty) UnmarshalRequest(r *http.Request) error {
if r.Method != http.MethodGet {
return arpc.ErrUnsupported
}
return nil
}
func (*Empty) Table() [][]string {
return [][]string{{"Operation success"}}
}
func Int(i int) *int {
return &i
}
func Int64(i int64) *int64 {
return &i
}
func String(s string) *string {
return &s
}
func Bool(b bool) *bool {
return &b
}
func age(t time.Time) string {
d := time.Since(t)
if x := d / (24 * time.Hour); x > 0 {
return fmt.Sprintf("%dd", x)
}
if x := d / (24 * time.Hour); x > 0 {
return fmt.Sprintf("%dh", x)
}
if x := d / time.Minute; x > 0 {
return fmt.Sprintf("%dm", x)
}
return fmt.Sprintf("%ds", d/time.Second)
}