TUI for The Lounge
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

53 lines
929 B

package main
import (
"os"
"log"
"io/ioutil"
"encoding/json"
)
type config struct {
Host string `json:"host"`
Path string `json:"path"`
User string `json:"user"`
Token string `json:"token"`
}
func handleTilde(in string) string {
if in[0] != '~' {
return in
}
return os.Getenv("HOME") + in[1:]
}
func configPath() string {
confHome := os.Getenv("XDG_CONFIG_HOME")
if confHome == "" {
confHome = "~/.config"
}
confDir := handleTilde(confHome) + "/linger"
_ = os.Mkdir(confDir, 0755)
return confDir + "/config.json"
}
func configLoad() *config {
conf := config{}
data, err := ioutil.ReadFile(configPath())
if err != nil {
return &conf
}
err = json.Unmarshal(data, &conf)
if err != nil {
return &conf
}
return &conf
}
func configWrite(conf *config) {
data, err := json.Marshal(conf)
err = ioutil.WriteFile(configPath(), data, 0644)
if err != nil {
log.Fatal("Failed to write config")
}
}