move config to its own package

This commit is contained in:
Benson Wong
2024-10-03 21:08:11 -07:00
parent cb576fb178
commit f44faf5a93
3 changed files with 49 additions and 36 deletions

31
config/config.go Normal file
View File

@@ -0,0 +1,31 @@
package config
import (
"os"
"gopkg.in/yaml.v3"
)
type ModelConfig struct {
Cmd string `yaml:"cmd"`
Proxy string `yaml:"proxy"`
}
type Config struct {
Models map[string]ModelConfig `yaml:"models"`
}
func LoadConfig(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
return nil, err
}
return &config, nil
}