Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6657
Closed
Open
Issue created Jun 14, 2020 by Administrator@rootContributor

[REQ][Go] Pass r.Context into handlers

Created by: metalmatze

Is your feature request related to a problem? Please describe.

I would like to propagate the request context through all levels of my application, so that I can use consistent request tracing across applications.

Describe the solution you'd like

Right now the generated handlers do not pass along the request or at least the request context. This can easily be fixed by:

func (c *DeploymentApiController) GetCurrentDeployment(w http.ResponseWriter, r *http.Request) {
-	result, err := c.service.GetCurrentDeployment()
+	result, err := c.service.GetCurrentDeployment(r.Context)
	if err != nil {
		w.WriteHeader(500)
		return
	}

	EncodeJSONResponse(result, nil, w)
}

Then all handlers of the services we need to implement have ctx context.Context as first argument. This should also make it possible for requests to close longer taking requests. If that's possible we could even cancel pretty heavy SQL queries etc.

Describe alternatives you've considered

Didn't really consider an alternative, as this is pretty much what every one in Go does these days. 😊

Assignee
Assign to
Time tracking