utils

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsMap

func AsMap(input interface{}) map[string]interface{}

AsMap attempts to convert the provided input to a map[string]interface{}.

If the conversion is successful, it returns the map; otherwise, it returns nil.

func BotIDFromToken

func BotIDFromToken(token string) string

BotIDFromToken extracts and returns the bot ID from the provided token string.

If the token is longer than 80 characters or does not contain ':', it returns an empty string.

func Dump

func Dump(input map[string]interface{})

Dump pretty print TDLib object

func IsBool

func IsBool(value string) bool

Check if a value is a boolean

func IsInt

func IsInt(value string) bool

Check if a value can be parsed as an integer

func KeyExists

func KeyExists(m map[string]interface{}, key string) bool

KeyExists checks whether the specified key exists in the given map[string]interface{}.

It returns true if the key exists, otherwise false.

func MakeError

func MakeError(code int, message string) map[string]interface{}

MakeError creates a map representing TDLib error with the given code and message.

func MakeObject

func MakeObject(requestType string, params Params) map[string]interface{}

MakeObject creates a map with the given requestType and additional parameters.

func Marshal

func Marshal(input map[string]interface{}) (string, error)

Marshal encodes the provided map[string]interface{} input into a JSON string.

If an error occurs during encoding, it returns an empty string and the error.

func MarshalWithIndent

func MarshalWithIndent(input map[string]interface{}) (string, error)

MarshalWithIndent encodes the provided map[string]interface{} input into a 4-indented JSON string.

If an error occurs during encoding, it returns an empty string and the error.

func PanicOnErr

func PanicOnErr(err interface{}, msg string, v interface{}, exit bool)

PanicOnErr checks the error or boolean value and either panics or exits based on the exit flag.

func Type

func Type(update map[string]interface{}) string

Type returns the "@type" field from the provided TDLib object as a string.

If the "@type" field is missing, it returns an empty string.

func Unmarshal

func Unmarshal(input string) (map[string]interface{}, error)

Unmarshal decodes the input JSON string into a map[string]interface{}.

If an error occurs during decoding, it returns nil and the error.

func UnmarshalWithTarget added in v0.1.7

func UnmarshalWithTarget(input []byte, target interface{}) error

UnmarshalWithTarget decodes the input JSON string into the target struct. The target must be a pointer to a struct.

If an error occurs during decoding, it returns the error.

func UnsafeMarshal

func UnsafeMarshal(input map[string]interface{}) string

UnsafeMarshal encodes the provided map[string]interface{} input into a JSON string.

If an error occurs during encoding, it prints the error and returns an empty string.

func UnsafeMarshalWithIndent

func UnsafeMarshalWithIndent(input map[string]interface{}) string

UnsafeMarshalWithIndent encodes the provided map[string]interface{} input into an indented JSON string.

If an error occurs during encoding, it prints the error and returns an empty string.

func UnsafeUnmarshal

func UnsafeUnmarshal(input string) map[string]interface{}

UnsafeUnmarshal decodes the input JSON string into a map[string]interface{}.

If an error occurs during decoding, it prints the error and returns nil.

Types

type IdGenerator

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

IdGenerator is a thread-safe generator for unique request IDs.

func NewIdGenerator

func NewIdGenerator() *IdGenerator

NewIdGenerator creates and returns a new instance of IdGenerator,

func (*IdGenerator) GenerateID

func (id *IdGenerator) GenerateID() int

GenerateID increments the current request ID and returns the new value.

This method is thread-safe.

type Params

type Params map[string]interface{}

Params represents a map of string keys to interface{} values, used to store various parameters in requests and responses.

type SafeResultsMap

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

SafeResultsMap is a thread-safe map for managing channels associated with TDLib responses to requests.

func NewSafeResultsMap

func NewSafeResultsMap() *SafeResultsMap

NewSafeResultsMap creates and returns a new SafeResultsMap instance.

func (*SafeResultsMap) ClearChannels

func (srm *SafeResultsMap) ClearChannels(send_abort bool)

ClearChannels closes all channels in the SafeResultsMap and deletes them.

If send_abort is true, it sends TDLib "Request aborted" error to each channel before closing it.

func (*SafeResultsMap) Delete

func (srm *SafeResultsMap) Delete(key string, send_abort bool)

Delete removes the channel for the specified key, closing it and optionally sending an abort message.

func (*SafeResultsMap) Get

func (srm *SafeResultsMap) Get(key string) (chan map[string]interface{}, bool)

Get retrieves the channel for the specified key.

func (*SafeResultsMap) Make

func (srm *SafeResultsMap) Make(key string) chan map[string]interface{}

Make creates and returns a new channel for the specified key.

func (*SafeResultsMap) SafeSend

func (srm *SafeResultsMap) SafeSend(ch chan<- map[string]interface{}, value map[string]interface{})

SafeSend safely sends TDLib object to the channel, recovering if the channel is closed.

type Scheduler added in v0.1.9

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

func NewScheduler added in v0.1.9

func NewScheduler(db_dir string, event_callback func(string, int64, string)) *Scheduler

func (*Scheduler) CancelEvent added in v0.1.9

func (sched *Scheduler) CancelEvent(eventID int64) int64

func (*Scheduler) Close added in v0.1.9

func (sched *Scheduler) Close() error

func (*Scheduler) CreateEvent added in v0.1.9

func (sched *Scheduler) CreateEvent(name string, sendAt int64, payload string) (int64, error)

func (*Scheduler) Start added in v0.1.9

func (sched *Scheduler) Start()

Jump to

Keyboard shortcuts

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