-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
67 lines (57 loc) · 1.58 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"math/bits"
"net/http"
"net/url"
"time"
"code.riba.cloud/go/toolbox-interplanetary/fil"
"code.riba.cloud/go/toolbox/cmn"
"github.com/hashicorp/go-retryablehttp"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
)
func init() {
if bits.UintSize != 64 {
panic("program relies on Int being 64bit (for mmapped buffer access)")
}
}
type WrCommP struct {
fil.CommP
}
func (out *WrCommP) UnmarshalJSON(b []byte) error {
c, err := cid.Decode(string(b[1 : len(b)-1]))
if err != nil {
return cmn.WrErr(err)
}
p, err := fil.CommPFromPCidV2(c)
if err != nil {
return cmn.WrErr(err)
}
*out = WrCommP{p}
return nil
}
type WrURL struct {
url.URL
}
func (out *WrURL) UnmarshalJSON(b []byte) error {
u, err := url.Parse(string(b[1 : len(b)-1]))
if err != nil {
return cmn.WrErr(err)
}
*out = WrURL{*u}
return nil
}
func retryingClient(attempts int, waitMin, waitMax time.Duration) *http.Client {
rc := retryablehttp.NewClient()
rc.Logger = &retLogWrap{ipfslog: log}
rc.RetryWaitMin = waitMin
rc.RetryWaitMax = waitMax
rc.RetryMax = attempts
rc.CheckRetry = retryablehttp.ErrorPropagatedRetryPolicy
return rc.StandardClient()
}
type retLogWrap struct{ ipfslog *logging.ZapEventLogger }
func (w *retLogWrap) Error(msg string, kv ...interface{}) { w.ipfslog.Errorw(msg, kv...) }
func (w *retLogWrap) Info(msg string, kv ...interface{}) { w.ipfslog.Infow(msg, kv...) }
func (w *retLogWrap) Debug(msg string, kv ...interface{}) { w.ipfslog.Debugw(msg, kv...) }
func (w *retLogWrap) Warn(msg string, kv ...interface{}) { w.ipfslog.Warnw(msg, kv...) }