Documentation ¶
Index ¶
- Constants
- Variables
- type App
- type Config
- type Context
- func (ctx *Context) Abort()
- func (ctx *Context) AddCookies(cookies ...*http.Cookie)
- func (ctx *Context) AddHeader(key, val string)
- func (ctx *Context) Cookie(key string) (*http.Cookie, error)
- func (ctx *Context) Fail(data interface{}) error
- func (ctx *Context) File(key string) (multipart.File, *multipart.FileHeader, error)
- func (ctx *Context) Get(key string) (interface{}, bool)
- func (ctx *Context) HTML(html string, statusCode ...int) error
- func (ctx *Context) Has(key string) bool
- func (ctx *Context) Header(key string) string
- func (ctx *Context) IP() string
- func (ctx *Context) JSON(data interface{}, statusCode ...int) error
- func (ctx *Context) Log(fmt string, args ...interface{})
- func (ctx *Context) Method() string
- func (ctx *Context) MultiValuesHeader(key string) []string
- func (ctx *Context) MultiValuesQuery(key string) []string
- func (ctx *Context) MultiValuesQueryDefault(key string, defaultValues []string) []string
- func (ctx *Context) Next()
- func (ctx *Context) Path() string
- func (ctx *Context) Post() string
- func (ctx *Context) PostForm(key string) string
- func (ctx *Context) PostJSON(payload interface{}) error
- func (ctx *Context) Query(key string) string
- func (ctx *Context) QueryDefault(key, defaultValue string) string
- func (ctx *Context) Redirect(url string, statusCode ...int)
- func (ctx *Context) Set(key string, val interface{}) interface{}
- func (ctx *Context) SetContentType(contentType string)
- func (ctx *Context) SetHeader(key, val string)
- func (ctx *Context) SetStatusCode(code int) error
- func (ctx *Context) String(data string, statusCode ...int) error
- func (ctx *Context) Success(data interface{}) error
- func (ctx *Context) Use(handlers ...HandlerFunc)
- func (ctx *Context) Write(data []byte) (int, error)
- type HandlerChain
- type HandlerFunc
- type O
- type Request
- func (req *Request) Cookie(key string) (*http.Cookie, error)
- func (req *Request) File(key string) (multipart.File, *multipart.FileHeader, error)
- func (req *Request) Header(key string) string
- func (req *Request) Host() string
- func (req *Request) IP() string
- func (req *Request) Method() string
- func (req *Request) MultiValuesHeader(key string) []string
- func (req *Request) MultiValuesQuery(key string) []string
- func (req *Request) Path() string
- func (req *Request) Post() string
- func (req *Request) PostForm(key string) string
- func (req *Request) Query(key string) string
- type Response
- func (resp *Response) AddCookies(cookies ...*http.Cookie)
- func (resp *Response) AddHeader(key, val string)
- func (resp *Response) SetBody(data []byte) (int, error)
- func (resp *Response) SetHeader(key, val string)
- func (resp *Response) SetStatusCode(code int) error
- func (resp *Response) StatusCode() int
Constants ¶
const ( // HeaderContentType is the "Content-Type" header. HeaderContentType = "Content-Type" // Host is the "Host" header. HeaderHost = "Host" // HeaderLocation is the "Location" header. HeaderLocation = "Location" // HeaderReferrer is the "Referer" header. HeaderReferrer = "Referrer" // HeaderSetCookie is the "Set-Cookie" header. HeaderSetCookie = "Set-Cookie" )
HTTP header names.
const ( // MIMETypeJSON indicates the "application/json" MIME type. MIMETypeJSON = "application/json" // MIMETypeHTML indicates the "text/html" MIME type. MIMETypeHTML = "text/html" // MIMETypeText indicates the "text/plain" MIME type. MIMETypeText = "text/plain" )
MIME types for HTTP content type.
Variables ¶
var DebugWriter io.Writer = os.Stdout
DebugWriter is the writter used to print debug messages, default `os.Stdout`.
var ErrInvalidStatusCode = errors.New("invalid status code")
ErrInvalidStatusCode is returned by the response status code is not valid.
var ErrNoTLSCert = errors.New("no TLS certificate file")
ErrNoTLSCert is returned by the TLS server when no certificate file is provided.
var ErrNoTLSKey = errors.New("no TLS key file")
ErrNoTLSKey is returned by the TLS server when no private key file is provided.
var Version = "v0.1.2"
Version is the current dolphin framework version.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the dolphin web server engine.
func (*App) RunTLS ¶ added in v0.1.1
RunTLS starts the app to provide HTTPS service and listens on the given port.
func (*App) ServeHTTP ¶
func (app *App) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface.
func (*App) Use ¶
func (app *App) Use(handlers ...HandlerFunc)
Use registers one or more middlewares or request handlers to the app.
type Config ¶
type Config struct { // CertFile is the TLS certificate file. CertFile *string // KeyFile is the TLS private key file. KeyFile *string // Logger is the logger used by the app, dolphin will use log.Printf if this // have not set. Logger *log.Logger // Port is the port to listen on. Port int }
Config is the configuration for the dolphin web application.
type Context ¶
type Context struct { // Request is the wrapped HTTP request. Request *Request // Response is the wrapped HTTP response. Response *Response // contains filtered or unexported fields }
Context is the context instance for the request.
func (*Context) AddCookies ¶
AddCookies adds one or more given cookies to the response.
func (*Context) Fail ¶
Fail writes the given data to the response body as JSON, and set the status code to 400 (Bad Request).
func (*Context) HTML ¶
HTML writes the given data to the response body as HTML, and set the content type to "text/html".
func (*Context) Has ¶ added in v0.1.1
Has returns true if the given key exists in the context state.
func (*Context) JSON ¶
JSON stringifies and writes the given data to the response body, and set the content type to "application/json".
func (*Context) MultiValuesHeader ¶
MultiValuesHeader returns a string array value for the given key from the request header.
func (*Context) MultiValuesQuery ¶
MultiValuesQuery returns a string array value for the given key from the request query.
func (*Context) MultiValuesQueryDefault ¶
MultiValuesQueryDefault returns a string array value for the given key from the request query string, and returns the default values if the key is not exists.
func (*Context) QueryDefault ¶
QueryDefault returns the query value from the request by the given key, and returns the default value if the key is not found.
func (*Context) Redirect ¶
Redirect redirects the request to the given URL, it'll set status code to 302 (Found) as default status code if it isn't set.
func (*Context) SetContentType ¶
SetContentType sets the response HTTP header "Content-Type" field to the specific MIME type value.
func (*Context) SetStatusCode ¶
SetStatusCode sets the status code of the response.
func (*Context) String ¶
String writes the given string to the response body, and sets the context type to "text/plain".
func (*Context) Success ¶
Success writes the given data to the response body as JSON, and set the status code to 200 (OK).
func (*Context) Use ¶
func (ctx *Context) Use(handlers ...HandlerFunc)
Use registers one or more middlewares or request handlers to the context.
type HandlerFunc ¶
type HandlerFunc func(*Context)
HandlerFunc is the function that register as a handler to the app.
type O ¶
type O map[string]interface{}
O is an alias for map that contains string key and interface{} value.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is the wrapped HTTP request object.
func (*Request) MultiValuesHeader ¶
MultiValuesHeader returns the string array type values from the request header by the specific key.
func (*Request) MultiValuesQuery ¶
MultiValuesQuery returns the string array type values from the request query string by the specific key.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is the HTTP response wrapper.
func (*Response) AddCookies ¶
AddCookies adds cookies setting to response, it will set response HTTP header "Set-Cookie" field.
func (*Response) SetStatusCode ¶
SetStatusCode sets the status code of the response.
func (*Response) StatusCode ¶
StatusCode gets the response status code.