From 47235bc46f1027d4d9627729736f7f7012f24fda Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 3 Apr 2012 08:54:50 -0400 Subject: [PATCH] Run gofix --- config/config.go | 4 ++-- server/paths.go | 21 +++++++++++---------- server/server.go | 33 +++++++++++++++++---------------- server/tv_rename.go | 20 +++++++++++--------- 4 files changed, 41 insertions(+), 37 deletions(-) diff --git a/config/config.go b/config/config.go index 75a195b..ae70283 100644 --- a/config/config.go +++ b/config/config.go @@ -10,7 +10,7 @@ package config import ( - "json" + "encoding/json" "os" ) @@ -31,7 +31,7 @@ type Configuration struct { IncludeDotfiles bool } -func ReadFromFile(aPath string, config *Configuration) os.Error { +func ReadFromFile(aPath string, config *Configuration) error { fd, error := os.Open(aPath) if error != nil { return error diff --git a/server/paths.go b/server/paths.go index 9b1d4f9..b0358da 100644 --- a/server/paths.go +++ b/server/paths.go @@ -10,11 +10,12 @@ package server import ( + "../config" "container/vector" + "errors" "os" "path" "strings" - "../config" ) var gConfig *config.Configuration @@ -47,10 +48,10 @@ func IsValid(path string) (bool, string) { return err == nil && checkInJail(path), path } -func List(the_path string) (files vector.StringVector, err os.Error) { +func List(the_path string) (files vector.StringVector, err error) { full_path := canonicalizePath(the_path) if !checkInJail(full_path) { - return nil, os.NewError("Path outside of jail") + return nil, errors.New("Path outside of jail") } fd, file_error := os.Open(full_path) @@ -77,30 +78,30 @@ func List(the_path string) (files vector.StringVector, err os.Error) { return files, nil } -func Remove(the_path string) os.Error { +func Remove(the_path string) error { full_path := canonicalizePath(the_path) if !checkInJail(full_path) { - return os.NewError("Path outside of jail") + return errors.New("Path outside of jail") } return os.RemoveAll(full_path) } -func Move(source string, target string) os.Error { +func Move(source string, target string) error { source = canonicalizePath(source) target = canonicalizePath(target) if !checkInJail(source) { - return os.NewError("Source outside of jail") + return errors.New("Source outside of jail") } if !checkInJail(target) { - return os.NewError("Target outside of jail") + return errors.New("Target outside of jail") } return os.Rename(source, target) } -func MakeDir(target string) os.Error { +func MakeDir(target string) error { target = canonicalizePath(target) if !checkInJail(target) { - return os.NewError("Path outside of jail") + return errors.New("Path outside of jail") } return os.Mkdir(target, 0755) } diff --git a/server/server.go b/server/server.go index 1dbbbe9..88ad930 100644 --- a/server/server.go +++ b/server/server.go @@ -10,16 +10,17 @@ package server import ( + "../config" + "encoding/json" "fmt" - "http" "io" - "json" "net" + "net/http" + "net/http/httputil" + "net/url" "os" "path" "strings" - "url" - "../config" ) var dir, file = path.Split(path.Clean(os.Getenv("_"))) @@ -29,7 +30,7 @@ var gConfig *config.Configuration = nil func indexHandler(response http.ResponseWriter, request *http.Request) { fd, err := os.Open(path.Join(kFrontEndFiles, "index.html")) if err != nil { - fmt.Print("Error opening file ", err.String(), "\n") + fmt.Print("Error opening file ", err.Error(), "\n") return } defer fd.Close() @@ -48,14 +49,14 @@ func serviceHandler(response http.ResponseWriter, request *http.Request) { case "list": files, err := paths.List(request.FormValue("path")) if err != nil { - errorResponse(response, err.String()) + errorResponse(response, err.Error()) } else { okResponse(response, files) } case "remove": err := paths.Remove(request.FormValue("path")) if err != nil { - errorResponse(response, err.String()) + errorResponse(response, err.Error()) } else { data := map[string]int{ "error": 0, @@ -67,7 +68,7 @@ func serviceHandler(response http.ResponseWriter, request *http.Request) { target := request.FormValue("target") err := paths.Move(source, target) if err != nil { - errorResponse(response, err.String()) + errorResponse(response, err.Error()) } else { data := map[string]interface{}{ "path": target, @@ -79,7 +80,7 @@ func serviceHandler(response http.ResponseWriter, request *http.Request) { path := request.FormValue("path") err := paths.MakeDir(path) if err != nil { - errorResponse(response, err.String()) + errorResponse(response, err.Error()) } else { data := map[string]interface{}{ "path": path, @@ -90,7 +91,7 @@ func serviceHandler(response http.ResponseWriter, request *http.Request) { case "tv_rename": newPath, err := tv_rename.RenameEpisode(request.FormValue("path")) if err != nil { - errorResponse(response, err.String()) + errorResponse(response, err.Error()) } else { data := map[string]interface{}{ "path": *newPath, @@ -123,21 +124,21 @@ func proxyHandler(response http.ResponseWriter, request *http.Request) { url_, err := url.Parse(rawURL) if err != nil { - errorResponse(response, err.String()) + errorResponse(response, err.Error()) return } err = performProxy(url_, response, request) if err != nil { - errorResponse(response, err.String()) + errorResponse(response, err.Error()) } } -func performProxy(url_ *url.URL, response http.ResponseWriter, origRequest *http.Request) os.Error { +func performProxy(url_ *url.URL, response http.ResponseWriter, origRequest *http.Request) error { conn, err := net.Dial("tcp", url_.Host+":http") if err != nil { return err } - client := http.NewClientConn(conn, nil) + client := httputil.NewClientConn(conn, nil) request, err := http.NewRequest("GET", url_.String(), nil) if err != nil { return err @@ -149,7 +150,7 @@ func performProxy(url_ *url.URL, response http.ResponseWriter, origRequest *http } var proxyResponse *http.Response proxyResponse, err = client.Read(request) - if err != nil && err != http.ErrPersistEOF { + if err != nil && err != httputil.ErrPersistEOF { return err } _, err = io.Copy(response, proxyResponse.Body) @@ -160,7 +161,7 @@ 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|. - if info.IsDirectory() { + if info.IsDir() { http.Error(response, "Path is a directory", http.StatusBadRequest) } else { http.ServeFile(response, request, fullPath) diff --git a/server/tv_rename.go b/server/tv_rename.go index b8d0704..f1dd48b 100644 --- a/server/tv_rename.go +++ b/server/tv_rename.go @@ -11,25 +11,27 @@ package server import ( "bufio" + "errors" "fmt" - "http" + "io" "net" - "os" + "net/http" + "net/http/httputil" + "net/url" "path" "regexp" "strconv" "strings" - "url" ) // Takes a full file path and renames the last path component as if it were a // TV episode. This performs the actual rename as well. -func RenameEpisode(inPath string) (*string, os.Error) { +func RenameEpisode(inPath string) (*string, error) { // Parse the filename into its components. dirName, fileName := path.Split(inPath) info := parseEpisodeName(fileName) if info == nil { - return nil, os.NewError("Could not parse file name") + return nil, errors.New("Could not parse file name") } // Create the URL and perform the lookup. @@ -113,7 +115,7 @@ 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) { +func performLookup(urlString string) (*http.Response, error) { url_, err := url.Parse(urlString) if err != nil { return nil, err @@ -126,7 +128,7 @@ func performLookup(urlString string) (*http.Response, os.Error) { } // Perform the HTTP request. - client := http.NewClientConn(conn, nil) + client := httputil.NewClientConn(conn, nil) request, err := http.NewRequest("GET", urlString, nil) if err != nil { return nil, err @@ -141,12 +143,12 @@ func performLookup(urlString string) (*http.Response, os.Error) { // Parses the HTTP response from performLookup(). func parseResponse(response *http.Response) *fullEpisodeInfo { - var err os.Error + var err error var line string var info fullEpisodeInfo buf := bufio.NewReader(response.Body) - for ; err != os.EOF; line, err = buf.ReadString('\n') { + for ; err != io.EOF; line, err = buf.ReadString('\n') { // An error ocurred while reading. if err != nil { return nil -- 2.43.5