Browse Source

go fmt

pull/1650/head
Chris Lu 4 years ago
parent
commit
0da7ecfd29
  1. 2
      weed/filer/filer_conf_test.go
  2. 40
      weed/operation/needle_parse_test.go
  3. 4
      weed/server/volume_server_handlers_read.go
  4. 2
      weed/shell/command_fs_configure.go
  5. 10
      weed/storage/needle/needle_parse_upload.go
  6. 7
      weed/util/compression.go

2
weed/filer/filer_conf_test.go

@ -22,7 +22,7 @@ func TestFilerConf(t *testing.T) {
}, },
{ {
LocationPrefix: "/buckets/", LocationPrefix: "/buckets/",
Replication: "001",
Replication: "001",
}, },
}} }}
fc.doLoadConf(conf) fc.doLoadConf(conf)

40
weed/operation/needle_parse_test.go

@ -76,29 +76,29 @@ func TestCreateNeedleFromRequest(t *testing.T) {
} }
/* /*
{
mc.needleHandling = func(n *needle.Needle, originalSize int, err error) {
assert.Equal(t, nil, err, "upload: %v", err)
assert.Equal(t, "text/plain", string(n.Mime), "mime detection failed: %v", string(n.Mime))
assert.Equal(t, true, n.IsCompressed(), "this should be compressed")
assert.Equal(t, true, util.IsZstdContent(n.Data), "this should be zstd")
fmt.Printf("needle: %v, dataSize:%d originalSize:%d\n", n, len(n.Data), originalSize)
{
mc.needleHandling = func(n *needle.Needle, originalSize int, err error) {
assert.Equal(t, nil, err, "upload: %v", err)
assert.Equal(t, "text/plain", string(n.Mime), "mime detection failed: %v", string(n.Mime))
assert.Equal(t, true, n.IsCompressed(), "this should be compressed")
assert.Equal(t, true, util.IsZstdContent(n.Data), "this should be zstd")
fmt.Printf("needle: %v, dataSize:%d originalSize:%d\n", n, len(n.Data), originalSize)
}
zstdData, _ := util.ZstdData([]byte(textContent))
Upload("http://localhost:8080/389,0f084d17353afda0", "t.txt", false, bytes.NewReader(zstdData), true, "text/plain", nil, "")
} }
zstdData, _ := util.ZstdData([]byte(textContent))
Upload("http://localhost:8080/389,0f084d17353afda0", "t.txt", false, bytes.NewReader(zstdData), true, "text/plain", nil, "")
}
{
mc.needleHandling = func(n *needle.Needle, originalSize int, err error) {
assert.Equal(t, nil, err, "upload: %v", err)
assert.Equal(t, "application/zstd", string(n.Mime), "mime detection failed: %v", string(n.Mime))
assert.Equal(t, false, n.IsCompressed(), "this should not be compressed")
assert.Equal(t, true, util.IsZstdContent(n.Data), "this should still be zstd")
fmt.Printf("needle: %v, dataSize:%d originalSize:%d\n", n, len(n.Data), originalSize)
{
mc.needleHandling = func(n *needle.Needle, originalSize int, err error) {
assert.Equal(t, nil, err, "upload: %v", err)
assert.Equal(t, "application/zstd", string(n.Mime), "mime detection failed: %v", string(n.Mime))
assert.Equal(t, false, n.IsCompressed(), "this should not be compressed")
assert.Equal(t, true, util.IsZstdContent(n.Data), "this should still be zstd")
fmt.Printf("needle: %v, dataSize:%d originalSize:%d\n", n, len(n.Data), originalSize)
}
zstdData, _ := util.ZstdData([]byte(textContent))
Upload("http://localhost:8080/389,0f084d17353afda0", "t.txt", false, bytes.NewReader(zstdData), false, "application/zstd", nil, "")
} }
zstdData, _ := util.ZstdData([]byte(textContent))
Upload("http://localhost:8080/389,0f084d17353afda0", "t.txt", false, bytes.NewReader(zstdData), false, "application/zstd", nil, "")
}
*/ */
} }

4
weed/server/volume_server_handlers_read.go

@ -159,8 +159,8 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
if n.Data, err = util.DecompressData(n.Data); err != nil { if n.Data, err = util.DecompressData(n.Data); err != nil {
glog.V(0).Infoln("ungzip error:", err, r.URL.Path) glog.V(0).Infoln("ungzip error:", err, r.URL.Path)
} }
// } else if strings.Contains(r.Header.Get("Accept-Encoding"), "zstd") && util.IsZstdContent(n.Data) {
// w.Header().Set("Content-Encoding", "zstd")
// } else if strings.Contains(r.Header.Get("Accept-Encoding"), "zstd") && util.IsZstdContent(n.Data) {
// w.Header().Set("Content-Encoding", "zstd")
} else if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") && util.IsGzippedContent(n.Data) { } else if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") && util.IsGzippedContent(n.Data) {
w.Header().Set("Content-Encoding", "gzip") w.Header().Set("Content-Encoding", "gzip")
} else { } else {

2
weed/shell/command_fs_configure.go

@ -107,7 +107,7 @@ func (c *commandFsConfigure) Do(args []string, commandEnv *CommandEnv, writer io
if err != nil { if err != nil {
return fmt.Errorf("parse replication %s: %v", *replication, err) return fmt.Errorf("parse replication %s: %v", *replication, err)
} }
if *volumeGrowthCount % rp.GetCopyCount() != 0 {
if *volumeGrowthCount%rp.GetCopyCount() != 0 {
return fmt.Errorf("volumeGrowthCount %d should be devided by replication copy count %d", *volumeGrowthCount, rp.GetCopyCount()) return fmt.Errorf("volumeGrowthCount %d should be devided by replication copy count %d", *volumeGrowthCount, rp.GetCopyCount())
} }
} }

10
weed/storage/needle/needle_parse_upload.go

@ -18,11 +18,11 @@ import (
) )
type ParsedUpload struct { type ParsedUpload struct {
FileName string
Data []byte
MimeType string
PairMap map[string]string
IsGzipped bool
FileName string
Data []byte
MimeType string
PairMap map[string]string
IsGzipped bool
// IsZstd bool // IsZstd bool
OriginalDataSize int OriginalDataSize int
ModifiedTime uint64 ModifiedTime uint64

7
weed/util/compression.go

@ -55,15 +55,14 @@ func GzipData(input []byte) ([]byte, error) {
return buf.Bytes(), nil return buf.Bytes(), nil
} }
func DecompressData(input []byte) ([]byte, error) { func DecompressData(input []byte) ([]byte, error) {
if IsGzippedContent(input) { if IsGzippedContent(input) {
return ungzipData(input) return ungzipData(input)
} }
/* /*
if IsZstdContent(input) {
return unzstdData(input)
}
if IsZstdContent(input) {
return unzstdData(input)
}
*/ */
return input, UnsupportedCompression return input, UnsupportedCompression
} }

Loading…
Cancel
Save