Documentation ¶
Index ¶
- Variables
- type Service
- func (s *Service) AssetURL(pluginID, pluginVersion, assetPath string) (string, error)
- func (s *Service) BaseURL() (string, error)
- func (s *Service) IsEnabled() bool
- func (s *Service) NewCDNURLConstructor(pluginID, pluginVersion string) URLConstructor
- func (s *Service) PluginSupported(pluginID string) bool
- func (s *Service) SystemJSAssetPath(pluginID, pluginVersion, assetPath string) (string, error)
- type URLConstructor
Constants ¶
This section is empty.
Variables ¶
var ErrPluginNotCDN = errors.New("plugin is not a cdn plugin")
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides methods for the plugins CDN.
func ProvideService ¶
func (*Service) AssetURL ¶
AssetURL returns the URL of a CDN asset for a CDN plugin. If the specified plugin is not a CDN plugin, it returns ErrPluginNotCDN.
func (*Service) BaseURL ¶
BaseURL returns the absolute base URL of the plugins CDN. This is the "fixed" part of the URL (protocol + host + root url). If the plugins CDN is disabled, it returns an empty string.
func (*Service) NewCDNURLConstructor ¶
func (s *Service) NewCDNURLConstructor(pluginID, pluginVersion string) URLConstructor
NewCDNURLConstructor returns a new URLConstructor for the provided plugin id and version. The CDN should be enabled for the plugin, otherwise the returned URLConstructor will have and invalid base url.
func (*Service) PluginSupported ¶
PluginSupported returns true if the CDN is enabled in the config and if the specified plugin ID has CDN enabled.
func (*Service) SystemJSAssetPath ¶
SystemJSAssetPath returns a system-js path for the specified asset on the plugins CDN. The returned path will follow the template specified in systemJSCDNURLTemplate. If assetPath is an empty string, the base path for the plugin is returned.
type URLConstructor ¶
type URLConstructor struct {
// contains filtered or unexported fields
}
URLConstructor is a struct that can build CDN URLs for plugins on a remote CDN.
func (URLConstructor) Path ¶
func (c URLConstructor) Path(assetPath string) (*url.URL, error)
Path returns a new *url.URL that points to an asset file for the CDN, plugin and plugin version specified by the current URLConstructor.
c.cdnURLTemplate is used to build the string, the following substitutions are performed in it:
- {id} -> plugin id
- {version} -> plugin version
- {assetPath} -> assetPath
The asset Path is sanitized via path.Clean (double slashes are removed, "../" is resolved, etc).
The returned URL will be for a file, so it won't have a trailing slash.
func (URLConstructor) StringPath ¶
func (c URLConstructor) StringPath(assetPath string) (string, error)
StringPath is like Path, but it returns the absolute URL as a string rather than *url.URL.