mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
Initial.
This commit is contained in:
37
models/heartbeat.go
Normal file
37
models/heartbeat.go
Normal file
@ -0,0 +1,37 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type HeartbeatReqTime time.Time
|
||||
|
||||
type Heartbeat struct {
|
||||
User string `json:"user"`
|
||||
Entity string `json:"entity"`
|
||||
Type string `json:"type"`
|
||||
Category string `json:"category"`
|
||||
Project string `json:"project"`
|
||||
Branch string `json:"branch"`
|
||||
Language string `json:"language"`
|
||||
IsWrite bool `json:"is_write"`
|
||||
Time HeartbeatReqTime `json:"time"`
|
||||
}
|
||||
|
||||
func (j *HeartbeatReqTime) UnmarshalJSON(b []byte) error {
|
||||
s := strings.Split(strings.Trim(string(b), "\""), ".")[0]
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t := time.Unix(i, 0)
|
||||
*j = HeartbeatReqTime(t)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (j HeartbeatReqTime) String() string {
|
||||
t := time.Time(j)
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
}
|
Reference in New Issue
Block a user