Dmitry Dyachkov
Dmitry Dyachkov

Reputation: 1785

Go Handling HTTPS requests in Google App Engine

In GAE I just use a default domain name: https://*.appspot.com, so I don't need to generate self-signed certificates.

Google App Engine docs specify how app.yaml should be configured to serve SSL connections:

https://cloud.google.com/appengine/docs/standard/go/config/appref#handlers_secure

But to serve an HTTPS connection in Go I write the following code example where I need to specify the certificates' filenames:

import (
    "net/http"
)

func main() {
    go http.ListenAndServeTLS(Address, "cert.pem", "key.pem", nil)
}

I don't understand how in this case to serve SSL requests if I don't generate certificates myself.

Upvotes: 0

Views: 341

Answers (1)

Darshan Rivka Whittle
Darshan Rivka Whittle

Reputation: 34031

You don't need to call http.ListenAndServeTLS on App Engine. If you have your app.yaml set up correctly, traffic will be served over SSL for you. A minimal App Engine app might be something like this:

package main

import (
    "fmt"
    "net/http"
)

func init() {
    http.HandleFunc("/", handler)
}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "Hi")
}

Upvotes: 3

Related Questions