renumber
This commit is contained in:
22
089-http-server-static-dynamic/http-server-static-dynamic.go
Normal file
22
089-http-server-static-dynamic/http-server-static-dynamic.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// ## HTTP Server Static Dynamic
|
||||
|
||||
package main
|
||||
|
||||
import "net/http"
|
||||
|
||||
func hello(res http.ResponseWriter, req *http.Request) {
|
||||
res.Header().Set("Content-Type", "text/plain")
|
||||
res.Write([]byte("Hello From HTTP\n"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
helloHandler := http.HandlerFunc(hello)
|
||||
staticHandler := http.StripPrefix("/static/", http.FileServer(http.Dir("./")))
|
||||
http.Handle("/hello", helloHandler)
|
||||
http.Handle("/static/", staticHandler)
|
||||
http.ListenAndServe(":5000", nil)
|
||||
}
|
||||
|
||||
// todo: try to get dynamic at root
|
||||
// todo: try to get static at root
|
||||
// todo: favicon
|
||||
@@ -0,0 +1,6 @@
|
||||
$ cd src
|
||||
$ go run xx-http-server-static-dynamic.go
|
||||
|
||||
$ curl http://127.0.0.1:5000/hello
|
||||
$ curl http://127.0.0.1:5000/static
|
||||
$ curl http://127.0.0.1:5000/static/01-hello.go
|
||||
Reference in New Issue
Block a user