app

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = AppVersion{
	Commit:    build.Commit,
	Version:   build.Version,
	BuildDate: build.BuildDate,
}

Functions

func CheckGitHubToken added in v0.6.0

func CheckGitHubToken() error

CheckGitHubToken reports whether the persisted token can be opened. A missing token is not an error.

func Db

func Db() *gorm.DB

func DeleteGitHubToken added in v0.6.0

func DeleteGitHubToken()

DeleteGitHubToken removes the token from the next persisted file.

func GetGitHubToken added in v0.6.0

func GetGitHubToken() string

GetGitHubToken returns the configured plaintext token, or "" when none is set or the sealed value cannot be opened.

func GitHubTokenConfigured added in v0.6.0

func GitHubTokenConfigured() bool

GitHubTokenConfigured reports whether a token is stored. It checks the sealed value only and never decrypts.

func InitDb added in v0.2.0

func InitDb(conf *Configuration) error

func InitLanguage added in v0.2.0

func InitLanguage(lang string)

func InitLogger added in v0.2.0

func InitLogger(conf *Configuration) error

func IsDevelopmentMode added in v0.2.0

func IsDevelopmentMode() bool

func IsProductionMode added in v0.2.0

func IsProductionMode() bool

func IsTestMode added in v0.2.0

func IsTestMode() bool

func LockdownDir added in v0.4.0

func LockdownDir() string

func ReloadConfig

func ReloadConfig()

func RemotePairingDir added in v0.4.0

func RemotePairingDir() string

func SaveSettings added in v0.2.0

func SaveSettings()

func SetGitHubToken added in v0.6.0

func SetGitHubToken(plaintext string) error

SetGitHubToken validates and seals plaintext, staging it for the next SaveSettings call. The caller must call SaveSettings to persist it.

func SideloadDataDir added in v0.3.0

func SideloadDataDir() string

func ValidateGitHubToken added in v0.6.0

func ValidateGitHubToken(token string) error

ValidateGitHubToken rejects empty-surrounding whitespace, control characters and masked previews so a copied mask can never be stored.

Types

type AppMode added in v0.2.0

type AppMode string
const (
	DevelopmentMode AppMode = "development"
	ProductionMode  AppMode = "production"
	TestMode        AppMode = "test"
)

func Environment

func Environment() AppMode

type AppVersion added in v0.2.0

type AppVersion struct {
	Commit    string `json:"commit"`
	Version   string `json:"version"`
	BuildDate string `json:"build_date"`
}

Info holds build information

type Configuration added in v0.2.0

type Configuration struct {
	App struct {
		DeveloperDiskImage struct {
			ImageSource string `koanf:"image_source" json:"image_source" default:"https://raw.githubusercontent.com/bitxeno/DeveloperDiskImages/main"`
			CNProxy     string `koanf:"cn_proxy" json:"cn_proxy" default:"https://mirror.ghproxy.com"`
		} `koanf:"developer_disk_image" json:"developer_disk_image"`
	} `koanf:"app" json:"app"`

	Log struct {
		Level      string `koanf:"level" default:"info"`
		TimeFormat string `koanf:"time_format" default:"2006-01-02 15:04:05.000"`
		LogFile    string `koanf:"log_file"`
		AccessLog  string `koanf:"access_log"`
	} `koanf:"log" json:"log"`

	Server struct {
		ListenAddr string `koanf:"listen_addr" default:"0.0.0.0"`
		Port       int    `koanf:"port" default:"9000"`
		DataDir    string `koanf:"work_dir"`
	} `koanf:"server" json:"server"`

	Db db.Config `koanf:"db" json:"db"`

	Signing struct {
		// KeyFile is the deployment key sealing the private keys of the
		// imported signing identities. Empty means <work_dir>/keys/signing-identity.key.
		KeyFile string `koanf:"key_file" json:"key_file"`
	} `koanf:"signing" json:"signing"`

	Secret struct {
		// KeyFile seals generic secrets such as the GitHub token.
		// Empty means <work_dir>/keys/secret-store.key.
		KeyFile string `koanf:"key_file" json:"key_file"`
	} `koanf:"secret" json:"secret"`
}

configuration holds any kind of configuration that comes from the outside world and is necessary for running the application.

var (
	Config *Configuration
)

func Cfg

func Cfg() *Configuration

func InitConfig added in v0.2.0

func InitConfig(path string, debug bool) (*Configuration, error)

load config from file

type SettingsConfiguration added in v0.2.0

type SettingsConfiguration struct {
	App struct {
		Language string `koanf:"language" json:"language"`
	} `koanf:"app" json:"app"`
	Task struct {
		Enabled       bool     `koanf:"enabled" json:"enabled" default:"true"`
		IphoneEnabled bool     `koanf:"iphone_enabled" json:"iphone_enabled" default:"true"`
		Mode          TaskMode `koanf:"mode" json:"mode" default:"1"`
		CrodTime      string   `koanf:"crod_time" json:"crod_time" default:"0,30 3-6 * * *"`
		AdvanceDays   int      `koanf:"advance_days" json:"advance_days" default:"1"`
	} `koanf:"task" json:"task"`
	Update struct {
		CheckInterval int `koanf:"check_interval" json:"check_interval" default:"6"` // hours between background update checks, 0 disables them
		// GitHubToken holds the AES-256-GCM sealed token (base64) persisted
		// in settings.json. It never holds plaintext: read it with
		// GetGitHubToken and write it with Set/DeleteGitHubToken. The
		// settings API only reports whether a token is configured.
		GitHubToken string `koanf:"github_token" json:"github_token"`
	} `koanf:"update" json:"update"`
	Notification struct {
		Enabled  bool   `koanf:"enabled" json:"enabled"`
		Type     string `koanf:"type" json:"type" default:"weixin"`
		Telegram struct {
			BotToken string `koanf:"bot_token" json:"bot_token"`
			ChatID   string `koanf:"chat_id" json:"chat_id"`
		} `koanf:"telegram" json:"telegram"`
		Weixin struct {
			CorpID     string `koanf:"corp_id" json:"corp_id"`
			CorpSecret string `koanf:"corp_secret" json:"corp_secret"`
			AgentID    string `koanf:"agent_id" json:"agent_id"`
			ToUser     string `koanf:"to_user" json:"to_user"`
		} `koanf:"weixin" json:"weixin"`
		Bark struct {
			BarkServer string `koanf:"bark_server" json:"bark_server" default:"https://api.day.app"`
			DeviceKey  string `koanf:"device_key" json:"device_key"`
		} `koanf:"bark" json:"bark"`
		Email struct {
			SMTPHost string `koanf:"smtp_host" json:"smtp_host"`
			SMTPPort int    `koanf:"smtp_port" json:"smtp_port" default:"587"`
			Username string `koanf:"username" json:"username"`
			Password string `koanf:"password" json:"password"`
			From     string `koanf:"from" json:"from"`
			To       string `koanf:"to" json:"to"`
		} `koanf:"email" json:"email"`
		Webhook struct {
			URL         string `koanf:"url" json:"url"`
			Method      string `koanf:"method" json:"method" default:"POST"`
			ContentType string `koanf:"content_type" json:"content_type" default:"application/json"`
			Header      string `koanf:"header" json:"header"`
			Body        string `koanf:"body" json:"body"`
		} `koanf:"webhook" json:"webhook"`
	} `koanf:"notification" json:"notification"`
	Network struct {
		ProxyEnabled bool   `koanf:"proxy_enabled" json:"proxy_enabled"`
		HTTPProxy    string `koanf:"http_proxy" json:"http_proxy"`
		HTTPSProxy   string `koanf:"https_proxy" json:"https_proxy"`
	} `koanf:"network" json:"network"`
}
var (
	Settings *SettingsConfiguration
)

func InitSettings added in v0.2.0

func InitSettings(conf *Configuration, debug bool) (*SettingsConfiguration, error)

load settings from file

type TaskMode added in v0.2.0

type TaskMode string
const (
	OneDayAgoMode TaskMode = "1"
	CustomMode    TaskMode = "2"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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