init
This commit is contained in:
29
config/config.go
Normal file
29
config/config.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
CurrentAPI string `toml:"CurrentAPI"`
|
||||
APIToken string `toml:"APIToken"`
|
||||
QuestionsPath string `toml:"QuestionsPath"`
|
||||
OutPath string `toml:"OutPath"`
|
||||
}
|
||||
|
||||
func LoadConfigOrDefault(fn string) *Config {
|
||||
if fn == "" {
|
||||
fn = "config.toml"
|
||||
}
|
||||
config := &Config{}
|
||||
_, err := toml.DecodeFile(fn, &config)
|
||||
if err != nil {
|
||||
fmt.Println("failed to read config from file, loading default", "error", err)
|
||||
config.CurrentAPI = "http://localhost:8080/completion"
|
||||
config.QuestionsPath = "data/questions.json"
|
||||
config.OutPath = "data/out.json"
|
||||
}
|
||||
return config
|
||||
}
|
Reference in New Issue
Block a user