/
service.go
66 lines (54 loc) · 1.37 KB
/
service.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
54
55
56
57
58
59
60
61
62
63
64
65
66
package generator
import (
"fmt"
"strings"
)
type Service struct {
Name string `yaml:"name"`
Errors []string `yaml:"errors"`
Methods []Method `yaml:"methods"`
ExchangeTypes []VectraType[AttributeWithTag] `yaml:"exchange_types"`
Bodies map[string]string `yaml:"-"`
}
type Method struct {
Name string `yaml:"name"`
Inputs []SimpleAttribute `yaml:"inputs"`
Outputs []string `yaml:"outputs"`
}
type Services struct {
*Generator
}
func NewServices(cfg *Vectra) *Generator {
var files []SourceFile
for _, service := range cfg.Services {
files = append(files,
NewDynSourceFile(
"src/model/service/service.go.tmpl",
fmt.Sprintf("src/model/service/%s_service.go",
strings.ToLower(service.Name)),
Skeleton),
)
}
generator := NewAbstractGenerator(
"services",
[]string{
"Services",
},
Report{
Files: files,
Version: 1,
}, cfg)
n := &Services{}
n.Generator = generator
n.IGenerator = n
return generator
}
func (i *Services) Generate() {
for n, service := range i.vectra.Services {
i.vectra.Services[n].Bodies = extractFunctionBody(
i.vectra.ProjectPath + "/src/model/service/" +
fmt.Sprintf("%s_service.go", strings.ToLower(service.Name)),
)
}
i.Generator.Generate(i.vectra.Services)
}