From ab6e14b154cb734cab88f225f454bde4d5a4ea82 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 14 Nov 2010 13:38:34 -0500 Subject: [PATCH] Sync to a new version of Golang. Include the version in the build.py file. --- build.py | 3 +++ src/server.go | 58 +++++++++++++++++++++++++-------------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/build.py b/build.py index b53e2a2..a7216b3 100755 --- a/build.py +++ b/build.py @@ -57,6 +57,9 @@ RESOURCES_CLOSURE = [ ] PRODUCT_NAME = 'armadillo' +# The Golang version (hg id). +BACK_END_COMPILER_VERSION = 'a7800e20064a release/release.2010-11-10' + COMPILER = '8g' LINKER = '8l' O_EXTENSION = '8' diff --git a/src/server.go b/src/server.go index 6080914..994d954 100644 --- a/src/server.go +++ b/src/server.go @@ -26,18 +26,18 @@ var dir, file = path.Split(path.Clean(os.Getenv("_"))) var kFrontEndFiles string = path.Join(dir, "fe") var gConfig *config.Configuration = nil -func indexHandler(connection *http.Conn, request *http.Request) { +func indexHandler(response http.ResponseWriter, 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) + io.Copy(response, fd) } -func serviceHandler(connection *http.Conn, request *http.Request) { +func serviceHandler(response http.ResponseWriter, request *http.Request) { if request.Method != "POST" { - io.WriteString(connection, "Error: Not a POST request") + io.WriteString(response, "Error: Not a POST request") return } @@ -45,38 +45,38 @@ func serviceHandler(connection *http.Conn, request *http.Request) { case "list": files, err := paths.List(request.FormValue("path")) if err != nil { - errorResponse(connection, err.String()) + errorResponse(response, err.String()) } else { - okResponse(connection, files) + okResponse(response, files) } case "remove": err := paths.Remove(request.FormValue("path")) if err != nil { - errorResponse(connection, err.String()) + errorResponse(response, err.String()) } else { - response := map[string] int { + data := map[string] int { "error" : 0, } - okResponse(connection, response) + okResponse(response, data) } case "move": source := request.FormValue("source") target := request.FormValue("target") err := paths.Move(source, target) if err != nil { - errorResponse(connection, err.String()) + errorResponse(response, err.String()) } else { - response := map[string] string { + data := map[string] string { "path" : target, } - okResponse(connection, response) + okResponse(response, data) } default: - errorResponse(connection, "Unhandled action") + errorResponse(response, "Unhandled action") } } -func proxyHandler(connection *http.Conn, request *http.Request) { +func proxyHandler(response http.ResponseWriter, request *http.Request) { rawURL := request.FormValue("url") if len(rawURL) < 1 { return @@ -89,22 +89,22 @@ func proxyHandler(connection *http.Conn, request *http.Request) { } if !validURL { - errorResponse(connection, "URL is not in proxy whitelist") + errorResponse(response, "URL is not in proxy whitelist") return } url, err := http.ParseURL(rawURL) if err != nil { - errorResponse(connection, err.String()) + errorResponse(response, err.String()) return } - err = performProxy(url, connection, request) + err = performProxy(url, response, request) if err != nil { - errorResponse(connection, err.String()) + errorResponse(response, err.String()) } } -func performProxy(url *http.URL, response *http.Conn, origRequest *http.Request) os.Error { +func performProxy(url *http.URL, response http.ResponseWriter, origRequest *http.Request) os.Error { conn, err := net.Dial("tcp", "", url.Host + ":http") if err != nil { return err @@ -127,29 +127,29 @@ func performProxy(url *http.URL, response *http.Conn, origRequest *http.Request) return err } -func errorResponse(connection *http.Conn, message string) { +func errorResponse(response http.ResponseWriter, message string) { message = strings.Replace(message, gConfig.JailRoot, "/", -1) - response := map[string] string { + data := map[string] string { "error" : "-1", "message" : message, } - json_data, err := json.Marshal(response) + json_data, err := json.Marshal(data) - connection.SetHeader("Content-Type", "text/json") + response.SetHeader("Content-Type", "text/json") if err != nil { - io.WriteString(connection, "{\"error\":\"-9\",\"message\":\"Internal encoding error\"}") + io.WriteString(response, "{\"error\":\"-9\",\"message\":\"Internal encoding error\"}") } else { - connection.Write(json_data) + response.Write(json_data) } } -func okResponse(connection *http.Conn, data interface{}) { - connection.SetHeader("Content-Type", "text/json") +func okResponse(response http.ResponseWriter, data interface{}) { + response.SetHeader("Content-Type", "text/json") json_data, err := json.Marshal(data) if err != nil { - errorResponse(connection, "Internal encoding error") + errorResponse(response, "Internal encoding error") } else { - connection.Write(json_data) + response.Write(json_data) } } -- 2.43.5