Documentation ¶
Index ¶
- Variables
- func DownloadInternetImage(url string, UserAgent string, Referer string, dynamicDirName string) string
- func DownloadInternetImageTemp(url string, UserAgent string, Referer string) string
- func GetDeviceName(UserAgent string) string
- func GetIP(request *http.Request) string
- func IsFileExist(path string) bool
- func NewFuncMap(context *Context) template.FuncMap
- func NewStaticController(rootPath, dir string)
- func QueryParams(m url.Values) map[string]string
- func RegisterFunction(funcName string, function IFunc)
- func RegisterWidget(funcName string, widget IWidget)
- func RequestByHeader(url string, UserAgent string, Referer string) (error, *http.Response, []byte)
- func WriteFile(fileBytes []byte, ContentType string, dynamicDirName, dirType string) string
- func WriteFilePath(fileBytes []byte, dynamicDirName, dirType string, fileName string) (error, string)
- func WriteTempFile(fileBytes []byte, ContentType string) string
- func WriteTempUrlNameFile(b []byte, Url string) string
- func WriteWithFile(file multipart.File, header *multipart.FileHeader, dynamicDirName string, ...) (error, string)
- type Attributes
- func (att *Attributes) Delete(key AttributesKey)
- func (att *Attributes) Get(key AttributesKey) interface{}
- func (att *Attributes) GetMap() map[string]interface{}
- func (att *Attributes) GetOrPut(key AttributesKey, value interface{}) (actual interface{}, loaded bool)
- func (att *Attributes) Put(key AttributesKey, value interface{})
- type AttributesKey
- type CacheConfig
- type Context
- type Controller
- func (c *Controller) AddHandler(routePath string, call IHandler) IController
- func (c *Controller) AddInterceptor(value Interceptor) IController
- func (c *Controller) AddStaticHandler(function *Function)
- func (c *Controller) DefaultHandle(call IHandler) IController
- func (c *Controller) NewController(actionName string) IController
- func (c *Controller) NotFoundHandler(call IHandler) IController
- type EmptyResult
- type ErrorResult
- type FileDirType
- type FileServerResult
- type FuncObject
- type Function
- type HTMLResult
- type HtmlPlainResult
- type IController
- type IFunc
- type IFuncResult
- type IHandler
- type IHandlerConnect
- type IHandlerDelete
- type IHandlerGet
- type IHandlerHead
- type IHandlerOptions
- type IHandlerPatch
- type IHandlerPost
- type IHandlerPut
- type IHandlerTrace
- type IWidget
- type ImageBytesResult
- type ImageResult
- type Interceptor
- type InterceptorFlow
- type Interceptors
- type JavaScriptResult
- type JsonResult
- type MIME
- type NotFoundHandler
- type RedirectToUrlResult
- type Result
- type ServiceConfig
- type Session
- type SessionSafeMap
- type SingleHostForwardProxyResult
- type SingleHostReverseProxyResult
- type TextResult
- type ViewActionMappingResult
- type ViewResult
- type XMLResult
Constants ¶
This section is empty.
Variables ¶
var AppRouter = mux.NewRouter()
var Sessions = &SessionSafeMap{}
Functions ¶
func DownloadInternetImage ¶ added in v1.3.0
func DownloadInternetImageTemp ¶ added in v1.3.0
func GetDeviceName ¶ added in v1.3.0
Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Mobile Safari/537.36 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36 Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1
func IsFileExist ¶ added in v1.3.0
func NewFuncMap ¶ added in v1.2.16
func NewStaticController ¶ added in v1.2.19
func NewStaticController(rootPath, dir string)
func RegisterFunction ¶ added in v1.3.0
func RegisterWidget ¶ added in v1.3.0
func RequestByHeader ¶ added in v1.3.0
func RequestByHeader(url string, UserAgent string, Referer string) ([]byte,error) {
client := http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { return nil,err } //req.Header.Add("User-Agent","Mozilla/5.0 (Linux; Android 7.0; SLA-AL00 Build/HUAWEISLA-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044109 Mobile Safari/537.36 MicroMessenger/6.6.7.1321(0x26060739) NetType/WIFI Language/zh_CN") if !strings.EqualFold(UserAgent, "") { req.Header.Add("User-Agent", UserAgent) } if !strings.EqualFold(Referer, "") { req.Header.Add("Referer", Referer) } resp, err := client.Do(req) if err != nil { return nil,err } defer resp.Body.Close() b, err := ioutil.ReadAll(resp.Body) return b,err
}
func WriteFilePath ¶ added in v1.3.0
func WriteTempFile ¶ added in v1.3.0
func WriteTempUrlNameFile ¶ added in v1.3.0
func WriteWithFile ¶ added in v1.3.0
Types ¶
type Attributes ¶
type Attributes struct {
// contains filtered or unexported fields
}
func (*Attributes) Delete ¶
func (att *Attributes) Delete(key AttributesKey)
func (*Attributes) Get ¶
func (att *Attributes) Get(key AttributesKey) interface{}
func (*Attributes) GetMap ¶
func (att *Attributes) GetMap() map[string]interface{}
func (*Attributes) GetOrPut ¶
func (att *Attributes) GetOrPut(key AttributesKey, value interface{}) (actual interface{}, loaded bool)
func (*Attributes) Put ¶
func (att *Attributes) Put(key AttributesKey, value interface{})
type AttributesKey ¶ added in v1.3.0
type AttributesKey string
func (AttributesKey) String ¶ added in v1.3.0
func (ak AttributesKey) String() string
type CacheConfig ¶ added in v1.2.17
type Context ¶
type Controller ¶ added in v1.2.19
type Controller struct { RoutePath string //定义路由的路径 Interceptors *Interceptors // ParentController *Controller // Router *mux.Router //dir ViewSubDir string // }
func (*Controller) AddHandler ¶ added in v1.2.19
func (c *Controller) AddHandler(routePath string, call IHandler) IController
func (*Controller) AddInterceptor ¶ added in v1.3.0
func (c *Controller) AddInterceptor(value Interceptor) IController
func (*Controller) AddStaticHandler ¶ added in v1.2.19
func (c *Controller) AddStaticHandler(function *Function)
func (*Controller) DefaultHandle ¶ added in v1.2.19
func (c *Controller) DefaultHandle(call IHandler) IController
func (*Controller) NewController ¶ added in v1.2.19
func (c *Controller) NewController(actionName string) IController
func (*Controller) NotFoundHandler ¶ added in v1.2.20
func (c *Controller) NotFoundHandler(call IHandler) IController
type EmptyResult ¶
type EmptyResult struct { }
func (*EmptyResult) Apply ¶
func (r *EmptyResult) Apply(context *Context)
type ErrorResult ¶
type ErrorResult struct {
Error error
}
func NewErrorResult ¶ added in v1.2.15
func NewErrorResult(err error) *ErrorResult
func (*ErrorResult) Apply ¶
func (r *ErrorResult) Apply(context *Context)
type FileDirType ¶ added in v1.3.0
type FileDirType int32
var FileDirT FileDirType = 1
var FileDirTemp FileDirType = 1
type FileServerResult ¶
func (*FileServerResult) Apply ¶
func (fs *FileServerResult) Apply(context *Context)
http.StripPrefix
type FuncObject ¶ added in v1.2.16
type FuncObject struct {
// contains filtered or unexported fields
}
type Function ¶ added in v1.2.16
type Function struct { RoutePath string Handler IHandler // contains filtered or unexported fields }
func NewFunction ¶ added in v1.2.19
type HTMLResult ¶
type HTMLResult struct { Name string StatusCode int Params map[string]interface{} Template []string //读取当前目录下 template 文件夹下的模板 }
HTMLResult 只映射已经定义的后缀模板文件
func (*HTMLResult) Apply ¶
func (r *HTMLResult) Apply(context *Context)
type HtmlPlainResult ¶
func (*HtmlPlainResult) Apply ¶
func (r *HtmlPlainResult) Apply(context *Context)
type IController ¶
type IController interface { DefaultHandle(call IHandler) IController NotFoundHandler(call IHandler) IController AddHandler(routePath string, call IHandler) IController AddInterceptor(value Interceptor) IController NewController(actionName string) IController }
func NewController ¶ added in v1.2.19
func NewController(rootPath, viewSubDir string) IController
NewController 根目录控制器,非具体的handler
type IFunc ¶ added in v1.3.0
type IFunc interface {
Call(ctx *Context) IFuncResult
}
type IFuncResult ¶ added in v1.3.0
type IFuncResult interface {
Result() interface{}
}
func NewMapFuncResult ¶ added in v1.3.0
func NewMapFuncResult(m map[string]interface{}) IFuncResult
func NewStringArrayFuncResult ¶ added in v1.3.0
func NewStringArrayFuncResult(args []string) IFuncResult
func NewStringFuncResult ¶ added in v1.3.0
func NewStringFuncResult(arg string) IFuncResult
type IHandlerConnect ¶ added in v1.3.0
type IHandlerDelete ¶ added in v1.3.0
type IHandlerGet ¶ added in v1.3.0
type IHandlerHead ¶ added in v1.3.0
type IHandlerOptions ¶ added in v1.3.0
type IHandlerPatch ¶ added in v1.3.0
type IHandlerPost ¶ added in v1.3.0
type IHandlerPut ¶ added in v1.3.0
type IHandlerTrace ¶ added in v1.3.0
type ImageBytesResult ¶
func (*ImageBytesResult) Apply ¶
func (r *ImageBytesResult) Apply(context *Context)
type ImageResult ¶
type ImageResult struct {
FilePath string
}
func (*ImageResult) Apply ¶
func (r *ImageResult) Apply(context *Context)
type Interceptor ¶
type InterceptorFlow ¶ added in v1.2.16
type InterceptorFlow string
const ( InterceptorFlowBreak InterceptorFlow = "BREAK" InterceptorFlowContinue InterceptorFlow = "CONTINUE" )
type Interceptors ¶
type Interceptors struct {
// contains filtered or unexported fields
}
func (*Interceptors) ActionAfter ¶ added in v1.3.0
func (inter *Interceptors) ActionAfter(context *Context, result Result) Result
func (inter *Interceptors) Len() int { if inter == nil { return 0 } if inter.list == nil { return 0 } if len(inter.list) == 0 { return 0 } return len(inter.list) }
func (*Interceptors) ActionBefore ¶ added in v1.3.0
func (inter *Interceptors) ActionBefore(context *Context) (bool, Result)
func (*Interceptors) ActionService ¶ added in v1.3.0
func (inter *Interceptors) ActionService(context *Context) ServiceConfig
func (*Interceptors) AddInterceptor ¶ added in v1.3.0
func (inter *Interceptors) AddInterceptor(value Interceptor)
type JavaScriptResult ¶
type JavaScriptResult struct {
Data string
}
func (*JavaScriptResult) Apply ¶
func (r *JavaScriptResult) Apply(context *Context)
type JsonResult ¶
type JsonResult struct { Data interface{} // contains filtered or unexported fields }
func (*JsonResult) Apply ¶
func (r *JsonResult) Apply(context *Context)
func (r *JsonResult)encodeJson() (error,[]byte) { r.Lock() defer r.Unlock() buffer := &bytes.Buffer{} encoder := json.NewEncoder(buffer) encoder.SetEscapeHTML(false) err := encoder.Encode(r.Data) return err,buffer.Bytes() }
type MIME ¶
type MIME string
const ( MultipartByteranges MIME = "multipart/byteranges" MultipartFormData MIME = "multipart/form-data" AudioWave MIME = "audio/wave" AudioWav MIME = "audio/wav" AudioXWav MIME = "audio/x-wav" AudioWPnWav MIME = "audio/x-pn-wav" AudioWebm MIME = "audio/webm" AudioOgg MIME = "audio/ogg" AudioMpeg MIME = "audio/mpeg" VideoWebm MIME = "video/webm" VideoOgg MIME = "video/ogg" VideoMp4 MIME = "video/mp4" ApplicationOgg MIME = "application/ogg" ApplicationJson MIME = "application/json" ApplicationJavascript MIME = "application/javascript" ApplicationEcmascript MIME = "application/ecmascript" ApplicationOctetStream MIME = "application/octet-stream" ImageGif MIME = "image/gif" ImageJpeg MIME = "image/jpeg" ImagePng MIME = "image/png" ImageSvgXml MIME = "image/svg+xml" TextCss MIME = "text/css" TextHtml MIME = "text/html" TextPlain MIME = "text/plain" )
type NotFoundHandler ¶ added in v1.2.20
type NotFoundHandler struct {
// contains filtered or unexported fields
}
func (*NotFoundHandler) ServeHTTP ¶ added in v1.2.20
func (h *NotFoundHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request)
type RedirectToUrlResult ¶
type RedirectToUrlResult struct {
Url string
}
func (*RedirectToUrlResult) Apply ¶
func (r *RedirectToUrlResult) Apply(context *Context)
type Result ¶
type Result interface {
Apply(context *Context)
}
func FileLoadAction ¶ added in v1.2.20
func (static Static) FileLoad(ctx *Context) Result { path := ctx.Request.URL.Query().Get("path") urldd, err := url.Parse(path) if glog.Error(err) || (strings.EqualFold(urldd.Scheme, "") && strings.EqualFold(urldd.Host, "")) { //dir, _ := filepath.Split(path) http.ServeFile(ctx.Response, ctx.Request, strings.Trim(conf.Config.UploadDir, "/")+"/"+strings.Trim(conf.Config.UploadDirName, "/")+"/"+path) return &EmptyResult{} } return &RedirectToUrlResult{Url: path} }
func (static Static) FileTempLoad(ctx *Context) Result { path := ctx.Request.URL.Query().Get("path") http.ServeFile(ctx.Response, ctx.Request, "temp/"+path) return &EmptyResult{} }
func FileTempLoadAction ¶ added in v1.2.20
type ServiceConfig ¶ added in v1.2.17
type ServiceConfig struct {
CacheConfig CacheConfig
}
type SessionSafeMap ¶
type SessionSafeMap struct {
// contains filtered or unexported fields
}
func (*SessionSafeMap) AddSession ¶
func (s *SessionSafeMap) AddSession(GLSESSIONID string, session *Session)
func (*SessionSafeMap) DeleteSession ¶
func (s *SessionSafeMap) DeleteSession(GLSESSIONID string)
func (*SessionSafeMap) GetSession ¶
func (s *SessionSafeMap) GetSession(GLSESSIONID string) *Session
func (*SessionSafeMap) Range ¶
func (s *SessionSafeMap) Range(f func(key, value interface{}) bool)
type SingleHostForwardProxyResult ¶
func (*SingleHostForwardProxyResult) Apply ¶
func (r *SingleHostForwardProxyResult) Apply(context *Context)
type SingleHostReverseProxyResult ¶
func (*SingleHostReverseProxyResult) Apply ¶
func (r *SingleHostReverseProxyResult) Apply(context *Context)
type TextResult ¶
type TextResult struct {
Data string
}
func (*TextResult) Apply ¶
func (r *TextResult) Apply(context *Context)
type ViewActionMappingResult ¶
type ViewActionMappingResult struct { }
* 类型/子类型 扩展名 application/json json application/envoy evy application/fractals fif application/futuresplash spl application/hta hta application/internet-property-stream acx application/mac-binhex40 hqx application/msword doc application/msword dot application/octet-stream * application/octet-stream bin application/octet-stream class application/octet-stream dms application/octet-stream exe application/octet-stream lha application/octet-stream lzh application/oda oda application/olescript axs application/pdf pdf application/pics-rules prf application/pkcs10 p10 application/pkix-crl crl application/postscript ai application/postscript eps application/postscript ps application/rtf rtf application/set-payment-initiation setpay application/set-registration-initiation setreg application/vnd.ms-excel xla application/vnd.ms-excel xlc application/vnd.ms-excel xlm application/vnd.ms-excel xls application/vnd.ms-excel xlt application/vnd.ms-excel xlw application/vnd.ms-outlook msg application/vnd.ms-pkicertstore sst application/vnd.ms-pkiseccat cat application/vnd.ms-pkistl stl application/vnd.ms-powerpoint pot application/vnd.ms-powerpoint pps application/vnd.ms-powerpoint ppt application/vnd.ms-project mpp application/vnd.ms-works wcm application/vnd.ms-works wdb application/vnd.ms-works wks application/vnd.ms-works wps application/winhlp hlp application/x-bcpio bcpio application/x-cdf cdf application/x-compress z application/x-compressed tgz application/x-cpio cpio application/x-csh csh application/x-director dcr application/x-director dir application/x-director dxr application/x-dvi dvi application/x-gtar gtar application/x-gzip gz application/x-hdf hdf application/x-internet-signup ins application/x-internet-signup isp application/x-iphone iii application/x-javascript js application/x-latex latex application/x-msaccess mdb application/x-mscardfile crd application/x-msclip clp application/x-msdownload dll application/x-msmediaview m13 application/x-msmediaview m14 application/x-msmediaview mvb application/x-msmetafile wmf application/x-msmoney mny application/x-mspublisher pub application/x-msschedule scd application/x-msterminal trm application/x-mswrite wri application/x-netcdf cdf application/x-netcdf nc application/x-perfmon pma application/x-perfmon pmc application/x-perfmon pml application/x-perfmon pmr application/x-perfmon pmw application/x-pkcs12 p12 application/x-pkcs12 pfx application/x-pkcs7-certificates p7b application/x-pkcs7-certificates spc application/x-pkcs7-certreqresp p7r application/x-pkcs7-mime p7c application/x-pkcs7-mime p7m application/x-pkcs7-signature p7s application/x-sh sh application/x-shar shar application/x-shockwave-flash swf application/x-stuffit sit application/x-sv4cpio sv4cpio application/x-sv4crc sv4crc application/x-tar tar application/x-tcl tcl application/x-tex tex application/x-texinfo texi application/x-texinfo texinfo application/x-troff roff application/x-troff t application/x-troff tr application/x-troff-man man application/x-troff-me me application/x-troff-ms ms application/x-ustar ustar application/x-wais-source src application/x-x509-ca-cert cer application/x-x509-ca-cert crt application/x-x509-ca-cert der application/ynd.ms-pkipko pko application/zip zip audio/basic au audio/basic snd audio/mid mid audio/mid rmi audio/mpeg mp3 audio/x-aiff aif audio/x-aiff aifc audio/x-aiff aiff audio/x-mpegurl m3u audio/x-pn-realaudio ra audio/x-pn-realaudio ram audio/x-wav wav image/bmp bmp image/cis-cod cod image/gif gif image/ief ief image/jpeg jpe image/jpeg jpeg image/jpeg jpg image/pipeg jfif image/svg+xml svg image/tiff tif image/tiff tiff image/x-cmu-raster ras image/x-cmx cmx image/x-icon ico image/x-portable-anymap pnm image/x-portable-bitmap pbm image/x-portable-graymap pgm image/x-portable-pixmap ppm image/x-rgb rgb image/x-xbitmap xbm image/x-xpixmap xpm image/x-xwindowdump xwd message/rfc822 mht message/rfc822 mhtml message/rfc822 nws text/css css text/h323 323 text/html htm text/html html text/html stm text/iuls uls text/plain bas text/plain c text/plain h text/plain txt text/richtext rtx text/scriptlet sct text/tab-separated-values tsv text/webviewhtml htt text/x-component htc text/x-setext etx text/x-vcard vcf video/mpeg mp2 video/mpeg mpa video/mpeg mpe video/mpeg mpeg video/mpeg mpg video/mpeg mpv2 video/quicktime mov video/quicktime qt video/x-la-asf lsf video/x-la-asf lsx video/x-ms-asf asf video/x-ms-asf asr video/x-ms-asf asx video/x-msvideo avi video/x-sgi-movie movie x-world/x-vrml flr x-world/x-vrml vrml x-world/x-vrml wrl x-world/x-vrml wrz x-world/x-vrml xaf x-world/x-vrml xof
func (*ViewActionMappingResult) Apply ¶
func (r *ViewActionMappingResult) Apply(context *Context)
type ViewResult ¶
type ViewResult struct { }
不做处理,返回原 Response
func (*ViewResult) Apply ¶
func (r *ViewResult) Apply(context *Context)