Skip to content
Snippets Groups Projects
Commit 84ca5451 authored by Balthazar Wilson's avatar Balthazar Wilson
Browse files

generalize request decoding

parent 078e1c4b
No related branches found
No related tags found
1 merge request!7Partie serveur
......@@ -34,7 +34,7 @@ func (rsa *BallotServerAgent) checkMethod(method string, w http.ResponseWriter,
return true
}
func (*BallotServerAgent) decodeRequest(r *http.Request) (req rad.BallotRequest, err error) {
func decodeRequest[Req rad.Request](r *http.Request) (req Req, err error) {
buf := new(bytes.Buffer)
buf.ReadFrom(r.Body)
err = json.Unmarshal(buf.Bytes(), &req)
......
......@@ -31,7 +31,7 @@ func (rsa *BallotServerAgent) createBallot(w http.ResponseWriter, r *http.Reques
}
// décodage de la requête
req, err := rsa.decodeRequest(r)
req, err := decodeRequest[rad.BallotRequest](r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, err.Error())
......
......@@ -23,3 +23,7 @@ type ResultResponse struct {
Winner int `json:"winner"`
Ranking []int `json:"ranking"`
}
type Request interface {
BallotRequest | Ballot | Vote
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment