From a22dfd3214a16b4628520a2e6ec947477f1c65eb Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 30 Dec 2011 10:27:12 -0500 Subject: [PATCH] Update to be compatible with Go r60.3 --- build.py | 2 +- src/server.go | 19 ++++++++++--------- src/tv_rename.go | 17 +++++++++-------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/build.py b/build.py index ceacb9c..74acfd3 100755 --- a/build.py +++ b/build.py @@ -51,7 +51,7 @@ RESOURCES_FE = [ PRODUCT_NAME = 'armadillo' # The Golang version (hg id). -BACK_END_COMPILER_VERSION = '95d2ce135523 (release-branch.r57) release/release.r57.1' +BACK_END_COMPILER_VERSION = 'c1702f36df03 (release-branch.r60) release/release.r60.3' COMPILER = '6g' LINKER = '6l' diff --git a/src/server.go b/src/server.go index d050b42..2b6f500 100644 --- a/src/server.go +++ b/src/server.go @@ -18,6 +18,7 @@ import ( "os" "path" "strings" + "url" "./config" "./paths" "./tv_rename" @@ -80,7 +81,7 @@ func serviceHandler(response http.ResponseWriter, request *http.Request) { errorResponse(response, err.String()) } else { data := map[string]interface{}{ - "path": path, + "path": path, "error": 0, } okResponse(response, data) @@ -119,27 +120,27 @@ func proxyHandler(response http.ResponseWriter, request *http.Request) { return } - url, err := http.ParseURL(rawURL) + url_, err := url.Parse(rawURL) if err != nil { errorResponse(response, err.String()) return } - err = performProxy(url, response, request) + err = performProxy(url_, response, request) if err != nil { errorResponse(response, err.String()) } } -func performProxy(url *http.URL, response http.ResponseWriter, origRequest *http.Request) os.Error { - conn, err := net.Dial("tcp", url.Host+":http") +func performProxy(url_ *url.URL, response http.ResponseWriter, origRequest *http.Request) os.Error { + conn, err := net.Dial("tcp", url_.Host+":http") if err != nil { return err } client := http.NewClientConn(conn, nil) var request http.Request - request.URL = url + request.URL = url_ request.Method = "GET" - request.UserAgent = origRequest.UserAgent + request.Header.Set("User-Agent", origRequest.UserAgent()) err = client.Write(&request) if err != nil { return err @@ -156,7 +157,7 @@ func performProxy(url *http.URL, response http.ResponseWriter, origRequest *http func downloadHandler(response http.ResponseWriter, request *http.Request) { valid, fullPath := paths.IsValid(request.FormValue("path")) if valid { - info, _ := os.Lstat(fullPath) // Error is already checked by |valid|. + info, _ := os.Lstat(fullPath) // Error is already checked by |valid|. if info.IsDirectory() { http.Error(response, "Path is a directory", http.StatusBadRequest) } else { @@ -196,7 +197,7 @@ func okResponse(response http.ResponseWriter, data interface{}) { func RunBackEnd(config *config.Configuration) { mux := http.NewServeMux() mux.HandleFunc("/", indexHandler) - mux.Handle("/fe/", http.FileServer(kFrontEndFiles, "/fe/")) + mux.Handle("/fe/", http.StripPrefix("/fe/", http.FileServer(http.Dir(kFrontEndFiles)))) mux.HandleFunc("/service", serviceHandler) mux.HandleFunc("/download", downloadHandler) mux.HandleFunc("/proxy", proxyHandler) diff --git a/src/tv_rename.go b/src/tv_rename.go index 4f003be..9d0eeab 100644 --- a/src/tv_rename.go +++ b/src/tv_rename.go @@ -19,6 +19,7 @@ import ( "regexp" "strconv" "strings" + "url" ) // Takes a full file path and renames the last path component as if it were a @@ -94,7 +95,7 @@ func parseEpisodeName(name string) *episodeInfo { // Builds the URL to which we send a HTTP request to get the episode name. func buildURL(info *episodeInfo) string { return fmt.Sprintf("http://services.tvrage.com/tools/quickinfo.php?show=%s&ep=%dx%d", - http.URLEscape(info.showName), info.season, info.episode) + url.QueryEscape(info.showName), info.season, info.episode) } // Converts a season and episode to integers. If the return values are both 0, @@ -113,13 +114,13 @@ func convertEpisode(season string, episode string) (int, int) { // Performs the actual lookup and returns the HTTP response. func performLookup(urlString string) (*http.Response, os.Error) { - url, err := http.ParseURL(urlString) + url_, err := url.Parse(urlString) if err != nil { return nil, err } // Open a TCP connection. - conn, err := net.Dial("tcp", url.Host+":"+url.Scheme) + conn, err := net.Dial("tcp", url_.Host+":"+url_.Scheme) if err != nil { return nil, err } @@ -127,9 +128,9 @@ func performLookup(urlString string) (*http.Response, os.Error) { // Perform the HTTP request. client := http.NewClientConn(conn, nil) var request http.Request - request.URL = url + request.URL = url_ request.Method = "GET" - request.UserAgent = "Armadillo File Manager" + request.Header.Set("User-Agent", "Armadillo File Manager") err = client.Write(&request) if err != nil { return nil, err @@ -149,7 +150,7 @@ func parseResponse(response *http.Response) *fullEpisodeInfo { if err != nil { return nil } - var parts []string = strings.Split(line, "@", 2) + var parts []string = strings.SplitN(line, "@", 2) if len(parts) != 2 { continue } @@ -158,10 +159,10 @@ func parseResponse(response *http.Response) *fullEpisodeInfo { info.episode.showName = strings.TrimSpace(parts[1]) case "Episode Info": // Split the line, which is of the form: |SxE^Name^AirDate|. - parts = strings.Split(parts[1], "^", 3) + parts = strings.SplitN(parts[1], "^", 3) info.episodeName = parts[1] // Split the episode string. - episode := strings.Split(parts[0], "x", 2) + episode := strings.SplitN(parts[0], "x", 2) info.episode.season, info.episode.episode = convertEpisode(episode[0], episode[1]) if info.episode.season == 0 && info.episode.season == info.episode.episode { return nil -- 2.43.5