Last active
February 27, 2018 00:46
-
-
Save kmassada/de32806b10d11419ed2ec187e9d1c16d to your computer and use it in GitHub Desktop.
go echoheaders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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