-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (46 loc) · 1.14 KB
/
main.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
package main
import (
"encoding/json"
"fmt"
"github.com/americanas-go/annotation"
"github.com/americanas-go/log"
"github.com/americanas-go/log/contrib/rs/zerolog.v1"
"gopkg.in/yaml.v3"
"os"
)
type RestResponse struct {
Code int `attr:"code"`
Type string `attr:"type"`
Description string `attr:"description"`
}
func main() {
annotation.WithLogger(zerolog.NewLogger(zerolog.WithLevel("TRACE")))
basePath, err := os.Getwd()
if err != nil {
log.Panic(err)
}
log.Infof("current path is %s", basePath)
collector, err := annotation.Collect(
annotation.WithFilters("Rest", "Boost", "Inject"),
annotation.WithPath(basePath+"/examples/decode/app"),
annotation.WithPackages("github.com/americanas-go/annotation"),
)
if err != nil {
log.Error(err.Error())
}
entries := collector.Entries()
j, _ := yaml.Marshal(entries)
fmt.Println(string(j))
for _, block := range entries {
for _, annon := range block.Annotations {
if annon.Name == "RestResponse" {
rp := RestResponse{}
if err := annon.Decode(&rp); err != nil {
panic(err)
}
j, _ := json.Marshal(rp)
fmt.Println(string(j))
}
}
}
}