save full cookie

This commit is contained in:
Celogeek 2021-12-15 09:48:23 +01:00
parent 4149f68938
commit 86981a063f
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
3 changed files with 9 additions and 6 deletions

View File

@ -58,7 +58,8 @@ func (p *Piwigo) LoadConfig() (err error) {
} }
err = json.Unmarshal(b, &p) err = json.Unmarshal(b, &p)
if p.Url == "" || p.Token == "" {
if p.Url == "" || p.Token == nil {
err = errors.New("missing configuration url or token") err = errors.New("missing configuration url or token")
} }

View File

@ -34,8 +34,8 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
} }
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
if p.Token != "" { if p.Token != nil {
req.AddCookie(&http.Cookie{Name: "pwg_id", Value: p.Token}) req.AddCookie(p.Token)
} }
r, err := http.DefaultClient.Do(req) r, err := http.DefaultClient.Do(req)
@ -60,7 +60,7 @@ func (p *Piwigo) Post(method string, form *url.Values, resp interface{}) error {
for _, c := range r.Cookies() { for _, c := range r.Cookies() {
if c.Name == "pwg_id" { if c.Name == "pwg_id" {
p.Token = c.Value p.Token = c
break break
} }
} }

View File

@ -1,8 +1,10 @@
package piwigo package piwigo
import "net/http"
type Piwigo struct { type Piwigo struct {
Url string `json:"url"` Url string `json:"url"`
Token string `json:"token"` Token *http.Cookie `json:"token"`
} }
type PiwigoResult struct { type PiwigoResult struct {