Election!

This commit is contained in:
Ian Gulliver
2023-06-01 06:43:35 -07:00
parent ef5323aa3f
commit 755ddc99f7
4 changed files with 50 additions and 21 deletions

View File

@@ -71,6 +71,10 @@ func (c *Candidate) State() CandidateState {
return c.state
}
func (c *Candidate) IsLeader() bool {
return c.State() == StateLeader
}
func (c *Candidate) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(
@@ -137,6 +141,8 @@ func (c *Candidate) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
err = enc.Encode(c.resp)