gowl

package
v0.0.0-...-e08aaa0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2018 License: MIT Imports: 28 Imported by: 0

Documentation

Index

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 DebugMode

func DebugMode() bool

func EnvMode

func EnvMode() string

func ExecPath

func ExecPath() string

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

func LoadConfig(filename string) (config *Config, err error)

func NewConfig

func NewConfig() *Config

func (*Config) String

func (c *Config) String() string

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 Handler

type Handler func(r *Request) ResponseInterface

Handler

type PanicEvent

type PanicEvent struct {
	events.Event
	// contains filtered or unexported fields
}

PanicEvent

func (*PanicEvent) Error

func (e *PanicEvent) Error() error

type ParamAttributes

type ParamAttributes struct {
	Requirement  string
	DefaultValue string
	// contains filtered or unexported fields
}

ParamAttributes

type Params

type Params map[string]ParamAttributes

Params

type Request

type Request struct {
	*http.Request

	Data types.Data
	// contains filtered or unexported fields
}

func (*Request) ClientIP

func (r *Request) ClientIP() (ip string)

func (*Request) GetURL

func (r *Request) GetURL(name string, params types.StringMap, absolute bool) string

func (*Request) Param

func (r *Request) Param(name string) string

func (*Request) Params

func (r *Request) Params() types.StringMap

func (*Request) Template

func (r *Request) Template() *template.Template

type RequestEvent

type RequestEvent struct {
	events.Event
	// contains filtered or unexported fields
}

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 NewResponse(statusCode int, content interface{}) *Response

func (*Response) Header

func (r *Response) Header() http.Header

func (*Response) SetStatusCode

func (r *Response) SetStatusCode(code int)

func (*Response) StatusCode

func (r *Response) StatusCode() int

func (*Response) Write

func (r *Response) Write(w io.Writer) (err error)

type ResponseEvent

type ResponseEvent struct {
	events.Event
	// contains filtered or unexported fields
}

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

type ResponseInterface interface {
	StatusCode() int
	Header() http.Header
	Write(w io.Writer) error
}

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

Jump to

Keyboard shortcuts

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