-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
46 lines (36 loc) · 796 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"log"
"os"
"gopkg.in/yaml.v2"
)
type OpenAI struct {
Token string `yaml:"token"`
}
type Azure struct {
ModelMapping map[string]string `yaml:"model-mapping"`
Key string `yaml:"key"`
Endpoint string `yaml:"endpoint"`
}
type Server struct {
IP string `yaml:"ip"`
Port int `yaml:"port"`
}
type Config struct {
Azure Azure `yaml:"azure"`
Mode string `yaml:"mode"`
OpenAI OpenAI `yaml:"openai"`
Server Server `yaml:"server"`
}
func NewConfig(path string) Config {
var config Config
data, err := os.ReadFile(path)
if err != nil {
log.Fatalf("Error reading YAML file: %s", err)
}
err = yaml.Unmarshal(data, &config)
if err != nil {
log.Fatalf("Error unmarshalling YAML data: %s", err)
}
return config
}