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"
|
var PongSecret = "felixfixit"
|
||||||
|
|
||||||
func init() {
|
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) {
|
router.GET("/api/students/:sid/pong", apiHandler(studentHandler(func (student Student, body []byte) (interface{}, error) {
|
||||||
return student.lastPongs()
|
return student.lastPongs()
|
||||||
})))
|
})))
|
||||||
router.POST("/api/students/:sid/pong", apiHandler(studentHandler(stdPong), sslOnly))
|
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 {
|
if pongs, err := student.lastPongs(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if len(pongs) <= 0 {
|
} else if len(pongs) <= 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
} else {
|
} else {
|
||||||
return time.Now().Before(pongs[0].Add(time.Second * 90)), nil
|
return pongs[0], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user