Documentation ¶
Index ¶
- Constants
- Variables
- func GetTiDBConnection(c *gin.Context) *gorm.DB
- func MWConnectTiDB(tidbForwarder *tidb.Forwarder) gin.HandlerFunc
- func MWHandleErrors() gin.HandlerFunc
- func MakeInsufficientPrivilegeError(c *gin.Context)
- func MakeUnauthorizedError(c *gin.Context)
- func NewJWTString(issuer string, data string) (string, error)
- func ParseJWTString(requiredIssuer string, tokenStr string) (string, error)
- func TakeTiDBConnection(c *gin.Context) *gorm.DB
- type APIEmptyResponse
- type APIError
- type Claims
- type NodeKind
- type RequestTargetNode
- type RequestTargetStatistics
- type SessionUser
Constants ¶
const (
// The key that attached the SessionUser in the gin Context.
SessionUserKey = "user"
)
Variables ¶
var ( ErrNS = errorx.NewNamespace("error.api") ErrOther = ErrNS.NewType("other") ErrInsufficientPrivilege = ErrNS.NewType("insufficient_privilege") ErrInvalidRequest = ErrNS.NewType("invalid_request") )
Functions ¶
func GetTiDBConnection ¶
GetTiDBConnection gets the TiDB connection stored in the gin context by `MWConnectTiDB` middleware.
The connection will be closed automatically after all handlers are finished. Thus you must not use it outside the request lifetime. If you want to extend the lifetime, use `TakeTiDBConnection`.
func MWConnectTiDB ¶
func MWConnectTiDB(tidbForwarder *tidb.Forwarder) gin.HandlerFunc
MWConnectTiDB creates a middleware that attaches TiDB connection to the context, according to the identity information attached in the context. If a connection cannot be established, subsequent handlers will be skipped and errors will be generated.
This middleware must be placed after the `MWAuthRequired()` middleware, otherwise it will panic.
func MWHandleErrors ¶
func MWHandleErrors() gin.HandlerFunc
MWHandleErrors creates a middleware that turns (last) error in the context into an APIError json response. In handlers, `c.Error(err)` can be used to attach the error to the context. When error is attached in the context: - The handler can optionally assign the HTTP status code. - The handler must not self-generate a response body.
func MakeUnauthorizedError ¶
func NewJWTString ¶
NewJWTString create a JWT string by given data
func ParseJWTString ¶
ParseJWTString parse the JWT string and return the raw data
func TakeTiDBConnection ¶
TakeTiDBConnection takes out the TiDB connection stored in the gin context by `MWConnectTiDB` middleware. Subsequent handlers in this context cannot access the TiDB connection any more.
The TiDB connection will no longer be closed automatically after all handlers are finished. You must manually close the taken out connection.
Types ¶
type APIEmptyResponse ¶
type APIEmptyResponse struct{}
type Claims ¶
type Claims struct { Data string `json:"data"` jwt.StandardClaims }
Claims is a struct that will be encoded to a JWT.
type RequestTargetNode ¶
type RequestTargetNode struct { Kind NodeKind `json:"kind" gorm:"size:8" example:"tidb"` DisplayName string `json:"display_name" gorm:"size:32" example:"127.0.0.1:4000"` IP string `json:"ip" gorm:"size:32" example:"127.0.0.1"` Port int `json:"port" example:"4000"` }
func (*RequestTargetNode) FileName ¶
func (n *RequestTargetNode) FileName() string
func (*RequestTargetNode) String ¶
func (n *RequestTargetNode) String() string
type RequestTargetStatistics ¶
type RequestTargetStatistics struct { NumTiKVNodes int `json:"num_tikv_nodes"` NumTiDBNodes int `json:"num_tidb_nodes"` NumPDNodes int `json:"num_pd_nodes"` }
func NewRequestTargetStatisticsFromArray ¶
func NewRequestTargetStatisticsFromArray(arr *[]RequestTargetNode) RequestTargetStatistics