Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: start reporting a meaningful version in headers #1426

Merged
merged 6 commits into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion google-api-go-generator/Makefile
Expand Up @@ -9,7 +9,6 @@ GENERATOR=./google-api-go-generator
# All downloaded files are cached in $TMPDIR for reuse with 'cached' below.
all: SHELL:=/bin/bash
all: $(GENERATOR)
cd ../internal/version; go generate
$(GENERATOR) -cache=false -install -api=* -gendir=..
go test . -v

Expand Down
5 changes: 3 additions & 2 deletions google-api-go-generator/gen.go
Expand Up @@ -27,7 +27,6 @@ import (
"unicode"

"google.golang.org/api/google-api-go-generator/internal/disco"
"google.golang.org/api/internal/version"
)

const (
Expand All @@ -50,6 +49,7 @@ var (
baseURL = flag.String("base_url", "", "(optional) Override the default service API URL. If empty, the service's root URL will be used.")
headerPath = flag.String("header_path", "", "If non-empty, prepend the contents of this file to generated services.")

internalPkg = flag.String("internal_pkg", "google.golang.org/api/internal", "Go package path of the 'internal' support package.")
gensupportPkg = flag.String("gensupport_pkg", "google.golang.org/api/internal/gensupport", "Go package path of the 'api/internal/gensupport' support package.")
googleapiPkg = flag.String("googleapi_pkg", "google.golang.org/api/googleapi", "Go package path of the 'api/googleapi' support package.")
optionPkg = flag.String("option_pkg", "google.golang.org/api/option", "Go package path of the 'api/option' support package.")
Expand Down Expand Up @@ -706,6 +706,7 @@ func (a *API) GenerateCode() ([]byte, error) {
pkg string
lname string
}{
{*internalPkg, "internal"},
{*gensupportPkg, "gensupport"},
{*googleapiPkg, "googleapi"},
{*optionPkg, "option"},
Expand Down Expand Up @@ -2071,7 +2072,7 @@ func (meth *Method) generateCode() {

pn("\nfunc (c *%s) doRequest(alt string) (*http.Response, error) {", callName)
pn(`reqHeaders := make(http.Header)`)
pn(`reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/%s")`, version.Repo)
pn(`reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/"+internal.Version)`)
pn("for k, v := range c.header_ {")
pn(" reqHeaders[k] = v")
pn("}")
Expand Down
6 changes: 3 additions & 3 deletions google-api-go-generator/gen_test.go
Expand Up @@ -14,7 +14,7 @@ import (
"testing"

"google.golang.org/api/google-api-go-generator/internal/disco"
"google.golang.org/api/internal/version"
"google.golang.org/api/internal"
)

var updateGolden = flag.Bool("update_golden", false, "If true, causes TestAPIs to update golden files")
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestAPIs(t *testing.T) {
}
goldenFile := filepath.Join("testdata", name+".want")
if *updateGolden {
clean := strings.Replace(string(clean), fmt.Sprintf("gdcl/%s", version.Repo), "gdcl/00000000", -1)
clean := strings.Replace(string(clean), fmt.Sprintf("gdcl/%s", internal.Version), "gdcl/00000000", -1)
if err := ioutil.WriteFile(goldenFile, []byte(clean), 0644); err != nil {
t.Fatal(err)
}
Expand All @@ -68,7 +68,7 @@ func TestAPIs(t *testing.T) {
if err != nil {
t.Fatal(err)
}
wantStr := strings.Replace(string(want), "gdcl/00000000", fmt.Sprintf("gdcl/%s", version.Repo), -1)
wantStr := strings.Replace(string(want), "gdcl/00000000", fmt.Sprintf("gdcl/%s", internal.Version), -1)
if !bytes.Equal([]byte(wantStr), clean) {
tf, _ := ioutil.TempFile("", "api-"+name+"-got-json.")
if _, err := tf.Write(clean); err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/version.go
@@ -0,0 +1,7 @@
// Copyright 2022 Google LLC. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package internal

const Version = "0.67.0"
codyoss marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 0 additions & 10 deletions internal/version/update_version.sh

This file was deleted.

13 changes: 0 additions & 13 deletions internal/version/version.go

This file was deleted.