1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00
wakapi/models/heartbeat.go
Ferdinand Mütsch 0bd71b7708 Initial.
2019-05-05 22:36:49 +02:00

38 lines
864 B
Go

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")
}