Documentation ¶
Overview ¶
Package ghttp provides powerful http server and simple client implements.
Index ¶
- Constants
- func BuildParams(params interface{}, noUrlEncode ...bool) (encodedParamStr string)
- func ConnectBytes(url string, data ...interface{}) []byte
- func ConnectContent(url string, data ...interface{}) string
- func DeleteBytes(url string, data ...interface{}) []byte
- func DeleteContent(url string, data ...interface{}) string
- func GetBytes(url string, data ...interface{}) []byte
- func GetContent(url string, data ...interface{}) string
- func HeadBytes(url string, data ...interface{}) []byte
- func HeadContent(url string, data ...interface{}) string
- func IsExitError(err interface{}) bool
- func OptionsBytes(url string, data ...interface{}) []byte
- func OptionsContent(url string, data ...interface{}) string
- func PatchBytes(url string, data ...interface{}) []byte
- func PatchContent(url string, data ...interface{}) string
- func PostBytes(url string, data ...interface{}) []byte
- func PostContent(url string, data ...interface{}) string
- func PutBytes(url string, data ...interface{}) []byte
- func PutContent(url string, data ...interface{}) string
- func RequestBytes(method string, url string, data ...interface{}) []byte
- func RequestContent(method string, url string, data ...interface{}) string
- func RestartAllServer(newExeFilePath ...string) error
- func SetGraceful(enabled bool)
- func ShutdownAllServer() error
- func TraceBytes(url string, data ...interface{}) []byte
- func TraceContent(url string, data ...interface{}) string
- func Wait()
- type CORSOptions
- type Client
- func (c *Client) BasicAuth(user, pass string) *Client
- func (c *Client) Clone() *Client
- func (c *Client) Connect(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) ConnectBytes(url string, data ...interface{}) []byte
- func (c *Client) ConnectContent(url string, data ...interface{}) string
- func (c *Client) ContentJson() *Client
- func (c *Client) ContentType(contentType string) *Client
- func (c *Client) ContentXml() *Client
- func (c *Client) Cookie(m map[string]string) *Client
- func (c *Client) Ctx(ctx context.Context) *Client
- func (c *Client) Delete(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) DeleteBytes(url string, data ...interface{}) []byte
- func (c *Client) DeleteContent(url string, data ...interface{}) string
- func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *ClientResponse, err error)
- func (c *Client) Get(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) GetBytes(url string, data ...interface{}) []byte
- func (c *Client) GetContent(url string, data ...interface{}) string
- func (c *Client) Head(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) HeadBytes(url string, data ...interface{}) []byte
- func (c *Client) HeadContent(url string, data ...interface{}) string
- func (c *Client) Header(m map[string]string) *Client
- func (c *Client) HeaderRaw(headers string) *Client
- func (c *Client) Options(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) OptionsBytes(url string, data ...interface{}) []byte
- func (c *Client) OptionsContent(url string, data ...interface{}) string
- func (c *Client) Patch(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) PatchBytes(url string, data ...interface{}) []byte
- func (c *Client) PatchContent(url string, data ...interface{}) string
- func (c *Client) Post(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) PostBytes(url string, data ...interface{}) []byte
- func (c *Client) PostContent(url string, data ...interface{}) string
- func (c *Client) Prefix(prefix string) *Client
- func (c *Client) Proxy(proxyURL string) *Client
- func (c *Client) Put(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) PutBytes(url string, data ...interface{}) []byte
- func (c *Client) PutContent(url string, data ...interface{}) string
- func (c *Client) RequestBytes(method string, url string, data ...interface{}) []byte
- func (c *Client) RequestContent(method string, url string, data ...interface{}) string
- func (c *Client) Retry(retryCount int, retryInterval time.Duration) *Client
- func (c *Client) SetBasicAuth(user, pass string) *Client
- func (c *Client) SetBrowserMode(enabled bool) *Client
- func (c *Client) SetContentType(contentType string) *Client
- func (c *Client) SetCookie(key, value string) *Client
- func (c *Client) SetCookieMap(m map[string]string) *Client
- func (c *Client) SetCtx(ctx context.Context) *Client
- func (c *Client) SetHeader(key, value string) *Client
- func (c *Client) SetHeaderMap(m map[string]string) *Client
- func (c *Client) SetHeaderRaw(headers string) *Client
- func (c *Client) SetPrefix(prefix string) *Client
- func (c *Client) SetProxy(proxyURL string)
- func (c *Client) SetRedirectLimit(redirectLimit int) *Client
- func (c *Client) SetRetry(retryCount int, retryInterval time.Duration) *Client
- func (c *Client) SetTimeout(t time.Duration) *Client
- func (c *Client) Timeout(t time.Duration) *Client
- func (c *Client) Trace(url string, data ...interface{}) (*ClientResponse, error)
- func (c *Client) TraceBytes(url string, data ...interface{}) []byte
- func (c *Client) TraceContent(url string, data ...interface{}) string
- type ClientResponse
- func Connect(url string, data ...interface{}) (*ClientResponse, error)
- func Delete(url string, data ...interface{}) (*ClientResponse, error)
- func DoRequest(method, url string, data ...interface{}) (*ClientResponse, error)
- func Get(url string, data ...interface{}) (*ClientResponse, error)
- func Head(url string, data ...interface{}) (*ClientResponse, error)
- func Options(url string, data ...interface{}) (*ClientResponse, error)
- func Patch(url string, data ...interface{}) (*ClientResponse, error)
- func Post(url string, data ...interface{}) (*ClientResponse, error)
- func Put(url string, data ...interface{}) (*ClientResponse, error)
- func Trace(url string, data ...interface{}) (*ClientResponse, error)
- func (r *ClientResponse) Close() error
- func (r *ClientResponse) GetCookie(key string) string
- func (r *ClientResponse) GetCookieMap() map[string]string
- func (r *ClientResponse) Raw() string
- func (r *ClientResponse) RawDump()
- func (r *ClientResponse) RawRequest() string
- func (r *ClientResponse) RawResponse() string
- func (r *ClientResponse) ReadAll() []byte
- func (r *ClientResponse) ReadAllString() string
- type Controller
- type Cookie
- func (c *Cookie) Contains(key string) bool
- func (c *Cookie) Flush()
- func (c *Cookie) Get(key string, def ...string) string
- func (c *Cookie) GetSessionId() string
- func (c *Cookie) Map() map[string]string
- func (c *Cookie) Remove(key string)
- func (c *Cookie) RemoveCookie(key, domain, path string)
- func (c *Cookie) Set(key, value string)
- func (c *Cookie) SetCookie(key, value, domain, path string, maxAge time.Duration, httpOnly ...bool)
- func (c *Cookie) SetSessionId(id string)
- type CookieItem
- type Domain
- func (d *Domain) BindController(pattern string, c Controller, methods ...string)
- func (d *Domain) BindControllerMethod(pattern string, c Controller, method string)
- func (d *Domain) BindControllerRest(pattern string, c Controller)
- func (d *Domain) BindHandler(pattern string, handler HandlerFunc)
- func (d *Domain) BindHookHandler(pattern string, hook string, handler HandlerFunc)
- func (d *Domain) BindHookHandlerByMap(pattern string, hookmap map[string]HandlerFunc)
- func (d *Domain) BindMiddleware(pattern string, handlers ...HandlerFunc)
- func (d *Domain) BindMiddlewareDefault(handlers ...HandlerFunc)
- func (d *Domain) BindObject(pattern string, obj interface{}, methods ...string)
- func (d *Domain) BindObjectMethod(pattern string, obj interface{}, method string)
- func (d *Domain) BindObjectRest(pattern string, obj interface{})
- func (d *Domain) BindStatusHandler(status int, handler HandlerFunc)
- func (d *Domain) BindStatusHandlerByMap(handlerMap map[int]HandlerFunc)
- func (d *Domain) Group(prefix string, groups ...func(group *RouterGroup)) *RouterGroup
- func (d *Domain) Use(handlers ...HandlerFunc)
- type GroupItem
- type HandlerFunc
- type Middleware
- type Plugin
- type Request
- func (r *Request) Assign(key string, value interface{})
- func (r *Request) Assigns(data gview.Params)
- func (r *Request) BasicAuth(user, pass string, tips ...string) bool
- func (r *Request) Context() context.Context
- func (r *Request) Exit()
- func (r *Request) ExitAll()
- func (r *Request) ExitHook()
- func (r *Request) Get(key string, def ...interface{}) interface{}
- func (r *Request) GetArray(key string, def ...interface{}) []string
- func (r *Request) GetBody() []byte
- func (r *Request) GetBodyString() string
- func (r *Request) GetBool(key string, def ...interface{}) bool
- func (r *Request) GetClientIp() string
- func (r *Request) GetCtx() context.Context
- func (r *Request) GetCtxVar(key interface{}, def ...interface{}) *gvar.Var
- func (r *Request) GetError() error
- func (r *Request) GetFloat32(key string, def ...interface{}) float32
- func (r *Request) GetFloat64(key string, def ...interface{}) float64
- func (r *Request) GetFloats(key string, def ...interface{}) []float64
- func (r *Request) GetForm(key string, def ...interface{}) interface{}
- func (r *Request) GetFormArray(key string, def ...interface{}) []string
- func (r *Request) GetFormBool(key string, def ...interface{}) bool
- func (r *Request) GetFormFloat32(key string, def ...interface{}) float32
- func (r *Request) GetFormFloat64(key string, def ...interface{}) float64
- func (r *Request) GetFormFloats(key string, def ...interface{}) []float64
- func (r *Request) GetFormInt(key string, def ...interface{}) int
- func (r *Request) GetFormInt32(key string, def ...interface{}) int32
- func (r *Request) GetFormInt64(key string, def ...interface{}) int64
- func (r *Request) GetFormInterfaces(key string, def ...interface{}) []interface{}
- func (r *Request) GetFormInts(key string, def ...interface{}) []int
- func (r *Request) GetFormMap(kvMap ...map[string]interface{}) map[string]interface{}
- func (r *Request) GetFormMapStrStr(kvMap ...map[string]interface{}) map[string]string
- func (r *Request) GetFormMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var
- func (r *Request) GetFormString(key string, def ...interface{}) string
- func (r *Request) GetFormStrings(key string, def ...interface{}) []string
- func (r *Request) GetFormStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetFormToStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetFormUint(key string, def ...interface{}) uint
- func (r *Request) GetFormUint32(key string, def ...interface{}) uint32
- func (r *Request) GetFormUint64(key string, def ...interface{}) uint64
- func (r *Request) GetFormVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetHost() string
- func (r *Request) GetInt(key string, def ...interface{}) int
- func (r *Request) GetInt32(key string, def ...interface{}) int32
- func (r *Request) GetInt64(key string, def ...interface{}) int64
- func (r *Request) GetInterfaces(key string, def ...interface{}) []interface{}
- func (r *Request) GetInts(key string, def ...interface{}) []int
- func (r *Request) GetJson() (*gjson.Json, error)
- func (r *Request) GetMap(def ...map[string]interface{}) map[string]interface{}
- func (r *Request) GetMapStrStr(def ...map[string]interface{}) map[string]string
- func (r *Request) GetMultipartFiles(name string) []*multipart.FileHeader
- func (r *Request) GetMultipartForm() *multipart.Form
- func (r *Request) GetPage(totalSize, pageSize int) *gpage.Page
- func (r *Request) GetParam(key string, def ...interface{}) interface{}
- func (r *Request) GetParamVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetPost(key string, def ...interface{}) interface{}
- func (r *Request) GetPostArray(key string, def ...interface{}) []string
- func (r *Request) GetPostBool(key string, def ...interface{}) bool
- func (r *Request) GetPostFloat32(key string, def ...interface{}) float32
- func (r *Request) GetPostFloat64(key string, def ...interface{}) float64
- func (r *Request) GetPostFloats(key string, def ...interface{}) []float64
- func (r *Request) GetPostInt(key string, def ...interface{}) int
- func (r *Request) GetPostInt32(key string, def ...interface{}) int32
- func (r *Request) GetPostInt64(key string, def ...interface{}) int64
- func (r *Request) GetPostInterfaces(key string, def ...interface{}) []interface{}
- func (r *Request) GetPostInts(key string, def ...interface{}) []int
- func (r *Request) GetPostMap(kvMap ...map[string]interface{}) map[string]interface{}
- func (r *Request) GetPostMapStrStr(kvMap ...map[string]interface{}) map[string]string
- func (r *Request) GetPostMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var
- func (r *Request) GetPostString(key string, def ...interface{}) string
- func (r *Request) GetPostStrings(key string, def ...interface{}) []string
- func (r *Request) GetPostStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetPostToStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetPostUint(key string, def ...interface{}) uint
- func (r *Request) GetPostUint32(key string, def ...interface{}) uint32
- func (r *Request) GetPostUint64(key string, def ...interface{}) uint64
- func (r *Request) GetPostVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetQuery(key string, def ...interface{}) interface{}
- func (r *Request) GetQueryArray(key string, def ...interface{}) []string
- func (r *Request) GetQueryBool(key string, def ...interface{}) bool
- func (r *Request) GetQueryFloat32(key string, def ...interface{}) float32
- func (r *Request) GetQueryFloat64(key string, def ...interface{}) float64
- func (r *Request) GetQueryFloats(key string, def ...interface{}) []float64
- func (r *Request) GetQueryInt(key string, def ...interface{}) int
- func (r *Request) GetQueryInt32(key string, def ...interface{}) int32
- func (r *Request) GetQueryInt64(key string, def ...interface{}) int64
- func (r *Request) GetQueryInterfaces(key string, def ...interface{}) []interface{}
- func (r *Request) GetQueryInts(key string, def ...interface{}) []int
- func (r *Request) GetQueryMap(kvMap ...map[string]interface{}) map[string]interface{}
- func (r *Request) GetQueryMapStrStr(kvMap ...map[string]interface{}) map[string]string
- func (r *Request) GetQueryMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var
- func (r *Request) GetQueryString(key string, def ...interface{}) string
- func (r *Request) GetQueryStrings(key string, def ...interface{}) []string
- func (r *Request) GetQueryStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetQueryToStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetQueryUint(key string, def ...interface{}) uint
- func (r *Request) GetQueryUint32(key string, def ...interface{}) uint32
- func (r *Request) GetQueryUint64(key string, def ...interface{}) uint64
- func (r *Request) GetQueryVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetRaw() []byte
- func (r *Request) GetRawString() string
- func (r *Request) GetReferer() string
- func (r *Request) GetRequest(key string, def ...interface{}) interface{}
- func (r *Request) GetRequestArray(key string, def ...interface{}) []string
- func (r *Request) GetRequestBool(key string, def ...interface{}) bool
- func (r *Request) GetRequestFloat32(key string, def ...interface{}) float32
- func (r *Request) GetRequestFloat64(key string, def ...interface{}) float64
- func (r *Request) GetRequestFloats(key string, def ...interface{}) []float64
- func (r *Request) GetRequestInt(key string, def ...interface{}) int
- func (r *Request) GetRequestInt32(key string, def ...interface{}) int32
- func (r *Request) GetRequestInt64(key string, def ...interface{}) int64
- func (r *Request) GetRequestInterfaces(key string, def ...interface{}) []interface{}
- func (r *Request) GetRequestInts(key string, def ...interface{}) []int
- func (r *Request) GetRequestMap(kvMap ...map[string]interface{}) map[string]interface{}
- func (r *Request) GetRequestMapStrStr(kvMap ...map[string]interface{}) map[string]string
- func (r *Request) GetRequestMapStrVar(kvMap ...map[string]interface{}) map[string]*gvar.Var
- func (r *Request) GetRequestString(key string, def ...interface{}) string
- func (r *Request) GetRequestStrings(key string, def ...interface{}) []string
- func (r *Request) GetRequestStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetRequestToStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetRequestUint(key string, def ...interface{}) uint
- func (r *Request) GetRequestUint32(key string, def ...interface{}) uint32
- func (r *Request) GetRequestUint64(key string, def ...interface{}) uint64
- func (r *Request) GetRequestVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetRouterString(key string, def ...interface{}) string
- func (r *Request) GetRouterValue(key string, def ...interface{}) interface{}
- func (r *Request) GetRouterVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetSessionId() string
- func (r *Request) GetString(key string, def ...interface{}) string
- func (r *Request) GetStrings(key string, def ...interface{}) []string
- func (r *Request) GetStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetToStruct(pointer interface{}, mapping ...map[string]string) error
- func (r *Request) GetUint(key string, def ...interface{}) uint
- func (r *Request) GetUint32(key string, def ...interface{}) uint32
- func (r *Request) GetUint64(key string, def ...interface{}) uint64
- func (r *Request) GetUploadFile(name string) *UploadFile
- func (r *Request) GetUploadFiles(name string) UploadFiles
- func (r *Request) GetUrl() string
- func (r *Request) GetVar(key string, def ...interface{}) *gvar.Var
- func (r *Request) GetView() *gview.View
- func (r *Request) IsAjaxRequest() bool
- func (r *Request) IsExited() bool
- func (r *Request) IsFileRequest() bool
- func (r *Request) Parse(pointer interface{}) error
- func (r *Request) SetCtxVar(key interface{}, value interface{})
- func (r *Request) SetForm(key string, value interface{})
- func (r *Request) SetParam(key string, value interface{})
- func (r *Request) SetQuery(key string, value interface{})
- func (r *Request) SetView(view *gview.View)
- func (r *Request) WebSocket() (*WebSocket, error)
- type Response
- func (r *Response) Buffer() []byte
- func (r *Response) BufferLength() int
- func (r *Response) BufferString() string
- func (r *Response) CORS(options CORSOptions)
- func (r *Response) CORSAllowedOrigin(options CORSOptions) bool
- func (r *Response) CORSDefault()
- func (r *Response) ClearBuffer()
- func (r *Response) DefaultCORSOptions() CORSOptions
- func (r *Response) Flush()
- func (r *Response) ParseTpl(tpl string, params ...gview.Params) (string, error)
- func (r *Response) ParseTplContent(content string, params ...gview.Params) (string, error)
- func (r *Response) ParseTplDefault(params ...gview.Params) (string, error)
- func (r *Response) RedirectBack(code ...int)
- func (r *Response) RedirectTo(location string, code ...int)
- func (r *Response) ServeFile(path string, allowIndex ...bool)
- func (r *Response) ServeFileDownload(path string, name ...string)
- func (r *Response) SetBuffer(data []byte)
- func (r *Response) Write(content ...interface{})
- func (r *Response) WriteExit(content ...interface{})
- func (r *Response) WriteJson(content interface{}) error
- func (r *Response) WriteJsonExit(content interface{}) error
- func (r *Response) WriteJsonP(content interface{}) error
- func (r *Response) WriteJsonPExit(content interface{}) error
- func (r *Response) WriteOver(content ...interface{})
- func (r *Response) WriteOverExit(content ...interface{})
- func (r *Response) WriteStatus(status int, content ...interface{})
- func (r *Response) WriteStatusExit(status int, content ...interface{})
- func (r *Response) WriteTpl(tpl string, params ...gview.Params) error
- func (r *Response) WriteTplContent(content string, params ...gview.Params) error
- func (r *Response) WriteTplDefault(params ...gview.Params) error
- func (r *Response) WriteXml(content interface{}, rootTag ...string) error
- func (r *Response) WriteXmlExit(content interface{}, rootTag ...string) error
- func (r *Response) Writef(format string, params ...interface{})
- func (r *Response) WritefExit(format string, params ...interface{})
- func (r *Response) Writefln(format string, params ...interface{})
- func (r *Response) WriteflnExit(format string, params ...interface{})
- func (r *Response) Writeln(content ...interface{})
- func (r *Response) WritelnExit(content ...interface{})
- type ResponseWriter
- func (w *ResponseWriter) Flush()
- func (w *ResponseWriter) Header() http.Header
- func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *ResponseWriter) RawWriter() http.ResponseWriter
- func (w *ResponseWriter) Write(data []byte) (int, error)
- func (w *ResponseWriter) WriteHeader(status int)
- type Router
- type RouterGroup
- func (g *RouterGroup) ALL(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) Bind(items []GroupItem) *RouterGroup
- func (g *RouterGroup) CONNECT(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) Clone() *RouterGroup
- func (g *RouterGroup) DELETE(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) GET(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) Group(prefix string, groups ...func(group *RouterGroup)) *RouterGroup
- func (g *RouterGroup) HEAD(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) Hook(pattern string, hook string, handler HandlerFunc) *RouterGroup
- func (g *RouterGroup) Middleware(handlers ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) OPTIONS(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) PATCH(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) POST(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) PUT(pattern string, object interface{}, params ...interface{}) *RouterGroup
- func (g *RouterGroup) REST(pattern string, object interface{}) *RouterGroup
- func (g *RouterGroup) TRACE(pattern string, object interface{}, params ...interface{}) *RouterGroup
- type RouterItem
- type Server
- func (s *Server) AddSearchPath(path string)
- func (s *Server) AddStaticPath(prefix string, path string)
- func (s *Server) BindController(pattern string, controller Controller, method ...string)
- func (s *Server) BindControllerMethod(pattern string, controller Controller, method string)
- func (s *Server) BindControllerRest(pattern string, controller Controller)
- func (s *Server) BindHandler(pattern string, handler HandlerFunc)
- func (s *Server) BindHookHandler(pattern string, hook string, handler HandlerFunc)
- func (s *Server) BindHookHandlerByMap(pattern string, hookMap map[string]HandlerFunc)
- func (s *Server) BindMiddleware(pattern string, handlers ...HandlerFunc)
- func (s *Server) BindMiddlewareDefault(handlers ...HandlerFunc)
- func (s *Server) BindObject(pattern string, object interface{}, method ...string)
- func (s *Server) BindObjectMethod(pattern string, object interface{}, method string)
- func (s *Server) BindObjectRest(pattern string, object interface{})
- func (s *Server) BindStatusHandler(status int, handler HandlerFunc)
- func (s *Server) BindStatusHandlerByMap(handlerMap map[int]HandlerFunc)
- func (s *Server) Domain(domains string) *Domain
- func (s *Server) EnableAdmin(pattern ...string)
- func (s *Server) EnableHTTPS(certFile, keyFile string, tlsConfig ...*tls.Config)
- func (s *Server) EnablePProf(pattern ...string)
- func (s *Server) GetCookieDomain() string
- func (s *Server) GetCookieMaxAge() time.Duration
- func (s *Server) GetCookiePath() string
- func (s *Server) GetIndexFiles() []string
- func (s *Server) GetLogPath() string
- func (s *Server) GetName() string
- func (s *Server) GetRouterArray() []RouterItem
- func (s *Server) GetSessionIdName() string
- func (s *Server) GetSessionMaxAge() time.Duration
- func (s *Server) Group(prefix string, groups ...func(group *RouterGroup)) *RouterGroup
- func (s *Server) Handler() http.Handler
- func (s *Server) IsAccessLogEnabled() bool
- func (s *Server) IsErrorLogEnabled() bool
- func (s *Server) Logger() *glog.Logger
- func (s *Server) Plugin(plugin ...Plugin)
- func (s *Server) Run()
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Server) SetAccessLogEnabled(enabled bool)
- func (s *Server) SetAddr(address string)
- func (s *Server) SetClientMaxBodySize(maxSize int64)
- func (s *Server) SetConfig(c ServerConfig) error
- func (s *Server) SetConfigWithMap(m map[string]interface{}) error
- func (s *Server) SetCookieDomain(domain string)
- func (s *Server) SetCookieMaxAge(ttl time.Duration)
- func (s *Server) SetCookiePath(path string)
- func (s *Server) SetDumpRouterMap(enabled bool)
- func (s *Server) SetErrorLogEnabled(enabled bool)
- func (s *Server) SetErrorStack(enabled bool)
- func (s *Server) SetFileServerEnabled(enabled bool)
- func (s *Server) SetFormParsingMemory(maxMemory int64)
- func (s *Server) SetHTTPSAddr(address string)
- func (s *Server) SetHTTPSPort(port ...int)
- func (s *Server) SetIdleTimeout(t time.Duration)
- func (s *Server) SetIndexFiles(indexFiles []string)
- func (s *Server) SetIndexFolder(enabled bool)
- func (s *Server) SetKeepAlive(enabled bool)
- func (s *Server) SetLogPath(path string)
- func (s *Server) SetLogStdout(enabled bool)
- func (s *Server) SetMaxHeaderBytes(b int)
- func (s *Server) SetNameToUriType(t int)
- func (s *Server) SetPort(port ...int)
- func (s *Server) SetReadTimeout(t time.Duration)
- func (s *Server) SetRewrite(uri string, rewrite string)
- func (s *Server) SetRewriteMap(rewrites map[string]string)
- func (s *Server) SetRouteOverWrite(enabled bool)
- func (s *Server) SetServerAgent(agent string)
- func (s *Server) SetServerRoot(root string)
- func (s *Server) SetSessionIdName(name string)
- func (s *Server) SetSessionMaxAge(ttl time.Duration)
- func (s *Server) SetSessionStorage(storage gsession.Storage)
- func (s *Server) SetTLSConfig(tlsConfig *tls.Config)
- func (s *Server) SetView(view *gview.View)
- func (s *Server) SetWriteTimeout(t time.Duration)
- func (s *Server) Shutdown() error
- func (s *Server) Start() error
- func (s *Server) Status() int
- func (s *Server) Use(handlers ...HandlerFunc)
- type ServerConfig
- type Session
- type StaticFile
- type UploadFile
- type UploadFiles
- type WebSocket
Examples ¶
Constants ¶
const ( SERVER_STATUS_STOPPED = 0 SERVER_STATUS_RUNNING = 1 HOOK_BEFORE_SERVE = "HOOK_BEFORE_SERVE" HOOK_AFTER_SERVE = "HOOK_AFTER_SERVE" HOOK_BEFORE_OUTPUT = "HOOK_BEFORE_OUTPUT" HOOK_AFTER_OUTPUT = "HOOK_AFTER_OUTPUT" HTTP_METHODS = "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE" )
const ( URI_TYPE_DEFAULT = 0 // Method name to URI converting type, which converts name to its lower case and joins the words using char '-'. URI_TYPE_FULLNAME = 1 // Method name to URI converting type, which does no converting to the method name. URI_TYPE_ALLLOWER = 2 // Method name to URI converting type, which converts name to its lower case. URI_TYPE_CAMEL = 3 // Method name to URI converting type, which converts name to its camel case. )
const ( // TextMessage denotes a text data message. The text message payload is // interpreted as UTF-8 encoded text data. WS_MSG_TEXT = websocket.TextMessage // BinaryMessage denotes a binary data message. WS_MSG_BINARY = websocket.BinaryMessage // CloseMessage denotes a close control message. The optional message // payload contains a numeric code and text. Use the FormatCloseMessage // function to format a close message payload. WS_MSG_CLOSE = websocket.CloseMessage // PingMessage denotes a ping control message. The optional message payload // is UTF-8 encoded text. WS_MSG_PING = websocket.PingMessage // PongMessage denotes a pong control message. The optional message payload // is UTF-8 encoded text. WS_MSG_PONG = websocket.PongMessage )
Variables ¶
This section is empty.
Functions ¶
func BuildParams ¶
BuildParams builds the request string for the http client. The <params> can be type of: string/[]byte/map/struct/*struct.
The optional parameter <noUrlEncode> specifies whether ignore the url encoding for the data.
func ConnectBytes ¶
ConnectBytes is a convenience method for sending CONNECT request, which retrieves and returns the result content as bytes and automatically closes response object.
func ConnectContent ¶
ConnectContent is a convenience method for sending CONNECT request, which retrieves and returns the result content and automatically closes response object.
func DeleteBytes ¶
DeleteBytes is a convenience method for sending DELETE request, which retrieves and returns the result content as bytes and automatically closes response object.
func DeleteContent ¶
DeleteContent is a convenience method for sending DELETE request, which retrieves and returns the result content and automatically closes response object.
func GetBytes ¶
GetBytes is a convenience method for sending GET request, which retrieves and returns the result content as bytes and automatically closes response object.
func GetContent ¶
GetContent is a convenience method for sending GET request, which retrieves and returns the result content and automatically closes response object.
func HeadBytes ¶
HeadBytes is a convenience method for sending HEAD request, which retrieves and returns the result content as bytes and automatically closes response object.
func HeadContent ¶
HeadContent is a convenience method for sending HEAD request, which retrieves and returns the result content and automatically closes response object.
func IsExitError ¶
func IsExitError(err interface{}) bool
IsExitError checks if given error is an exit error of server. This is used in old version of server for custom error handler. Deprecated.
func OptionsBytes ¶
OptionsBytes is a convenience method for sending OPTIONS request, which retrieves and returns the result content as bytes and automatically closes response object.
func OptionsContent ¶
OptionsContent is a convenience method for sending OPTIONS request, which retrieves and returns the result content and automatically closes response object.
func PatchBytes ¶
PatchBytes is a convenience method for sending PATCH request, which retrieves and returns the result content as bytes and automatically closes response object.
func PatchContent ¶
PatchContent is a convenience method for sending PATCH request, which retrieves and returns the result content and automatically closes response object.
func PostBytes ¶
PostBytes is a convenience method for sending POST request, which retrieves and returns the result content as bytes and automatically closes response object.
func PostContent ¶
PostContent is a convenience method for sending POST request, which retrieves and returns the result content and automatically closes response object.
func PutBytes ¶
PutBytes is a convenience method for sending PUT request, which retrieves and returns the result content as bytes and automatically closes response object.
func PutContent ¶
PutContent is a convenience method for sending PUT request, which retrieves and returns the result content and automatically closes response object.
func RequestBytes ¶
RequestBytes is a convenience method for sending custom http method request, which retrieves and returns the result content as bytes and automatically closes response object.
func RequestContent ¶
RequestContent is a convenience method for sending custom http method request, which retrieves and returns the result content and automatically closes response object.
func RestartAllServer ¶
RestartAllServer restarts all the servers of the process. The optional parameter <newExeFilePath> specifies the new binary file for creating process.
func SetGraceful ¶
func SetGraceful(enabled bool)
SetGraceful enables/disables the graceful reload feature for server, which is false in default.
Note that this feature switch is not for single server instance but for whole process. Deprecated, use configuration of ghttp.Server for controlling this feature.
func ShutdownAllServer ¶
func ShutdownAllServer() error
ShutdownAllServer shuts down all servers of current process.
func TraceBytes ¶
TraceBytes is a convenience method for sending TRACE request, which retrieves and returns the result content as bytes and automatically closes response object.
func TraceContent ¶
TraceContent is a convenience method for sending TRACE request, which retrieves and returns the result content and automatically closes response object.
Types ¶
type CORSOptions ¶
type CORSOptions struct { AllowDomain []string // Used for allowing requests from custom domains AllowOrigin string // Access-Control-Allow-Origin AllowCredentials string // Access-Control-Allow-Credentials ExposeHeaders string // Access-Control-Expose-Headers MaxAge int // Access-Control-Max-Age AllowMethods string // Access-Control-Allow-Methods AllowHeaders string // Access-Control-Allow-Headers }
CORSOptions is the options for CORS feature. See https://www.w3.org/TR/cors/ .
type Client ¶
type Client struct { http.Client // Underlying HTTP Client. // contains filtered or unexported fields }
Client is the HTTP client for HTTP request management.
func (*Client) BasicAuth ¶
BasicAuth is a chaining function, which sets HTTP basic authentication information for next request.
func (*Client) Connect ¶
func (c *Client) Connect(url string, data ...interface{}) (*ClientResponse, error)
Connect send CONNECT request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) ConnectBytes ¶
ConnectBytes sends a CONNECT request, retrieves and returns the result content as bytes.
func (*Client) ConnectContent ¶
ConnectContent is a convenience method for sending CONNECT request, which retrieves and returns the result content and automatically closes response object.
func (*Client) ContentJson ¶
ContentJson is a chaining function, which sets the HTTP content type as "application/json" for the next request.
Note that it also checks and encodes the parameter to JSON format automatically.
func (*Client) ContentType ¶
ContentType is a chaining function, which sets HTTP content type for the next request.
func (*Client) ContentXml ¶
ContentXml is a chaining function, which sets the HTTP content type as "application/xml" for the next request.
Note that it also checks and encodes the parameter to XML format automatically.
func (*Client) Cookie ¶
Cookie is a chaining function, which sets cookie items with map for next request.
func (*Client) Ctx ¶
Ctx is a chaining function, which sets context for next request of this client.
func (*Client) Delete ¶
func (c *Client) Delete(url string, data ...interface{}) (*ClientResponse, error)
Delete send DELETE request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) DeleteBytes ¶
DeleteBytes sends a DELETE request, retrieves and returns the result content as bytes.
func (*Client) DeleteContent ¶
DeleteContent is a convenience method for sending DELETE request, which retrieves and returns the result content and automatically closes response object.
func (*Client) DoRequest ¶
func (c *Client) DoRequest(method, url string, data ...interface{}) (resp *ClientResponse, err error)
DoRequest sends request with given HTTP method and data and returns the response object. Note that the response object MUST be closed if it'll be never used.
Note that it uses "multipart/form-data" as its Content-Type if it contains file uploading, else it uses "application/x-www-form-urlencoded". It also automatically detects the post content for JSON format, and for that it automatically sets the Content-Type as "application/json".
func (*Client) Get ¶
func (c *Client) Get(url string, data ...interface{}) (*ClientResponse, error)
Get send GET request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) GetBytes ¶
GetBytes sends a GET request, retrieves and returns the result content as bytes.
func (*Client) GetContent ¶
GetContent is a convenience method for sending GET request, which retrieves and returns the result content and automatically closes response object.
func (*Client) Head ¶
func (c *Client) Head(url string, data ...interface{}) (*ClientResponse, error)
Head send HEAD request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) HeadBytes ¶
HeadBytes sends a HEAD request, retrieves and returns the result content as bytes.
func (*Client) HeadContent ¶
HeadContent is a convenience method for sending HEAD request, which retrieves and returns the result content and automatically closes response object.
func (*Client) Header ¶
Header is a chaining function, which sets custom HTTP headers with map for next request.
func (*Client) HeaderRaw ¶
Header is a chaining function, which sets custom HTTP header using raw string for next request.
func (*Client) Options ¶
func (c *Client) Options(url string, data ...interface{}) (*ClientResponse, error)
Options send OPTIONS request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) OptionsBytes ¶
OptionsBytes sends a OPTIONS request, retrieves and returns the result content as bytes.
func (*Client) OptionsContent ¶
OptionsContent is a convenience method for sending OPTIONS request, which retrieves and returns the result content and automatically closes response object.
func (*Client) Patch ¶
func (c *Client) Patch(url string, data ...interface{}) (*ClientResponse, error)
Patch send PATCH request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) PatchBytes ¶
PatchBytes sends a PATCH request, retrieves and returns the result content as bytes.
func (*Client) PatchContent ¶
PatchContent is a convenience method for sending PATCH request, which retrieves and returns the result content and automatically closes response object.
func (*Client) Post ¶
func (c *Client) Post(url string, data ...interface{}) (*ClientResponse, error)
Post sends request using HTTP method POST and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) PostBytes ¶
PostBytes sends a POST request, retrieves and returns the result content as bytes.
func (*Client) PostContent ¶
PostContent is a convenience method for sending POST request, which retrieves and returns the result content and automatically closes response object.
func (*Client) Prefix ¶
Prefix is a chaining function, which sets the URL prefix for next request of this client.
func (*Client) Proxy ¶
Proxy is a chaining function, which sets proxy for next request. Make sure you pass the correct `proxyURL`. The correct pattern is like `http://USER:PASSWORD@IP:PORT` or `socks5://USER:PASSWORD@IP:PORT`. Only `http` and `socks5` proxies are supported currently.
func (*Client) Put ¶
func (c *Client) Put(url string, data ...interface{}) (*ClientResponse, error)
Put send PUT request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) PutBytes ¶
PutBytes sends a PUT request, retrieves and returns the result content as bytes.
func (*Client) PutContent ¶
PutContent is a convenience method for sending PUT request, which retrieves and returns the result content and automatically closes response object.
func (*Client) RequestBytes ¶
RequestBytes sends request using given HTTP method and data, retrieves returns the result as bytes. It reads and closes the response object internally automatically.
func (*Client) RequestContent ¶
RequestContent is a convenience method for sending custom http method request, which retrieves and returns the result content and automatically closes response object.
func (*Client) Retry ¶
Retry is a chaining function, which sets retry count and interval when failure for next request.
func (*Client) SetBasicAuth ¶
SetBasicAuth sets HTTP basic authentication information for the client.
func (*Client) SetBrowserMode ¶
SetBrowserMode enables browser mode of the client. When browser mode is enabled, it automatically saves and sends cookie content from and to server.
func (*Client) SetContentType ¶
SetContentType sets HTTP content type for the client.
func (*Client) SetCookieMap ¶
SetCookieMap sets cookie items with map.
func (*Client) SetHeaderMap ¶
SetHeaderMap sets custom HTTP headers with map.
func (*Client) SetHeaderRaw ¶
SetHeaderRaw sets custom HTTP header using raw string.
func (*Client) SetProxy ¶
SetProxy set proxy for the client. This func will do nothing when the parameter `proxyURL` is empty or in wrong pattern. The correct pattern is like `http://USER:PASSWORD@IP:PORT` or `socks5://USER:PASSWORD@IP:PORT`. Only `http` and `socks5` proxies are supported currently.
Example ¶
ExampleClient_SetProxy a example for `ghttp.Client.SetProxy` method. please prepare two proxy server before running this example. http proxy server listening on `127.0.0.1:1081` socks5 proxy server listening on `127.0.0.1:1080`
package main import ( "fmt" "github.com/csrgxtu/gf/net/ghttp" "time" ) func main() { // connect to a http proxy server client := ghttp.NewClient() client.SetProxy("http://127.0.0.1:1081") client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout response, err := client.Get("https://api.ip.sb/ip") if err != nil { // err is not nil when your proxy server is down. // eg. Get "https://api.ip.sb/ip": proxyconnect tcp: dial tcp 127.0.0.1:1087: connect: connection refused fmt.Println(err) } response.RawDump() // connect to a http proxy server which needs auth client.SetProxy("http://user:password:127.0.0.1:1081") client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout response, err = client.Get("https://api.ip.sb/ip") if err != nil { // err is not nil when your proxy server is down. // eg. Get "https://api.ip.sb/ip": proxyconnect tcp: dial tcp 127.0.0.1:1087: connect: connection refused fmt.Println(err) } response.RawDump() // connect to a socks5 proxy server client.SetProxy("socks5://127.0.0.1:1080") client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout response, err = client.Get("https://api.ip.sb/ip") if err != nil { // err is not nil when your proxy server is down. // eg. Get "https://api.ip.sb/ip": socks connect tcp 127.0.0.1:1087->api.ip.sb:443: dial tcp 127.0.0.1:1087: connect: connection refused fmt.Println(err) } fmt.Println(response.RawResponse()) // connect to a socks5 proxy server which needs auth client.SetProxy("socks5://user:password@127.0.0.1:1080") client.SetTimeout(5 * time.Second) // it's suggested to set http client timeout response, err = client.Get("https://api.ip.sb/ip") if err != nil { // err is not nil when your proxy server is down. // eg. Get "https://api.ip.sb/ip": socks connect tcp 127.0.0.1:1087->api.ip.sb:443: dial tcp 127.0.0.1:1087: connect: connection refused fmt.Println(err) } fmt.Println(response.RawResponse()) }
Output:
func (*Client) SetRedirectLimit ¶
SetRedirectLimit limit the number of jumps
func (*Client) SetTimeout ¶
SetTimeOut sets the request timeout for the client.
func (*Client) Trace ¶
func (c *Client) Trace(url string, data ...interface{}) (*ClientResponse, error)
Trace send TRACE request and returns the response object. Note that the response object MUST be closed if it'll be never used.
func (*Client) TraceBytes ¶
TraceBytes sends a TRACE request, retrieves and returns the result content as bytes.
func (*Client) TraceContent ¶
TraceContent is a convenience method for sending TRACE request, which retrieves and returns the result content and automatically closes response object.
type ClientResponse ¶
ClientResponse is the struct for client request response.
func Connect ¶
func Connect(url string, data ...interface{}) (*ClientResponse, error)
Connect is a convenience method for sending CONNECT request. NOTE that remembers CLOSING the response object when it'll never be used.
func Delete ¶
func Delete(url string, data ...interface{}) (*ClientResponse, error)
Delete is a convenience method for sending DELETE request. NOTE that remembers CLOSING the response object when it'll never be used.
func DoRequest ¶
func DoRequest(method, url string, data ...interface{}) (*ClientResponse, error)
DoRequest is a convenience method for sending custom http method request. NOTE that remembers CLOSING the response object when it'll never be used.
func Get ¶
func Get(url string, data ...interface{}) (*ClientResponse, error)
Get is a convenience method for sending GET request. NOTE that remembers CLOSING the response object when it'll never be used.
func Head ¶
func Head(url string, data ...interface{}) (*ClientResponse, error)
Head is a convenience method for sending HEAD request. NOTE that remembers CLOSING the response object when it'll never be used.
func Options ¶
func Options(url string, data ...interface{}) (*ClientResponse, error)
Options is a convenience method for sending OPTIONS request. NOTE that remembers CLOSING the response object when it'll never be used.
func Patch ¶
func Patch(url string, data ...interface{}) (*ClientResponse, error)
Patch is a convenience method for sending PATCH request. NOTE that remembers CLOSING the response object when it'll never be used.
func Post ¶
func Post(url string, data ...interface{}) (*ClientResponse, error)
Post is a convenience method for sending POST request. NOTE that remembers CLOSING the response object when it'll never be used.
func Put ¶
func Put(url string, data ...interface{}) (*ClientResponse, error)
Put is a convenience method for sending PUT request. NOTE that remembers CLOSING the response object when it'll never be used.
func Trace ¶
func Trace(url string, data ...interface{}) (*ClientResponse, error)
Trace is a convenience method for sending TRACE request. NOTE that remembers CLOSING the response object when it'll never be used.
func (*ClientResponse) Close ¶
func (r *ClientResponse) Close() error
Close closes the response when it will never be used.
func (*ClientResponse) GetCookie ¶
func (r *ClientResponse) GetCookie(key string) string
GetCookie retrieves and returns the cookie value of specified <key>.
func (*ClientResponse) GetCookieMap ¶
func (r *ClientResponse) GetCookieMap() map[string]string
GetCookieMap retrieves and returns a copy of current cookie values map.
func (*ClientResponse) Raw ¶
func (r *ClientResponse) Raw() string
Raw returns the raw text of the request and the response.
func (*ClientResponse) RawDump ¶
func (r *ClientResponse) RawDump()
RawDump outputs the raw text of the request and the response to stdout.
Example ¶
package main import ( "github.com/csrgxtu/gf/frame/g" ) func main() { response, err := g.Client().Get("https://goframe.org") if err != nil { panic(err) } response.RawDump() }
Output:
func (*ClientResponse) RawRequest ¶
func (r *ClientResponse) RawRequest() string
RawRequest returns the raw content of the request.
func (*ClientResponse) RawResponse ¶
func (r *ClientResponse) RawResponse() string
RawResponse returns the raw content of the response.
func (*ClientResponse) ReadAll ¶
func (r *ClientResponse) ReadAll() []byte
ReadAll retrieves and returns the response content as []byte.
func (*ClientResponse) ReadAllString ¶
func (r *ClientResponse) ReadAllString() string
ReadAllString retrieves and returns the response content as string.
type Controller ¶
type Controller interface { Init(*Request) Shut() }
Controller is the base struct for controller.
type Cookie ¶
type Cookie struct {
// contains filtered or unexported fields
}
Cookie for HTTP COOKIE management.
func GetCookie ¶
GetCookie creates or retrieves a cookie object with given request. It retrieves and returns an existing cookie object if it already exists with given request. It creates and returns a new cookie object if it does not exist with given request.
func (*Cookie) Get ¶
Get retrieves and returns the value with specified key. It returns <def> if specified key does not exist and <def> is given.
func (*Cookie) GetSessionId ¶
GetSessionId retrieves and returns the session id from cookie.
func (*Cookie) Remove ¶
Remove deletes specified key and its value from cookie using default domain and path. It actually tells the http client that the cookie is expired, do not send it to server next time.
func (*Cookie) RemoveCookie ¶
RemoveCookie deletes specified key and its value from cookie using given domain and path. It actually tells the http client that the cookie is expired, do not send it to server next time.
func (*Cookie) SetCookie ¶
SetCookie sets cookie item given given domain, path and expiration age. The optional parameter <httpOnly> specifies if the cookie item is only available in HTTP, which is usually empty.
func (*Cookie) SetSessionId ¶
SetSessionId sets session id in the cookie.
type CookieItem ¶
type CookieItem struct {
// contains filtered or unexported fields
}
CookieItem is cookie item stored in Cookie management object.
type Domain ¶
type Domain struct {
// contains filtered or unexported fields
}
Domain is used for route register for domains.
func (*Domain) BindController ¶
func (d *Domain) BindController(pattern string, c Controller, methods ...string)
func (*Domain) BindControllerMethod ¶
func (d *Domain) BindControllerMethod(pattern string, c Controller, method string)
func (*Domain) BindControllerRest ¶
func (d *Domain) BindControllerRest(pattern string, c Controller)
func (*Domain) BindHandler ¶
func (d *Domain) BindHandler(pattern string, handler HandlerFunc)
func (*Domain) BindHookHandler ¶
func (d *Domain) BindHookHandler(pattern string, hook string, handler HandlerFunc)
func (*Domain) BindHookHandlerByMap ¶
func (d *Domain) BindHookHandlerByMap(pattern string, hookmap map[string]HandlerFunc)
func (*Domain) BindMiddleware ¶
func (d *Domain) BindMiddleware(pattern string, handlers ...HandlerFunc)
func (*Domain) BindMiddlewareDefault ¶
func (d *Domain) BindMiddlewareDefault(handlers ...HandlerFunc)
func (*Domain) BindObject ¶
func (*Domain) BindObjectMethod ¶
func (*Domain) BindObjectRest ¶
func (*Domain) BindStatusHandler ¶
func (d *Domain) BindStatusHandler(status int, handler HandlerFunc)
func (*Domain) BindStatusHandlerByMap ¶
func (d *Domain) BindStatusHandlerByMap(handlerMap map[int]HandlerFunc)
func (*Domain) Group ¶
func (d *Domain) Group(prefix string, groups ...func(group *RouterGroup)) *RouterGroup
Group creates and returns a RouterGroup object, which is bound to a specified domain.
func (*Domain) Use ¶
func (d *Domain) Use(handlers ...HandlerFunc)
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware is the plugin for request workflow management.
func (*Middleware) Next ¶
func (m *Middleware) Next()
Next calls the next workflow handler. It's an important function controlling the workflow of the server request execution.
type Plugin ¶
type Plugin interface { Name() string // Name returns the name of the plugin. Author() string // Author returns the author of the plugin. Version() string // Version returns the version of the plugin, like "v1.0.0". Description() string // Description returns the description of the plugin. Install(s *Server) error // Install installs the plugin before server starts. Remove() error // Remove removes the plugin. }
Plugin is the interface for server plugin.
type Request ¶
type Request struct { *http.Request Server *Server // Server. Cookie *Cookie // Cookie. Session *gsession.Session // Session. Response *Response // Corresponding Response of this request. Router *Router // Matched Router for this request. Note that it's not available in HOOK handler. EnterTime int64 // Request starting time in microseconds. LeaveTime int64 // Request ending time in microseconds. Middleware *Middleware // Middleware manager. StaticFile *StaticFile // Static file object for static file serving. // contains filtered or unexported fields }
Request is the context object for a request.
func (*Request) BasicAuth ¶
BasicAuth enables the http basic authentication feature with given passport and password and asks client for authentication. It returns true if authentication success, else returns false if failure.
func (*Request) Context ¶
Context is alias for function GetCtx. This function overwrites the http.Request.Context function. See GetCtx.
func (*Request) ExitAll ¶
func (r *Request) ExitAll()
ExitAll exits executing of current and following HTTP handlers.
func (*Request) ExitHook ¶
func (r *Request) ExitHook()
ExitHook exits executing of current and following HTTP HOOK handlers.
func (*Request) Get ¶
Get is alias of GetRequest, which is one of the most commonly used functions for retrieving parameter. See r.GetRequest.
func (*Request) GetArray ¶
GetArray is an alias and convenient function for GetRequestArray. See GetRequestArray.
func (*Request) GetBody ¶
GetBody retrieves and returns request body content as bytes. It can be called multiple times retrieving the same body content.
func (*Request) GetBodyString ¶
GetBodyString retrieves and returns request body content as string. It can be called multiple times retrieving the same body content.
func (*Request) GetBool ¶
GetBool is an alias and convenient function for GetRequestBool. See GetRequestBool.
func (*Request) GetClientIp ¶
GetClientIp returns the client ip of this request without port.
func (*Request) GetCtxVar ¶
GetCtxVar retrieves and returns a Var with given key name. The optional parameter <def> specifies the default value of the Var if given <key> does not exist in the context.
func (*Request) GetError ¶
GetError returns the error occurs in the procedure of the request. It returns nil if there's no error.
func (*Request) GetFloat32 ¶
GetFloat32 is an alias and convenient function for GetRequestFloat32. See GetRequestFloat32.
func (*Request) GetFloat64 ¶
GetFloat64 is an alias and convenient function for GetRequestFloat64. See GetRequestFloat64.
func (*Request) GetFloats ¶
GetFloats is an alias and convenient function for GetRequestFloats. See GetRequestFloats.
func (*Request) GetForm ¶
GetForm retrieves and returns parameter <key> from form. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormArray ¶
GetFormArray retrieves and returns parameter <key> from form as []string. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormBool ¶
GetFormBool retrieves and returns parameter <key> from form as bool. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormFloat32 ¶
GetFormFloat32 retrieves and returns parameter <key> from form as float32. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormFloat64 ¶
GetFormFloat64 retrieves and returns parameter <key> from form as float64. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormFloats ¶
GetFormFloats retrieves and returns parameter <key> from form as []float64. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormInt ¶
GetFormInt retrieves and returns parameter <key> from form as int. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormInt32 ¶
GetFormInt32 retrieves and returns parameter <key> from form as int32. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormInt64 ¶
GetFormInt64 retrieves and returns parameter <key> from form as int64. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormInterfaces ¶
GetFormInterfaces retrieves and returns parameter <key> from form as []interface{}. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormInts ¶
GetFormInts retrieves and returns parameter <key> from form as []int. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormMap ¶
GetFormMap retrieves and returns all form parameters passed from client as map. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
func (*Request) GetFormMapStrStr ¶
GetFormMapStrStr retrieves and returns all form parameters passed from client as map[string]string. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
func (*Request) GetFormMapStrVar ¶
GetFormMapStrVar retrieves and returns all form parameters passed from client as map[string]*gvar.Var. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
func (*Request) GetFormString ¶
GetFormString retrieves and returns parameter <key> from form as string. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormStrings ¶
GetFormStrings retrieves and returns parameter <key> from form as []string. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormStruct ¶
GetFormStruct retrieves all form parameters passed from client and converts them to given struct object. Note that the parameter <pointer> is a pointer to the struct object. The optional parameter <mapping> is used to specify the key to attribute mapping.
func (*Request) GetFormToStruct ¶
GetFormToStruct is alias of GetFormStruct. See GetFormStruct. Deprecated.
func (*Request) GetFormUint ¶
GetFormUint retrieves and returns parameter <key> from form as uint. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormUint32 ¶
GetFormUint32 retrieves and returns parameter <key> from form as uint32. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormUint64 ¶
GetFormUint64 retrieves and returns parameter <key> from form as uint64. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetFormVar ¶
GetFormVar retrieves and returns parameter <key> from form as Var. It returns <def> if <key> does not exist in the form and <def> is given, or else it returns nil.
func (*Request) GetHost ¶
GetHost returns current request host name, which might be a domain or an IP without port.
func (*Request) GetInt ¶
GetInt is an alias and convenient function for GetRequestInt. See GetRequestInt.
func (*Request) GetInt32 ¶
GetInt32 is an alias and convenient function for GetRequestInt32. See GetRequestInt32.
func (*Request) GetInt64 ¶
GetInt64 is an alias and convenient function for GetRequestInt64. See GetRequestInt64.
func (*Request) GetInterfaces ¶
GetInterfaces is an alias and convenient function for GetRequestInterfaces. See GetRequestInterfaces.
func (*Request) GetInts ¶
GetInts is an alias and convenient function for GetRequestInts. See GetRequestInts.
func (*Request) GetJson ¶
GetJson parses current request content as JSON format, and returns the JSON object. Note that the request content is read from request BODY, not from any field of FORM.
func (*Request) GetMap ¶
GetMap is an alias and convenient function for GetRequestMap. See GetRequestMap.
func (*Request) GetMapStrStr ¶
GetMapStrStr is an alias and convenient function for GetRequestMapStrStr. See GetRequestMapStrStr.
func (*Request) GetMultipartFiles ¶
func (r *Request) GetMultipartFiles(name string) []*multipart.FileHeader
GetMultipartFiles parses and returns the post files array. Note that the request form should be type of multipart.
func (*Request) GetMultipartForm ¶
GetMultipartForm parses and returns the form as multipart form.
func (*Request) GetPage ¶
GetPage creates and returns the pagination object for given <totalSize> and <pageSize>. NOTE THAT the page parameter name from client is constantly defined as gpage.PAGE_NAME for simplification and convenience.
func (*Request) GetParam ¶
GetParam returns custom parameter with given name <key>. It returns <def> if <key> does not exist. It returns nil if <def> is not passed.
func (*Request) GetParamVar ¶
GetParamVar returns custom parameter with given name <key> as gvar.Var. It returns <def> if <key> does not exist. It returns nil if <def> is not passed.
func (*Request) GetPost ¶
GetPost retrieves and returns parameter <key> from form and body. It returns <def> if <key> does not exist in neither form nor body. It returns nil if <def> is not passed.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: form > body.
Deprecated.
func (*Request) GetPostArray ¶
Deprecated.
func (*Request) GetPostBool ¶
Deprecated.
func (*Request) GetPostFloat32 ¶
Deprecated.
func (*Request) GetPostFloat64 ¶
Deprecated.
func (*Request) GetPostFloats ¶
Deprecated.
func (*Request) GetPostInt ¶
Deprecated.
func (*Request) GetPostInt32 ¶
Deprecated.
func (*Request) GetPostInt64 ¶
Deprecated.
func (*Request) GetPostInterfaces ¶
Deprecated.
func (*Request) GetPostInts ¶
Deprecated.
func (*Request) GetPostMap ¶
GetPostMap retrieves and returns all parameters in the form and body passed from client as map. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: form > body.
Deprecated.
func (*Request) GetPostMapStrStr ¶
GetPostMapStrStr retrieves and returns all parameters in the form and body passed from client as map[string]string. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
Deprecated.
func (*Request) GetPostMapStrVar ¶
GetPostMapStrVar retrieves and returns all parameters in the form and body passed from client as map[string]*gvar.Var. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
Deprecated.
func (*Request) GetPostString ¶
Deprecated.
func (*Request) GetPostStrings ¶
Deprecated.
func (*Request) GetPostStruct ¶
GetPostStruct retrieves all parameters in the form and body passed from client and converts them to given struct object. Note that the parameter <pointer> is a pointer to the struct object. The optional parameter <mapping> is used to specify the key to attribute mapping.
Deprecated.
func (*Request) GetPostToStruct ¶
GetPostToStruct is alias of GetQueryStruct. See GetPostStruct.
Deprecated.
func (*Request) GetPostUint ¶
Deprecated.
func (*Request) GetPostUint32 ¶
Deprecated.
func (*Request) GetPostUint64 ¶
Deprecated.
func (*Request) GetPostVar ¶
Deprecated.
func (*Request) GetQuery ¶
GetQuery retrieves and returns parameter with given name <key> from query string and request body. It returns <def> if <key> does not exist in the query and <def> is given, or else it returns nil.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: query > body.
func (*Request) GetQueryArray ¶
func (*Request) GetQueryBool ¶
func (*Request) GetQueryFloat32 ¶
func (*Request) GetQueryFloat64 ¶
func (*Request) GetQueryFloats ¶
func (*Request) GetQueryInt ¶
func (*Request) GetQueryInt32 ¶
func (*Request) GetQueryInt64 ¶
func (*Request) GetQueryInterfaces ¶
func (*Request) GetQueryInts ¶
func (*Request) GetQueryMap ¶
GetQueryMap retrieves and returns all parameters passed from client using HTTP GET method as map. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: query > body.
func (*Request) GetQueryMapStrStr ¶
GetQueryMapStrStr retrieves and returns all parameters passed from client using HTTP GET method as map[string]string. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
func (*Request) GetQueryMapStrVar ¶
GetQueryMapStrVar retrieves and returns all parameters passed from client using HTTP GET method as map[string]*gvar.Var. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
func (*Request) GetQueryString ¶
func (*Request) GetQueryStrings ¶
func (*Request) GetQueryStruct ¶
GetQueryStruct retrieves all parameters passed from client using HTTP GET method and converts them to given struct object. Note that the parameter <pointer> is a pointer to the struct object. The optional parameter <mapping> is used to specify the key to attribute mapping.
func (*Request) GetQueryToStruct ¶
GetQueryToStruct is alias of GetQueryStruct. See GetQueryStruct. Deprecated.
func (*Request) GetQueryUint ¶
func (*Request) GetQueryUint32 ¶
func (*Request) GetQueryUint64 ¶
func (*Request) GetQueryVar ¶
func (*Request) GetRawString ¶
GetRawString is alias of GetBodyString. See GetBodyString. Deprecated.
func (*Request) GetReferer ¶
GetReferer returns referer of this request.
func (*Request) GetRequest ¶
GetRequest retrieves and returns the parameter named <key> passed from client and custom params as interface{}, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
GetRequest is one of the most commonly used functions for retrieving parameters.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: router < query < body < form < custom.
func (*Request) GetRequestArray ¶
GetRequestArray retrieves and returns the parameter named <key> passed from client and custom params as []string, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestBool ¶
GetRequestBool retrieves and returns the parameter named <key> passed from client and custom params as bool, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestFloat32 ¶
GetRequestFloat32 retrieves and returns the parameter named <key> passed from client and custom params as float32, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestFloat64 ¶
GetRequestFloat64 retrieves and returns the parameter named <key> passed from client and custom params as float64, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestFloats ¶
GetRequestFloats retrieves and returns the parameter named <key> passed from client and custom params as []float64, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInt ¶
GetRequestInt retrieves and returns the parameter named <key> passed from client and custom params as int, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInt32 ¶
GetRequestInt32 retrieves and returns the parameter named <key> passed from client and custom params as int32, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInt64 ¶
GetRequestInt64 retrieves and returns the parameter named <key> passed from client and custom params as int64, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInterfaces ¶
GetRequestInterfaces retrieves and returns the parameter named <key> passed from client and custom params as []interface{}, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestInts ¶
GetRequestInts retrieves and returns the parameter named <key> passed from client and custom params as []int, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestMap ¶
GetRequestMap retrieves and returns all parameters passed from client and custom params as map, no matter what HTTP method the client is using. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass the according keys.
GetRequestMap is one of the most commonly used functions for retrieving parameters.
Note that if there're multiple parameters with the same name, the parameters are retrieved and overwrote in order of priority: router < query < body < form < custom.
func (*Request) GetRequestMapStrStr ¶
GetRequestMapStrStr retrieves and returns all parameters passed from client and custom params as map[string]string, no matter what HTTP method the client is using. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
func (*Request) GetRequestMapStrVar ¶
GetRequestMapStrVar retrieves and returns all parameters passed from client and custom params as map[string]*gvar.Var, no matter what HTTP method the client is using. The parameter <kvMap> specifies the keys retrieving from client parameters, the associated values are the default values if the client does not pass.
func (*Request) GetRequestString ¶
GetRequestString retrieves and returns the parameter named <key> passed from client and custom params as string, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestStrings ¶
GetRequestStrings retrieves and returns the parameter named <key> passed from client and custom params as []string, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestStruct ¶
GetRequestStruct retrieves all parameters passed from client and custom params no matter what HTTP method the client is using, and converts them to given struct object. Note that the parameter <pointer> is a pointer to the struct object. The optional parameter <mapping> is used to specify the key to attribute mapping.
func (*Request) GetRequestToStruct ¶
GetRequestToStruct is alias of GetRequestStruct. See GetRequestStruct. Deprecated.
func (*Request) GetRequestUint ¶
GetRequestUint retrieves and returns the parameter named <key> passed from client and custom params as uint, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestUint32 ¶
GetRequestUint32 retrieves and returns the parameter named <key> passed from client and custom params as uint32, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestUint64 ¶
GetRequestUint64 retrieves and returns the parameter named <key> passed from client and custom params as uint64, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRequestVar ¶
GetRequestVar retrieves and returns the parameter named <key> passed from client and custom params as gvar.Var, no matter what HTTP method the client is using. The parameter <def> specifies the default value if the <key> does not exist.
func (*Request) GetRouterString ¶
GetRouterString retrieves and returns the router value as string with given key name <key>. It returns <def> if <key> does not exist.
func (*Request) GetRouterValue ¶
GetRouterValue retrieves and returns the router value with given key name <key>. It returns <def> if <key> does not exist.
func (*Request) GetRouterVar ¶
GetRouterVar retrieves and returns the router value as gvar.Var with given key name <key>. It returns <def> if <key> does not exist.
func (*Request) GetSessionId ¶
GetSessionId retrieves and returns session id from cookie or header.
func (*Request) GetString ¶
GetString is an alias and convenient function for GetRequestString. See GetRequestString.
func (*Request) GetStrings ¶
GetStrings is an alias and convenient function for GetRequestStrings. See GetRequestStrings.
func (*Request) GetStruct ¶
GetStruct is an alias and convenient function for GetRequestStruct. See GetRequestStruct.
func (*Request) GetToStruct ¶
GetToStruct is an alias and convenient function for GetRequestStruct. See GetRequestToStruct. Deprecated.
func (*Request) GetUint ¶
GetUint is an alias and convenient function for GetRequestUint. See GetRequestUint.
func (*Request) GetUint32 ¶
GetUint32 is an alias and convenient function for GetRequestUint32. See GetRequestUint32.
func (*Request) GetUint64 ¶
GetUint64 is an alias and convenient function for GetRequestUint64. See GetRequestUint64.
func (*Request) GetUploadFile ¶
func (r *Request) GetUploadFile(name string) *UploadFile
GetUploadFile retrieves and returns the uploading file with specified form name. This function is used for retrieving single uploading file object, which is uploaded using multipart form content type.
It returns nil if retrieving failed or no form file with given name posted.
Note that the <name> is the file field name of the multipart form from client.
func (*Request) GetUploadFiles ¶
func (r *Request) GetUploadFiles(name string) UploadFiles
GetUploadFiles retrieves and returns multiple uploading files with specified form name. This function is used for retrieving multiple uploading file objects, which are uploaded using multipart form content type.
It returns nil if retrieving failed or no form file with given name posted.
Note that the <name> is the file field name of the multipart form from client.
func (*Request) IsAjaxRequest ¶
IsAjaxRequest checks and returns whether current request is an AJAX request.
func (*Request) IsFileRequest ¶
IsFileRequest checks and returns whether current request is serving file.
func (*Request) Parse ¶
Parse is the most commonly used function, which converts request parameters to struct or struct slice. It also automatically validates the struct or every element of the struct slice according to the validation tag of the struct.
The parameter <pointer> can be type of: *struct/**struct/*[]struct/*[]*struct.
It supports single and multiple struct convertion: 1. Single struct, post content like: {"id":1, "name":"john"} 2. Multiple struct, post content like: [{"id":1, "name":"john"}, {"id":, "name":"smith"}]
TODO: Improve the performance by reducing duplicated reflect usage on the same variable across packages.
func (*Request) SetCtxVar ¶
func (r *Request) SetCtxVar(key interface{}, value interface{})
SetCtxVar sets custom parameter to context with key-value pair.
type Response ¶
type Response struct { *ResponseWriter // Underlying ResponseWriter. Server *Server // Parent server. Writer *ResponseWriter // Alias of ResponseWriter. Request *Request // According request. }
Response is the http response manager. Note that it implements the http.ResponseWriter interface with buffering feature.
func (*Response) BufferLength ¶
BufferLength returns the length of the buffered content.
func (*Response) BufferString ¶
BufferString returns the buffered content as string.
func (*Response) CORS ¶
func (r *Response) CORS(options CORSOptions)
CORS sets custom CORS options. See https://www.w3.org/TR/cors/ .
func (*Response) CORSAllowedOrigin ¶
func (r *Response) CORSAllowedOrigin(options CORSOptions) bool
CORSAllowed checks whether the current request origin is allowed cross-domain.
func (*Response) CORSDefault ¶
func (r *Response) CORSDefault()
CORSDefault sets CORS with default CORS options, which allows any cross-domain request.
func (*Response) ClearBuffer ¶
func (r *Response) ClearBuffer()
ClearBuffer clears the response buffer.
func (*Response) DefaultCORSOptions ¶
func (r *Response) DefaultCORSOptions() CORSOptions
DefaultCORSOptions returns the default CORS options, which allows any cross-domain request.
func (*Response) Flush ¶
func (r *Response) Flush()
Output outputs the buffer content to the client and clears the buffer.
func (*Response) ParseTpl ¶
ParseTpl parses given template file <tpl> with given template variables <params> and returns the parsed template content.
func (*Response) ParseTplContent ¶
ParseTplContent parses given template file <file> with given template parameters <params> and returns the parsed template content.
func (*Response) ParseTplDefault ¶
ParseDefault parses the default template file with params.
func (*Response) RedirectBack ¶
RedirectBack redirects client back to referer. The optional parameter <code> specifies the http status code for redirecting, which commonly can be 301 or 302. It's 302 in default.
func (*Response) RedirectTo ¶
RedirectTo redirects client to another location. The optional parameter <code> specifies the http status code for redirecting, which commonly can be 301 or 302. It's 302 in default.
func (*Response) ServeFileDownload ¶
ServeFileDownload serves file downloading to the response.
func (*Response) Write ¶
func (r *Response) Write(content ...interface{})
Write writes <content> to the response buffer.
func (*Response) WriteExit ¶
func (r *Response) WriteExit(content ...interface{})
WriteExit writes <content> to the response buffer and exits executing of current handler. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
func (*Response) WriteJsonExit ¶
WriteJsonExit writes <content> to the response with JSON format and exits executing of current handler if success. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
func (*Response) WriteJsonP ¶
WriteJson writes <content> to the response with JSONP format.
Note that there should be a "callback" parameter in the request for JSONP format.
func (*Response) WriteJsonPExit ¶
WriteJsonPExit writes <content> to the response with JSONP format and exits executing of current handler if success. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
Note that there should be a "callback" parameter in the request for JSONP format.
func (*Response) WriteOver ¶
func (r *Response) WriteOver(content ...interface{})
WriteOver overwrites the response buffer with <content>.
func (*Response) WriteOverExit ¶
func (r *Response) WriteOverExit(content ...interface{})
WriteOverExit overwrites the response buffer with <content> and exits executing of current handler. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
func (*Response) WriteStatus ¶
WriteStatus writes HTTP <status> and <content> to the response. Note that do not set Content-Type header here.
func (*Response) WriteStatusExit ¶
WriteStatusExit writes HTTP <status> and <content> to the response and exits executing of current handler if success. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
func (*Response) WriteTpl ¶
WriteTpl parses and responses given template file. The parameter <params> specifies the template variables for parsing.
func (*Response) WriteTplContent ¶
WriteTplContent parses and responses the template content. The parameter <params> specifies the template variables for parsing.
func (*Response) WriteTplDefault ¶
WriteTplDefault parses and responses the default template file. The parameter <params> specifies the template variables for parsing.
func (*Response) WriteXmlExit ¶
WriteXmlExit writes <content> to the response with XML format and exits executing of current handler if success. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
func (*Response) WritefExit ¶
WritefExit writes the response with fmt.Sprintf and exits executing of current handler. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
func (*Response) WriteflnExit ¶
WriteflnExit writes the response with fmt.Sprintf and new line and exits executing of current handler. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
func (*Response) Writeln ¶
func (r *Response) Writeln(content ...interface{})
Writef writes the response with <content> and new line.
func (*Response) WritelnExit ¶
func (r *Response) WritelnExit(content ...interface{})
WritelnExit writes the response with <content> and new line and exits executing of current handler. The "Exit" feature is commonly used to replace usage of return statement in the handler, for convenience.
type ResponseWriter ¶
type ResponseWriter struct { Status int // HTTP status. // contains filtered or unexported fields }
ResponseWriter is the custom writer for http response.
func (*ResponseWriter) Flush ¶
func (w *ResponseWriter) Flush()
OutputBuffer outputs the buffer to client and clears the buffer.
func (*ResponseWriter) Header ¶
func (w *ResponseWriter) Header() http.Header
Header implements the interface function of http.ResponseWriter.Header.
func (*ResponseWriter) Hijack ¶
func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements the interface function of http.Hijacker.Hijack.
func (*ResponseWriter) RawWriter ¶
func (w *ResponseWriter) RawWriter() http.ResponseWriter
RawWriter returns the underlying ResponseWriter.
func (*ResponseWriter) Write ¶
func (w *ResponseWriter) Write(data []byte) (int, error)
Write implements the interface function of http.ResponseWriter.Write.
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(status int)
WriteHeader implements the interface of http.ResponseWriter.WriteHeader.
type Router ¶
type Router struct { Uri string // URI. Method string // HTTP method Domain string // Bound domain. RegRule string // Parsed regular expression for route matching. RegNames []string // Parsed router parameter names. Priority int // Just for reference. }
Router object.
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is a group wrapping multiple routes and middleware.
func (*RouterGroup) ALL ¶
func (g *RouterGroup) ALL(pattern string, object interface{}, params ...interface{}) *RouterGroup
ALL registers a http handler to given route pattern and all http methods.
func (*RouterGroup) Bind ¶
func (g *RouterGroup) Bind(items []GroupItem) *RouterGroup
Bind does batch route registering feature for router group.
func (*RouterGroup) CONNECT ¶
func (g *RouterGroup) CONNECT(pattern string, object interface{}, params ...interface{}) *RouterGroup
CONNECT registers a http handler to given route pattern and http method: CONNECT.
func (*RouterGroup) Clone ¶
func (g *RouterGroup) Clone() *RouterGroup
Clone returns a new router group which is a clone of current group.
func (*RouterGroup) DELETE ¶
func (g *RouterGroup) DELETE(pattern string, object interface{}, params ...interface{}) *RouterGroup
DELETE registers a http handler to given route pattern and http method: DELETE.
func (*RouterGroup) GET ¶
func (g *RouterGroup) GET(pattern string, object interface{}, params ...interface{}) *RouterGroup
GET registers a http handler to given route pattern and http method: GET.
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(prefix string, groups ...func(group *RouterGroup)) *RouterGroup
Group creates and returns a sub-group of current router group.
func (*RouterGroup) HEAD ¶
func (g *RouterGroup) HEAD(pattern string, object interface{}, params ...interface{}) *RouterGroup
HEAD registers a http handler to given route pattern and http method: HEAD.
func (*RouterGroup) Hook ¶
func (g *RouterGroup) Hook(pattern string, hook string, handler HandlerFunc) *RouterGroup
Hook registers a hook to given route pattern.
func (*RouterGroup) Middleware ¶
func (g *RouterGroup) Middleware(handlers ...HandlerFunc) *RouterGroup
Middleware binds one or more middleware to the router group.
func (*RouterGroup) OPTIONS ¶
func (g *RouterGroup) OPTIONS(pattern string, object interface{}, params ...interface{}) *RouterGroup
OPTIONS registers a http handler to given route pattern and http method: OPTIONS.
func (*RouterGroup) PATCH ¶
func (g *RouterGroup) PATCH(pattern string, object interface{}, params ...interface{}) *RouterGroup
PATCH registers a http handler to given route pattern and http method: PATCH.
func (*RouterGroup) POST ¶
func (g *RouterGroup) POST(pattern string, object interface{}, params ...interface{}) *RouterGroup
POST registers a http handler to given route pattern and http method: POST.
func (*RouterGroup) PUT ¶
func (g *RouterGroup) PUT(pattern string, object interface{}, params ...interface{}) *RouterGroup
PUT registers a http handler to given route pattern and http method: PUT.
func (*RouterGroup) REST ¶
func (g *RouterGroup) REST(pattern string, object interface{}) *RouterGroup
REST registers a http handler to given route pattern according to REST rule.
func (*RouterGroup) TRACE ¶
func (g *RouterGroup) TRACE(pattern string, object interface{}, params ...interface{}) *RouterGroup
TRACE registers a http handler to given route pattern and http method: TRACE.
type RouterItem ¶
type RouterItem struct { Server string // Server name. Address string // Listening address. Domain string // Bound domain. Type int // Router type. Middleware string // Bound middleware. Method string // Handler method name. Route string // Route URI. Priority int // Just for reference. IsServiceHandler bool // Is service handler. // contains filtered or unexported fields }
Router item just for route dumps.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps the http.Server and provides more feature.
func GetServer ¶
func GetServer(name ...interface{}) *Server
GetServer creates and returns a server instance using given name and default configurations. Note that the parameter <name> should be unique for different servers. It returns an existing server instance if given <name> is already existing in the server mapping.
Example ¶
package main import ( "github.com/csrgxtu/gf/frame/g" "github.com/csrgxtu/gf/net/ghttp" ) func main() { s := g.Server() s.BindHandler("/", func(r *ghttp.Request) { r.Response.Write("hello world") }) s.SetPort(8999) s.Run() }
Output:
func (*Server) AddSearchPath ¶
AddSearchPath add searching directory path for static file service.
func (*Server) AddStaticPath ¶
AddStaticPath sets the uri to static directory path mapping for static file service.
func (*Server) BindController ¶
func (s *Server) BindController(pattern string, controller Controller, method ...string)
BindController registers controller to server routes with specified pattern. The controller needs to implement the gmvc.Controller interface. Each request of the controller bound in this way will initialize a new controller object for processing, corresponding to different request sessions.
The optional parameter <method> is used to specify the method to be registered, which supports multiple method names, multiple methods are separated by char ',', case sensitive.
func (*Server) BindControllerMethod ¶
func (s *Server) BindControllerMethod(pattern string, controller Controller, method string)
BindControllerMethod registers specified method to server routes with specified pattern.
The optional parameter <method> is used to specify the method to be registered, which does not supports multiple method names but only one, case sensitive.
func (*Server) BindControllerRest ¶
func (s *Server) BindControllerRest(pattern string, controller Controller)
BindControllerRest registers controller in REST API style to server with specified pattern. The controller needs to implement the gmvc.Controller interface. Each request of the controller bound in this way will initialize a new controller object for processing, corresponding to different request sessions. The method will recognize the HTTP method and do REST binding, for example: The method "Post" of controller will be bound to the HTTP POST method request processing, and the method "Delete" will be bound to the HTTP DELETE method request processing. Therefore, only the method corresponding to the HTTP Method will be bound, other methods will not automatically register the binding.
func (*Server) BindHandler ¶
func (s *Server) BindHandler(pattern string, handler HandlerFunc)
BindHandler registers a handler function to server with given pattern.
func (*Server) BindHookHandler ¶
func (s *Server) BindHookHandler(pattern string, hook string, handler HandlerFunc)
BindHookHandler registers handler for specified hook.
func (*Server) BindHookHandlerByMap ¶
func (s *Server) BindHookHandlerByMap(pattern string, hookMap map[string]HandlerFunc)
func (*Server) BindMiddleware ¶
func (s *Server) BindMiddleware(pattern string, handlers ...HandlerFunc)
BindMiddleware registers one or more global middleware to the server. Global middleware can be used standalone without service handler, which intercepts all dynamic requests before or after service handler. The parameter <pattern> specifies what route pattern the middleware intercepts, which is usually a "fuzzy" pattern like "/:name", "/*any" or "/{field}".
func (*Server) BindMiddlewareDefault ¶
func (s *Server) BindMiddlewareDefault(handlers ...HandlerFunc)
BindMiddlewareDefault registers one or more global middleware to the server using default pattern "/*". Global middleware can be used standalone without service handler, which intercepts all dynamic requests before or after service handler.
func (*Server) BindObject ¶
BindObject registers object to server routes with given pattern.
The optional parameter <method> is used to specify the method to be registered, which supports multiple method names, multiple methods are separated by char ',', case sensitive.
Note that the route method should be defined as ghttp.HandlerFunc.
func (*Server) BindObjectMethod ¶
BindObjectMethod registers specified method of object to server routes with given pattern.
The optional parameter <method> is used to specify the method to be registered, which does not supports multiple method names but only one, case sensitive.
Note that the route method should be defined as ghttp.HandlerFunc.
func (*Server) BindObjectRest ¶
BindObjectRest registers object in REST API style to server with specified pattern. Note that the route method should be defined as ghttp.HandlerFunc.
func (*Server) BindStatusHandler ¶
func (s *Server) BindStatusHandler(status int, handler HandlerFunc)
BindStatusHandler registers handler for given status code.
func (*Server) BindStatusHandlerByMap ¶
func (s *Server) BindStatusHandlerByMap(handlerMap map[int]HandlerFunc)
BindStatusHandlerByMap registers handler for given status code using map.
func (*Server) Domain ¶
Domain creates and returns a domain object for management for one or more domains.
func (*Server) EnableAdmin ¶
EnableAdmin enables the administration feature for the process. The optional parameter <pattern> specifies the URI for the administration page.
func (*Server) EnableHTTPS ¶
EnableHTTPS enables HTTPS with given certification and key files for the server. The optional parameter <tlsConfig> specifies custom TLS configuration.
func (*Server) EnablePProf ¶
EnablePProf enables PProf feature for server.
func (*Server) GetCookieDomain ¶
GetCookieDomain returns CookieDomain of server.
func (*Server) GetCookieMaxAge ¶
GetCookieMaxAge returns the CookieMaxAge of server.
func (*Server) GetCookiePath ¶
GetCookiePath returns the CookiePath of server.
func (*Server) GetIndexFiles ¶
GetIndexFiles retrieves and returns the index files from server.
func (*Server) GetRouterArray ¶
func (s *Server) GetRouterArray() []RouterItem
GetRouterArray retrieves and returns the router array. The key of the returned map is the domain of the server.
func (*Server) GetSessionIdName ¶
GetSessionIdName returns the SessionIdName of server.
func (*Server) GetSessionMaxAge ¶
GetSessionMaxAge returns the SessionMaxAge of server.
func (*Server) Group ¶
func (s *Server) Group(prefix string, groups ...func(group *RouterGroup)) *RouterGroup
Group creates and returns a RouterGroup object.
func (*Server) IsAccessLogEnabled ¶
IsAccessLogEnabled checks whether the access log enabled.
func (*Server) IsErrorLogEnabled ¶
IsErrorLogEnabled checks whether the error log enabled.
func (*Server) Run ¶
func (s *Server) Run()
Run starts server listening in blocking way. It's commonly used for single server situation.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is the default handler for http request. It should not create new goroutine handling the request as it's called by am already created new goroutine from http.Server.
This function also make serve implementing the interface of http.Handler.
func (*Server) SetAccessLogEnabled ¶
SetAccessLogEnabled enables/disables the access log.
func (*Server) SetAddr ¶
SetAddr sets the listening address for the server. The address is like ':80', '0.0.0.0:80', '127.0.0.1:80', '180.18.99.10:80', etc.
func (*Server) SetClientMaxBodySize ¶
SetClientMaxBodySize sets the ClientMaxBodySize for server.
func (*Server) SetConfig ¶
func (s *Server) SetConfig(c ServerConfig) error
SetConfig sets the configuration for the server.
func (*Server) SetConfigWithMap ¶
SetConfigWithMap sets the configuration for the server using map.
func (*Server) SetCookieDomain ¶
SetCookieDomain sets the CookieDomain for server.
func (*Server) SetCookieMaxAge ¶
SetCookieMaxAge sets the CookieMaxAge for server.
func (*Server) SetCookiePath ¶
SetCookiePath sets the CookiePath for server.
func (*Server) SetDumpRouterMap ¶
SetDumpRouterMap sets the DumpRouterMap for server. If DumpRouterMap is enabled, it automatically dumps the route map when server starts.
func (*Server) SetErrorLogEnabled ¶
SetErrorLogEnabled enables/disables the error log.
func (*Server) SetErrorStack ¶
SetErrorStack enables/disables the error stack feature.
func (*Server) SetFileServerEnabled ¶
SetFileServerEnabled enables/disables the static file service. It's the main switch for the static file service. When static file service configuration functions like SetServerRoot, AddSearchPath and AddStaticPath are called, this configuration is automatically enabled.
func (*Server) SetFormParsingMemory ¶
SetFormParsingMemory sets the FormParsingMemory for server.
func (*Server) SetHTTPSAddr ¶
SetHTTPSAddr sets the HTTPS listening ports for the server.
func (*Server) SetHTTPSPort ¶
SetHTTPSPort sets the HTTPS listening ports for the server. The listening ports can be multiple like: SetHTTPSPort(443, 500).
func (*Server) SetIdleTimeout ¶
SetIdleTimeout sets the IdleTimeout for the server.
func (*Server) SetIndexFiles ¶
SetIndexFiles sets the index files for server.
func (*Server) SetIndexFolder ¶
SetIndexFolder enables/disables listing the sub-files if requesting a directory.
func (*Server) SetKeepAlive ¶
SetKeepAlive sets the KeepAlive for the server.
func (*Server) SetLogPath ¶
SetLogPath sets the log path for server. It logs content to file only if the log path is set.
func (*Server) SetLogStdout ¶
SetLogStdout sets whether output the logging content to stdout.
func (*Server) SetMaxHeaderBytes ¶
SetMaxHeaderBytes sets the MaxHeaderBytes for the server.
func (*Server) SetNameToUriType ¶
SetNameToUriType sets the NameToUriType for server.
func (*Server) SetPort ¶
SetPort sets the listening ports for the server. The listening ports can be multiple like: SetPort(80, 8080).
func (*Server) SetReadTimeout ¶
SetReadTimeout sets the ReadTimeout for the server.
func (*Server) SetRewrite ¶
SetRewrite sets rewrites for static URI for server.
func (*Server) SetRewriteMap ¶
SetRewriteMap sets the rewrite map for server.
func (*Server) SetRouteOverWrite ¶
SetRouteOverWrite sets the RouteOverWrite for server.
func (*Server) SetServerAgent ¶
SetServerAgent sets the ServerAgent for the server.
func (*Server) SetServerRoot ¶
SetServerRoot sets the document root for static service.
func (*Server) SetSessionIdName ¶
SetSessionIdName sets the SessionIdName for server.
func (*Server) SetSessionMaxAge ¶
SetSessionMaxAge sets the SessionMaxAge for server.
func (*Server) SetSessionStorage ¶
SetSessionStorage sets the SessionStorage for server.
func (*Server) SetTLSConfig ¶
SetTLSConfig sets custom TLS configuration and enables HTTPS feature for the server.
func (*Server) SetWriteTimeout ¶
SetWriteTimeout sets the WriteTimeout for the server.
func (*Server) Start ¶
Start starts listening on configured port. This function does not block the process, you can use function Wait blocking the process.
func (*Server) Use ¶
func (s *Server) Use(handlers ...HandlerFunc)
Use is alias of BindMiddlewareDefault. See BindMiddlewareDefault.
type ServerConfig ¶
type ServerConfig struct { // Address specifies the server listening address like "port" or ":port", // multiple addresses joined using ','. Address string // HTTPSAddr specifies the HTTPS addresses, multiple addresses joined using char ','. HTTPSAddr string // HTTPSCertPath specifies certification file path for HTTPS service. HTTPSCertPath string // HTTPSKeyPath specifies the key file path for HTTPS service. HTTPSKeyPath string // TLSConfig optionally provides a TLS configuration for use // by ServeTLS and ListenAndServeTLS. Note that this value is // cloned by ServeTLS and ListenAndServeTLS, so it's not // possible to modify the configuration with methods like // tls.Config.SetSessionTicketKeys. To use // SetSessionTicketKeys, use Server.Serve with a TLS Listener // instead. TLSConfig *tls.Config // Handler the handler for HTTP request. Handler http.Handler // ReadTimeout is the maximum duration for reading the entire // request, including the body. // // Because ReadTimeout does not let Handlers make per-request // decisions on each request body's acceptable deadline or // upload rate, most users will prefer to use // ReadHeaderTimeout. It is valid to use them both. ReadTimeout time.Duration // WriteTimeout is the maximum duration before timing out // writes of the response. It is reset whenever a new // request's header is read. Like ReadTimeout, it does not // let Handlers make decisions on a per-request basis. WriteTimeout time.Duration // IdleTimeout is the maximum amount of time to wait for the // next request when keep-alives are enabled. If IdleTimeout // is zero, the value of ReadTimeout is used. If both are // zero, there is no timeout. IdleTimeout time.Duration // MaxHeaderBytes controls the maximum number of bytes the // server will read parsing the request header's keys and // values, including the request line. It does not limit the // size of the request body. // // It can be configured in configuration file using string like: 1m, 10m, 500kb etc. // It's 1024 bytes in default. MaxHeaderBytes int // KeepAlive enables HTTP keep-alive. KeepAlive bool // ServerAgent specifies the server agent information, which is wrote to // HTTP response header as "Server". ServerAgent string // View specifies the default template view object for the server. View *gview.View // Rewrites specifies the URI rewrite rules map. Rewrites map[string]string // IndexFiles specifies the index files for static folder. IndexFiles []string // IndexFolder specifies if listing sub-files when requesting folder. // The server responses HTTP status code 403 if it is false. IndexFolder bool // ServerRoot specifies the root directory for static service. ServerRoot string // SearchPaths specifies additional searching directories for static service. SearchPaths []string // StaticPaths specifies URI to directory mapping array. StaticPaths []staticPathItem // FileServerEnabled is the global switch for static service. // It is automatically set enabled if any static path is set. FileServerEnabled bool // CookieMaxAge specifies the max TTL for cookie items. CookieMaxAge time.Duration // CookiePath specifies cookie path. // It also affects the default storage for session id. CookiePath string // CookieDomain specifies cookie domain. // It also affects the default storage for session id. CookieDomain string // SessionMaxAge specifies max TTL for session items. SessionMaxAge time.Duration // SessionIdName specifies the session id name. SessionIdName string // SessionPath specifies the session storage directory path for storing session files. // It only makes sense if the session storage is type of file storage. SessionPath string // SessionStorage specifies the session storage. SessionStorage gsession.Storage // Logger specifies the logger for server. Logger *glog.Logger // LogPath specifies the directory for storing logging files. LogPath string // LogStdout specifies whether printing logging content to stdout. LogStdout bool // ErrorStack specifies whether logging stack information when error. ErrorStack bool // ErrorLogEnabled enables error logging content to files. ErrorLogEnabled bool // ErrorLogPattern specifies the error log file pattern like: error-{Ymd}.log ErrorLogPattern string // AccessLogEnabled enables access logging content to files. AccessLogEnabled bool // AccessLogPattern specifies the error log file pattern like: access-{Ymd}.log AccessLogPattern string // PProfEnabled enables PProf feature. PProfEnabled bool // PProfPattern specifies the PProf service pattern for router. PProfPattern string // ClientMaxBodySize specifies the max body size limit in bytes for client request. // It can be configured in configuration file using string like: 1m, 10m, 500kb etc. // It's 8MB in default. ClientMaxBodySize int64 // FormParsingMemory specifies max memory buffer size in bytes which can be used for // parsing multimedia form. // It can be configured in configuration file using string like: 1m, 10m, 500kb etc. // It's 1MB in default. FormParsingMemory int64 // NameToUriType specifies the type for converting struct method name to URI when // registering routes. NameToUriType int // RouteOverWrite allows overwrite the route if duplicated. RouteOverWrite bool // DumpRouterMap specifies whether automatically dumps router map when server starts. DumpRouterMap bool // Graceful enables graceful reload feature for all servers of the process. Graceful bool }
ServerConfig is the HTTP Server configuration manager.
func Config ¶
func Config() ServerConfig
Config creates and returns a ServerConfig object with default configurations. Note that, do not define this default configuration to local package variable, as there're some pointer attributes that may be shared in different servers.
func ConfigFromMap ¶
func ConfigFromMap(m map[string]interface{}) (ServerConfig, error)
ConfigFromMap creates and returns a ServerConfig object with given map and default configuration object.
type StaticFile ¶
type StaticFile struct { File *gres.File // Resource file object. Path string // File path. IsDir bool // Is directory. }
StaticFile is the file struct for static file service.
type UploadFile ¶
type UploadFile struct {
*multipart.FileHeader
}
UploadFile wraps the multipart uploading file with more and convenient features.
func (*UploadFile) Save ¶
func (f *UploadFile) Save(dirPath string, randomlyRename ...bool) (filename string, err error)
Save saves the single uploading file to directory path and returns the saved file name.
The parameter <dirPath> should be a directory path or it returns error.
Note that it will OVERWRITE the target file if there's already a same name file exist.
type UploadFiles ¶
type UploadFiles []*UploadFile
UploadFiles is array type for *UploadFile.
func (UploadFiles) Save ¶
func (fs UploadFiles) Save(dirPath string, randomlyRename ...bool) (filenames []string, err error)
Save saves all uploading files to specified directory path and returns the saved file names.
The parameter <dirPath> should be a directory path or it returns error.
The parameter <randomlyRename> specifies whether randomly renames all the file names.
Source Files ¶
- ghttp.go
- ghttp_client_api.go
- ghttp_client_bytes.go
- ghttp_client_chain.go
- ghttp_client_config.go
- ghttp_client_content.go
- ghttp_client_dump.go
- ghttp_client_request.go
- ghttp_client_response.go
- ghttp_controller.go
- ghttp_func.go
- ghttp_request.go
- ghttp_request_auth.go
- ghttp_request_middleware.go
- ghttp_request_param.go
- ghttp_request_param_ctx.go
- ghttp_request_param_file.go
- ghttp_request_param_form.go
- ghttp_request_param_page.go
- ghttp_request_param_param.go
- ghttp_request_param_post.go
- ghttp_request_param_query.go
- ghttp_request_param_request.go
- ghttp_request_param_router.go
- ghttp_request_view.go
- ghttp_response.go
- ghttp_response_cors.go
- ghttp_response_view.go
- ghttp_response_write.go
- ghttp_response_writer.go
- ghttp_server.go
- ghttp_server_admin.go
- ghttp_server_admin_process.go
- ghttp_server_admin_unix.go
- ghttp_server_config.go
- ghttp_server_config_cookie.go
- ghttp_server_config_logging.go
- ghttp_server_config_mess.go
- ghttp_server_config_route.go
- ghttp_server_config_session.go
- ghttp_server_config_static.go
- ghttp_server_cookie.go
- ghttp_server_domain.go
- ghttp_server_error_logger.go
- ghttp_server_graceful.go
- ghttp_server_handler.go
- ghttp_server_log.go
- ghttp_server_plugin.go
- ghttp_server_pprof.go
- ghttp_server_router.go
- ghttp_server_router_group.go
- ghttp_server_router_hook.go
- ghttp_server_router_middleware.go
- ghttp_server_router_serve.go
- ghttp_server_service_controller.go
- ghttp_server_service_handler.go
- ghttp_server_service_object.go
- ghttp_server_session.go
- ghttp_server_status.go
- ghttp_server_websocket.go