|
@@ -5,7 +5,6 @@ import (
|
|
"encoding/xml"
|
|
"encoding/xml"
|
|
"fmt"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
- "log"
|
|
|
|
"net/http"
|
|
"net/http"
|
|
"net/http/cookiejar"
|
|
"net/http/cookiejar"
|
|
"strings"
|
|
"strings"
|
|
@@ -77,12 +76,23 @@ type Progress struct {
|
|
}
|
|
}
|
|
|
|
|
|
// LoadConfig func
|
|
// LoadConfig func
|
|
-func (api *API) LoadConfig(name string) {
|
|
|
|
|
|
+func (api *API) LoadConfig(name string) error {
|
|
cfg, err := ioutil.ReadFile(name)
|
|
cfg, err := ioutil.ReadFile(name)
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Fatal("Unable to load config", err)
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
yaml.Unmarshal(cfg, &api)
|
|
yaml.Unmarshal(cfg, &api)
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// SaveConfig func
|
|
|
|
+func (api *API) SaveConfig(name string) error {
|
|
|
|
+ data, err := yaml.Marshal(api)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ err = ioutil.WriteFile(name, data, 0700)
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
|
|
|
|
func (api *API) setHeader(req *http.Request) {
|
|
func (api *API) setHeader(req *http.Request) {
|