indexfs

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2024 License: MIT, MIT Imports: 3 Imported by: 0

README

indexfs

Go lang index http.FileSystem

Installation

$ go get github.com/dolfly/httpfs/indexfs

Usage

import "github.com/dolfly/httpfs/indexfs"

Examples

IndexFS
package main

import (
	"github.com/dolfly/httpfs/indexfs"
	"net/http"
)

func main() {
	fs := indexfs.New(http.Dir("sites"), func(fs http.FileSystem, dir string) (http.File, error) {
		return indexfs.OpenIndex(fs, dir, "index.html", "index.htm")
	})

	http.Handle("/", http.FileServer(fs))
	http.ListenAndServe(":8080", nil)
}

Simple index webserver

indexes := indexfs.Indexes{"index.html", "index.htm"}
fs := indexfs.New(http.Dir("test"), indexes.DirIndex)
indexes := indexfs.Indexes{"index.html", "index.htm"}
fs := indexfs.New(http.Dir("test"), indexes.AutoIndex)

Author

gnue

License

MIT

Documentation

Overview

Go lang index http.FileSystem

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenIndex

func OpenIndex(fs http.FileSystem, dir string, indexes ...string) (http.File, error)

Types

type FileSystem

type FileSystem struct {
	// contains filtered or unexported fields
}

func New

func New(fs http.FileSystem, callback callbackFunc) *FileSystem

func (*FileSystem) HasIndex

func (idx *FileSystem) HasIndex(dir string) bool

func (*FileSystem) Open

func (idx *FileSystem) Open(name string) (http.File, error)

func (*FileSystem) OpenIndex

func (idx *FileSystem) OpenIndex(dir string) (http.File, error)

type Indexes

type Indexes []string

func (Indexes) AutoIndex

func (idx Indexes) AutoIndex(fs http.FileSystem, dir string) (http.File, error)

func (Indexes) DirIndex

func (idx Indexes) DirIndex(fs http.FileSystem, dir string) (http.File, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL