Documentation ¶
Index ¶
- Constants
- Variables
- func Base(next http.Handler) http.Handler
- func BaseFunc(next http.Handler) http.HandlerFunc
- func CorsHandler() gin.HandlerFunc
- func GetClientIp(r *http.Request) string
- func GetCookie(r *http.Request, name string) (*http.Cookie, error)
- func GetCookieVal(r *http.Request, name string) string
- func GetFromArg(r *http.Request, name string) string
- func GetFromFile(r *http.Request, name string) (multipart.File, *multipart.FileHeader, error)
- func GetHeader(r *http.Request, name string) string
- func GetIP(r *http.Request) (ip string)
- func GetIp(r *http.Request) (ip string)
- func GetJsonParam(r *http.Request, param interface{})
- func GetUrlArg(r *http.Request, name string) string
- func GetUrlArgInt(r *http.Request, name string) int
- func GetUrlArgInt64(r *http.Request, name string) int64
- func Health(w http.ResponseWriter, r *http.Request)
- func Hello(w http.ResponseWriter, r *http.Request)
- func Out404(w http.ResponseWriter)
- func OutErrBody(w http.ResponseWriter, code int, err error)
- func OutJPG(w http.ResponseWriter, path string)
- func OutPdf(w http.ResponseWriter, path string)
- func OutStaticFile(w http.ResponseWriter, path string)
- func OutSucceedBody(w http.ResponseWriter, data interface{})
- func OutSucceedBodyJsonP(w http.ResponseWriter, data interface{})
- func OutUploadFile(w http.ResponseWriter, path, fileName string)
- func ReqLimit(ipv *IpVisitor, nextHeader http.Handler) http.Handler
- func SetCookie(w http.ResponseWriter, name, value string, t int)
- func SetCookieMap(w http.ResponseWriter, data map[string]string, t int)
- func SetSockOptInt() net.ListenConfig
- type Engine
- func (engine *Engine) GetMux() *http.ServeMux
- func (engine *Engine) OpenPprof()
- func (engine *Engine) Router(path string, f func(w http.ResponseWriter, r *http.Request))
- func (engine *Engine) RouterFunc(path string, f func(w http.ResponseWriter, r *http.Request))
- func (engine *Engine) Run(port string)
- type HttpOutBody
- type IpVisitor
- func (ipv *IpVisitor) AddBlackList(ip string)
- func (ipv *IpVisitor) AddVisitor(ip string) *rate.Limiter
- func (ipv *IpVisitor) AddWhiteList(ip string)
- func (ipv *IpVisitor) CleanupVisitors()
- func (ipv *IpVisitor) DelBlackList(ip string)
- func (ipv *IpVisitor) DelWhiteList(ip string)
- func (ipv *IpVisitor) GetVisitor(ip string) *rate.Limiter
- func (ipv *IpVisitor) IsBlackList(ip string) (ok bool)
- func (ipv *IpVisitor) IsWhiteList(ip string) (ok bool)
- type ResponseWriter
Constants ¶
View Source
const ( BodyJSON = "application/json; charset=utf-8" BodyAsciiJSON = "application/json" BodyHTML = "text/html; charset=utf-8" BodyJavaScript = "application/javascript; charset=utf-8" BodyXML = "application/xml; charset=utf-8" BodyPlain = "text/plain; charset=utf-8" BodyYAML = "application/x-yaml; charset=utf-8" BodyDownload = "application/octet-stream; charset=utf-8" BodyPDF = "application/pdf" BodyJPG = "image/jpeg" BodyPNG = "image/png" BodyGif = "image/gif" BodyWord = "application/msword" BodyOctet = "application/octet-stream" )
View Source
const Logo = `` /* 166-byte string literal not displayed */
Variables ¶
View Source
var Path, _ = os.Getwd()
Functions ¶
func GetClientIp ¶
func GetFromFile ¶
func GetIP ¶
GetIP 获取ip - X-Real-IP:只包含客户端机器的一个IP,如果为空,某些代理服务器(如Nginx)会填充此header。 - X-Forwarded-For:一系列的IP地址列表,以,分隔,每个经过的代理服务器都会添加一个IP。 - RemoteAddr:包含客户端的真实IP地址。 这是Web服务器从其接收连接并将响应发送到的实际物理IP地址。 但是,如果客户端通过代理连接,它将提供代理的IP地址。
RemoteAddr是最可靠的,但是如果客户端位于代理之后或使用负载平衡器或反向代理服务器时,它将永远不会提供正确的IP地址,因此顺序是先是X-REAL-IP, 然后是X-FORWARDED-FOR,然后是 RemoteAddr。 请注意,恶意用户可以创建伪造的X-REAL-IP和X-FORWARDED-FOR标头。
func GetJsonParam ¶
func Out404 ¶
func Out404(w http.ResponseWriter)
func OutErrBody ¶
func OutErrBody(w http.ResponseWriter, code int, err error)
func OutJPG ¶
func OutJPG(w http.ResponseWriter, path string)
func OutPdf ¶
func OutPdf(w http.ResponseWriter, path string)
func OutSucceedBody ¶
func OutSucceedBody(w http.ResponseWriter, data interface{})
func OutSucceedBodyJsonP ¶
func OutSucceedBodyJsonP(w http.ResponseWriter, data interface{})
func OutUploadFile ¶
func OutUploadFile(w http.ResponseWriter, path, fileName string)
OutUploadFile 给客户端下载的静态文件
func SetCookieMap ¶
func SetCookieMap(w http.ResponseWriter, data map[string]string, t int)
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func SimpleEngine ¶
func SimpleEngine() *Engine
func (*Engine) RouterFunc ¶
type HttpOutBody ¶
type HttpOutBody struct { Code int `json:"code"` Timestamp int64 `json:"timestamp"` Msg string `json:"msg"` Data interface{} `json:"data"` }
HttpOutBody HTTP 输出 json body 定义 [Code] - 0 成功 - 1001 参数错误 - 2001 程序错误
func (*HttpOutBody) JsonStr ¶
func (m *HttpOutBody) JsonStr() (string, error)
type IpVisitor ¶
type IpVisitor struct { BlackList map[string]struct{} WhiteList map[string]struct{} // contains filtered or unexported fields }
func NewIpVisitor ¶
func NewIpVisitor() *IpVisitor
func (*IpVisitor) AddBlackList ¶
func (*IpVisitor) AddWhiteList ¶
func (*IpVisitor) CleanupVisitors ¶
func (ipv *IpVisitor) CleanupVisitors()
CleanupVisitors 启动一个协成 10分钟查一下ip限流数据,看看有没有超过1小时删除记录,有就删除 主要目的的为了释放内存空间
func (*IpVisitor) DelBlackList ¶
func (*IpVisitor) DelWhiteList ¶
func (*IpVisitor) IsBlackList ¶
func (*IpVisitor) IsWhiteList ¶
type ResponseWriter ¶
type ResponseWriter struct { http.ResponseWriter StatusCode int }
func NewResponseWriter ¶
func NewResponseWriter(w http.ResponseWriter) *ResponseWriter
func (*ResponseWriter) WriteHeader ¶
func (lrw *ResponseWriter) WriteHeader(code int)
Click to show internal directories.
Click to hide internal directories.