13 var dir, file = path.Split(path.Clean(os.Getenv("_")))
14 var kFrontEndFiles string = path.Join(dir, "fe")
16 func indexHandler(connection *http.Conn, request *http.Request) {
17 fd, err := os.Open(path.Join(kFrontEndFiles, "index.html"), os.O_RDONLY, 0)
19 fmt.Print("Error opening file ", err.String(), "\n")
22 io.Copy(connection, fd)
25 func serviceHandler(connection *http.Conn, request *http.Request) {
26 if request.Method != "POST" {
27 io.WriteString(connection, "Error: Not a POST request")
31 switch request.FormValue("action") {
33 files, err := paths.List(request.FormValue("path"))
35 errorResponse(connection, err.String())
37 okResponse(connection, files)
42 errorResponse(connection, "Unhandled action")
45 func errorResponse(connection *http.Conn, message string) {
46 response := map[string] string {
50 json_data, err := json.Marshal(response)
52 connection.SetHeader("Content-Type", "text/json")
54 io.WriteString(connection, "{\"error\":\"-9\",\"message\":\"Internal encoding error\"}")
56 connection.Write(json_data)
60 func okResponse(connection *http.Conn, data interface{}) {
61 connection.SetHeader("Content-Type", "text/json")
62 json_data, err := json.Marshal(data)
64 errorResponse(connection, "Internal encoding error")
66 connection.Write(json_data)
71 mux := http.NewServeMux()
72 mux.HandleFunc("/", indexHandler)
73 mux.Handle("/fe/", http.FileServer(kFrontEndFiles, "/fe/"))
74 mux.HandleFunc("/service", serviceHandler)
76 error := http.ListenAndServe(":8084", mux)
77 fmt.Printf("error %v", error)