I am creating a REST API in Go, and I want to build URLs to other resources in my replies.
Based on the http.Response
I can get the Host
and URL
.
However, how would I go about getting the transport scheme used by the server? http
or https
?
I attemped to check if server.TLSConfig
is nil
and then assuming it is using http
since it says this in the documentation for http.Server
:
TLSConfig *tls.Config // optional TLS config, used by ListenAndServeTLS
But it turns out this exists even when I do not run the server with ListenAndServeTLS
.
Or is this way of building my URLs the wrong way of doing things? Is there some other normal way of doing this?