Documentation
¶
Overview ¶
Package middleware defines middleware abstraction for RPC invokers.
Example ¶
package main
import (
"context"
"time"
"golang.org/x/time/rate"
"github.com/gotd/td/middleware"
"github.com/gotd/td/middleware/floodwait"
"github.com/gotd/td/middleware/ratelimit"
"github.com/gotd/td/telegram"
)
func main() {
// Create a new telegram.Client instance that handles FLOOD_WAIT errors
// and limits request rate to 10 Hz with max burst size of 5 request.
//
// Note that you must not use test app credentials in production.
// See https://core.telegram.org/api/obtaining_api_id
//
client := telegram.NewClient(
telegram.TestAppID,
telegram.TestAppHash,
telegram.Options{
Middleware: middleware.Chain(
floodwait.Middleware(),
ratelimit.Middleware(
rate.NewLimiter(rate.Every(100*time.Millisecond), 5),
),
),
},
)
ctx := context.TODO()
err := client.Run(ctx, func(ctx context.Context) error {
return nil
})
if err != nil {
panic(err)
}
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
Middleware is a tg.Invoker middleware constructor.
func Chain ¶
func Chain(middlewares ...Middleware) Middleware
Chain returns a Middleware that chains multiple Middleware constructor calls.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package floodwait implements a tg.Invoker that handles flood wait errors.
|
Package floodwait implements a tg.Invoker that handles flood wait errors. |
|
Package ratelimit implements a tg.Invoker that limits request rate.
|
Package ratelimit implements a tg.Invoker that limits request rate. |
Click to show internal directories.
Click to hide internal directories.