Added bento :)

This commit is contained in:
2026-05-01 14:10:22 -06:00
parent fec14022cd
commit 9ea2cf8c34
17 changed files with 1304 additions and 253 deletions
+94
View File
@@ -0,0 +1,94 @@
package config
import (
"os"
"path/filepath"
"gopkg.in/yaml.v3"
)
type Connection struct {
Name string `yaml:"name"`
URL string `yaml:"url"`
Username string `yaml:"username"`
Token string `yaml:"token"`
}
type Config struct {
Connections []Connection `yaml:"connections"`
}
func GetConfigPath() (string, error) {
exe, err := os.Executable()
if err != nil {
return "", err
}
dir := filepath.Dir(exe)
wrappedDir := filepath.Join(dir, ".wrapped")
if err := os.MkdirAll(wrappedDir, 0o755); err != nil {
return "", err
}
return filepath.Join(wrappedDir, "config.yaml"), nil
}
func GetResultsDir() (string, error) {
exe, err := os.Executable()
if err != nil {
return "", err
}
dir := filepath.Dir(exe)
resultsDir := filepath.Join(dir, ".wrapped", "results")
if err := os.MkdirAll(resultsDir, 0o755); err != nil {
return "", err
}
return resultsDir, nil
}
func LoadConfig() (*Config, error) {
configPath, err := GetConfigPath()
if err != nil {
return nil, err
}
data, err := os.ReadFile(configPath)
if err != nil {
if os.IsNotExist(err) {
return &Config{Connections: []Connection{}}, nil
}
return nil, err
}
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
}
func (c *Config) Save() error {
configPath, err := GetConfigPath()
if err != nil {
return err
}
data, err := yaml.Marshal(c)
if err != nil {
return err
}
return os.WriteFile(configPath, data, 0o600)
}
func (c *Config) GetConnection(name string) *Connection {
for i := range c.Connections {
if c.Connections[i].Name == name {
return &c.Connections[i]
}
}
return nil
}
func (c *Config) AddConnection(conn Connection) {
c.Connections = append(c.Connections, conn)
}