config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config holds the data dir layout, config.json, env switches and file-mode helpers.

Index

Constants

View Source
const (
	EnvHome     = "TGAC_HOME"
	EnvReadOnly = "TGAC_READONLY"
	EnvLockWait = "TGAC_LOCK_WAIT"

	DefaultLockWait          = 90 * time.Second
	DefaultDeviceModel       = "telegram-agent-cli"
	DefaultLangCode          = "en"
	DefaultWatcherSessionEnv = "TGAC_WATCHER_SESSION"
	DefaultGlobalPerHour     = 30
)

Variables

This section is empty.

Functions

func DefaultHome

func DefaultHome() (string, error)

DefaultHome is $TGAC_HOME or ~/.config/telegram-agent-cli.

func LockWait

func LockWait() time.Duration

LockWait is TGAC_LOCK_WAIT seconds (default 90).

func Mode

func Mode(path string) string

Mode returns the permission bits of path as "0700", or "" if it does not exist.

func ReadOnly

func ReadOnly() bool

ReadOnly is true unless TGAC_READONLY is one of 0|false|no|off (case-insensitive).

func ReadOnlyFrom

func ReadOnlyFrom(v string) bool

ReadOnlyFrom applies the TGAC_READONLY rule to a raw value.

func ValidAPIHash

func ValidAPIHash(s string) bool

ValidAPIHash reports whether s looks like a my.telegram.org api_hash.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, mode os.FileMode) error

WriteFileAtomic writes via a temp file + rename so readers never see a partial file.

Types

type Config

type Config struct {
	APIID             int    `json:"api_id"`
	APIHash           string `json:"api_hash"`
	Phone             string `json:"phone"`
	DeviceModel       string `json:"device_model,omitempty"`
	SystemVersion     string `json:"system_version,omitempty"`
	AppVersion        string `json:"app_version,omitempty"`
	LangCode          string `json:"lang_code,omitempty"`
	WatcherSessionEnv string `json:"watcher_session_env,omitempty"`
	GlobalPerHour     int    `json:"global_per_hour,omitempty"`
}

Config is config.json.

func (Config) Validate

func (c Config) Validate() error

Validate checks the fields needed to talk to Telegram.

func (Config) WithDefaults

func (c Config) WithDefaults(appVersion string) Config

WithDefaults fills empty optional fields. appVersion is the binary's version.

type Lock

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

Lock is an flock on a file; the data dir's .lock lets one process talk to Telegram at a time.

func (*Lock) Acquire

func (l *Lock) Acquire(ctx context.Context, wait time.Duration) error

Acquire waits up to wait for the exclusive lock; a timeout is a lock_busy error.

func (*Lock) Release

func (l *Lock) Release()

Release drops the lock; safe to call when not held.

type Paths

type Paths struct {
	Home string
}

Paths is the data dir layout.

func (Paths) Answered

func (p Paths) Answered() string

func (Paths) Config

func (p Paths) Config() string

func (Paths) ConfigExists

func (p Paths) ConfigExists() bool

Exists reports whether config.json exists.

func (Paths) Ensure

func (p Paths) Ensure() error

Ensure creates the data dir with mode 0700 (and tightens it if it exists).

func (Paths) FixModes

func (p Paths) FixModes()

FixModes tightens the data dir to 0700 and every regular file in it to 0600.

func (Paths) LoadConfig

func (p Paths) LoadConfig() (Config, error)

LoadConfig reads config.json; a missing file is an auth error.

func (Paths) Lock

func (p Paths) Lock() string

func (Paths) NewLock

func (p Paths) NewLock() *Lock

NewLock returns an unlocked Lock on the data dir's .lock file.

func (Paths) NewWatchLock

func (p Paths) NewWatchLock() *Lock

NewWatchLock returns the lock that serialises watcher check-and-send runs.

func (Paths) PauseAll

func (p Paths) PauseAll() string

func (Paths) Peers

func (p Paths) Peers() string

func (Paths) Pending

func (p Paths) Pending() string

func (Paths) SaveConfig

func (p Paths) SaveConfig(c Config) error

SaveConfig writes config.json with mode 0600.

func (Paths) Session

func (p Paths) Session() string

func (Paths) WatchLock

func (p Paths) WatchLock() string

WatchLock serialises watcher check-and-send runs (see Paths.NewWatchLock).

func (Paths) WatcherDir

func (p Paths) WatcherDir(name string) string

WatcherDir is the data-dir directory of one watcher; name must be validated first.

func (Paths) Watchers

func (p Paths) Watchers() string

func (Paths) WatchersDir

func (p Paths) WatchersDir() string

WatchersDir holds one directory per watcher (send logs, user PAUSE) inside the data dir.

func (Paths) WritePrivate

func (p Paths) WritePrivate(path string, data []byte) error

WritePrivate atomically writes a 0600 file inside the data dir.

Jump to

Keyboard shortcuts

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