-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.go
More file actions
90 lines (77 loc) · 1.72 KB
/
run.go
File metadata and controls
90 lines (77 loc) · 1.72 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package go2openapi
import (
"log"
"os"
"time"
"github.com/getkin/kin-openapi/openapi3"
"github.com/kataras/iris/v12"
)
// TODO: custom open api
func initOpenAPI() *openapi3.T {
return &openapi3.T{
OpenAPI: "3.0.0",
Info: &openapi3.Info{
//Version: "", TODO: currently ls does not support versioning
Title: "LiveSession Internal Web API",
},
Servers: openapi3.Servers{
{
URL: "https://api.livesession.io",
Description: "Production",
},
{
URL: "https://api-labs.livesession.io/",
Description: "Labs",
},
{
URL: "http://localhost:3001",
Description: "Local",
},
},
Paths: openapi3.NewPaths(),
Components: &openapi3.Components{
RequestBodies: make(openapi3.RequestBodies),
},
}
}
func save(openapi *openapi3.T, path string) {
if path == "" {
path = "./openapi.json"
}
data, _ := openapi.MarshalJSON()
f, err := os.Create(path)
if err != nil {
log.Fatal(err)
}
_, err = f.WriteString(string(data))
if err != nil {
log.Fatal(err)
}
}
type Options struct {
SearchIdentifiers []*SearchIdentifier
StructsMappingRootPath string
SavePath string
GoModName string
IgnoreRoutes []string
Require map[string]bool
iris *iris.Application
}
func (o *Options) WithIris(app *iris.Application) *Options {
o.iris = app
return o
}
func Init(options *Options) {
// wait for router registration
go func() {
time.Sleep(time.Second * 2)
openapi := initOpenAPI()
if options.iris != nil {
if err := irisRouterStrategy(options, openapi); err != nil {
panic(err)
}
}
save(openapi, options.SavePath)
log.Println("finished openapi with iris strategy")
}()
}