Skip to content

Instantly share code, notes, and snippets.

@nwjlyons
Created September 28, 2017 13:14
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 nwjlyons/121063467e11d0c30e7561357b6ea24f to your computer and use it in GitHub Desktop.
Save nwjlyons/121063467e11d0c30e7561357b6ea24f to your computer and use it in GitHub Desktop.
Print HTTP request to stdout
package main
import (
"net"
"os"
"log"
"fmt"
"io"
)
func main() {
port := 8080
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
log.Fatalf("could not listen to tcp connections on port %d: %v", port, err)
}
for {
conn, err := ln.Accept()
if err != nil {
log.Printf("could not accept connection: %v", err)
}
go func(){
io.Copy(os.Stdout, conn)
}()
}
}
@nwjlyons
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment