I know that, right now (and probably forever), we won't have static variables in Go... but is there a way to protect variables in some way?
import (
"net/http"
"net/http/cookiejar"
)
func funcThatDoesRequests(request Request) (response Response, e error){
static cookieJar, _ := cookiejar.New(nil)
static client := http.Client{ Jar: cookieJar }
response, e = client.Do(handshakeRequest)
return
}
I don't want the http client
and its cookieJar
floating around so other functions can do something with them. I need the cookieJar
and client
to only be accessible inside the funcThatDoesRequests
. Is that possible?
Static variables (see static keyword in the pseudo code example) is a feature present in languages like C and PHP, to name some common languages.