-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.go
53 lines (44 loc) · 1.25 KB
/
template.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package domain
import (
"context"
"time"
"github.com/deepcode-ai/hermes/templater"
)
type TemplateType string
const (
TemplateTypeText TemplateType = "text"
TemplateTypeMustache TemplateType = "mustache"
TemplateTypeGoTemplate TemplateType = "gotmpl"
)
type Template struct {
ID string `json:"id,omitempty"`
Pattern string `json:"pattern,omitempty"`
Type TemplateType `json:"type,omitempty"`
DateCreated time.Time `json:"date_created,omitempty"`
DateUpdated time.Time `json:"date_updated,omitempty"`
SupportedProviders []ProviderType `json:"supported_providers"`
}
func (t *Template) IsSupported(provider ProviderType) bool {
for _, v := range t.SupportedProviders {
if v == provider {
return true
}
}
return false
}
type TemplateRepository interface {
Create(ctx context.Context, template *Template) IError
GetByID(ctx context.Context, id string) (*Template, IError)
}
type Templater interface {
Execute(pattern string, params interface{}) ([]byte, error)
}
func (t *Template) GetTemplater() Templater {
switch t.Type {
case TemplateTypeMustache:
return &templater.Mustache{}
case TemplateTypeGoTemplate:
return &templater.Go{}
}
return nil
}