Initial commit
This commit is contained in:
31
pkg/manager/manager.go
Normal file
31
pkg/manager/manager.go
Normal file
@ -0,0 +1,31 @@
|
||||
package manager
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Manager struct {
|
||||
Config *ManagerConfig
|
||||
GitLabHost string
|
||||
gitLabToken string
|
||||
}
|
||||
|
||||
type ManagerParams struct {
|
||||
GitLabHost string
|
||||
GitLabToken string
|
||||
ConfigFile string
|
||||
}
|
||||
|
||||
// Returns a new instance of project manager
|
||||
// with optional overrides for common settings
|
||||
// More complex configuration is provided in the
|
||||
// configuration file
|
||||
func NewManager(p *ManagerParams) *Manager {
|
||||
return &Manager{
|
||||
Config: NewConfigFromFile(p.ConfigFile),
|
||||
GitLabHost: p.GitLabHost,
|
||||
gitLabToken: p.GitLabToken,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) String() string {
|
||||
return fmt.Sprintf("%+v", *m)
|
||||
}
|
29
pkg/manager/manager_config.go
Normal file
29
pkg/manager/manager_config.go
Normal file
@ -0,0 +1,29 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slog"
|
||||
)
|
||||
|
||||
const (
|
||||
managerDefCacheFile = "/tmp/gitlab_project-manager_cache"
|
||||
managerDefConfigFile = "~/.config/project-manager/config.yaml"
|
||||
managerDefProjectsPath = "~/work/projects"
|
||||
)
|
||||
|
||||
type ManagerConfig struct {
|
||||
CacheTTL time.Duration `yaml:"cacheTTL" json:"cacheTTL" default:"48h"`
|
||||
CacheFile string `yaml:"cacheFile" json:"cacheFile"`
|
||||
ConfigFile string `yaml:"configFile" json:"configFile"`
|
||||
ProjectsPath string `yaml:"projectsPath" json:"projectsPath"`
|
||||
}
|
||||
|
||||
func NewConfigFromFile(file string) *ManagerConfig {
|
||||
_, err := os.Open(file)
|
||||
if err != nil {
|
||||
slog.Warn("Skipping config file, can't read", "err", err)
|
||||
}
|
||||
return &ManagerConfig{}
|
||||
}
|
Reference in New Issue
Block a user