1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GO+GAE+Middlewareで気をつけたこと

Posted at

Handlerはきちんとreturnしないといけない

たいして躓いたわけではないが、MiddelewareHandlerを定義するときはきちんとreturnしておかないと、不要なコードが実行されてしまうということ。


func loggingMiddleware(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		log.Println("メインのHandlerの前にここが実行されて次の制御に移るわけだが")
        if true {
		    next.ServeHTTP(w, r)
            log.Println("ここで終わってくれなくて")
            //return 終わらせたければしっかりreturnしないといけない
        }   
        log.Println("その制御から戻ってきてこのコードは実行されてしまう")
		return
	})
}

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?