Denmaseno 8 years ago
parent
commit
6992c7051d
1 changed files with 13 additions and 3 deletions
  1. 13 3
      plex.go

+ 13 - 3
plex.go

@@ -5,7 +5,6 @@ import (
 	"encoding/xml"
 	"fmt"
 	"io/ioutil"
-	"log"
 	"net/http"
 	"net/http/cookiejar"
 	"strings"
@@ -77,12 +76,23 @@ type Progress struct {
 }
 
 // LoadConfig func
-func (api *API) LoadConfig(name string) {
+func (api *API) LoadConfig(name string) error {
 	cfg, err := ioutil.ReadFile(name)
 	if err != nil {
-		log.Fatal("Unable to load config", err)
+		return err
 	}
 	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) {