1 Star 0 Fork 13

tadpole/HxGo

forked from 傅小黑/GoInk 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
request.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
package hxgo
import (
"net/http"
"path"
"strings"
"mime/multipart"
)
// request object
type Request struct {
Raw *http.Request
Param []string
Url string
Method string
Host string
Uri string
RemoteAddr string
TLS bool
Ip string
UserAgent string
Refer string
Suffix string
}
// init request, fill properties
func (this *Request) init() {
this.Url = this.Raw.URL.Path
this.Method = this.Raw.Method
this.Host = this.Raw.URL.Host
this.Uri = this.Raw.RequestURI
this.RemoteAddr = this.Raw.RemoteAddr
this.TLS = this.Raw.TLS == nil
this.Ip = strings.Split(this.Raw.RemoteAddr, ":")[0]
this.UserAgent = this.Raw.UserAgent()
this.Refer = this.Raw.Referer()
this.Suffix = path.Ext(this.Url)
}
// get request header
func (this *Request) Header(key string) string {
return this.Raw.Header.Get(key)
}
// get request cookie value
func (this *Request) Cookie(name string) string {
c, e := this.Raw.Cookie(name)
if e != nil {
return ""
}
return c.Value
}
// check isAjax request
func (this *Request) IsAjax() bool {
return this.Header("X-Requested-With") == "XMLHttpRequest"
}
// get uploaded file by key string
func (this *Request) File(key string) (multipart.File, *multipart.FileHeader, error) {
this.Raw.ParseMultipartForm(32<<20)
return this.Raw.FormFile(key)
}
// create new request object
func NewRequested(r *http.Request) *Request {
req := &Request{Raw:r}
req.init()
return req
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tadpole/hxgo.git
git@gitee.com:tadpole/hxgo.git
tadpole
hxgo
HxGo
master

搜索帮助