Documentation
¶
Overview ¶
Package guard refuses every MTProto request that is not on an exact read allowlist before it leaves the process.
The method name is the TL schema name from the gotd type (TypeName(), e.g. "messages.getHistory"). Wrapper requests (invokeWithLayer, initConnection, invokeWithoutUpdates) are checked by their inner query. The allowlist is the set of reads the CLI makes plus what gotd sends internally; a name prefix is never enough (payments.resolveStarGiftOffer is a "resolve" that moves money).
Index ¶
- Constants
- func AllowOnce(ctx context.Context, method string) context.Context
- func Allowed(name string, authMode bool) bool
- func AllowedMethods(authMode bool) []string
- func Check(req any, readOnly, authMode bool) error
- func MethodName(req any) string
- func Middleware(readOnly func() bool, authMode bool) telegram.Middleware
- type BlockedError
Constants ¶
const MethodSendMessage = "messages.sendMessage"
MethodSendMessage is the RPC a watcher reply is granted (see AllowOnce).
Variables ¶
This section is empty.
Functions ¶
func AllowOnce ¶
AllowOnce returns a ctx under which exactly one request named method passes read-only mode. Other methods, later calls and always-denied methods stay blocked.
func Allowed ¶
Allowed reports whether a method name may be called while read-only. Check also refuses allowed methods used with write-like arguments.
func AllowedMethods ¶
AllowedMethods lists the read-only allowlist (sorted), for tests and docs.
func MethodName ¶
MethodName returns the TL name of a request, or "" if it has none.
func Middleware ¶
func Middleware(readOnly func() bool, authMode bool) telegram.Middleware
Middleware is the gotd middleware; readOnly is evaluated per call.
Types ¶
type BlockedError ¶
BlockedError is returned for a refused request.
func (*BlockedError) Error ¶
func (e *BlockedError) Error() string