feat: add config and models packages
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
40
internal/config/config.go
Normal file
40
internal/config/config.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
ListenAddr string
|
||||||
|
DataDir string
|
||||||
|
DBPath string
|
||||||
|
ReposDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
var instance *Config
|
||||||
|
var initOnce sync.Once
|
||||||
|
|
||||||
|
func Get() *Config {
|
||||||
|
initOnce.Do(func() {
|
||||||
|
instance = &Config{
|
||||||
|
ListenAddr: ":9000",
|
||||||
|
DataDir: "./data",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return instance
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) SetDataDir(dir string) {
|
||||||
|
c.DataDir = dir
|
||||||
|
c.DBPath = filepath.Join(dir, "gitm.db")
|
||||||
|
c.ReposDir = filepath.Join(dir, "repos")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) EnsureDirs() error {
|
||||||
|
if err := os.MkdirAll(c.DataDir, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.MkdirAll(c.ReposDir, 0755)
|
||||||
|
}
|
||||||
42
internal/models/models.go
Normal file
42
internal/models/models.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type GiteaServer struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Token string `json:"-"` // Never expose in JSON
|
||||||
|
SyncInterval int `json:"sync_interval"`
|
||||||
|
LastSyncAt *time.Time `json:"last_sync_at"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Repo struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
ServerID int64 `json:"server_id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
CloneURL string `json:"clone_url"`
|
||||||
|
LocalPath string `json:"local_path"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
LastSyncAt *time.Time `json:"last_sync_at"`
|
||||||
|
SyncStatus string `json:"sync_status"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SyncLog struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
ServerID int64 `json:"server_id"`
|
||||||
|
RepoID *int64 `json:"repo_id"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
StartedAt time.Time `json:"started_at"`
|
||||||
|
FinishedAt *time.Time `json:"finished_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Setting struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user