webdav/sharepoint: renew cookies after 12hrs

This commit is contained in:
Henning Surmeier
2018-09-26 13:04:41 +01:00
committed by Nick Craig-Wood
parent c7aa6b587b
commit 22ac80e83a
2 changed files with 43 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package odrvcookie
import (
"time"
"github.com/ncw/rclone/lib/rest"
)
// CookieRenew holds information for the renew
type CookieRenew struct {
srv *rest.Client
timer *time.Ticker
renewFn func()
}
// NewRenew returns and starts a CookieRenew
func NewRenew(interval time.Duration, renewFn func()) *CookieRenew {
renew := CookieRenew{
timer: time.NewTicker(interval),
renewFn: renewFn,
}
go renew.Renew()
return &renew
}
// Renew calls the renewFn for every tick
func (c *CookieRenew) Renew() {
for {
<-c.timer.C // wait for tick
c.renewFn()
}
}