api

package
v1.5.8 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// data error
	PermissionDeny     = 1
	JsonUnmarshalError = 2
	TimeoutError       = 3

	// http error
	ParseTokenEorror = 11
	GetBodyError     = 12
	GetTokenError    = 13
	GetHeaderError   = 14
	GetIdError       = 15

	// login error
	AuthenticationError = 31
	LdapConnectError    = 32
	LdapSearchError     = 33
	LdapUserAuthError   = 34
	ParseHeaderError    = 35
	GoogleCodeError     = 36

	// connect other components error
	ConnectAuthenticationError = 41
	ConnectTaskWorkerError     = 42

	// DB connnect error
	SelectDbError = 51
	AddDbError    = 52
	UpdateDbError = 53
	DeleteDbError = 54

	// Redis connect error
	ConnectRedisError = 61
	SelectRedisError  = 62

	// reflect error
	ReflectError           = 71
	UnmarshalResponseError = 72
	SpecialReturnError     = 73

	// task error
	CreateTaskError     = 81
	GetTaskBodyError    = 82
	CannotFindTaskError = 83
	GetTaskStatusError  = 84
)
View Source
const (
	HealthcheckStatusUP   = "UP"
	HealthcheckStatusDOWN = "DOWN"
)
View Source
const (
	HttpTimeout     = 10
	HttpReadTimeout = 900
)

Variables

View Source
var (
	// Reverser 全局调用自身路由的对象
	Reverser *router.RoutePathReverser
	// Auth ApiAuth 存储Api认证
	Auth string
	// AuthenticateUrl 存储Authenticate组件地址
	AuthenticateUrl string
)
View Source
var (
	NilBody   = bytes.NewBuffer([]byte(""))
	NilHeader = http.Header{}
)

Functions

func CreateApi

func CreateApi(service Service, isSwagger bool) (*iris.Application, func() error)

func EmptyCtx added in v1.5.5

func EmptyCtx() iris.Context

func Fusion

func Fusion(u ...string) string

func GetParams added in v1.4.2

func GetParams(ctx iris.Context, key string) string

func GetTraceId

func GetTraceId(ctx iris.Context) string

func GetUserName

func GetUserName(ctx iris.Context) string

func HttpUtil

func HttpUtil(method, url string, timeout time.Duration, headers http.Header, body io.Reader) (int, []byte, error)

func Logger

func Logger(ctx iris.Context) *logrus.Entry

func NormalSpecialTask

func NormalSpecialTask(m *map[string]interface{}) error

func ParseToken

func ParseToken(ctx iris.Context) (string, float64, float64, error)

func ResponseBody

func ResponseBody(ctx iris.Context, response *Response, data interface{})

func ReturnErr

func ReturnErr(code int, ctx iris.Context, err error, response *Response)

func ReverserInfoUtil

func ReverserInfoUtil(ctx iris.Context, response *Response, headers http.Header, body io.Reader, method, path string) (int, []byte)

func ReverserUtil

func ReverserUtil(ctx iris.Context, response *Response, method, path string) (int, []byte)

Types

type AuthenticationData

type AuthenticationData struct {
	Header   map[string]string `json:"header,omitempty"`
	Approved bool              `json:"approved"`
}

AuthenticationData 鉴权组件返回的Data的内容格式

type AuthenticationResponse

type AuthenticationResponse struct {
	Response
	Data AuthenticationData `json:"data,omitempty"`
}

type HealthcheckItem

type HealthcheckItem struct {
	Status  string                 `json:"status"`
	Details map[string]interface{} `json:"details"`
}

type HealthcheckSpec

type HealthcheckSpec struct {
	Status  string                      `json:"status"`
	Details map[string]*HealthcheckItem `json:"details"`
}

func (*HealthcheckSpec) AddItem

func (hc *HealthcheckSpec) AddItem(name string, item *HealthcheckItem)

func (*HealthcheckSpec) MergeHealthcheckStatus

func (hc *HealthcheckSpec) MergeHealthcheckStatus()

type Object

type Object struct{}

func (Object) Authenticate

func (Object) Authenticate(ctx iris.Context) error

func (Object) AuthenticateApi

func (Object) AuthenticateApi(ctx iris.Context)

AuthenticateApi 登录认证 @Summary 登录认证 @Description 登录认证 @Param body body AuthenticateConfig true "Account Info" @tags login @Accept json @Produce json @Success 200 string api_interface.Response "ok" @Failure 401 string api_interface.Response "未授权" @Failure 407 string api_interface.Response "权限不足" @Failure 501 string api_interface.Response "处理存在异常" @Security ApiKeyAuth @Router /authenticate [post]

func (Object) Dot

func (Object) Dot(i ...interface{})

func (Object) GetAuth

func (Object) GetAuth() string

func (Object) GetAuthenticateUrl

func (Object) GetAuthenticateUrl() string

func (Object) Health

func (Object) Health() func() map[string]error

func (Object) Party

func (Object) Party(iris.Party)

func (Object) Webhook added in v1.4.1

func (Object) Webhook(iris.Party)

type Response

type Response struct {
	TraceId string      `json:"traceId"`
	Code    int         `json:"code,omitempty"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Pages   int         `json:"pages,omitempty"`
}

Response api 返回的统一数据结构 traceId 首先从Header中获取,如果有继续往下传递,否则新生成一个traceId Code 用于标识返回状态, Code的定义应该全局统一,看Code就知道错误类型,0 为正常 Message 用于当api调用出错时返回信息 Data 是正常返回时,返回的数据

func ResponseInit

func ResponseInit(ctx iris.Context) (response *Response)

func UnmarshalResponse

func UnmarshalResponse(body []byte) (*Response, error)

type Service

type Service interface {
	// GetAuth 传入Api使用的Auth信息
	GetAuth() string
	// GetAuthenticateUrl 传入Authenticate组件地址
	GetAuthenticateUrl() string
	// Webhook 自定义路由逻辑
	Webhook(iris.Party)
	// Party 自定义路由逻辑
	Party(iris.Party)
	// Health 定义健康检查接口需要检查的内容
	Health() func() map[string]error
	// Dot 接口请求访问的需要打点逻辑,可以定义:
	Dot(...interface{})

	// AuthenticateApi 自定义登录认证的接口
	AuthenticateApi(iris.Context)
	// Authenticate 请求Authenticate组件的方法
	Authenticate(ctx iris.Context) error
}

type UserClaims

type UserClaims struct {
	Username string `json:"username"`
}

Jump to

Keyboard shortcuts

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