2023-05-17 09:53:13 +00:00
|
|
|
package template
|
2023-05-15 09:25:01 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-07-05 08:54:31 +00:00
|
|
|
"net/url"
|
2023-05-15 09:25:01 +00:00
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
2023-05-17 13:33:04 +00:00
|
|
|
var errSkipThisFile = errors.New("skip generating this file")
|
2023-05-15 09:25:01 +00:00
|
|
|
|
|
|
|
var HelperFuncs = template.FuncMap{
|
2023-07-04 14:01:47 +00:00
|
|
|
// Text template execution returns the error only if it's the second return
|
|
|
|
// value from a function: https://pkg.go.dev/text/template#hdr-Pipelines
|
2023-07-04 13:59:25 +00:00
|
|
|
"skipThisFile": func() (any, error) {
|
|
|
|
return nil, errSkipThisFile
|
2023-05-15 09:25:01 +00:00
|
|
|
},
|
2023-07-05 08:54:31 +00:00
|
|
|
"urlParse": func(rawUrl string) (*url.URL, error) {
|
|
|
|
return url.Parse(rawUrl)
|
|
|
|
},
|
2023-05-15 09:25:01 +00:00
|
|
|
}
|