Documentation
¶
Index ¶
- Constants
- Variables
- func CreateApi(service Service, isSwagger bool) (*iris.Application, func() error)
- func EmptyCtx() iris.Context
- func Fusion(u ...string) string
- func GetParams(ctx iris.Context, key string) string
- func GetTraceId(ctx iris.Context) string
- func GetUserName(ctx iris.Context) string
- func HttpUtil(method, url string, timeout time.Duration, headers http.Header, body io.Reader) (int, []byte, error)
- func Logger(ctx iris.Context) *logrus.Entry
- func NormalSpecialTask(m *map[string]interface{}) error
- func ParseToken(ctx iris.Context) (string, float64, float64, error)
- func ResponseBody(ctx iris.Context, response *Response, data interface{})
- func ReturnErr(code int, ctx iris.Context, err error, response *Response)
- func ReverserInfoUtil(ctx iris.Context, response *Response, headers http.Header, body io.Reader, ...) (int, []byte)
- func ReverserUtil(ctx iris.Context, response *Response, method, path string) (int, []byte)
- type AuthenticationData
- type AuthenticationResponse
- type HealthcheckItem
- type HealthcheckSpec
- type Object
- func (Object) Authenticate(ctx iris.Context) error
- func (Object) AuthenticateApi(ctx iris.Context)
- func (Object) Dot(i ...interface{})
- func (Object) GetAuth() string
- func (Object) GetAuthenticateUrl() string
- func (Object) Health() func() map[string]error
- func (Object) Party(iris.Party)
- func (Object) Webhook(iris.Party)
- type Response
- type Service
- type UserClaims
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 )
Functions ¶
func GetTraceId ¶
func GetUserName ¶
func NormalSpecialTask ¶
func ResponseBody ¶
func ReverserInfoUtil ¶
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 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) AuthenticateApi ¶
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) GetAuthenticateUrl ¶
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 UnmarshalResponse ¶
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"`
}
Click to show internal directories.
Click to hide internal directories.