Documentation ¶
Overview ¶
Package api :: appError.go
api.Error interface wraps error with http status. api.AppError composes error and http status code for http handler without accessing to header in http.ResponseWriter.
Package api :: appHandler.go
api.AppHandler declares an extended http.Handler with configuration data and error (see api.AppError).
Package api :: appLogger.go - logging handlers
Package api :: appServer.go
Package api :: auth.go - auth handlers
Package api :: formatter.go - api formatters
Package api :: markdown.go - a Markdown handler
Package api :: params.go - http request parameters
Package api :: proxy.go - proxy handler
For each Proxy redirect/forward call, api.ProxyRoute defines a RedirectURL per prefix path. The api.ProxyRoute implements http.Handler interface so that the struct pointer itself can be wrapped in a routing configuration; optionally, a Proxy() can construct a http.Handler with prefix and predefined redirect URL.
Package api :: redirect.go - http redirect handlers
Package api :: route.go
Index ¶
- func AppLogger(handler http.Handler, name string) http.Handler
- func Auth(next http.Handler, token string) http.Handler
- func BasicAuth(next http.Handler, user, password string) http.Handler
- func GetJSONEncoder(w io.Writer, indent string) *json.Encoder
- func NewLogger(prefix string) *negroni.Logger
- func NewMarkdown(prefix, dir, indexFile string) negroni.Handler
- func NewMiddleware() *negroni.Negroni
- func NewRecovery() *negroni.Recovery
- func NewRouter(ctx cfg.Context, routeConfigs RouteConfigs) *mux.Router
- func Proxy(prefix, redirectURL string, w http.ResponseWriter, r *http.Request) error
- func ProxyHandler(prefix, redirectURL string) http.Handler
- func Redirect(prefix, redirectURL string, w http.ResponseWriter, r *http.Request) error
- func RedirectHandler(prefix, redirectURL string) http.Handler
- func RedirectToHTTPS(next http.Handler) http.Handler
- func WriteJSON(w http.ResponseWriter, code int, data interface{})
- func WriteZIP(w http.ResponseWriter, data []byte, filename string)
- type AppError
- type AppHandler
- type AppLoggerResponseWriter
- type AppServer
- type AppServerInterface
- type BodyParams
- type Error
- type HandlerFunc
- type MarkdownHandler
- type Params
- func (params *Params) GetBody(key string) interface{}
- func (params *Params) GetDateRange(key string) ([]time.Time, error)
- func (params *Params) GetDateValues(key string) ([]time.Time, error)
- func (params *Params) GetInt(key string, defaultValues ...int) (int, error)
- func (params *Params) GetIntByRange(key string, rangeValues ...int) int
- func (params *Params) GetNextPageURL(pgOffsetKey string, pgOffset int) string
- func (params *Params) GetValue(key string, defaultValues ...string) string
- func (params *Params) GetValues(key string) []string
- func (params *Params) HasKey(key string) bool
- type ProxyClient
- type ProxyRoute
- type RouteConfig
- type RouteConfigs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetJSONEncoder ¶
GetJSONEncoder returns JSON by specified indent
func NewMarkdown ¶
NewMarkdown constructs a MarkdownHandler
func NewMiddleware ¶
NewMiddleware returns a negroni middleware
func NewRecovery ¶
NewRecovery returns a negroni recovery handler
func NewRouter ¶
func NewRouter(ctx cfg.Context, routeConfigs RouteConfigs) *mux.Router
NewRouter returns *mux.Router
func ProxyHandler ¶
ProxyHandler constructs an http.Handler by prefix path and redirect URL
func RedirectHandler ¶
RedirectHandler constructs an http.Handler by prefix path and redirect URL
func RedirectToHTTPS ¶
RedirectToHTTPS is a middleware handler returns http.HandlerFunc
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, code int, data interface{})
WriteJSON writes status code and response data
Types ¶
type AppError ¶
type AppError struct { // Err inherits standard error interface Err error `json:"-"` // ErrorMessage represents Err.Error() ErrorMessage string `json:"message,omitempty"` // StatusCode is http status code StatusCode int `json:"code,omitempty"` }
AppError represents an error with an associated HTTP status code.
func NewAppError ¶
NewAppError constructs an AppError
func (AppError) StatusText ¶
StatusText returns HTTP status text.
type AppHandler ¶
type AppHandler struct { cfg.Context Handle func(e cfg.Context, w http.ResponseWriter, r *http.Request) error }
AppHandler struct wraps Env and Handle function implementing http.Handler
func (AppHandler) ServeHTTP ¶
func (ah AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
type AppLoggerResponseWriter ¶
type AppLoggerResponseWriter struct { http.ResponseWriter StatusCode int }
AppLoggerResponseWriter implements http.ResponseWriter
func (*AppLoggerResponseWriter) WriteHeader ¶
func (alw *AppLoggerResponseWriter) WriteHeader(code int)
WriteHeader implements http.ResponseWriter interface
type AppServer ¶
type AppServer struct { Ctx *cfg.Context // app context Doc negroni.Handler // negroni static handler Handler *negroni.Negroni // negroni handler Logger *negroni.Logger // negroni logger Router *mux.Router // mux router Server AppServerInterface // http.Server implements ListenAndServe }
AppServer represents partial http.Server
type AppServerInterface ¶
type AppServerInterface interface { ListenAndServe() error ListenAndServeTLS(string, string) error }
AppServerInterface represents partial http.Server interface
type BodyParams ¶
type BodyParams map[string]interface{}
BodyParams struct contains an JSON key/value map object
type Error ¶
Error represents a handler error to provide Status() and embed the built-in error interface.
func WriteAppError ¶
func WriteAppError(w http.ResponseWriter, appError AppError) Error
WriteAppError writes status code and returns Error
func WriteError ¶
func WriteError(w http.ResponseWriter, code int, message string) Error
WriteError writes status code and returns Error
type HandlerFunc ¶
HandlerFunc represents a handler function with cfg.Context
type MarkdownHandler ¶
type MarkdownHandler struct {
// contains filtered or unexported fields
}
MarkdownHandler struct is a negroni.Handler
func (*MarkdownHandler) ServeHTTP ¶
func (m *MarkdownHandler) ServeHTTP( rw http.ResponseWriter, req *http.Request, next http.HandlerFunc)
ServeHTTP implements negroni.Handler interface
type Params ¶
type Params struct { Form url.Values Body []byte Path string Post BodyParams Vars map[string]string }
Params struct contains key/value pairs from URL path, request body, and query string
func (*Params) GetDateRange ¶
GetDateRange method returns a date range by the key name
func (*Params) GetDateValues ¶
GetDateValues method returns sorted date values by the key name
func (*Params) GetInt ¶
GetInt method returns int value by the key name or the second parameter as default value
func (*Params) GetIntByRange ¶
GetIntByRange method returns int value by the key name and within the range of rangeValues parameters
func (*Params) GetNextPageURL ¶
GetNextPageURL returns next page URL per current page offset
func (*Params) GetValue ¶
GetValue method returns the value string by the key name or the second parameter as default value
type ProxyClient ¶
ProxyClient interface
type ProxyRoute ¶
type ProxyRoute struct { // Prefix defines the matching prefix path to be replaced Prefix string // RedirectOnly specifies to use httpRedirect rather than a proxy client RedirectOnly bool // RedirectURL defines the replacing URL path RedirectURL string }
ProxyRoute struct defines a redirecting URL based on pattern by converting matched Prefix path to RedirectURL
func (*ProxyRoute) ServeHTTP ¶
func (p *ProxyRoute) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler
type RouteConfig ¶
type RouteConfig struct { Pattern string Method string Name string HandlerFunc func(e cfg.Context, w http.ResponseWriter, r *http.Request) error Proxy ProxyRoute }
RouteConfig struct