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

WIP: vote

parent 078e1c4b
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,
return true
}
func (*BallotServerAgent) decodeRequest(r *http.Request) (req rad.BallotRequest, err error) {
func (*BallotServerAgent) decodeRequest[R any](r *http.Request) (req rad.BallotRequest, err error) {
buf := new(bytes.Buffer)
buf.ReadFrom(r.Body)
err = json.Unmarshal(buf.Bytes(), &req)
......@@ -57,7 +57,7 @@ func (rsa *BallotServerAgent) Start() {
// création du multiplexer
mux := http.NewServeMux()
mux.HandleFunc("/new_ballot", rsa.createBallot)
mux.HandleFunc("/vote", rsa.doReqcount)
mux.HandleFunc("/vote", rsa.receiveVote)
mux.HandleFunc("/result", rsa.doReqcount)
rsa.ballots = make(map[rad.Ballot]BallotInfo)
......
package ballotagent
import (
"fmt"
"net/http"
)
func (rsa *BallotServerAgent) receiveVote(w http.ResponseWriter, r *http.Request) {
// mise à jour du nombre de requêtes
rsa.Lock()
defer rsa.Unlock()
rsa.reqCount++
// vérification de la méthode de la requête
if !rsa.checkMethod("POST", w, r) {
return
}
// décodage de la requête
req, err := rsa.decodeRequest(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprint(w, err.Error())
return
}
// recupération des infos
scrutin := req.
}
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