88 "io/fs"
99 "log"
1010 "path/filepath"
11+ "regexp"
1112 "sort"
1213 "strings"
1314 "text/template"
@@ -95,6 +96,10 @@ func serverFiles(req *plugin.GenerateRequest, options *opts.Options, enums []Enu
9596 return nil
9697 }
9798
99+ if strings .HasSuffix (newPath , "metric.go" ) && ! def .Metric {
100+ return nil
101+ }
102+
98103 if strings .HasSuffix (newPath , "tracing.go" ) && ! def .DistributedTracing {
99104 return nil
100105 }
@@ -144,6 +149,10 @@ func toServerDefinition(req *plugin.GenerateRequest, options *opts.Options, enum
144149 if sqlPackage == "" {
145150 sqlPackage = "database/sql"
146151 }
152+ migrationLib := options .MigrationLib
153+ if migrationLib == "" {
154+ migrationLib = "goose"
155+ }
147156 messages := make (map [string ]* metadata.Message )
148157 for _ , st := range structs {
149158 msg := metadata.Message {
@@ -157,9 +166,27 @@ func toServerDefinition(req *plugin.GenerateRequest, options *opts.Options, enum
157166 }
158167 messages [st .Name ] = & msg
159168 }
169+ queriesToSkip := make ([]* regexp.Regexp , 0 )
170+ for _ , queryName := range strings .Split (options .SkipQueries , "," ) {
171+ s := strings .TrimSpace (queryName )
172+ if s == "" {
173+ continue
174+ }
175+ queriesToSkip = append (queriesToSkip , regexp .MustCompile (s ))
176+ }
160177 services := make ([]* metadata.Service , 0 )
161178 var hasExecResult bool
162179 for _ , query := range queries {
180+ var skip bool
181+ for _ , re := range queriesToSkip {
182+ if re .MatchString (query .MethodName ) {
183+ skip = true
184+ break
185+ }
186+ }
187+ if skip {
188+ continue
189+ }
163190 inputNames := make ([]string , 0 )
164191 inputTypes := make ([]string , 0 )
165192 if query .Arg .Struct != nil {
@@ -244,13 +271,34 @@ func toServerDefinition(req *plugin.GenerateRequest, options *opts.Options, enum
244271 } else if query .Cmd == ":execresult" {
245272 out .WriteString ("sql.Result" )
246273 }
274+ httpSpecs := make ([]metadata.HttpSpec , 0 )
275+ for _ , doc := range query .Comments {
276+ doc = strings .TrimSpace (doc )
277+ if strings .HasPrefix (doc , "http: " ) {
278+ opts := strings .Split (strings .TrimPrefix (doc , "http: " ), " " )
279+ if len (opts ) != 2 {
280+ continue
281+ }
282+ httpMethod , httpPath := strings .ToUpper (opts [0 ]), opts [1 ]
283+ switch httpMethod {
284+ case "POST" , "GET" , "PUT" , "DELETE" , "PATCH" :
285+ default :
286+ continue
287+ }
288+ httpSpecs = append (httpSpecs , metadata.HttpSpec {
289+ Method : httpMethod ,
290+ Path : httpPath ,
291+ })
292+ }
293+ }
247294 services = append (services , & metadata.Service {
248295 Name : query .MethodName ,
249296 Sql : query .SQL ,
250297 Messages : messages ,
251298 Output : out .String (),
252299 InputNames : inputNames ,
253300 InputTypes : inputTypes ,
301+ HttpSpecs : httpSpecs ,
254302 })
255303 }
256304 sort .SliceStable (services , func (i , j int ) bool {
@@ -279,7 +327,9 @@ func toServerDefinition(req *plugin.GenerateRequest, options *opts.Options, enum
279327 LiteFS : options .LiteFS ,
280328 Litestream : options .Litestream ,
281329 DistributedTracing : options .Tracing ,
330+ Metric : options .Metric ,
282331 MigrationPath : options .MigrationPath ,
332+ MigrationLib : migrationLib ,
283333 }
284334
285335 outAdapters := make (map [string ]struct {})
0 commit comments