Created
December 5, 2022 09:08
-
-
Save 2minchul/23ae3e0edc4c1e0012b86d6f966a1a29 to your computer and use it in GitHub Desktop.
Revisions
-
2minchul created this gist
Dec 5, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ package main import ( "context" "crypto/tls" "io" "net/http" "net/url" "cloud.google.com/go/storage" "golang.org/x/oauth2" "golang.org/x/oauth2/google" "google.golang.org/api/option" ) func main() { u, _ := url.Parse("http://127.0.0.1:8888") ctx := context.Background() cred, err := google.FindDefaultCredentials(ctx) if err != nil { panic(err) } client := http.Client{ Transport: &oauth2.Transport{ Base: &http.Transport{ Proxy: http.ProxyURL(u), TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, Source: cred.TokenSource, }, } c, err := storage.NewClient(ctx, option.WithHTTPClient(&client)) r, err := c.Bucket("bucket").Object("object").NewReader(ctx) if err != nil { panic(err) } defer r.Close() b, err := io.ReadAll(r) if err != nil { panic(err) } println("read", len(b), "bytes") }