Documentation ¶
Overview ¶
Copyright 2013 Julien Schmidt. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- Constants
- func Alert(a ...interface{})
- func Alertf(format string, a ...interface{})
- func BytesToString(b *[]byte) string
- func CleanURLPath(urlPath string) string
- func Close()
- func Debug(a ...interface{})
- func Debugf(format string, a ...interface{})
- func Error(a ...interface{})
- func Errorf(format string, a ...interface{})
- func FileSize(s int64) string
- func GetFuncInfo(i interface{}) (funcName, file string, line int)
- func Info(a ...interface{})
- func Infof(format string, a ...interface{})
- func NewGroupLogger(level LogLevel) *groupLogger
- func OpenORCreateFile(fullname string) (*os.File, error)
- func Register(name string, impl ILogger)
- func SetLevel(level LogLevel)
- func SetOutput(loggers map[string]string)
- func StringToBytes(s *string) []byte
- func Warning(a ...interface{})
- func Warningf(format string, a ...interface{})
- type Context
- func (c *Context) AddHandlers(handlers ...Handler)
- func (c *Context) GetAllHandlers() []Handler
- func (c *Context) GetClientIP() string
- func (c *Context) GetCookie(key string) string
- func (c *Context) GetParam(key string) string
- func (c *Context) GetRegURLPath() string
- func (c *Context) GetResponseHeader() http.Header
- func (c *Context) GetResponseWriter() http.ResponseWriter
- func (c *Context) GetSecureCookie(secret, key string) string
- func (c *Context) GetValue(key string) (value interface{}, ok bool)
- func (c *Context) NewError(statusCode int, errs ...error) error
- func (c *Context) Next() (interface{}, error)
- func (c *Context) ParseJSONRequest(target interface{}) error
- func (c *Context) PutValue(key string, value interface{})
- func (c *Context) SetCookie(key string, value string, cookiePath string, maxAge int) error
- func (c *Context) SetSecureCookie(secret, cookieName, cookieValue, cookiePath string, cookieMaxDay int) error
- func (c *Context) UploadFiles(folder string, maxLen int, allowExt string) ([]string, error)
- func (c *Context) WriteHeader(code int)
- type Handler
- type ILogger
- type LogLevel
- type ResponseWriter
- type Router
- type Server
- func (s *Server) AddServerFilter(filters ...Handler)
- func (s *Server) DELETE(urlPath string, handler Handler)
- func (s *Server) GET(urlPath string, handler Handler)
- func (s *Server) HEAD(urlPath string, handler Handler)
- func (s *Server) OPTIONS(urlPath string, handler Handler)
- func (s *Server) PATCH(urlPath string, handler Handler)
- func (s *Server) POST(urlPath string, handler Handler)
- func (s *Server) PUT(urlPath string, handler Handler)
- func (s *Server) Root(rootPath string, handlers ...Handler) *groupRoutes
- func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (s *Server) Start(addr string) error
- func (s *Server) StartTLS(addr, certFile, keyFile string) error
Constants ¶
const Version = "slimgo v1.0.0"
Variables ¶
This section is empty.
Functions ¶
func BytesToString ¶
func CleanURLPath ¶
func GetFuncInfo ¶
GetFuncInfo 通过反射获取方法信息
func NewGroupLogger ¶
func NewGroupLogger(level LogLevel) *groupLogger
func OpenORCreateFile ¶
open or create log file.
func StringToBytes ¶
Types ¶
type Context ¶
Context server context
func (*Context) AddHandlers ¶
func (*Context) GetAllHandlers ¶
func (*Context) GetClientIP ¶
GetClientIP return client IP. if in proxy, return first proxy id; if error ,return 127.0.0.1;
func (*Context) GetRegURLPath ¶
func (*Context) GetResponseHeader ¶
func (*Context) GetResponseWriter ¶
func (c *Context) GetResponseWriter() http.ResponseWriter
func (*Context) GetSecureCookie ¶
Get secure cookie.
func (*Context) ParseJSONRequest ¶
ParseJSONRequest parse json request
func (*Context) SetSecureCookie ¶
func (c *Context) SetSecureCookie(secret, cookieName, cookieValue, cookiePath string, cookieMaxDay int) error
Set secure cookie.
func (*Context) UploadFiles ¶
文件上传 floder 文件所要保存的目录 maxLen 文件最大长度 允许的扩展名[正则表达式],例如:(.png|.jpeg|.jpg|.gif)
func (*Context) WriteHeader ¶
type ILogger ¶
type ILogger interface { Init(config string) error Message(message string, level LogLevel) error Flush() Close() }
Logger interface
type LogLevel ¶
type LogLevel uint8
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter Written() bool }
func NewResponseWriter ¶
func NewResponseWriter(res http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type Router ¶
type Router struct { // Enables automatic redirection if the current route can't be matched but a // handler for the path with (without) the trailing slash exists. // For example if /foo/ is requested but a route only exists for /foo, the // client is redirected to /foo with http status code 301 for GET requests // and 307 for all other request methods. RedirectTrailingSlash bool // If enabled, the router tries to fix the current request path, if no // handle is registered for it. // First superfluous path elements like ../ or // are removed. // Afterwards the router does a case-insensitive lookup of the cleaned path. // If a handle can be found for this route, the router makes a redirection // to the corrected path with status code 301 for GET requests and 307 for // all other request methods. // For example /FOO and /..//Foo could be redirected to /foo. // RedirectTrailingSlash is independent of this option. RedirectFixedPath bool // contains filtered or unexported fields }
Router server router
func (*Router) Register ¶
Register registers a new request handle with the given path and method.
For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
type Server ¶
type Server struct { // NotFound Configurable http.Handler which is called when no matching route is // found. If it is not set, http.NotFound is used. NotFound Handler // MethodNotAllowed Configurable http.Handler which is called when a request // cannot be routed and HandleMethodNotAllowed is true. // If it is not set, http.Error with http.StatusMethodNotAllowed is used. // The "Allow" header with allowed request methods is set before the handler // is called. MethodNotAllowed Handler // contains filtered or unexported fields }
Server http server handler
func (*Server) AddServerFilter ¶
AddFilter 注册全局过滤器