vk

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: MIT Imports: 13 Imported by: 0

README

go-vk

Simple golang client for vk.com api

Features

  • Rate limiting
  • Auto retry on rate limit
  • Concurrent execution
  • Context support

Usage

Make client with client := vk.NewClient("5.103", "ru") Send request and read from channel

requests := []*vk.Request{{
	Method: "users.get",
	Params: url.Values{"access_token":  {"foo"}},
}}
resultChannel := p.client.Send(ctx, requests, 1)
response := <- resultChannel

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiError added in v1.0.3

type ApiError struct {
	ErrorCode     int    `json:"error_code"`
	ErrorMsg      string `json:"error_msg"`
	RequestParams []struct {
		Key   string `json:"key"`
		Value string `json:"value"`
	} `json:"request_params"`
}

type Client

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

func NewClient

func NewClient(v string, lang string, retryAttempts uint, retryDelay time.Duration) *Client

func (*Client) SendMany added in v1.5.0

func (c *Client) SendMany(ctx context.Context, requests []*Request, concurrency int) (<-chan string, <-chan *FailedRequest)

func (*Client) SendSingle added in v1.5.0

func (c *Client) SendSingle(ctx context.Context, request *Request) (string, error)

func (*Client) SetRateLimiter

func (c *Client) SetRateLimiter(rateLimiter ratelimit.Limiter)

type FailedRequest added in v1.5.0

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

func (*FailedRequest) Error added in v1.5.0

func (r *FailedRequest) Error() string

type Request

type Request struct {
	Method string
	Params url.Values
}

func (*Request) ToRequest added in v1.4.0

func (r *Request) ToRequest(accessToken string) *Request

type Requester added in v1.1.0

type Requester interface {
	ToRequest(accessToken string) *Request
}

type ResponseError

type ResponseError struct {
	Error *ApiError `json:"error"`
}

func (*ResponseError) HasErrorCode added in v1.5.0

func (r *ResponseError) HasErrorCode(value string) bool

func (*ResponseError) HasResponse added in v1.5.0

func (r *ResponseError) HasResponse(value string) bool

func (*ResponseError) HasRetryErrorCode added in v1.5.0

func (r *ResponseError) HasRetryErrorCode() bool

Jump to

Keyboard shortcuts

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