statping/handlers/query.go

27 lines
488 B
Go
Raw Normal View History

2020-02-24 05:53:15 +00:00
package handlers
2020-03-04 10:29:00 +00:00
import (
"encoding/json"
"errors"
"github.com/gorilla/mux"
2020-03-09 18:17:55 +00:00
"github.com/statping/statping/utils"
2020-03-04 10:29:00 +00:00
"net/http"
)
func DecodeJSON(r *http.Request, obj interface{}) error {
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&obj)
if err != nil {
return err
}
return nil
}
func GetID(r *http.Request) (int64, error) {
vars := mux.Vars(r)
if vars["id"] == "" {
return 0, errors.New("no id specified in request")
}
return utils.ToInt(vars["id"]), nil
}