Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Calling a handler from another handler results in an incorrect return#2724

Answeredbyaldas
HarryPeach asked this question inQ&A
Discussion options

Hey, I'm writing a handler that needs to call another handler (i.e. I have a POST handler that verifies a users access, and I'd like another POST handler "getData" that calls the access handler first)

When I do this however, the return value of the "getData" handler is always that of the verify handler.

Short Example:

funcverifyUser(c echo.Context)error {...returnc.NoContent(http.StatusOK)}funcgetData(c echo.Context)error {err:=verifyUser(c)[...handleerror,propagateifnecessary]returnc.NoContent(http.StatusInternalServerError)// ERROR: This returns 200 (OK)}

Is there an obvious issue I'm missing or another way to approach this?

You must be logged in to vote
Answered by aldasDec 19, 2024

refactor thatverifyUser not to usereturn c.NoContent(http.StatusOK) and separates its business logic as separate function - and call that ingetData.

Callingc.NoContent(http.StatusOK) means that the response will be sent immeteately to the client and any call toc.NoContent etc will be discarder as response has been "commited"

Replies: 1 comment

Comment options

refactor thatverifyUser not to usereturn c.NoContent(http.StatusOK) and separates its business logic as separate function - and call that ingetData.

Callingc.NoContent(http.StatusOK) means that the response will be sent immeteately to the client and any call toc.NoContent etc will be discarder as response has been "commited"

You must be logged in to vote
0 replies
Answer selected byHarryPeach
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@HarryPeach@aldas

[8]ページ先頭

©2009-2026 Movatter.jp