5
0
Fork 0

Fixed mismatched types

master
UnicodingUnicorn 2019-04-02 22:54:43 +08:00
parent e3f5d029f2
commit 6de36a5c66
1 changed files with 14 additions and 11 deletions

25
main.go
View File

@ -25,7 +25,7 @@ type RawClient struct {
} }
type Ping struct { type Ping struct {
Time uint64 `json:"time"` Time int64 `json:"time"`
Status string `json:"status"` Status string `json:"status"`
} }
@ -94,14 +94,17 @@ func Subscribe(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
cachedTime, err1 := redisClient.HGet(userId, "time").Result() cachedTime, err1 := redisClient.HGet(userId, "time").Result()
cachedStatus, err2 := redisClient.HGet(userId, "status").Result() cachedStatus, err2 := redisClient.HGet(userId, "status").Result()
if err1 == nil && err2 == nil { if err1 == nil && err2 == nil {
ping := Ping { uintTime, err3 := strconv.ParseInt(cachedTime, 10, 64)
Time: cachedTime, if err3 != nil {
Status: cachedStatus, ping := Ping {
} Time: uintTime,
pingBytes, err := json.Marshal(&ping) Status: cachedStatus,
if err == nil { }
fmt.Fprintf(w, "data: %s\n\n", pingBytes) pingBytes, err := json.Marshal(&ping)
flusher.Flush() if err == nil {
fmt.Fprintf(w, "data: %s\n\n", pingBytes)
flusher.Flush()
}
} }
} }
@ -147,12 +150,12 @@ func PostTime(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
} }
ping := Ping { ping := Ping {
Time: strconv.FormatInt(time.Now().UTC().Unix(), 10), // UTC Epoch time, Time: time.Now().UTC().Unix(), // UTC Epoch time,
Status: ptRequest.Status, Status: ptRequest.Status,
} }
key := client.UserId key := client.UserId
_ = redisClient.HSet(key, "time", []byte(ping.Time)) _ = redisClient.HSet(key, "time", []byte(strconv.FormatInt(ping.Time, 10)))
_ = redisClient.HSet(key, "status", []byte(ping.Status)) _ = redisClient.HSet(key, "status", []byte(ping.Status))
pingBytes, err := json.Marshal(&ping) pingBytes, err := json.Marshal(&ping)