config

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBackupPath

func GetBackupPath() (string, error)

GetBackupPath 获取备份文件路径

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath 获取配置文件路径

func Save

func Save(cfg *Config) error

Save 保存配置文件

Types

type AuthConfig

type AuthConfig struct {
	Type         string `yaml:"type"`          // auto, password, key
	Password     string `yaml:"password"`      // 密码(不加密存储)
	IdentityFile string `yaml:"identity_file"` // 密钥文件路径
}

AuthConfig 认证配置

type Config

type Config struct {
	Version string     `yaml:"version"`
	Sync    SyncConfig `yaml:"sync"`
	Servers []Server   `yaml:"servers"`
}

Config 主配置结构

func Load

func Load() (*Config, error)

Load 加载配置文件

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig 创建默认配置

func (*Config) AddServer

func (c *Config) AddServer(server Server) error

AddServer 添加服务器

func (*Config) DeleteServer

func (c *Config) DeleteServer(name string) error

DeleteServer 删除服务器

func (*Config) FilterServers

func (c *Config) FilterServers(tags []string, group string) []Server

FilterServers 根据标签和分组过滤服务器

func (*Config) GetGroups

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

GetGroups 获取所有分组

func (*Config) GetServer

func (c *Config) GetServer(name string) (*Server, error)

GetServer 获取服务器配置

func (*Config) GetTags

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

GetTags 获取所有标签

type Server

type Server struct {
	Name        string     `yaml:"name"`
	Hostname    string     `yaml:"hostname"`
	User        string     `yaml:"user"`
	Port        int        `yaml:"port"`
	Description string     `yaml:"description"`
	Tags        []string   `yaml:"tags"`
	Group       string     `yaml:"group"` // 分组
	Auth        AuthConfig `yaml:"auth"`
	LastUsed    string     `yaml:"last_used"`
	CreatedAt   string     `yaml:"created_at"`
}

Server 服务器配置

func (*Server) GetAddress

func (s *Server) GetAddress() string

GetAddress 获取完整地址

func (*Server) GetDisplayName

func (s *Server) GetDisplayName() string

GetDisplayName 获取显示名称(包含描述)

func (*Server) UpdateLastUsed

func (s *Server) UpdateLastUsed()

UpdateLastUsed 更新服务器的最后使用时间

type SyncConfig

type SyncConfig struct {
	Enabled  bool   `yaml:"enabled"`
	Type     string `yaml:"type"`      // ssh, http, ftp (未来扩展)
	SSHHost  string `yaml:"ssh_host"`  // SSH同步时的主机地址
	SSHUser  string `yaml:"ssh_user"`  // SSH同步时的用户名
	SSHPath  string `yaml:"ssh_path"`  // SSH同步时的远程路径
	SSHKey   string `yaml:"ssh_key"`   // SSH密钥路径(可选)
	Password string `yaml:"password"`  // 密码(可选,用于SSH认证)
	AutoSync bool   `yaml:"auto_sync"` // 启动时自动同步
	LastSync string `yaml:"last_sync"` // 最后同步时间
}

SyncConfig 同步配置

Jump to

Keyboard shortcuts

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