-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack.go
35 lines (26 loc) · 931 Bytes
/
slack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package helper
import (
"embed"
"encoding/json"
"github.com/pkg/errors"
)
func GetTemplateFS(embedFS embed.FS, file string, args, destStruct interface{}) error {
templateValue, err := ParseTemplate(embedFS, file, args)
if err != nil {
return errors.Wrap(err, "phastos.go.helper.slack.GetTemplate.ParseTemplate")
}
if err = json.Unmarshal(templateValue.Bytes(), destStruct); err != nil {
return errors.Wrap(err, "phastos.go.third_party.slack.templating.GetTemplate.UnmarshalToStruct")
}
return nil
}
func GetTemplate(file string, args, destStruct interface{}) error {
templateValue, err := ParseFileTemplate(file, args)
if err != nil {
return errors.Wrap(err, "phastos.go.helper.slack.GetTemplate.ParseTemplate")
}
if err = json.Unmarshal(templateValue.Bytes(), destStruct); err != nil {
return errors.Wrap(err, "phastos.go.third_party.slack.templating.GetTemplate.UnmarshalToStruct")
}
return nil
}