-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
61 lines (48 loc) · 1022 Bytes
/
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
59
60
61
package main
import (
"database/sql"
"flag"
"fmt"
"io/ioutil"
"log"
sql2 "github.com/minitauros/swagen/sql"
"github.com/minitauros/swagen/swagger"
"gopkg.in/yaml.v2"
)
type Config struct {
DB struct {
DSN string
}
Service swagger.ServiceInfo
Resources map[string]swagger.Resource // Table name => resource
}
func main() {
configFilePath := flag.String("conf", "", "config file path")
flag.Parse()
if *configFilePath == "" {
log.Fatal("No config file path given. Use the -conf flag.")
}
configBytes, err := ioutil.ReadFile(*configFilePath)
if err != nil {
log.Fatal(err)
}
conf := Config{}
err = yaml.Unmarshal(configBytes, &conf)
if err != nil {
log.Fatal(err)
}
db, err := sql.Open("mysql", conf.DB.DSN)
if err != nil {
log.Fatal(err)
}
generator := swagger.Generator{
TableService: sql2.NewTableService(db),
Resources: conf.Resources,
ServiceInfo: conf.Service,
}
swag, err := generator.Generate()
if err != nil {
log.Fatal(err)
}
fmt.Println(swag)
}