50 lines
1003 B
Go
50 lines
1003 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"os"
|
||
|
"path"
|
||
|
)
|
||
|
|
||
|
type Config struct {
|
||
|
Editor string `json:"editor"` // we don't care about this
|
||
|
Gopher bool `json:"gopher"`
|
||
|
Nopub bool `json:"post as nopub"`
|
||
|
PublishDir string `json:"publish dir"`
|
||
|
Publishing bool `json:"publishing"`
|
||
|
Rainbows bool `json:"rainbows"` // we don't care about this
|
||
|
}
|
||
|
|
||
|
var Default = &Config{
|
||
|
Editor: "nano",
|
||
|
Gopher: false,
|
||
|
Nopub: false,
|
||
|
PublishDir: "blog",
|
||
|
Publishing: false,
|
||
|
Rainbows: false,
|
||
|
}
|
||
|
|
||
|
func Read() (config *Config, err error) {
|
||
|
file, err := os.Open(path.Join(os.Getenv("HOME"), ".ttbp/config/ttbprc"))
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
defer file.Close()
|
||
|
|
||
|
decoder := json.NewDecoder(file)
|
||
|
err = decoder.Decode(&config)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (config *Config) Write() (err error) {
|
||
|
file, err := os.Create(path.Join(os.Getenv("HOME"), ".ttbp/config/ttbprc"))
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
defer file.Close()
|
||
|
|
||
|
encoder := json.NewEncoder(file)
|
||
|
err = encoder.Encode(config)
|
||
|
return
|
||
|
}
|