srv

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: Apache-2.0 Imports: 27 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyRequestHeaders

func CopyRequestHeaders(r *http.Request, dst *http.Request)

func CopyResponseHeaders

func CopyResponseHeaders(w http.ResponseWriter, src *http.Response)

func CustomErrorResponse

func CustomErrorResponse(w http.ResponseWriter, statusCode int, vars map[string]string)

func DumpGoroutinesStackTrace

func DumpGoroutinesStackTrace(pid int)

func ErrorResponse added in v1.6.0

func ErrorResponse(w http.ResponseWriter, err error)

func GetVars

func GetVars(r *http.Request) map[string]string

func LogPanics

func LogPanics(logger LowLevelLogger, msg string)

func LogRequest added in v0.0.2

func LogRequest(logger LowLevelLogger, next http.Handler) http.Handler

LogRequest is a middleware that logs requests and also sets up a logger in the request context.

func LogRequestLine added in v0.0.2

func LogRequestLine(logger *zap.Logger, request *http.Request, start time.Time, newWriter *WebWriter, newReader *CountingReadCloser)

func NewCustomWriter

func NewCustomWriter(w http.ResponseWriter, f func(w http.ResponseWriter, status int) int) http.ResponseWriter

NewCustomWriter creates an http.ResponseWriter wrapper that calls your function on WriteHeader.

func NewRouter

func NewRouter() *router

func RetryListen

func RetryListen(ip string, port int) (net.Listener, error)

func RunServers

func RunServers(getServer func(conf.Config, *flag.FlagSet, ConfigLoader) (*IpPort, Server, LowLevelLogger, error), flags *flag.FlagSet)

func SetLogger

func SetLogger(r *http.Request, l LowLevelLogger) *http.Request

func SetVars

func SetVars(r *http.Request, v map[string]string) *http.Request

func SimpleErrorResponse

func SimpleErrorResponse(w http.ResponseWriter, statusCode int, body string)

func Split2

func Split2(path string, sep string) (string, string)

Split a string in twain on sep. Doing it this way over strings.Split*() saves allocating a slice.

func StandardResponse

func StandardResponse(w http.ResponseWriter, statusCode int)

func ValidateRequest

func ValidateRequest(w http.ResponseWriter, r *http.Request) bool

Types

type ConfigLoader added in v0.0.2

type ConfigLoader interface {
	GetHashPrefixAndSuffix() (string, string, error)
	GetPolicies() (conf.PolicyList, error)
	GetSyncRealms() (conf.SyncRealmList, error)
	GetRing(ringType, prefix, suffix string, policy int) (ring.Ring, error)
}

type CountingReadCloser added in v0.0.2

type CountingReadCloser struct {
	io.ReadCloser
	ByteCount int
}

func (*CountingReadCloser) Read added in v0.0.2

func (crc *CountingReadCloser) Read(b []byte) (n int, err error)

type DefaultConfigLoader added in v0.0.2

type DefaultConfigLoader struct{}

func (DefaultConfigLoader) GetHashPrefixAndSuffix added in v0.0.2

func (d DefaultConfigLoader) GetHashPrefixAndSuffix() (string, string, error)

func (DefaultConfigLoader) GetPolicies added in v0.0.2

func (d DefaultConfigLoader) GetPolicies() (conf.PolicyList, error)

func (DefaultConfigLoader) GetRing added in v0.0.2

func (d DefaultConfigLoader) GetRing(ringType, prefix, suffix string, policy int) (ring.Ring, error)

func (DefaultConfigLoader) GetSyncRealms added in v0.0.2

func (d DefaultConfigLoader) GetSyncRealms() (conf.SyncRealmList, error)

type HummingbirdServer

type HummingbirdServer struct {
	*http.Server
	// contains filtered or unexported fields
}

type IpPort added in v0.0.2

type IpPort struct {
	Ip                string
	Port              int
	CertFile, KeyFile string
}

type KeyType

type KeyType int

type LowLevelLogger

type LowLevelLogger interface {
	Error(msg string, fields ...zapcore.Field)
	Info(msg string, fields ...zapcore.Field)
	Debug(msg string, fields ...zapcore.Field)
	With(fields ...zapcore.Field) *zap.Logger
	Sugar() *zap.SugaredLogger
}

func GetLogger

func GetLogger(r *http.Request) LowLevelLogger

func SetupLogger

func SetupLogger(prefix string, atomicLevel *zap.AtomicLevel, flags *flag.FlagSet) (LowLevelLogger, error)

SetupLogger configures structured logging using uber's zap library.

type Server

type Server interface {
	Type() string
	Background(flags *flag.FlagSet) chan struct{}
	GetHandler(config conf.Config, metricsPrefix string) http.Handler
	Finalize() // This is called before stoping gracefully so that a server can clean up before closing
}

type TestConfigLoader added in v0.0.2

type TestConfigLoader struct {
	DefaultConfigLoader
	GetHashPrefixAndSuffixFunc func() (string, string, error)
	GetPoliciesFunc            func() (conf.PolicyList, error)
	GetSyncRealmsFunc          func() (conf.SyncRealmList, error)
	GetRingFunc                func(ringType, prefix, suffix string, policy int) (ring.Ring, error)
}

func NewTestConfigLoader added in v0.0.2

func NewTestConfigLoader(testRing ring.Ring) *TestConfigLoader

func (*TestConfigLoader) GetHashPrefixAndSuffix added in v0.0.2

func (t *TestConfigLoader) GetHashPrefixAndSuffix() (string, string, error)

func (*TestConfigLoader) GetPolicies added in v0.0.2

func (t *TestConfigLoader) GetPolicies() (conf.PolicyList, error)

func (*TestConfigLoader) GetRing added in v0.0.2

func (t *TestConfigLoader) GetRing(ringType, prefix, suffix string, policy int) (ring.Ring, error)

func (*TestConfigLoader) GetSyncRealms added in v0.0.2

func (t *TestConfigLoader) GetSyncRealms() (conf.SyncRealmList, error)

type WebWriter

type WebWriter struct {
	http.ResponseWriter
	Status          int
	ResponseStarted time.Time
	ByteCount       int
}

func (WebWriter) Hijack

func (w WebWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*WebWriter) Response

func (w *WebWriter) Response() (time.Time, int)

func (*WebWriter) Write added in v0.0.2

func (w *WebWriter) Write(b []byte) (n int, err error)

func (*WebWriter) WriteHeader

func (w *WebWriter) WriteHeader(status int)

type WebWriterInterface

type WebWriterInterface interface {
	http.ResponseWriter
	Response() (time.Time, int)
}

Jump to

Keyboard shortcuts

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