package appimport ()// ResourceResolver is an interface that defines the method to resolve// resources from /web/ path to its full URL or file location.typeResourceResolverinterface {// Resolve takes a resource path and returns its resolved URL or file path.Resolve(string) string}// LocalDir returns a ResourceResolver for local resources. It resolves paths// starting with /web/ to their full file path based on the specified local directory.// This resolver is suitable for handling resources stored in the local filesystem.func ( string) ResourceResolver { = strings.TrimRight(, "/")returnlocalResourceResolver{Handler: http.FileServer(http.Dir()),directory: , }}type localResourceResolver struct {http.Handler directory string}func ( localResourceResolver) ( string) string {if == "/" || == "" {return"/" }ifremoteLocation() || !webLocation() {return }return .directory + "/" + strings.Trim(, "/")}// RemoteBucket returns a ResourceResolver for remote resources. It resolves// paths starting with /web/ to their full URL based on the specified remote URL,// such as a cloud storage bucket. This resolver is ideal for resources hosted// remotely.func ( string) ResourceResolver {returnremoteResourceResolver{url: strings.Trim(, "/"), }}type remoteResourceResolver struct { url string}func ( remoteResourceResolver) ( string) string {if == "/" || == "" {return"/" }ifremoteLocation() || !webLocation() {return }return .url + "/" + strings.Trim(, "/")}// PrefixedLocation returns a ResourceResolver that resolves resources with// a specified prefix. This resolver prepends the given prefix to resource paths,// which is particularly useful when serving resources from a specific directory// or URL path.//// The prefix is added to the beginning of the resource path, effectively// modifying the path from which the resources are served.//// For example, if the prefix is "/assets", a resource path like "/web/main.css"// will be resolved as "/assets/web/main.css".func ( string) ResourceResolver {returnprefixedResourceResolver{prefix: , }}type prefixedResourceResolver struct {localResourceResolver prefix string}func ( prefixedResourceResolver) ( string) string {ifremoteLocation() {return } = .localResourceResolver.Resolve()if == "/" {returnstrings.TrimRight(.prefix, "/") }returnstrings.TrimRight(.prefix, "/") + }// GitHubPages returns a ResourceResolver tailored for serving resources// from a GitHub Pages site. It creates a resolver with a prefix matching// the given repository name. This is particularly useful when hosting// a go-app project on GitHub Pages, where resources need to be served// from a repository-specific subpath.//// For example, if the repository name is "myapp", the resources will be// served from paths starting with "/myapp/web/".func ( string) ResourceResolver {returnPrefixedLocation("/" + strings.Trim(, "/"))}func clientResourceResolver( string) func(string) string {returnfunc( string) string {ifremoteLocation() || !webLocation() {return } = strings.Trim(, "/")return + "/" + strings.TrimPrefix(, "web/") }}func resolveOGResource( string, string) string {ifremoteLocation() {return }return"https://" + + strings.TrimRight("/"+strings.Trim(, "/"), "/")}func remoteLocation( string) bool {returnstrings.HasPrefix(, "https://") ||strings.HasPrefix(, "http://")}func webLocation( string) bool {returnstrings.HasPrefix(, "/web/") || == "/web" ||strings.HasPrefix(, "web/") || == "web"}// ProxyResource is a proxy descriptor that maps a given resource to an URL// path.typeProxyResourcestruct {// The URL path from where a static resource is accessible. Path string// The path of the static resource that is proxied. It must start with // "/web/". ResourcePath string}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.