Documentation ¶
Overview ¶
Package pkghttp defines common functionality for http.
Index ¶
- Variables
- func Error(responseWriter http.ResponseWriter, statusCode int, err error) bool
- func ErrorInternal(responseWriter http.ResponseWriter, err error) bool
- func FileHandlerFunc(filePath string) func(http.ResponseWriter, *http.Request)
- func GetAndListenAndServe(handler http.Handler) error
- func ListenAndServe(handler http.Handler, handlerEnv HandlerEnv) error
- func NewWrapperHandler(delegate http.Handler, handlerEnv HandlerEnv) http.Handler
- func ParseDate(valueString string, timeFormat string) (*google_type.Date, error)
- func ParseFloat64(valueString string) (float64, error)
- func ParseMoney(valueString string) (*pbmoney.Money, error)
- func ParseUint32(valueString string) (uint32, error)
- func QueryGet(request *http.Request, key string) string
- func QueryGetDate(request *http.Request, key string, timeFormat string) (*google_type.Date, error)
- func QueryGetFloat64(request *http.Request, key string) (float64, error)
- func QueryGetMoney(request *http.Request, key string) (*pbmoney.Money, error)
- func QueryGetUint32(request *http.Request, key string) (uint32, error)
- type Call
- func (*Call) Descriptor() ([]byte, []int)
- func (m *Call) GetDuration() *google_protobuf.Duration
- func (m *Call) GetQuery() map[string]string
- func (m *Call) GetRequestForm() map[string]string
- func (m *Call) GetRequestHeader() map[string]string
- func (m *Call) GetResponseHeader() map[string]string
- func (*Call) ProtoMessage()
- func (m *Call) Reset()
- func (m *Call) String() string
- type HandlerEnv
- type ServerCouldNotStart
- type ServerFinished
- type ServerStarting
- type Templater
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Error ¶
func Error(responseWriter http.ResponseWriter, statusCode int, err error) bool
Error does http.Error on the error if not nil, and returns true if not nil.
func ErrorInternal ¶
func ErrorInternal(responseWriter http.ResponseWriter, err error) bool
ErrorInternal does Error 500.
func FileHandlerFunc ¶
func FileHandlerFunc(filePath string) func(http.ResponseWriter, *http.Request)
FileHandlerFunc returns a handler function for a file path.
func GetAndListenAndServe ¶
GetAndListenAndServe is GetHandlerEnv then ListenAndServe.
func ListenAndServe ¶
func ListenAndServe(handler http.Handler, handlerEnv HandlerEnv) error
ListenAndServe is the equivalent to http's method.
Intercepts requests and responses, handles SIGINT and SIGTERM. When this returns, any errors will have been logged. If the server starts, this will block until the server stops.
Uses a wrapper handler.
func NewWrapperHandler ¶
func NewWrapperHandler(delegate http.Handler, handlerEnv HandlerEnv) http.Handler
NewWrapperHandler returns a new wrapper handler.
func ParseDate ¶
ParseDate parses the Date from the valueString, if it exists. Otherwise, returns nil. The time format given will be used to parse the request value into a time.Time object.
func ParseFloat64 ¶
ParseFloat64 parses the float64 from the valueString, if it exists. Otherwise, returns 0.0. error returned if there is a parsing error.
func ParseMoney ¶
ParseMoney parses the money from the valueString, if it exists. Otherwise, returns nil. Money is expected to be in float notation, ie $123.45 is 123.45. error returned if there is a parsing error.
func ParseUint32 ¶
ParseUint32 parses the uint32 from the valueString, if it exists. Otherwise, returns 0. error returned if there is a parsing error.
func QueryGet ¶
QueryGet gets the string by key from the request query, if it exists. Otherwise, returns "".
func QueryGetDate ¶
QueryGetDate gets the Date by key from the request query, if it exists. Otherwise, returns nil. The time format given will be used to parse the request value into a time.Time object.
func QueryGetFloat64 ¶
QueryGetFloat64 gets the float64 by key from the request query, if it exists. Otherwise, returns 0.0. error returned if there is a parsing error.
func QueryGetMoney ¶
QueryGetMoney gets the money by key from the request query, if it exists. Otherwise, returns nil. Money is expected to be in float notation, ie $123.45 is 123.45. error returned if there is a parsing error.
Types ¶
type Call ¶
type Call struct { Method string `protobuf:"bytes,1,opt,name=method" json:"method,omitempty"` Path string `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"` Query map[string]string `` /* 130-byte string literal not displayed */ RequestHeader map[string]string `` /* 148-byte string literal not displayed */ RequestForm map[string]string `` /* 144-byte string literal not displayed */ ResponseHeader map[string]string `` /* 150-byte string literal not displayed */ StatusCode uint32 `protobuf:"varint,7,opt,name=status_code" json:"status_code,omitempty"` Duration *google_protobuf.Duration `protobuf:"bytes,8,opt,name=duration" json:"duration,omitempty"` Error string `protobuf:"bytes,9,opt,name=error" json:"error,omitempty"` }
func (*Call) GetDuration ¶
func (m *Call) GetDuration() *google_protobuf.Duration
type HandlerEnv ¶
type HandlerEnv struct { // The port to serve on. Port uint16 `env:"PORT,default=8080"` // HealthCheckPath is the path for health checking. // This path will always return 200 for a GET. // Default value is /health. HealthCheckPath string `env:"HTTP_HEALTH_CHECK_PATH,default=/health"` // The time in seconds to shutdown after a SIGINT or SIGTERM. // Default value is 10. ShutdownTimeoutSec uint64 `env:"HTTP_SHUTDOWN_TIMEOUT_SEC,default=10"` }
HandlerEnv is the environment for a handler.
func GetHandlerEnv ¶
func GetHandlerEnv() (HandlerEnv, error)
GetHandlerEnv gets the HandlerEnv from the environment.
type ServerCouldNotStart ¶
type ServerCouldNotStart struct {
Error string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
}
func (*ServerCouldNotStart) Descriptor ¶
func (*ServerCouldNotStart) Descriptor() ([]byte, []int)
func (*ServerCouldNotStart) ProtoMessage ¶
func (*ServerCouldNotStart) ProtoMessage()
func (*ServerCouldNotStart) Reset ¶
func (m *ServerCouldNotStart) Reset()
func (*ServerCouldNotStart) String ¶
func (m *ServerCouldNotStart) String() string
type ServerFinished ¶
type ServerFinished struct { Error string `protobuf:"bytes,1,opt,name=error" json:"error,omitempty"` Duration *google_protobuf.Duration `protobuf:"bytes,2,opt,name=duration" json:"duration,omitempty"` }
func (*ServerFinished) Descriptor ¶
func (*ServerFinished) Descriptor() ([]byte, []int)
func (*ServerFinished) GetDuration ¶
func (m *ServerFinished) GetDuration() *google_protobuf.Duration
func (*ServerFinished) ProtoMessage ¶
func (*ServerFinished) ProtoMessage()
func (*ServerFinished) Reset ¶
func (m *ServerFinished) Reset()
func (*ServerFinished) String ¶
func (m *ServerFinished) String() string
type ServerStarting ¶
type ServerStarting struct {
Port uint32 `protobuf:"varint,1,opt,name=port" json:"port,omitempty"`
}
func (*ServerStarting) Descriptor ¶
func (*ServerStarting) Descriptor() ([]byte, []int)
func (*ServerStarting) ProtoMessage ¶
func (*ServerStarting) ProtoMessage()
func (*ServerStarting) Reset ¶
func (m *ServerStarting) Reset()
func (*ServerStarting) String ¶
func (m *ServerStarting) String() string