mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-14 06:10:27 +00:00
34 lines
549 B
Go
34 lines
549 B
Go
|
//go:build !go1.16
|
||
|
// +build !go1.16
|
||
|
|
||
|
package echo
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
)
|
||
|
|
||
|
func (c *context) File(file string) (err error) {
|
||
|
f, err := os.Open(file)
|
||
|
if err != nil {
|
||
|
return NotFoundHandler(c)
|
||
|
}
|
||
|
defer f.Close()
|
||
|
|
||
|
fi, _ := f.Stat()
|
||
|
if fi.IsDir() {
|
||
|
file = filepath.Join(file, indexPage)
|
||
|
f, err = os.Open(file)
|
||
|
if err != nil {
|
||
|
return NotFoundHandler(c)
|
||
|
}
|
||
|
defer f.Close()
|
||
|
if fi, err = f.Stat(); err != nil {
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
|
||
|
return
|
||
|
}
|