Documentation ¶
Index ¶
- Constants
- func ClearPath(pathStr string) string
- func EnsurePrefix(s, prefix string) string
- func EnsureSuffix(s, suffix string) string
- func ExeDir() string
- func WorkingDir() string
- type Area
- type BufResult
- func (b *BufResult) AddHeader(key, value string)
- func (b *BufResult) ExecResult(w http.ResponseWriter, r *http.Request)
- func (b *BufResult) ReadFrom(r io.Reader) (n int64, err error)
- func (b *BufResult) Write(p []byte) (n int, err error)
- func (b *BufResult) WriteByte(c byte) error
- func (b *BufResult) WriteRune(r rune) (n int, err error)
- func (b *BufResult) WriteString(s string) (n int, err error)
- type ErrHandler
- type FileResult
- type HttpCtx
- func (ctx *HttpCtx) CtxId() uint64
- func (ctx *HttpCtx) End()
- func (ctx *HttpCtx) FileResult(path string, contentType string) Result
- func (ctx *HttpCtx) FormValue(key string) string
- func (ctx *HttpCtx) GetCtxItem(key string) interface{}
- func (ctx *HttpCtx) JsonResult(data interface{}) Result
- func (ctx *HttpCtx) JsonpResult(data interface{}, callback string) Result
- func (ctx *HttpCtx) MapContentPath(urlPath string) string
- func (ctx *HttpCtx) MapRootPath(path string) string
- func (ctx *HttpCtx) PostFile(formName string) *UploadFile
- func (ctx *HttpCtx) QueryStr(key string) string
- func (ctx *HttpCtx) Redirect(urlStr string, permanent bool)
- func (ctx *HttpCtx) RedirectResult(urlStr string, permanent bool) Result
- func (ctx *HttpCtx) RemoveCtxItem(key string)
- func (ctx *HttpCtx) Request() *http.Request
- func (ctx *HttpCtx) Response() http.ResponseWriter
- func (ctx *HttpCtx) RouteVar(key string) string
- func (ctx *HttpCtx) SetCtxItem(key string, data interface{})
- func (ctx *HttpCtx) TextResult(content, contentType string) Result
- func (ctx *HttpCtx) ViewResult(viewName string, data interface{}) Result
- func (ctx *HttpCtx) XmlResult(data interface{}) Result
- type RedirectResult
- type Result
- type RouteConnect
- type RouteCopy
- type RouteDelete
- type RouteFilter
- type RouteFunc
- type RouteGet
- type RouteHead
- type RouteLock
- type RouteMkcol
- type RouteMove
- type RouteOpt
- type RouteOptions
- type RoutePatch
- type RoutePost
- type RouteProcessor
- type RoutePropFind
- type RoutePropPatch
- type RoutePut
- type RouteTrace
- type RouteUnlock
- type Server
- func (s *Server) AddRouteFunc(name string, fun RouteFunc)
- func (s *Server) ExtendView(name string, f interface{})
- func (s *Server) GetArea(pathPrefix string) *Area
- func (s *Server) GetVar(key string) interface{}
- func (s *Server) GetVarBool(key string, defaultValue bool) bool
- func (s *Server) GetVarFloat(key string, defaultValue float64) float64
- func (s *Server) GetVarInt(key string, defaultValue int) int
- func (s *Server) GetVarStr(key string, defaultValue string) string
- func (s *Server) Handle400(h http.HandlerFunc)
- func (s *Server) Handle403(h http.HandlerFunc)
- func (s *Server) Handle404(h http.HandlerFunc)
- func (s *Server) Handle500(h func(http.ResponseWriter, *http.Request, interface{}))
- func (s *Server) HijackRequest(pathPrefix string, h func(*HttpCtx))
- func (s *Server) MapContentPath(virtualPath string) string
- func (s *Server) MapRootPath(virtualPath string) string
- func (s *Server) OnStart(h func())
- func (s *Server) Route(routePath string, handler interface{})
- func (s *Server) Run()
- func (s *Server) RunTLS(certFile, keyFile string)
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetVar(key string, v interface{})
- type UploadFile
- type ViewEngine
Constants ¶
const Version = "1.0"
Variables ¶
This section is empty.
Functions ¶
func EnsurePrefix ¶
EnsurePrefix ensure that the string s must has the prefix
func EnsureSuffix ¶
EnsureSuffix ensure that the string s must has suffix
Types ¶
type Area ¶
type Area struct {
// contains filtered or unexported fields
}
Area implement mego area
func (*Area) ExtendView ¶
ExtendView add view function to the view engine of the current area
func (*Area) HijackRequest ¶
HijackRequest hijack the area dynamic request that starts with pathPrefix
type BufResult ¶
type BufResult struct { ContentType string Encoding string StatusCode int // contains filtered or unexported fields }
BufResult the buffered result
func NewBufResult ¶
NewBufResult create a new buffer result with default value buf
func (*BufResult) ExecResult ¶
func (b *BufResult) ExecResult(w http.ResponseWriter, r *http.Request)
ExecResult write the data in the result buffer to the response writer
type ErrHandler ¶
type ErrHandler func(http.ResponseWriter, *http.Request, interface{})
ErrHandler define the internal s error handler func
type FileResult ¶
FileResult the file result
func (*FileResult) ExecResult ¶
func (fr *FileResult) ExecResult(w http.ResponseWriter, r *http.Request)
ExecResult execute the result
type HttpCtx ¶
type HttpCtx struct { Server *Server // contains filtered or unexported fields }
HttpCtx the mego http context struct
func (*HttpCtx) End ¶
func (ctx *HttpCtx) End()
End end the mego context and stop the rest request function
func (*HttpCtx) FileResult ¶
FileResult generate the mego result as file result
func (*HttpCtx) FormValue ¶
FormValue get the form value from request. It's the same as ctx.Request().FormValue(key)
func (*HttpCtx) GetCtxItem ¶
GetCtxItem get the context data from mego context by key
func (*HttpCtx) JsonResult ¶
JsonResult generate the mego result as JSON string
func (*HttpCtx) JsonpResult ¶
JsonpResult generate the mego result as jsonp string
func (*HttpCtx) MapContentPath ¶
MapContentPath Returns the physical file path that corresponds to the specified virtual path.
func (*HttpCtx) MapRootPath ¶
MapRootPath Returns the physical file path that corresponds to the specified virtual path.
func (*HttpCtx) PostFile ¶
func (ctx *HttpCtx) PostFile(formName string) *UploadFile
PostFile get the post file info
func (*HttpCtx) RedirectResult ¶
Redirect get the redirect result. if the value of 'permanent' is true , the status code is 301, else the status code is 302
func (*HttpCtx) RemoveCtxItem ¶
RemoveCtxItem delete context item from mego context by key
func (*HttpCtx) Response ¶
func (ctx *HttpCtx) Response() http.ResponseWriter
Response get the mego response
func (*HttpCtx) SetCtxItem ¶
SetCtxItem add context data to mego context
func (*HttpCtx) TextResult ¶
TextResult generate the mego result as plain text
func (*HttpCtx) ViewResult ¶
ViewResult find the view by view name, execute the view template and get the result
type RedirectResult ¶
RedirectResult the redirect result
func (*RedirectResult) ExecResult ¶
func (rr *RedirectResult) ExecResult(w http.ResponseWriter, r *http.Request)
ExecResult execute the redirect result
type Result ¶
type Result interface {
ExecResult(w http.ResponseWriter, r *http.Request)
}
Result the request result interface
type RouteConnect ¶
type RouteConnect interface {
Connect(ctx *HttpCtx) interface{}
}
type RouteCopy ¶
type RouteCopy interface {
Copy(ctx *HttpCtx) interface{}
}
RouteCopy WebDAV http method 'COPY' processing interface
type RouteDelete ¶
type RouteDelete interface {
Delete(ctx *HttpCtx) interface{}
}
type RouteFilter ¶
type RouteFilter interface {
Filter(ctx *HttpCtx)
}
type RouteLock ¶
type RouteLock interface {
Lock(ctx *HttpCtx) interface{}
}
RouteLock WebDAV http method 'LOCK' processing interface
type RouteMkcol ¶
type RouteMkcol interface {
Mkcol(ctx *HttpCtx) interface{}
}
RouteMkcol WebDAV http method 'MKCOL' processing interface
type RouteMove ¶
type RouteMove interface {
Move(ctx *HttpCtx) interface{}
}
RouteMove WebDAV http method 'MOVE' processing interface
type RouteOptions ¶
type RouteOptions interface {
Options(ctx *HttpCtx) interface{}
}
type RoutePatch ¶
type RoutePatch interface {
Patch(ctx *HttpCtx) interface{}
}
type RouteProcessor ¶
type RouteProcessor interface {
ProcessRequest(ctx *HttpCtx) interface{}
}
type RoutePropFind ¶
type RoutePropFind interface {
PropFind(ctx *HttpCtx) interface{}
}
RoutePropFind WebDAV http method 'PROPFIND' processing interface
type RoutePropPatch ¶
type RoutePropPatch interface {
PropPatch(ctx *HttpCtx) interface{}
}
RoutePropPatch WebDAV http method 'PROPPATCH' processing interface
type RouteTrace ¶
type RouteTrace interface {
Trace(ctx *HttpCtx) interface{}
}
type RouteUnlock ¶
type RouteUnlock interface {
Unlock(ctx *HttpCtx) interface{}
}
RouteUnlock WebDAV http method 'UNLOCK' processing interface
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
NewServer create a new server
webRoot: the root of this web server. and the content root is '${webRoot}/www'
addr: the address the server is listen on
func (*Server) AddRouteFunc ¶
AddRouteFunc add route validation func
func (*Server) ExtendView ¶
ExtendView extend the view engine with func f
func (*Server) Handle400 ¶
func (s *Server) Handle400(h http.HandlerFunc)
Handle404 set custom error handler for status code 404
func (*Server) Handle403 ¶
func (s *Server) Handle403(h http.HandlerFunc)
Handle404 set custom error handler for status code 404
func (*Server) Handle404 ¶
func (s *Server) Handle404(h http.HandlerFunc)
Handle404 set custom error handler for status code 404
func (*Server) Handle500 ¶
func (s *Server) Handle500(h func(http.ResponseWriter, *http.Request, interface{}))
Handle500 set custom error handler for status code 500
func (*Server) HijackRequest ¶
Hijack hijack the dynamic request that starts with pathPrefix
func (*Server) MapContentPath ¶
MapContentPath Returns the physical file path that corresponds to the specified virtual path. @param virtualPath: the virtual path starts with @return the absolute file path
func (*Server) MapRootPath ¶
MapRootPath Returns the physical file path that corresponds to the specified virtual path. @param virtualPath: the virtual path starts with @return the absolute file path
func (*Server) OnStart ¶
func (s *Server) OnStart(h func())
OnStart attach an event handler to the s start event
type UploadFile ¶
type UploadFile struct { FileName string Size int64 Error error File multipart.File Header *multipart.FileHeader }
UploadFile the uploaded file struct
func (*UploadFile) Save ¶
func (file *UploadFile) Save(path string) error
Save save the posted file data as a file.
func (*UploadFile) SaveAndClose ¶
func (file *UploadFile) SaveAndClose(path string) error
SaveAndClose save the posted file as a file and then close the posted data stream
type ViewEngine ¶
type ViewEngine struct {
// contains filtered or unexported fields
}
ViewEngine the mego view engine struct
func NewViewEngine ¶
func NewViewEngine(viewDir string) *ViewEngine
NewViewEngine create a new view engine in ViewDir with file extension '.gohtml'
func (*ViewEngine) ExtendView ¶
func (e *ViewEngine) ExtendView(name string, viewFunc interface{})
ExtendView extend the view helper functions with 'name' and 'viewFunc'
func (*ViewEngine) Render ¶
func (e *ViewEngine) Render(viewName string, data interface{}) Result
Render render the view 'viewName' with 'data' and get the view result