autobrr/internal/action/macros.go
Ludvig Lundgren 9eccc6b5e2
Feature: Exec action (#7)
* feat: implement exec action

* chore: change logs to trace

* refactor: extract from action
2021-08-15 02:40:38 +02:00

30 lines
472 B
Go

package action
import (
"bytes"
"text/template"
)
type Macro struct {
TorrentName string
TorrentPathName string
TorrentUrl string
}
// Parse takes a string and replaces valid vars
func (m Macro) Parse(text string) (string, error) {
// setup template
tmpl, err := template.New("macro").Parse(text)
if err != nil {
return "", err
}
var tpl bytes.Buffer
err = tmpl.Execute(&tpl, m)
if err != nil {
return "", err
}
return tpl.String(), nil
}