Doc + use ParseInt instead of Atoi in roomserver

This commit is contained in:
Brendan Abolivier 2017-08-10 12:17:11 +01:00
parent f4a53ee54b
commit a99f7de70f
No known key found for this signature in database
GPG key ID: 8EF1500759F70623
2 changed files with 4 additions and 3 deletions

View file

@ -89,6 +89,8 @@ func GetPublicRooms(
}
}
// fillPublicRoomsReq fills the Limit, Since and Filter attributes of a request to the roomserver's
// GetPublicRooms API by parsing the incoming HTTP request
func fillPublicRoomsReq(httpReq *http.Request, queryReq *api.GetPublicRoomsRequest) *util.JSONResponse {
if httpReq.Method == "GET" {
limit, err := strconv.Atoi(httpReq.FormValue("limit"))

View file

@ -113,13 +113,12 @@ func (r *RoomserverPublicRoomAPI) GetPublicRooms(
var offset int64
limit = req.Limit
ofst, err := strconv.Atoi(req.Since)
// Atoi returns 0 and an error when trying to parse an empty string
offset, err := strconv.ParseInt(req.Since, 10, 64)
// ParseInt returns 0 and an error when trying to parse an empty string
// In that case, we want to assign 0 so we ignore the error
if err != nil && len(req.Since) > 0 {
return err
}
offset = int64(ofst)
roomIDs, err := r.DB.GetPublicRoomIDs()
if err != nil {