-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
51 lines (42 loc) · 1.28 KB
/
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
47
48
49
50
51
package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
"github.com/pkg/errors"
)
const cacheRoot = "_cache/"
const noteCacheDirName = "notes/"
const resourceCacheDirName = "resources/"
const postDirName = "_posts/"
const resourceDirName = "resources/"
const configFilePath = "_evernote.yml"
type config struct {
ClientKey string `yaml:"client_key"`
ClientSecret string `yaml:"client_secret"`
DeveloperToken string `yaml:"developer_token"`
Sandbox bool `yaml:"is_sandbox"`
NotebookName string `yaml:"notebook_name"`
}
func getConfig() (*config, error) {
var cfg *config
configBytes, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, errors.Wrapf(err, "can't read %v", configFilePath)
}
if err := yaml.Unmarshal(configBytes, &cfg); err != nil {
return nil, errors.Wrapf(err, "can't unmarshal %v", configFilePath)
}
if cfg.ClientKey == "" {
return nil, errors.Errorf("client key is blank %v", configFilePath)
}
if cfg.ClientSecret == "" {
return nil, errors.Errorf("client secret is blank %v", configFilePath)
}
if cfg.DeveloperToken == "" {
return nil, errors.Errorf("developer token is blank %v", configFilePath)
}
if cfg.NotebookName == "" {
return nil, errors.Errorf("notebook name is blank %v", configFilePath)
}
return cfg, nil
}