Created
July 4, 2018 04:54
-
-
Save hauxe/f88a87f4037bca23f04f6d100f6e08d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FileSystem custom file system handler | |
type FileSystem struct { | |
fs http.FileSystem | |
} | |
// Open opens file | |
func (fs FileSystem) Open(path string) (http.File, error) { | |
f, err := fs.fs.Open(path) | |
if err != nil { | |
return nil, err | |
} | |
s, err := f.Stat() | |
if s.IsDir() { | |
index := strings.TrimSuffix(path, "/") + "/index.html" | |
if _, err := fs.fs.Open(index); err != nil { | |
return nil, err | |
} | |
} | |
return f, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working ..