config

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HomeDirectory    = "HomeDirectory"
	WorkingDirectory = "WorkingDirectory"
	ProgramDirectory = "ProgramDirectory"
)

Variables

View Source
var (
	Server *http.Server
	Mutex  sync.Mutex
)
View Source
var CfgStatus = Status{}

Functions

func AutoSetCacheDir added in v1.1.0

func AutoSetCacheDir()

func DefaultConfigLocation added in v1.0.0

func DefaultConfigLocation() string

DefaultConfigLocation 判断当前配置文件应该保存到哪里。 逻辑:

  1. 是否在HomeDirectory已有 config.toml
  2. 否则是否在WorkingDirectory已有 config.toml
  3. 否则是否在ProgramDirectory已有 config.toml 若都没有,则返回 "HomeDirectory"。

返回:location字符串

func DeleteConfigIn

func DeleteConfigIn(in string) error

func GetConfigDir added in v1.1.0

func GetConfigDir() (dir string, err error)

GetConfigDir 获取配置文件所在目录

func GetHomeDirectoryConfig added in v1.0.0

func GetHomeDirectoryConfig() string

func GetJwtSigningKey added in v1.0.0

func GetJwtSigningKey() string

GetJwtSigningKey JWT令牌签名key,目前是用户名+密码(如果两者都设置了的话)

func GetProgramDirectoryConfig added in v1.0.0

func GetProgramDirectoryConfig() string

func GetQrcodeURL

func GetQrcodeURL() string

func GetVersion added in v1.0.0

func GetVersion() string

func GetWorkingDirectoryConfig added in v1.0.0

func GetWorkingDirectoryConfig() string

func SaveConfig

func SaveConfig(to string) error

func SetByExecutableFilename added in v1.0.0

func SetByExecutableFilename()

SetByExecutableFilename 通过执行文件名设置默认网页模板参数

func SetPort added in v1.0.0

func SetPort(port int)

func SetUploadPath added in v1.0.0

func SetUploadPath(path string)

func UpdateConfigByJson added in v1.0.0

func UpdateConfigByJson(jsonString string) error

UpdateConfigByJson 使用 JSON 字符串反序列化将更新的配置解析为映射,遍历映射并更新配置,减少重复的代码。

func UpdateConfigFile added in v1.1.0

func UpdateConfigFile() error

UpdateConfigFile 如果存在本地配置,更新本地配置

Types

type Config

type Config struct {
	AutoRescan             bool            `json:"AutoRescan" comment:"刷新页面时,是否自动重新扫描书籍是否存在"`
	CacheDir               string          `json:"CacheDir" comment:"本地图片缓存位置,默认系统临时文件夹"`
	ClearCacheExit         bool            `json:"ClearCacheExit" comment:"退出程序的时候,清理web图片缓存"`
	ClearDatabaseWhenExit  bool            `json:"ClearDatabaseWhenExit" comment:"启用本地数据库时,扫描完成后,清除不存在的书籍。"`
	ConfigFile             string          `json:"-" toml:"-" comment:"用户指定的的yaml设置文件路径"`
	ReadOnlyMode           bool            `json:"ReadOnlyMode" comment:"只读模式。禁止网页端更改配置或上传文件。"`
	Debug                  bool            `json:"Debug" comment:"开启Debug模式"`
	DefaultMode            string          `json:"DefaultMode" comment:"默认阅读模式,默认为空,可以设置为scroll或flip"`
	DisableLAN             bool            `json:"DisableLAN" comment:"只在本机提供阅读服务,不对外共享"`
	EnableDatabase         bool            `json:"EnableDatabase" comment:"启用本地数据库,保存扫描到的书籍数据。"`
	EnableTLS              bool            `json:"EnableTLS" comment:"是否启用HTTPS协议。需要设置证书于key文件。"`
	AutoTLSCertificate     bool            `json:"AutoTLSCertificate" comment:"自动申请、签发 HTTPS 证书(Let's Encrypt)"`
	Host                   string          `` /* 191-byte string literal not displayed */
	KeyFile                string          `json:"KeyFile" comment:"TLS/SSL key文件路径 (default: ~/.config/.comigo/key.key)"`
	CertFile               string          `json:"CertFile" comment:"TLS/SSL 证书文件路径 (default: ~/.config/.comigo/cert.crt)"`
	EnableUpload           bool            `json:"EnableUpload" comment:"启用上传功能"`
	ExcludePath            []string        `json:"ExcludePath" comment:"扫描书籍的时候,需要排除的文件或文件夹的名字"`
	GenerateMetaData       bool            `json:"GenerateMetaData" toml:"GenerateMetaData" comment:"生成书籍元数据"`
	StoreUrls              []string        `json:"StoreUrls" comment:"本地书库路径列表,支持多个路径。可以是本地文件夹或网络书库地址。"` // 书库地址列表
	LogFileName            string          `json:"LogFileName" comment:"Log文件名"`
	LogFilePath            string          `json:"LogFilePath" comment:"Log文件的保存位置"`
	LogToFile              bool            `json:"LogToFile" comment:"是否保存程序Log到本地文件。默认不保存。"`
	MaxScanDepth           int             `json:"MaxScanDepth" comment:"最大扫描深度"`
	MinImageNum            int             `json:"MinImageNum" comment:"压缩包或文件夹内,至少有几张图片,才算作书籍"`
	OpenBrowser            bool            `json:"OpenBrowser" comment:"是否同时打开浏览器,windows默认true,其他默认false"`
	Password               string          `json:"Password" comment:"登录界面需要的密码。"`
	Port                   int             `` /* 320-byte string literal not displayed */
	PrintAllPossibleQRCode bool            `json:"PrintAllPossibleQRCode" comment:"扫描完成后,打印所有可能的阅读链接二维码"`
	SupportFileType        []string        `json:"SupportFileType" comment:"支持的书籍压缩包后缀"`
	SupportMediaType       []string        `json:"SupportMediaType" comment:"扫描压缩包时,用于统计图片数量的图片文件后缀"`
	SupportTemplateFile    []string        `json:"SupportTemplateFile" comment:"支持的模板文件类型,默认为html"`
	Timeout                int             `json:"Timeout" comment:"cookie过期的时间。单位为分钟。默认60*24*30分钟后过期。"`
	TimeoutLimitForScan    int             `` /* 130-byte string literal not displayed */
	UploadDirOption        UploadDirOption `` /* 132-byte string literal not displayed */
	UploadPath             string          `json:"UploadPath" comment:"指定上传路径时,上传文件的存储位置"`
	UseCache               bool            `json:"UseCache" comment:"开启本地图片缓存,可以加快二次读取,但会占用硬盘空间"`
	Username               string          `json:"Username" comment:"登录界用的用户名。"`
	EnableTailscale        bool            `json:"EnableTailscale" comment:"启用Tailscale网络支持"`
	TailscaleHostname      string          `json:"TailscaleHostname" comment:"Tailscale网络的主机名,默认为comigo"`
	FunnelTunnel           bool            `json:"FunnelTunnel" comment:"启用Tailscale的Funnel模式,允许通过Tailscale公开comigo服务到公网。"`
	FunnelLoginCheck       bool            `json:"funnel_enforce_password" comment:"启用Funnel模式时,强制要求使用密码登录comigo服务。"`
	TailscalePort          int             `json:"TailscalePort" comment:"Tailscale网络的端口,默认为443"`
	TailscaleAuthKey       string          `` /* 142-byte string literal not displayed */
	ZipFileTextEncoding    string          `json:"ZipFileTextEncoding" comment:"非utf-8编码的ZIP文件,尝试用什么编码解析,默认GBK"`
	EnableSingleInstance   bool            `json:"EnableSingleInstance" comment:"启用单实例模式,确保同一时间只有一个程序实例运行"`
	Language               string          `` /* 148-byte string literal not displayed */
	RegisterContextMenu    bool            `json:"RegisterContextMenu" comment:"在 Windows 上注册资源管理器文件夹右键菜单:使用Comigo打开"`
	UnregisterContextMenu  bool            `json:"UnregisterContextMenu" comment:"在 Windows 上卸载资源管理器文件夹右键菜单:使用Comigo打开"`
}

Config Comigo全局配置

func CopyCfg added in v1.0.0

func CopyCfg() Config

func GetCfg added in v1.0.0

func GetCfg() *Config

func (*Config) AddStoreUrl added in v1.1.0

func (c *Config) AddStoreUrl(storeURL string) error

AddStoreUrl 添加本地书库(单个路径)

func (*Config) AddStringArrayConfig added in v1.0.0

func (c *Config) AddStringArrayConfig(fieldName, addValue string) ([]string, error)

AddStringArrayConfig 往指定的 []string 字段中添加一个新字符串

func (*Config) DeleteStringArrayConfig added in v1.0.0

func (c *Config) DeleteStringArrayConfig(fieldName, deleteValue string) ([]string, error)

DeleteStringArrayConfig 从指定的 []string 字段中删除某个字符串

func (*Config) GetClearDatabaseWhenExit added in v1.0.0

func (c *Config) GetClearDatabaseWhenExit() bool

func (*Config) GetDebug added in v1.0.0

func (c *Config) GetDebug() bool

func (*Config) GetEnableDatabase added in v1.0.0

func (c *Config) GetEnableDatabase() bool

func (*Config) GetEnableUpload added in v1.1.0

func (c *Config) GetEnableUpload() bool

func (*Config) GetExcludePath added in v1.0.0

func (c *Config) GetExcludePath() []string

func (*Config) GetHost added in v1.1.0

func (c *Config) GetHost() string

func (*Config) GetMaxScanDepth added in v1.0.0

func (c *Config) GetMaxScanDepth() int

func (*Config) GetMinImageNum added in v1.0.0

func (c *Config) GetMinImageNum() int

func (*Config) GetPort added in v1.1.0

func (c *Config) GetPort() int

func (*Config) GetStoreUrls added in v1.1.0

func (c *Config) GetStoreUrls() []string

func (*Config) GetSupportFileType added in v1.0.0

func (c *Config) GetSupportFileType() []string

func (*Config) GetSupportMediaType added in v1.0.0

func (c *Config) GetSupportMediaType() []string

func (*Config) GetSupportTemplateFile added in v1.0.0

func (c *Config) GetSupportTemplateFile() []string

func (*Config) GetTimeoutLimitForScan added in v1.0.0

func (c *Config) GetTimeoutLimitForScan() int

func (*Config) GetTopStoreName added in v1.0.0

func (c *Config) GetTopStoreName() string

func (*Config) GetZipFileTextEncoding added in v1.0.0

func (c *Config) GetZipFileTextEncoding() string

func (*Config) InitConfigStoreUrls added in v1.1.5

func (c *Config) InitConfigStoreUrls()

InitConfigStoreUrls TODO: 初始化配置文件中的书库,后续支持网络书库的时候需要修改

func (*Config) RequiresAuth added in v1.1.0

func (c *Config) RequiresAuth() bool

RequiresAuth 是否需要登录

func (*Config) SetConfigValue added in v1.0.0

func (c *Config) SetConfigValue(fieldName, fieldValue string) error

SetConfigValue 更新 Config 的相应字段,如果【fieldName】不存在、或【fieldValue】类型有问题,都返回错误。

func (*Config) StoreUrlIsExits added in v1.1.0

func (c *Config) StoreUrlIsExits(url string) bool

StoreUrlIsExits 检查书库URL是否可添加

type FrpClientConfig added in v1.0.0

type FrpClientConfig struct {
	FrpcCommand      string `comment:"手动设定frpc可执行程序的路径,默认为frpc"`
	ServerAddr       string
	ServerPort       int
	Token            string
	FrpType          string // 本地转发端口设置
	RemotePort       int
	RandomRemotePort bool
}

FrpClientConfig frp客户端配置

type Status

type Status struct {
	// 当前生效的配置文件路径 None、HomeDirectory、WorkingDirectory、ProgramDirectory
	// 设置读取顺序:None(默认值) -> HomeDirectory -> ProgramDirectory -> WorkingDirectory
	In   string
	Path struct {
		// 对应配置文件的绝对路径
		WorkingDirectory string
		HomeDirectory    string
		ProgramDirectory string
	}
}

func (*Status) SetConfigStatus added in v1.0.0

func (c *Status) SetConfigStatus() error

type UploadDirOption added in v1.0.0

type UploadDirOption int

type WebPServerConfig added in v1.0.0

type WebPServerConfig struct {
	WebpCommand  string
	HOST         string
	PORT         string
	ImgPath      string
	QUALITY      int
	AllowedTypes []string
	ExhaustPath  string
}

WebPServerConfig WebPServer服务端配置

Jump to

Keyboard shortcuts

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