github.com/letsencrypt/boulder@v0.20251208.0/test/chall-test-srv/http.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "errors" 6 "io" 7 "net/http" 8 ) 9 10 // mustParsePOST will attempt to read a JSON POST body from the provided request 11 // and unmarshal it into the provided ob. If an error occurs at any point it 12 // will be returned. 13 func mustParsePOST(ob any, request *http.Request) error { 14 jsonBody, err := io.ReadAll(request.Body) 15 if err != nil { 16 return err 17 } 18 19 if string(jsonBody) == "" { 20 return errors.New("Expected JSON POST body, was empty") 21 } 22 23 return json.Unmarshal(jsonBody, ob) 24 }