From ebe1e39d64d0bfd671ca9c7d321cc1dee5ae5479 Mon Sep 17 00:00:00 2001 From: Cody Oss Date: Sat, 2 Nov 2024 17:53:33 -0500 Subject: [PATCH] feat: add logging support --- go.mod | 1 - go.sum | 4 +- go.work.sum | 3 + google-api-go-generator/gen.go | 53 +++-- google-api-go-generator/testdata/any.want | 95 ++++++--- .../testdata/arrayofarray-1.want | 8 +- .../testdata/arrayofenum.want | 8 +- .../testdata/arrayofmapofobjects.want | 8 +- .../testdata/arrayofmapofstrings.want | 8 +- .../testdata/blogger-3.want | 182 ++++++++++++----- google-api-go-generator/testdata/floats.want | 8 +- .../testdata/getwithoutbody.want | 15 +- .../testdata/http-body.want | 18 +- .../testdata/json-body.want | 183 +++++++++++++----- .../testdata/mapofany.want | 8 +- .../testdata/mapofarrayofobjects.want | 15 +- .../testdata/mapofint64strings.want | 8 +- .../testdata/mapofobjects.want | 8 +- .../testdata/mapofstrings-1.want | 15 +- .../testdata/mapprotostruct.want | 17 +- .../testdata/param-rename.want | 22 ++- .../testdata/quotednum.want | 8 +- .../testdata/repeated.want | 12 +- .../testdata/required-query.want | 15 +- .../testdata/resource-named-service.want | 115 ++++++++--- .../testdata/unfortunatedefaults.want | 8 +- .../testdata/variants.want | 8 +- .../testdata/wrapnewlines.want | 8 +- googleapi/googleapi.go | 4 + internal/gensupport/send.go | 17 ++ secretmanager/v1/secretmanager-gen.go | 3 +- 31 files changed, 645 insertions(+), 240 deletions(-) diff --git a/go.mod b/go.mod index 636dbba09d3..53b2de5ef7a 100644 --- a/go.mod +++ b/go.mod @@ -33,5 +33,4 @@ require ( golang.org/x/crypto v0.31.0 // indirect golang.org/x/sys v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect ) diff --git a/go.sum b/go.sum index f48dd75cb93..3c82d8ed3be 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 h1:pgr/4QbFyktUv9CtQ/Fq4gzEE6/Xs7iCXbktaGzLHbQ= -google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697/go.mod h1:+D9ySVjN8nY8YCVjc5O7PZDIdZporIDY3KaGfJunh88= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 h1:M0KvPgPmDZHPlbRbaNU1APr28TvwvvdUPlSv7PUvy8g= +google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28/go.mod h1:dguCy7UOdZhTvLzDyt15+rOrawrpM4q7DD9dQ1P11P4= google.golang.org/genproto/googleapis/bytestream v0.0.0-20241206012308-a4fef0638583 h1:QNxhiucJGWLF/fFpnyTIk8GdEGTa6tUC7/JYG7VN3XU= google.golang.org/genproto/googleapis/bytestream v0.0.0-20241206012308-a4fef0638583/go.mod h1:qUsLYwbwz5ostUWtuFuXPlHmSJodC5NI/88ZlHj4M1o= google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 h1:IfdSdTcLFy4lqUQrQJLkLt1PB+AsqVz6lwkWPzWEz10= diff --git a/go.work.sum b/go.work.sum index 67264de29b2..c5b7c574b71 100644 --- a/go.work.sum +++ b/go.work.sum @@ -674,6 +674,8 @@ github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= github.com/googleapis/gax-go/v2 v2.8.0/go.mod h1:4orTrqY6hXxxaUL4LHIPl6lGo8vAE38/qKbhSAKP6QI= github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU= +github.com/googleapis/gax-go/v2 v2.14.0 h1:f+jMrjBPl+DL9nI4IQzLUxMq7XrAqFYB7hBPqMNIe8o= +github.com/googleapis/gax-go/v2 v2.14.0/go.mod h1:lhBCnjdLrWRaPvLWhmc8IS24m9mr07qSYnHncrgo+zk= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= @@ -704,6 +706,7 @@ go.opentelemetry.io/otel/trace v1.22.0/go.mod h1:RbbHXVqKES9QhzZq/fE5UnOSILqRt40 go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/google-api-go-generator/gen.go b/google-api-go-generator/gen.go index 1fc1a3f2d9d..6aa6a7c5d5f 100644 --- a/google-api-go-generator/gen.go +++ b/google-api-go-generator/gen.go @@ -809,6 +809,7 @@ func (a *API) GenerateCode() ([]byte, error) { "errors", "fmt", "io", + "log/slog", "net/http", "net/url", "strconv", @@ -820,6 +821,7 @@ func (a *API) GenerateCode() ([]byte, error) { if a.Name == "storage" { pn(" %q", "github.com/googleapis/gax-go/v2") } + pn(" %q", "github.com/googleapis/gax-go/v2/internallog") for _, imp := range []struct { pkg string lname string @@ -895,7 +897,10 @@ func (a *API) GenerateCode() ([]byte, error) { pn("client, endpoint, err := htransport.NewClient(ctx, opts...)") pn("if err != nil { return nil, err }") - pn("s, err := New(client)") + pn("s := &%s{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)}", service) + for _, res := range a.doc.Resources { // add top level resources. + pn("s.%s = New%s(s)", resourceGoField(res, nil), resourceGoType(res)) + } pn("if err != nil { return nil, err }") pn(`if endpoint != "" { s.BasePath = endpoint }`) pn("return s, nil") @@ -908,15 +913,12 @@ func (a *API) GenerateCode() ([]byte, error) { pn("// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.") pn("func New(client *http.Client) (*%s, error) {", service) pn("if client == nil { return nil, errors.New(\"client is nil\") }") - pn("s := &%s{client: client, BasePath: basePath}", service) - for _, res := range a.doc.Resources { // add top level resources. - pn("s.%s = New%s(s)", resourceGoField(res, nil), resourceGoType(res)) - } - pn("return s, nil") + pn("return NewService(context.Background(), option.WithHTTPClient(client))") pn("}") pn("\ntype %s struct {", service) pn(" client *http.Client") + pn(" logger *slog.Logger") pn(" BasePath string // API endpoint base URL") pn(" UserAgent string // optional additional User-Agent fragment") @@ -995,6 +997,7 @@ func splitFileHeading(w io.Writer, pkg string) { "context", "fmt", "io", + "log/slog", "net/http", } { pn(" %q", imp) @@ -2279,34 +2282,44 @@ func (meth *Method) generateCode() { pn(` reqHeaders.Set("If-None-Match", c.ifNoneMatch_)`) pn("}") } - pn("var body io.Reader = nil") + var hasBody bool if meth.IsRawRequest() { - pn("body = c.body_") + pn("body := bytes.NewBuffer(nil)") + pn("_, err := body.ReadFrom(c.body_)") + pn("if err != nil { return nil, err }") + hasBody = true } else if meth.IsProtoStructRequest() { pn("protoBytes, err := json.Marshal(c.req)") pn("if err != nil { return nil, err }") - pn("body = bytes.NewReader(protoBytes)") + pn("body := bytes.NewReader(protoBytes)") + hasBody = true } else { if ba := args.bodyArg(); ba != nil && httpMethod != "GET" { if meth.m.ID == "ml.projects.predict" { // TODO(cbro): move ML API to rawHTTP (it will be a breaking change) - // Skip JSONReader for APIs that require clients to pass in JSON already. - pn("body = strings.NewReader(c.%s.HttpBody.Data)", ba.goname) + // Skip JSONBuffer for APIs that require clients to pass in JSON already. + pn("body := bytes.NewBufferString(c.%s.HttpBody.Data)", ba.goname) } else { style := "WithoutDataWrapper" if a.needsDataWrapper() { style = "WithDataWrapper" } - pn("body, err := googleapi.%s.JSONReader(c.%s)", style, ba.goname) + pn("body, err := googleapi.%s.JSONBuffer(c.%s)", style, ba.goname) pn("if err != nil { return nil, err }") } + hasBody = true } pn(`c.urlParams_.Set("alt", alt)`) pn(`c.urlParams_.Set("prettyPrint", "false")`) } + body := "nil" + if hasBody { + body = body + } pn("urls := googleapi.ResolveRelative(c.s.BasePath, %q)", meth.m.Path) if meth.supportsMediaUpload() { + body = "newBody" pn("if c.mediaInfo_ != nil {") pn(" urls = googleapi.ResolveRelative(c.s.BasePath, %q)", meth.mediaUploadPath()) pn(` c.urlParams_.Set("uploadType", c.mediaInfo_.UploadType())`) @@ -2316,11 +2329,11 @@ func (meth *Method) generateCode() { pn(" body = new(bytes.Buffer)") pn(` reqHeaders.Set("Content-Type", "application/json")`) pn("}") - pn("body, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)") + pn("newBody, getBody, cleanup := c.mediaInfo_.UploadRequest(reqHeaders, body)") pn("defer cleanup()") } pn(`urls += "?" + c.urlParams_.Encode()`) - pn("req, err := http.NewRequest(%q, urls, body)", httpMethod) + pn("req, err := http.NewRequest(%q, urls, %s)", httpMethod, body) pn("if err != nil { return nil, err }") pn("req.Header = reqHeaders") if meth.supportsMediaUpload() { @@ -2337,12 +2350,18 @@ func (meth *Method) generateCode() { } pn(`})`) } + logBody := "nil" + if hasBody { + logBody = "body.Bytes()" + } if meth.supportsMediaUpload() && meth.api.Name == "storage" { + pn(`c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", %q, "request", internallog.HTTPRequest(req, %s))`, meth.Id(), logBody) pn("if c.retry != nil {") pn(" return gensupport.SendRequestWithRetry(c.ctx_, c.s.client, req, c.retry)") pn("}") pn("return gensupport.SendRequest(c.ctx_, c.s.client, req)") } else { + pn(`c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", %q, "request", internallog.HTTPRequest(req, %s))`, meth.Id(), logBody) pn("return gensupport.SendRequest(c.ctx_, c.s.client, req)") } pn("}") @@ -2421,6 +2440,7 @@ func (meth *Method) generateCode() { pn("}") } if retTypeComma == "" { + pn(`c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", %q, "response", internallog.HTTPResponse(res, nil))`, meth.Id()) pn("return nil") } else { if meth.IsProtoStructResponse() { @@ -2449,8 +2469,11 @@ func (meth *Method) generateCode() { pn("if err := res.Body.Close(); err != nil { return nil, err }") pn("if err := json.NewDecoder(bytes.NewReader(b.Bytes())).Decode(target); err != nil { return nil, err }") pn("ret.Data = b.String()") + pn(`c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", %q, "response", internallog.HTTPResponse(res, b.Bytes()))`, meth.Id()) } else { - pn("if err := gensupport.DecodeResponse(target, res); err != nil { return nil, err }") + pn("b, err := gensupport.DecodeResponseBytes(target, res)") + pn("if err != nil { return nil, err }") + pn(`c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", %q, "response", internallog.HTTPResponse(res, b))`, meth.Id()) } pn("return ret, nil") } diff --git a/google-api-go-generator/testdata/any.want b/google-api-go-generator/testdata/any.want index 7d623e14e7c..2f025bc4288 100644 --- a/google-api-go-generator/testdata/any.want +++ b/google-api-go-generator/testdata/any.want @@ -57,11 +57,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -114,7 +116,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Projects = NewProjectsService(s) if err != nil { return nil, err } @@ -133,13 +136,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Projects = NewProjectsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -765,6 +767,7 @@ func (c *ProjectsLogServicesListCall) doRequest(alt string) (*http.Response, err googleapi.Expand(req.URL, map[string]string{ "projectsId": c.projectsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logServices.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -800,9 +803,11 @@ func (c *ProjectsLogServicesListCall) Do(opts ...googleapi.CallOption) (*ListLog }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logServices.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -949,6 +954,7 @@ func (c *ProjectsLogServicesIndexesListCall) doRequest(alt string) (*http.Respon "projectsId": c.projectsId, "logServicesId": c.logServicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logServices.indexes.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -984,9 +990,11 @@ func (c *ProjectsLogServicesIndexesListCall) Do(opts ...googleapi.CallOption) (* }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logServices.indexes.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1060,7 +1068,7 @@ func (c *ProjectsLogServicesSinksCreateCall) Header() http.Header { func (c *ProjectsLogServicesSinksCreateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_, "x-goog-api-version", "v1_20240501") var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.logsink) if err != nil { return nil, err } @@ -1077,6 +1085,7 @@ func (c *ProjectsLogServicesSinksCreateCall) doRequest(alt string) (*http.Respon "projectsId": c.projectsId, "logServicesId": c.logServicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.create", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1111,9 +1120,11 @@ func (c *ProjectsLogServicesSinksCreateCall) Do(opts ...googleapi.CallOption) (* }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.create", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1180,6 +1191,7 @@ func (c *ProjectsLogServicesSinksDeleteCall) doRequest(alt string) (*http.Respon "logServicesId": c.logServicesId, "sinksId": c.sinksId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1214,9 +1226,11 @@ func (c *ProjectsLogServicesSinksDeleteCall) Do(opts ...googleapi.CallOption) (* }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1295,6 +1309,7 @@ func (c *ProjectsLogServicesSinksGetCall) doRequest(alt string) (*http.Response, "logServicesId": c.logServicesId, "sinksId": c.sinksId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1329,9 +1344,11 @@ func (c *ProjectsLogServicesSinksGetCall) Do(opts ...googleapi.CallOption) (*Log }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1407,6 +1424,7 @@ func (c *ProjectsLogServicesSinksListCall) doRequest(alt string) (*http.Response "projectsId": c.projectsId, "logServicesId": c.logServicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1442,9 +1460,11 @@ func (c *ProjectsLogServicesSinksListCall) Do(opts ...googleapi.CallOption) (*Li }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1499,7 +1519,7 @@ func (c *ProjectsLogServicesSinksUpdateCall) Header() http.Header { func (c *ProjectsLogServicesSinksUpdateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_, "x-goog-api-version", "v1_20240501") var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.logsink) if err != nil { return nil, err } @@ -1517,6 +1537,7 @@ func (c *ProjectsLogServicesSinksUpdateCall) doRequest(alt string) (*http.Respon "logServicesId": c.logServicesId, "sinksId": c.sinksId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.update", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1551,9 +1572,11 @@ func (c *ProjectsLogServicesSinksUpdateCall) Do(opts ...googleapi.CallOption) (* }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logServices.sinks.update", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1617,6 +1640,7 @@ func (c *ProjectsLogsDeleteCall) doRequest(alt string) (*http.Response, error) { "projectsId": c.projectsId, "logsId": c.logsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1651,9 +1675,11 @@ func (c *ProjectsLogsDeleteCall) Do(opts ...googleapi.CallOption) (*Empty, error }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1765,6 +1791,7 @@ func (c *ProjectsLogsListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "projectsId": c.projectsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1800,9 +1827,11 @@ func (c *ProjectsLogsListCall) Do(opts ...googleapi.CallOption) (*ListLogsRespon }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1882,7 +1911,7 @@ func (c *ProjectsLogsEntriesWriteCall) Header() http.Header { func (c *ProjectsLogsEntriesWriteCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_, "x-goog-api-version", "v1_20240501") var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.writelogentriesrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.writelogentriesrequest) if err != nil { return nil, err } @@ -1899,6 +1928,7 @@ func (c *ProjectsLogsEntriesWriteCall) doRequest(alt string) (*http.Response, er "projectsId": c.projectsId, "logsId": c.logsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.entries.write", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1934,9 +1964,11 @@ func (c *ProjectsLogsEntriesWriteCall) Do(opts ...googleapi.CallOption) (*WriteL }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.entries.write", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1988,7 +2020,7 @@ func (c *ProjectsLogsSinksCreateCall) Header() http.Header { func (c *ProjectsLogsSinksCreateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_, "x-goog-api-version", "v1_20240501") var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.logsink) if err != nil { return nil, err } @@ -2005,6 +2037,7 @@ func (c *ProjectsLogsSinksCreateCall) doRequest(alt string) (*http.Response, err "projectsId": c.projectsId, "logsId": c.logsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.create", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2039,9 +2072,11 @@ func (c *ProjectsLogsSinksCreateCall) Do(opts ...googleapi.CallOption) (*LogSink }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.create", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2108,6 +2143,7 @@ func (c *ProjectsLogsSinksDeleteCall) doRequest(alt string) (*http.Response, err "logsId": c.logsId, "sinksId": c.sinksId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2142,9 +2178,11 @@ func (c *ProjectsLogsSinksDeleteCall) Do(opts ...googleapi.CallOption) (*Empty, }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2223,6 +2261,7 @@ func (c *ProjectsLogsSinksGetCall) doRequest(alt string) (*http.Response, error) "logsId": c.logsId, "sinksId": c.sinksId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2257,9 +2296,11 @@ func (c *ProjectsLogsSinksGetCall) Do(opts ...googleapi.CallOption) (*LogSink, e }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2334,6 +2375,7 @@ func (c *ProjectsLogsSinksListCall) doRequest(alt string) (*http.Response, error "projectsId": c.projectsId, "logsId": c.logsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2369,9 +2411,11 @@ func (c *ProjectsLogsSinksListCall) Do(opts ...googleapi.CallOption) (*ListLogSi }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2426,7 +2470,7 @@ func (c *ProjectsLogsSinksUpdateCall) Header() http.Header { func (c *ProjectsLogsSinksUpdateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_, "x-goog-api-version", "v1_20240501") var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.logsink) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.logsink) if err != nil { return nil, err } @@ -2444,6 +2488,7 @@ func (c *ProjectsLogsSinksUpdateCall) doRequest(alt string) (*http.Response, err "logsId": c.logsId, "sinksId": c.sinksId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.update", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2478,8 +2523,10 @@ func (c *ProjectsLogsSinksUpdateCall) Do(opts ...googleapi.CallOption) (*LogSink }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "logging.projects.logs.sinks.update", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/arrayofarray-1.want b/google-api-go-generator/testdata/arrayofarray-1.want index 21b3b2fbc1a..4262b351ee7 100644 --- a/google-api-go-generator/testdata/arrayofarray-1.want +++ b/google-api-go-generator/testdata/arrayofarray-1.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/arrayofenum.want b/google-api-go-generator/testdata/arrayofenum.want index a9f4de04823..0206119fb0c 100644 --- a/google-api-go-generator/testdata/arrayofenum.want +++ b/google-api-go-generator/testdata/arrayofenum.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/arrayofmapofobjects.want b/google-api-go-generator/testdata/arrayofmapofobjects.want index 6bd02b469cb..84290738a2d 100644 --- a/google-api-go-generator/testdata/arrayofmapofobjects.want +++ b/google-api-go-generator/testdata/arrayofmapofobjects.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/arrayofmapofstrings.want b/google-api-go-generator/testdata/arrayofmapofstrings.want index 58ae792254a..229f27adc68 100644 --- a/google-api-go-generator/testdata/arrayofmapofstrings.want +++ b/google-api-go-generator/testdata/arrayofmapofstrings.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/blogger-3.want b/google-api-go-generator/testdata/blogger-3.want index 94ab15560ef..8d0ceadcb2c 100644 --- a/google-api-go-generator/testdata/blogger-3.want +++ b/google-api-go-generator/testdata/blogger-3.want @@ -62,11 +62,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -123,7 +125,15 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.BlogUserInfos = NewBlogUserInfosService(s) + s.Blogs = NewBlogsService(s) + s.Comments = NewCommentsService(s) + s.PageViews = NewPageViewsService(s) + s.Pages = NewPagesService(s) + s.PostUserInfos = NewPostUserInfosService(s) + s.Posts = NewPostsService(s) + s.Users = NewUsersService(s) if err != nil { return nil, err } @@ -142,20 +152,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.BlogUserInfos = NewBlogUserInfosService(s) - s.Blogs = NewBlogsService(s) - s.Comments = NewCommentsService(s) - s.PageViews = NewPageViewsService(s) - s.Pages = NewPagesService(s) - s.PostUserInfos = NewPostUserInfosService(s) - s.Posts = NewPostsService(s) - s.Users = NewUsersService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -1347,6 +1349,7 @@ func (c *BlogUserInfosGetCall) doRequest(alt string) (*http.Response, error) { "userId": c.userId, "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.blogUserInfos.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1381,9 +1384,11 @@ func (c *BlogUserInfosGetCall) Do(opts ...googleapi.CallOption) (*BlogUserInfo, }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.blogUserInfos.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1461,6 +1466,7 @@ func (c *BlogsGetCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.blogs.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1495,9 +1501,11 @@ func (c *BlogsGetCall) Do(opts ...googleapi.CallOption) (*Blog, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.blogs.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1564,6 +1572,7 @@ func (c *BlogsGetByUrlCall) doRequest(alt string) (*http.Response, error) { return nil, err } req.Header = reqHeaders + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.blogs.getByUrl", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1598,9 +1607,11 @@ func (c *BlogsGetByUrlCall) Do(opts ...googleapi.CallOption) (*Blog, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.blogs.getByUrl", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1691,6 +1702,7 @@ func (c *BlogsListByUserCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "userId": c.userId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.blogs.listByUser", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1725,9 +1737,11 @@ func (c *BlogsListByUserCall) Do(opts ...googleapi.CallOption) (*BlogList, error }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.blogs.listByUser", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1794,6 +1808,7 @@ func (c *CommentsApproveCall) doRequest(alt string) (*http.Response, error) { "postId": c.postId, "commentId": c.commentId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.comments.approve", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1828,9 +1843,11 @@ func (c *CommentsApproveCall) Do(opts ...googleapi.CallOption) (*Comment, error) }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.comments.approve", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1897,6 +1914,7 @@ func (c *CommentsDeleteCall) doRequest(alt string) (*http.Response, error) { "postId": c.postId, "commentId": c.commentId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.comments.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1911,6 +1929,7 @@ func (c *CommentsDeleteCall) Do(opts ...googleapi.CallOption) error { if err := googleapi.CheckResponse(res); err != nil { return gensupport.WrapError(err) } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.comments.delete", "response", internallog.HTTPResponse(res, nil)) return nil } @@ -1989,6 +2008,7 @@ func (c *CommentsGetCall) doRequest(alt string) (*http.Response, error) { "postId": c.postId, "commentId": c.commentId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.comments.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2023,9 +2043,11 @@ func (c *CommentsGetCall) Do(opts ...googleapi.CallOption) (*Comment, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.comments.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2160,6 +2182,7 @@ func (c *CommentsListCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.comments.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2194,9 +2217,11 @@ func (c *CommentsListCall) Do(opts ...googleapi.CallOption) (*CommentList, error }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.comments.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2324,6 +2349,7 @@ func (c *CommentsListByBlogCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.comments.listByBlog", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2358,9 +2384,11 @@ func (c *CommentsListByBlogCall) Do(opts ...googleapi.CallOption) (*CommentList, }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.comments.listByBlog", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2448,6 +2476,7 @@ func (c *CommentsMarkAsSpamCall) doRequest(alt string) (*http.Response, error) { "postId": c.postId, "commentId": c.commentId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.comments.markAsSpam", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2482,9 +2511,11 @@ func (c *CommentsMarkAsSpamCall) Do(opts ...googleapi.CallOption) (*Comment, err }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.comments.markAsSpam", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2551,6 +2582,7 @@ func (c *CommentsRemoveContentCall) doRequest(alt string) (*http.Response, error "postId": c.postId, "commentId": c.commentId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.comments.removeContent", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2585,9 +2617,11 @@ func (c *CommentsRemoveContentCall) Do(opts ...googleapi.CallOption) (*Comment, }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.comments.removeContent", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2670,6 +2704,7 @@ func (c *PageViewsGetCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.pageViews.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2704,9 +2739,11 @@ func (c *PageViewsGetCall) Do(opts ...googleapi.CallOption) (*Pageviews, error) }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.pageViews.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2769,6 +2806,7 @@ func (c *PagesDeleteCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "pageId": c.pageId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.pages.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2783,6 +2821,7 @@ func (c *PagesDeleteCall) Do(opts ...googleapi.CallOption) error { if err := googleapi.CheckResponse(res); err != nil { return gensupport.WrapError(err) } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.pages.delete", "response", internallog.HTTPResponse(res, nil)) return nil } @@ -2869,6 +2908,7 @@ func (c *PagesGetCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "pageId": c.pageId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.pages.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2903,9 +2943,11 @@ func (c *PagesGetCall) Do(opts ...googleapi.CallOption) (*Page, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.pages.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2954,7 +2996,7 @@ func (c *PagesInsertCall) Header() http.Header { func (c *PagesInsertCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.page) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.page) if err != nil { return nil, err } @@ -2970,6 +3012,7 @@ func (c *PagesInsertCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.pages.insert", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3004,9 +3047,11 @@ func (c *PagesInsertCall) Do(opts ...googleapi.CallOption) (*Page, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.pages.insert", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3109,6 +3154,7 @@ func (c *PagesListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.pages.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3143,9 +3189,11 @@ func (c *PagesListCall) Do(opts ...googleapi.CallOption) (*PageList, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.pages.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3197,7 +3245,7 @@ func (c *PagesPatchCall) Header() http.Header { func (c *PagesPatchCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.page) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.page) if err != nil { return nil, err } @@ -3214,6 +3262,7 @@ func (c *PagesPatchCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "pageId": c.pageId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.pages.patch", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3248,9 +3297,11 @@ func (c *PagesPatchCall) Do(opts ...googleapi.CallOption) (*Page, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.pages.patch", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3302,7 +3353,7 @@ func (c *PagesUpdateCall) Header() http.Header { func (c *PagesUpdateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.page) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.page) if err != nil { return nil, err } @@ -3319,6 +3370,7 @@ func (c *PagesUpdateCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "pageId": c.pageId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.pages.update", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3353,9 +3405,11 @@ func (c *PagesUpdateCall) Do(opts ...googleapi.CallOption) (*Page, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.pages.update", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3442,6 +3496,7 @@ func (c *PostUserInfosGetCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.postUserInfos.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3476,9 +3531,11 @@ func (c *PostUserInfosGetCall) Do(opts ...googleapi.CallOption) (*PostUserInfo, }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.postUserInfos.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3631,6 +3688,7 @@ func (c *PostUserInfosListCall) doRequest(alt string) (*http.Response, error) { "userId": c.userId, "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.postUserInfos.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3666,9 +3724,11 @@ func (c *PostUserInfosListCall) Do(opts ...googleapi.CallOption) (*PostUserInfos }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.postUserInfos.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3752,6 +3812,7 @@ func (c *PostsDeleteCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3766,6 +3827,7 @@ func (c *PostsDeleteCall) Do(opts ...googleapi.CallOption) error { if err := googleapi.CheckResponse(res); err != nil { return gensupport.WrapError(err) } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.delete", "response", internallog.HTTPResponse(res, nil)) return nil } @@ -3859,6 +3921,7 @@ func (c *PostsGetCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3893,9 +3956,11 @@ func (c *PostsGetCall) Do(opts ...googleapi.CallOption) (*Post, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3987,6 +4052,7 @@ func (c *PostsGetByPathCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.getByPath", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4021,9 +4087,11 @@ func (c *PostsGetByPathCall) Do(opts ...googleapi.CallOption) (*Post, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.getByPath", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4079,7 +4147,7 @@ func (c *PostsInsertCall) Header() http.Header { func (c *PostsInsertCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.post) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.post) if err != nil { return nil, err } @@ -4095,6 +4163,7 @@ func (c *PostsInsertCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.insert", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4129,9 +4198,11 @@ func (c *PostsInsertCall) Do(opts ...googleapi.CallOption) (*Post, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.insert", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4287,6 +4358,7 @@ func (c *PostsListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4321,9 +4393,11 @@ func (c *PostsListCall) Do(opts ...googleapi.CallOption) (*PostList, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4396,7 +4470,7 @@ func (c *PostsPatchCall) Header() http.Header { func (c *PostsPatchCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.post) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.post) if err != nil { return nil, err } @@ -4413,6 +4487,7 @@ func (c *PostsPatchCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.patch", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4447,9 +4522,11 @@ func (c *PostsPatchCall) Do(opts ...googleapi.CallOption) (*Post, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.patch", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4519,6 +4596,7 @@ func (c *PostsPublishCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.publish", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4553,9 +4631,11 @@ func (c *PostsPublishCall) Do(opts ...googleapi.CallOption) (*Post, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.publish", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4618,6 +4698,7 @@ func (c *PostsRevertCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.revert", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4652,9 +4733,11 @@ func (c *PostsRevertCall) Do(opts ...googleapi.CallOption) (*Post, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.revert", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4746,6 +4829,7 @@ func (c *PostsSearchCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "blogId": c.blogId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.search", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4780,9 +4864,11 @@ func (c *PostsSearchCall) Do(opts ...googleapi.CallOption) (*PostList, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.search", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4834,7 +4920,7 @@ func (c *PostsUpdateCall) Header() http.Header { func (c *PostsUpdateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.post) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.post) if err != nil { return nil, err } @@ -4851,6 +4937,7 @@ func (c *PostsUpdateCall) doRequest(alt string) (*http.Response, error) { "blogId": c.blogId, "postId": c.postId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.posts.update", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4885,9 +4972,11 @@ func (c *PostsUpdateCall) Do(opts ...googleapi.CallOption) (*Post, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.posts.update", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4958,6 +5047,7 @@ func (c *UsersGetCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "userId": c.userId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "blogger.users.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4992,8 +5082,10 @@ func (c *UsersGetCall) Do(opts ...googleapi.CallOption) (*User, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "blogger.users.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/floats.want b/google-api-go-generator/testdata/floats.want index 544cd5e8434..a3bfa148d1c 100644 --- a/google-api-go-generator/testdata/floats.want +++ b/google-api-go-generator/testdata/floats.want @@ -57,11 +57,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -103,7 +105,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -122,12 +124,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/getwithoutbody.want b/google-api-go-generator/testdata/getwithoutbody.want index c4a0b27fb70..233ce9bae65 100644 --- a/google-api-go-generator/testdata/getwithoutbody.want +++ b/google-api-go-generator/testdata/getwithoutbody.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.MetricDescriptors = NewMetricDescriptorsService(s) if err != nil { return nil, err } @@ -118,13 +121,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.MetricDescriptors = NewMetricDescriptorsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -288,6 +290,7 @@ func (c *MetricDescriptorsListCall) doRequest(alt string) (*http.Response, error googleapi.Expand(req.URL, map[string]string{ "project": c.project, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "getwithoutbody.metricDescriptors.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -323,9 +326,11 @@ func (c *MetricDescriptorsListCall) Do(opts ...googleapi.CallOption) (*ListMetri }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "getwithoutbody.metricDescriptors.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/http-body.want b/google-api-go-generator/testdata/http-body.want index 5e4e1d8a059..ecb80bbab3b 100644 --- a/google-api-go-generator/testdata/http-body.want +++ b/google-api-go-generator/testdata/http-body.want @@ -57,11 +57,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -114,7 +116,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Projects = NewProjectsService(s) if err != nil { return nil, err } @@ -133,13 +136,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Projects = NewProjectsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -334,7 +336,11 @@ func (c *ProjectsLocationsDatasetsFhirStoresFhirCreateResourceCall) Header() htt func (c *ProjectsLocationsDatasetsFhirStoresFhirCreateResourceCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "", c.header_) var body io.Reader = nil - body = c.body_ + body := bytes.NewBuffer(nil) + _, err := body.ReadFrom(c.body_) + if err != nil { + return nil, err + } urls := googleapi.ResolveRelative(c.s.BasePath, "v1beta1/{+parent}/fhir/{+type}") urls += "?" + c.urlParams_.Encode() req, err := http.NewRequest("POST", urls, body) @@ -346,6 +352,7 @@ func (c *ProjectsLocationsDatasetsFhirStoresFhirCreateResourceCall) doRequest(al "parent": c.parent, "type": c.type_, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "healthcare.projects.locations.datasets.fhirStores.fhir.createResource", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -443,6 +450,7 @@ func (c *ProjectsLocationsDatasetsFhirStoresFhirReadCall) doRequest(alt string) googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "healthcare.projects.locations.datasets.fhirStores.fhir.read", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } diff --git a/google-api-go-generator/testdata/json-body.want b/google-api-go-generator/testdata/json-body.want index 153a2e0cecd..ca697418b28 100644 --- a/google-api-go-generator/testdata/json-body.want +++ b/google-api-go-generator/testdata/json-body.want @@ -57,11 +57,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -114,7 +116,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Projects = NewProjectsService(s) if err != nil { return nil, err } @@ -133,13 +136,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Projects = NewProjectsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -2470,6 +2472,7 @@ func (c *ProjectsGetConfigCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.getConfig", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2505,9 +2508,11 @@ func (c *ProjectsGetConfigCall) Do(opts ...googleapi.CallOption) (*GoogleCloudMl }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.getConfig", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2564,7 +2569,7 @@ func (c *ProjectsPredictCall) Header() http.Header { func (c *ProjectsPredictCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body = strings.NewReader(c.googlecloudmlv1__predictrequest.HttpBody.Data) + body := bytes.NewBufferString(c.googlecloudmlv1__predictrequest.HttpBody.Data) c.urlParams_.Set("alt", alt) c.urlParams_.Set("prettyPrint", "false") urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+name}:predict") @@ -2577,6 +2582,7 @@ func (c *ProjectsPredictCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.predict", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2623,6 +2629,7 @@ func (c *ProjectsPredictCall) Do(opts ...googleapi.CallOption) (*GoogleApi__Http return nil, err } ret.Data = b.String() + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.predict", "response", internallog.HTTPResponse(res, b.Bytes())) return ret, nil } @@ -2671,7 +2678,7 @@ func (c *ProjectsJobsCancelCall) Header() http.Header { func (c *ProjectsJobsCancelCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__canceljobrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__canceljobrequest) if err != nil { return nil, err } @@ -2687,6 +2694,7 @@ func (c *ProjectsJobsCancelCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.cancel", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2722,9 +2730,11 @@ func (c *ProjectsJobsCancelCall) Do(opts ...googleapi.CallOption) (*GoogleProtob }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.cancel", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2773,7 +2783,7 @@ func (c *ProjectsJobsCreateCall) Header() http.Header { func (c *ProjectsJobsCreateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__job) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__job) if err != nil { return nil, err } @@ -2789,6 +2799,7 @@ func (c *ProjectsJobsCreateCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "parent": c.parent, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.create", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2824,9 +2835,11 @@ func (c *ProjectsJobsCreateCall) Do(opts ...googleapi.CallOption) (*GoogleCloudM }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.create", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2897,6 +2910,7 @@ func (c *ProjectsJobsGetCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2932,9 +2946,11 @@ func (c *ProjectsJobsGetCall) Do(opts ...googleapi.CallOption) (*GoogleCloudMlV1 }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3010,6 +3026,7 @@ func (c *ProjectsJobsGetIamPolicyCall) doRequest(alt string) (*http.Response, er googleapi.Expand(req.URL, map[string]string{ "resource": c.resource, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.getIamPolicy", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3045,9 +3062,11 @@ func (c *ProjectsJobsGetIamPolicyCall) Do(opts ...googleapi.CallOption) (*Google }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.getIamPolicy", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3159,6 +3178,7 @@ func (c *ProjectsJobsListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "parent": c.parent, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3194,9 +3214,11 @@ func (c *ProjectsJobsListCall) Do(opts ...googleapi.CallOption) (*GoogleCloudMlV }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3299,7 +3321,7 @@ func (c *ProjectsJobsPatchCall) Header() http.Header { func (c *ProjectsJobsPatchCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__job) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__job) if err != nil { return nil, err } @@ -3315,6 +3337,7 @@ func (c *ProjectsJobsPatchCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.patch", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3350,9 +3373,11 @@ func (c *ProjectsJobsPatchCall) Do(opts ...googleapi.CallOption) (*GoogleCloudMl }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.patch", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3405,7 +3430,7 @@ func (c *ProjectsJobsSetIamPolicyCall) Header() http.Header { func (c *ProjectsJobsSetIamPolicyCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googleiamv1__setiampolicyrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googleiamv1__setiampolicyrequest) if err != nil { return nil, err } @@ -3421,6 +3446,7 @@ func (c *ProjectsJobsSetIamPolicyCall) doRequest(alt string) (*http.Response, er googleapi.Expand(req.URL, map[string]string{ "resource": c.resource, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.setIamPolicy", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3456,9 +3482,11 @@ func (c *ProjectsJobsSetIamPolicyCall) Do(opts ...googleapi.CallOption) (*Google }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.setIamPolicy", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3519,7 +3547,7 @@ func (c *ProjectsJobsTestIamPermissionsCall) Header() http.Header { func (c *ProjectsJobsTestIamPermissionsCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googleiamv1__testiampermissionsrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googleiamv1__testiampermissionsrequest) if err != nil { return nil, err } @@ -3535,6 +3563,7 @@ func (c *ProjectsJobsTestIamPermissionsCall) doRequest(alt string) (*http.Respon googleapi.Expand(req.URL, map[string]string{ "resource": c.resource, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.jobs.testIamPermissions", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3570,9 +3599,11 @@ func (c *ProjectsJobsTestIamPermissionsCall) Do(opts ...googleapi.CallOption) (* }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.jobs.testIamPermissions", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3645,6 +3676,7 @@ func (c *ProjectsLocationsGetCall) doRequest(alt string) (*http.Response, error) googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.locations.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3680,9 +3712,11 @@ func (c *ProjectsLocationsGetCall) Do(opts ...googleapi.CallOption) (*GoogleClou }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.locations.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3778,6 +3812,7 @@ func (c *ProjectsLocationsListCall) doRequest(alt string) (*http.Response, error googleapi.Expand(req.URL, map[string]string{ "parent": c.parent, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.locations.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3813,9 +3848,11 @@ func (c *ProjectsLocationsListCall) Do(opts ...googleapi.CallOption) (*GoogleClo }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.locations.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3891,7 +3928,7 @@ func (c *ProjectsModelsCreateCall) Header() http.Header { func (c *ProjectsModelsCreateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__model) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__model) if err != nil { return nil, err } @@ -3907,6 +3944,7 @@ func (c *ProjectsModelsCreateCall) doRequest(alt string) (*http.Response, error) googleapi.Expand(req.URL, map[string]string{ "parent": c.parent, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.create", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3942,9 +3980,11 @@ func (c *ProjectsModelsCreateCall) Do(opts ...googleapi.CallOption) (*GoogleClou }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.create", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4009,6 +4049,7 @@ func (c *ProjectsModelsDeleteCall) doRequest(alt string) (*http.Response, error) googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4044,9 +4085,11 @@ func (c *ProjectsModelsDeleteCall) Do(opts ...googleapi.CallOption) (*GoogleLong }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4120,6 +4163,7 @@ func (c *ProjectsModelsGetCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4155,9 +4199,11 @@ func (c *ProjectsModelsGetCall) Do(opts ...googleapi.CallOption) (*GoogleCloudMl }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4233,6 +4279,7 @@ func (c *ProjectsModelsGetIamPolicyCall) doRequest(alt string) (*http.Response, googleapi.Expand(req.URL, map[string]string{ "resource": c.resource, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.getIamPolicy", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4268,9 +4315,11 @@ func (c *ProjectsModelsGetIamPolicyCall) Do(opts ...googleapi.CallOption) (*Goog }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.getIamPolicy", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4378,6 +4427,7 @@ func (c *ProjectsModelsListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "parent": c.parent, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4413,9 +4463,11 @@ func (c *ProjectsModelsListCall) Do(opts ...googleapi.CallOption) (*GoogleCloudM }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4514,7 +4566,7 @@ func (c *ProjectsModelsPatchCall) Header() http.Header { func (c *ProjectsModelsPatchCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__model) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__model) if err != nil { return nil, err } @@ -4530,6 +4582,7 @@ func (c *ProjectsModelsPatchCall) doRequest(alt string) (*http.Response, error) googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.patch", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4565,9 +4618,11 @@ func (c *ProjectsModelsPatchCall) Do(opts ...googleapi.CallOption) (*GoogleLongr }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.patch", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4620,7 +4675,7 @@ func (c *ProjectsModelsSetIamPolicyCall) Header() http.Header { func (c *ProjectsModelsSetIamPolicyCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googleiamv1__setiampolicyrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googleiamv1__setiampolicyrequest) if err != nil { return nil, err } @@ -4636,6 +4691,7 @@ func (c *ProjectsModelsSetIamPolicyCall) doRequest(alt string) (*http.Response, googleapi.Expand(req.URL, map[string]string{ "resource": c.resource, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.setIamPolicy", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4671,9 +4727,11 @@ func (c *ProjectsModelsSetIamPolicyCall) Do(opts ...googleapi.CallOption) (*Goog }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.setIamPolicy", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4734,7 +4792,7 @@ func (c *ProjectsModelsTestIamPermissionsCall) Header() http.Header { func (c *ProjectsModelsTestIamPermissionsCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googleiamv1__testiampermissionsrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googleiamv1__testiampermissionsrequest) if err != nil { return nil, err } @@ -4750,6 +4808,7 @@ func (c *ProjectsModelsTestIamPermissionsCall) doRequest(alt string) (*http.Resp googleapi.Expand(req.URL, map[string]string{ "resource": c.resource, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.testIamPermissions", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4785,9 +4844,11 @@ func (c *ProjectsModelsTestIamPermissionsCall) Do(opts ...googleapi.CallOption) }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.testIamPermissions", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4850,7 +4911,7 @@ func (c *ProjectsModelsVersionsCreateCall) Header() http.Header { func (c *ProjectsModelsVersionsCreateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__version) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__version) if err != nil { return nil, err } @@ -4866,6 +4927,7 @@ func (c *ProjectsModelsVersionsCreateCall) doRequest(alt string) (*http.Response googleapi.Expand(req.URL, map[string]string{ "parent": c.parent, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.versions.create", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4901,9 +4963,11 @@ func (c *ProjectsModelsVersionsCreateCall) Do(opts ...googleapi.CallOption) (*Go }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.versions.create", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4971,6 +5035,7 @@ func (c *ProjectsModelsVersionsDeleteCall) doRequest(alt string) (*http.Response googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.versions.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5006,9 +5071,11 @@ func (c *ProjectsModelsVersionsDeleteCall) Do(opts ...googleapi.CallOption) (*Go }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.versions.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5086,6 +5153,7 @@ func (c *ProjectsModelsVersionsGetCall) doRequest(alt string) (*http.Response, e googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.versions.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5121,9 +5189,11 @@ func (c *ProjectsModelsVersionsGetCall) Do(opts ...googleapi.CallOption) (*Googl }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.versions.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5229,6 +5299,7 @@ func (c *ProjectsModelsVersionsListCall) doRequest(alt string) (*http.Response, googleapi.Expand(req.URL, map[string]string{ "parent": c.parent, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.versions.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5264,9 +5335,11 @@ func (c *ProjectsModelsVersionsListCall) Do(opts ...googleapi.CallOption) (*Goog }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.versions.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5361,7 +5434,7 @@ func (c *ProjectsModelsVersionsPatchCall) Header() http.Header { func (c *ProjectsModelsVersionsPatchCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__version) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__version) if err != nil { return nil, err } @@ -5377,6 +5450,7 @@ func (c *ProjectsModelsVersionsPatchCall) doRequest(alt string) (*http.Response, googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.versions.patch", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5412,9 +5486,11 @@ func (c *ProjectsModelsVersionsPatchCall) Do(opts ...googleapi.CallOption) (*Goo }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.versions.patch", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5476,7 +5552,7 @@ func (c *ProjectsModelsVersionsSetDefaultCall) Header() http.Header { func (c *ProjectsModelsVersionsSetDefaultCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.googlecloudmlv1__setdefaultversionrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.googlecloudmlv1__setdefaultversionrequest) if err != nil { return nil, err } @@ -5492,6 +5568,7 @@ func (c *ProjectsModelsVersionsSetDefaultCall) doRequest(alt string) (*http.Resp googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.models.versions.setDefault", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5527,9 +5604,11 @@ func (c *ProjectsModelsVersionsSetDefaultCall) Do(opts ...googleapi.CallOption) }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.models.versions.setDefault", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5600,6 +5679,7 @@ func (c *ProjectsOperationsCancelCall) doRequest(alt string) (*http.Response, er googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.operations.cancel", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5635,9 +5715,11 @@ func (c *ProjectsOperationsCancelCall) Do(opts ...googleapi.CallOption) (*Google }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.operations.cancel", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5702,6 +5784,7 @@ func (c *ProjectsOperationsDeleteCall) doRequest(alt string) (*http.Response, er googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.operations.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5737,9 +5820,11 @@ func (c *ProjectsOperationsDeleteCall) Do(opts ...googleapi.CallOption) (*Google }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.operations.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5814,6 +5899,7 @@ func (c *ProjectsOperationsGetCall) doRequest(alt string) (*http.Response, error googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.operations.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5849,9 +5935,11 @@ func (c *ProjectsOperationsGetCall) Do(opts ...googleapi.CallOption) (*GoogleLon }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.operations.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -5955,6 +6043,7 @@ func (c *ProjectsOperationsListCall) doRequest(alt string) (*http.Response, erro googleapi.Expand(req.URL, map[string]string{ "name": c.name, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "ml.projects.operations.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -5990,9 +6079,11 @@ func (c *ProjectsOperationsListCall) Do(opts ...googleapi.CallOption) (*GoogleLo }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "ml.projects.operations.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/mapofany.want b/google-api-go-generator/testdata/mapofany.want index f301cd52304..fe3769e4bf8 100644 --- a/google-api-go-generator/testdata/mapofany.want +++ b/google-api-go-generator/testdata/mapofany.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/mapofarrayofobjects.want b/google-api-go-generator/testdata/mapofarrayofobjects.want index 9438d2e7fe2..8603f0eecda 100644 --- a/google-api-go-generator/testdata/mapofarrayofobjects.want +++ b/google-api-go-generator/testdata/mapofarrayofobjects.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Atlas = NewAtlasService(s) if err != nil { return nil, err } @@ -118,13 +121,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Atlas = NewAtlasService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -239,6 +241,7 @@ func (c *AtlasGetMapCall) doRequest(alt string) (*http.Response, error) { return nil, err } req.Header = reqHeaders + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "mapofstrings.getMap", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -255,8 +258,10 @@ func (c *AtlasGetMapCall) Do(opts ...googleapi.CallOption) (map[string]string, e } var ret map[string]string target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "mapofstrings.getMap", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/mapofint64strings.want b/google-api-go-generator/testdata/mapofint64strings.want index 54883d21d81..b6a6501f39e 100644 --- a/google-api-go-generator/testdata/mapofint64strings.want +++ b/google-api-go-generator/testdata/mapofint64strings.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/mapofobjects.want b/google-api-go-generator/testdata/mapofobjects.want index edd7116578d..f03096ef316 100644 --- a/google-api-go-generator/testdata/mapofobjects.want +++ b/google-api-go-generator/testdata/mapofobjects.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/mapofstrings-1.want b/google-api-go-generator/testdata/mapofstrings-1.want index f2173014861..e65fad66bc9 100644 --- a/google-api-go-generator/testdata/mapofstrings-1.want +++ b/google-api-go-generator/testdata/mapofstrings-1.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Atlas = NewAtlasService(s) if err != nil { return nil, err } @@ -118,13 +121,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Atlas = NewAtlasService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -236,6 +238,7 @@ func (c *AtlasGetMapCall) doRequest(alt string) (*http.Response, error) { return nil, err } req.Header = reqHeaders + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "mapofstrings.getMap", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -252,8 +255,10 @@ func (c *AtlasGetMapCall) Do(opts ...googleapi.CallOption) (map[string]string, e } var ret map[string]string target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "mapofstrings.getMap", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/mapprotostruct.want b/google-api-go-generator/testdata/mapprotostruct.want index 74118a411a2..03cf5a6eec3 100644 --- a/google-api-go-generator/testdata/mapprotostruct.want +++ b/google-api-go-generator/testdata/mapprotostruct.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Atlas = NewAtlasService(s) if err != nil { return nil, err } @@ -118,13 +121,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Atlas = NewAtlasService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -204,7 +206,7 @@ func (c *AtlasGetMapCall) doRequest(alt string) (*http.Response, error) { if err != nil { return nil, err } - body = bytes.NewReader(protoBytes) + body := bytes.NewReader(protoBytes) urls := googleapi.ResolveRelative(c.s.BasePath, "map") urls += "?" + c.urlParams_.Encode() req, err := http.NewRequest("GET", urls, body) @@ -212,6 +214,7 @@ func (c *AtlasGetMapCall) doRequest(alt string) (*http.Response, error) { return nil, err } req.Header = reqHeaders + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "mapprotostruct.getMap", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -228,8 +231,10 @@ func (c *AtlasGetMapCall) Do(opts ...googleapi.CallOption) (map[string]any, erro } var ret map[string]any target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "mapprotostruct.getMap", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/param-rename.want b/google-api-go-generator/testdata/param-rename.want index 745170b91a2..c311cd8ffac 100644 --- a/google-api-go-generator/testdata/param-rename.want +++ b/google-api-go-generator/testdata/param-rename.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,9 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Events = NewEventsService(s) + s.Reports = NewReportsService(s) if err != nil { return nil, err } @@ -118,14 +122,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Events = NewEventsService(s) - s.Reports = NewReportsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -227,6 +229,7 @@ func (c *EventsMoveCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "right-string": c.rightString, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "calendar.events.move", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -261,9 +264,11 @@ func (c *EventsMoveCall) Do(opts ...googleapi.CallOption) (*Event, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "calendar.events.move", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -331,6 +336,7 @@ func (c *ReportsQueryCall) doRequest(alt string) (*http.Response, error) { return nil, err } req.Header = reqHeaders + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "youtubeAnalytics.reports.query", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -365,8 +371,10 @@ func (c *ReportsQueryCall) Do(opts ...googleapi.CallOption) (*ResultTable, error }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "youtubeAnalytics.reports.query", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/quotednum.want b/google-api-go-generator/testdata/quotednum.want index 3cacb89a0bc..5d0ba184967 100644 --- a/google-api-go-generator/testdata/quotednum.want +++ b/google-api-go-generator/testdata/quotednum.want @@ -57,11 +57,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -114,7 +116,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -133,12 +135,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/repeated.want b/google-api-go-generator/testdata/repeated.want index a56b2ec3e43..e8642576542 100644 --- a/google-api-go-generator/testdata/repeated.want +++ b/google-api-go-generator/testdata/repeated.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Accounts = NewAccountsService(s) if err != nil { return nil, err } @@ -118,13 +121,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Accounts = NewAccountsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -261,6 +263,7 @@ func (c *AccountsReportsGenerateCall) doRequest(alt string) (*http.Response, err googleapi.Expand(req.URL, map[string]string{ "accountId": c.accountId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "adsense.accounts.reports.generate", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -275,5 +278,6 @@ func (c *AccountsReportsGenerateCall) Do(opts ...googleapi.CallOption) error { if err := googleapi.CheckResponse(res); err != nil { return gensupport.WrapError(err) } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "adsense.accounts.reports.generate", "response", internallog.HTTPResponse(res, nil)) return nil } diff --git a/google-api-go-generator/testdata/required-query.want b/google-api-go-generator/testdata/required-query.want index 2112fea886e..cd61d6ef1cb 100644 --- a/google-api-go-generator/testdata/required-query.want +++ b/google-api-go-generator/testdata/required-query.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Techs = NewTechsService(s) if err != nil { return nil, err } @@ -118,13 +121,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - s.Techs = NewTechsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -235,6 +237,7 @@ func (c *TechsCountCall) doRequest(alt string) (*http.Response, error) { return nil, err } req.Header = reqHeaders + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "tshealth.techs.count", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -270,8 +273,10 @@ func (c *TechsCountCall) Do(opts ...googleapi.CallOption) (*Google3CorpSupportTo }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "tshealth.techs.count", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/resource-named-service.want b/google-api-go-generator/testdata/resource-named-service.want index 6cd5bc0d683..00ff87ef838 100644 --- a/google-api-go-generator/testdata/resource-named-service.want +++ b/google-api-go-generator/testdata/resource-named-service.want @@ -57,11 +57,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -114,7 +116,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*APIService, if err != nil { return nil, err } - s, err := New(client) + s := &APIService{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} + s.Apps = NewAppsService(s) if err != nil { return nil, err } @@ -133,13 +136,12 @@ func New(client *http.Client) (*APIService, error) { if client == nil { return nil, errors.New("client is nil") } - s := &APIService{client: client, BasePath: basePath} - s.Apps = NewAppsService(s) - return s, nil + return NewService(option.WithHTTPClient(client)) } type APIService struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment @@ -1825,6 +1827,7 @@ func (c *AppsGetCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "appsId": c.appsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1859,9 +1862,11 @@ func (c *AppsGetCall) Do(opts ...googleapi.CallOption) (*Application, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -1914,7 +1919,7 @@ func (c *AppsRepairCall) Header() http.Header { func (c *AppsRepairCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.repairapplicationrequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.repairapplicationrequest) if err != nil { return nil, err } @@ -1930,6 +1935,7 @@ func (c *AppsRepairCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "appsId": c.appsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.repair", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -1964,9 +1970,11 @@ func (c *AppsRepairCall) Do(opts ...googleapi.CallOption) (*Operation, error) { }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.repair", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2041,6 +2049,7 @@ func (c *AppsLocationsGetCall) doRequest(alt string) (*http.Response, error) { "appsId": c.appsId, "locationsId": c.locationsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.locations.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2075,9 +2084,11 @@ func (c *AppsLocationsGetCall) Do(opts ...googleapi.CallOption) (*Location, erro }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.locations.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2169,6 +2180,7 @@ func (c *AppsLocationsListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "appsId": c.appsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.locations.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2204,9 +2216,11 @@ func (c *AppsLocationsListCall) Do(opts ...googleapi.CallOption) (*ListLocations }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.locations.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2304,6 +2318,7 @@ func (c *AppsOperationsGetCall) doRequest(alt string) (*http.Response, error) { "appsId": c.appsId, "operationsId": c.operationsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.operations.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2338,9 +2353,11 @@ func (c *AppsOperationsGetCall) Do(opts ...googleapi.CallOption) (*Operation, er }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.operations.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2434,6 +2451,7 @@ func (c *AppsOperationsListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "appsId": c.appsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.operations.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2469,9 +2487,11 @@ func (c *AppsOperationsListCall) Do(opts ...googleapi.CallOption) (*ListOperatio }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.operations.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2556,6 +2576,7 @@ func (c *AppsServicesDeleteCall) doRequest(alt string) (*http.Response, error) { "appsId": c.appsId, "servicesId": c.servicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2590,9 +2611,11 @@ func (c *AppsServicesDeleteCall) Do(opts ...googleapi.CallOption) (*Operation, e }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2668,6 +2691,7 @@ func (c *AppsServicesGetCall) doRequest(alt string) (*http.Response, error) { "appsId": c.appsId, "servicesId": c.servicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2702,9 +2726,11 @@ func (c *AppsServicesGetCall) Do(opts ...googleapi.CallOption) (*Service, error) }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2790,6 +2816,7 @@ func (c *AppsServicesListCall) doRequest(alt string) (*http.Response, error) { googleapi.Expand(req.URL, map[string]string{ "appsId": c.appsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2825,9 +2852,11 @@ func (c *AppsServicesListCall) Do(opts ...googleapi.CallOption) (*ListServicesRe }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -2927,7 +2956,7 @@ func (c *AppsServicesPatchCall) Header() http.Header { func (c *AppsServicesPatchCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.service) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.service) if err != nil { return nil, err } @@ -2944,6 +2973,7 @@ func (c *AppsServicesPatchCall) doRequest(alt string) (*http.Response, error) { "appsId": c.appsId, "servicesId": c.servicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.patch", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -2978,9 +3008,11 @@ func (c *AppsServicesPatchCall) Do(opts ...googleapi.CallOption) (*Operation, er }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.patch", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3033,7 +3065,7 @@ func (c *AppsServicesVersionsCreateCall) Header() http.Header { func (c *AppsServicesVersionsCreateCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.version) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.version) if err != nil { return nil, err } @@ -3050,6 +3082,7 @@ func (c *AppsServicesVersionsCreateCall) doRequest(alt string) (*http.Response, "appsId": c.appsId, "servicesId": c.servicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.create", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3084,9 +3117,11 @@ func (c *AppsServicesVersionsCreateCall) Do(opts ...googleapi.CallOption) (*Oper }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.create", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3154,6 +3189,7 @@ func (c *AppsServicesVersionsDeleteCall) doRequest(alt string) (*http.Response, "servicesId": c.servicesId, "versionsId": c.versionsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3188,9 +3224,11 @@ func (c *AppsServicesVersionsDeleteCall) Do(opts ...googleapi.CallOption) (*Oper }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3284,6 +3322,7 @@ func (c *AppsServicesVersionsGetCall) doRequest(alt string) (*http.Response, err "servicesId": c.servicesId, "versionsId": c.versionsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3318,9 +3357,11 @@ func (c *AppsServicesVersionsGetCall) Do(opts ...googleapi.CallOption) (*Version }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3422,6 +3463,7 @@ func (c *AppsServicesVersionsListCall) doRequest(alt string) (*http.Response, er "appsId": c.appsId, "servicesId": c.servicesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3457,9 +3499,11 @@ func (c *AppsServicesVersionsListCall) Do(opts ...googleapi.CallOption) (*ListVe }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3557,7 +3601,7 @@ func (c *AppsServicesVersionsPatchCall) Header() http.Header { func (c *AppsServicesVersionsPatchCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.version) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.version) if err != nil { return nil, err } @@ -3575,6 +3619,7 @@ func (c *AppsServicesVersionsPatchCall) doRequest(alt string) (*http.Response, e "servicesId": c.servicesId, "versionsId": c.versionsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.patch", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3609,9 +3654,11 @@ func (c *AppsServicesVersionsPatchCall) Do(opts ...googleapi.CallOption) (*Opera }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.patch", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3675,7 +3722,7 @@ func (c *AppsServicesVersionsInstancesDebugCall) Header() http.Header { func (c *AppsServicesVersionsInstancesDebugCall) doRequest(alt string) (*http.Response, error) { reqHeaders := gensupport.SetHeaders(c.s.userAgent(), "application/json", c.header_) var body io.Reader = nil - body, err := googleapi.WithoutDataWrapper.JSONReader(c.debuginstancerequest) + body, err := googleapi.WithoutDataWrapper.JSONBuffer(c.debuginstancerequest) if err != nil { return nil, err } @@ -3694,6 +3741,7 @@ func (c *AppsServicesVersionsInstancesDebugCall) doRequest(alt string) (*http.Re "versionsId": c.versionsId, "instancesId": c.instancesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.debug", "request", internallog.HTTPRequest(req, body.Bytes())) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3728,9 +3776,11 @@ func (c *AppsServicesVersionsInstancesDebugCall) Do(opts ...googleapi.CallOption }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.debug", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3802,6 +3852,7 @@ func (c *AppsServicesVersionsInstancesDeleteCall) doRequest(alt string) (*http.R "versionsId": c.versionsId, "instancesId": c.instancesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.delete", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3836,9 +3887,11 @@ func (c *AppsServicesVersionsInstancesDeleteCall) Do(opts ...googleapi.CallOptio }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.delete", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -3922,6 +3975,7 @@ func (c *AppsServicesVersionsInstancesGetCall) doRequest(alt string) (*http.Resp "versionsId": c.versionsId, "instancesId": c.instancesId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.get", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -3956,9 +4010,11 @@ func (c *AppsServicesVersionsInstancesGetCall) Do(opts ...googleapi.CallOption) }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.get", "response", internallog.HTTPResponse(res, b)) return ret, nil } @@ -4052,6 +4108,7 @@ func (c *AppsServicesVersionsInstancesListCall) doRequest(alt string) (*http.Res "servicesId": c.servicesId, "versionsId": c.versionsId, }) + c.s.logger.DebugContext(c.ctx_, "api request", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.list", "request", internallog.HTTPRequest(req, nil)) return gensupport.SendRequest(c.ctx_, c.s.client, req) } @@ -4087,9 +4144,11 @@ func (c *AppsServicesVersionsInstancesListCall) Do(opts ...googleapi.CallOption) }, } target := &ret - if err := gensupport.DecodeResponse(target, res); err != nil { + b, err := gensupport.DecodeResponseBytes(target, res) + if err != nil { return nil, err } + c.s.logger.DebugContext(c.ctx_, "api response", "serviceName", apiName, "rpcName", "appengine.apps.services.versions.instances.list", "response", internallog.HTTPResponse(res, b)) return ret, nil } diff --git a/google-api-go-generator/testdata/unfortunatedefaults.want b/google-api-go-generator/testdata/unfortunatedefaults.want index 5b0c7f666e4..1f058bdb9e2 100644 --- a/google-api-go-generator/testdata/unfortunatedefaults.want +++ b/google-api-go-generator/testdata/unfortunatedefaults.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/variants.want b/google-api-go-generator/testdata/variants.want index bdb5c72f0a4..302e60c9e53 100644 --- a/google-api-go-generator/testdata/variants.want +++ b/google-api-go-generator/testdata/variants.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/google-api-go-generator/testdata/wrapnewlines.want b/google-api-go-generator/testdata/wrapnewlines.want index 4bc5d3b6e1f..50351f07fa0 100644 --- a/google-api-go-generator/testdata/wrapnewlines.want +++ b/google-api-go-generator/testdata/wrapnewlines.want @@ -55,11 +55,13 @@ import ( "errors" "fmt" "io" + "log/slog" "net/http" "net/url" "strconv" "strings" + "github.com/googleapis/gax-go/v2/internallog" googleapi "google.golang.org/api/googleapi" internal "google.golang.org/api/internal" gensupport "google.golang.org/api/internal/gensupport" @@ -99,7 +101,7 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath, logger: internaloption.GetLogger(opts)} if err != nil { return nil, err } @@ -118,12 +120,12 @@ func New(client *http.Client) (*Service, error) { if client == nil { return nil, errors.New("client is nil") } - s := &Service{client: client, BasePath: basePath} - return s, nil + return NewService(option.WithHTTPClient(client)) } type Service struct { client *http.Client + logger *slog.Logger BasePath string // API endpoint base URL UserAgent string // optional additional User-Agent fragment } diff --git a/googleapi/googleapi.go b/googleapi/googleapi.go index 04a10f51c97..a5fdd73c314 100644 --- a/googleapi/googleapi.go +++ b/googleapi/googleapi.go @@ -201,6 +201,10 @@ var WithDataWrapper = MarshalStyle(true) var WithoutDataWrapper = MarshalStyle(false) func (wrap MarshalStyle) JSONReader(v interface{}) (io.Reader, error) { + return wrap.JSONBuffer(v) +} + +func (wrap MarshalStyle) JSONBuffer(v interface{}) (*bytes.Buffer, error) { buf := new(bytes.Buffer) if wrap { buf.Write([]byte(`{"data": `)) diff --git a/internal/gensupport/send.go b/internal/gensupport/send.go index f6716134ebf..f25c953ddee 100644 --- a/internal/gensupport/send.go +++ b/internal/gensupport/send.go @@ -9,6 +9,7 @@ import ( "encoding/json" "errors" "fmt" + "io" "net/http" "strings" "time" @@ -222,3 +223,19 @@ func DecodeResponse(target interface{}, res *http.Response) error { } return json.NewDecoder(res.Body).Decode(target) } + +// DecodeResponse decodes the body of res into target and returns bytes read +// from the body. If there is no body, target is unchanged. +func DecodeResponseBytes(target interface{}, res *http.Response) ([]byte, error) { + if res.StatusCode == http.StatusNoContent { + return nil, nil + } + b, err := io.ReadAll(res.Body) + if err != nil { + return nil, err + } + if err := json.Unmarshal(b, target); err != nil { + return nil, err + } + return b, nil +} diff --git a/secretmanager/v1/secretmanager-gen.go b/secretmanager/v1/secretmanager-gen.go index 359558a4b16..1222a6afdfb 100644 --- a/secretmanager/v1/secretmanager-gen.go +++ b/secretmanager/v1/secretmanager-gen.go @@ -115,7 +115,8 @@ func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, err if err != nil { return nil, err } - s, err := New(client) + s := &Service{client: client, BasePath: basePath} + s.Projects = NewProjectsService(s) if err != nil { return nil, err }