refactoring to separate master and volume server, so that these servers

can be embedded into other applications
This commit is contained in:
Chris Lu
2013-12-02 01:37:36 -08:00
parent bc2f3b26e7
commit c38eee73ca
8 changed files with 741 additions and 531 deletions

View File

@@ -10,6 +10,7 @@ import (
"net"
"net/http"
"os"
"path/filepath"
"strings"
"sync"
"text/template"
@@ -244,3 +245,36 @@ func secure(whiteList []string, f func(w http.ResponseWriter, r *http.Request))
writeJsonQuiet(w, r, map[string]interface{}{"error": "No write permisson from " + host})
}
}
func parseURLPath(path string) (vid, fid, filename, ext string, isVolumeIdOnly bool) {
switch strings.Count(path, "/") {
case 3:
parts := strings.Split(path, "/")
vid, fid, filename = parts[1], parts[2], parts[3]
ext = filepath.Ext(filename)
case 2:
parts := strings.Split(path, "/")
vid, fid = parts[1], parts[2]
dotIndex := strings.LastIndex(fid, ".")
if dotIndex > 0 {
ext = fid[dotIndex:]
fid = fid[0:dotIndex]
}
default:
sepIndex := strings.LastIndex(path, "/")
commaIndex := strings.LastIndex(path[sepIndex:], ",")
if commaIndex <= 0 {
vid, isVolumeIdOnly = path[sepIndex+1:], true
return
}
dotIndex := strings.LastIndex(path[sepIndex:], ".")
vid = path[sepIndex+1 : commaIndex]
fid = path[commaIndex+1:]
ext = ""
if dotIndex > 0 {
fid = path[commaIndex+1 : dotIndex]
ext = path[dotIndex:]
}
}
return
}