It won't serve index.html file by default like in case of 
neuteredReaddirFile

On Wednesday, March 16, 2016 at 10:38:22 AM UTC+5:30, George Armhold wrote:
>
> I've settled on the following, which has the added benefit of returning 404 
> for directories.
>
>
> Corrections appreciated.
>
>
>
> type justFilesFilesystem struct {
>    Fs http.FileSystem
> }
>
> func (fs justFilesFilesystem) Open(name string) (http.File, error) {
>    f, err := fs.Fs.Open(name)
>    if err != nil {
>       return nil, err
>    }
>
>    stat, err := f.Stat()
>    if stat.IsDir() {
>       return nil, os.ErrNotExist
>    }
>
>    return f, nil
> }
>
>
> On Tuesday, October 9, 2012 at 10:52:46 AM UTC-4, Brad Fitzpatrick wrote:
>>
>> package main
>>
>> import (
>> "net/http"
>> "os"
>> )
>>
>> type justFilesFilesystem struct {
>> fs http.FileSystem
>> }
>>
>> func (fs justFilesFilesystem) Open(name string) (http.File, error) {
>> f, err := fs.fs.Open(name)
>> if err != nil {
>> return nil, err
>> }
>> return neuteredReaddirFile{f}, nil
>> }
>>
>> type neuteredReaddirFile struct {
>> http.File
>> }
>>
>> func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
>> return nil, nil
>> }
>>
>> func main() {
>> fs := justFilesFilesystem{http.Dir("/tmp/")}
>> http.ListenAndServe(":8080", http.FileServer(fs))
>> }
>>
>>
>> On Tue, Oct 9, 2012 at 12:50 AM, Trung Pham <tr...@phamcom.com> wrote:
>>
>>> Hi,
>>>
>>> I'm using the built in static file http.FileServer.
>>> Do you know if there is an easy way to disable the directory listing? 
>>> Just simply return a 404.
>>>
>>> Thanks.
>>>
>>> -- 
>>>  
>>>  
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to