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

merge new generics function

parents 462752e4 84ca5451
Branches main
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ func (rsa *BallotServerAgent) checkMethod(method string, w http.ResponseWriter,
return true
}
func (*BallotServerAgent) decodeRequest[R any](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