To be able to get same ETags on different servers.
github.com/dustin/go-humanize v1.0.1
github.com/klauspost/compress v1.17.7
golang.org/x/net v0.19.0
- golang.org/x/sys v0.15.0
)
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
-golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
-golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
// Highly-customizable HTTP, HTTP/2, HTTPS server
package godlighty
-const Version = "godlighty/0.6.0"
+const Version = "godlighty/0.7.0"
var BindAddr string
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
- etag, err = ctimeETag(fd)
+ etag, err = mtimeETag(fd)
fd.Close()
if err != nil {
printErr(http.StatusInternalServerError, err)
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
- etag, err = ctimeETag(fd)
+ etag, err = mtimeETag(fd)
if err != nil {
printErr(http.StatusInternalServerError, err)
http.Error(w, "internal error", http.StatusInternalServerError)
"encoding/base64"
"encoding/binary"
"os"
-
- "golang.org/x/sys/unix"
)
-func ctimeETag(fd *os.File) (string, error) {
- var stat unix.Stat_t
- err := unix.Fstat(int(fd.Fd()), &stat)
+func mtimeETag(fd *os.File) (string, error) {
+ fi, err := fd.Stat()
if err != nil {
return "", err
}
- sec, nsec := stat.Ctim.Unix()
- buf := make([]byte, 8*2)
- binary.BigEndian.PutUint64(buf[:8], uint64(sec))
- binary.BigEndian.PutUint64(buf[8:], uint64(nsec))
+ mtime := fi.ModTime()
+ buf := make([]byte, 8*3)
+ binary.BigEndian.PutUint64(buf[:8], uint64(fi.Size()))
+ binary.BigEndian.PutUint64(buf[8:16], uint64(mtime.Unix()))
+ binary.BigEndian.PutUint64(buf[16:], uint64(mtime.Nanosecond()))
return `"` + base64.RawURLEncoding.EncodeToString(buf) + `"`, nil
}