net

package
v0.0.0-...-cc90098 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TelegramAPIEndpoint is the endpoint for all API method with formatting for Sprintf.
	TelegramAPIEndpoint = "https://api.telegram.org/bot%s/%s"
	// TelegramFileEndpoint is the endpoint for downloading a file from Telegram.
	TelegramFileEndpoint = "https://api.telegram.org/file/bot%s/%s"
	// TelegramHTTPMethod http method for request
	TelegramHTTPMethod = "POST"
)

Variables

This section is empty.

Functions

func ToForm

func ToForm(src interface{}) (*bytes.Buffer, string, error)

ToForm encodes src to multipart/from-data *bytes.Buffer

func ToJSON

func ToJSON(src interface{}) (*bytes.Buffer, string, error)

ToJSON encodes src to json *bytes.Buffer

Types

type Client

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

Client represents a telegram api client.

func NewClient

func NewClient(token string) *Client

NewClient creates Client.

func (*Client) Call

func (c *Client) Call(method method.TelegramMethod) (Response, error)

Call builds http request and performs its from passed telegram method.

func (*Client) Token

func (c *Client) Token() string

Token returns telegram token

type Errors

type Errors map[string]error

Errors contains information about errors.

func (Errors) Error

func (e Errors) Error() string

type Response

type Response struct {
	Ok          bool                `json:"ok"`
	Result      json.RawMessage     `json:"result"`
	ErrorCode   int                 `json:"error_code"`
	Description string              `json:"description"`
	Parameters  *ResponseParameters `json:"parameters"`
}

Response is a response from Telegram API with the result stored raw

type ResponseParameters

type ResponseParameters struct {
	MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
	RetryAfter      int   `json:"retry_after"`        // optional
}

ResponseParameters are various errors that can be returned in APIResponse.

func (*ResponseParameters) String

func (rp *ResponseParameters) String() string

Jump to

Keyboard shortcuts

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