Documentation ¶
Index ¶
- Constants
- Variables
- func Error(issuer string, e error) error
- func Keep()
- func Listen(addr string, gs ...*Sola)
- func ListenKeep(addr string, gs ...*Sola)
- func ListenKeepTLS(addr, certFile, keyFile string, gs ...*Sola)
- func ListenTLS(addr, certFile, keyFile string, gs ...*Sola)
- func Use(ms ...Middleware)
- type C
- type Context
- type File
- type H
- type Handler
- type InternalError
- type M
- type Middleware
- type Sola
- func (s *Sola) CacheORM(key string, db *gorm.DB)
- func (s *Sola) DefaultORM() *gorm.DB
- func (s *Sola) Dev()
- func (s *Sola) LoadConfig()
- func (s *Sola) ORM(key string) *gorm.DB
- func (s *Sola) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Sola) SetHandler(code int, h Handler)
- func (s *Sola) Use(ms ...Middleware)
Constants ¶
View Source
const ( MIMEApplicationJSON = "application/json" MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8 MIMEApplicationJavaScript = "application/javascript" MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8 MIMEApplicationXML = "application/xml" MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8 MIMETextXML = "text/xml" MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8 MIMEApplicationForm = "application/x-www-form-urlencoded" MIMEApplicationProtobuf = "application/protobuf" MIMEApplicationMsgpack = "application/msgpack" MIMETextHTML = "text/html" MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 MIMETextPlain = "text/plain" MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8 MIMEMultipartForm = "multipart/form-data" MIMEOctetStream = "application/octet-stream" )
MIME types
View Source
const ( // Version of Sola Version = "v2.1.2" // Issuer of InternalError Issuer = "sola" )
View Source
const ( CtxSola = "sola" CtxRequest = "sola.request" CtxResponse = "sola.response" )
ContextKey
View Source
const (
HandleCodePass = iota
)
Custom Handle Code
Variables ¶
View Source
var (
DefaultApp = New()
)
default
View Source
var (
ErrM2H = errors.New("Middleware using next() can't be Handler")
)
error(s)
View Source
var HandlePass = Handler(func(c Context) error { return nil })
HandlePass Handler
View Source
var TplInternalError = template.Must(template. New("SolaInternalError"). Parse(`<html> <head> <meta charset="utf-8"> <title>Sola Internal Error</title> <style> body { margin-top: 50px; } th { color: #4f6b72; border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; border-top: 1px solid #C1DAD7; letter-spacing: 2px; text-transform: uppercase; text-align: left; padding: 6px 6px 6px 12px; } th.top { border-left: 1px solid #C1DAD7; border-right: 1px solid #C1DAD7; } th.spec { border-left: 1px solid #C1DAD7; border-top: 0; color: #797268; } td { border-right: 1px solid #C1DAD7; border-bottom: 1px solid #C1DAD7; background: #fff; font-size: 11px; padding: 6px 6px 6px 12px; color: #4f6b72; } tr:nth-child(odd) td { background: #F5FAFA; color: #797268; } </style> </head> <body> <h1 style="text-align: center;">Sola Internal Error</h1> <table cellspacing="0" style="width: 70%;margin: auto;"> <tr> <th class="top">Meta</th> <th>Value</th> </tr> {{range $i,$e := .}} <tr> <th class="spec">{{$i}}</td> <td>{{$e}}</td> </tr> {{end}} </table> </body> </html>`))
TplInternalError for sola
Functions ¶
func ListenKeepTLS ¶ added in v2.1.2
ListenKeepTLS Serve(s)
Types ¶
type Context ¶
type Context interface { // Set/Get Store() map[string]interface{} Origin() Context Shadow() Context Set(key string, value interface{}) Get(key string) interface{} // API Sola() *Sola SetCookie(cookie *http.Cookie) Request() *http.Request Response() http.ResponseWriter // Writer Blob(code int, contentType string, bs []byte) (err error) HTML(code int, data string) error String(code int, data string) error JSON(code int, data interface{}) error File(f File) (err error) // Reader GetJSON(data interface{}) error // Handler Handle(code int) Handler }
Context for Middleware
type Handler ¶
Handler func
func FromHandler ¶ added in v2.1.2
FromHandler http.Handler
func FromHandlerFunc ¶ added in v2.1.2
func FromHandlerFunc(h func(http.ResponseWriter, *http.Request)) Handler
FromHandlerFunc func(http.ResponseWriter, *http.Request)
func MergeFunc ¶
func MergeFunc(h Handler, middlewares ...Middleware) Handler
MergeFunc for Middlewares & Handler
func OriginContext ¶
OriginContext Middleware change ctx to it's origin
func (Handler) ServeHTTP ¶ added in v2.1.2
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ToHandlerFunc func(http.ResponseWriter, *http.Request)
func (Handler) ToHandlerFunc ¶ added in v2.1.2
func (h Handler) ToHandlerFunc() func(http.ResponseWriter, *http.Request)
ToHandlerFunc func(http.ResponseWriter, *http.Request)
type InternalError ¶ added in v2.1.2
type InternalError struct {
// contains filtered or unexported fields
}
InternalError of sola
func IError ¶ added in v2.1.2
func IError(issuer string, e error) *InternalError
IError Internal Error
func (*InternalError) Handler ¶ added in v2.1.2
func (e *InternalError) Handler() Handler
Handler of InternalError
func (*InternalError) Issuer ¶ added in v2.1.2
func (e *InternalError) Issuer() string
Issuer of InternalError
type Middleware ¶
Middleware func
func (Middleware) Must ¶ added in v2.1.2
func (m Middleware) Must(not Handler) Middleware
Must not nil
Source Files ¶
Click to show internal directories.
Click to hide internal directories.