Documentation
¶
Overview ¶
Package server assembles teled's storage, RPC handlers and MTProto transport into a single embeddable Telegram server.
It is the same wiring the teled binary uses, exposed as a library so that programs and tests can run a real Telegram server in-process. For a turnkey test harness (throwaway PostgreSQL, random port, ready-made client) see github.com/gotd/teled/teledtest.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// DC is this server's datacenter id, advertised in help.getConfig.
DC int
// Host and Port are the address advertised to clients in the DC options of
// help.getConfig. They should match how clients reach the listener.
Host string
Port int
// Logger receives server logs. Defaults to zap.NewNop.
Logger *zap.Logger
// Obfuscated wraps the listener in MTProto's obfuscated transport, as the
// production server does. Leave false to auto-detect the transport codec,
// which is what in-process test clients use.
Obfuscated bool
// TracerProvider and MeterProvider instrument the server. Nil yields no-op.
TracerProvider trace.TracerProvider
MeterProvider metric.MeterProvider
}
Options configures a Server. The zero value is valid: DC defaults to 1, Logger to a no-op, and telemetry to no-op providers.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an embeddable teled Telegram server. Construct it with New and run it with Serve.
func New ¶
func New(key *rsa.PrivateKey, pool *pgxpool.Pool, store teled.ObjectStore, opts Options) *Server
New assembles a server from a private key and storage. pool is a PostgreSQL pool already migrated with Migrate; pass nil to run with in-memory auth keys and no persistence (most RPCs then return NOT_IMPLEMENTED). store backs media upload/download and may be nil when media is unused.