forked from TrueCloudLab/frostfs-node
Airat Arifullin
9b13a18aac
* Update version within go.mod; * Fix deprecated frostfs-api-go/v2 package and use frostfs-sdk-go/api instead. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package response
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/util"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
|
|
)
|
|
|
|
// Service represents universal v2 service
|
|
// that sets response meta header values.
|
|
type Service struct {
|
|
version refs.Version
|
|
|
|
state netmap.State
|
|
}
|
|
|
|
// NewService creates, initializes and returns Service instance.
|
|
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.version)
|
|
meta.SetTTL(1) // FIXME: #1160 TTL must be calculated
|
|
meta.SetEpoch(s.state.CurrentEpoch())
|
|
|
|
if origin := resp.GetMetaHeader(); origin != nil {
|
|
// FIXME: #1160 what if origin is set by local server?
|
|
meta.SetOrigin(origin)
|
|
}
|
|
|
|
resp.SetMetaHeader(meta)
|
|
}
|