contrib icon indicating copy to clipboard operation
contrib copied to clipboard

static middleware doesn't work on Windows

Open iamxeph opened this issue 9 years ago • 2 comments

static middleware uses os.Stat which is not for Windows.

stats, err := os.Stat(name)

iamxeph avatar Apr 01 '16 13:04 iamxeph

Also

package main

import (
	"os"

	"github.com/gin-gonic/contrib/static"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()
	r.Use(static.Serve("/", static.LocalFile(os.Getenv("HOME"), true)))
	r.GET("/ping", func(c *gin.Context) {
		c.String(200, "test")
	})
	r.Run(":8080")
}

Return 404 page not found. But it works in Linux.

DeadNumbers avatar Apr 23 '17 05:04 DeadNumbers

I have no Windows machine to try this out; however, by looking at the Go source code, os.Stat() was patched a few times during 2016/2017 in order to provide better support under Windows and make it 'more compatible' with the routines calling os.Stat(). As such, this ought to be working fine (in 2023!). Can someone confirm that?

GwynethLlewelyn avatar Aug 30 '23 19:08 GwynethLlewelyn