api

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentTypeJSON http content type
	ContentTypeJSON = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Caller

type Caller interface {
	Call(url string, data *RequestData) (*Response, error)
}

Caller represents way to call API with request

type DefaultConstructor

type DefaultConstructor struct{}

DefaultConstructor default implementation of RequestConstructor

func (DefaultConstructor) JSONRequest

func (d DefaultConstructor) JSONRequest(parameters interface{}) (*RequestData, error)

JSONRequest is default implementation

func (DefaultConstructor) MultipartRequest

func (d DefaultConstructor) MultipartRequest(
	parameters map[string]string, filesParameters map[string]*os.File) (*RequestData, error)

MultipartRequest is default implementation

type Error

type Error struct {
	Description string              `json:"description,omitempty"`
	ErrorCode   int                 `json:"error_code,omitempty"`
	Parameters  *ResponseParameters `json:"parameters,omitempty"`
}

Error represents error from telegram API

func (Error) Error

func (a Error) Error() string

Error converts Error to human-readable string

type FasthttpAPICaller

type FasthttpAPICaller struct {
	Client *fasthttp.Client
}

FasthttpAPICaller fasthttp implementation of Caller

func (FasthttpAPICaller) Call

func (a FasthttpAPICaller) Call(url string, data *RequestData) (*Response, error)

Call is fasthttp implementation

type RequestConstructor

type RequestConstructor interface {
	JSONRequest(parameters interface{}) (*RequestData, error)
	MultipartRequest(parameters map[string]string, filesParameters map[string]*os.File) (*RequestData, error)
}

RequestConstructor represents way to construct API request

type RequestData

type RequestData struct {
	ContentType string
	Buffer      *bytes.Buffer
}

RequestData represents data needed to execute request

type Response

type Response struct {
	Ok     bool               `json:"ok"`
	Result stdJson.RawMessage `json:"result,omitempty"`
	*Error
}

Response represents response returned by Telegram API

func (Response) String

func (r Response) String() string

type ResponseParameters

type ResponseParameters struct {
	// MigrateToChatID - Optional. The group has been migrated to a supergroup with the specified identifier.
	// This number may have more than 32 significant bits and some programming languages may have difficulty/silent
	// defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or
	// double-precision float type are safe for storing this identifier.
	MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`

	// RetryAfter - Optional. In case of exceeding flood control, the number of seconds left to wait before the
	// request can be repeated
	RetryAfter int `json:"retry_after,omitempty"`
}

ResponseParameters - Contains information about why a request was unsuccessful.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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