From 94247e5eb9d4536d601c6c0a1dad0cb18ed53634 Mon Sep 17 00:00:00 2001 From: Sasha Melentyev Date: Sat, 5 Nov 2022 00:08:33 +0300 Subject: [PATCH] Use io/os instread of ioutil and use suitable verb (#2991) * Use io/os instread of ioutil and use suitable verb * Fix goimports lint issues --- .../internal/integration/integration_test.go | 119 +++++++++--------- internal/codegenerator/parse_req.go | 9 +- internal/descriptor/grpc_api_configuration.go | 6 +- internal/descriptor/openapi_configuration.go | 13 +- .../internal/genopenapi/helpers.go | 2 +- .../internal/genopenapi/template.go | 3 +- runtime/handler_test.go | 7 +- runtime/marshal_proto.go | 6 +- utilities/readerfactory.go | 3 +- 9 files changed, 80 insertions(+), 88 deletions(-) diff --git a/examples/internal/integration/integration_test.go b/examples/internal/integration/integration_test.go index 480deff3ab4..e650e0b896f 100644 --- a/examples/internal/integration/integration_test.go +++ b/examples/internal/integration/integration_test.go @@ -8,7 +8,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "reflect" @@ -68,9 +67,9 @@ func TestEchoUnauthorized(t *testing.T) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } msg := new(statuspb.Status) @@ -125,9 +124,9 @@ func TestEchoPatch(t *testing.T) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -224,9 +223,9 @@ func testEcho(t *testing.T, port int, apiPrefix string, contentType string) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -257,9 +256,9 @@ func testEchoOneof(t *testing.T, port int, apiPrefix string, contentType string) return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -290,9 +289,9 @@ func testEchoOneof1(t *testing.T, port int, apiPrefix string, contentType string return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -323,9 +322,9 @@ func testEchoOneof2(t *testing.T, port int, apiPrefix string, contentType string return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -372,9 +371,9 @@ func testEchoBody(t *testing.T, port int, apiPrefix string, useTrailers bool) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -470,9 +469,9 @@ func testABECreate(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -580,9 +579,9 @@ func testABECreateBody(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -709,9 +708,9 @@ func testABEBulkCreate(t *testing.T, port int, useTrailers bool) { } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -792,9 +791,9 @@ func testABEBulkCreateWithError(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -819,9 +818,9 @@ func testABELookup(t *testing.T, port int) { return } defer cresp.Body.Close() - buf, err := ioutil.ReadAll(cresp.Body) + buf, err := io.ReadAll(cresp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(cresp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(cresp.Body) failed with %v; want success", err) return } if got, want := cresp.StatusCode, http.StatusOK; got != want { @@ -844,9 +843,9 @@ func testABELookup(t *testing.T, port int) { } defer resp.Body.Close() - buf, err = ioutil.ReadAll(resp.Body) + buf, err = io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -893,7 +892,7 @@ func TestABEPatch(t *testing.T) { t.Fatalf("failed to issue PATCH request: %v", err) } if got, want := patchResp.StatusCode, http.StatusOK; got != want { - if body, err := ioutil.ReadAll(patchResp.Body); err != nil { + if body, err := io.ReadAll(patchResp.Body); err != nil { t.Errorf("patchResp body couldn't be read: %v", err) } else { t.Errorf("patchResp.StatusCode= %d; want %d resp: %v", got, want, string(body)) @@ -1026,7 +1025,7 @@ func TestABEPatchBody(t *testing.T) { t.Fatalf("failed to issue PATCH request: %v", err) } if got, want := patchResp.StatusCode, http.StatusOK; got != want { - if body, err := ioutil.ReadAll(patchResp.Body); err != nil { + if body, err := io.ReadAll(patchResp.Body); err != nil { t.Errorf("patchResp body couldn't be read: %v", err) } else { t.Errorf("patchResp.StatusCode= %d; want %d resp: %v", got, want, string(body)) @@ -1061,7 +1060,7 @@ func postABE(t *testing.T, port int, abe *examplepb.ABitOfEverything) (uuid stri t.Fatalf("http.Post(%q) failed with %v; want success", apiURL, err) return } - body, err := ioutil.ReadAll(postResp.Body) + body, err := io.ReadAll(postResp.Body) if err != nil { t.Fatalf("postResp body couldn't be read: %v", err) } @@ -1090,7 +1089,7 @@ func getABE(t *testing.T, port int, uuid string) *examplepb.ABitOfEverything { t.Fatalf("getResp.StatusCode= %d, want %d. resp: %v", got, want, getResp) } var getRestatuspbody examplepb.ABitOfEverything - body, err := ioutil.ReadAll(getResp.Body) + body, err := io.ReadAll(getResp.Body) if err != nil { t.Fatalf("getResp body couldn't be read: %v", err) } @@ -1123,9 +1122,9 @@ func testABELookupNotFound(t *testing.T, port int, useTrailers bool) { } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -1409,9 +1408,9 @@ func testAdditionalBindings(t *testing.T, port int) { } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success; i=%d", err, i) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success; i=%d", err, i) return } if got, want := resp.StatusCode, http.StatusOK; got != want { @@ -1528,9 +1527,9 @@ func testABERepeated(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -1632,9 +1631,9 @@ func TestUnknownPath(t *testing.T) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -1657,9 +1656,9 @@ func TestNotImplemented(t *testing.T) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } if got, want := resp.StatusCode, http.StatusNotImplemented; got != want { @@ -1681,9 +1680,9 @@ func TestInvalidArgument(t *testing.T) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -1726,9 +1725,9 @@ func testResponseBody(t *testing.T, port int) { } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Fatalf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Fatalf("io.ReadAll(resp.Body) failed with %v; want success", err) } if got, want := resp.StatusCode, tt.wantStatus; got != want { @@ -1806,9 +1805,9 @@ func testResponseBodies(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -1863,9 +1862,9 @@ func testResponseStrings(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -1894,9 +1893,9 @@ func testResponseStrings(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -1925,9 +1924,9 @@ func testResponseStrings(t *testing.T, port int) { return } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -2062,9 +2061,9 @@ func testRequestQueryParams(t *testing.T, port int) { } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(resp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(resp.Body) failed with %v; want success", err) return } @@ -2293,7 +2292,7 @@ func testNonStandardNames(t *testing.T, port int, method string, jsonBody string t.Fatalf("failed to issue PATCH request: %v", err) } - body, err := ioutil.ReadAll(patchResp.Body) + body, err := io.ReadAll(patchResp.Body) if err != nil { t.Errorf("patchResp body couldn't be read: %v", err) } @@ -2324,9 +2323,9 @@ func testABEExists(t *testing.T, port int) { return } defer cresp.Body.Close() - buf, err := ioutil.ReadAll(cresp.Body) + buf, err := io.ReadAll(cresp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(cresp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(cresp.Body) failed with %v; want success", err) return } if got, want := cresp.StatusCode, http.StatusOK; got != want { @@ -2415,9 +2414,9 @@ func testABETrace(t *testing.T, port int) { t.Fatal(err) } defer resp.Body.Close() - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { - t.Errorf("ioutil.ReadAll(cresp.Body) failed with %v; want success", err) + t.Errorf("io.ReadAll(cresp.Body) failed with %v; want success", err) return } if got, want := resp.StatusCode, http.StatusOK; got != want { diff --git a/internal/codegenerator/parse_req.go b/internal/codegenerator/parse_req.go index ca92d8e9985..65749a65a87 100644 --- a/internal/codegenerator/parse_req.go +++ b/internal/codegenerator/parse_req.go @@ -3,7 +3,6 @@ package codegenerator import ( "fmt" "io" - "io/ioutil" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/pluginpb" @@ -11,13 +10,13 @@ import ( // ParseRequest parses a code generator request from a proto Message. func ParseRequest(r io.Reader) (*pluginpb.CodeGeneratorRequest, error) { - input, err := ioutil.ReadAll(r) + input, err := io.ReadAll(r) if err != nil { - return nil, fmt.Errorf("failed to read code generator request: %v", err) + return nil, fmt.Errorf("failed to read code generator request: %w", err) } req := new(pluginpb.CodeGeneratorRequest) - if err = proto.Unmarshal(input, req); err != nil { - return nil, fmt.Errorf("failed to unmarshal code generator request: %v", err) + if err := proto.Unmarshal(input, req); err != nil { + return nil, fmt.Errorf("failed to unmarshal code generator request: %w", err) } return req, nil } diff --git a/internal/descriptor/grpc_api_configuration.go b/internal/descriptor/grpc_api_configuration.go index a3ae3b83ad1..ad6cfa1de07 100644 --- a/internal/descriptor/grpc_api_configuration.go +++ b/internal/descriptor/grpc_api_configuration.go @@ -3,7 +3,7 @@ package descriptor import ( "encoding/json" "fmt" - "io/ioutil" + "os" "strings" "github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/apiconfig" @@ -64,9 +64,9 @@ func registerHTTPRulesFromGrpcAPIService(registry *Registry, service *apiconfig. // Note that for the purposes of the gateway generator we only consider a subset of all // available features google supports in their service descriptions. func (r *Registry) LoadGrpcAPIServiceFromYAML(yamlFile string) error { - yamlFileContents, err := ioutil.ReadFile(yamlFile) + yamlFileContents, err := os.ReadFile(yamlFile) if err != nil { - return fmt.Errorf("failed to read gRPC API Configuration description from '%v': %v", yamlFile, err) + return fmt.Errorf("failed to read gRPC API Configuration description from %q: %w", yamlFile, err) } service, err := loadGrpcAPIServiceFromYAML(yamlFileContents, yamlFile) diff --git a/internal/descriptor/openapi_configuration.go b/internal/descriptor/openapi_configuration.go index 3487c06d64b..c0a58a671e8 100644 --- a/internal/descriptor/openapi_configuration.go +++ b/internal/descriptor/openapi_configuration.go @@ -3,7 +3,7 @@ package descriptor import ( "encoding/json" "fmt" - "io/ioutil" + "os" "github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/openapiconfig" "google.golang.org/protobuf/encoding/protojson" @@ -12,9 +12,8 @@ import ( func loadOpenAPIConfigFromYAML(yamlFileContents []byte, yamlSourceLogName string) (*openapiconfig.OpenAPIConfig, error) { var yamlContents interface{} - err := yaml.Unmarshal(yamlFileContents, &yamlContents) - if err != nil { - return nil, fmt.Errorf("failed to parse gRPC API Configuration from YAML in '%v': %v", yamlSourceLogName, err) + if err := yaml.Unmarshal(yamlFileContents, &yamlContents); err != nil { + return nil, fmt.Errorf("failed to parse gRPC API Configuration from YAML in %q: %w", yamlSourceLogName, err) } jsonContents, err := json.Marshal(yamlContents) @@ -29,7 +28,7 @@ func loadOpenAPIConfigFromYAML(yamlFileContents []byte, yamlSourceLogName string openapiConfiguration := openapiconfig.OpenAPIConfig{} if err := unmarshaler.Unmarshal(jsonContents, &openapiConfiguration); err != nil { - return nil, fmt.Errorf("failed to parse OpenAPI Configuration from YAML in '%v': %v", yamlSourceLogName, err) + return nil, fmt.Errorf("failed to parse OpenAPI Configuration from YAML in '%v': %w", yamlSourceLogName, err) } return &openapiConfiguration, nil @@ -42,7 +41,7 @@ func registerOpenAPIOptions(registry *Registry, openAPIConfig *openapiconfig.Ope } if err := registry.RegisterOpenAPIOptions(openAPIConfig.OpenapiOptions); err != nil { - return fmt.Errorf("failed to register option in %s: %s", yamlSourceLogName, err) + return fmt.Errorf("failed to register option in %s: %w", yamlSourceLogName, err) } return nil } @@ -51,7 +50,7 @@ func registerOpenAPIOptions(registry *Registry, openAPIConfig *openapiconfig.Ope // and registers the OpenAPI options the given registry. // This must be done after loading the proto file. func (r *Registry) LoadOpenAPIConfigFromYAML(yamlFile string) error { - yamlFileContents, err := ioutil.ReadFile(yamlFile) + yamlFileContents, err := os.ReadFile(yamlFile) if err != nil { return fmt.Errorf("failed to read OpenAPI Configuration description from '%v': %v", yamlFile, err) } diff --git a/protoc-gen-openapiv2/internal/genopenapi/helpers.go b/protoc-gen-openapiv2/internal/genopenapi/helpers.go index 0885be81162..37b328c5575 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/helpers.go +++ b/protoc-gen-openapiv2/internal/genopenapi/helpers.go @@ -14,7 +14,7 @@ func fieldName(k string) string { return strings.ReplaceAll(cases.Title(language.AmericanEnglish).String(k), "-", "_") } -//this method will filter the same fields and return the unique one +// this method will filter the same fields and return the unique one func getUniqueFields(schemaFieldsRequired []string, fieldsRequired []string) []string { var unique []string var index *int diff --git a/protoc-gen-openapiv2/internal/genopenapi/template.go b/protoc-gen-openapiv2/internal/genopenapi/template.go index 7bbd8d643a8..f23b01cf208 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/template.go +++ b/protoc-gen-openapiv2/internal/genopenapi/template.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "math" "net/textproto" "os" @@ -2234,7 +2233,7 @@ func goTemplateComments(comment string, data interface{}, reg *descriptor.Regist tpl, err := template.New("").Funcs(template.FuncMap{ // Allows importing documentation from a file "import": func(name string) string { - file, err := ioutil.ReadFile(name) + file, err := os.ReadFile(name) if err != nil { return err.Error() } diff --git a/runtime/handler_test.go b/runtime/handler_test.go index 3755cd31366..90629721916 100644 --- a/runtime/handler_test.go +++ b/runtime/handler_test.go @@ -3,7 +3,6 @@ package runtime_test import ( "context" "io" - "io/ioutil" "net/http" "net/http/httptest" "testing" @@ -104,7 +103,7 @@ func TestForwardResponseStream(t *testing.T) { if h := w.Header.Get("Transfer-Encoding"); h != "chunked" { t.Errorf("ForwardResponseStream missing header chunked") } - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Errorf("Failed to read response body with %v", err) } @@ -238,7 +237,7 @@ func TestForwardResponseStreamCustomMarshaler(t *testing.T) { if h := w.Header.Get("Transfer-Encoding"); h != "chunked" { t.Errorf("ForwardResponseStream missing header chunked") } - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Errorf("Failed to read response body with %v", err) } @@ -302,7 +301,7 @@ func TestForwardResponseMessage(t *testing.T) { if h := w.Header.Get("Content-Type"); h != tt.contentType { t.Errorf("Content-Type %v want %v", h, tt.contentType) } - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Errorf("Failed to read response body with %v", err) } diff --git a/runtime/marshal_proto.go b/runtime/marshal_proto.go index 007f8f1a2c7..521da0f5dca 100644 --- a/runtime/marshal_proto.go +++ b/runtime/marshal_proto.go @@ -1,10 +1,8 @@ package runtime import ( - "io" - "errors" - "io/ioutil" + "io" "google.golang.org/protobuf/proto" ) @@ -38,7 +36,7 @@ func (*ProtoMarshaller) Unmarshal(data []byte, value interface{}) error { // NewDecoder returns a Decoder which reads proto stream from "reader". func (marshaller *ProtoMarshaller) NewDecoder(reader io.Reader) Decoder { return DecoderFunc(func(value interface{}) error { - buffer, err := ioutil.ReadAll(reader) + buffer, err := io.ReadAll(reader) if err != nil { return err } diff --git a/utilities/readerfactory.go b/utilities/readerfactory.go index 6dd3854665f..01d26edae3c 100644 --- a/utilities/readerfactory.go +++ b/utilities/readerfactory.go @@ -3,13 +3,12 @@ package utilities import ( "bytes" "io" - "io/ioutil" ) // IOReaderFactory takes in an io.Reader and returns a function that will allow you to create a new reader that begins // at the start of the stream func IOReaderFactory(r io.Reader) (func() io.Reader, error) { - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return nil, err }