[#74] Replace atomics with mutex for reloadable params
All checks were successful
/ DCO (pull_request) Successful in 1m7s
/ Vulncheck (pull_request) Successful in 1m28s
/ Builds (1.20) (pull_request) Successful in 1m37s
/ Builds (1.21) (pull_request) Successful in 1m12s
/ Lint (pull_request) Successful in 14m9s
/ Tests (1.20) (pull_request) Successful in 1m41s
/ Tests (1.21) (pull_request) Successful in 9m36s

Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
Marina Biryukova 2023-09-05 18:17:22 +03:00
parent d219943542
commit e26577e753
4 changed files with 45 additions and 32 deletions

View file

@ -5,7 +5,6 @@ import (
"errors"
"io"
"net/url"
"sync/atomic"
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-http-gw/resolver"
@ -21,43 +20,26 @@ import (
"go.uber.org/zap"
)
type Config interface {
DefaultTimestamp() bool
ZipCompression() bool
}
type Handler struct {
log *zap.Logger
pool *pool.Pool
ownerID *user.ID
settings *Settings
config Config
containerResolver *resolver.ContainerResolver
tree *tree.Tree
}
// Settings stores reloading parameters, so it has to provide atomic getters and setters.
type Settings struct {
defaultTimestamp atomic.Bool
zipCompression atomic.Bool
}
func (s *Settings) DefaultTimestamp() bool {
return s.defaultTimestamp.Load()
}
func (s *Settings) SetDefaultTimestamp(val bool) {
s.defaultTimestamp.Store(val)
}
func (s *Settings) ZipCompression() bool {
return s.zipCompression.Load()
}
func (s *Settings) SetZipCompression(val bool) {
s.zipCompression.Store(val)
}
func New(params *utils.AppParams, settings *Settings, tree *tree.Tree) *Handler {
func New(params *utils.AppParams, config Config, tree *tree.Tree) *Handler {
return &Handler{
log: params.Logger,
pool: params.Pool,
ownerID: params.Owner,
settings: settings,
config: config,
containerResolver: params.Resolver,
tree: tree,
}