Documentation
¶
Overview ¶
* 暴力破解監控 * 舉例:同一個對/login,在一段時間内報錯多次,判定暴力破解,禁用IP 24小時 * 設定:1分鐘內,10次錯誤,則禁用IP 24小時
限流器 基於IP的限流器,如果1秒内出現100請求都是404,則封禁IP 5分鐘
Index ¶
- type Apper
- func (this *Apper) Close()
- func (this *Apper) Get(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
- func (this *Apper) GetClientIP(r *http.Request) string
- func (this *Apper) Logger()
- func (this *Apper) Post(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
- func (this *Apper) Print(key string)
- func (this *Apper) Route(method string, path string, f http.HandlerFunc, mid ...MiddlewareFunc)
- func (this *Apper) Run()
- func (this *Apper) RunTLS(certFile, keyFile string)
- func (this *Apper) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (this *Apper) SetConfig()
- func (this *Apper) SetLog()
- func (this *Apper) SetPort()
- func (this *Apper) SetRate()
- func (this *Apper) SetStatic()
- func (this *Apper) Use(middleware ...MiddlewareFunc)
- type Bruter
- type BruterIP
- type Cacher
- type Configer
- type FileUploader
- type IpData
- type Jwter
- func (this *Jwter) Decode(token string) (string, error)
- func (this *Jwter) Encode() (string, error)
- func (this *Jwter) GetArr(tokenstr string) ([]string, error)
- func (this *Jwter) GetJoin(key string, exp string, code string) (string, error)
- func (this *Jwter) OneToTwo(val string) string
- func (this *Jwter) Validate(token string) error
- type MiddlewareFunc
- type Rater
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Apper ¶
type Apper struct {
// 配置信息结构体指针
// Configuration information struct pointer
Config *Configer
// contains filtered or unexported fields
}
Apper 是应用程序的主结构体,包含路由映射、配置信息、端口、日志等信息 Apper is the main struct of the application, containing route mappings, configuration information, port, logs, etc.
func (*Apper) Close ¶
func (this *Apper) Close()
Close 关闭应用程序资源,包括日志文件和消息通道 Close closes application resources, including log file and message channel
func (*Apper) Get ¶
func (this *Apper) Get(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
Get 注册GET请求的路由处理函数 Get registers the route handler function for GET requests
func (*Apper) GetClientIP ¶
GetClientIP 获取客户端真实IP地址 GetClientIP get client real IP address
func (*Apper) Logger ¶
func (this *Apper) Logger()
Logger 处理日志记录,监听消息通道并将日志写入文件或控制台 Logger handles log recording, listens to the message channel and writes logs to file or console
func (*Apper) Post ¶
func (this *Apper) Post(path string, f http.HandlerFunc, mid ...MiddlewareFunc)
Post 注册POST请求的路由处理函数 Post registers the route handler function for POST requests
func (*Apper) Route ¶
func (this *Apper) Route(method string, path string, f http.HandlerFunc, mid ...MiddlewareFunc)
Route 注册指定HTTP方法的路由处理函数 Route registers the route handler function for the specified HTTP method
func (*Apper) ServeHTTP ¶
func (this *Apper) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP 实现http.Handler接口,处理HTTP请求 ServeHTTP implements the http.Handler interface to handle HTTP requests
func (*Apper) SetConfig ¶
func (this *Apper) SetConfig()
SetConfig 从config.ini文件中读取配置信息 SetConfig reads configuration information from config.ini file
func (*Apper) SetLog ¶
func (this *Apper) SetLog()
SetLog 根据配置设置日志记录器 SetLog sets up the logger according to configuration
func (*Apper) SetPort ¶
func (this *Apper) SetPort()
SetPort 从配置中设置服务器端口,默认为8080 SetPort sets the server port from configuration, default is 8080
func (*Apper) SetRate ¶ added in v1.1.0
func (this *Apper) SetRate()
SetLimit 設置限流 SetLimit set rate limiting
func (*Apper) SetStatic ¶ added in v1.1.5
func (this *Apper) SetStatic()
SetStatic 设置静态文件目录 SetStatic sets the static file directory
func (*Apper) Use ¶
func (this *Apper) Use(middleware ...MiddlewareFunc)
全局中間件處理 Global middleware processing
type Bruter ¶ added in v1.1.2
type Bruter struct {
// 1分鐘內,10次錯誤,則禁用IP 24小時
MaxIp int // 監控IP數量
MaxErr int // 監控錯誤數量
MaxTime int // 監控時間秒
ErrIps map[string]*BruterIP
BlockIps map[string]time.Time
sync.RWMutex
}
func (*Bruter) GetClientIP ¶ added in v1.1.2
獲得IP
type Cacher ¶
type Cacher struct {
// contains filtered or unexported fields
}
type FileUploader ¶
type FileUploader struct {
MaxSize int64
AllowedTypes []string
SavePath string
MaxFiles int //一次最大上传文件数量
FieldName string // 添加单文件字段名
FieldNames string // 添加多文件字段名
Keyword string // 添加文件名关键字
}
func NewFileUploader ¶
func NewFileUploader(maxSize int64, allowedTypes []string, savePath string) *FileUploader
func (*FileUploader) HandleUpload ¶
func (f *FileUploader) HandleUpload(r *http.Request) ([]string, error)
HandleUpload 修改为支持批量文件上传
