-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswagger.go
More file actions
73 lines (54 loc) · 1.28 KB
/
swagger.go
File metadata and controls
73 lines (54 loc) · 1.28 KB
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
67
68
69
70
71
72
73
package generators
import (
"net/url"
"os"
"strconv"
"strings"
"time"
"github.com/goccy/go-json"
)
type Swagger struct {
}
func (g *Swagger) Generate(template Template, modulePath string, driver string) {
workDir, _ := os.Getwd()
var path strings.Builder
path.WriteString(workDir)
path.WriteString("/")
path.WriteString("swaggers/modules.json")
modules, err := os.ReadFile(path.String())
if err != nil {
panic(err)
}
modulesJson := []ModuleJson{}
json.Unmarshal(modules, &modulesJson)
path.Reset()
path.WriteString("./")
path.WriteString(template.ModuleLowercase)
path.WriteString(".swagger.json")
modulesJson = append(modulesJson, ModuleJson{
Name: template.Module,
Url: path.String(),
})
occurred := make(map[string]bool)
for k, m := range modulesJson {
if occurred[m.Name] == true {
continue
}
occurred[m.Name] = true
mUrl, _ := url.Parse(m.Url)
query := mUrl.Query()
query.Set("v", strconv.Itoa(int(time.Now().UnixMicro())))
mUrl.RawQuery = query.Encode()
m.Url = mUrl.String()
modulesJson[k] = m
}
modules, _ = json.Marshal(modulesJson)
path.Reset()
path.WriteString(workDir)
path.WriteString("/")
path.WriteString("swaggers/modules.json")
err = os.WriteFile(path.String(), modules, 0644)
if err != nil {
panic(err)
}
}