refactoring, clean up, v0.17
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
func init() {
|
||||
cmdMaster.Run = runMaster // break init cycle
|
||||
IsDebug = cmdMaster.Flag.Bool("debug", false, "enable debug mode")
|
||||
port = cmdMaster.Flag.Int("port", 8080, "http listen port")
|
||||
}
|
||||
|
||||
var cmdMaster = &Command{
|
||||
@@ -26,6 +25,7 @@ var cmdMaster = &Command{
|
||||
}
|
||||
|
||||
var (
|
||||
mport = cmdMaster.Flag.Int("port", 9333, "http listen port")
|
||||
metaFolder = cmdMaster.Flag.String("mdir", "/tmp", "data directory to store mappings")
|
||||
capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold")
|
||||
mapper *directory.Mapper
|
||||
@@ -53,7 +53,6 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if err == nil {
|
||||
writeJson(w, r, map[string]string{"fid": fid, "url": machine.Url, "publicUrl":machine.PublicUrl, "count":strconv.Itoa(count)})
|
||||
} else {
|
||||
log.Println(err)
|
||||
writeJson(w, r, map[string]string{"error": err.Error()})
|
||||
}
|
||||
}
|
||||
@@ -79,8 +78,8 @@ func runMaster(cmd *Command, args []string) bool {
|
||||
http.HandleFunc("/dir/join", dirJoinHandler)
|
||||
http.HandleFunc("/dir/status", dirStatusHandler)
|
||||
|
||||
log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*port))
|
||||
e := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
|
||||
log.Println("Start directory service at http://127.0.0.1:" + strconv.Itoa(*mport))
|
||||
e := http.ListenAndServe(":"+strconv.Itoa(*mport), nil)
|
||||
if e != nil {
|
||||
log.Fatal("Fail to start:", e)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ func runVersion(cmd *Command, args []string) bool{
|
||||
cmd.Usage()
|
||||
}
|
||||
|
||||
fmt.Printf("version 0.16 %s %s\n",runtime.GOOS, runtime.GOARCH)
|
||||
fmt.Printf("version 0.17 %s %s\n",runtime.GOOS, runtime.GOARCH)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
func init() {
|
||||
cmdVolume.Run = runVolume // break init cycle
|
||||
IsDebug = cmdVolume.Flag.Bool("debug", false, "enable debug mode")
|
||||
port = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
||||
}
|
||||
|
||||
var cmdVolume = &Command{
|
||||
@@ -26,6 +25,7 @@ var cmdVolume = &Command{
|
||||
}
|
||||
|
||||
var (
|
||||
vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
||||
chunkFolder = cmdVolume.Flag.String("dir", "/tmp", "data directory to store files")
|
||||
volumes = cmdVolume.Flag.String("volumes", "0,1-3,4", "comma-separated list of volume ids or range of ids")
|
||||
publicUrl = cmdVolume.Flag.String("publicUrl", "localhost:8080", "public url to serve data read")
|
||||
@@ -153,7 +153,7 @@ func parseURLPath(path string) (vid, fid, ext string) {
|
||||
|
||||
func runVolume(cmd *Command, args []string) bool {
|
||||
//TODO: now default to 1G, this value should come from server?
|
||||
store = storage.NewStore(*port, *publicUrl, *chunkFolder, *volumes)
|
||||
store = storage.NewStore(*vport, *publicUrl, *chunkFolder, *volumes)
|
||||
defer store.Close()
|
||||
http.HandleFunc("/", storeHandler)
|
||||
http.HandleFunc("/status", statusHandler)
|
||||
@@ -167,8 +167,8 @@ func runVolume(cmd *Command, args []string) bool {
|
||||
}()
|
||||
log.Println("store joined at", *metaServer)
|
||||
|
||||
log.Println("Start storage service at http://127.0.0.1:"+strconv.Itoa(*port), "public url", *publicUrl)
|
||||
e := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
|
||||
log.Println("Start storage service at http://127.0.0.1:"+strconv.Itoa(*vport), "public url", *publicUrl)
|
||||
e := http.ListenAndServe(":"+strconv.Itoa(*vport), nil)
|
||||
if e != nil {
|
||||
log.Fatalf("Fail to start:", e)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
|
||||
var IsDebug *bool
|
||||
var server *string
|
||||
var port *int
|
||||
|
||||
var commands = []*Command{
|
||||
cmdFix,
|
||||
@@ -53,7 +52,7 @@ func main() {
|
||||
if args[0] == "help" {
|
||||
help(args[1:])
|
||||
for _, cmd := range commands {
|
||||
if cmd.Name() == args[1] && cmd.Run != nil {
|
||||
if len(args)>2 && cmd.Name() == args[1] && cmd.Run != nil {
|
||||
fmt.Fprintf(os.Stderr, "Default Parameters:\n")
|
||||
cmd.Flag.PrintDefaults()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user