github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/baidupcs/internal/panhome/cache.go (about) 1 package panhome 2 3 import ( 4 "github.com/qjfoidnh/BaiduPCS-Go/baidupcs/expires" 5 "time" 6 ) 7 8 // SetSignExpires 设置sign过期 9 func (ph *PanHome) SetSignExpires() { 10 if ph.signExpires != nil { 11 ph.signExpires.SetExpires(true) 12 } 13 } 14 15 // CacheSignature 在有效期内返回缓存结果 16 func (ph *PanHome) CacheSignature() (sign SignRes, err error) { 17 if ph.signExpires == nil || ph.signExpires.IsExpires() { 18 // 先签名再设置有效期 19 ph.signRes, err = ph.Signature() 20 if err != nil { // 空指针与空接口不等价 21 return nil, err 22 } 23 24 ph.signExpires = expires.NewExpires(1 * time.Hour) // 设置一小时有效期 25 return ph.signRes, nil 26 } 27 28 return ph.signRes, nil 29 }