http

package
v1.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package http implements http protocol, provide service that cab be called by api.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSortTypes = errors.New("invalid sort types, only one of type, -type, name, -name, time and -time")

ErrInvalidSortTypes represents invalid sort types

View Source
var ErrWrongHTTPRange = errors.New("wrong http range header, start must be less than end")

ErrWrongHTTPRange represent wrong http range header

View Source
var ErrWrongRangeHeader = errors.New("http range header format error")

ErrWrongRangeHeader represent the http range header format error

View Source
var GetParamsSignBody = getParamsSignBody

GetParamsSignBody is used to export getParamsSignBody, sign the params and get the http post body

View Source
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

func DirectoryListHandler(ctx *gin.Context)

DirectoryListHandler is used to list a directory

func FileCreateHandler

func FileCreateHandler(ctx *gin.Context)

FileCreateHandler is used to create file or directory

func FileDeleteHandler

func FileDeleteHandler(ctx *gin.Context)

FileDeleteHandler is used to delete a file or a directory

func FileReadHandler

func FileReadHandler(ctx *gin.Context)

FileReadHandler is used to handle file read request

func FileUpdateHandler

func FileUpdateHandler(ctx *gin.Context)

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 Routers

func Routers() *gin.Engine

Routers will define all routers for service

func SignStrWithSecret

func SignStrWithSecret(paramStr, secret string) string

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

func TokenCreateHandler(ctx *gin.Context)

TokenCreateHandler is used to handle token create http request

func TokenDeleteHandler

func TokenDeleteHandler(ctx *gin.Context)

TokenDeleteHandler is used to delete a token

func TokenUpdateHandler

func TokenUpdateHandler(ctx *gin.Context)

TokenUpdateHandler is used to handle request for update token

func ValidateRequestSignature

func ValidateRequestSignature(ctx *gin.Context, secret string) bool

ValidateRequestSignature will validate the signature of request

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL