Skip to content

Commit

Permalink
internal: add golint to vet.sh
Browse files Browse the repository at this point in the history
Change-Id: Ib812e2d562b34fd86b6236cb9d30777de16694f9
Reviewed-on: https://code-review.googlesource.com/c/35592
Reviewed-by: kokoro <[email protected]>
Reviewed-by: Eno Compton <[email protected]>
  • Loading branch information
jeanbza committed Nov 26, 2018
1 parent 8970221 commit 09030fc
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 34 deletions.
10 changes: 5 additions & 5 deletions examples/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func computeMain(client *http.Client, argv []string) {
log.Fatalf("Unable to create Compute service: %v", err)
}

projectId := argv[0]
projectID := argv[0]
instanceName := argv[1]

prefix := "https://www.googleapis.com/compute/v1/projects/" + projectId
prefix := "https://www.googleapis.com/compute/v1/projects/" + projectID
imageURL := "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140606"
zone := "us-central1-a"

// Show the current images that are available.
res, err := service.Images.List(projectId).Do()
res, err := service.Images.List(projectID).Do()
log.Printf("Got compute.Images.List, err: %#v, %v", res, err)

instance := &compute.Instance{
Expand Down Expand Up @@ -92,12 +92,12 @@ func computeMain(client *http.Client, argv []string) {
},
}

op, err := service.Instances.Insert(projectId, zone, instance).Do()
op, err := service.Instances.Insert(projectID, zone, instance).Do()
log.Printf("Got compute.Operation, err: %#v, %v", op, err)
etag := op.Header.Get("Etag")
log.Printf("Etag=%v", etag)

inst, err := service.Instances.Get(projectId, zone, instanceName).IfNoneMatch(etag).Do()
inst, err := service.Instances.Get(projectID, zone, instanceName).IfNoneMatch(etag).Do()
log.Printf("Got compute.Instance, err: %#v, %v", inst, err)
if googleapi.IsNotModified(err) {
log.Printf("Instance not modified since insert.")
Expand Down
5 changes: 5 additions & 0 deletions gensupport/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"
)

// BackoffStrategy defines the set of functions that a backoff-er must
// implement.
type BackoffStrategy interface {
// Pause returns the duration of the next pause and true if the operation should be
// retried, or false if no further retries should be attempted.
Expand All @@ -28,6 +30,7 @@ type ExponentialBackoff struct {
n uint
}

// Pause returns the amount of time the caller should wait.
func (eb *ExponentialBackoff) Pause() (time.Duration, bool) {
if eb.total > eb.Max {
return 0, false
Expand All @@ -40,6 +43,8 @@ func (eb *ExponentialBackoff) Pause() (time.Duration, bool) {
return d, true
}

// Reset resets the backoff strategy such that the next Pause call will begin
// counting from the start. It is not safe to call concurrently with Pause.
func (eb *ExponentialBackoff) Reset() {
eb.n = 0
eb.total = 0
Expand Down
4 changes: 3 additions & 1 deletion gensupport/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"google.golang.org/api/googleapi"
)

// MediaBuffer buffers data from an io.Reader to support uploading media in retryable chunks.
// MediaBuffer buffers data from an io.Reader to support uploading media in
// retryable chunks. It should be created with NewMediaBuffer.
type MediaBuffer struct {
media io.Reader

Expand All @@ -22,6 +23,7 @@ type MediaBuffer struct {
off int64
}

// NewMediaBuffer initializes a MediaBuffer.
func NewMediaBuffer(media io.Reader, chunkSize int) *MediaBuffer {
return &MediaBuffer{media: media, chunk: make([]byte, 0, chunkSize)}
}
Expand Down
1 change: 1 addition & 0 deletions gensupport/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func NewInfoFromResumableMedia(r io.ReaderAt, size int64, mediaType string) *Med
}
}

// SetProgressUpdater sets the progress updater for the media info.
func (mi *MediaInfo) SetProgressUpdater(pu googleapi.ProgressUpdater) {
if mi != nil {
mi.progressUpdater = pu
Expand Down
1 change: 1 addition & 0 deletions gensupport/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (u URLParams) Encode() string {
return url.Values(u).Encode()
}

// SetOptions sets the URL params and any additional call options.
func SetOptions(u URLParams, opts ...googleapi.CallOption) {
for _, o := range opts {
u.Set(o.Get())
Expand Down
24 changes: 19 additions & 5 deletions googleapi/googleapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,28 @@ type SizeReaderAt interface {
// ServerResponse is embedded in each Do response and
// provides the HTTP status code and header sent by the server.
type ServerResponse struct {
// HTTPStatusCode is the server's response status code.
// When using a resource method's Do call, this will always be in the 2xx range.
// HTTPStatusCode is the server's response status code. When using a
// resource method's Do call, this will always be in the 2xx range.
HTTPStatusCode int
// Header contains the response header fields from the server.
Header http.Header
}

const (
// Version defines the gax version being used. This is typically sent
// in an HTTP header to services.
Version = "0.5"

// UserAgent is the header string used to identify this package.
UserAgent = "google-api-go-client/" + Version

// The default chunk size to use for resumable uploads if not specified by the user.
// DefaultUploadChunkSize is the default chunk size to use for resumable
// uploads if not specified by the user.
DefaultUploadChunkSize = 8 * 1024 * 1024

// The minimum chunk size that can be used for resumable uploads. All
// user-specified chunk sizes must be multiple of this value.
// MinUploadChunkSize is the minimum chunk size that can be used for
// resumable uploads. All user-specified chunk sizes must be multiple of
// this value.
MinUploadChunkSize = 256 * 1024
)

Expand Down Expand Up @@ -161,9 +165,13 @@ func CheckMediaResponse(res *http.Response) error {
}
}

// MarshalStyle defines whether to marshal JSON with a {"data": ...} wrapper.
type MarshalStyle bool

// WithDataWrapper marshals JSON with a {"data": ...} wrapper.
var WithDataWrapper = MarshalStyle(true)

// WithoutDataWrapper marshals JSON without a {"data": ...} wrapper.
var WithoutDataWrapper = MarshalStyle(false)

func (wrap MarshalStyle) JSONReader(v interface{}) (io.Reader, error) {
Expand Down Expand Up @@ -212,6 +220,7 @@ func (w countingWriter) Write(p []byte) (int, error) {
// The remaining usable pieces of resumable uploads is exposed in each auto-generated API.
type ProgressUpdater func(current, total int64)

// MediaOption defines the interface for setting media options.
type MediaOption interface {
setOptions(o *MediaOptions)
}
Expand Down Expand Up @@ -268,6 +277,11 @@ func ProcessMediaOptions(opts []MediaOption) *MediaOptions {
return mo
}

// ResolveRelative resolves relatives such as "http://www.golang.org/" and
// "topics/myproject/mytopic" into a single string, such as
// "http://www.golang.org/topics/myproject/mytopic". It strips all parent
// references (e.g. ../..) as well as anything after the host
// (e.g. /bar/gaz gets stripped out of foo.com/bar/gaz).
func ResolveRelative(basestr, relstr string) string {
u, _ := url.Parse(basestr)
afterColonPath := ""
Expand Down
6 changes: 3 additions & 3 deletions googleapi/googleapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ func TestCheckResponse(t *testing.T) {
g := CheckResponse(res)
if !reflect.DeepEqual(g, test.want) {
t.Errorf("CheckResponse: got %v, want %v", g, test.want)
gotJson, err := json.Marshal(g)
gotJSON, err := json.Marshal(g)
if err != nil {
t.Error(err)
}
wantJson, err := json.Marshal(test.want)
wantJSON, err := json.Marshal(test.want)
if err != nil {
t.Error(err)
}
t.Errorf("json(got): %q\njson(want): %q", string(gotJson), string(wantJson))
t.Errorf("json(got): %q\njson(want): %q", string(gotJSON), string(wantJSON))
}
if g != nil && g.Error() != test.errText {
t.Errorf("CheckResponse: unexpected error message.\nGot: %q\nwant: %q", g, test.errText)
Expand Down
30 changes: 15 additions & 15 deletions googleapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,33 @@ func quotedList(n int, fn func(dst []byte, i int) []byte) ([]byte, error) {
return dst, nil
}

func (s Int64s) MarshalJSON() ([]byte, error) {
return quotedList(len(s), func(dst []byte, i int) []byte {
return strconv.AppendInt(dst, s[i], 10)
func (q Int64s) MarshalJSON() ([]byte, error) {
return quotedList(len(q), func(dst []byte, i int) []byte {
return strconv.AppendInt(dst, q[i], 10)
})
}

func (s Int32s) MarshalJSON() ([]byte, error) {
return quotedList(len(s), func(dst []byte, i int) []byte {
return strconv.AppendInt(dst, int64(s[i]), 10)
func (q Int32s) MarshalJSON() ([]byte, error) {
return quotedList(len(q), func(dst []byte, i int) []byte {
return strconv.AppendInt(dst, int64(q[i]), 10)
})
}

func (s Uint64s) MarshalJSON() ([]byte, error) {
return quotedList(len(s), func(dst []byte, i int) []byte {
return strconv.AppendUint(dst, s[i], 10)
func (q Uint64s) MarshalJSON() ([]byte, error) {
return quotedList(len(q), func(dst []byte, i int) []byte {
return strconv.AppendUint(dst, q[i], 10)
})
}

func (s Uint32s) MarshalJSON() ([]byte, error) {
return quotedList(len(s), func(dst []byte, i int) []byte {
return strconv.AppendUint(dst, uint64(s[i]), 10)
func (q Uint32s) MarshalJSON() ([]byte, error) {
return quotedList(len(q), func(dst []byte, i int) []byte {
return strconv.AppendUint(dst, uint64(q[i]), 10)
})
}

func (s Float64s) MarshalJSON() ([]byte, error) {
return quotedList(len(s), func(dst []byte, i int) []byte {
return strconv.AppendFloat(dst, s[i], 'g', -1, 64)
func (q Float64s) MarshalJSON() ([]byte, error) {
return quotedList(len(q), func(dst []byte, i int) []byte {
return strconv.AppendFloat(dst, q[i], 'g', -1, 64)
})
}

Expand Down
16 changes: 16 additions & 0 deletions internal/kokoro/vet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ try3 go get -u \
git ls-files "*[^.pb].go" | xargs grep -L "\(Copyright [0-9]\{4,\}\)" 2>&1 | tee /dev/stderr | (! read)
gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read)
goimports -l . 2>&1 | tee /dev/stderr | (! read)

# Runs the linter. Regrettably the linter is very simple and does not provide the ability to exclude rules or files,
# so we rely on inverse grepping to do this for us.
golint ./... 2>&1 | ( \
grep -v "gen.go" | \
grep -v "disco.go" | \
grep -v "exported const DefaultDelayThreshold should have comment" | \
grep -v "exported const DefaultBundleCountThreshold should have comment" | \
grep -v "exported const DefaultBundleByteThreshold should have comment" | \
grep -v "exported const DefaultBufferedByteLimit should have comment" | \
grep -v "error var Done should have name of the form ErrFoo" | \
grep -v "exported method APIKey.RoundTrip should have comment or be unexported" | \
grep -v "exported method MarshalStyle.JSONReader should have comment or be unexported" | \
grep -v "UnmarshalJSON should have comment or be unexported" | \
grep -v "MarshalJSON should have comment or be unexported" | \
grep -vE "\.pb\.go:" || true) | tee /dev/stderr | (! read)
1 change: 1 addition & 0 deletions internal/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (r *PoolResolver) Next() ([]*naming.Update, error) {
return <-r.ch, nil
}

// Close releases resources associated with the pool and causes Next to unblock.
func (r *PoolResolver) Close() {
close(r.ch)
}
1 change: 1 addition & 0 deletions option/credentials_go19.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (w *withCreds) Apply(o *internal.DialSettings) {
o.Credentials = (*google.Credentials)(w)
}

// WithCredentials returns a ClientOption that authenticates API calls.
func WithCredentials(creds *google.Credentials) ClientOption {
return (*withCreds)(creds)
}
2 changes: 1 addition & 1 deletion transport/bytestream/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *Client) NewReader(ctx context.Context, resourceName string) (*Reader, e
return c.NewReaderAt(ctx, resourceName, 0)
}

// NewReader creates a new Reader to read a resource from the given offset.
// NewReaderAt creates a new Reader to read a resource from the given offset.
func (c *Client) NewReaderAt(ctx context.Context, resourceName string, offset int64) (*Reader, error) {
// readClient is set up for Read(). ReadAt() will copy needed fields into its reentrantReader.
readClient, err := c.client.Read(ctx, &pb.ReadRequest{
Expand Down
4 changes: 2 additions & 2 deletions transport/bytestream/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ func (w *UnsendableWriteClient) Trailer() metadata.MD {
log.Fatalf("UnsendableWriteClient.Trailer() should never be called")
return metadata.MD{}
}
func (fake *UnsendableWriteClient) SendMsg(m interface{}) error {
func (w *UnsendableWriteClient) SendMsg(m interface{}) error {
log.Fatalf("UnsendableWriteClient.SendMsg() should never be called")
return nil
}
func (fake *UnsendableWriteClient) RecvMsg(m interface{}) error {
func (w *UnsendableWriteClient) RecvMsg(m interface{}) error {
log.Fatalf("UnsendableWriteClient.RecvMsg() should never be called")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion transport/grpc/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package transport/grpc supports network connections to GRPC servers.
// Package grpc supports network connections to GRPC servers.
// This package is not intended for use by end developers. Use the
// google.golang.org/api/option package to configure API clients.
package grpc
Expand Down
2 changes: 1 addition & 1 deletion transport/http/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package transport/http supports network connections to HTTP servers.
// Package http supports network connections to HTTP servers.
// This package is not intended for use by end developers. Use the
// google.golang.org/api/option package to configure API clients.
package http
Expand Down

0 comments on commit 09030fc

Please sign in to comment.