static

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 15 Imported by: 0

README

Static Files Middleware

What it does

Serves files from a directory with options for index files, cache headers, directory behavior, and asset delivery.

How to implement

package main

import (
	"github.com/oarkflow/fh"
	"github.com/oarkflow/fh/mw/static"
)

func main() {
	app := fh.New()
	app.Use(static.New("./public"))

	app.Get("/", func(c fh.Ctx) error {
		return c.Status(fh.StatusOK).SendString("ok")
	})
}

Impact

Efficient for local static assets. Large file serving consumes disk/network I/O.

Ordering guidance

Mount on specific prefixes before fallback routes. Pair with compression, ETag, conditional requests, and cache headers.

Production considerations

Prevent directory traversal. Disable directory listing unless intentional. Use CDN/object storage for very high traffic assets.

Documentation

Overview

Package static serves files as route handlers with cache and download controls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(root string, config ...Config) fh.HandlerFunc

Types

type Config

type Config struct {
	Root         string
	Prefix       string
	Index        string
	Browse       bool
	ETag         bool
	LastModified bool
	CacheControl string
	MaxAge       time.Duration
	Immutable    bool
	SPAFallback  string
	Download     bool
}

Jump to

Keyboard shortcuts

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