markbates / pkger

Embed static files in Go binaries (replacement for gobuffalo/packr)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: implement Stat on the output of Dir

sagikazarmark opened this issue · comments

I use pkger in a project where I need to serve static files, but I need to manually handle 404, so I started writing the following:

dir := pkger.Dir("/static")
fs := http.FileServer(dir)

handler := func(w http.ResponseWriter, r *http.Request) {
    s, err := dir.Stat("something")
    if err != nil /*or not found*/ {
        // handle 404
    }

    fs.ServeHTTP(w, r)
}

But returned Dir doesn't implement the Stat method. Using Dir would actually be a nice way to handle file prefixes, so we wouldn't have to repeat them and just pass around the output of Dir. (Could even write an interface for that)