Go http.FileServer()
Go http.FileServer()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import (
	"io"
	"net/http"
)
func main() {
	http.Handle("/", http.FileServer(http.Dir(".")))
	http.HandleFunc("/tesla", teslaFromFileSystem)
	http.ListenAndServe(":8080", nil)
}
func teslaFromFileSystem(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	io.WriteString(w, `<img src="tesla.jpg">`)
}
 This post is licensed under  CC BY 4.0  by the author.
