♻️ Simplify static resources usage in main

This commit is contained in:
Maxim Lebedev 2023-11-10 09:09:07 +06:00
parent 962317d0c3
commit 369233a83e
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 2 additions and 3 deletions

View File

@ -5,7 +5,6 @@
package main
import (
"bytes"
"context"
"errors"
"flag"
@ -104,7 +103,7 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
return
}
f, err := staticer.Do(r.Context(), r.URL.Path)
res, err := staticer.Do(r.Context(), r.URL.Path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
http.Error(w, err.Error(), http.StatusNotFound)
@ -117,7 +116,7 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
return
}
http.ServeContent(w, r, f.LogicalName(), f.Updated, bytes.NewReader(f.Content))
http.ServeContent(w, r, res.Name(), domain.ResourceModTime(res), res)
return
}