Documentation
¶
Overview ¶
HTTP サーバー関係。
Index ¶
- Variables
- func CopyResponse(w http.ResponseWriter, resp *http.Response) error
- func DeleteCookie(r *http.Request, label string)
- func LogRequest(lv level.Level, r *http.Request, useBody bool, prefs ...interface{})
- func LogResponse(lv level.Level, r *http.Response, useBody bool, prefs ...interface{})
- func ParseSender(r *http.Request) string
- func RespondErrorHtml(w http.ResponseWriter, r *http.Request, origErr error, ...)
- func RespondErrorJson(w http.ResponseWriter, r *http.Request, origErr error, logPrefs ...interface{})
- func Serve(handler http.Handler, socType, protType string, param interface{}) error
- func WrapApi(stopper *Stopper, f HandlerFunc) http.HandlerFunc
- func WrapPage(stopper *Stopper, f HandlerFunc, errTmpl *template.Template) http.HandlerFunc
- type DebugParameter
- type Error
- type HandlerFunc
- type Stopper
- type TcpParameter
- type UnixParameter
Constants ¶
This section is empty.
Variables ¶
View Source
var Debug = false
デバッグログにリクエストボディを記録するかどうか。
View Source
var MaxSleepTime = time.Minute
冷却期間の最大値。
View Source
var ResetInterval = time.Minute
この期間以上エラー無しで動作したら冷却期間を 0 にする。
Functions ¶
func CopyResponse ¶
func CopyResponse(w http.ResponseWriter, resp *http.Response) error
func LogRequest ¶
func LogResponse ¶
func ParseSender ¶
HTTP リクエストの送り元を返す。 X-Forwarded-For ヘッダがあれば、その情報を優先する。
func RespondErrorHtml ¶
func RespondErrorHtml(w http.ResponseWriter, r *http.Request, origErr error, errTmpl *template.Template, logPrefs ...interface{})
HTML でエラーを返す。 テンプレートでは以下が使える。 {{.Status}}: HTTP ステータスコード。404 とか {{.StatusText}}: HTTP ステータスコード。Not Found とか {{.Error}}: エラー内容 {{.Debug}}: エラー詳細
func RespondErrorJson ¶
func RespondErrorJson(w http.ResponseWriter, r *http.Request, origErr error, logPrefs ...interface{})
JSON でエラーを返す。
func WrapApi ¶
func WrapApi(stopper *Stopper, f HandlerFunc) http.HandlerFunc
処理がパニックやエラーで終わったら、適当なレスポンスを JSON で返す。
func WrapPage ¶
func WrapPage(stopper *Stopper, f HandlerFunc, errTmpl *template.Template) http.HandlerFunc
処理がパニックやエラーで終わったら、適当なレスポンスを HTML で返す。
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
HTTP のステータスコードを付加したエラー。
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) error
WrapPage や WrapApi に渡す処理。
type Stopper ¶
type Stopper struct {
// contains filtered or unexported fields
}
処理途中でサーバーが終了するのを防ぐ。
メイン側で、
s.Lock() defer s.Unlock() for s.Stopped() { s.Wait() }
処理側で、
s.Stop() defer s.Unstop()
func NewStopper ¶
func NewStopper() *Stopper
type TcpParameter ¶
type TcpParameter interface { // tcp のポート番号。 SocketPort() int }
SocketType が tcp のときに追加で必要な関数。
type UnixParameter ¶
type UnixParameter interface { // unix のファイルパス。 SocketPath() string }
SocketType が unix のときに追加で必要な関数。
Click to show internal directories.
Click to hide internal directories.