Noob question context

OK so as cool as Golang is, it’s a bit of a mine field with a lot of examples all assuming knowledge.

So I’ve a local GAE engine running, starting build out basic programs, what I now want to do is access GCS, I’ve created a service account, downloaded the .json key but am struggling for an example (that works) as to how I can access my cloud bucket using the service account. Am setting the set GOOGLE_APPLICATION_CREDENTIALS=(path to json file) as I run up the app, but context I’m assuming is ctx := context.Background() ??
Sorry this is probably way too easier question for forum, but if you don’t ask…

If you initiate the context yourself then yes you can use context.Background() as shown here.

If you are working in a handler, you can access the current context with:

func handler(w http.ResponseWriter, r *http.Request) {
    ctx := r.Context()
}

To learn more about context, see Go Concurrency Patterns: Context.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.