4
4
"bufio"
5
5
"bytes"
6
6
"encoding/json"
7
+ "fmt"
7
8
"strings"
8
9
"text/template"
9
10
@@ -15,17 +16,43 @@ import (
15
16
16
17
func Generate (req * plugin.CodeGenRequest ) (* plugin.CodeGenResponse , error ) {
17
18
structs := buildStructs (req )
19
+
20
+ options , err := parseOptions (req )
21
+ if err != nil {
22
+ return nil , errors .Errorf ("error parse options: %w" , err )
23
+ }
24
+
18
25
queries , err := buildQueries (req , structs )
19
26
if err != nil {
20
27
return nil , errors .Errorf ("error generating queries: %w" , err )
21
28
}
22
- return generate (req , structs , queries )
29
+ return generate (req , structs , queries , options )
30
+ }
31
+
32
+ type FSharpOption struct {
33
+ Async bool
34
+ }
35
+
36
+ func parseOptions (req * plugin.CodeGenRequest ) (* FSharpOption , error ) {
37
+ if req .Settings .Codegen != nil {
38
+ if len (req .Settings .Codegen .Options ) != 0 {
39
+ var options * FSharpOption
40
+ dec := json .NewDecoder (bytes .NewReader (req .Settings .Codegen .Options ))
41
+ dec .DisallowUnknownFields ()
42
+ if err := dec .Decode (& options ); err != nil {
43
+ return options , fmt .Errorf ("unmarshalling options: %s" , err )
44
+ }
45
+ return options , nil
46
+ }
47
+ }
48
+ return new (FSharpOption ), nil
23
49
}
24
50
25
51
type tmplCtx struct {
26
52
Q string
27
53
Structs []Struct
28
54
Queries []Query
55
+ Options * FSharpOption
29
56
30
57
// XXX: race
31
58
SourceName string
@@ -35,7 +62,7 @@ func (t *tmplCtx) OutputQuery(sourceName string) bool {
35
62
return t .SourceName == sourceName
36
63
}
37
64
38
- func generate (req * plugin.CodeGenRequest , structs []Struct , queries []Query ) (* plugin.CodeGenResponse , error ) {
65
+ func generate (req * plugin.CodeGenRequest , structs []Struct , queries []Query , options * FSharpOption ) (* plugin.CodeGenResponse , error ) {
39
66
funcMap := template.FuncMap {
40
67
"stem" : sdk .Stem ,
41
68
"pascalCase" : sdk .ToPascalCase ,
@@ -58,6 +85,7 @@ func generate(req *plugin.CodeGenRequest, structs []Struct, queries []Query) (*p
58
85
Q : "\" \" \" " ,
59
86
Queries : queries ,
60
87
Structs : structs ,
88
+ Options : options ,
61
89
}
62
90
63
91
output := map [string ]string {}
0 commit comments