server

package
v0.0.0-...-69e45e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2015 License: Apache-2.0 Imports: 21 Imported by: 34

Documentation

Overview

HTTP サーバー関係。

Index

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 DeleteCookie

func DeleteCookie(r *http.Request, label string)

リクエストから指定した cookie を削除する。

func LogRequest

func LogRequest(lv level.Level, r *http.Request, useBody bool, prefs ...interface{})

func LogResponse

func LogResponse(lv level.Level, r *http.Response, useBody bool, prefs ...interface{})

func ParseSender

func ParseSender(r *http.Request) string

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 Serve

func Serve(handler http.Handler, socType, protType string, param interface{}) error

サーバーを立てる。

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 DebugParameter

type DebugParameter interface {
	ShutdownChannel() chan struct{}
}

デバッグに使える関数。

type Error

type Error struct {
	// contains filtered or unexported fields
}

HTTP のステータスコードを付加したエラー。

func ErrorFrom

func ErrorFrom(err error) *Error

通常のエラーから変換する。

func NewError

func NewError(stat int, msg string, cause error) *Error

stat が 0 の場合、代わりに http.StatusInternalServerError が入る。

func (*Error) Cause

func (this *Error) Cause() error

func (*Error) Error

func (this *Error) Error() string

func (*Error) Message

func (this *Error) Message() string

func (*Error) Status

func (this *Error) Status() int

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

func (*Stopper) Lock

func (this *Stopper) Lock()

func (*Stopper) Stop

func (this *Stopper) Stop()

func (*Stopper) Stopped

func (this *Stopper) Stopped() bool

func (*Stopper) Unlock

func (this *Stopper) Unlock()

func (*Stopper) Unstop

func (this *Stopper) Unstop()

func (*Stopper) Wait

func (this *Stopper) Wait()

type TcpParameter

type TcpParameter interface {
	// tcp のポート番号。
	SocketPort() int
}

SocketType が tcp のときに追加で必要な関数。

type UnixParameter

type UnixParameter interface {
	// unix のファイルパス。
	SocketPath() string
}

SocketType が unix のときに追加で必要な関数。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL