server

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

func Migrate

func Migrate(dsn string) error

Migrate applies teled's schema migrations to the PostgreSQL database at dsn. Call it once before opening a pool for New.

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.

func (*Server) DC

func (s *Server) DC() int

DC returns the server's datacenter id.

func (*Server) Key

func (s *Server) Key() telegram.PublicKey

Key returns the server's public key, for clients to pin via telegram.Options.PublicKeys.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

Serve accepts and handles MTProto connections on ln until ctx is canceled.

Jump to

Keyboard shortcuts

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