2022-08-28 11:21:57 +00:00
|
|
|
// Package data provides utilities for DLNA server.
|
2019-05-26 17:03:40 +00:00
|
|
|
// The "go:generate" directive compiles static assets by running assets_generate.go
|
2022-08-28 11:21:57 +00:00
|
|
|
//
|
|
|
|
//go:generate go run assets_generate.go
|
2019-05-26 17:03:40 +00:00
|
|
|
package data
|
2019-09-15 16:44:28 +00:00
|
|
|
|
|
|
|
import (
|
2021-11-04 10:12:57 +00:00
|
|
|
"fmt"
|
2022-08-20 14:38:02 +00:00
|
|
|
"io"
|
2019-09-15 16:44:28 +00:00
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetTemplate returns the rootDesc XML template
|
|
|
|
func GetTemplate() (tpl *template.Template, err error) {
|
|
|
|
templateFile, err := Assets.Open("rootDesc.xml.tmpl")
|
|
|
|
if err != nil {
|
2021-11-04 10:12:57 +00:00
|
|
|
return nil, fmt.Errorf("get template open: %w", err)
|
2019-09-15 16:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defer fs.CheckClose(templateFile, &err)
|
|
|
|
|
2022-08-20 14:38:02 +00:00
|
|
|
templateBytes, err := io.ReadAll(templateFile)
|
2019-09-15 16:44:28 +00:00
|
|
|
if err != nil {
|
2021-11-04 10:12:57 +00:00
|
|
|
return nil, fmt.Errorf("get template read: %w", err)
|
2019-09-15 16:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var templateString = string(templateBytes)
|
|
|
|
|
|
|
|
tpl, err = template.New("rootDesc").Parse(templateString)
|
|
|
|
if err != nil {
|
2021-11-04 10:12:57 +00:00
|
|
|
return nil, fmt.Errorf("get template parse: %w", err)
|
2019-09-15 16:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|