The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/plugins/frontend_plugin.go

48 lines
1002 B

package plugins
import (
"net/url"
"path"
)
type FrontendPluginBase struct {
PluginBase
Module string `json:"module"`
StaticRoot string `json:"staticRoot"`
}
func (fp *FrontendPluginBase) initFrontendPlugin() {
if fp.StaticRoot != "" {
StaticRoutes = append(StaticRoutes, &PluginStaticRoute{
Directory: fp.StaticRoot,
PluginId: fp.Id,
})
}
fp.Info.Logos.Small = evalRelativePluginUrlPath(fp.Info.Logos.Small, fp.Id)
fp.Info.Logos.Large = evalRelativePluginUrlPath(fp.Info.Logos.Large, fp.Id)
fp.handleModuleDefaults()
}
func (fp *FrontendPluginBase) handleModuleDefaults() {
if fp.Module != "" {
return
}
if fp.StaticRoot != "" {
fp.Module = path.Join("plugins", fp.Type, fp.Id, "module")
return
}
fp.Module = path.Join("app/plugins", fp.Type, fp.Id, "module")
}
func evalRelativePluginUrlPath(pathStr string, pluginId string) string {
u, _ := url.Parse(pathStr)
if u.IsAbs() {
return pathStr
}
return path.Join("public/plugins", pluginId, pathStr)
}