larkcore

package
v3.0.0-...-30c28ac Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 17 Imported by: 5

Documentation

Index

Constants

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

	HttpHeaderKeyLogId = "X-Tt-Logid"
)

Variables

This section is empty.

Functions

func File2Bytes

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

func FileNameByHeader

func FileNameByHeader(header http.Header) string

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.

Types

type AccessTokenType

type AccessTokenType string
const (
	AccessTokenTypePersonal AccessTokenType = "personal_access_token"
	AccessTokenTypeNone     AccessTokenType = "none_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 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
	PersonalBaseToken string
	AppToken          string
	ReqTimeout        time.Duration
	LogLevel          LogLevel
	HttpClient        HttpClient
	Logger            Logger
	LogReqAtDebug     bool
	Header            http.Header
	Serializable      Serializable
}

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 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 {
	PersonalToken string
	RequestId     string
	FileUpload    bool
	FileDownload  bool
	Header        http.Header
}

type RequestOptionFunc

type RequestOptionFunc func(option *RequestOption)

func WithFileDownload

func WithFileDownload() RequestOptionFunc

func WithFileUpload

func WithFileUpload() RequestOptionFunc

func WithHeaders

func WithHeaders(header http.Header) RequestOptionFunc

func WithRequestId

func WithRequestId(requestId string) RequestOptionFunc

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

Jump to

Keyboard shortcuts

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