golang-samples | Sample apps and code written for Google Cloud in the Go programming language | GCP library

 by   GoogleCloudPlatform Go Version: Current License: Apache-2.0

kandi X-RAY | golang-samples Summary

golang-samples is a Go library typically used in Cloud, GCP applications. golang-samples has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
Sample apps and code written for Google Cloud in the Go programming language.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        golang-samples has a medium active ecosystem.
                        summary
                        It has 3790 star(s) with 1633 fork(s). There are 181 watchers for this library.
                        summary
                        It had no major release in the last 6 months.
                        summary
                        There are 34 open issues and 780 have been closed. On average issues are closed in 65 days. There are 15 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of golang-samples is current.
                        golang-samples Support
                          Best in #GCP
                            Average in #GCP
                            golang-samples Support
                              Best in #GCP
                                Average in #GCP

                                  kandi-Quality Quality

                                    summary
                                    golang-samples has 0 bugs and 0 code smells.
                                    golang-samples Quality
                                      Best in #GCP
                                        Average in #GCP
                                        golang-samples Quality
                                          Best in #GCP
                                            Average in #GCP

                                              kandi-Security Security

                                                summary
                                                golang-samples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                golang-samples code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                golang-samples Security
                                                  Best in #GCP
                                                    Average in #GCP
                                                    golang-samples Security
                                                      Best in #GCP
                                                        Average in #GCP

                                                          kandi-License License

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

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        golang-samples releases are not available. You will need to build from source code and install.
                                                                        summary
                                                                        It has 81351 lines of code, 2937 functions and 1507 files.
                                                                        summary
                                                                        It has high code complexity. Code complexity directly impacts maintainability of the code.
                                                                        golang-samples Reuse
                                                                          Best in #GCP
                                                                            Average in #GCP
                                                                            golang-samples 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.

                                                                                  golang-samples Key Features

                                                                                  Sample apps and code written for Google Cloud in the Go programming language.

                                                                                  golang-samples Examples and Code Snippets

                                                                                  No Code Snippets are available at this moment for golang-samples.
                                                                                  Community Discussions

                                                                                  Trending Discussions on golang-samples

                                                                                  Google Cloud Vision API "cannot use connPool"
                                                                                  chevron right
                                                                                  Google Cloud: Build always fails, MANIFEST_UNKNOWN error
                                                                                  chevron right
                                                                                  Standard Go Project Layout with Docker causes build context problem
                                                                                  chevron right
                                                                                  GCP: Bucket Creation in Go
                                                                                  chevron right
                                                                                  Google Cloud CDN signed cookies with bucket as backend
                                                                                  chevron right

                                                                                  QUESTION

                                                                                  Google Cloud Vision API "cannot use connPool"
                                                                                  Asked 2020-Nov-03 at 15:20

                                                                                  I'm learning Google Cloud Vision API, but facing some issues. I have completely repeated all the steps from the 'Getting Started' Guide.

                                                                                  1. download/install google cloud SDK
                                                                                  2. activate login credentials using gcloud
                                                                                  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS
                                                                                  4. Install the client library

                                                                                  After that I ran this code and got this error when compiling:

                                                                                  ..\cloud.google.com\go\longrunning\autogen\operations_client.go:166:54: cannot use connPool (type "google.golang.org/api/internal".ConnPool) as type *"google.golang.org/grpc".ClientConn in argument to longrunning.NewOperationsClient
                                                                                  
                                                                                  Compilation finished with exit code 2
                                                                                  

                                                                                  I repeated all the steps over and over and still get this error. Windows 10 is installed on my pc with the latest software updates. I have NOT changed the code from the tutorial.

                                                                                  Can anyone please tell me why I'm getting this error?

                                                                                  ANSWER

                                                                                  Answered 2020-Nov-03 at 15:20

                                                                                  Issue has been fixed.

                                                                                  I just needed to remove conflicting custom imports and re-install Google Vision library.

                                                                                  Well that was a dumb mistake, sorry to bother you.

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

                                                                                  QUESTION

                                                                                  Google Cloud: Build always fails, MANIFEST_UNKNOWN error
                                                                                  Asked 2020-Oct-29 at 10:38

                                                                                  I'm trying to deploy an app engine application, but no matter which code I'm trying to deploy, even if it's taken from their samples at:

                                                                                  https://github.com/GoogleCloudPlatform/golang-samples

                                                                                  I get the same error:

                                                                                  Step #1: error building image: getting stage builder for stage 0: MANIFEST_UNKNOWN: "Manifest with digest 'sha256:249859465bcde1cb15128ff0d9eb2bb54de67f72a834a7576e6649cfe0a27698' has media type 'application/vnd.docker.distribution.manifest.list.v2+json', but client accepts 'application/vnd.docker.distribution.manifest.v2+json'."
                                                                                  

                                                                                  I'm not good at devops, so no idea howto work this around

                                                                                  ANSWER

                                                                                  Answered 2020-Oct-25 at 19:18

                                                                                  I encountered the same issue when deploying on AppEngine Flexible today. I don't think it's something you can do. I opened an issue on github hopefully the google cloud team will fix it fast.

                                                                                  For info, the issue the OP has is that when running gcloud app deploy app.yaml he expects the app do be deployed.

                                                                                  Cloud Build tries to fetch an image that has a media type it does not understand.

                                                                                  Got: application/vnd.docker.distribution.manifest.list.v2+json Expected: application/vnd.docker.distribution.manifest.v2+json

                                                                                  Step #0: gcr.io/gcp-runtimes/go1-builder@sha256:7b53332a8e6418ba9a3f123c29dd5fe075504d0f9c0b683edfc7e7b75cd27822
                                                                                  Finished Step #0
                                                                                  Starting Step #1
                                                                                  Step #1: Already have image (with digest): gcr.io/kaniko-project/executor@sha256:f87c11770a4d3ed33436508d206c584812cd656e6ed08eda1cff5c1ee44f5870
                                                                                  Step #1: INFO[0000] Downloading base image gcr.io/distroless/base@sha256:884ac2144c3ee154bd67271e99bc6ef00f430092750167729b0321ab55fde5ec 
                                                                                  Step #1: error building image: getting stage builder for stage 0: MANIFEST_UNKNOWN: "Manifest with digest 'sha256:884ac2144c3ee154bd67271e99bc6ef00f430092750167729b0321ab55fde5ec' has media type 'application/vnd.docker.distribution.manifest.list.v2+json', but client accepts 'application/vnd.docker.distribution.manifest.v2+json'."
                                                                                  

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

                                                                                  QUESTION

                                                                                  Standard Go Project Layout with Docker causes build context problem
                                                                                  Asked 2020-Sep-19 at 18:26

                                                                                  I'm following two guides which appear to conflict

                                                                                  1. Standard Go Project Layout
                                                                                  2. Google Cloud Endpoints Sample for Go using gRPC

                                                                                  Go's Standard Go Project Layout recommends a /build directory, the use of which is described as

                                                                                  Packaging and Continuous Integration.

                                                                                  Put your cloud (AMI), container (Docker), OS (deb, rpm, pkg) package configurations and scripts in the /build/package directory.

                                                                                  Following Google Cloud Endpoints Sample for Go using gRPC, I have a Dockerfile which copies application source code and installs any dependencies with go get.

                                                                                  # /build/Dockerfile
                                                                                  
                                                                                  FROM golang:alpine
                                                                                  
                                                                                  # Alpine Linux package management
                                                                                  RUN apk update
                                                                                  RUN apk add git
                                                                                  
                                                                                  COPY ../ /go/src/github.com/username/repository
                                                                                  
                                                                                  # Downloads the packages named by the import paths, along with their
                                                                                  # dependencies. It then installs the named packages, like 'go install'.
                                                                                  # ****Don't do this in production! Use vendoring instead.****
                                                                                  RUN go get -v github.com/username/repository/foo-module
                                                                                  
                                                                                  # Compiles and installs the packages named by the import paths.
                                                                                  RUN go install github.com/username/repository/foo-module
                                                                                  
                                                                                  ENTRYPOINT ["/go/bin/foo-module"]
                                                                                  

                                                                                  Following Standard Go Project Layout I place the aforementioned Dockerfile in /build.

                                                                                  Since the Dockerfile is now in the /build directory, I modified the COPY command to copy the parent directory to find the application source code (COPY ../ /go/src/github.com/username/repository).

                                                                                  The Docker build command is not run directly, rather the build is started with Google Cloud Build

                                                                                  cloud-build-local --config=build/cloudbuild.yaml .
                                                                                  

                                                                                  The cloudbuild.yaml file is really simple and just kicks off the Docker build. The --file flag points to build/Dockerfile since the Cloud Build command is started from the project root and not from /build)

                                                                                  # /build/cloudbuild.yaml
                                                                                  
                                                                                  steps:
                                                                                      - id: Build
                                                                                        name: "gcr.io/cloud-builders/docker"
                                                                                  
                                                                                        dir: ${_SOURCE}
                                                                                        args:
                                                                                          [
                                                                                              "build",
                                                                                              "--file build/Dockerfile",
                                                                                              ".",
                                                                                          ]
                                                                                  

                                                                                  As expected, this fails

                                                                                  COPY failed: Forbidden path outside the build context: ../ ()
                                                                                  

                                                                                  How to include files outside of Docker's build context? suggests using the --file flag, however, this assumes the build is started from the root context. When using Google's Cloud Build, the build is started from cloudbuild.yaml, which also located in /build.

                                                                                  I could just place the Docker file in the root of my go module, but I would like to follow best practices where possible and keep cloudbuild.yaml and Dockerfile in /build.

                                                                                  What is the correct way to achieve this while following the Standard Go Project Layout?

                                                                                  ANSWER

                                                                                  Answered 2020-Sep-19 at 18:26

                                                                                  That's a rather long question, so lets focus on the problem encountered:

                                                                                  COPY ../ /go/src/github.com/username/repository
                                                                                  

                                                                                  which resulted in

                                                                                  COPY failed: Forbidden path outside the build context: ../ ()
                                                                                  

                                                                                  You don't include files outside of the context, docker doesn't allow that. Instead you change your context to include the files you need to build your image, and make the paths in your COPY/ADD commands relative to that context. Make sure to reread that, these paths are not relative to the Dockerfile location.

                                                                                  So with a docker build, if you have build/Dockerfile, you would build from the parent directory with:

                                                                                  docker build -f build/Dockerfile .
                                                                                  

                                                                                  That trailing dot is the path to the build context which gets sent to the docker engine to perform the build. It doesn't access files directly on the client, which is why you can't include files from outside of the context (plus you don't want malicious Dockerfiles extracting data from the build server).

                                                                                  Then inside the Dockerfile you'd define the paths relative to that context:

                                                                                  COPY . /go/src/github.com/username/repository
                                                                                  

                                                                                  And if for some reason you cannot build from that parent directory because of the tooling, then make the context the parent folder with a relative path:

                                                                                  docker build -f Dockerfile ..
                                                                                  

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

                                                                                  QUESTION

                                                                                  GCP: Bucket Creation in Go
                                                                                  Asked 2020-Aug-15 at 11:28

                                                                                  I'm trying to create a bucket in GCP using Go, I tried this create method, that creates a bucket in Go. Here's the go playground of the same. When I try to run it, it just says timeout running go build and Go Build Failed. I know it's trying to download some packages, but not sure why it is getting timed out while downloading the package?. I'm new to Go and wanted to test out how bucket creation works in go. Am I missing something?.

                                                                                  ANSWER

                                                                                  Answered 2020-Aug-15 at 11:28

                                                                                  Log in:

                                                                                  gcloud auth application-default login
                                                                                  

                                                                                  Create this create-bucket.go file and replace the project ID with your project ID:

                                                                                  // Sample storage-quickstart creates a Google Cloud Storage bucket.
                                                                                  package main
                                                                                  
                                                                                  import (
                                                                                      "context"
                                                                                      "fmt"
                                                                                      "log"
                                                                                      "time"
                                                                                  
                                                                                      "cloud.google.com/go/storage"
                                                                                  )
                                                                                  
                                                                                  func main() {
                                                                                      ctx := context.Background()
                                                                                  
                                                                                      // Sets your Google Cloud Platform project ID.
                                                                                      projectID := ""
                                                                                  
                                                                                      // Creates a client.
                                                                                      client, err := storage.NewClient(ctx)
                                                                                      if err != nil {
                                                                                          log.Fatalf("Failed to create client: %v", err)
                                                                                      }
                                                                                  
                                                                                      // Sets the name for the new bucket.
                                                                                      bucketName := "go-new-bucket"
                                                                                  
                                                                                      // Creates a Bucket instance.
                                                                                      bucket := client.Bucket(bucketName)
                                                                                  
                                                                                      // Creates the new bucket.
                                                                                      ctx, cancel := context.WithTimeout(ctx, time.Second*10)
                                                                                      defer cancel()
                                                                                      if err := bucket.Create(ctx, projectID, nil); err != nil {
                                                                                          log.Fatalf("Failed to create bucket: %v", err)
                                                                                      }
                                                                                  
                                                                                      fmt.Printf("Bucket %v created.\n", bucketName)
                                                                                  }
                                                                                  

                                                                                  Run the go file that you created in the previous step:

                                                                                  go run create-bucket.go
                                                                                  

                                                                                  You'll find the go-new-bucket under the GCP storage menu:

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

                                                                                  QUESTION

                                                                                  Google Cloud CDN signed cookies with bucket as backend
                                                                                  Asked 2020-Apr-25 at 13:50

                                                                                  As an alternative to signed urls with a url prefix, I'm trying to get signed cookies working. Google Cloud CDN is setup with a backend bucket which is configured and working for standard signed urls.

                                                                                  Using these Go examples I've implemented a cookie signing function in nodejs(typescript) that when provied with the test sample data produces the expected outcome.

                                                                                  export function signCookie(urlPrefix: any, keyName: string, key: any, experation: Date): string {
                                                                                      // Base64url encode the url prefix
                                                                                      const urlPrefixEncoded = Buffer.from(urlPrefix)
                                                                                          .toString('base64')
                                                                                          .replace(/\+/g, '-')
                                                                                          .replace(/\//g, '_');
                                                                                  
                                                                                      // Input to be signed
                                                                                      const input = `URLPrefix=${urlPrefixEncoded}:Expires=${experation.getTime()}:KeyName=${keyName}`;
                                                                                  
                                                                                      // Create bytes from given key string.
                                                                                      const keyBytes = Buffer.from(key, 'base64');
                                                                                  
                                                                                      // Use key bytes and crypto.createHmac to produce a base64 encoded signature which is then escaped to be base64url encoded.
                                                                                      const signature = createHmac('sha1', keyBytes)
                                                                                          .update(input)
                                                                                          .digest('base64').replace(/\+/g, '-')
                                                                                          .replace(/\//g, '_');
                                                                                  
                                                                                      // Adding the signature on the end if the cookie value
                                                                                      const signedValue = `${input}:Signature=${signature}`;
                                                                                  
                                                                                      return signedValue;
                                                                                  }
                                                                                  

                                                                                  When I then use the same function to produce signed cookie values for my actual cdn instance I get the following (key name and url prefix not actual):

                                                                                  URLPrefix=aHR0cHM6L------------------HdhcmUuaW8v:Expires=1587585646437:KeyName=my-key-name:Signature=2mJbbtYVclycXBGIpKzsJWuLXEA=

                                                                                  Creating a cooking using firefox dev tools I get the following two results when the cookie is attached and when it is not:

                                                                                  It appears that the cookie "Cloud-CDN-Cookie" is just being passed through Cloud CDN and straight to the backend bucket where it's ignored and the standard response access denied response is given.

                                                                                  The cloud platform logs shows no cdn intervention.

                                                                                  With cookie attached No cookie attached

                                                                                  Is there something in either the signing implementation or creation and use of the cookie that I'm doing wrong?

                                                                                  ANSWER

                                                                                  Answered 2020-Apr-25 at 13:50

                                                                                  My Google project did not yet have the signed cookie feature enabled. Another user contacted support and once the issue was resolved for them it was resolved for me no change to code and it works.

                                                                                  This is my final nodejs(typescript) signed cookie implementation.

                                                                                  function signCookie(urlPrefix: any, keyName: string, key: any, experation: Date): string {
                                                                                      // Base64url encode the url prefix
                                                                                      const urlPrefixEncoded = Buffer.from(urlPrefix)
                                                                                          .toString('base64')
                                                                                          .replace(/\+/g, '-')
                                                                                          .replace(/\//g, '_');
                                                                                  
                                                                                      // Input to be signed
                                                                                      const input = `URLPrefix=${urlPrefixEncoded}:Expires=${experation.getTime()}:KeyName=${keyName}`;
                                                                                  
                                                                                      // Create bytes from given key string.
                                                                                      const keyBytes = Buffer.from(key, 'base64');
                                                                                  
                                                                                      // Use key bytes and crypto.createHmac to produce a base64 encoded signature which is then escaped to be base64url encoded.
                                                                                      const signature = createHmac('sha1', keyBytes)
                                                                                          .update(input)
                                                                                          .digest('base64').replace(/\+/g, '-')
                                                                                          .replace(/\//g, '_');
                                                                                  
                                                                                      // Adding the signature on the end if the cookie value
                                                                                      const signedValue = `${input}:Signature=${signature}`;
                                                                                  
                                                                                      return signedValue;
                                                                                  }
                                                                                  

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

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

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install golang-samples

                                                                                  You can download it from GitHub.

                                                                                  Support

                                                                                  Entirely new samples are not accepted. Bug fixes are welcome, either as pull requests or as GitHub issues. See CONTRIBUTING.md for details on how to contribute.
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit
                                                                                  CLONE
                                                                                • HTTPS

                                                                                  https://github.com/GoogleCloudPlatform/golang-samples.git

                                                                                • CLI

                                                                                  gh repo clone GoogleCloudPlatform/golang-samples

                                                                                • sshUrl

                                                                                  git@github.com:GoogleCloudPlatform/golang-samples.git

                                                                                • Share this Page

                                                                                  share link

                                                                                  Explore Related Topics

                                                                                  Consider Popular GCP Libraries

                                                                                  microservices-demo

                                                                                  by GoogleCloudPlatform

                                                                                  awesome-kubernetes

                                                                                  by ramitsurana

                                                                                  go-cloud

                                                                                  by google

                                                                                  infracost

                                                                                  by infracost

                                                                                  python-docs-samples

                                                                                  by GoogleCloudPlatform

                                                                                  Try Top Libraries by GoogleCloudPlatform

                                                                                  microservices-demo

                                                                                  by GoogleCloudPlatformPython

                                                                                  terraformer

                                                                                  by GoogleCloudPlatformGo

                                                                                  training-data-analyst

                                                                                  by GoogleCloudPlatformJupyter Notebook

                                                                                  python-docs-samples

                                                                                  by GoogleCloudPlatformJupyter Notebook

                                                                                  tensorflow-without-a-phd

                                                                                  by GoogleCloudPlatformJupyter Notebook

                                                                                  Compare GCP Libraries with Highest Support

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit