assets

package
v1.18.2-rc.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package assets hold utilities for serving static assets.

The actual assets live in auto subpackages instead of here, because the set of assets varies per program.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MimeTypeForFile

func MimeTypeForFile(file string) string

MimeTypeForFile returns the appropriate MIME type for an asset, based on the filename.

We use a built in table of the common types since the system TypeByExtension might be unreliable. But if we don't know, we delegate to the system. All our text files are in UTF-8.

func Serve

func Serve(w http.ResponseWriter, r *http.Request, asset Asset)

Serve writes a gzipped asset to w.

Types

type Asset

type Asset struct {
	Content  string // Contents of asset, possibly gzipped.
	Gzipped  bool
	Length   int       // Length of (decompressed) Content.
	Filename string    // Original filename, determines Content-Type.
	Modified time.Time // Determines ETag and Last-Modified.
}

An Asset is an embedded file to be served over HTTP.

Jump to

Keyboard shortcuts

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