From 2b5ab18066be22d72e6db2982dfa10f26d5aad91 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 18 Aug 2010 01:06:08 -0400 Subject: [PATCH] Add index and fe handlers. --- src/server.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/server.go b/src/server.go index 13566e8..1370b95 100644 --- a/src/server.go +++ b/src/server.go @@ -4,20 +4,32 @@ import ( "fmt" "http" "io" + "os" + "path" ) -const kFrontEndFiles = "/Users/rsesek/Projects/armadillo/out/fe/" +const kFrontEndFiles = "/Users/rsesek/Projects/armadillo/out/fe" func testHandler(connection *http.Conn, request *http.Request) { fmt.Print("Got a request"); io.WriteString(connection, "Hello world") } +func indexHandler(connection *http.Conn, request *http.Request) { + fd, err := os.Open(path.Join(kFrontEndFiles, "index.html"), os.O_RDONLY, 0) + if err != nil { + fmt.Print("Error opening file ", err.String(), "\n") + return + } + io.Copy(connection, fd) +} + func RunFrontEnd() { mux := http.NewServeMux() - mux.Handle("/fe", http.FileServer(kFrontEndFiles, "")) + mux.HandleFunc("/", indexHandler) + mux.Handle("/fe/", http.FileServer(kFrontEndFiles, "/fe/")) mux.HandleFunc("/test", testHandler) - // mux.Handle() + error := http.ListenAndServe(":8084", mux) fmt.Printf("error %v", error) } -- 2.43.5