diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2021-08-30 20:08:51 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2021-08-30 20:44:45 -0600 |
commit | 9343d2ea697f13e52e9199fce62a959f1954f580 (patch) | |
tree | e1e36e330a3c9891bfd8a625229a9b417ad89afa /srv/api/pow.go | |
parent | 3e9a17abb9a9d63af3c260fba9dc404dd9c59ade (diff) |
add chat handlers and only allow POST methods
Diffstat (limited to 'srv/api/pow.go')
-rw-r--r-- | srv/api/pow.go | 10 |
1 files changed, 6 insertions, 4 deletions
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 } |