mirror of
https://github.com/lukaszraczylo/go-telegram.git
synced 2026-06-05 22:43:59 +00:00
docs(reference): regenerate after perf series
Picks up new symbols from the perf commits: Context typed fields and Set method, header/buf pool vars in client and transport.
This commit is contained in:
@@ -80,7 +80,7 @@ var (
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Call"></a>
|
<a name="Call"></a>
|
||||||
## func [Call](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/call.go#L25>)
|
## func [Call](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/call.go#L53>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func Call[Req any, Resp any](ctx context.Context, b *Bot, method string, req Req) (Resp, error)
|
func Call[Req any, Resp any](ctx context.Context, b *Bot, method string, req Req) (Resp, error)
|
||||||
@@ -93,7 +93,7 @@ It is generic over both request and response types. Methods with no parameters m
|
|||||||
Call is exported because the api package \(which lives outside this one\) invokes it from generated method wrappers. User code should not normally call it directly — use the typed wrappers in package api instead.
|
Call is exported because the api package \(which lives outside this one\) invokes it from generated method wrappers. User code should not normally call it directly — use the typed wrappers in package api instead.
|
||||||
|
|
||||||
<a name="CallRaw"></a>
|
<a name="CallRaw"></a>
|
||||||
## func [CallRaw](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/call.go#L74>)
|
## func [CallRaw](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/call.go#L104>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func CallRaw[Req any](ctx context.Context, b *Bot, method string, req Req) (json.RawMessage, error)
|
func CallRaw[Req any](ctx context.Context, b *Bot, method string, req Req) (json.RawMessage, error)
|
||||||
@@ -296,7 +296,7 @@ type Logger interface {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="MultipartFile"></a>
|
<a name="MultipartFile"></a>
|
||||||
## type [MultipartFile](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/multipart.go#L27-L31>)
|
## type [MultipartFile](<https://github.com/lukaszraczylo/go-telegram/blob/main/client/multipart.go#L28-L32>)
|
||||||
|
|
||||||
MultipartFile describes a single file part in a multipart upload.
|
MultipartFile describes a single file part in a multipart upload.
|
||||||
|
|
||||||
|
|||||||
+27
-12
@@ -13,6 +13,7 @@ Package dispatch provides a typed router for Telegram updates. It consumes any t
|
|||||||
- [Variables](<#variables>)
|
- [Variables](<#variables>)
|
||||||
- [type Context](<#Context>)
|
- [type Context](<#Context>)
|
||||||
- [func NewContext\(ctx context.Context, b \*client.Bot, u \*api.Update\) \*Context](<#NewContext>)
|
- [func NewContext\(ctx context.Context, b \*client.Bot, u \*api.Update\) \*Context](<#NewContext>)
|
||||||
|
- [func \(c \*Context\) Set\(key string, val any\)](<#Context.Set>)
|
||||||
- [type Filter](<#Filter>)
|
- [type Filter](<#Filter>)
|
||||||
- [func All\[T any\]\(filters ...Filter\[T\]\) Filter\[T\]](<#All>)
|
- [func All\[T any\]\(filters ...Filter\[T\]\) Filter\[T\]](<#All>)
|
||||||
- [func Any\[T any\]\(filters ...Filter\[T\]\) Filter\[T\]](<#Any>)
|
- [func Any\[T any\]\(filters ...Filter\[T\]\) Filter\[T\]](<#Any>)
|
||||||
@@ -90,7 +91,7 @@ var ErrEndGroups = errors.New("dispatch: end groups")
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="Context"></a>
|
<a name="Context"></a>
|
||||||
## type [Context](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/context.go#L29-L34>)
|
## type [Context](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/context.go#L41-L49>)
|
||||||
|
|
||||||
Context bundles the per\-update state every handler receives.
|
Context bundles the per\-update state every handler receives.
|
||||||
|
|
||||||
@@ -100,25 +101,30 @@ Bot is the API client. Handlers reply by calling api.SendMessage\(c.Ctx, c.Bot,
|
|||||||
|
|
||||||
Update is the raw update; payload\-typed handlers also receive a narrowed pointer to one of its sub\-fields.
|
Update is the raw update; payload\-typed handlers also receive a narrowed pointer to one of its sub\-fields.
|
||||||
|
|
||||||
Values is a per\-update bag matchers populate. Conventional keys:
|
Command, CommandArgs and RegexMatch are populated by the router for the matching route kind; they replace the previous "command", "command\_args" and "regex\_match" entries in Values, which were the only conventional keys. Values remains for user\-defined custom keys.
|
||||||
|
|
||||||
```
|
Command is the matched bot command \(e.g. "/start"\); empty when the route is not a command match.
|
||||||
"command": string, the matched bot command (e.g. "/start")
|
|
||||||
"command_args": string, everything after the command
|
CommandArgs is everything after the command; empty when no command matched or the command had no trailing text.
|
||||||
"regex_match": []string, regex sub-matches when OnText matches
|
|
||||||
```
|
RegexMatch is the regex sub\-matches when an OnText/OnCallback regex route matched; nil otherwise.
|
||||||
|
|
||||||
|
Values is lazily allocated for user\-defined keys. Handlers that don't write pay no allocation. Reads against a nil map return the zero value. Writers must use Set instead of indexing the map directly.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type Context struct {
|
type Context struct {
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
Bot *client.Bot
|
Bot *client.Bot
|
||||||
Update *api.Update
|
Update *api.Update
|
||||||
Values map[string]any
|
Command string
|
||||||
|
CommandArgs string
|
||||||
|
RegexMatch []string
|
||||||
|
Values map[string]any
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewContext"></a>
|
<a name="NewContext"></a>
|
||||||
### func [NewContext](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/context.go#L38>)
|
### func [NewContext](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/context.go#L53>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewContext(ctx context.Context, b *client.Bot, u *api.Update) *Context
|
func NewContext(ctx context.Context, b *client.Bot, u *api.Update) *Context
|
||||||
@@ -126,6 +132,15 @@ func NewContext(ctx context.Context, b *client.Bot, u *api.Update) *Context
|
|||||||
|
|
||||||
NewContext constructs a Context. Used by Router internally; exposed for custom test harnesses.
|
NewContext constructs a Context. Used by Router internally; exposed for custom test harnesses.
|
||||||
|
|
||||||
|
<a name="Context.Set"></a>
|
||||||
|
### func \(\*Context\) [Set](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/context.go#L60>)
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (c *Context) Set(key string, val any)
|
||||||
|
```
|
||||||
|
|
||||||
|
Set writes key/val into Values, allocating the map on first use. Use this instead of \`c.Values\[k\] = v\` so the no\-write path stays allocation\-free.
|
||||||
|
|
||||||
<a name="Filter"></a>
|
<a name="Filter"></a>
|
||||||
## type [Filter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L9>)
|
## type [Filter](<https://github.com/lukaszraczylo/go-telegram/blob/main/dispatch/filter.go#L9>)
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ type Updater interface {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="WebhookOption"></a>
|
<a name="WebhookOption"></a>
|
||||||
## type [WebhookOption](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L38>)
|
## type [WebhookOption](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L57>)
|
||||||
|
|
||||||
WebhookOption configures a WebhookServer at construction time.
|
WebhookOption configures a WebhookServer at construction time.
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ type WebhookOption func(*webhookOptions)
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="WithBufferSize"></a>
|
<a name="WithBufferSize"></a>
|
||||||
### func [WithBufferSize](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L46>)
|
### func [WithBufferSize](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L65>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func WithBufferSize(n int) WebhookOption
|
func WithBufferSize(n int) WebhookOption
|
||||||
@@ -172,7 +172,7 @@ func WithBufferSize(n int) WebhookOption
|
|||||||
WithBufferSize sets the size of the updates channel buffer. Default is 64.
|
WithBufferSize sets the size of the updates channel buffer. Default is 64.
|
||||||
|
|
||||||
<a name="WebhookServer"></a>
|
<a name="WebhookServer"></a>
|
||||||
## type [WebhookServer](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L24-L35>)
|
## type [WebhookServer](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L43-L54>)
|
||||||
|
|
||||||
WebhookServer implements Updater by exposing an http.Handler that receives updates from Telegram. It can be mounted on the user's own HTTP server \(via ServeHTTP\) or run standalone \(via ListenAndServe\).
|
WebhookServer implements Updater by exposing an http.Handler that receives updates from Telegram. It can be mounted on the user's own HTTP server \(via ServeHTTP\) or run standalone \(via ListenAndServe\).
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ type WebhookServer struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
<a name="NewWebhookServer"></a>
|
<a name="NewWebhookServer"></a>
|
||||||
### func [NewWebhookServer](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L52>)
|
### func [NewWebhookServer](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L71>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewWebhookServer(b *client.Bot, opts ...WebhookOption) *WebhookServer
|
func NewWebhookServer(b *client.Bot, opts ...WebhookOption) *WebhookServer
|
||||||
@@ -194,7 +194,7 @@ func NewWebhookServer(b *client.Bot, opts ...WebhookOption) *WebhookServer
|
|||||||
NewWebhookServer constructs a WebhookServer with default buffer size \(64\). Use WithBufferSize to override.
|
NewWebhookServer constructs a WebhookServer with default buffer size \(64\). Use WithBufferSize to override.
|
||||||
|
|
||||||
<a name="WebhookServer.ListenAndServe"></a>
|
<a name="WebhookServer.ListenAndServe"></a>
|
||||||
### func \(\*WebhookServer\) [ListenAndServe](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L150>)
|
### func \(\*WebhookServer\) [ListenAndServe](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L168>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) ListenAndServe(ctx context.Context, addr string) error
|
func (w *WebhookServer) ListenAndServe(ctx context.Context, addr string) error
|
||||||
@@ -203,7 +203,7 @@ func (w *WebhookServer) ListenAndServe(ctx context.Context, addr string) error
|
|||||||
ListenAndServe starts an HTTP server on addr and blocks until Stop is called \(which triggers Shutdown with the caller's context\) or the server returns an error other than http.ErrServerClosed. Callers must invoke Stop\(ctx\) to cleanly shut down the server; the ctx passed here is only used as the server's base context for incoming requests.
|
ListenAndServe starts an HTTP server on addr and blocks until Stop is called \(which triggers Shutdown with the caller's context\) or the server returns an error other than http.ErrServerClosed. Callers must invoke Stop\(ctx\) to cleanly shut down the server; the ctx passed here is only used as the server's base context for incoming requests.
|
||||||
|
|
||||||
<a name="WebhookServer.Run"></a>
|
<a name="WebhookServer.Run"></a>
|
||||||
### func \(\*WebhookServer\) [Run](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L71>)
|
### func \(\*WebhookServer\) [Run](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L90>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) Run(ctx context.Context) error
|
func (w *WebhookServer) Run(ctx context.Context) error
|
||||||
@@ -212,7 +212,7 @@ func (w *WebhookServer) Run(ctx context.Context) error
|
|||||||
Run implements Updater. It blocks until Stop is called or ctx is cancelled. If the server has not been started via ListenAndServe, Run only watches for shutdown — the user is expected to mount ServeHTTP on their own router.
|
Run implements Updater. It blocks until Stop is called or ctx is cancelled. If the server has not been started via ListenAndServe, Run only watches for shutdown — the user is expected to mount ServeHTTP on their own router.
|
||||||
|
|
||||||
<a name="WebhookServer.ServeHTTP"></a>
|
<a name="WebhookServer.ServeHTTP"></a>
|
||||||
### func \(\*WebhookServer\) [ServeHTTP](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L97>)
|
### func \(\*WebhookServer\) [ServeHTTP](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L116>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
func (w *WebhookServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
||||||
@@ -221,7 +221,7 @@ func (w *WebhookServer) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
ServeHTTP implements http.Handler. Telegram POSTs each update as JSON to this endpoint. Non\-POST requests get 405; bad bodies get 400; secret token mismatches get 401.
|
ServeHTTP implements http.Handler. Telegram POSTs each update as JSON to this endpoint. Non\-POST requests get 405; bad bodies get 400; secret token mismatches get 401.
|
||||||
|
|
||||||
<a name="WebhookServer.Stop"></a>
|
<a name="WebhookServer.Stop"></a>
|
||||||
### func \(\*WebhookServer\) [Stop](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L83>)
|
### func \(\*WebhookServer\) [Stop](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L102>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) Stop(ctx context.Context) error
|
func (w *WebhookServer) Stop(ctx context.Context) error
|
||||||
@@ -230,7 +230,7 @@ func (w *WebhookServer) Stop(ctx context.Context) error
|
|||||||
Stop implements Updater.
|
Stop implements Updater.
|
||||||
|
|
||||||
<a name="WebhookServer.Updates"></a>
|
<a name="WebhookServer.Updates"></a>
|
||||||
### func \(\*WebhookServer\) [Updates](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L65>)
|
### func \(\*WebhookServer\) [Updates](<https://github.com/lukaszraczylo/go-telegram/blob/main/transport/webhook.go#L84>)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (w *WebhookServer) Updates() <-chan api.Update
|
func (w *WebhookServer) Updates() <-chan api.Update
|
||||||
|
|||||||
Reference in New Issue
Block a user