LoginSignup
0
0

More than 1 year has passed since last update.

http: superfluous response.WriteHeader call from~エラー

Posted at

Golangでの開発中、サーバを立ち上げて機能を確認しようとgo runしたところ
http: superfluous response.WriteHeader call from~ エラーが。
あまり参考にできるサイトが少なく、chatGPTに聞いてみたら

このエラーは、HTTPレスポンスの WriteHeader メソッドが複数回呼び出されたことを示しています。HTTPレスポンスでは、WriteHeaderメソッドはレスポンスヘッダーを一度だけ設定する必要がありますが、このエラーが発生すると、同じレスポンスヘッダーが複数回設定されることになります。

エラー箇所を見ると

...
case http.MethodPost:
...
}
http.Redirect(w, r, "/", 302)
}

http.Redirect(w, r, "/", 302)がswitchのネストに入っていなかった。。。

ちゃんとネストに含めると動きました。

0
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
0
0