all: fix or disable staticcheck deprecations

(Originally from https://github.com/perkeep/perkeep/pull/1648)
This commit is contained in:
Oleksandr Redko 2024-01-13 16:43:50 -08:00 committed by Brad Fitzpatrick
parent bc9fbcd89e
commit a911bc8060
11 changed files with 19 additions and 16 deletions

View File

@ -267,8 +267,8 @@ func (zh *zipHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
zh := zip.FileHeader{
Name: file.path,
Method: zip.Store,
Modified: fr.ModTime().UTC(),
}
zh.SetModTime(fr.ModTime())
f, err := zw.CreateHeader(&zh)
if err != nil {
log.Printf("Could not create %q in zip: %v", file.path, err)

View File

@ -32,6 +32,7 @@ import (
"golang.org/x/oauth2/google"
compute "google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"
"google.golang.org/api/option"
"perkeep.org/internal/osutil"
"perkeep.org/pkg/env"
@ -158,7 +159,7 @@ func gceInstance() (*gceInst, error) {
if err != nil {
return nil, fmt.Errorf("error getting a default http client: %v", err)
}
cs, err := compute.New(hc)
cs, err := compute.NewService(ctx, option.WithHTTPClient(hc))
if err != nil {
return nil, fmt.Errorf("error getting a compute service: %v", err)
}

View File

@ -363,7 +363,7 @@ func ProjectTokenSource(proj string, scopes ...string) (oauth2.TokenSource, erro
if err != nil {
return nil, fmt.Errorf("reading JSON config from %s: %v", fileName, err)
}
return conf.TokenSource(oauth2.NoContext), nil
return conf.TokenSource(context.TODO()), nil
}
var bucketProject = map[string]string{

View File

@ -924,7 +924,7 @@ func ProjectTokenSource(proj string, scopes ...string) (oauth2.TokenSource, erro
if err != nil {
return nil, fmt.Errorf("reading JSON config from %s: %v", fileName, err)
}
return conf.TokenSource(oauth2.NoContext), nil
return conf.TokenSource(context.TODO()), nil
}
var bucketProject = map[string]string{

View File

@ -94,7 +94,7 @@ func testServeBlobContents(t *testing.T, contents, wantType string) {
if rr.Code != 200 {
t.Errorf("Response code = %d; want 200", rr.Code)
}
if g, w := rr.HeaderMap.Get("Content-Type"), wantType; g != w {
if g, w := rr.Result().Header.Get("Content-Type"), wantType; g != w {
t.Errorf("Content-Type = %q; want %q", g, w)
}
if rr.Body.String() != contents {

View File

@ -28,6 +28,7 @@ import (
"golang.org/x/time/rate"
"google.golang.org/api/drive/v3"
"google.golang.org/api/googleapi"
"google.golang.org/api/option"
)
var scopeURLs = []string{drive.DriveReadonlyScope}
@ -50,7 +51,7 @@ const (
// The permission ID becomes the "userID" (AcctAttrUserID) value on the
// account's "importerAccount" permanode.
func getUser(ctx context.Context, client *http.Client) (*drive.User, error) {
srv, err := drive.New(client)
srv, err := drive.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, err
}
@ -75,8 +76,8 @@ type downloader struct {
//
// The client must be authenticated for drive.DrivePhotosReadonlyScope
// ("https://www.googleapis.com/auth/drive.photos.readonly")..
func newDownloader(client *http.Client) (*downloader, error) {
srv, err := drive.New(client)
func newDownloader(ctx context.Context, client *http.Client) (*downloader, error) {
srv, err := drive.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, err
}

View File

@ -309,7 +309,7 @@ func (imp) Run(rctx *importer.RunContext) error {
}
}
dl, err := newDownloader(ctxutil.Client(ctx))
dl, err := newDownloader(ctx, ctxutil.Client(ctx))
if err != nil {
return err
}

View File

@ -76,6 +76,6 @@ func TestImportRootPageHTML(t *testing.T) {
r := httptest.NewRequest("GET", "/importer/", nil)
h.serveImportersRoot(w, r)
if w.Code != 200 || !strings.Contains(w.Body.String(), "dummy1") {
t.Errorf("Got %d response with header %v, body %s", w.Code, w.HeaderMap, w.Body.String())
t.Errorf("Got %d response with header %v, body %s", w.Code, w.Result().Header, w.Body.String())
}
}

View File

@ -325,10 +325,9 @@ func (im *imp) LongPoll(rctx *importer.RunContext) error {
}
form := url.Values{"with": {"user"}}
req, _ := http.NewRequest("GET", "https://userstream.twitter.com/1.1/user.json", nil)
req, _ := http.NewRequestWithContext(rctx.Context(), "GET", "https://userstream.twitter.com/1.1/user.json", nil)
req.Header.Set("Authorization", oauthClient.AuthorizationHeader(accessCreds, "GET", req.URL, form))
req.URL.RawQuery = form.Encode()
req.Cancel = rctx.Context().Done()
log.Printf("twitter: beginning long poll, awaiting new tweets...")
res, err := http.DefaultClient.Do(req)

View File

@ -27,6 +27,7 @@ import (
"cloud.google.com/go/compute/metadata"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
sqladmin "google.golang.org/api/sqladmin/v1beta4"
)
@ -45,7 +46,8 @@ func maybeRemapCloudSQL(host string) (out string, err error) {
return "", fmt.Errorf("Failed to lookup GCE project ID: %v", err)
}
admin, _ := sqladmin.New(oauth2.NewClient(context.Background(), google.ComputeTokenSource("")))
ctx := context.TODO()
admin, _ := sqladmin.NewService(ctx, option.WithHTTPClient(oauth2.NewClient(ctx, google.ComputeTokenSource(""))))
listRes, err := admin.Instances.List(proj).Do()
if err != nil {
return "", fmt.Errorf("error enumerating Cloud SQL instances: %v", err)

View File

@ -76,7 +76,7 @@ func maybeSetupGoogleCloudLogging() io.Closer {
}
ctx := context.Background()
logc, err := logging.NewClient(ctx,
flagGCEProjectID, option.WithServiceAccountFile(flagGCEJWTFile))
flagGCEProjectID, option.WithCredentialsFile(flagGCEJWTFile))
if err != nil {
exitf("Error creating GCL client: %v", err)
}