kandi background
Explore Kits

google-cloud-go | Google Cloud Client Libraries for Go | GCP library

 by   googleapis Go Version: compute/v1.6.1 License: Apache-2.0

 by   googleapis Go Version: compute/v1.6.1 License: Apache-2.0

Download this library from

kandi X-RAY | google-cloud-go Summary

google-cloud-go is a Go library typically used in Cloud, GCP applications. google-cloud-go has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
Google Cloud Client Libraries for Go.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • google-cloud-go has a medium active ecosystem.
  • It has 2827 star(s) with 1016 fork(s). There are 251 watchers for this library.
  • There were 10 major release(s) in the last 12 months.
  • There are 177 open issues and 2990 have been closed. On average issues are closed in 47 days. There are 46 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of google-cloud-go is compute/v1.6.1
google-cloud-go Support
Best in #GCP
Average in #GCP
google-cloud-go Support
Best in #GCP
Average in #GCP

quality kandi Quality

  • google-cloud-go has no bugs reported.
google-cloud-go Quality
Best in #GCP
Average in #GCP
google-cloud-go Quality
Best in #GCP
Average in #GCP

securitySecurity

  • google-cloud-go has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
google-cloud-go Security
Best in #GCP
Average in #GCP
google-cloud-go Security
Best in #GCP
Average in #GCP

license License

  • google-cloud-go is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
google-cloud-go License
Best in #GCP
Average in #GCP
google-cloud-go License
Best in #GCP
Average in #GCP

buildReuse

  • google-cloud-go releases are available to install and integrate.
  • Installation instructions are not available. Examples and code snippets are available.
google-cloud-go Reuse
Best in #GCP
Average in #GCP
google-cloud-go Reuse
Best in #GCP
Average in #GCP
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

google-cloud-go Key Features

Google Cloud Client Libraries for Go.

Google Cloud Client Libraries for Go

copy iconCopydownload iconDownload
import "cloud.google.com/go"

Authorization

copy iconCopydownload iconDownload
client, err := storage.NewClient(ctx)

How to use gcp signed url with custom headers in Go

copy iconCopydownload iconDownload
import (
    "context"
    "fmt"
    "time"

    "cloud.google.com/go/storage"
    "github.com/dkbyo/go-stringhttpheader"
)

type Headers struct {
    GoogleMetaReference string `header:"x-goog-meta-reference"`
}

func GenerateSignedURL(bucket string, key string, expiration time.Time,
) (string, error) {
    ctx := context.Background()
    gcsClient, err := storage.NewClient(ctx)
    if err != nil {
        return "", fmt.Errorf("storage.NewClient: %v", err)
    }
    defer gcsClient.Close()
    headers := Headers{
        GoogleMetaReference: "xxx",
    }
    fmt.Print(stringhttpheader.Encode(headers))
    stringheaders, _ := stringhttpheader.Encode(headers)
    //storage.SignedURL()
    opts := &storage.SignedURLOptions{
        Scheme:      storage.SigningSchemeV4,
        Method:      "PUT",
        ContentType: "text/csv",
        Headers:     stringheaders,
        Expires:     expiration,
    }

    url, err := gcsClient.Bucket(bucket).SignedURL(key, opts)
    if err != nil {
        log.WithContext(ctx).Warn("Failed to generate a GCS signed URL")
        return "", err
    }

    return url, nil
}

How to convert string value to custom type in function

copy iconCopydownload iconDownload
return policy.HasRole(serviceAccount, iam.RoleName(role))
func checkRole(key, serviceAccount, role iam.RoleName) bool {
...
   return policy.HasRole(serviceAccount, role)
}
return policy.HasRole(serviceAccount, iam.RoleName(role))
func checkRole(key, serviceAccount, role iam.RoleName) bool {
...
   return policy.HasRole(serviceAccount, role)
}

Community Discussions

Trending Discussions on google-cloud-go
  • How to use gcp signed url with custom headers in Go
  • PageInfo in Firestore not usable
  • How to convert string value to custom type in function
  • How does the exponential backoff configured in Google Pub/Sub's RetryPolicy work?
Trending Discussions on google-cloud-go

QUESTION

How to use gcp signed url with custom headers in Go

Asked 2022-Feb-15 at 16:45

I am trying to set the x-goog-meta-reference in the header section dynamically so i want to pass an argument called reference in the function signature and assign that to the x-goog-meta-reference in the header. See x-goog-meta-reference in my code sample below. I followed this link regarding canonical requests.

My sample code is from here but it is the edited version of my prod code.

func GenerateSignedURL(ctx context.Context, bucket string, key string, expiration time.Time,
) (string, error) {
    gcsClient, err := storage.NewClient(ctx)
    if err != nil {
        return "", fmt.Errorf("storage.NewClient: %v", err)
    }
    defer gcsClient.Close()

    storage.SignedURL()
    opts := &storage.SignedURLOptions{
        Scheme:      storage.SigningSchemeV4,
        Method:      "PUT",
        ContentType: "text/csv",
        Headers:     []string{
            "x-goog-meta-reference: xxx", // << I want xxx value to be whatever I pass to this function as an arg
        },
        Expires:     expiration,
    }

    url, err := gcsClient.Bucket(bucket).SignedURL(key, opts)
    if err != nil {
        log.WithContext(ctx).Warn("Failed to generate a GCS signed URL")
        return "", err
    }

    return url, nil
}

I tried looking at some examples but all of them are s3 and I did not run into any gcp sample code. However, I did find this issue but i was not able to figure it out myself.

ANSWER

Answered 2022-Feb-15 at 16:45

As @dazwilkin mentions, fmt.Sprintf is good enough for this case, but you can also use this library that I ported from mozilla

import (
    "context"
    "fmt"
    "time"

    "cloud.google.com/go/storage"
    "github.com/dkbyo/go-stringhttpheader"
)

type Headers struct {
    GoogleMetaReference string `header:"x-goog-meta-reference"`
}

func GenerateSignedURL(bucket string, key string, expiration time.Time,
) (string, error) {
    ctx := context.Background()
    gcsClient, err := storage.NewClient(ctx)
    if err != nil {
        return "", fmt.Errorf("storage.NewClient: %v", err)
    }
    defer gcsClient.Close()
    headers := Headers{
        GoogleMetaReference: "xxx",
    }
    fmt.Print(stringhttpheader.Encode(headers))
    stringheaders, _ := stringhttpheader.Encode(headers)
    //storage.SignedURL()
    opts := &storage.SignedURLOptions{
        Scheme:      storage.SigningSchemeV4,
        Method:      "PUT",
        ContentType: "text/csv",
        Headers:     stringheaders,
        Expires:     expiration,
    }

    url, err := gcsClient.Bucket(bucket).SignedURL(key, opts)
    if err != nil {
        log.WithContext(ctx).Warn("Failed to generate a GCS signed URL")
        return "", err
    }

    return url, nil
}

Source https://stackoverflow.com/questions/71105918

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install google-cloud-go

You can download it from GitHub.

Support

For an updated list of all of our released APIs please see our reference docs.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Consider Popular GCP Libraries
Try Top Libraries by googleapis
Compare GCP Libraries with Highest Support
Compare GCP Libraries with Highest Quality
Compare GCP Libraries with Highest Security
Compare GCP Libraries with Permissive License
Compare GCP Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.