utils

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DcList = DCOptions{
	DCS: map[int][]DC{
		1: {{"149.154.175.58:443", false}},
		2: {{"149.154.167.50:443", false}},
		3: {{"149.154.175.100:443", false}},
		4: {{"149.154.167.91:443", false},
			{"[2001:067c:04e8:f002::a]:443", true}},
		5: {{"91.108.56.151:443", false}},
	},
	TestDCs: map[int]string{
		1: "149.154.175.10:443",
		2: "149.154.167.40:443",
		3: "149.154.175.117:443",
	},
	CdnDCs: map[int][]DC{
		201: {{"91.108.23.100:443", false}},
		203: {{"91.105.192.100:443", false},
			{"[2a0a:f280:0203:000a:5000:0000:0000:0100]:443", true}},
	},
}
View Source
var (
	RegexpDCMigrate = regexp.MustCompile(`DC (\d+)`)
)

Functions

func AskForConfirmation

func AskForConfirmation() bool

func AuthKeyHash

func AuthKeyHash(key []byte) []byte

func CloseChannelWithoutPanic

func CloseChannelWithoutPanic(c chan tl.Object)

func FmtIp added in v1.4.1

func FmtIp(ipv6WithPort string) string

func FmtMethod added in v1.6.3

func FmtMethod(data tl.Object) string

func FullStack

func FullStack()

func GenerateSessionID

func GenerateSessionID() int64

func GetDefaultHostIp added in v1.6.1

func GetDefaultHostIp(dc int, test bool, ipv6 bool) string

func MinSafeDuration added in v1.6.7

func MinSafeDuration(d int) time.Duration

func NewMsgIDGenerator

func NewMsgIDGenerator() func(timeOffset int64) int64

func OrDefault added in v1.6.9

func OrDefault[T comparable](val, def T) T

func RandomBytes

func RandomBytes(size int) []byte

func RandomSenderID added in v1.6.9

func RandomSenderID() string

func Sha1

func Sha1(input string) []byte

func Sha1Byte

func Sha1Byte(input []byte) []byte

func Xor

func Xor(dst, src []byte)

Types

type AudioInfo added in v1.6.3

type AudioInfo struct {
	Duration   int64
	Bitrate    uint32
	Channels   uint32
	SampleRate uint32
}

func ParseFLAC added in v1.6.3

func ParseFLAC(filename string) (*AudioInfo, error)

func ParseM4A added in v1.6.3

func ParseM4A(filename string) (*AudioInfo, error)

func ParseMP3 added in v1.6.3

func ParseMP3(filename string) (*AudioInfo, error)

func ParseWAV added in v1.6.3

func ParseWAV(filename string) (*AudioInfo, error)

type Bitset added in v1.6.9

type Bitset struct {
	// contains filtered or unexported fields
}

func CloneBitset added in v1.6.9

func CloneBitset(from *Bitset) *Bitset

func NewBitset added in v1.6.9

func NewBitset(v ...bool) *Bitset

func (*Bitset) Append added in v1.6.9

func (b *Bitset) Append(other *Bitset) error

func (*Bitset) AppendBools added in v1.6.9

func (b *Bitset) AppendBools(bits ...bool)

func (*Bitset) AppendByte added in v1.6.9

func (b *Bitset) AppendByte(value byte, numBits int) error

func (*Bitset) AppendBytes added in v1.6.9

func (b *Bitset) AppendBytes(data []byte) error

func (*Bitset) AppendNumBools added in v1.6.9

func (b *Bitset) AppendNumBools(num int, value bool)

func (*Bitset) AppendUint32 added in v1.6.9

func (b *Bitset) AppendUint32(value uint32, numBits int) error

func (*Bitset) At added in v1.6.9

func (b *Bitset) At(index int) bool

func (*Bitset) ByteAt added in v1.6.9

func (b *Bitset) ByteAt(index int) byte

func (*Bitset) Len added in v1.6.9

func (b *Bitset) Len() int

func (*Bitset) Substr added in v1.6.9

func (b *Bitset) Substr(start, end int) (*Bitset, error)

type DC added in v1.4.0

type DC struct {
	Addr string
	V    bool
}

type DCOptions

type DCOptions struct {
	DCS     map[int][]DC
	TestDCs map[int]string
	CdnDCs  map[int][]DC
}

func NewDCOptions added in v1.6.1

func NewDCOptions() *DCOptions

func (*DCOptions) GetCdnAddr added in v1.6.1

func (opt *DCOptions) GetCdnAddr(dc int) (string, bool)

func (*DCOptions) GetHostIp added in v1.6.1

func (opt *DCOptions) GetHostIp(dc int, test bool, ipv6 bool) string

func (*DCOptions) SearchAddr added in v1.6.1

func (opt *DCOptions) SearchAddr(addr string) int

func (*DCOptions) SetDCs added in v1.6.1

func (opt *DCOptions) SetDCs(dcs map[int][]DC, cdnDcs map[int][]DC)

type Hook added in v1.6.7

type Hook func(*LogEntry)

type JSONFormatter added in v1.6.7

type JSONFormatter struct {
	PrettyPrint     bool
	TimestampFormat string
}

JSONFormatter formats logs as JSON

func (*JSONFormatter) Format added in v1.6.7

func (f *JSONFormatter) Format(entry *LogEntry) string

type LogEntry added in v1.6.7

type LogEntry struct {
	Time       time.Time      `json:"time"`
	Level      LogLevel       `json:"level"`
	Message    string         `json:"message"`
	Prefix     string         `json:"prefix,omitempty"`
	File       string         `json:"file,omitempty"`
	Line       int            `json:"line,omitempty"`
	Function   string         `json:"function,omitempty"`
	Fields     map[string]any `json:"fields,omitempty"`
	Error      error          `json:"error,omitempty"`
	StackTrace string         `json:"stack_trace,omitempty"`
}

type LogFormatter added in v1.6.7

type LogFormatter interface {
	Format(entry *LogEntry) string
}

type LogLevel added in v1.4.3

type LogLevel int
const (
	TraceLevel LogLevel = iota
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
	PanicLevel
	NoLevel
)

func (LogLevel) String added in v1.6.7

func (l LogLevel) String() string

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(prefix string) *Logger

func NewLoggerWithConfig added in v1.6.7

func NewLoggerWithConfig(config *LoggerConfig) *Logger

func (*Logger) AddHook added in v1.6.7

func (l *Logger) AddHook(hook Hook) *Logger

func (*Logger) Clone added in v1.6.7

func (l *Logger) Clone() *Logger

func (*Logger) Close added in v1.6.7

func (l *Logger) Close() error

func (*Logger) Color added in v1.4.2

func (l *Logger) Color() bool

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

func (*Logger) DebugErr added in v1.6.7

func (l *Logger) DebugErr(err error)

func (*Logger) Debugf added in v1.6.7

func (l *Logger) Debugf(format string, args ...any)

func (*Logger) EnableRotation added in v1.6.7

func (l *Logger) EnableRotation(maxFileSize int64, logFilePath string) *Logger

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

func (*Logger) ErrorErr added in v1.6.7

func (l *Logger) ErrorErr(err error)

func (*Logger) Errorf added in v1.6.7

func (l *Logger) Errorf(format string, args ...any)

func (*Logger) Fatal added in v1.6.7

func (l *Logger) Fatal(msg string, args ...any)

func (*Logger) Fatalf added in v1.6.7

func (l *Logger) Fatalf(format string, args ...any)

func (*Logger) Flush added in v1.6.7

func (l *Logger) Flush() error

func (*Logger) GetLevel added in v1.6.7

func (l *Logger) GetLevel() LogLevel

func (*Logger) GetPrefix added in v1.6.7

func (l *Logger) GetPrefix() string

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

func (*Logger) Infof added in v1.6.7

func (l *Logger) Infof(format string, args ...any)

func (*Logger) Lev

func (l *Logger) Lev() LogLevel

func (*Logger) Panic

func (l *Logger) Panic(msg string, args ...any)

func (*Logger) Panicf added in v1.6.7

func (l *Logger) Panicf(format string, args ...any)

func (*Logger) SetColor added in v1.6.7

func (l *Logger) SetColor(enabled bool) *Logger

func (*Logger) SetFormatter added in v1.6.7

func (l *Logger) SetFormatter(formatter LogFormatter) *Logger

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel) *Logger

func (*Logger) SetOutput added in v1.6.7

func (l *Logger) SetOutput(w io.Writer) *Logger

func (*Logger) SetPrefix added in v1.4.5

func (l *Logger) SetPrefix(prefix string) *Logger

func (*Logger) SetTimestampFormat added in v1.6.7

func (l *Logger) SetTimestampFormat(format string) *Logger

func (*Logger) ShowCaller added in v1.6.7

func (l *Logger) ShowCaller(enabled bool) *Logger

func (*Logger) ShowFunction added in v1.6.7

func (l *Logger) ShowFunction(enabled bool) *Logger

func (*Logger) Trace

func (l *Logger) Trace(msg string, args ...any)

func (*Logger) TraceErr added in v1.6.7

func (l *Logger) TraceErr(err error)

func (*Logger) Tracef added in v1.6.7

func (l *Logger) Tracef(format string, args ...any)

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

func (*Logger) WarnErr added in v1.6.7

func (l *Logger) WarnErr(err error)

func (*Logger) Warnf added in v1.6.7

func (l *Logger) Warnf(format string, args ...any)

func (*Logger) Warning added in v1.6.7

func (l *Logger) Warning(msg string, args ...any)

func (*Logger) Warningf added in v1.6.7

func (l *Logger) Warningf(format string, args ...any)

func (*Logger) WithError added in v1.6.7

func (l *Logger) WithError(err error) *Logger

func (*Logger) WithField added in v1.6.7

func (l *Logger) WithField(key string, value any) *Logger

func (*Logger) WithFields added in v1.6.7

func (l *Logger) WithFields(fields map[string]any) *Logger

func (*Logger) WithPrefix added in v1.6.7

func (l *Logger) WithPrefix(prefix string) *Logger

type LoggerConfig added in v1.6.7

type LoggerConfig struct {
	Level           LogLevel
	Prefix          string
	Output          io.Writer
	Formatter       LogFormatter
	Color           bool
	ShowCaller      bool
	ShowFunction    bool
	TimestampFormat string
	BufferSize      int
	AsyncMode       bool
	AsyncQueueSize  int
	ErrorHandler    func(error)
}

func DefaultConfig added in v1.6.7

func DefaultConfig() *LoggerConfig

type MKVInfo added in v1.6.3

type MKVInfo struct {
	Duration float64
	Width    uint32
	Height   uint32
}

func ParseMKV added in v1.6.3

func ParseMKV(filename string) (*MKVInfo, error)

func ParseWebM added in v1.6.3

func ParseWebM(filename string) (*MKVInfo, error)

type MP4Info added in v1.6.3

type MP4Info struct {
	Duration  int64
	Width     uint32
	Height    uint32
	Timescale uint32
}

func ParseMP4 added in v1.6.3

func ParseMP4(filename string) (*MP4Info, error)

type PingParams

type PingParams struct {
	PingID int64
}

func (*PingParams) CRC

func (*PingParams) CRC() uint32

type Proxy added in v1.6.7

type Proxy struct {
	Type     string // socks4, socks5, http, https, mtproxy
	Host     string
	Port     int
	Username string
	Password string
	Secret   string // for MTProxy
}

func (*Proxy) GetHost added in v1.6.7

func (p *Proxy) GetHost() string

func (*Proxy) GetPassword added in v1.6.7

func (p *Proxy) GetPassword() string

func (*Proxy) GetPort added in v1.6.7

func (p *Proxy) GetPort() int

func (*Proxy) GetSecret added in v1.6.7

func (p *Proxy) GetSecret() string

func (*Proxy) GetType added in v1.6.7

func (p *Proxy) GetType() string

func (*Proxy) GetUsername added in v1.6.7

func (p *Proxy) GetUsername() string

func (*Proxy) IsEmpty added in v1.6.7

func (p *Proxy) IsEmpty() bool

func (*Proxy) String added in v1.6.7

func (p *Proxy) String() string

func (*Proxy) ToURL added in v1.6.7

func (p *Proxy) ToURL() *url.URL

type QRCode added in v1.6.9

type QRCode struct {
	Content         string
	ForegroundColor color.Color
	BackgroundColor color.Color
	DisableBorder   bool
	// contains filtered or unexported fields
}

func NewQRCode added in v1.6.9

func NewQRCode(content string) (*QRCode, error)

func (*QRCode) Base64PNG added in v1.6.9

func (q *QRCode) Base64PNG(size int) string

func (*QRCode) Bitmap added in v1.6.9

func (q *QRCode) Bitmap() ([][]bool, error)

func (*QRCode) Image added in v1.6.9

func (q *QRCode) Image(size int) (image.Image, error)

func (*QRCode) PNG added in v1.6.9

func (q *QRCode) PNG(size int) ([]byte, error)

func (*QRCode) ToSmallString added in v1.6.9

func (q *QRCode) ToSmallString(inverse bool) string

type SyncIntObjectChan

type SyncIntObjectChan struct {
	// contains filtered or unexported fields
}

func NewSyncIntObjectChan

func NewSyncIntObjectChan() *SyncIntObjectChan

func (*SyncIntObjectChan) Add

func (s *SyncIntObjectChan) Add(key int, value chan tl.Object)

func (*SyncIntObjectChan) Close

func (s *SyncIntObjectChan) Close()

func (*SyncIntObjectChan) Delete

func (s *SyncIntObjectChan) Delete(key int) bool

func (*SyncIntObjectChan) Get

func (s *SyncIntObjectChan) Get(key int) (chan tl.Object, bool)

func (*SyncIntObjectChan) Has

func (s *SyncIntObjectChan) Has(key int) bool

func (*SyncIntObjectChan) Keys

func (s *SyncIntObjectChan) Keys() []int

func (*SyncIntObjectChan) Reset

func (s *SyncIntObjectChan) Reset()

type SyncIntReflectTypes

type SyncIntReflectTypes struct {
	// contains filtered or unexported fields
}

func NewSyncIntReflectTypes

func NewSyncIntReflectTypes() *SyncIntReflectTypes

func (*SyncIntReflectTypes) Add

func (s *SyncIntReflectTypes) Add(key int, value []reflect.Type)

func (*SyncIntReflectTypes) Delete

func (s *SyncIntReflectTypes) Delete(key int) bool

func (*SyncIntReflectTypes) Get

func (s *SyncIntReflectTypes) Get(key int) ([]reflect.Type, bool)

func (*SyncIntReflectTypes) Has

func (s *SyncIntReflectTypes) Has(key int) bool

func (*SyncIntReflectTypes) Keys

func (s *SyncIntReflectTypes) Keys() []int

func (*SyncIntReflectTypes) Reset

func (s *SyncIntReflectTypes) Reset()

type SyncSet

type SyncSet[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSyncSet

func NewSyncSet[T comparable]() *SyncSet[T]

func (*SyncSet[T]) Add

func (s *SyncSet[T]) Add(key T) bool

func (*SyncSet[T]) Clear

func (s *SyncSet[T]) Clear()

func (*SyncSet[T]) Clone

func (s *SyncSet[T]) Clone() *SyncSet[T]

func (*SyncSet[T]) Delete

func (s *SyncSet[T]) Delete(key T)

func (*SyncSet[T]) ForEach

func (s *SyncSet[T]) ForEach(fn func(key T) bool)

func (*SyncSet[T]) Has

func (s *SyncSet[T]) Has(key T) bool

func (*SyncSet[T]) Keys

func (s *SyncSet[T]) Keys() []T

func (*SyncSet[T]) Len

func (s *SyncSet[T]) Len() int

func (*SyncSet[T]) Pop

func (s *SyncSet[T]) Pop(key T) bool

type TextFormatter added in v1.6.7

type TextFormatter struct {
	NoColor         bool
	ShowTimestamp   bool
	ShowLevel       bool
	ShowCaller      bool
	ShowFunction    bool
	TimestampFormat string
	FullTimestamp   bool
	PadLevelText    bool
}

TextFormatter formats logs as human-readable text

func (*TextFormatter) Format added in v1.6.7

func (f *TextFormatter) Format(entry *LogEntry) string

type UpdatesGetStateParams

type UpdatesGetStateParams struct{}

Jump to

Keyboard shortcuts

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