github.com/wangkui503/aero@v1.0.0/ETag.go (about)

     1  package aero
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/OneOfOne/xxhash"
     7  )
     8  
     9  // ETag produces a hash for the given slice of bytes.
    10  // It is the same hash that Aero uses for its ETag header.
    11  func ETag(b []byte) string {
    12  	h := xxhash.NewS64(0)
    13  	h.Write(b)
    14  	return strconv.FormatUint(h.Sum64(), 16)
    15  }
    16  
    17  // ETagString produces a hash for the given string.
    18  // It is the same hash that Aero uses for its ETag header.
    19  func ETagString(b string) string {
    20  	h := xxhash.NewS64(0)
    21  	h.WriteString(b)
    22  	return strconv.FormatUint(h.Sum64(), 16)
    23  }