Improve config lookup and OpenAI streaming decode

This commit is contained in:
2025-10-01 17:27:37 +02:00
parent dccaf8e870
commit 4271ee3d73
5 changed files with 178 additions and 32 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"gopkg.in/yaml.v3"
@@ -63,8 +64,19 @@ func Load(path string) (*Config, error) {
return nil, err
}
} else {
if err := loadFile("config.yaml", &cfg); err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, err
candidates := []string{"config.yaml"}
if home, err := os.UserHomeDir(); err == nil && strings.TrimSpace(home) != "" {
candidates = append(candidates, filepath.Join(home, ".config", "goaichat", "config.yaml"))
}
for _, candidate := range candidates {
if err := loadFile(candidate, &cfg); err != nil {
if errors.Is(err, os.ErrNotExist) {
continue
}
return nil, err
}
break
}
}