Files
miniws/fetch.go
2025-08-02 21:30:41 +02:00

25 lines
404 B
Go

package main
import (
"os"
"strings"
)
func fetchFileContents(filepath string) ([]byte, error) {
if filepath == "/" {
filepath = "."
} else {
filepath_relative, _ := strings.CutPrefix(filepath, "/")
filepath = filepath_relative
}
fileinfo, err := os.Stat(filepath)
if err != nil {
return nil, err
}
if fileinfo.IsDir() {
filepath += "/index.html"
}
return os.ReadFile(filepath)
}