Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

refactoring, start to use gorilla/mux

Chris Lubc2f3b26e708
diff --git a/go/weed/master.go b/go/weed/master.go
index 4fff9c2dd0..6255f85f5d 100644
--- a/go/weed/master.go
+++ b/go/weed/master.go
@@ -10,6 +10,7 @@ import (
"code.google.com/p/weed-fs/go/topology"
"encoding/json"
"errors"
+ "github.com/gorilla/mux"
"net/http"
"os"
"path"
@@ -233,23 +234,24 @@ func runMaster(cmd *Command, args []string) bool {
}
vg = replication.NewDefaultVolumeGrowth()
glog.V(0).Infoln("Volume Size Limit is", *volumeSizeLimitMB, "MB")
- http.HandleFunc("/dir/assign", secure(masterWhiteList, dirAssignHandler))
- http.HandleFunc("/dir/lookup", secure(masterWhiteList, dirLookupHandler))
- http.HandleFunc("/dir/join", secure(masterWhiteList, dirJoinHandler))
- http.HandleFunc("/dir/status", secure(masterWhiteList, dirStatusHandler))
- http.HandleFunc("/vol/grow", secure(masterWhiteList, volumeGrowHandler))
- http.HandleFunc("/vol/status", secure(masterWhiteList, volumeStatusHandler))
- http.HandleFunc("/vol/vacuum", secure(masterWhiteList, volumeVacuumHandler))
- http.HandleFunc("/submit", secure(masterWhiteList, submitFromMasterServerHandler))
- http.HandleFunc("/", redirectHandler)
+ r := mux.NewRouter()
+ r.HandleFunc("/dir/assign", secure(masterWhiteList, dirAssignHandler))
+ r.HandleFunc("/dir/lookup", secure(masterWhiteList, dirLookupHandler))
+ r.HandleFunc("/dir/join", secure(masterWhiteList, dirJoinHandler))
+ r.HandleFunc("/dir/status", secure(masterWhiteList, dirStatusHandler))
+ r.HandleFunc("/vol/grow", secure(masterWhiteList, volumeGrowHandler))
+ r.HandleFunc("/vol/status", secure(masterWhiteList, volumeStatusHandler))
+ r.HandleFunc("/vol/vacuum", secure(masterWhiteList, volumeVacuumHandler))
+ r.HandleFunc("/submit", secure(masterWhiteList, submitFromMasterServerHandler))
+ r.HandleFunc("/", redirectHandler)
topo.StartRefreshWritableVolumes(*garbageThreshold)
glog.V(0).Infoln("Start Weed Master", VERSION, "at port", strconv.Itoa(*mport))
srv := &http.Server{
Addr: ":" + strconv.Itoa(*mport),
- Handler: http.DefaultServeMux,
+ Handler: r,
ReadTimeout: time.Duration(*mReadTimeout) * time.Second,
}
e = srv.ListenAndServe()
diff --git a/go/weed/volume.go b/go/weed/volume.go
index 8bb1a0540e..f3a6038c2d 100644
--- a/go/weed/volume.go
+++ b/go/weed/volume.go
@@ -5,6 +5,7 @@ import (
"code.google.com/p/weed-fs/go/operation"
"code.google.com/p/weed-fs/go/replication"
"code.google.com/p/weed-fs/go/storage"
+ "github.com/gorilla/mux"
"math/rand"
"mime"
"net/http"
@@ -341,14 +342,15 @@ func runVolume(cmd *Command, args []string) bool {
store = storage.NewStore(*vport, *ip, *publicUrl, folders, maxCounts)
defer store.Close()
- http.HandleFunc("/", storeHandler)
- http.HandleFunc("/submit", secure(volumeWhiteList, submitFromVolumeServerHandler))
- http.HandleFunc("/status", secure(volumeWhiteList, statusHandler))
- http.HandleFunc("/admin/assign_volume", secure(volumeWhiteList, assignVolumeHandler))
- http.HandleFunc("/admin/vacuum_volume_check", secure(volumeWhiteList, vacuumVolumeCheckHandler))
- http.HandleFunc("/admin/vacuum_volume_compact", secure(volumeWhiteList, vacuumVolumeCompactHandler))
- http.HandleFunc("/admin/vacuum_volume_commit", secure(volumeWhiteList, vacuumVolumeCommitHandler))
- http.HandleFunc("/admin/freeze_volume", secure(volumeWhiteList, freezeVolumeHandler))
+ r := mux.NewRouter()
+ r.HandleFunc("/submit", secure(volumeWhiteList, submitFromVolumeServerHandler))
+ r.HandleFunc("/status", secure(volumeWhiteList, statusHandler))
+ r.HandleFunc("/admin/assign_volume", secure(volumeWhiteList, assignVolumeHandler))
+ r.HandleFunc("/admin/vacuum_volume_check", secure(volumeWhiteList, vacuumVolumeCheckHandler))
+ r.HandleFunc("/admin/vacuum_volume_compact", secure(volumeWhiteList, vacuumVolumeCompactHandler))
+ r.HandleFunc("/admin/vacuum_volume_commit", secure(volumeWhiteList, vacuumVolumeCommitHandler))
+ r.HandleFunc("/admin/freeze_volume", secure(volumeWhiteList, freezeVolumeHandler))
+ r.HandleFunc("/", storeHandler)
go func() {
connected := true
@@ -375,7 +377,7 @@ func runVolume(cmd *Command, args []string) bool {
glog.V(0).Infoln("Start Weed volume server", VERSION, "at http://"+*ip+":"+strconv.Itoa(*vport))
srv := &http.Server{
Addr: ":" + strconv.Itoa(*vport),
- Handler: http.DefaultServeMux,
+ Handler: r,
ReadTimeout: (time.Duration(*vReadTimeout) * time.Second),
}
e := srv.ListenAndServe()