本文整理汇总了Golang中golang.org/x/oauth2/google.DefaultClient函数的典型用法代码示例。如果您正苦于以下问题:Golang DefaultClient函数的具体用法?Golang DefaultClient怎么用?Golang DefaultClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DefaultClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: newComputeUtil
// NewComputeUtil creates and initializes a ComputeUtil.
func newComputeUtil(driver *Driver) (*ComputeUtil, error) {
client, err := google.DefaultClient(oauth2.NoContext, raw.ComputeScope)
if err != nil {
return nil, err
}
service, err := raw.New(client)
if err != nil {
return nil, err
}
return &ComputeUtil{
zone: driver.Zone,
instanceName: driver.MachineName,
userName: driver.SSHUser,
project: driver.Project,
diskTypeURL: driver.DiskType,
address: driver.Address,
network: driver.Network,
preemptible: driver.Preemptible,
useInternalIP: driver.UseInternalIP,
useInternalIPOnly: driver.UseInternalIPOnly,
service: service,
zoneURL: apiURL + driver.Project + "/zones/" + driver.Zone,
globalURL: apiURL + driver.Project + "/global",
SwarmMaster: driver.SwarmMaster,
SwarmHost: driver.SwarmHost,
}, nil
}
开发者ID:bgokden,项目名称:machine,代码行数:30,代码来源:compute_util.go
示例2: pubsubContext
func pubsubContext(ctx context.Context, projectID string) (context.Context, error) {
httpClient, err := google.DefaultClient(ctx, pubsub.ScopePubSub)
if err != nil {
return nil, err
}
return cloud.WithContext(ctx, projectID, httpClient), nil
}
开发者ID:wuman,项目名称:golang-samples,代码行数:7,代码来源:pubsub.go
示例3: GetService
func GetService() (*deploymentmanager.Service, error) {
client, err := google.DefaultClient(oauth2.NoContext, "https://www.googleapis.com/auth/cloud-platform")
if err != nil {
return &deploymentmanager.Service{}, err
}
return deploymentmanager.New(client)
}
开发者ID:evandbrown,项目名称:dm,代码行数:7,代码来源:deployment.go
示例4: GetStorageService
func GetStorageService(ctx context.Context) (*storage.Service, error) {
client, err := google.DefaultClient(ctx, storage.DevstorageFullControlScope)
if err != nil {
return nil, err
}
return storage.New(client)
}
开发者ID:xanxys,项目名称:bonsai,代码行数:7,代码来源:main.go
示例5: handler
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
search, allele, err := requestToSearch(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
client, err := google.DefaultClient(c, genomics.GenomicsReadonlyScope)
if err != nil {
http.Error(w, "Invalid server configuration", http.StatusInternalServerError)
}
genomicsService, err := genomics.New(client)
if err != nil {
http.Error(w, "Invalid server configuration", http.StatusInternalServerError)
}
variantsService := genomics.NewVariantsService(genomicsService)
type beaconResponse struct {
XMLName struct{} `xml:"BEACONResponse"`
Exists bool `xml:"exists"`
}
var resp beaconResponse
for {
searchResponse, err := variantsService.Search(search).Do()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for _, variant := range searchResponse.Variants {
if search.Start != variant.Start {
continue
}
if allele == variant.ReferenceBases {
resp.Exists = true
} else {
for _, base := range variant.AlternateBases {
if base == allele {
resp.Exists = true
break
}
}
}
}
if resp.Exists || searchResponse.NextPageToken == "" {
break
}
search.PageToken = searchResponse.NextPageToken
}
w.Header().Set("Content-Type", "application/xml")
enc := xml.NewEncoder(w)
enc.Indent("", " ")
if err = enc.Encode(resp); err != nil {
http.Error(w, "Failed writing response", http.StatusInternalServerError)
}
}
开发者ID:googlegenomics,项目名称:beacon-go,代码行数:60,代码来源:beacon.go
示例6: ListBuckets
// ListBuckets returns a slice of all the buckets in the given projectId.
// [START ListBuckets]
func ListBuckets(projectId string) ([]*storage.Bucket, error) {
// Create the client that uses Application Default Credentials
client, err := google.DefaultClient(
oauth2.NoContext,
"https://www.googleapis.com/auth/devstorage.read_only")
if err != nil {
return nil, err
}
// Create the Google Cloud Storage service
service, err := storage.New(client)
if err != nil {
return nil, err
}
// Create the request to list buckets for the project id
request := service.Buckets.List(projectId)
// Execute the request
buckets, err := request.Do()
if err != nil {
return nil, err
}
return buckets.Items, nil
}
开发者ID:dwightjl,项目名称:go-docs-samples,代码行数:28,代码来源:listbuckets.go
示例7: datasets
// datasets returns a list with the IDs of all the Big Query datasets visible
// with the given context.
func datasets(ctx context.Context) ([]string, error) {
// Create a new authenticated HTTP client over urlfetch.
hc, err := google.DefaultClient(ctx, bigquery.BigqueryScope)
if err != nil {
return nil, fmt.Errorf("could not create http client: %v", err)
}
// Create the BigQuery service.
bq, err := bigquery.New(hc)
if err != nil {
return nil, fmt.Errorf("could not create service: %v", err)
}
// Get the current application ID, which is the same as the project ID.
projectID := appengine.AppID(ctx)
// Return a list of IDs.
var ids []string
datasets, err := bq.Datasets.List(projectID).Do()
if err != nil {
return nil, fmt.Errorf("could not list datasets for %q: %v", projectID, err)
}
for _, d := range datasets.Datasets {
ids = append(ids, d.Id)
}
return ids, nil
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:29,代码来源:app.go
示例8: handleStoragePut
func handleStoragePut(c context.Context, w http.ResponseWriter, r *http.Request) {
bucket := r.URL.Query().Get("bucket")
name := r.URL.Query().Get("name")
value := r.URL.Query().Get("value")
if bucket == "" || name == "" || value == "" {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Missing bucket, name, or value query parameter."))
return
}
client, err := google.DefaultClient(c, storage.DevstorageReadWriteScope)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Failed to get default google client. " + err.Error()))
return
}
service, err := storage.New(client)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Failed to get storage service. " + err.Error()))
return
}
obj, err := service.Objects.Insert(bucket, &storage.Object{Name: name}).Media(strings.NewReader(value)).Do()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Failed to insert object. " + err.Error()))
return
}
w.Write([]byte(fmt.Sprintf("put succeeded: %v", obj)))
}
开发者ID:drichardson,项目名称:go-appengine-vm-example,代码行数:29,代码来源:app.go
示例9: Publish
func (f *Fetcher) Publish(request *FetchRequest, entries []*FetchResponse) (err error) {
client, err := google.DefaultClient(request.Context, pubsub.CloudPlatformScope)
if err != nil {
return
}
service, err := pubsub.New(client)
if err != nil {
return
}
messages := make([]*pubsub.PubsubMessage, len(entries))
for i := range entries {
messages[i] = &pubsub.PubsubMessage{
Data: base64.StdEncoding.EncodeToString(entries[i].Content),
}
}
pr := pubsub.PublishRequest{
Messages: messages,
}
var topic string
if request.Topic != "" {
topic = request.Topic
} else {
topic = f.Topic
}
if topic == "" {
return fmt.Errorf("fetcher: topic is empty")
}
full := fmt.Sprintf("projects/%s/topics/%s", request.AppID(), topic)
_, err = service.Projects.Topics.Publish(full, &pr).Do()
if err != nil {
return
}
return
}
开发者ID:pombredanne,项目名称:appengine-toolkit,代码行数:35,代码来源:fetcher.go
示例10: NewProtoClient
// NewProtoClient returns a ProtoClient for communicating with a Google cloud service,
// configured with the given ClientOptions.
func NewProtoClient(ctx context.Context, opt ...cloud.ClientOption) (*ProtoClient, error) {
var o opts.DialOpt
for _, opt := range opt {
opt.Resolve(&o)
}
if o.GRPCClient != nil {
return nil, errors.New("unsupported GRPC base transport specified")
}
var client *http.Client
switch {
case o.HTTPClient != nil:
if o.TokenSource != nil {
return nil, errors.New("at most one of WithTokenSource or WithBaseHTTP may be provided")
}
client = o.HTTPClient
case o.TokenSource != nil:
client = oauth2.NewClient(ctx, o.TokenSource)
default:
var err error
client, err = google.DefaultClient(ctx, o.Scopes...)
if err != nil {
return nil, err
}
}
return &ProtoClient{
client: client,
endpoint: o.Endpoint,
userAgent: o.UserAgent,
}, nil
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:33,代码来源:dial.go
示例11: init
func init() {
if !metadata.OnGCE() {
return
}
hc, err := google.DefaultClient(oauth2.NoContext)
if err != nil {
registerBrokenFS(fmt.Errorf("could not get http client for context: %v", err))
return
}
projID, err := metadata.ProjectID()
if projID == "" || err != nil {
registerBrokenFS(fmt.Errorf("could not get GCE project ID: %v", err))
return
}
ctx := cloud.NewContext(projID, hc)
sc, err := storage.NewClient(ctx)
if err != nil {
registerBrokenFS(fmt.Errorf("could not get cloud storage client: %v", err))
return
}
wkfs.RegisterFS("/gcs/", &gcsFS{
ctx: ctx,
sc: sc,
})
}
开发者ID:cgag,项目名称:coreos-baremetal,代码行数:25,代码来源:gcs.go
示例12: authenticatedClient
// If we're not running on GCE (e.g. dev mode on localhost) and have
// no other way to get the info, the error value is is errNoRefresh.
func (h *DeployHandler) authenticatedClient() (project string, hc *http.Client, err error) {
project = os.Getenv("CAMLI_GCE_PROJECT")
accountFile := os.Getenv("CAMLI_GCE_SERVICE_ACCOUNT")
if project != "" && accountFile != "" {
data, errr := ioutil.ReadFile(accountFile)
err = errr
if err != nil {
return
}
jwtConf, errr := google.JWTConfigFromJSON(data, "https://www.googleapis.com/auth/compute.readonly")
err = errr
if err != nil {
return
}
hc = jwtConf.Client(context.Background())
return
}
if !metadata.OnGCE() {
err = errNoRefresh
return
}
project, _ = metadata.ProjectID()
hc, err = google.DefaultClient(oauth2.NoContext)
return project, hc, err
}
开发者ID:preillyme,项目名称:camlistore,代码行数:27,代码来源:handler.go
示例13: getComputeClient
func getComputeClient() (*compute.Service, error) {
const retries = 10
const backoff = time.Second * 6
// Setup the gce client for provisioning instances
// Getting credentials on gce jenkins is flaky, so try a couple times
var err error
var cs *compute.Service
for i := 0; i < retries; i++ {
if i > 0 {
time.Sleep(backoff)
}
var client *http.Client
client, err = google.DefaultClient(oauth2.NoContext, compute.ComputeScope)
if err != nil {
continue
}
cs, err = compute.New(client)
if err != nil {
continue
}
return cs, nil
}
return nil, err
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:27,代码来源:run_remote.go
示例14: handleStorageGet
func handleStorageGet(c context.Context, w http.ResponseWriter, r *http.Request) {
bucket := r.URL.Query().Get("bucket")
name := r.URL.Query().Get("name")
if bucket == "" || name == "" {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Missing bucket or name query parameter."))
return
}
client, err := google.DefaultClient(c, storage.DevstorageReadOnlyScope)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Failed to get default google client. " + err.Error()))
return
}
service, err := storage.New(client)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Failed to get storage service. " + err.Error()))
return
}
res, err := service.Objects.Get(bucket, name).Download()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("Failed to get object. " + err.Error()))
return
}
w.Header().Set("Content-Type", res.Header.Get("Content-Type"))
_, err = io.Copy(w, res.Body)
if err != nil {
// to late to change status code now
clog.Errorf(c, "io.Copy failed to copy storage get to response. %v", err)
}
}
开发者ID:drichardson,项目名称:go-appengine-vm-example,代码行数:33,代码来源:app.go
示例15: init
func init() {
var err error
cloudClient, err = google.DefaultClient(context.Background())
if err != nil {
panic(err)
}
}
开发者ID:flowlo,项目名称:coduno-api,代码行数:7,代码来源:cloud.go
示例16: newServiceAccountClient
// newServiceAccountClient returns a service account authenticated http.Client.
func newServiceAccountClient(c context.Context) (*http.Client, error) {
client, err := google.DefaultClient(c, BigqueryScope)
if err != nil {
return nil, err
}
return client, nil
}
开发者ID:ronoaldo,项目名称:aetools,代码行数:8,代码来源:bigquery.go
示例17: init
func init() {
gcloudProject = os.Getenv("GCE_PROJECT")
gcloudDomain = os.Getenv("GCE_DOMAIN")
_, err := google.DefaultClient(context.Background(), dns.NdevClouddnsReadwriteScope)
if err == nil && len(gcloudProject) > 0 && len(gcloudDomain) > 0 {
gcloudLiveTest = true
}
}
开发者ID:aebruno,项目名称:lego,代码行数:8,代码来源:googlecloud_test.go
示例18: NewPubsubService
func NewPubsubService(c context.Context) (s *pubsub.Service, err error) {
client, err := google.DefaultClient(c, pubsub.CloudPlatformScope)
if err != nil {
return
}
s, err = pubsub.New(client)
return
}
开发者ID:pombredanne,项目名称:appengine-toolkit,代码行数:8,代码来源:pubsub.go
示例19: ExampleDefaultClient
func ExampleDefaultClient() {
client, err := google.DefaultClient(oauth2.NoContext,
"https://www.googleapis.com/auth/devstorage.full_control")
if err != nil {
log.Fatal(err)
}
client.Get("...")
}
开发者ID:Crosse,项目名称:oauth2,代码行数:8,代码来源:example_test.go
示例20: InitDefault
// InitDefault attempts to initialize the Dial function using application
// default credentials.
func InitDefault(ctx context.Context) error {
cl, err := google.DefaultClient(ctx, "https://www.googleapis.com/auth/sqlservice.admin")
if err != nil {
return err
}
Init(cl, nil, nil)
return nil
}
开发者ID:GoogleCloudPlatform,项目名称:cloudsql-proxy,代码行数:10,代码来源:dial.go
注:本文中的golang.org/x/oauth2/google.DefaultClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论