Skip to content

asset ​

go
import "github.com/tangoui/tango/asset"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package asset serves a front end to Tango surfaces: static files from an fs.FS, or, in development builds (-tags tango_dev, which tan dev adds), a reverse proxy to a dev server (Vite).

常量 ​

go
const DevURLEnv = "TANGO_DEV_URL"

DevURLEnv is the environment variable FromEnv checks in development builds (-tags tango_dev). Production builds, the default, ignore it.

函数 ​

func ContentType ​

go
func ContentType(name string) string

ContentType returns the media type for a file name, or "" if unknown (the caller then sniffs the content).

func DevProxy ​

go
func DevProxy(target string) http.Handler

DevProxy returns a reverse proxy to a dev server such as Vite (e.g. "http://localhost:5173"). WebSocket upgrades (HMR) are forwarded. The Host header is rewritten to the target so dev-server host checks pass. The target must be a loopback address (DevProxyWith can allow remote targets); a rejected target answers every request with 502.

func DevProxyWith ​

go
func DevProxyWith(target string, o DevProxyOptions) http.Handler

DevProxyWith is DevProxy with options. The zero DevProxyOptions behaves like DevProxy.

func FS ​

go
func FS(fsys fs.FS, opts Options) http.Handler

FS returns a handler serving files from fsys. Use fs.Sub to serve a subdirectory of an embed.FS. Directory listings are never produced, and paths that try to escape fsys are rejected.

func FromEnv ​

go
func FromEnv(fsys fs.FS, opts ...Options) http.Handler

FromEnv returns FS(fsys, opts), or, in development builds (-tags tango_dev, as tan dev builds) with $TANGO_DEV_URL set, DevProxy to that URL, which must be a loopback address. Production builds, the default, never read the variable. opts is optional; at most one is used.

类型 ​

DevProxyOptions ​

go
type DevProxyOptions struct {

	// AllowRemote lets the target be any host. By default only loopback
	// targets are accepted: localhost, 127.0.0.0/8 and ::1. (Android's adb
	// reverse and the iOS Simulator both reach the dev machine through
	// localhost.)
	AllowRemote bool
	// contains filtered or unexported fields
}

DevProxyOptions configures DevProxyWith.

Options ​

go
type Options struct {

	// Index is the file served for directory paths. Default "index.html".
	Index string
	// SPA serves the root index for unknown paths whose last segment has no
	// file extension (client-side routes such as /settings/profile).
	SPA bool
	// Headers are added to every successful response (e.g. a CSP).
	Headers http.Header
	// contains filtered or unexported fields
}

Options configures FS.

以 MIT 许可发布