forked from NVIDIA/aistore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
48 lines (38 loc) · 1.13 KB
/
common.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
// Package backend contains implementation of various backend providers.
/*
* Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
*/
package backend
import (
"context"
"io"
"time"
"github.com/artashesbalabekyan/aistore/3rdparty/glog"
"github.com/artashesbalabekyan/aistore/cmn"
"github.com/artashesbalabekyan/aistore/cmn/cos"
)
type ctx = context.Context // used when omitted for shortness sake
var verbose bool
func Init() {
verbose = bool(glog.FastV(4, glog.SmoduleBackend))
}
func wrapReader(ctx context.Context, r io.ReadCloser) io.ReadCloser {
if v := ctx.Value(cos.CtxReadWrapper); v != nil {
return v.(cos.ReadWrapperFunc)(r)
}
return r
}
func setSize(ctx context.Context, size int64) {
if v := ctx.Value(cos.CtxSetSize); v != nil {
v.(cos.SetSizeFunc)(size)
}
}
func fmtTime(t time.Time) string { return t.Format(time.RFC3339) }
func calcPageSize(pageSize, maxPageSize uint) uint {
if pageSize == 0 {
return maxPageSize
}
return pageSize
}
//nolint:deadcode,unused // It is used but in `*_mock.go` files.
func newErrInitBackend(provider string) error { return &cmn.ErrInitBackend{Provider: provider} }