Documentation
¶
Overview ¶
Package config holds the data dir layout, config.json, env switches and file-mode helpers.
Index ¶
- Constants
- func DefaultHome() (string, error)
- func LockWait() time.Duration
- func Mode(path string) string
- func ReadOnly() bool
- func ReadOnlyFrom(v string) bool
- func ValidAPIHash(s string) bool
- func WriteFileAtomic(path string, data []byte, mode os.FileMode) error
- type Config
- type Lock
- type Paths
- func (p Paths) Answered() string
- func (p Paths) Config() string
- func (p Paths) ConfigExists() bool
- func (p Paths) Ensure() error
- func (p Paths) FixModes()
- func (p Paths) LoadConfig() (Config, error)
- func (p Paths) Lock() string
- func (p Paths) NewLock() *Lock
- func (p Paths) NewWatchLock() *Lock
- func (p Paths) PauseAll() string
- func (p Paths) Peers() string
- func (p Paths) Pending() string
- func (p Paths) SaveConfig(c Config) error
- func (p Paths) Session() string
- func (p Paths) WatchLock() string
- func (p Paths) WatcherDir(name string) string
- func (p Paths) Watchers() string
- func (p Paths) WatchersDir() string
- func (p Paths) WritePrivate(path string, data []byte) error
Constants ¶
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 ¶
DefaultHome is $TGAC_HOME or ~/.config/telegram-agent-cli.
func ReadOnly ¶
func ReadOnly() bool
ReadOnly is true unless TGAC_READONLY is one of 0|false|no|off (case-insensitive).
func ReadOnlyFrom ¶
ReadOnlyFrom applies the TGAC_READONLY rule to a raw value.
func ValidAPIHash ¶
ValidAPIHash reports whether s looks like a my.telegram.org api_hash.
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) WithDefaults ¶
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.
type Paths ¶
type Paths struct {
Home string
}
Paths is the data dir layout.
func (Paths) ConfigExists ¶
Exists reports whether config.json 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 ¶
LoadConfig reads config.json; a missing file is an auth error.
func (Paths) NewWatchLock ¶
NewWatchLock returns the lock that serialises watcher check-and-send runs.
func (Paths) SaveConfig ¶
SaveConfig writes config.json with mode 0600.
func (Paths) WatcherDir ¶
WatcherDir is the data-dir directory of one watcher; name must be validated first.
func (Paths) WatchersDir ¶
WatchersDir holds one directory per watcher (send logs, user PAUSE) inside the data dir.