refactoring
This commit is contained in:
@@ -9,8 +9,32 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
||||||
"github.com/chrislusf/seaweedfs/weed/util"
|
"github.com/chrislusf/seaweedfs/weed/util"
|
||||||
|
"bytes"
|
||||||
|
"encoding/xml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type mimeType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
mimeNone mimeType = ""
|
||||||
|
mimeJSON mimeType = "application/json"
|
||||||
|
mimeXML mimeType = "application/xml"
|
||||||
|
)
|
||||||
|
|
||||||
|
func setCommonHeaders(w http.ResponseWriter) {
|
||||||
|
w.Header().Set("x-amz-request-id", fmt.Sprintf("%d", time.Now().UnixNano()))
|
||||||
|
w.Header().Set("Accept-Ranges", "bytes")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encodes the response headers into XML format.
|
||||||
|
func encodeResponse(response interface{}) []byte {
|
||||||
|
var bytesBuffer bytes.Buffer
|
||||||
|
bytesBuffer.WriteString(xml.Header)
|
||||||
|
e := xml.NewEncoder(&bytesBuffer)
|
||||||
|
e.Encode(response)
|
||||||
|
return bytesBuffer.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
func newContext(r *http.Request, api string) context.Context {
|
func newContext(r *http.Request, api string) context.Context {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
return context.WithValue(context.Background(), "bucket", vars["bucket"])
|
return context.WithValue(context.Background(), "bucket", vars["bucket"])
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
package s3api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/xml"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type mimeType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
mimeNone mimeType = ""
|
|
||||||
mimeJSON mimeType = "application/json"
|
|
||||||
mimeXML mimeType = "application/xml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func setCommonHeaders(w http.ResponseWriter) {
|
|
||||||
w.Header().Set("x-amz-request-id", fmt.Sprintf("%d", time.Now().UnixNano()))
|
|
||||||
w.Header().Set("Accept-Ranges", "bytes")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encodes the response headers into XML format.
|
|
||||||
func encodeResponse(response interface{}) []byte {
|
|
||||||
var bytesBuffer bytes.Buffer
|
|
||||||
bytesBuffer.WriteString(xml.Header)
|
|
||||||
e := xml.NewEncoder(&bytesBuffer)
|
|
||||||
e.Encode(response)
|
|
||||||
return bytesBuffer.Bytes()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user