-
Notifications
You must be signed in to change notification settings - Fork 38
/
service.go
114 lines (92 loc) · 2.64 KB
/
service.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package deletesvc
import (
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
putsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/put"
searchsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/search"
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/user"
"go.uber.org/zap"
)
// Service utility serving requests of Object.Get service.
type Service struct {
*cfg
}
// Option is a Service's constructor option.
type Option func(*cfg)
// NetworkInfo wraps network state and configurations.
type NetworkInfo interface {
netmap.State
// Must return the lifespan of the tombstones
// in the NeoFS epochs.
TombstoneLifetime() (uint64, error)
// Returns user ID of the local storage node. Result must not be nil.
// New tombstone objects will have the result as an owner ID if removal is executed w/o a session.
LocalNodeID() user.ID
}
type cfg struct {
log *logger.Logger
header interface {
// must return (nil, nil) for PHY objects
splitInfo(*execCtx) (*object.SplitInfo, error)
children(*execCtx) ([]oid.ID, error)
// must return (nil, nil) for 1st object in chain
previous(*execCtx, oid.ID) (*oid.ID, error)
}
searcher interface {
splitMembers(*execCtx) ([]oid.ID, error)
}
placer interface {
put(*execCtx) (*oid.ID, error)
}
netInfo NetworkInfo
}
func defaultCfg() *cfg {
return &cfg{
log: zap.L(),
}
}
// New creates, initializes and returns utility serving
// Object.Get service requests.
func New(opts ...Option) *Service {
c := defaultCfg()
for i := range opts {
opts[i](c)
}
return &Service{
cfg: c,
}
}
// WithLogger returns option to specify Delete service's logger.
func WithLogger(l *logger.Logger) Option {
return func(c *cfg) {
c.log = l.With(zap.String("component", "Object.Delete service"))
}
}
// WithHeadService returns option to set Head service
// to work with object headers.
func WithHeadService(h *getsvc.Service) Option {
return func(c *cfg) {
c.header = (*headSvcWrapper)(h)
}
}
// WithSearchService returns option to set search service.
func WithSearchService(s *searchsvc.Service) Option {
return func(c *cfg) {
c.searcher = (*searchSvcWrapper)(s)
}
}
// WithPutService returns option to specify put service.
func WithPutService(p *putsvc.Service) Option {
return func(c *cfg) {
c.placer = (*putSvcWrapper)(p)
}
}
// WithNetworkInfo returns option to set network information source.
func WithNetworkInfo(netInfo NetworkInfo) Option {
return func(c *cfg) {
c.netInfo = netInfo
}
}