core

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HTTPHeaderUserKey      = "X-USER-KEY"
	HTTPHeaderAccessToken  = "X-PLUGIN-TOKEN"
	HTTPHeaderIdemUUID     = "X-IDEM-UUID"
	HTTPHeaderKeyRequestID = "X-Request-Id"
	HTTPHeaderKeyLogID     = "X-Tt-Logid"
)
View Source
const (
	PluginAccessTokenInternalUrlPath string = "/open_api/authen/plugin_token"
)

Variables

This section is empty.

Functions

func DownloadFile

func DownloadFile(ctx context.Context, url string) ([]byte, error)

DownloadFile returns the url of resource

func FileNameByHeader

func FileNameByHeader(header http.Header) string

func NewCache

func NewCache(config *Config)

func NewHttpClient

func NewHttpClient(config *Config)

func NewLogger

func NewLogger(config *Config)

func Prettify

func Prettify(i interface{}) string

Prettify returns the string representation of a value.

Types

type APIReq

type APIReq struct {
	HttpMethod  string
	ApiPath     string
	Body        interface{}
	QueryParams QueryParams
	PathParams  PathParams
	SkipAuth    bool
}

type APIResp

type APIResp struct {
	StatusCode int         `json:"-"`
	Header     http.Header `json:"-"`
	RawBody    []byte      `json:"-"`
}

func Request

func Request(ctx context.Context, req *APIReq, config *Config, options ...RequestOptionFunc) (*APIResp, error)

func (APIResp) JSONUnmarshalBody

func (resp APIResp) JSONUnmarshalBody(val interface{}, config *Config) error

func (APIResp) RequestId

func (resp APIResp) RequestId() string

type AccessToken

type AccessToken struct {
	ExpireTime int    `json:"expire_time"`
	Token      string `json:"token"`
}

type AccessTokenErr

type AccessTokenErr struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

func (AccessTokenErr) Error

func (ce AccessTokenErr) Error() string

func (AccessTokenErr) String

func (ce AccessTokenErr) String() string

type AccessTokenType

type AccessTokenType int
const (
	AccessTokenTypePlugin        AccessTokenType = 0
	AccessTokenTypeVirtualPlugin AccessTokenType = 1
)

type Cache

type Cache interface {
	Set(ctx context.Context, key string, value string, expireTime time.Duration) error
	Get(ctx context.Context, key string) (string, error)
}

type ClientTimeoutError

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

func (*ClientTimeoutError) Error

func (err *ClientTimeoutError) Error() string

type CodeError

type CodeError struct {
	ErrCode int    `json:"err_code"`
	ErrMsg  string `json:"err_msg"`
	Err     struct {
		Code int    `json:"code,omitempty"`
		Msg  string `json:"msg,omitempty"`
	} `json:"err"`
}

func (CodeError) Code

func (ce CodeError) Code() int

func (CodeError) Error

func (ce CodeError) Error() string

func (CodeError) String

func (ce CodeError) String() string

func (CodeError) Success

func (ce CodeError) Success() bool

type Config

type Config struct {
	BaseUrl          string
	AppID            string
	AppSecret        string
	ReqTimeout       time.Duration
	LogLevel         LogLevel
	HttpClient       HttpClient
	Logger           Logger
	EnableTokenCache bool
	TokenCache       Cache
	LogReqAtDebug    bool
	AccessTokenType  AccessTokenType
	Header           http.Header
}

type FormData

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

func NewFormdata

func NewFormdata() *FormData

func (*FormData) AddField

func (fd *FormData) AddField(field string, val interface{}) *FormData

func (*FormData) AddFile

func (fd *FormData) AddFile(field string, r io.Reader) *FormData

type GetAccessTokenReq

type GetAccessTokenReq struct {
	PluginId     string `json:"plugin_id"`
	PluginSecret string `json:"plugin_secret"`
	Type         int    `json:"type"`
}

type GetAccessTokenResp

type GetAccessTokenResp struct {
	*APIResp `json:"-"`
	Error    *AccessTokenErr `json:"error"`
	Data     *AccessToken    `json:"data"`
}

func (*GetAccessTokenResp) Success

func (t *GetAccessTokenResp) Success() bool

type HttpClient

type HttpClient interface {
	Do(*http.Request) (*http.Response, error)
}

type IllegalParamError

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

func (*IllegalParamError) Error

func (err *IllegalParamError) Error() string

type LogLevel

type LogLevel int
const (
	LogLevelDebug LogLevel = 1
	LogLevelInfo  LogLevel = 2
	LogLevelWarn  LogLevel = 3
	LogLevelError LogLevel = 4
)

type Logger

type Logger interface {
	Debug(context.Context, ...interface{})
	Info(context.Context, ...interface{})
	Warn(context.Context, ...interface{})
	Error(context.Context, ...interface{})
}

func NewEventLogger

func NewEventLogger() Logger

type MarketplaceAppAccessTokenReq

type MarketplaceAppAccessTokenReq struct {
	AppID     string `json:"app_id"`
	AppSecret string `json:"app_secret"`
	AppTicket string `json:"app_ticket"`
}

type MarketplaceTenantAccessTokenReq

type MarketplaceTenantAccessTokenReq struct {
	AppAccessToken string `json:"app_access_token"`
	TenantKey      string `json:"tenant_key"`
}

type PathParams

type PathParams map[string]string

func (PathParams) Get

func (u PathParams) Get(key string) string

func (PathParams) Set

func (u PathParams) Set(key, value string)

type QueryParams

type QueryParams map[string][]string

func (QueryParams) Add

func (u QueryParams) Add(key, value string)

func (QueryParams) Encode

func (u QueryParams) Encode() string

func (QueryParams) Get

func (u QueryParams) Get(key string) string

func (QueryParams) Set

func (u QueryParams) Set(key, value string)

type ReqTranslator

type ReqTranslator struct {
}

type RequestOption

type RequestOption struct {
	Header http.Header
}

type RequestOptionFunc

type RequestOptionFunc func(option *RequestOption)

func WithAccessToken

func WithAccessToken(accessToken string) RequestOptionFunc

func WithHeaders

func WithHeaders(header http.Header) RequestOptionFunc

func WithIdemUUID

func WithIdemUUID(uuid string) RequestOptionFunc

func WithUserKey

func WithUserKey(userKey string) RequestOptionFunc

type ServerTimeoutError

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

func (*ServerTimeoutError) Error

func (err *ServerTimeoutError) Error() string

type TokenManager

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

type Value

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

Jump to

Keyboard shortcuts

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