github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/devserver/util.go (about) 1 // Copyright 2018 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package devserver 6 7 import ( 8 "errors" 9 "net/http" 10 "net/url" 11 "strings" 12 ) 13 14 // defaultHTTPClient is a HTTP client used by default by devserver clients. 15 // It is different from net/http's default client since we want more concurrent 16 // connections for parallel downloads. 17 var defaultHTTPClient = &http.Client{ 18 Transport: &http.Transport{ 19 MaxIdleConnsPerHost: 10, 20 Proxy: http.ProxyFromEnvironment, 21 }, 22 } 23 24 // ParseGSURL parses a Google Cloud Storage URL. It is parsed as: 25 // 26 // gs://<bucket>/<path> 27 // 28 // Note that path is not prefixed with a slash, which is suitable for use with 29 // GCS APIs. 30 func ParseGSURL(gsURL string) (bucket, path string, err error) { 31 parsed, err := url.Parse(gsURL) 32 if err != nil { 33 return "", "", err 34 } 35 if parsed.Scheme != "gs" { 36 return "", "", errors.New("not a GS URL") 37 } 38 39 bucket = parsed.Host 40 path = strings.TrimPrefix(parsed.Path, "/") 41 return bucket, path, nil 42 }