asset
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).
常量
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
func ContentType(name string) stringContentType returns the media type for a file name, or "" if unknown (the caller then sniffs the content).
func DevProxy
func DevProxy(target string) http.HandlerDevProxy 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
func DevProxyWith(target string, o DevProxyOptions) http.HandlerDevProxyWith is DevProxy with options. The zero DevProxyOptions behaves like DevProxy.
func FS
func FS(fsys fs.FS, opts Options) http.HandlerFS 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
func FromEnv(fsys fs.FS, opts ...Options) http.HandlerFromEnv 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
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
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.