http

package
v0.0.4-beta.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: MIT Imports: 17 Imported by: 15

Documentation

Index

Constants

View Source
const (
	SuccessCode                     = "0"
	FaaSInfraFailCodeInternalError  = "k_ec_000001"
	FaaSInfraFailCodeTokenExpire    = "k_ident_013000"
	FaaSInfraFailCodeIllegalToken   = "k_ident_013001"
	FaaSInfraFailCodeMissingToken   = "k_fs_ec_100001"
	FaaSInfraFailCodeRateLimitError = "k_fs_ec_000004"
)
View Source
const (
	OpenapiPathGetToken  = "/auth/v1/appToken"
	FaaSInfraPathSendLog = "/log/v1/namespaces/:namespace/logs/batchSend"
)
View Source
const (
	SCFileDownload = ""
	SCSuccess      = "0"

	ECInternalError  = "k_ec_000001"
	ECNoTenantID     = "k_ec_000002"
	ECNoUserID       = "k_ec_000003"
	ECUnknownError   = "k_ec_000004"
	ECOpUnknownError = "k_op_ec_00001"
	ECSystemBusy     = "k_op_ec_20001"
	ECSystemError    = "k_op_ec_20002"
	ECRateLimitError = "k_op_ec_20003"
	ECTokenExpire    = "k_ident_013000"
	ECIllegalToken   = "k_ident_013001"
	ECMissingToken   = "k_op_ec_10205"
)

Variables

This section is empty.

Functions

func AppTokenMiddleware

func AppTokenMiddleware(ctx context.Context, req *http.Request) (err error)

func GetAppTokenHttp

func GetAppTokenHttp(ctx context.Context, clientID, clientSecret string) (*structs.AppTokenResp, error)

func GetFaaSInfraPathSendLog

func GetFaaSInfraPathSendLog() string

func GetTimeoutCtx

func GetTimeoutCtx(ctx context.Context) (context.Context, context.CancelFunc)

func IsSysError

func IsSysError(errCode string) bool

func SendLog

func SendLog(ctx context.Context, data interface{}) error

func ServiceIDMiddleware

func ServiceIDMiddleware(ctx context.Context, req *http.Request) error

func SetCredentialToCtx

func SetCredentialToCtx(ctx context.Context, credential *AppCredential) context.Context

func TenantAndUserMiddleware

func TenantAndUserMiddleware(ctx context.Context, req *http.Request) error

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(ctx context.Context, net, addr string) (c net.Conn, err error)

TimeoutDialer 设置连接&读写超时,非 0 才设置

Types

type AppCredential

type AppCredential struct {
	// contains filtered or unexported fields
}

func NewAppCredential

func NewAppCredential(id, secret string) *AppCredential

func (*AppCredential) GetTenantInfo

func (c *AppCredential) GetTenantInfo(ctx context.Context) (*structs.Tenant, error)

type ClientType

type ClientType int
const (
	OpenAPIClient ClientType = iota + 1
	FaaSInfraClient
)

type HttpClient

type HttpClient struct {
	Type ClientType
	http.Client
}

func GetFaaSInfraClient

func GetFaaSInfraClient() *HttpClient

func GetOpenapiClient

func GetOpenapiClient() *HttpClient

func (*HttpClient) DeleteJson

func (c *HttpClient) DeleteJson(ctx context.Context, path string, headers map[string][]string, data interface{}, midList ...ReqMiddleWare) ([]byte, map[string]interface{}, error)

func (*HttpClient) Get

func (c *HttpClient) Get(ctx context.Context, path string, headers map[string][]string, midList ...ReqMiddleWare) ([]byte, map[string]interface{}, error)

func (*HttpClient) PatchJson

func (c *HttpClient) PatchJson(ctx context.Context, path string, headers map[string][]string, data interface{}, midList ...ReqMiddleWare) ([]byte, map[string]interface{}, error)

func (*HttpClient) PostBson

func (c *HttpClient) PostBson(ctx context.Context, path string, headers map[string][]string, data interface{}, midList ...ReqMiddleWare) ([]byte, map[string]interface{}, error)

func (*HttpClient) PostFormData

func (c *HttpClient) PostFormData(ctx context.Context, path string, headers map[string][]string, body *bytes.Buffer, midList ...ReqMiddleWare) ([]byte, map[string]interface{}, error)

func (*HttpClient) PostJson

func (c *HttpClient) PostJson(ctx context.Context, path string, headers map[string][]string, data interface{}, midList ...ReqMiddleWare) ([]byte, map[string]interface{}, error)

type ICredential

type ICredential interface {
	// contains filtered or unexported methods
}

type ReqMiddleWare

type ReqMiddleWare func(ctx context.Context, req *http.Request) error

Jump to

Keyboard shortcuts

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