issue 43 "go fmt" chagnes from "Ryan S. Brown" <sb@ryansb.com>

some basic changes to parse upload url
This commit is contained in:
Chris Lu
2013-09-01 23:58:21 -07:00
parent 2e70cc8be7
commit 82b74c7940
28 changed files with 102 additions and 86 deletions

View File

@@ -3,9 +3,9 @@ package main
import (
"archive/tar"
"bytes"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
"fmt"
"code.google.com/p/weed-fs/go/glog"
"os"
"path"
"strconv"

View File

@@ -1,8 +1,8 @@
package main
import (
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/storage"
"os"
"path"
"strconv"

View File

@@ -182,7 +182,7 @@ func volumeStatusHandler(w http.ResponseWriter, r *http.Request) {
}
func redirectHandler(w http.ResponseWriter, r *http.Request) {
vid, _, _, _ := parseURLPath(r.URL.Path)
vid, _, _, _, _ := parseURLPath(r.URL.Path)
volumeId, err := storage.NewVolumeId(vid)
if err != nil {
debug("parsing error:", err, r.URL.Path)

View File

@@ -2,8 +2,8 @@ package main
import (
"bufio"
"fmt"
"code.google.com/p/weed-fs/go/glog"
"fmt"
"os"
)

View File

@@ -118,7 +118,7 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
}
func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
n := new(storage.Needle)
vid, fid, filename, ext := parseURLPath(r.URL.Path)
vid, fid, filename, ext, _ := parseURLPath(r.URL.Path)
volumeId, err := storage.NewVolumeId(vid)
if err != nil {
debug("parsing error:", err, r.URL.Path)
@@ -207,7 +207,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
writeJsonError(w, r, e)
return
}
vid, _, _, _ := parseURLPath(r.URL.Path)
vid, _, _, _, _ := parseURLPath(r.URL.Path)
volumeId, ve := storage.NewVolumeId(vid)
if ve != nil {
debug("NewVolumeId error:", ve)
@@ -231,7 +231,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
}
func DeleteHandler(w http.ResponseWriter, r *http.Request) {
n := new(storage.Needle)
vid, fid, _, _ := parseURLPath(r.URL.Path)
vid, fid, _, _, _ := parseURLPath(r.URL.Path)
volumeId, _ := storage.NewVolumeId(vid)
n.ParsePath(fid)
@@ -266,7 +266,7 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) {
writeJsonQuiet(w, r, m)
}
func parseURLPath(path string) (vid, fid, filename, ext string) {
func parseURLPath(path string) (vid, fid, filename, ext string, isVolumeIdOnly bool) {
switch strings.Count(path, "/") {
case 3:
parts := strings.Split(path, "/")
@@ -284,9 +284,7 @@ func parseURLPath(path string) (vid, fid, filename, ext string) {
sepIndex := strings.LastIndex(path, "/")
commaIndex := strings.LastIndex(path[sepIndex:], ",")
if commaIndex <= 0 {
if "favicon.ico" != path[sepIndex+1:] {
glog.V(0).Infoln("unknown file id", path[sepIndex+1:])
}
vid, isVolumeIdOnly = path[sepIndex+1:], true
return
}
dotIndex := strings.LastIndex(path[sepIndex:], ".")

View File

@@ -7,7 +7,7 @@ import (
"fmt"
"io"
"math/rand"
"net"
"net"
"net/http"
"os"
"strings"
@@ -225,20 +225,20 @@ func debug(params ...interface{}) {
}
}
func secure(whiteList []string, f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if len(whiteList) == 0 {
f(w, r)
return
}
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err == nil {
for _, ip := range whiteList {
if ip == host {
f(w, r)
return
}
}
}
writeJsonQuiet(w, r, map[string]interface{}{"error": "No write permisson from " + host})
}
return func(w http.ResponseWriter, r *http.Request) {
if len(whiteList) == 0 {
f(w, r)
return
}
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err == nil {
for _, ip := range whiteList {
if ip == host {
f(w, r)
return
}
}
}
writeJsonQuiet(w, r, map[string]interface{}{"error": "No write permisson from " + host})
}
}