larkcore

package
v3.0.22 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HttpHeaderKeyRequestId = "X-Request-Id"

	HttpHeaderKeyLogId = "X-Tt-Logid"
)
View Source
const (
	AppAccessTokenInternalUrlPath    string = "/open-apis/auth/v3/app_access_token/internal"
	AppAccessTokenUrlPath            string = "/open-apis/auth/v3/app_access_token"
	TenantAccessTokenInternalUrlPath string = "/open-apis/auth/v3/tenant_access_token/internal"
	TenantAccessTokenUrlPath         string = "/open-apis/auth/v3/tenant_access_token"
	ApplyAppTicketPath               string = "/open-apis/auth/v3/app_ticket/resend"
)

Variables

View Source
var ErrAppTicketIsEmpty = errors.New("app ticket is empty")

Functions

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr returns a pointer to the bool value passed in.

func BoolValue

func BoolValue(v *bool) bool

BoolValue returns the value of the bool pointer passed in or false if the pointer is nil.

func DownloadFile

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

DownloadFile returns the url of resource

func EncryptedEventMsg

func EncryptedEventMsg(ctx context.Context, data interface{}, encryptKey string) (string, error)

func File2Bytes

func File2Bytes(fileName string) ([]byte, error)

func FileNameByHeader

func FileNameByHeader(header http.Header) string

func Float32Ptr

func Float32Ptr(v float32) *float32

Float32Ptr returns a pointer to the float32 value passed in.

func Float32Value

func Float32Value(v *float32) float32

Float32Value returns the value of the float32 pointer passed in or 0 if the pointer is nil.

func Float64Ptr

func Float64Ptr(v float64) *float64

Float64Ptr returns a pointer to the float64 value passed in.

func Float64Value

func Float64Value(v *float64) float64

Float64Value returns the value of the float64 pointer passed in or 0 if the pointer is nil.

func Int16Ptr

func Int16Ptr(v int16) *int16

Int16Ptr returns a pointer to the int16 value passed in.

func Int16Value

func Int16Value(v *int16) int16

Int16Value returns the value of the int16 pointer passed in or 0 if the pointer is nil.

func Int32Ptr

func Int32Ptr(v int32) *int32

Int32Ptr returns a pointer to the int32 value passed in.

func Int32Value

func Int32Value(v *int32) int32

Int32Value returns the value of the int32 pointer passed in or 0 if the pointer is nil.

func Int64Ptr

func Int64Ptr(v int64) *int64

Int64Ptr returns a pointer to the int64 value passed in.

func Int64Value

func Int64Value(v *int64) int64

Int64Value returns the value of the int64 pointer passed in or 0 if the pointer is nil.

func Int8Ptr

func Int8Ptr(v int8) *int8

Int8Ptr returns a pointer to the int8 value passed in.

func Int8Value

func Int8Value(v *int8) int8

Int8Value returns the value of the int8 pointer passed in or 0 if the pointer is nil.

func IntPtr

func IntPtr(v int) *int

IntPtr returns a pointer to the int value passed in.

func IntValue

func IntValue(v *int) int

IntValue returns the value of the int pointer passed in or 0 if the pointer is nil.

func NewCache

func NewCache(config *Config)

func NewHttpClient

func NewHttpClient(config *Config)

func NewLogger

func NewLogger(config *Config)

func NewSerialization

func NewSerialization(config *Config)

func Prettify

func Prettify(i interface{}) string

Prettify returns the string representation of a value.

func StringPtr

func StringPtr(v string) *string

StringPtr returns a pointer to the string value passed in.

func StringValue

func StringValue(v *string) string

StringValue returns the value of the string pointer passed in or "" if the pointer is nil.

func StructToMap

func StructToMap(val interface{}) (map[string]interface{}, error)

func TimePtr

func TimePtr(v time.Time) *time.Time

TimePtr returns a pointer to the time.Time value passed in.

func TimeValue

func TimeValue(v *time.Time) time.Time

TimeValue returns the value of the time.Time pointer passed in or time.Time{} if the pointer is nil.

Types

type AccessTokenType

type AccessTokenType string
const (
	AccessTokenTypeNone   AccessTokenType = "none_access_token"
	AccessTokenTypeApp    AccessTokenType = "app_access_token"
	AccessTokenTypeTenant AccessTokenType = "tenant_access_token"
	AccessTokenTypeUser   AccessTokenType = "user_access_token"
)

type ApiReq

type ApiReq struct {
	HttpMethod                string
	ApiPath                   string
	Body                      interface{}
	QueryParams               QueryParams
	PathParams                PathParams
	SupportedAccessTokenTypes []AccessTokenType
}

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

func (ApiResp) String

func (resp ApiResp) String() string

func (ApiResp) Write

func (resp ApiResp) Write(writer http.ResponseWriter)

type AppAccessTokenResp

type AppAccessTokenResp struct {
	*ApiResp `json:"-"`
	CodeError
	Expire         int    `json:"expire"`
	AppAccessToken string `json:"app_access_token"`
}

func (*AppAccessTokenResp) Success

func (t *AppAccessTokenResp) Success() bool

type AppTicketManager

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

func GetAppTicketManager

func GetAppTicketManager() *AppTicketManager

func (*AppTicketManager) Get

func (m *AppTicketManager) Get(ctx context.Context, config *Config) (string, error)

func (*AppTicketManager) Set

func (m *AppTicketManager) Set(ctx context.Context, appId, value string, ttl time.Duration) error

type AppType

type AppType string
const (
	AppTypeSelfBuilt   AppType = "SelfBuilt"
	AppTypeMarketplace AppType = "Marketplace"
)

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 {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Err  *struct {
		Details              []*CodeErrorDetail              `json:"details,omitempty"`
		PermissionViolations []*CodeErrorPermissionViolation `json:"permission_violations,omitempty"`
		FieldViolations      []*CodeErrorFieldViolation      `json:"field_violations,omitempty"`
	} `json:"error"`
}

func (CodeError) Error

func (ce CodeError) Error() string

func (CodeError) String

func (ce CodeError) String() string

type CodeErrorDetail

type CodeErrorDetail struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type CodeErrorFieldViolation

type CodeErrorFieldViolation struct {
	Field       string `json:"field,omitempty"`
	Value       string `json:"value,omitempty"`
	Description string `json:"description,omitempty"`
}

type CodeErrorPermissionViolation

type CodeErrorPermissionViolation struct {
	Type        string `json:"type,omitempty"`
	Subject     string `json:"subject,omitempty"`
	Description string `json:"description,omitempty"`
}

type Config

type Config struct {
	BaseUrl           string
	AppId             string
	AppSecret         string
	HelpDeskId        string
	HelpDeskToken     string
	HelpdeskAuthToken string
	ReqTimeout        time.Duration
	LogLevel          LogLevel
	HttpClient        HttpClient
	Logger            Logger
	AppType           AppType
	EnableTokenCache  bool
	TokenCache        Cache
	LogReqAtDebug     bool
	Header            http.Header
	Serializable      Serializable
	SkipSignVerify    bool
}

type DecryptErr

type DecryptErr struct {
	Message string
}

func (DecryptErr) Error

func (e DecryptErr) Error() string

type DefaultSerialization

type DefaultSerialization struct {
}

func (*DefaultSerialization) Deserialize

func (d *DefaultSerialization) Deserialize(data []byte, v interface{}) error

func (*DefaultSerialization) Serialize

func (d *DefaultSerialization) Serialize(v interface{}) ([]byte, error)

type DialFailedError

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

func (*DialFailedError) Error

func (err *DialFailedError) Error() string

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 HttpClient

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

HttpClient :sdk-core面向HttpClient接口编程,实现core与httpclient解耦 1.可以适配所有基于go-sdk内置httpclient构建的三方httpclient 2.可以方便的对httpclient进行mock, 方便编写单元测试

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 {
	TenantKey         string
	UserAccessToken   string
	AppAccessToken    string
	TenantAccessToken string
	NeedHelpDeskAuth  bool
	RequestId         string
	AppTicket         string
	FileUpload        bool
	FileDownload      bool
	Header            http.Header
}

type RequestOptionFunc

type RequestOptionFunc func(option *RequestOption)

func WithAppTicket

func WithAppTicket(appTicket string) RequestOptionFunc

func WithFileDownload

func WithFileDownload() RequestOptionFunc

func WithFileUpload

func WithFileUpload() RequestOptionFunc

func WithHeaders

func WithHeaders(header http.Header) RequestOptionFunc

func WithNeedHelpDeskAuth

func WithNeedHelpDeskAuth() RequestOptionFunc

func WithRequestId

func WithRequestId(requestId string) RequestOptionFunc

func WithTenantAccessToken

func WithTenantAccessToken(tenantAccessToken string) RequestOptionFunc

func WithTenantKey

func WithTenantKey(tenantKey string) RequestOptionFunc

func WithUserAccessToken

func WithUserAccessToken(userAccessToken string) RequestOptionFunc

type ResendAppTicketReq

type ResendAppTicketReq struct {
	AppID     string `json:"app_id"`
	AppSecret string `json:"app_secret"`
}

type ResendAppTicketResp

type ResendAppTicketResp struct {
	*ApiResp `json:"-"`
	CodeError
}

func (*ResendAppTicketResp) Success

func (r *ResendAppTicketResp) Success() bool

type SelfBuiltAppAccessTokenReq

type SelfBuiltAppAccessTokenReq struct {
	AppID     string `json:"app_id"`
	AppSecret string `json:"app_secret"`
}

type SelfBuiltTenantAccessTokenReq

type SelfBuiltTenantAccessTokenReq struct {
	AppID     string `json:"app_id"`
	AppSecret string `json:"app_secret"`
}

type Serializable

type Serializable interface {
	Serialize(v interface{}) ([]byte, error)
	Deserialize(data []byte, v interface{}) error
}

type ServerTimeoutError

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

func (*ServerTimeoutError) Error

func (err *ServerTimeoutError) Error() string

type TenantAccessTokenResp

type TenantAccessTokenResp struct {
	*ApiResp `json:"-"`
	CodeError
	Expire            int    `json:"expire"`
	TenantAccessToken string `json:"tenant_access_token"`
}

func (*TenantAccessTokenResp) Success

func (t *TenantAccessTokenResp) Success() bool

type TokenManager

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

type Value

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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