rest

package
v0.0.0-...-86d5f22 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package rest rest context

Package rest xxx

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorUnauthorized 错误
	ErrorUnauthorized = errors.New("用户未登入")
)

Functions

func APIResponse

func APIResponse(c *Context, data interface{})

APIResponse 正常返回

func AbortWithBadRequestError

func AbortWithBadRequestError(c *Context, err error)

AbortWithBadRequestError 请求失败

func AbortWithJSONError

func AbortWithJSONError(c *Context, err error)

AbortWithJSONError 目前的UI规范, 返回200状态码, 通过里面的code判断请求成功与否

func AbortWithUnauthorizedError

func AbortWithUnauthorizedError(c *Context, err error)

AbortWithUnauthorizedError 未登入

func AbortWithWithForbiddenError

func AbortWithWithForbiddenError(c *Context, err error)

AbortWithWithForbiddenError 没有权限

func RestHandlerFunc

func RestHandlerFunc(handler HandlerFunc) gin.HandlerFunc

RestHandlerFunc rest handler

func STDRestHandlerFunc

func STDRestHandlerFunc(handler HandlerFunc) gin.HandlerFunc

STDRestHandlerFunc 标准handler, 错误返回非200状态码

func StreamHandler

func StreamHandler(handler StreamHandlerFunc) gin.HandlerFunc

StreamHandler 流式 Handler

Types

type APIGWApp

type APIGWApp struct {
	AppCode  string `json:"app_code"`
	Verified bool   `json:"verified"`
}

APIGWApp xxx

type APIGWToken

type APIGWToken struct {
	App  *APIGWApp  `json:"app"`
	User *APIGWUser `json:"user"`
	*jwt.StandardClaims
}

APIGWToken 返回信息

func (*APIGWToken) String

func (a *APIGWToken) String() string

String :

type APIGWUser

type APIGWUser struct {
	Username string `json:"username"`
	Verified bool   `json:"verified"`
}

APIGWUser xxx

type Context

type Context struct {
	*gin.Context
	RequestId     string          `json:"request_id"`
	StartTime     time.Time       `json:"start_time"`
	Operator      string          `json:"operator"`
	Username      string          `json:"username"`
	ProjectId     string          `json:"project_id"`
	ProjectCode   string          `json:"project_code"`
	ClusterId     string          `json:"cluster_id"`
	SharedCluster bool            `json:"shared_cluster"`
	BindEnv       *EnvToken       `json:"bind_env"`
	BindBCS       *UserClaimsInfo `json:"bind_bcs"`
	BindAPIGW     *APIGWToken     `json:"bind_apigw"`
	BindCluster   *bcs.Cluster    `json:"bind_cluster"`
	BindProject   *bcs.Project    `json:"bind_project"`
}

Context xxx

func GetRestContext

func GetRestContext(c *gin.Context) (*Context, error)

GetRestContext 查询鉴权信息

func InitRestContext

func InitRestContext(c *gin.Context) *Context

InitRestContext :

func (*Context) WriteAttachment

func (c *Context) WriteAttachment(data []byte, filename string)

WriteAttachment 提供附件下载能力

type EnvToken

type EnvToken struct {
	Username string
}

EnvToken xxx

type HandlerFunc

type HandlerFunc func(*Context) (interface{}, error)

HandlerFunc xxx

type Result

type Result struct {
	Code      int         `json:"code"`
	Message   string      `json:"message"`
	RequestId string      `json:"request_id"`
	Data      interface{} `json:"data"`
}

Result 返回的标准结构

type StreamHandlerFunc

type StreamHandlerFunc func(*Context)

StreamHandlerFunc xxx

type UserClaimsInfo

type UserClaimsInfo struct {
	SubType      string `json:"sub_type"`
	UserName     string `json:"username"`
	BKAppCode    string `json:"bk_app_code"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	// https://tools.ietf.org/html/rfc7519#section-4.1
	// aud: 接收jwt一方; exp: jwt过期时间; jti: jwt唯一身份认证; IssuedAt: 签发时间; Issuer: jwt签发者
	*jwt.StandardClaims
}

UserClaimsInfo custom jwt claims

Directories

Path Synopsis
Package middleware Authorization
Package middleware Authorization
Package tracing request id
Package tracing request id

Jump to

Keyboard shortcuts

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