Documentation ¶
Index ¶
- Constants
- Variables
- func AddMetaKvs(c *gin.Context, key, value string)
- func Download(c *gin.Context, mimeType MimeType, filename string, content []byte) error
- func Error(c *gin.Context, code int, msg string)
- func Failure(c *gin.Context, err error)
- func Forbidden(c *gin.Context, err error)
- func GetAuthorizationToken(c *gin.Context) (string, error)
- func GetMetaKvs(c *gin.Context) []string
- func GetPagination(c *gin.Context, args ...int64) *pagination.Pagination
- func GetRealIP(c *gin.Context) string
- func InvalidRequest(c *gin.Context, err error)
- func IsPrivateIp(ipStr string) bool
- func NewRouter(logger types.LogProvider) *gin.Engine
- func PermanentRedirect(c *gin.Context, location string)
- func Redirect(c *gin.Context, location string)
- func SetDebugMode()
- func SetReleaseMode()
- func SetTestMode()
- func Success(c *gin.Context, args ...interface{})
- func SuccessPages(c *gin.Context, total int64, pages interface{})
- func SuccessRaw(c *gin.Context, result interface{})
- func Unauthorized(c *gin.Context, err error)
- type HttpMethod
- type HttpServer
- func (srv *HttpServer) AddGroupRoutes(groupName string, routes []*Route) error
- func (srv *HttpServer) AddRoutes(routes []*Route)
- func (srv *HttpServer) CreateRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) error
- func (srv *HttpServer) GetRouterGroup(groupName string) *gin.RouterGroup
- func (srv *HttpServer) NewRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) (*gin.RouterGroup, error)
- func (srv *HttpServer) Run()
- type HttpsServer
- type MimeType
- type PageResponse
- type PaginationParam
- type Response
- type Route
- type WebServer
Constants ¶
View Source
const DefaultPageSize = 10
Variables ¶
View Source
var ( ErrTokenNotFound = errors.New("token not found") ErrInvalidHttpAuthorizationHeader = errors.New("invalid http authorization header") )
View Source
var ( ErrDuplicateRouterGroup = errors.New("duplicate router group") ErrRouterGroupNotFound = errors.New("router group not found") )
View Source
var (
HttpContentTypes = map[MimeType]string{
MimeTypeBinary: "application/octet-stream",
MimeTypePDF: "application/pdf",
MimeTypeMSWord: "application/msword",
MimeTypeJPEG: "image/jpeg",
}
)
View Source
var SkipHttpMethods = []string{
"PRI",
"HEAD",
}
Functions ¶
func GetAuthorizationToken ¶
GetAuthorizationToken get bearer token or other token from http header
func GetPagination ¶
func GetPagination(c *gin.Context, args ...int64) *pagination.Pagination
GetPagination get *Pagination args[0] is default page size then you can use pagination.Paging or pagination.GetSQLClause(total) 去获取分页的limit子句
func InvalidRequest ¶
func PermanentRedirect ¶
func Success ¶
Success respond with data empty args respond with 'ok' message args[0] is the response data
func SuccessPages ¶
SuccessPages respond with pagination data
func SuccessRaw ¶
SuccessRaw respond with raw data
func Unauthorized ¶
Types ¶
type HttpServer ¶
func (*HttpServer) AddGroupRoutes ¶
func (srv *HttpServer) AddGroupRoutes(groupName string, routes []*Route) error
func (*HttpServer) AddRoutes ¶
func (srv *HttpServer) AddRoutes(routes []*Route)
AddRoutes add routes from Route slice
func (*HttpServer) CreateRouterGroup ¶
func (srv *HttpServer) CreateRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) error
CreateRouterGroup create a gin router group
func (*HttpServer) GetRouterGroup ¶
func (srv *HttpServer) GetRouterGroup(groupName string) *gin.RouterGroup
func (*HttpServer) NewRouterGroup ¶
func (srv *HttpServer) NewRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) (*gin.RouterGroup, error)
NewRouterGroup new a gin router group
type HttpsServer ¶
type HttpsServer struct { *HttpServer CertPath string KeyPath string }
func (*HttpsServer) Run ¶
func (srv *HttpsServer) Run()
type MimeType ¶
type MimeType int
const ( MimeTypeBinary MimeType MimeTypeJPEG MimeTypePDF MimeTypeMSWord )
type PageResponse ¶
type PaginationParam ¶
type Route ¶
type Route struct { Method HttpMethod Path string Handler gin.HandlerFunc }
type WebServer ¶
type WebServer interface { Run() NewRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) (*gin.RouterGroup, error) CreateRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) error GetRouterGroup(groupName string) *gin.RouterGroup AddRoutes(routes []*Route) AddGroupRoutes(groupName string, routes []*Route) error }
func NewHttpServer ¶
func NewHttpServer(logger types.LogProvider, address string) WebServer
func NewHttpsServer ¶
func NewHttpsServer(logger types.LogProvider, certPath, keyPath, address string) (WebServer, error)
Click to show internal directories.
Click to hide internal directories.