Documentation ¶
Overview ¶
Package http implements http protocol, provide service that cab be called by api.
Index ¶
- Variables
- func AccessLogMiddleware() gin.HandlerFunc
- func ConfigContextMiddleware(db *gorm.DB) gin.HandlerFunc
- func DirectoryListHandler(ctx *gin.Context)
- func FileCreateHandler(ctx *gin.Context)
- func FileDeleteHandler(ctx *gin.Context)
- func FileReadHandler(ctx *gin.Context)
- func FileUpdateHandler(ctx *gin.Context)
- func ParseAppMiddleware() gin.HandlerFunc
- func ParseTokenMiddleware() gin.HandlerFunc
- func RateLimitByIPMiddleware(interval time.Duration, maxNumber int) gin.HandlerFunc
- func RecordRequestMiddleware() gin.HandlerFunc
- func ReplayAttackMiddleware() gin.HandlerFunc
- func Routers() *gin.Engine
- func SignStrWithSecret(paramStr, secret string) string
- func SignWithAppMiddleware(input interface{}) gin.HandlerFunc
- func SignWithTokenMiddleware(input interface{}) gin.HandlerFunc
- func TokenCreateHandler(ctx *gin.Context)
- func TokenDeleteHandler(ctx *gin.Context)
- func TokenUpdateHandler(ctx *gin.Context)
- func ValidateRequestSignature(ctx *gin.Context, secret string) bool
- type AppUIDInput
- type NonceInput
- type Response
- type TokenInput
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidSortTypes = errors.New("invalid sort types, only one of type, -type, name, -name, time and -time")
ErrInvalidSortTypes represents invalid sort types
var ErrWrongHTTPRange = errors.New("wrong http range header, start must be less than end")
ErrWrongHTTPRange represent wrong http range header
var ErrWrongRangeHeader = errors.New("http range header format error")
ErrWrongRangeHeader represent the http range header format error
var GetParamsSignBody = getParamsSignBody
GetParamsSignBody is used to export getParamsSignBody, sign the params and get the http post body
var GetParamsSignature = getParamsSignature
GetParamsSignature is used to get the signature of the params.
Functions ¶
func AccessLogMiddleware ¶
func AccessLogMiddleware() gin.HandlerFunc
AccessLogMiddleware just wrap gin.LoggerWithFormatter
func ConfigContextMiddleware ¶
func ConfigContextMiddleware(db *gorm.DB) gin.HandlerFunc
ConfigContextMiddleware will config context for each request. such as: db connection
func DirectoryListHandler ¶
DirectoryListHandler is used to list a directory
func FileCreateHandler ¶
FileCreateHandler is used to create file or directory
func FileDeleteHandler ¶
FileDeleteHandler is used to delete a file or a directory
func FileReadHandler ¶
FileReadHandler is used to handle file read request
func FileUpdateHandler ¶
FileUpdateHandler is used to handle file update request
func ParseAppMiddleware ¶
func ParseAppMiddleware() gin.HandlerFunc
ParseAppMiddleware will parse request context to get an app. It's should be put behind RecordRequestMiddleware
func ParseTokenMiddleware ¶
func ParseTokenMiddleware() gin.HandlerFunc
ParseTokenMiddleware is used to parse request context and get a token It's should be put behind RecordRequestMiddleware
func RateLimitByIPMiddleware ¶
func RateLimitByIPMiddleware(interval time.Duration, maxNumber int) gin.HandlerFunc
RateLimitByIPMiddleware will record requests number by ip, avoid floor attack. It's should put behind RecordRequestMiddleware
func RecordRequestMiddleware ¶
func RecordRequestMiddleware() gin.HandlerFunc
RecordRequestMiddleware is used to record request in database. It's should be put behind ConfigContextMiddleware
func ReplayAttackMiddleware ¶
func ReplayAttackMiddleware() gin.HandlerFunc
ReplayAttackMiddleware is used to avoid request replay attack. We recommend that you should provide a 'nonce' value for request in all of 'UPDATE' request. But for 'QUERY' request, you should not add this. Of course, if you want to do this, bigfile allow that.
For developers, this middleware should be put behind ParseAppMiddleware or ParseTokenMiddleware, we need appId to validate this.
func SignStrWithSecret ¶
SignStrWithSecret will calculate the sign of request paramStr that has already been sorted and concat together.
func SignWithAppMiddleware ¶
func SignWithAppMiddleware(input interface{}) gin.HandlerFunc
SignWithAppMiddleware will validate request signature of request. It's should be put behind ParseAppMiddleware
func SignWithTokenMiddleware ¶
func SignWithTokenMiddleware(input interface{}) gin.HandlerFunc
SignWithTokenMiddleware will validate request signature of request. It's should be put behind SignWithTokenMiddleware
func TokenCreateHandler ¶
TokenCreateHandler is used to handle token create http request
func TokenDeleteHandler ¶
TokenDeleteHandler is used to delete a token
func TokenUpdateHandler ¶
TokenUpdateHandler is used to handle request for update token
Types ¶
type AppUIDInput ¶
type AppUIDInput struct {
AppUID string `form:"appUid" binding:"required"`
}
AppUIDInput represent 'AppUid' request param
type NonceInput ¶
type NonceInput struct {
Nonce *string `form:"nonce" header:"X-Request-Nonce" binding:"omitempty,min=32,max=48"`
}
NonceInput represent `nonce` request param
type Response ¶
type Response struct { RequestID int64 `json:"requestId"` Success bool `json:"success"` Errors map[string][]string `json:"errors"` Data interface{} `json:"data"` }
Response represent http response for client
type TokenInput ¶
type TokenInput struct {
Token string `form:"token" binding:"required"`
}
TokenInput represent `token` request param