diff --git a/http/server.go b/http/server.go index 516426f..788cb7e 100644 --- a/http/server.go +++ b/http/server.go @@ -1,34 +1,27 @@ package http import ( - "net" + "net/http" "fmt" ) func NewServer(port string) (error) { - l, err := net.Listen("tcp", ":" + port) - if err != nil { + server := http.NewServeMux() + server_setup(server) + if err := http.ListenAndServe(":" + port, server); err != nil { return err } - go start(l) return nil } -func start(l net.Listener) { - for { - conn, err := l.Accept() - if err != nil { - continue - } - go handle_conn(conn) - } +func server_setup(server *http.ServeMux) { + server.HandleFunc("/", test) } -func handle_conn(conn net.Conn) { - defer conn.Close() - buf := make([]byte, 1024) - if _, err := conn.Read(buf); err != nil { - return +func test(w http.ResponseWriter, r *http.Request) { + test_buf := make([]byte, 32) + copy(test_buf, "test\ntest") + if _, err := w.Write(test_buf); err != nil { + fmt.Println(err) } - fmt.Println(buf) }