diff --git a/cmd/main.go b/cmd/main.go index 38dd16d..7905807 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,3 +1,5 @@ package main -func main() {} +func main() { + +} diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..9d86cc3 --- /dev/null +++ b/config.yaml @@ -0,0 +1,40 @@ +platforms: + github: + users: + - username: "zz_main" + token: "" # 可选:未来扩展 API 功能 + projects: + - name: "projectA" + path: "F:/Projects/github/projectA" + - name: "projectB" + path: "F:/Projects/github/projectB" + + - username: "zz_work" + token: "" + projects: + - name: "work-tool" + path: "F:/Projects/github/work-tool" + + gitee: + users: + - username: "zz_gitee" + token: "" + projects: + - name: "gitee-demo" + path: "F:/Projects/gitee/demo" + + gitea: + base_url: "http://192.168.1.10:3000" + users: + - username: "admin" + token: "" + projects: + - name: "gitea-app" + path: "F:/Projects/gitea/app" + - name: "gitea-service" + path: "F:/Projects/gitea/service" + +settings: + concurrency: 6 + network_check: true + log_level: "info" diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..9f50ee0 --- /dev/null +++ b/config/config.go @@ -0,0 +1,71 @@ +package config + +import ( + "fmt" + "os" + + "gopkg.in/yaml.v3" +) + +type Project struct { + Name string `yaml:"name"` + Path string `yaml:"path"` + Enabled bool `yaml:"enabled"` // 可选,默认 true +} + +type User struct { + Username string `yaml:"username"` + Token string `yaml:"token"` // 可选:未来扩展 API 功能 + Projects []Project `yaml:"projects"` +} + +type Platform struct { + BaseURL string `yaml:"base_url"` // GitHub/Gitee 可为空,Gitea 需要 + Users []User `yaml:"users"` +} + +type Settings struct { + Concurrency int `yaml:"concurrency"` + NetworkCheck bool `yaml:"network_check"` + LogLevel string `yaml:"log_level"` +} + +type AppConfig struct { + Platforms map[string]Platform `yaml:"platforms"` + Settings Settings `yaml:"settings"` +} + +// LoadConfig 从 config.yaml 文件加载配置 +func LoadConfig() (*AppConfig, error) { + file, err := os.Open("config.yaml") + if err != nil { + return nil, err + } + defer file.Close() + + var appConfig *AppConfig + + err = yaml.NewDecoder(file).Decode(&appConfig) + if err != nil { + return nil, err + } + + return appConfig, nil +} + +// SaveConfig 将配置保存到 config.yaml 文件 +func SaveConfig(config *AppConfig) error { + file, err := os.OpenFile("config.yaml", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644) + if err != nil { + return err + } + defer file.Close() + enc := yaml.NewEncoder(file) + enc.SetIndent(2) + if err := enc.Encode(config); err != nil { + return fmt.Errorf("写入配置文件失败: %w", err) + } + + return enc.Close() + +}