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
No related branches found
No related tags found
1 merge request!8implémentation des votants par Balthazar
...@@ -34,7 +34,7 @@ func (rsa *BallotServerAgent) checkMethod(method string, w http.ResponseWriter, ...@@ -34,7 +34,7 @@ func (rsa *BallotServerAgent) checkMethod(method string, w http.ResponseWriter,
return true 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 := new(bytes.Buffer)
buf.ReadFrom(r.Body) buf.ReadFrom(r.Body)
err = json.Unmarshal(buf.Bytes(), &req) err = json.Unmarshal(buf.Bytes(), &req)
......
...@@ -31,7 +31,7 @@ func (rsa *BallotServerAgent) createBallot(w http.ResponseWriter, r *http.Reques ...@@ -31,7 +31,7 @@ func (rsa *BallotServerAgent) createBallot(w http.ResponseWriter, r *http.Reques
} }
// décodage de la requête // décodage de la requête
req, err := rsa.decodeRequest(r) req, err := decodeRequest[rad.BallotRequest](r)
if err != nil { if err != nil {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, err.Error()) fmt.Fprint(w, err.Error())
......
...@@ -23,3 +23,7 @@ type ResultResponse struct { ...@@ -23,3 +23,7 @@ type ResultResponse struct {
Winner int `json:"winner"` Winner int `json:"winner"`
Ranking []int `json:"ranking"` 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