1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00
This commit is contained in:
Ferdinand Mütsch
2019-05-05 22:36:49 +02:00
commit 0bd71b7708
6 changed files with 178 additions and 0 deletions

37
models/heartbeat.go Normal file
View 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")
}