From 7c67b85994fdb27113911215b14aff2a6b873e07 Mon Sep 17 00:00:00 2001 From: Marwan Sulaiman Date: Fri, 16 Sep 2022 10:27:31 -0400 Subject: [PATCH] Remove deprecated ioutil from generator --- clientcompat/gocompat/gocompat.go | 4 +-- .../internal/clientcompat/clientcompat.pb.go | 2 +- .../clientcompat/clientcompat.twirp.go | 26 ++++++++++--------- example/service.pb.go | 2 +- example/service.twirp.go | 22 +++++++++------- internal/descriptors/descriptors.go | 4 +-- internal/gen/main.go | 3 +-- internal/gen/typemap/typemap_test.go | 4 +-- .../empty_service/empty_service.pb.go | 2 +- .../empty_service/empty_service.twirp.go | 22 +++++++++------- .../google_protobuf_imports/service.pb.go | 2 +- .../google_protobuf_imports/service.twirp.go | 24 +++++++++-------- .../twirptest/importable/importable.pb.go | 2 +- .../twirptest/importable/importable.twirp.go | 24 +++++++++-------- internal/twirptest/importer/importer.pb.go | 2 +- internal/twirptest/importer/importer.twirp.go | 24 +++++++++-------- .../importer_local/importer_local.pb.go | 2 +- .../importer_local/importer_local.twirp.go | 24 +++++++++-------- .../importer_local_msgdef.pb.go | 2 +- internal/twirptest/importmapping/x/x.pb.go | 2 +- internal/twirptest/importmapping/x/x.twirp.go | 24 +++++++++-------- internal/twirptest/importmapping/y/y.pb.go | 2 +- .../json_serialization.pb.go | 2 +- .../json_serialization.twirp.go | 24 +++++++++-------- internal/twirptest/multiple/multiple1.pb.go | 2 +- .../twirptest/multiple/multiple1.twirp.go | 24 +++++++++-------- internal/twirptest/multiple/multiple2.pb.go | 2 +- .../twirptest/multiple/multiple2.twirp.go | 12 ++++----- .../no_package_name/no_package_name.pb.go | 2 +- .../no_package_name/no_package_name.twirp.go | 24 +++++++++-------- .../no_package_name_importer.pb.go | 2 +- .../no_package_name_importer.twirp.go | 24 +++++++++-------- internal/twirptest/service.pb.go | 2 +- internal/twirptest/service.twirp.go | 24 +++++++++-------- .../service_method_same_name.pb.go | 2 +- .../service_method_same_name.twirp.go | 24 +++++++++-------- internal/twirptest/service_test.go | 16 ++++++------ .../snake_case_names/snake_case_names.pb.go | 2 +- .../snake_case_names.twirp.go | 24 +++++++++-------- license_test.go | 3 +-- protoc-gen-twirp/generator.go | 10 +++---- 41 files changed, 238 insertions(+), 212 deletions(-) diff --git a/clientcompat/gocompat/gocompat.go b/clientcompat/gocompat/gocompat.go index 044fe125..c84938a6 100644 --- a/clientcompat/gocompat/gocompat.go +++ b/clientcompat/gocompat/gocompat.go @@ -15,7 +15,7 @@ package main import ( "context" - "io/ioutil" + "io" "log" "net/http" "os" @@ -28,7 +28,7 @@ import ( func main() { var in clientcompat.ClientCompatMessage - inBytes, err := ioutil.ReadAll(os.Stdin) + inBytes, err := io.ReadAll(os.Stdin) if err != nil { log.Fatalf("read stdin err: %v", err) } diff --git a/clientcompat/internal/clientcompat/clientcompat.pb.go b/clientcompat/internal/clientcompat/clientcompat.pb.go index 62aa7edb..83e40e20 100644 --- a/clientcompat/internal/clientcompat/clientcompat.pb.go +++ b/clientcompat/internal/clientcompat/clientcompat.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: clientcompat.proto diff --git a/clientcompat/internal/clientcompat/clientcompat.twirp.go b/clientcompat/internal/clientcompat/clientcompat.twirp.go index 1dcfb7c4..c60f78cd 100644 --- a/clientcompat/internal/clientcompat/clientcompat.twirp.go +++ b/clientcompat/internal/clientcompat/clientcompat.twirp.go @@ -6,7 +6,7 @@ package clientcompat import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -61,7 +60,7 @@ func NewCompatServiceProtobufClient(baseURL string, client HTTPClient, opts ...t o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -200,7 +199,7 @@ func NewCompatServiceJSONClient(baseURL string, client HTTPClient, opts ...twirp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -335,7 +334,7 @@ type compatServiceServer struct { func NewCompatServiceServer(svc CompatService, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -536,7 +535,7 @@ func (s *compatServiceServer) serveMethodProtobuf(ctx context.Context, resp http return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -716,7 +715,7 @@ func (s *compatServiceServer) serveNoopMethodProtobuf(ctx context.Context, resp return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -910,7 +909,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -924,9 +923,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -1032,7 +1034,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -1232,7 +1234,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/example/service.pb.go b/example/service.pb.go index 17641a36..f0493d65 100644 --- a/example/service.pb.go +++ b/example/service.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: service.proto diff --git a/example/service.twirp.go b/example/service.twirp.go index e409baaf..691c024a 100644 --- a/example/service.twirp.go +++ b/example/service.twirp.go @@ -6,7 +6,7 @@ package example import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -61,7 +60,7 @@ func NewHaberdasherProtobufClient(baseURL string, client HTTPClient, opts ...twi o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -153,7 +152,7 @@ func NewHaberdasherJSONClient(baseURL string, client HTTPClient, opts ...twirp.C o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -241,7 +240,7 @@ type haberdasherServer struct { func NewHaberdasherServer(svc Haberdasher, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -439,7 +438,7 @@ func (s *haberdasherServer) serveMakeHatProtobuf(ctx context.Context, resp http. return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -647,9 +646,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -755,7 +757,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -955,7 +957,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/descriptors/descriptors.go b/internal/descriptors/descriptors.go index 74e86707..67af4e85 100644 --- a/internal/descriptors/descriptors.go +++ b/internal/descriptors/descriptors.go @@ -18,7 +18,7 @@ package descriptors import ( "bytes" "compress/gzip" - "io/ioutil" + "io" "google.golang.org/protobuf/proto" protobuf "google.golang.org/protobuf/types/descriptorpb" @@ -36,7 +36,7 @@ func UnpackFile(gz []byte) (*protobuf.FileDescriptorProto, error) { } defer r.Close() - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return nil, errors.Wrap(err, "failed to uncompress descriptor") } diff --git a/internal/gen/main.go b/internal/gen/main.go index 7aa5ba76..c5fb7288 100644 --- a/internal/gen/main.go +++ b/internal/gen/main.go @@ -15,7 +15,6 @@ package gen import ( "io" - "io/ioutil" "os" "google.golang.org/protobuf/proto" @@ -50,7 +49,7 @@ Outer: } func readGenRequest(r io.Reader) *plugin.CodeGeneratorRequest { - data, err := ioutil.ReadAll(r) + data, err := io.ReadAll(r) if err != nil { Error(err, "reading input") } diff --git a/internal/gen/typemap/typemap_test.go b/internal/gen/typemap/typemap_test.go index 6f480f0d..53de5052 100644 --- a/internal/gen/typemap/typemap_test.go +++ b/internal/gen/typemap/typemap_test.go @@ -14,7 +14,7 @@ package typemap import ( - "io/ioutil" + "os" "path/filepath" "testing" @@ -25,7 +25,7 @@ import ( ) func loadTestPb(t *testing.T) []*descriptor.FileDescriptorProto { - f, err := ioutil.ReadFile(filepath.Join("testdata", "fileset.pb")) + f, err := os.ReadFile(filepath.Join("testdata", "fileset.pb")) require.NoError(t, err, "unable to read testdata protobuf file") set := new(descriptor.FileDescriptorSet) diff --git a/internal/twirptest/empty_service/empty_service.pb.go b/internal/twirptest/empty_service/empty_service.pb.go index 0f195510..f1381ec7 100644 --- a/internal/twirptest/empty_service/empty_service.pb.go +++ b/internal/twirptest/empty_service/empty_service.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: empty_service.proto diff --git a/internal/twirptest/empty_service/empty_service.twirp.go b/internal/twirptest/empty_service/empty_service.twirp.go index 071b0143..37a667de 100644 --- a/internal/twirptest/empty_service/empty_service.twirp.go +++ b/internal/twirptest/empty_service/empty_service.twirp.go @@ -6,7 +6,7 @@ package empty_service import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -58,7 +57,7 @@ func NewEmptyProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Cli o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -99,7 +98,7 @@ func NewEmptyJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientO o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -136,7 +135,7 @@ type emptyServer struct { func NewEmptyServer(svc Empty, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -345,7 +344,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -359,9 +358,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -467,7 +469,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -667,7 +669,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/google_protobuf_imports/service.pb.go b/internal/twirptest/google_protobuf_imports/service.pb.go index c6a4a60c..36569391 100644 --- a/internal/twirptest/google_protobuf_imports/service.pb.go +++ b/internal/twirptest/google_protobuf_imports/service.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: service.proto diff --git a/internal/twirptest/google_protobuf_imports/service.twirp.go b/internal/twirptest/google_protobuf_imports/service.twirp.go index fb5365e5..b5025c8f 100644 --- a/internal/twirptest/google_protobuf_imports/service.twirp.go +++ b/internal/twirptest/google_protobuf_imports/service.twirp.go @@ -6,7 +6,7 @@ package google_protobuf_imports import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -21,7 +21,6 @@ import google_protobuf1 "google.golang.org/protobuf/types/known/wrapperspb" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -62,7 +61,7 @@ func NewSvcProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clien o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -154,7 +153,7 @@ func NewSvcJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOpt o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -242,7 +241,7 @@ type svcServer struct { func NewSvcServer(svc Svc, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -440,7 +439,7 @@ func (s *svcServer) serveSendProtobuf(ctx context.Context, resp http.ResponseWri return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -634,7 +633,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -648,9 +647,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -756,7 +758,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -956,7 +958,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/importable/importable.pb.go b/internal/twirptest/importable/importable.pb.go index 61f2469b..374d40a8 100644 --- a/internal/twirptest/importable/importable.pb.go +++ b/internal/twirptest/importable/importable.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: importable.proto diff --git a/internal/twirptest/importable/importable.twirp.go b/internal/twirptest/importable/importable.twirp.go index d0581012..bd7e79dc 100644 --- a/internal/twirptest/importable/importable.twirp.go +++ b/internal/twirptest/importable/importable.twirp.go @@ -8,7 +8,7 @@ package importable import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -20,7 +20,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -61,7 +60,7 @@ func NewSvcProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clien o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -153,7 +152,7 @@ func NewSvcJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOpt o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -241,7 +240,7 @@ type svcServer struct { func NewSvcServer(svc Svc, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -439,7 +438,7 @@ func (s *svcServer) serveSendProtobuf(ctx context.Context, resp http.ResponseWri return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -633,7 +632,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -647,9 +646,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -755,7 +757,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -955,7 +957,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/importer/importer.pb.go b/internal/twirptest/importer/importer.pb.go index 3bf15e33..e28a0fae 100644 --- a/internal/twirptest/importer/importer.pb.go +++ b/internal/twirptest/importer/importer.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: importer.proto diff --git a/internal/twirptest/importer/importer.twirp.go b/internal/twirptest/importer/importer.twirp.go index 0e53f092..4a773b12 100644 --- a/internal/twirptest/importer/importer.twirp.go +++ b/internal/twirptest/importer/importer.twirp.go @@ -8,7 +8,7 @@ package importer import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -22,7 +22,6 @@ import twirp_internal_twirptest_importable "github.com/twitchtv/twirp/internal/t import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -63,7 +62,7 @@ func NewSvc2ProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clie o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -155,7 +154,7 @@ func NewSvc2JSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -243,7 +242,7 @@ type svc2Server struct { func NewSvc2Server(svc Svc2, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -441,7 +440,7 @@ func (s *svc2Server) serveSendProtobuf(ctx context.Context, resp http.ResponseWr return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -635,7 +634,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -649,9 +648,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -757,7 +759,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -957,7 +959,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/importer_local/importer_local.pb.go b/internal/twirptest/importer_local/importer_local.pb.go index b53ec1d3..e011ca8e 100644 --- a/internal/twirptest/importer_local/importer_local.pb.go +++ b/internal/twirptest/importer_local/importer_local.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: importer_local.proto diff --git a/internal/twirptest/importer_local/importer_local.twirp.go b/internal/twirptest/importer_local/importer_local.twirp.go index 56bc399b..a76bf214 100644 --- a/internal/twirptest/importer_local/importer_local.twirp.go +++ b/internal/twirptest/importer_local/importer_local.twirp.go @@ -6,7 +6,7 @@ package importer_local import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -59,7 +58,7 @@ func NewSvcProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clien o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -151,7 +150,7 @@ func NewSvcJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOpt o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -239,7 +238,7 @@ type svcServer struct { func NewSvcServer(svc Svc, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -437,7 +436,7 @@ func (s *svcServer) serveSendProtobuf(ctx context.Context, resp http.ResponseWri return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -631,7 +630,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -645,9 +644,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -753,7 +755,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -953,7 +955,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/importer_local/importer_local_msgdef.pb.go b/internal/twirptest/importer_local/importer_local_msgdef.pb.go index 32ab8321..d1520c03 100644 --- a/internal/twirptest/importer_local/importer_local_msgdef.pb.go +++ b/internal/twirptest/importer_local/importer_local_msgdef.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: importer_local_msgdef.proto diff --git a/internal/twirptest/importmapping/x/x.pb.go b/internal/twirptest/importmapping/x/x.pb.go index a455cff3..23721f96 100644 --- a/internal/twirptest/importmapping/x/x.pb.go +++ b/internal/twirptest/importmapping/x/x.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: x/x.proto diff --git a/internal/twirptest/importmapping/x/x.twirp.go b/internal/twirptest/importmapping/x/x.twirp.go index 16804971..50081d25 100644 --- a/internal/twirptest/importmapping/x/x.twirp.go +++ b/internal/twirptest/importmapping/x/x.twirp.go @@ -6,7 +6,7 @@ package x import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -20,7 +20,6 @@ import twirp_internal_twirptest_importmapping_y "github.com/twitchtv/twirp/inter import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -61,7 +60,7 @@ func NewSvc1ProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clie o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -153,7 +152,7 @@ func NewSvc1JSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -241,7 +240,7 @@ type svc1Server struct { func NewSvc1Server(svc Svc1, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -439,7 +438,7 @@ func (s *svc1Server) serveSendProtobuf(ctx context.Context, resp http.ResponseWr return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -633,7 +632,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -647,9 +646,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -755,7 +757,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -955,7 +957,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/importmapping/y/y.pb.go b/internal/twirptest/importmapping/y/y.pb.go index 8cea861d..c8152e2d 100644 --- a/internal/twirptest/importmapping/y/y.pb.go +++ b/internal/twirptest/importmapping/y/y.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: y/y.proto diff --git a/internal/twirptest/json_serialization/json_serialization.pb.go b/internal/twirptest/json_serialization/json_serialization.pb.go index 2f3ba2eb..5a163422 100644 --- a/internal/twirptest/json_serialization/json_serialization.pb.go +++ b/internal/twirptest/json_serialization/json_serialization.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: json_serialization.proto diff --git a/internal/twirptest/json_serialization/json_serialization.twirp.go b/internal/twirptest/json_serialization/json_serialization.twirp.go index 81286392..70270910 100644 --- a/internal/twirptest/json_serialization/json_serialization.twirp.go +++ b/internal/twirptest/json_serialization/json_serialization.twirp.go @@ -6,7 +6,7 @@ package json_serialization import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -59,7 +58,7 @@ func NewJSONSerializationProtobufClient(baseURL string, client HTTPClient, opts o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -151,7 +150,7 @@ func NewJSONSerializationJSONClient(baseURL string, client HTTPClient, opts ...t o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -239,7 +238,7 @@ type jSONSerializationServer struct { func NewJSONSerializationServer(svc JSONSerialization, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -437,7 +436,7 @@ func (s *jSONSerializationServer) serveEchoJSONProtobuf(ctx context.Context, res return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -631,7 +630,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -645,9 +644,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -753,7 +755,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -953,7 +955,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/multiple/multiple1.pb.go b/internal/twirptest/multiple/multiple1.pb.go index 0d5a5f81..4667dff5 100644 --- a/internal/twirptest/multiple/multiple1.pb.go +++ b/internal/twirptest/multiple/multiple1.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: multiple1.proto diff --git a/internal/twirptest/multiple/multiple1.twirp.go b/internal/twirptest/multiple/multiple1.twirp.go index 3e381fbc..ac9e95bb 100644 --- a/internal/twirptest/multiple/multiple1.twirp.go +++ b/internal/twirptest/multiple/multiple1.twirp.go @@ -8,7 +8,7 @@ package multiple import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -20,7 +20,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -61,7 +60,7 @@ func NewSvc1ProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clie o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -153,7 +152,7 @@ func NewSvc1JSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -241,7 +240,7 @@ type svc1Server struct { func NewSvc1Server(svc Svc1, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -439,7 +438,7 @@ func (s *svc1Server) serveSendProtobuf(ctx context.Context, resp http.ResponseWr return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -633,7 +632,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -647,9 +646,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -755,7 +757,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -955,7 +957,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/multiple/multiple2.pb.go b/internal/twirptest/multiple/multiple2.pb.go index 4ddd6ea0..8e95c390 100644 --- a/internal/twirptest/multiple/multiple2.pb.go +++ b/internal/twirptest/multiple/multiple2.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: multiple2.proto diff --git a/internal/twirptest/multiple/multiple2.twirp.go b/internal/twirptest/multiple/multiple2.twirp.go index 23afb26e..6d47ce74 100644 --- a/internal/twirptest/multiple/multiple2.twirp.go +++ b/internal/twirptest/multiple/multiple2.twirp.go @@ -8,7 +8,7 @@ package multiple import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -57,7 +57,7 @@ func NewSvc2ProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clie o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -196,7 +196,7 @@ func NewSvc2JSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -331,7 +331,7 @@ type svc2Server struct { func NewSvc2Server(svc Svc2, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -532,7 +532,7 @@ func (s *svc2Server) serveSendProtobuf(ctx context.Context, resp http.ResponseWr return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -712,7 +712,7 @@ func (s *svc2Server) serveSamePackageProtoImportProtobuf(ctx context.Context, re return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return diff --git a/internal/twirptest/no_package_name/no_package_name.pb.go b/internal/twirptest/no_package_name/no_package_name.pb.go index 15db2012..46762680 100644 --- a/internal/twirptest/no_package_name/no_package_name.pb.go +++ b/internal/twirptest/no_package_name/no_package_name.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: no_package_name.proto diff --git a/internal/twirptest/no_package_name/no_package_name.twirp.go b/internal/twirptest/no_package_name/no_package_name.twirp.go index ac8c2cb9..1231b756 100644 --- a/internal/twirptest/no_package_name/no_package_name.twirp.go +++ b/internal/twirptest/no_package_name/no_package_name.twirp.go @@ -6,7 +6,7 @@ package no_package_name import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -59,7 +58,7 @@ func NewSvcProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clien o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -151,7 +150,7 @@ func NewSvcJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOpt o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -239,7 +238,7 @@ type svcServer struct { func NewSvcServer(svc Svc, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -437,7 +436,7 @@ func (s *svcServer) serveSendProtobuf(ctx context.Context, resp http.ResponseWri return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -631,7 +630,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -645,9 +644,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -753,7 +755,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -953,7 +955,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/no_package_name_importer/no_package_name_importer.pb.go b/internal/twirptest/no_package_name_importer/no_package_name_importer.pb.go index a2d5b606..17be3ce1 100644 --- a/internal/twirptest/no_package_name_importer/no_package_name_importer.pb.go +++ b/internal/twirptest/no_package_name_importer/no_package_name_importer.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: no_package_name_importer/no_package_name_importer.proto diff --git a/internal/twirptest/no_package_name_importer/no_package_name_importer.twirp.go b/internal/twirptest/no_package_name_importer/no_package_name_importer.twirp.go index fa6900f9..b517cd46 100644 --- a/internal/twirptest/no_package_name_importer/no_package_name_importer.twirp.go +++ b/internal/twirptest/no_package_name_importer/no_package_name_importer.twirp.go @@ -6,7 +6,7 @@ package no_package_name_importer import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -20,7 +20,6 @@ import no_package_name "github.com/twitchtv/twirp/internal/twirptest/no_package_ import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -61,7 +60,7 @@ func NewSvc2ProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clie o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -153,7 +152,7 @@ func NewSvc2JSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -241,7 +240,7 @@ type svc2Server struct { func NewSvc2Server(svc Svc2, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -439,7 +438,7 @@ func (s *svc2Server) serveMethodProtobuf(ctx context.Context, resp http.Response return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -633,7 +632,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -647,9 +646,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -755,7 +757,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -955,7 +957,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/service.pb.go b/internal/twirptest/service.pb.go index 2f4e7715..159193eb 100644 --- a/internal/twirptest/service.pb.go +++ b/internal/twirptest/service.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: service.proto diff --git a/internal/twirptest/service.twirp.go b/internal/twirptest/service.twirp.go index 3e763b88..c3bb6890 100644 --- a/internal/twirptest/service.twirp.go +++ b/internal/twirptest/service.twirp.go @@ -6,7 +6,7 @@ package twirptest import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -61,7 +60,7 @@ func NewHaberdasherProtobufClient(baseURL string, client HTTPClient, opts ...twi o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -153,7 +152,7 @@ func NewHaberdasherJSONClient(baseURL string, client HTTPClient, opts ...twirp.C o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -241,7 +240,7 @@ type haberdasherServer struct { func NewHaberdasherServer(svc Haberdasher, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -439,7 +438,7 @@ func (s *haberdasherServer) serveMakeHatProtobuf(ctx context.Context, resp http. return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -633,7 +632,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -647,9 +646,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -755,7 +757,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -955,7 +957,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/service_method_same_name/service_method_same_name.pb.go b/internal/twirptest/service_method_same_name/service_method_same_name.pb.go index 1ccb9096..d3071a7f 100644 --- a/internal/twirptest/service_method_same_name/service_method_same_name.pb.go +++ b/internal/twirptest/service_method_same_name/service_method_same_name.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: service_method_same_name.proto diff --git a/internal/twirptest/service_method_same_name/service_method_same_name.twirp.go b/internal/twirptest/service_method_same_name/service_method_same_name.twirp.go index 7d94cb60..5acd7a21 100644 --- a/internal/twirptest/service_method_same_name/service_method_same_name.twirp.go +++ b/internal/twirptest/service_method_same_name/service_method_same_name.twirp.go @@ -6,7 +6,7 @@ package service_method_same_name import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -18,7 +18,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -59,7 +58,7 @@ func NewEchoProtobufClient(baseURL string, client HTTPClient, opts ...twirp.Clie o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -151,7 +150,7 @@ func NewEchoJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -239,7 +238,7 @@ type echoServer struct { func NewEchoServer(svc Echo, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -437,7 +436,7 @@ func (s *echoServer) serveEchoProtobuf(ctx context.Context, resp http.ResponseWr return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -631,7 +630,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -645,9 +644,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -753,7 +755,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -953,7 +955,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/internal/twirptest/service_test.go b/internal/twirptest/service_test.go index 8dbb8122..9980914b 100644 --- a/internal/twirptest/service_test.go +++ b/internal/twirptest/service_test.go @@ -20,10 +20,10 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/http" "net/http/httptest" + "os" "reflect" "regexp" "strings" @@ -83,7 +83,7 @@ func TestServerJSONWithMalformedRequest(t *testing.T) { t.Fatalf("Expected 400 BadRequest when sending malformed request, got %d", resp.StatusCode) } // Make sure the response is meaningful - respBytes, err := ioutil.ReadAll(resp.Body) + respBytes, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("Could not even read bytes from response: %q", err.Error()) } @@ -114,7 +114,7 @@ func TestServerJSONWithUnknownFields(t *testing.T) { }() // Make sure that the returned hat is valid and has empty (zero-value) size - respBytes, err := ioutil.ReadAll(resp.Body) // read manually first in case jsonpb.Unmarshal so it can be printed for debugging + respBytes, err := io.ReadAll(resp.Body) // read manually first in case jsonpb.Unmarshal so it can be printed for debugging if err != nil { t.Fatalf("Could not even read bytes from response: %q", err.Error()) } @@ -149,7 +149,7 @@ func TestServerProtobufMalformedRequest(t *testing.T) { t.Fatalf("Expected 400 BadRequest when sending malformed request, got %d", resp.StatusCode) } // Make sure the response is meaningful - respBytes, err := ioutil.ReadAll(resp.Body) + respBytes, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("Could not even read bytes from response: %q", err.Error()) } @@ -436,7 +436,7 @@ func TestHooks(t *testing.T) { base: http.DefaultTransport, rewrite: func(r *http.Request) *http.Request { r.ContentLength = 1 - r.Body = ioutil.NopCloser(io.LimitReader(r.Body, 1)) + r.Body = io.NopCloser(io.LimitReader(r.Body, 1)) return r }, } @@ -987,7 +987,7 @@ func testMuxingTwirpServer(t *testing.T, prefix string, handler TwirpServer) { t.Errorf("health check endpoint err=%q", err) } else { if resp.StatusCode != 200 { - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) t.Errorf("got a non-200 response from /health: %d", resp.StatusCode) t.Logf("response body: %s", body) t.Logf("response read err: %s", err) @@ -1451,7 +1451,7 @@ func TestReflection(t *testing.T) { }) t.Run("ProtoGenTwirpVersion", func(t *testing.T) { // Should match whatever is in the file at protoc-gen-twirp/version.go - file, err := ioutil.ReadFile("../gen/version.go") + file, err := os.ReadFile("../gen/version.go") if err != nil { t.Fatalf("unable to load version file: %v", err) } @@ -1657,7 +1657,7 @@ func TestRequestBodyError(t *testing.T) { } // validate error message - respBytes, err := ioutil.ReadAll(w.Body) + respBytes, err := io.ReadAll(w.Body) if err != nil { t.Fatalf("Could not even read bytes from response: %q", err.Error()) } diff --git a/internal/twirptest/snake_case_names/snake_case_names.pb.go b/internal/twirptest/snake_case_names/snake_case_names.pb.go index e8ffa7f8..07b9009a 100644 --- a/internal/twirptest/snake_case_names/snake_case_names.pb.go +++ b/internal/twirptest/snake_case_names/snake_case_names.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0-devel +// protoc-gen-go v1.28.0 // protoc v3.19.4 // source: snake_case_names.proto diff --git a/internal/twirptest/snake_case_names/snake_case_names.twirp.go b/internal/twirptest/snake_case_names/snake_case_names.twirp.go index d569fa48..2a8de785 100644 --- a/internal/twirptest/snake_case_names/snake_case_names.twirp.go +++ b/internal/twirptest/snake_case_names/snake_case_names.twirp.go @@ -9,7 +9,7 @@ package snake_case_names import context "context" import fmt "fmt" import http "net/http" -import ioutil "io/ioutil" +import io "io" import json "encoding/json" import strconv "strconv" import strings "strings" @@ -21,7 +21,6 @@ import ctxsetters "github.com/twitchtv/twirp/ctxsetters" import bytes "bytes" import errors "errors" -import io "io" import path "path" import url "net/url" @@ -63,7 +62,7 @@ func NewHaberdasherV1ProtobufClient(baseURL string, client HTTPClient, opts ...t o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -164,7 +163,7 @@ func NewHaberdasherV1JSONClient(baseURL string, client HTTPClient, opts ...twirp o(&clientOpts) } - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future literalURLs := false _ = clientOpts.ReadOpt("literalURLs", &literalURLs) var pathPrefix string @@ -261,7 +260,7 @@ type haberdasherV1Server struct { func NewHaberdasherV1Server(svc HaberdasherV1, opts ...interface{}) TwirpServer { serverOpts := newServerOpts(opts) - // Using ReadOpt allows backwards and forwads compatibility with new options in the future + // Using ReadOpt allows backwards and forwards compatibility with new options in the future jsonSkipDefaults := false _ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults) jsonCamelCase := false @@ -459,7 +458,7 @@ func (s *haberdasherV1Server) serveMakeHatV1Protobuf(ctx context.Context, resp h return } - buf, err := ioutil.ReadAll(req.Body) + buf, err := io.ReadAll(req.Body) if err != nil { s.handleRequestBodyError(ctx, resp, "failed to read request body", err) return @@ -653,7 +652,7 @@ func writeError(ctx context.Context, resp http.ResponseWriter, err error, hooks } // sanitizeBaseURL parses the the baseURL, and adds the "http" scheme if needed. -// If the URL is unparsable, the baseURL is returned unchaged. +// If the URL is unparsable, the baseURL is returned unchanged. func sanitizeBaseURL(baseURL string) string { u, err := url.Parse(baseURL) if err != nil { @@ -667,9 +666,12 @@ func sanitizeBaseURL(baseURL string) string { // baseServicePath composes the path prefix for the service (without ). // e.g.: baseServicePath("/twirp", "my.pkg", "MyService") -// returns => "/twirp/my.pkg.MyService/" +// +// returns => "/twirp/my.pkg.MyService/" +// // e.g.: baseServicePath("", "", "MyService") -// returns => "/MyService/" +// +// returns => "/MyService/" func baseServicePath(prefix, pkg, service string) string { fullServiceName := service if pkg != "" { @@ -775,7 +777,7 @@ func errorFromResponse(resp *http.Response) twirp.Error { return twirpErrorFromIntermediary(statusCode, msg, location) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return wrapInternal(err, "failed to read server error response body") } @@ -975,7 +977,7 @@ func doProtobufRequest(ctx context.Context, client HTTPClient, hooks *twirp.Clie return ctx, errorFromResponse(resp) } - respBodyBytes, err := ioutil.ReadAll(resp.Body) + respBodyBytes, err := io.ReadAll(resp.Body) if err != nil { return ctx, wrapInternal(err, "failed to read response body") } diff --git a/license_test.go b/license_test.go index 5cb3d751..5309f63b 100644 --- a/license_test.go +++ b/license_test.go @@ -16,7 +16,6 @@ package twirp import ( "bytes" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -64,7 +63,7 @@ func TestSourceCodeLicenseHeaders(t *testing.T) { if err != nil { return err } - fileBytes, err := ioutil.ReadAll(file) + fileBytes, err := io.ReadAll(file) if err != nil { return err } diff --git a/protoc-gen-twirp/generator.go b/protoc-gen-twirp/generator.go index 73916324..601f80fd 100644 --- a/protoc-gen-twirp/generator.go +++ b/protoc-gen-twirp/generator.go @@ -100,7 +100,6 @@ func (t *twirp) Generate(in *plugin.CodeGeneratorRequest) *plugin.CodeGeneratorR t.registerPackageName("context") t.registerPackageName("http") t.registerPackageName("io") - t.registerPackageName("ioutil") t.registerPackageName("json") t.registerPackageName("protojson") t.registerPackageName("proto") @@ -286,7 +285,7 @@ func (t *twirp) generateImports(file *descriptor.FileDescriptorProto) { t.P(`import `, t.pkgs["context"], ` "context"`) t.P(`import `, t.pkgs["fmt"], ` "fmt"`) t.P(`import `, t.pkgs["http"], ` "net/http"`) - t.P(`import `, t.pkgs["ioutil"], ` "io/ioutil"`) + t.P(`import `, t.pkgs["io"], ` "io"`) t.P(`import `, t.pkgs["json"], ` "encoding/json"`) t.P(`import `, t.pkgs["strconv"], ` "strconv"`) t.P(`import `, t.pkgs["strings"], ` "strings"`) @@ -349,7 +348,6 @@ func (t *twirp) generateImports(file *descriptor.FileDescriptorProto) { func (t *twirp) generateUtilImports() { t.P(`import `, t.pkgs["bytes"], ` "bytes"`) t.P(`import `, t.pkgs["errors"], ` "errors"`) - t.P(`import `, t.pkgs["io"], ` "io"`) t.P(`import `, t.pkgs["path"], ` "path"`) t.P(`import `, t.pkgs["url"], ` "net/url"`) } @@ -599,7 +597,7 @@ func (t *twirp) generateUtils() { t.P(` return twirpErrorFromIntermediary(statusCode, msg, location)`) t.P(` }`) t.P(``) - t.P(` respBodyBytes, err := `, t.pkgs["ioutil"], `.ReadAll(resp.Body)`) + t.P(` respBodyBytes, err := `, t.pkgs["io"], `.ReadAll(resp.Body)`) t.P(` if err != nil {`) t.P(` return wrapInternal(err, "failed to read server error response body")`) t.P(` }`) @@ -804,7 +802,7 @@ func (t *twirp) generateUtils() { t.P(` return ctx, errorFromResponse(resp)`) t.P(` }`) t.P() - t.P(` respBodyBytes, err := `, t.pkgs["ioutil"], `.ReadAll(resp.Body)`) + t.P(` respBodyBytes, err := `, t.pkgs["io"], `.ReadAll(resp.Body)`) t.P(` if err != nil {`) t.P(` return ctx, wrapInternal(err, "failed to read response body")`) t.P(` }`) @@ -1384,7 +1382,7 @@ func (t *twirp) generateServerProtobufMethod(service *descriptor.ServiceDescript t.P(` return`) t.P(` }`) t.P() - t.P(` buf, err := `, t.pkgs["ioutil"], `.ReadAll(req.Body)`) + t.P(` buf, err := `, t.pkgs["io"], `.ReadAll(req.Body)`) t.P(` if err != nil {`) t.P(` s.handleRequestBodyError(ctx, resp, "failed to read request body", err)`) t.P(` return`)