Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kmassada
Last active February 27, 2018 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmassada/de32806b10d11419ed2ec187e9d1c16d to your computer and use it in GitHub Desktop.
Save kmassada/de32806b10d11419ed2ec187e9d1c16d to your computer and use it in GitHub Desktop.
go echoheaders
package main
import (
"fmt"
"net/http"
"strings"
"time"
)
// handler hello world, the web server
func handler(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "path:%s\n", req.URL.Path)
fmt.Fprintf(w, "scheme:%s\n", req.URL.Scheme)
for k, v := range req.Header {
fmt.Fprintf(w, "key:%s", k)
fmt.Fprintf(w, "val:%s", strings.Join(v, ""))
}
}
// main fundtion
func main() {
http.HandleFunc("/", handler)
server := &http.Server{
Addr: ":3333",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
server.SetKeepAlivesEnabled(true)
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment