mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 08:37:10 +08:00
Add example in README.
Use `map[string][]byte` instead of `map[string]string`.
This commit is contained in:
@@ -2,6 +2,7 @@ package s3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
@@ -10,9 +11,11 @@ import (
|
||||
// Additional methods for S3, but not required by gofiber Storage interface.
|
||||
|
||||
// SetWithChecksum sets key with value and checksum.
|
||||
// Key of `checksum` map is algorithm in upper cases like `CRC32`, `CRC32C`,
|
||||
// `SHA1`, `SHA256`, value is the checksum.
|
||||
func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[string]string) error {
|
||||
// Key of `checksum` map is algorithm in upper cases, value is the checksum.
|
||||
// Currently only 4 algorithm are supported: `CRC32`, `CRC32C`, `SHA1`, `SHA256`.
|
||||
//
|
||||
// For more information, see [PutObjectInput](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#PutObjectInput).
|
||||
func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[string][]byte) error {
|
||||
if len(key) <= 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -29,13 +32,15 @@ func (s *Storage) SetWithChecksum(key string, val []byte, checksum map[string]st
|
||||
for alg, sum := range checksum {
|
||||
switch alg {
|
||||
case "CRC32":
|
||||
poi.ChecksumCRC32 = aws.String(sum)
|
||||
poi.ChecksumCRC32 = aws.String(fmt.Sprintf("%x", sum))
|
||||
case "CRC32C":
|
||||
poi.ChecksumCRC32C = aws.String(sum)
|
||||
poi.ChecksumCRC32C = aws.String(fmt.Sprintf("%x", sum))
|
||||
case "SHA1":
|
||||
poi.ChecksumSHA1 = aws.String(sum)
|
||||
poi.ChecksumSHA1 = aws.String(fmt.Sprintf("%x", sum))
|
||||
case "SHA256":
|
||||
poi.ChecksumSHA256 = aws.String(sum)
|
||||
poi.ChecksumSHA256 = aws.String(fmt.Sprintf("%x", sum))
|
||||
default:
|
||||
return fmt.Errorf("invalid checksum algorithm: %s", alg)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user