We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66d10c5 commit 1b78f0fCopy full SHA for 1b78f0f
tools/serve.go
@@ -3,11 +3,28 @@ package main
3
import (
4
"fmt"
5
"net/http"
6
+ "os"
7
)
8
9
+type HTMLDir struct {
10
+ d http.Dir
11
+}
12
+
13
+func (d HTMLDir) Open(name string) (http.File, error) {
14
+ f, err := d.d.Open(name)
15
+ if os.IsNotExist(err) {
16
+ if f, err := d.d.Open(name + ".html"); err == nil {
17
+ return f, nil
18
+ }
19
20
+ return f, err
21
22
23
func main() {
24
port := "8000"
25
publicDir := "public"
26
fmt.Printf("Serving Go by Example at http://127.0.0.1:%s\n", port)
- http.ListenAndServe(":"+port, http.FileServer(http.Dir(publicDir)))
27
+ fs := http.FileServer(HTMLDir{http.Dir(publicDir)})
28
+ http.Handle("/", http.StripPrefix("/", fs))
29
+ http.ListenAndServe(":"+port, nil)
30
}
0 commit comments