Beispiel #1
0
func Example_auth() {
	// Initialize an authorized transport with Google Developers Console
	// JSON key. Read the google package examples to learn more about
	// different authorization flows you can use.
	// http://godoc.org/github.com/golang/oauth2/google
	conf, err := google.NewServiceAccountJSONConfig(
		"/path/to/json/keyfile.json",
		storage.ScopeFullControl)
	if err != nil {
		log.Fatal(err)
	}

	ctx := cloud.NewContext("project-id", &http.Client{Transport: conf.NewTransport()})
	_ = ctx // Use the context (see other examples)
}
Beispiel #2
0
func main() {
	flag.Parse()
	runtime.GOMAXPROCS(runtime.NumCPU())

	ctx = cloud.NewContext(projectID, &http.Client{
		Transport: google.NewComputeEngineConfig("").NewTransport(),
	})

	config, err := google.NewServiceAccountJSONConfig(*account, "https://www.googleapis.com/auth/userinfo.email")
	if err != nil {
		log.Fatal(err)
	}
	client = &http.Client{Transport: config.NewTransport()}

	http.HandleFunc("/healthcheck", func(http.ResponseWriter, *http.Request) {})
	http.HandleFunc("/", notificationHandler)
	log.Println("server listening on", listenAddress)

	if err := http.ListenAndServe(listenAddress, nil); err != nil {
		log.Fatal(err)
	}
}