mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-18 23:47:55 +08:00
refactoring
This commit is contained in:
@@ -2,28 +2,47 @@ package weed_server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/chrislusf/seaweedfs/weed/stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
|
func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
start := time.Now()
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "GET":
|
case "GET":
|
||||||
|
stats.FilerRequestCounter.WithLabelValues("get").Inc()
|
||||||
fs.GetOrHeadHandler(w, r, true)
|
fs.GetOrHeadHandler(w, r, true)
|
||||||
|
stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds())
|
||||||
case "HEAD":
|
case "HEAD":
|
||||||
|
stats.FilerRequestCounter.WithLabelValues("head").Inc()
|
||||||
fs.GetOrHeadHandler(w, r, false)
|
fs.GetOrHeadHandler(w, r, false)
|
||||||
|
stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
|
stats.FilerRequestCounter.WithLabelValues("delete").Inc()
|
||||||
fs.DeleteHandler(w, r)
|
fs.DeleteHandler(w, r)
|
||||||
|
stats.FilerRequestHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds())
|
||||||
case "PUT":
|
case "PUT":
|
||||||
|
stats.FilerRequestCounter.WithLabelValues("put").Inc()
|
||||||
fs.PostHandler(w, r)
|
fs.PostHandler(w, r)
|
||||||
|
stats.FilerRequestHistogram.WithLabelValues("put").Observe(time.Since(start).Seconds())
|
||||||
case "POST":
|
case "POST":
|
||||||
|
stats.FilerRequestCounter.WithLabelValues("post").Inc()
|
||||||
fs.PostHandler(w, r)
|
fs.PostHandler(w, r)
|
||||||
|
stats.FilerRequestHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {
|
func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
start := time.Now()
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "GET":
|
case "GET":
|
||||||
|
stats.FilerRequestCounter.WithLabelValues("get").Inc()
|
||||||
fs.GetOrHeadHandler(w, r, true)
|
fs.GetOrHeadHandler(w, r, true)
|
||||||
|
stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds())
|
||||||
case "HEAD":
|
case "HEAD":
|
||||||
|
stats.FilerRequestCounter.WithLabelValues("head").Inc()
|
||||||
fs.GetOrHeadHandler(w, r, false)
|
fs.GetOrHeadHandler(w, r, false)
|
||||||
|
stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/chrislusf/seaweedfs/weed/filer2"
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
||||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||||
@@ -21,10 +20,6 @@ import (
|
|||||||
|
|
||||||
func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
|
func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
|
||||||
|
|
||||||
stats.FilerRequestCounter.WithLabelValues("get").Inc()
|
|
||||||
start := time.Now()
|
|
||||||
defer func() { stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds()) }()
|
|
||||||
|
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
if strings.HasSuffix(path, "/") && len(path) > 1 {
|
if strings.HasSuffix(path, "/") && len(path) > 1 {
|
||||||
path = path[:len(path)-1]
|
path = path[:len(path)-1]
|
||||||
@@ -61,7 +56,6 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
|
|||||||
|
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
w.Header().Set("Accept-Ranges", "bytes")
|
||||||
if r.Method == "HEAD" {
|
if r.Method == "HEAD" {
|
||||||
stats.FilerRequestCounter.WithLabelValues("head").Inc()
|
|
||||||
w.Header().Set("Content-Length", strconv.FormatInt(int64(filer2.TotalSize(entry.Chunks)), 10))
|
w.Header().Set("Content-Length", strconv.FormatInt(int64(filer2.TotalSize(entry.Chunks)), 10))
|
||||||
w.Header().Set("Last-Modified", entry.Attr.Mtime.Format(http.TimeFormat))
|
w.Header().Set("Last-Modified", entry.Attr.Mtime.Format(http.TimeFormat))
|
||||||
setEtag(w, filer2.ETag(entry.Chunks))
|
setEtag(w, filer2.ETag(entry.Chunks))
|
||||||
|
@@ -77,10 +77,6 @@ func (fs *FilerServer) assignNewFileInfo(w http.ResponseWriter, r *http.Request,
|
|||||||
|
|
||||||
func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
stats.FilerRequestCounter.WithLabelValues("post").Inc()
|
|
||||||
start := time.Now()
|
|
||||||
defer func() { stats.FilerRequestHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds()) }()
|
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
@@ -275,10 +271,6 @@ func (fs *FilerServer) uploadToVolumeServer(r *http.Request, u *url.URL, auth se
|
|||||||
// curl -X DELETE http://localhost:8888/path/to?recursive=true
|
// curl -X DELETE http://localhost:8888/path/to?recursive=true
|
||||||
func (fs *FilerServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
func (fs *FilerServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
stats.FilerRequestCounter.WithLabelValues("delete").Inc()
|
|
||||||
start := time.Now()
|
|
||||||
defer func() { stats.FilerRequestHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds()) }()
|
|
||||||
|
|
||||||
isRecursive := r.FormValue("recursive") == "true"
|
isRecursive := r.FormValue("recursive") == "true"
|
||||||
|
|
||||||
err := fs.filer.DeleteEntryMetaAndData(context.Background(), filer2.FullPath(r.URL.Path), isRecursive, true)
|
err := fs.filer.DeleteEntryMetaAndData(context.Background(), filer2.FullPath(r.URL.Path), isRecursive, true)
|
||||||
|
Reference in New Issue
Block a user