erroneousboat-slack-term/src/config/config.go

44 lines
864 B
Go
Raw Normal View History

2016-09-25 22:34:02 +02:00
package config
import (
"encoding/json"
"os"
2016-10-10 21:45:31 +02:00
"github.com/gizak/termui"
2016-09-25 22:34:02 +02:00
)
2016-10-02 16:07:35 +02:00
// Config is the definition of a Config struct
2016-09-25 22:34:02 +02:00
type Config struct {
SlackToken string `json:"slack_token"`
2016-10-10 21:45:31 +02:00
Theme string `json:"theme"`
2016-09-25 22:34:02 +02:00
}
2016-10-02 16:07:35 +02:00
// NewConfig loads the config file and returns a Config struct
2016-09-25 22:34:02 +02:00
func NewConfig(filepath string) (*Config, error) {
2016-10-10 21:45:31 +02:00
cfg := Config{
Theme: "dark",
}
2016-09-25 22:34:02 +02:00
file, err := os.Open(filepath)
if err != nil {
return &cfg, err
}
if err := json.NewDecoder(file).Decode(&cfg); err != nil {
return &cfg, err
}
2016-10-10 21:45:31 +02:00
if cfg.Theme == "light" {
termui.ColorMap = map[string]termui.Attribute{
"fg": termui.ColorBlack,
"bg": termui.ColorDefault,
"border.fg": termui.ColorBlack,
2016-10-11 19:28:37 +02:00
"label.fg": termui.ColorBlue,
2016-10-10 21:45:31 +02:00
"par.fg": termui.ColorYellow,
"par.label.bg": termui.ColorWhite,
}
}
2016-09-25 22:34:02 +02:00
return &cfg, nil
}