From 9343d2ea697f13e52e9199fce62a959f1954f580 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Mon, 30 Aug 2021 20:08:51 -0600 Subject: add chat handlers and only allow POST methods --- srv/api/pow.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'srv/api/pow.go') diff --git a/srv/api/pow.go b/srv/api/pow.go index 096e252..6d11061 100644 --- a/srv/api/pow.go +++ b/srv/api/pow.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/mediocregopher/blog.mediocregopher.com/srv/api/apiutils" ) func (a *api) newPowChallengeHandler() http.Handler { @@ -12,7 +14,7 @@ func (a *api) newPowChallengeHandler() http.Handler { challenge := a.params.PowManager.NewChallenge() - jsonResult(rw, r, struct { + apiutils.JSONResult(rw, r, struct { Seed string `json:"seed"` Target uint32 `json:"target"` }{ @@ -28,21 +30,21 @@ func (a *api) requirePowMiddleware(h http.Handler) http.Handler { seedHex := r.PostFormValue("powSeed") seed, err := hex.DecodeString(seedHex) if err != nil || len(seed) == 0 { - badRequest(rw, r, errors.New("invalid powSeed")) + apiutils.BadRequest(rw, r, errors.New("invalid powSeed")) return } solutionHex := r.PostFormValue("powSolution") solution, err := hex.DecodeString(solutionHex) if err != nil || len(seed) == 0 { - badRequest(rw, r, errors.New("invalid powSolution")) + apiutils.BadRequest(rw, r, errors.New("invalid powSolution")) return } err = a.params.PowManager.CheckSolution(seed, solution) if err != nil { - badRequest(rw, r, fmt.Errorf("checking proof-of-work solution: %w", err)) + apiutils.BadRequest(rw, r, fmt.Errorf("checking proof-of-work solution: %w", err)) return } -- cgit v1.2.3