// Package drive provides a thin wrapper around the Google Drive v3 API, // used only to read modifiedTime for cache invalidation. package drive import ( "context" "net/http" "time" "google.golang.org/api/drive/v3" "google.golang.org/api/option" ) // Client wraps the Drive v3 API, scoped to read-only modifiedTime checks. type Client struct { svc *drive.Service } // New builds a Client using a service-account credentials file. // timeout applies to each Drive API call. func New(ctx context.Context, credentialsPath string, timeout time.Duration) (*Client, error) { hc := &http.Client{Timeout: timeout} svc, err := drive.NewService(ctx, option.WithCredentialsFile(credentialsPath), //nolint:staticcheck option.WithScopes(drive.DriveReadonlyScope), option.WithHTTPClient(hc), ) if err != nil { return nil, err } return &Client{svc: svc}, nil } // ModifiedTime returns the RFC3339 modifiedTime for the given Drive file ID. // Returns ("", err) if the Drive API call fails. func (c *Client) ModifiedTime(ctx context.Context, fileID string) (string, error) { meta, err := c.svc.Files.Get(fileID). Fields("modifiedTime"). SupportsAllDrives(true). Context(ctx). Do() if err != nil { return "", err } return meta.ModifiedTime, nil }