static

package
v1.4.14 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

static

Static File Handler from a filesystem. For example:

package main

import (
    "github.com/mutablelogic/go-server/pkg/httpserver"
)

func main() {
    static, err := static.Config{FS: os.DirFS("/"), DirListing: true, Prefix: ""}.New(context.Background())
    if err != nil {
        log.Fatal(err)
    }
    // ...
}

Passing DirListing as true will serve a basic directory listing for a filesystem. Otherwise, the handler will serve files from the directory FS only, and serve the index.html file is lieu of a directory, if it exists.

The configuration option Prefix will root the handler at a specific subdirectory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	FS         fs.FS  `hcl:"fs" description:"File system to serve"`
	DirPrefix  string `hcl:"prefix" description:"Directory to serve files from"`
	DirListing bool   `hcl:"dir" description:"Serve directory listings"`
	Path       string `hcl:"path" description:"host/path to serve files on"`
}

func (Config) Description

func (Config) Description() string

Description returns the description of the service

func (Config) Name

func (Config) Name() string

Name returns the name of the service

func (Config) New

func (c Config) New() (server.Task, error)

Create a new static handler from the configuration

Jump to

Keyboard shortcuts

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