token-validator: return last ping time instead of boolean
This commit is contained in:
parent
d8dabcf549
commit
f50638048f
@ -9,20 +9,20 @@ import (
|
||||
var PongSecret = "felixfixit"
|
||||
|
||||
func init() {
|
||||
router.GET("/api/students/:sid/ping", apiHandler(studentHandler(isPinging)))
|
||||
router.GET("/api/students/:sid/ping", apiHandler(studentHandler(lastPing)))
|
||||
router.GET("/api/students/:sid/pong", apiHandler(studentHandler(func (student Student, body []byte) (interface{}, error) {
|
||||
return student.lastPongs()
|
||||
})))
|
||||
router.POST("/api/students/:sid/pong", apiHandler(studentHandler(stdPong), sslOnly))
|
||||
}
|
||||
|
||||
func isPinging(student Student, body []byte) (interface{}, error) {
|
||||
func lastPing(student Student, body []byte) (interface{}, error) {
|
||||
if pongs, err := student.lastPongs(); err != nil {
|
||||
return nil, err
|
||||
} else if len(pongs) <= 0 {
|
||||
return false, nil
|
||||
} else {
|
||||
return time.Now().Before(pongs[0].Add(time.Second * 90)), nil
|
||||
return pongs[0], nil
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user