2019-05-27 01:03:40 +08:00
|
|
|
//go:generate go run assets_generate.go
|
|
|
|
// The "go:generate" directive compiles static assets by running assets_generate.go
|
|
|
|
|
|
|
|
package data
|
2019-09-16 00:44:28 +08:00
|
|
|
|
|
|
|
import (
|
2021-11-04 18:12:57 +08:00
|
|
|
"fmt"
|
2019-09-16 00:44:28 +08:00
|
|
|
"io/ioutil"
|
|
|
|
"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 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("get template open: %w", err)
|
2019-09-16 00:44:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
defer fs.CheckClose(templateFile, &err)
|
|
|
|
|
|
|
|
templateBytes, err := ioutil.ReadAll(templateFile)
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("get template read: %w", err)
|
2019-09-16 00:44:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var templateString = string(templateBytes)
|
|
|
|
|
|
|
|
tpl, err = template.New("rootDesc").Parse(templateString)
|
|
|
|
if err != nil {
|
2021-11-04 18:12:57 +08:00
|
|
|
return nil, fmt.Errorf("get template parse: %w", err)
|
2019-09-16 00:44:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|