fix(ui): defer file close
parent
a47845a390
commit
3909411dae
ui
15
ui/dist.go
15
ui/dist.go
|
@ -83,6 +83,7 @@ func addCacheHeaders(name string, headers http.Header) error {
|
||||||
if input, err := buildDir.Open(name); err != nil {
|
if input, err := buildDir.Open(name); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
|
defer input.Close()
|
||||||
if _, err := io.Copy(hash, input); err != nil {
|
if _, err := io.Copy(hash, input); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -103,14 +104,14 @@ func (b *BindataAssets) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
openFn := func(name string) (fs.File, error) {
|
openFn := func(name string) (fs.File, error) {
|
||||||
// If the named asset exists, then return it directly.
|
// If the named asset exists, then return it directly.
|
||||||
file, err := buildDir.Open(name)
|
file, err := buildDir.Open(name)
|
||||||
|
// If this is at / then we we can return a Directory
|
||||||
|
// that will be be redirected to /index.html by http.fs
|
||||||
|
if name == "/" || name == "." {
|
||||||
|
return file, err
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If this is at / then we just error out so we can return a Directory
|
// If this is anything other than root, we have to return the default
|
||||||
// This directory will then be redirected by go to the /index.html
|
// asset. This default asset will handle the routing.
|
||||||
if name == "/" || name == "." {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// If this is anything other than slash, we just return the default
|
|
||||||
// asset. This default asset will handle the routing.
|
|
||||||
// Additionally, because we know we are returning the default asset,
|
// Additionally, because we know we are returning the default asset,
|
||||||
// we need to set the default asset's content-type.
|
// we need to set the default asset's content-type.
|
||||||
w.Header().Set("Content-Type", DefaultPageContentType)
|
w.Header().Set("Content-Type", DefaultPageContentType)
|
||||||
|
|
Loading…
Reference in New Issue