[#6] services/util: Simplify response.Service
It has only 1 parameter, which is obligatory. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
5a4054eeb6
commit
fef172c5b0
2 changed files with 7 additions and 35 deletions
|
@ -622,7 +622,7 @@ func initShared(appCfg *config.Config, key *keys.PrivateKey, netState *networkSt
|
|||
key: key,
|
||||
binPublicKey: key.PublicKey().Bytes(),
|
||||
localAddr: netAddr,
|
||||
respSvc: response.NewService(response.WithNetworkState(netState)),
|
||||
respSvc: response.NewService(netState),
|
||||
clientCache: cache.NewSDKClientCache(cacheOpts),
|
||||
bgClientCache: cache.NewSDKClientCache(cacheOpts),
|
||||
putClientCache: cache.NewSDKClientCache(cacheOpts),
|
||||
|
|
|
@ -11,45 +11,24 @@ import (
|
|||
// Service represents universal v2 service
|
||||
// that sets response meta header values.
|
||||
type Service struct {
|
||||
cfg *cfg
|
||||
}
|
||||
|
||||
// Option is an option of Service constructor.
|
||||
type Option func(*cfg)
|
||||
|
||||
type cfg struct {
|
||||
version refs.Version
|
||||
|
||||
state netmap.State
|
||||
}
|
||||
|
||||
func defaultCfg() *cfg {
|
||||
var c cfg
|
||||
|
||||
version.Current().WriteToV2(&c.version)
|
||||
|
||||
return &c
|
||||
}
|
||||
|
||||
// NewService creates, initializes and returns Service instance.
|
||||
func NewService(opts ...Option) *Service {
|
||||
c := defaultCfg()
|
||||
|
||||
for i := range opts {
|
||||
opts[i](c)
|
||||
}
|
||||
|
||||
return &Service{
|
||||
cfg: c,
|
||||
}
|
||||
func NewService(nmState netmap.State) *Service {
|
||||
s := &Service{state: nmState}
|
||||
version.Current().WriteToV2(&s.version)
|
||||
return s
|
||||
}
|
||||
|
||||
// SetMeta sets adds meta-header to resp.
|
||||
func (s *Service) SetMeta(resp util.ResponseMessage) {
|
||||
meta := new(session.ResponseMetaHeader)
|
||||
meta.SetVersion(&s.cfg.version)
|
||||
meta.SetVersion(&s.version)
|
||||
meta.SetTTL(1) // FIXME: #1160 TTL must be calculated
|
||||
meta.SetEpoch(s.cfg.state.CurrentEpoch())
|
||||
meta.SetEpoch(s.state.CurrentEpoch())
|
||||
|
||||
if origin := resp.GetMetaHeader(); origin != nil {
|
||||
// FIXME: #1160 what if origin is set by local server?
|
||||
|
@ -58,10 +37,3 @@ func (s *Service) SetMeta(resp util.ResponseMessage) {
|
|||
|
||||
resp.SetMetaHeader(meta)
|
||||
}
|
||||
|
||||
// WithNetworkState returns option to set network state of Service.
|
||||
func WithNetworkState(v netmap.State) Option {
|
||||
return func(c *cfg) {
|
||||
c.state = v
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue