26 lines
471 B
Go
26 lines
471 B
Go
package httpserver
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func hello(rw http.ResponseWriter, req *http.Request) {
|
|
fmt.Fprintln(rw, "Hello, world!")
|
|
}
|
|
|
|
func headers(rw http.ResponseWriter, req *http.Request) {
|
|
for k, v := range req.Header {
|
|
fmt.Fprintf(rw, "%s: %v\n", k, strings.Join(v, " "))
|
|
}
|
|
}
|
|
|
|
func HttpServer() {
|
|
http.HandleFunc("/hello", hello)
|
|
http.HandleFunc("/headers", headers)
|
|
|
|
fmt.Println("Listening on 8002")
|
|
http.ListenAndServe(":8002", nil)
|
|
}
|