Documentation ¶
Index ¶
- Constants
- Variables
- func DebugMode() bool
- func EnvMode() string
- func ExecPath() string
- func NegotiateRequestListener(offers []string, useFirstOffer bool) func(event EventInterface)
- func RegisterCommand(command console.CommandInterface)
- func RegisterServer(server ServerInterface)
- func Run(server ...ServerInterface)
- type Config
- type Controller
- func (c *Controller) IndexAction(r *Request) ResponseInterface
- func (c *Controller) Name() string
- func (c *Controller) OK(content interface{}) ResponseInterface
- func (c *Controller) Response(statusCode int, content interface{}) ResponseInterface
- func (c *Controller) Routing(r RouterInterface)
- func (c *Controller) TemplateResponse(statusCode int, templateName string, content interface{}) ResponseInterface
- type ControllerInterface
- type EventInterface
- type Handler
- type PanicEvent
- type ParamAttributes
- type Params
- type Request
- type RequestEvent
- type Response
- type ResponseEvent
- type ResponseInterface
- func EmptyResponse() ResponseInterface
- func ErrorResponse(statusCode int, debug string) ResponseInterface
- func JSONResponse(statusCode int, content interface{}) ResponseInterface
- func RedirectResponse(request *Request, statusCode int, url string) ResponseInterface
- func StreamResponse(statusCode int, content func(w io.Writer) error) ResponseInterface
- func TemplateResponse(statusCode int, template *template.Template, content interface{}) ResponseInterface
- func XMLResponse(statusCode int, content interface{}) ResponseInterface
- type ResponseWriterInterface
- type RouteInterface
- type RouterInterface
- type ServerInterface
Constants ¶
View Source
const ( EventRequest events.EventType = "request" EventResponse events.EventType = "response" EventPanic events.EventType = "panic" )
View Source
const ( Development = "dev" Staging = "staging" Production = "prod" )
View Source
const ( HEAD = http.MethodHead GET = http.MethodGet POST = http.MethodPost PUT = http.MethodPut PATCH = http.MethodPatch DELETE = http.MethodDelete OPTIONS = http.MethodOptions TRACE = http.MethodTrace CONNECT = http.MethodConnect )
View Source
const ( HandleOPTIONS types.Flag HandleMethodNotAllowed RedirectTrailingSlash )
View Source
const RouteParamRequirement = `[^/]+`
View Source
const (
ServerName = "gowl/1.0"
)
Variables ¶
View Source
var ( Debug = log.New(stdout, "[gowl] ", log.LstdFlags) Error = log.New(stderr, "[gowl] ", log.LstdFlags|log.Lshortfile) )
View Source
var ErrorTemplate = template.Must(template.New("error").Parse(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{.name}}</title>
</head>
<body style="font-family: sans-serif">
<h1 style="font-size: x-large">{{.name}}</h1>
{{if .debug -}}
<pre>{{.debug}}</pre>
{{- end}}
<hr style="border-style: outset">
<small>{{.server}}</small>
</body>
</html>`))
Functions ¶
func NegotiateRequestListener ¶
func NegotiateRequestListener(offers []string, useFirstOffer bool) func(event EventInterface)
func RegisterCommand ¶
func RegisterCommand(command console.CommandInterface)
func RegisterServer ¶
func RegisterServer(server ServerInterface)
func Run ¶
func Run(server ...ServerInterface)
Types ¶
type Config ¶
type Config struct { Addr string `json:"addr"` EnableTLS bool `json:"enable_tls"` CertFile string `json:"cert_file"` KeyFile string `json:"key_file"` ServerName string `json:"server_name"` NotFoundHandler Handler `json:"-"` MethodNotAllowedHandler Handler `json:"-"` HandleOptions bool `json:"handle_options"` HandleMethodNotAllowed bool `json:"handle_method_not_allowed"` RedirectTrailingSlash bool `json:"redirect_trailing_slash"` RedirectUpperCasePath bool `json:"redirect_upper_case_path"` TemplatePath string `json:"template_path"` TemplateFileExt string `json:"template_file_ext"` TemplateFunc template.FuncMap `json:"-"` }
func LoadConfig ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller
func (*Controller) IndexAction ¶
func (c *Controller) IndexAction(r *Request) ResponseInterface
func (*Controller) Name ¶
func (c *Controller) Name() string
func (*Controller) OK ¶
func (c *Controller) OK(content interface{}) ResponseInterface
func (*Controller) Response ¶
func (c *Controller) Response(statusCode int, content interface{}) ResponseInterface
func (*Controller) Routing ¶
func (c *Controller) Routing(r RouterInterface)
func (*Controller) TemplateResponse ¶
func (c *Controller) TemplateResponse(statusCode int, templateName string, content interface{}) ResponseInterface
type ControllerInterface ¶
type ControllerInterface interface { Name() string Routing(r RouterInterface) // contains filtered or unexported methods }
ControllerInterface
type EventInterface ¶
type EventInterface = events.EventInterface
type ParamAttributes ¶
type ParamAttributes struct { Requirement string DefaultValue string // contains filtered or unexported fields }
ParamAttributes
type RequestEvent ¶
RequestEvent
func (*RequestEvent) Request ¶
func (e *RequestEvent) Request() *Request
func (*RequestEvent) SetResponse ¶
func (e *RequestEvent) SetResponse(response ResponseInterface)
type Response ¶
type Response struct { Content interface{} // contains filtered or unexported fields }
Response
func NewResponse ¶
func (*Response) SetStatusCode ¶
func (*Response) StatusCode ¶
type ResponseEvent ¶
ResponseEvent
func (*ResponseEvent) Request ¶
func (e *ResponseEvent) Request() *Request
func (*ResponseEvent) Response ¶
func (e *ResponseEvent) Response() ResponseInterface
func (*ResponseEvent) SetResponse ¶
func (e *ResponseEvent) SetResponse(response ResponseInterface)
type ResponseInterface ¶
ResponseInterface
func EmptyResponse ¶
func EmptyResponse() ResponseInterface
func ErrorResponse ¶
func ErrorResponse(statusCode int, debug string) ResponseInterface
func JSONResponse ¶
func JSONResponse(statusCode int, content interface{}) ResponseInterface
func RedirectResponse ¶
func RedirectResponse(request *Request, statusCode int, url string) ResponseInterface
func StreamResponse ¶
func StreamResponse(statusCode int, content func(w io.Writer) error) ResponseInterface
...
func TemplateResponse ¶
func TemplateResponse(statusCode int, template *template.Template, content interface{}) ResponseInterface
func XMLResponse ¶
func XMLResponse(statusCode int, content interface{}) ResponseInterface
type ResponseWriterInterface ¶
type ResponseWriterInterface interface {
WriteResponse(w http.ResponseWriter) error
}
ResponseWriterInterface
type RouteInterface ¶
type RouteInterface interface { SetName(name string) RouteInterface AddParam(name string, attr ParamAttributes) RouteInterface SetParams(params Params) RouteInterface SetFlag(flag types.Flag) RouteInterface On(eventType events.EventType, listener func(event EventInterface)) RouteInterface String() string // contains filtered or unexported methods }
RouteInterface
type RouterInterface ¶
type RouterInterface interface { SetPrefix(path string) SetFlag(flag types.Flag) Match(path string, handler Handler, method ...string) RouteInterface HEAD(path string, handler Handler) RouteInterface GET(path string, handler Handler) RouteInterface POST(path string, handler Handler) RouteInterface PUT(path string, handler Handler) RouteInterface PATCH(path string, handler Handler) RouteInterface DELETE(path string, handler Handler) RouteInterface OPTIONS(path string, handler Handler) RouteInterface TRACE(path string, handler Handler) RouteInterface CONNECT(path string, handler Handler) RouteInterface On(eventType events.EventType, listener func(event EventInterface)) // contains filtered or unexported methods }
RouterInterface
func NewRouter ¶
func NewRouter(flags types.Flag) RouterInterface
type ServerInterface ¶
type ServerInterface interface { Config() *Config NewRouter() RouterInterface RegisterRouter(router RouterInterface, routers ...RouterInterface) RegisterController(controller ControllerInterface, controllers ...ControllerInterface) On(eventType events.EventType, listener func(event EventInterface)) LoadTemplates() Listen() error String() string }
ServerInterface
func NewServer ¶
func NewServer(config *Config) ServerInterface
Click to show internal directories.
Click to hide internal directories.