Debian Codegraph @

pkg/services/standard/standard_templater.go

raw symbols SCIP
1 package standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src . fmt/"
5 "osscip-go gomod github.com/golang/go/src . os/"
6 "text/templatescip-go gomod github.com/golang/go/src . `text/template`/"
7 )
8
9 // Templater is the standard implementation of ApplyTemplate using the "text/template" library.
10 type Templaterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater# struct {
11 templatesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#templates. map[string]*templatescip-go gomod github.com/golang/go/src . `text/template`/.Templatescip-go gomod github.com/golang/go/src . `text/template`/Template#
12 }
13
14 // GetTemplate attempts to retrieve the template identified with id.
15 func (t *Templaterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#) GetTemplatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#GetTemplate().(id string) (*templatescip-go gomod github.com/golang/go/src . `text/template`/.Templatescip-go gomod github.com/golang/go/src . `text/template`/Template#, bool) {
16 tpl, found := t.templatesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#templates.[id]
17
18 return tpl, found
19 }
20
21 // SetTemplateFile creates a new template from the file and assigns it the id.
22 func (t *Templaterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#) SetTemplateFilescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#SetTemplateFile().(templateID, file string) error {
23 bytes, err := osscip-go gomod github.com/golang/go/src . os/.ReadFilescip-go gomod github.com/golang/go/src . os/ReadFile().(file)
24 if err != nil {
25 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("reading template file %q for ID %q: %w", file, templateID, err)
26 }
27
28 return t.SetTemplateStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#SetTemplateString().(templateID, string(bytes))
29 }
30
31 // SetTemplateString creates a new template from the body and assigns it the id.
32 func (t *Templaterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#) SetTemplateStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#SetTemplateString().(templateID, body string) error {
33 tpl, err := templatescip-go gomod github.com/golang/go/src . `text/template`/.Newscip-go gomod github.com/golang/go/src . `text/template`/New().("").Parsescip-go gomod github.com/golang/go/src . `text/template`/Template#Parse().(body)
34 if err != nil {
35 return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("parsing template string for ID %q: %w", templateID, err)
36 }
37
38 if t.templatesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#templates. == nil {
39 t.templatesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#templates. = make(map[string]*templatescip-go gomod github.com/golang/go/src . `text/template`/.Templatescip-go gomod github.com/golang/go/src . `text/template`/Template#, 1)
40 }
41
42 t.templatesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/Templater#templates.[templateID] = tpl
43
44 return nil
45 }