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 Failure(c *gin.Context, err error)
- func Forbidden(c *gin.Context)
- 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)
- 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)
- type HttpMethod
- type MimeType
- type MyHttpServer
- func (srv *MyHttpServer) AddGroupRoutes(groupName string, routes []*Route) error
- func (srv *MyHttpServer) AddRoutes(routes []*Route)
- func (srv *MyHttpServer) CreateRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) error
- func (srv *MyHttpServer) GetRouterGroup(groupName string) *gin.RouterGroup
- func (srv *MyHttpServer) Run()
- type MyHttpsServer
- type PageResponse
- type PaginationParam
- type Response
- type Route
Constants ¶
View Source
const ( ErrCodeServerInternal // 内部错误 ErrCodeInvalidRequest // 非法请求 ErrCodeForbidden // 拒绝访问 )
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 = err.New("duplicate router group") ErrRouterGroupNotFound = err.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 MimeType ¶
type MimeType int
const ( MimeTypeBinary MimeType MimeTypeJPEG MimeTypePDF MimeTypeMSWord )
type MyHttpServer ¶
func NewHttpServer ¶
func NewHttpServer(logger types.LogProvider, address string) *MyHttpServer
func (*MyHttpServer) AddGroupRoutes ¶
func (srv *MyHttpServer) AddGroupRoutes(groupName string, routes []*Route) error
func (*MyHttpServer) AddRoutes ¶
func (srv *MyHttpServer) AddRoutes(routes []*Route)
AddRoutes add routes from Route slice
func (*MyHttpServer) CreateRouterGroup ¶
func (srv *MyHttpServer) CreateRouterGroup(name, relativePath string, handlers ...gin.HandlerFunc) error
CreateRouterGroup create a gin router group
func (*MyHttpServer) GetRouterGroup ¶
func (srv *MyHttpServer) GetRouterGroup(groupName string) *gin.RouterGroup
type MyHttpsServer ¶
type MyHttpsServer struct { *MyHttpServer CertPath string KeyPath string }
func NewHttpsServer ¶
func NewHttpsServer(logger types.LogProvider, certPath, keyPath, address string) (*MyHttpsServer, error)
func (*MyHttpsServer) Run ¶
func (srv *MyHttpsServer) Run()
type PageResponse ¶
type PaginationParam ¶
type Route ¶
type Route struct { Method HttpMethod Path string Handler gin.HandlerFunc }
Click to show internal directories.
Click to hide internal directories.