add config and bruno
This commit is contained in:
parent
8ceb698f03
commit
472c1b36a7
9 changed files with 708 additions and 7 deletions
44
gemlog/config.go
Normal file
44
gemlog/config.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package gemlog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// CouchDBConfig represents the CouchDB configuration section
|
||||
type CouchDBConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
|
||||
// Config represents the main configuration structure
|
||||
type Config struct {
|
||||
CouchDB CouchDBConfig `yaml:"couchdb"`
|
||||
}
|
||||
|
||||
// LoadConfig reads and parses the YAML configuration file from ~/.config/gemlog-cli
|
||||
func LoadConfig() (*Config, error) {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get user home directory: %w", err)
|
||||
}
|
||||
|
||||
configPath := filepath.Join(homeDir, ".config", "gemlog-cli", "config.yml")
|
||||
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read config file %s: %w", configPath, err)
|
||||
}
|
||||
|
||||
var config Config
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse YAML config: %w", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue