cocore

package
v0.28.108 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const UserAgent = "cored-openapi-sdk-go/" + Version

User-Agent

View Source
const Version = "0.28.108"

SDK version

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiClient

type ApiClient interface {
	Preheat(ctx context.Context) error
	Request(ctx context.Context, req *ApiRequest) (*ApiResponse, error)
	OnEvent(eventType string, handler EventHandler)
	OffEvent(eventType string, handler EventHandler)
	Close() error
}

func NewDefaultApiClient

func NewDefaultApiClient(config *Config) ApiClient

type ApiError

type ApiError struct {
	Code  int         `json:"code"` // code < 0 means local error
	Msg   string      `json:"msg"`
	LogId string      `json:"log_id"`
	Data  interface{} `json:"data,omitempty"`
}

func (*ApiError) Error

func (e *ApiError) Error() string

type ApiRequest

type ApiRequest struct {
	Method             string            `json:"method"`
	Path               string            `json:"path"`
	PathParams         map[string]string `json:"path_params,omitempty"`
	QueryParams        map[string]string `json:"query_params,omitempty"`
	HeaderParams       map[string]string `json:"header_params,omitempty"`
	Body               interface{}       `json:"body,omitempty"`
	Stream             io.Reader         `json:"stream,omitempty"`
	WithAppAccessToken bool              `json:"with_app_access_token,omitempty"`
	WithWebSocket      bool              `json:"with_websocket,omitempty"`
}

type ApiResponse

type ApiResponse struct {
	GetBody func() ([]byte, error)
	// contains filtered or unexported fields
}

func (*ApiResponse) JSON

func (e *ApiResponse) JSON(value interface{}) error

type Config

type Config struct {
	AppId      string
	AppSecret  string
	BackendUrl string

	HttpClient       HttpClient
	ApiClient        ApiClient
	EnableEncryption bool
	RequestTimeout   time.Duration
	TimeManager      TimeManager

	Logger Logger

	JsonMarshal   Marshaller
	JsonUnmarshal Unmarshaller
}

type EventHandler

type EventHandler func(ctx context.Context, header *EventHeader, body []byte) error

type EventHeader

type EventHeader struct {
	EventId        string `json:"event_id,omitempty"`
	EventType      string `json:"event_type,omitempty"`
	EventCreatedAt uint64 `json:"event_created_at,omitempty"`
}

type HttpClient

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

func NewDefaultHttpClient

func NewDefaultHttpClient(requestTimeout time.Duration) HttpClient

type Logger

type Logger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warnf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

func NewDefaultLogger

func NewDefaultLogger(level LoggerLevel) Logger

type LoggerLevel

type LoggerLevel int8
const (
	LoggerLevelDebug LoggerLevel = iota
	LoggerLevelInfo
	LoggerLevelWarn
	LoggerLevelError
)

type Marshaller

type Marshaller = func(v interface{}) ([]byte, error)

type TimeManager

type TimeManager interface {
	GetSystemTimestamp() int64
	GetServerTimestamp() int64
	SyncServerTimestamp(timestamp int64)
}

func NewDefaultTimeManager

func NewDefaultTimeManager() TimeManager

type Unmarshaller

type Unmarshaller = func(data []byte, v interface{}) error

Jump to

Keyboard shortcuts

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