- OAuth认证系统(Gitea + Lua扩展) - Git自动化操作(本地/SSH远程) - 实时进度WebSocket推送 - 现代化Tab界面UI - Cobra CLI命令行(init/version/serve) - 完整构建系统(Makefile + Taskfile) - UPX压缩支持(体积减少70%)
117 lines
4.0 KiB
Go
117 lines
4.0 KiB
Go
package config
|
|
|
|
import (
|
|
"cs-bridge/internal/consts"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
type Server struct {
|
|
Debug bool `mapstructure:"debug"`
|
|
Port int `mapstructure:"port"`
|
|
}
|
|
|
|
type Log struct {
|
|
Level string `mapstructure:"level" yaml:"level"`
|
|
Filepath string `mapstructure:"filepath" yaml:"filepath"`
|
|
MaxSizeMB int `mapstructure:"max_size_mb" yaml:"max_size_mb"` // 单个日志文件最大(MB)
|
|
MaxAgeDay int `mapstructure:"max_age_day" yaml:"max_age_day"` // 日志文件最大保存天数
|
|
Backups int `mapstructure:"backups" yaml:"backups"` // 保留的旧文件个数
|
|
Compress bool `mapstructure:"compress" yaml:"compress"` // 是否压缩
|
|
}
|
|
|
|
type Database struct {
|
|
SqliteDbPath string `mapstructure:"sqlite_db_path" yaml:"sqlite_db_path"`
|
|
}
|
|
|
|
type Secret struct {
|
|
TokenTTL time.Duration `mapstructure:"token_ttl" yaml:"token_ttl"`
|
|
WSTTL time.Duration `mapstructure:"ws_ttl" yaml:"ws_ttl"`
|
|
}
|
|
|
|
type Provider struct {
|
|
Name string `mapstructure:"name" yaml:"name"`
|
|
Type string `mapstructure:"type" yaml:"type"`
|
|
ClientID string `mapstructure:"client_id" yaml:"client_id"`
|
|
ClientSecret string `mapstructure:"client_secret" yaml:"client_secret"`
|
|
BaseURL string `mapstructure:"base_url" yaml:"base_url"`
|
|
AuthorizeURL string `mapstructure:"authorize_url" yaml:"authorize_url"`
|
|
TokenURL string `mapstructure:"token_url" yaml:"token_url"`
|
|
UserURL string `mapstructure:"user_url" yaml:"user_url"`
|
|
}
|
|
|
|
type OAuth struct {
|
|
BaseURL string `mapstructure:"base_url" yaml:"base_url"`
|
|
Providers []Provider `mapstructure:"providers" yaml:"providers"`
|
|
}
|
|
|
|
type CodeServer struct {
|
|
BaseURL string `mapstructure:"base_url" yaml:"base_url"`
|
|
WorkspaceRoot string `mapstructure:"workspace_root" yaml:"workspace_root"` // 容器内路径,传递给code-server
|
|
// SSH配置 - 用于远程执行git操作
|
|
SSHHost string `mapstructure:"ssh_host" yaml:"ssh_host"` // SSH服务器地址
|
|
SSHPort int `mapstructure:"ssh_port" yaml:"ssh_port"` // SSH端口,默认22
|
|
SSHUser string `mapstructure:"ssh_user" yaml:"ssh_user"` // SSH用户名(专用账号)
|
|
SSHKeyPath string `mapstructure:"ssh_key_path" yaml:"ssh_key_path"` // SSH私钥路径
|
|
SSHWorkspaceRoot string `mapstructure:"ssh_workspace_root" yaml:"ssh_workspace_root"` // SSH服务器上的workspace路径(容器映射到宿主机的路径)
|
|
}
|
|
|
|
type Config struct {
|
|
Server Server `mapstructure:"server" yaml:"server"`
|
|
Log Log `mapstructure:"log" yaml:"log"`
|
|
Database Database `mapstructure:"database" yaml:"database"`
|
|
Secret Secret `mapstructure:"secret" yaml:"secret"`
|
|
OAuth OAuth `mapstructure:"oauth" yaml:"oauth"`
|
|
CodeServer CodeServer `mapstructure:"code_server" yaml:"code_server"`
|
|
}
|
|
|
|
func DefaultConfig() *Config {
|
|
logPath := filepath.Join(consts.DataDir, "log.log")
|
|
dbPath := filepath.Join(consts.DataDir, "sqlite.db")
|
|
return &Config{
|
|
Server: Server{
|
|
Debug: true,
|
|
Port: 8080,
|
|
},
|
|
Log: Log{
|
|
Level: "debug",
|
|
Filepath: logPath,
|
|
MaxSizeMB: 10,
|
|
MaxAgeDay: 7,
|
|
Backups: 3,
|
|
Compress: true,
|
|
},
|
|
Database: Database{
|
|
SqliteDbPath: dbPath,
|
|
},
|
|
Secret: Secret{
|
|
TokenTTL: time.Millisecond * 600,
|
|
WSTTL: time.Millisecond * 3600,
|
|
},
|
|
OAuth: OAuth{
|
|
BaseURL: "http://localhost:8080",
|
|
Providers: []Provider{
|
|
{
|
|
Name: "gitea",
|
|
Type: "gitea",
|
|
ClientID: "xxx",
|
|
ClientSecret: "xxx",
|
|
BaseURL: "https://xxx",
|
|
AuthorizeURL: "/login/oauth/authorize",
|
|
TokenURL: "/login/oauth/access_token",
|
|
UserURL: "/api/v1/user",
|
|
},
|
|
},
|
|
},
|
|
CodeServer: CodeServer{
|
|
BaseURL: "xxx",
|
|
WorkspaceRoot: "/config/workspace", // 容器内路径
|
|
SSHHost: "",
|
|
SSHPort: 22,
|
|
SSHUser: "git",
|
|
SSHKeyPath: "",
|
|
SSHWorkspaceRoot: "/root/code-server/data/workspace", // SSH服务器实际路径
|
|
},
|
|
}
|
|
}
|