add: web基本知识
This commit is contained in:
26
web/framework/basic/main.go
Normal file
26
web/framework/basic/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// 路由1
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "hello basic web!")
|
||||
})
|
||||
|
||||
// 路由2
|
||||
http.HandleFunc("/xiaowei", func(w http.ResponseWriter, r *http.Request) {
|
||||
headers := r.Header
|
||||
for k, v := range headers {
|
||||
fmt.Fprintf(w, "[%v]-[%v]\n", k, v)
|
||||
}
|
||||
})
|
||||
// 启动一个httpserver
|
||||
if err := http.ListenAndServe(":9000", nil); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user