Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-04-07 16:43:59 +03:00 committed by Angira Kekteeva
parent 5080b43a04
commit baf425453d
2 changed files with 17 additions and 12 deletions

6
app.go
View file

@ -199,10 +199,7 @@ func (a *app) Serve(ctx context.Context) {
}()
edts := a.cfg.GetBool(cfgUploaderHeaderEnableDefaultTimestamp)
uploader := uploader.New(a.log, a.pool, edts)
downloader, err := downloader.New(a.log, downloader.Settings{ZipCompression: a.cfg.GetBool(cfgZipCompression)}, a.pool)
if err != nil {
a.log.Fatal("failed to create downloader", zap.Error(err))
}
downloader := downloader.New(a.log, downloader.Settings{ZipCompression: a.cfg.GetBool(cfgZipCompression)}, a.pool)
// Configure router.
r := router.New()
r.RedirectTrailingSlash = true
@ -237,6 +234,7 @@ func (a *app) Serve(ctx context.Context) {
tlsKeyPath := a.cfg.GetString(cfgTLSKey)
a.webServer.Handler = r.Handler
var err error
if tlsCertPath == "" && tlsKeyPath == "" {
a.log.Info("running web server", zap.String("address", bind))
err = a.webServer.ListenAndServe(bind)

View file

@ -13,6 +13,8 @@ import (
"strconv"
"strings"
"time"
"unicode"
"unicode/utf8"
"github.com/nspcc-dev/neofs-http-gw/response"
"github.com/nspcc-dev/neofs-http-gw/tokens"
@ -190,7 +192,7 @@ func systemBackwardTranslator(key string) string {
strs := strings.Split(key, "_")
for i, s := range strs {
s = strings.Title(strings.ToLower(s))
s = title(strings.ToLower(s))
res.WriteString(s)
if i != len(strs)-1 {
res.WriteString("-")
@ -200,6 +202,16 @@ func systemBackwardTranslator(key string) string {
return res.String()
}
func title(str string) string {
if str == "" {
return ""
}
r, size := utf8.DecodeRuneInString(str)
r0 := unicode.ToTitle(r)
return string(r0) + str[size:]
}
func bearerToken(ctx context.Context) *token.BearerToken {
if tkn, err := tokens.LoadBearerToken(ctx); err == nil {
return tkn
@ -243,13 +255,8 @@ type Settings struct {
}
// New creates an instance of Downloader using specified options.
func New(log *zap.Logger, settings Settings, conns *pool.Pool) (*Downloader, error) {
var err error
d := &Downloader{log: log, pool: conns, settings: settings}
if err != nil {
return nil, fmt.Errorf("failed to get neofs client's reusable artifacts: %w", err)
}
return d, nil
func New(log *zap.Logger, settings Settings, conns *pool.Pool) *Downloader {
return &Downloader{log: log, pool: conns, settings: settings}
}
func (d *Downloader) newRequest(ctx *fasthttp.RequestCtx, log *zap.Logger) *request {