Home / File/ fs.go — gin Source File

fs.go — gin Source File

Architecture documentation for fs.go, a go file in the gin codebase. 1 imports, 0 dependents.

File go GinCore Middleware 1 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  989161f2_e526_a83e_5efc_795d7f4d8548["fs.go"]
  08248871_dc00_f330_15ef_4a0fbf2bafbb["http"]
  989161f2_e526_a83e_5efc_795d7f4d8548 --> 08248871_dc00_f330_15ef_4a0fbf2bafbb
  style 989161f2_e526_a83e_5efc_795d7f4d8548 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package gin

import (
	"net/http"
	"os"
)

// OnlyFilesFS implements an http.FileSystem without `Readdir` functionality.
type OnlyFilesFS struct {
	FileSystem http.FileSystem
}

// Open passes `Open` to the upstream implementation without `Readdir` functionality.
func (o OnlyFilesFS) Open(name string) (http.File, error) {
	f, err := o.FileSystem.Open(name)
	if err != nil {
		return nil, err
	}

	return neutralizedReaddirFile{f}, nil
}

// neutralizedReaddirFile wraps http.File with a specific implementation of `Readdir`.
type neutralizedReaddirFile struct {
	http.File
}

// Readdir overrides the http.File default implementation and always returns nil.
func (n neutralizedReaddirFile) Readdir(_ int) ([]os.FileInfo, error) {
	// this disables directory listing
	return nil, nil
}

// Dir returns an http.FileSystem that can be used by http.FileServer().
// It is used internally in router.Static().
// if listDirectory == true, then it works the same as http.Dir(),
// otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.
func Dir(root string, listDirectory bool) http.FileSystem {
	fs := http.Dir(root)

	if listDirectory {
		return fs
	}

	return &OnlyFilesFS{FileSystem: fs}
}

Domain

Subdomains

Functions

Dependencies

  • http

Frequently Asked Questions

What does fs.go do?
fs.go is a source file in the gin codebase, written in go. It belongs to the GinCore domain, Middleware subdomain.
What functions are defined in fs.go?
fs.go defines 1 function(s): Dir.
What does fs.go depend on?
fs.go imports 1 module(s): http.
Where is fs.go in the architecture?
fs.go is located at fs.go (domain: GinCore, subdomain: Middleware).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free