diff --git a/app.go b/app.go index 487d356..22aaadb 100644 --- a/app.go +++ b/app.go @@ -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) diff --git a/downloader/download.go b/downloader/download.go index 3221c45..03fce82 100644 --- a/downloader/download.go +++ b/downloader/download.go @@ -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 {