chore: support ETag for providers

This commit is contained in:
wwqgtxx
2024-09-22 11:36:31 +08:00
parent 223eae0e06
commit 5d242510c8
7 changed files with 201 additions and 105 deletions

29
constant/provider/hash.go Normal file
View File

@@ -0,0 +1,29 @@
package provider
import (
"bytes"
"crypto/md5"
)
type HashType [md5.Size]byte // MD5
func MakeHash(data []byte) HashType {
return md5.Sum(data)
}
func (h HashType) Equal(hash HashType) bool {
return h == hash
}
func (h HashType) EqualBytes(hashBytes []byte) bool {
return bytes.Equal(hashBytes, h[:])
}
func (h HashType) Bytes() []byte {
return h[:]
}
func (h HashType) IsValid() bool {
var zero HashType
return h != zero
}

View File

@@ -32,7 +32,7 @@ func (v VehicleType) String() string {
}
type Vehicle interface {
Read(ctx context.Context) ([]byte, error)
Read(ctx context.Context, oldHash HashType) (buf []byte, hash HashType, err error)
Path() string
Url() string
Proxy() string