Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/chat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
package main

import (
"bytes"
_ "embed"
"flag"
"log"
"net/http"
"time"
)

var addr = flag.String("addr", ":8080", "http service address")

//go:embed home.html
var homeHtml []byte

func serveHome(w http.ResponseWriter, r *http.Request) {
log.Println(r.URL)
if r.URL.Path != "/" {
Expand All @@ -22,7 +28,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
http.ServeFile(w, r, "home.html")
http.ServeContent(w, r, "home.html", time.Now(), bytes.NewReader(homeHtml))
}

func main() {
Expand Down
7 changes: 6 additions & 1 deletion examples/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package main

import (
"bufio"
"bytes"
_ "embed"
"flag"
"io"
"log"
Expand Down Expand Up @@ -165,6 +167,9 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
}
}

//go:embed home.html
var homeHtml []byte

func serveHome(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.Error(w, "Not found", http.StatusNotFound)
Expand All @@ -174,7 +179,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
http.ServeFile(w, r, "home.html")
http.ServeContent(w, r, "home.html", time.Now(), bytes.NewReader(homeHtml))
}

func main() {
Expand Down