Documentation ¶
Overview ¶
Package gcpcloud contains Wire providers for GCP services.
Example ¶
This is an example of how to bootstrap an HTTP server running on Google Cloud Platform (GCP). The code in this function would be placed in main().
package main import ( "context" "fmt" "log" "net/http" "github.com/google/wire" "github.com/kainoaseto/go-cloud/gcp/gcpcloud" "github.com/kainoaseto/go-cloud/server" "github.com/kainoaseto/go-cloud/server/health" "go.opencensus.io/trace" ) // This is an example of how to bootstrap an HTTP server running on // Google Cloud Platform (GCP). The code in this function would be // placed in main(). func main() { // Connect and authenticate to GCP. srv, cleanup, err := setup(context.Background()) if err != nil { log.Fatal(err) } defer cleanup() // Set up the HTTP routes. http.HandleFunc("/", greet) // Run the server. This behaves much like http.ListenAndServe, // including that passing a nil handler will use http.DefaultServeMux. log.Fatal(srv.ListenAndServe(":8080")) } // setup is a Wire injector function that creates an HTTP server // configured to send diagnostics to Stackdriver. The second return // value is a clean-up function that can be called to shut down any // resources created by setup. // // The body of this function will be filled in by running Wire. While // the name of the function does not matter, the signature signals to // Wire what provider functions to call. See // https://github.com/google/wire/blob/master/docs/guide.md#injectors // for more details. func setup(ctx context.Context) (*server.Server, func(), error) { wire.Build( // The GCP set includes all the default wiring for GCP, including // for *server.Server. gcpcloud.GCP, // Providing nil instructs the server to use the default sampling policy. wire.Value(trace.Sampler(nil)), // Health checks can be added to delay your server reporting healthy // to the load balancer before critical dependencies are available. wire.Value([]health.Checker{}), ) return nil, nil, nil } // greet is an ordinary http.HandleFunc. func greet(w http.ResponseWriter, req *http.Request) { fmt.Fprintln(w, "Hello, World!") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var GCP = wire.NewSet(Services, gcp.DefaultIdentity)
GCP is a Wire provider set that includes all Google Cloud Platform services in this repository and authenticates using Application Default Credentials.
View Source
var Services = wire.NewSet( gcp.DefaultTransport, gcp.NewHTTPClient, gcpruntimeconfig.Set, gcpkms.Set, gcppubsub.Set, gcsblob.Set, cloudsql.CertSourceSet, gcpfirestore.Set, sdserver.Set, )
Services is a Wire provider set that includes the default wiring for all Google Cloud Platform services in this repository, but does not include credentials. Individual services may require additional configuration.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.