From 25d46611f14f5b8317a573f32f380a9c6503d03f Mon Sep 17 00:00:00 2001 From: Cocoa <0xbbc@0xbbc.com> Date: Wed, 26 Feb 2020 02:04:50 +0800 Subject: [PATCH] Copy `ImgName` before invoke c.SendFile since `stripTrailingSlashes` in fasthttp will change the content of ctx.URI().Path(), which was once obtained as `ImgPath := c.Path()` Signed-off-by: Cocoa <0xbbc@0xbbc.com> --- webp-server.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webp-server.go b/webp-server.go index caa7785..6411320 100644 --- a/webp-server.go +++ b/webp-server.go @@ -169,11 +169,13 @@ func main() { if err != nil { fmt.Println(err) } + + ImgNameCopy := string([]byte(ImgName)) c.SendFile(WebpAbsolutePath) // /home/webp_server/exhaust/path/to/tsuki.jpg.1582558100.webp <- older ones will be removed // /home/webp_server/exhaust/path/to/tsuki.jpg.1582558990.webp <- keep the latest one - WebpCachedImgPath := path.Clean(fmt.Sprintf("%s/exhaust%s/%s.*.webp", CurrentPath, DirPath, ImgName)) + WebpCachedImgPath := path.Clean(fmt.Sprintf("%s/exhaust%s/%s.*.webp", CurrentPath, DirPath, ImgNameCopy)) matches, err := filepath.Glob(WebpCachedImgPath) if err != nil { fmt.Println(err.Error())