Http server
This commit is contained in:
parent
2b1c780df3
commit
28962d2d44
1
.gitignore
vendored
1
.gitignore
vendored
@ -51,3 +51,4 @@ example-redis/example-redis
|
||||
echorot13/echorot13
|
||||
chatserver/chatserver
|
||||
example-httptcp/example-httptcp
|
||||
example-httpserver/example-httpserver
|
||||
|
23
example-httpserver/main.go
Normal file
23
example-httpserver/main.go
Normal file
@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type MyHandler int
|
||||
|
||||
func (MyHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||
resp.Header().Set("Content-Type", "text/plain")
|
||||
io.WriteString(resp, req.URL.Path)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var myHandler = new(MyHandler)
|
||||
s := &http.Server{
|
||||
Addr: ":9000",
|
||||
Handler: myHandler,
|
||||
}
|
||||
log.Fatal(s.ListenAndServe())
|
||||
}
|
Loading…
Reference in New Issue
Block a user