Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd277cc

Browse files
authored
feat: Remove reflect methods (#2129)
<!-- Explain what problem this PR addresses --> ---
1 parent e85ce0b commit bd277cc

File tree

8 files changed

+48
-25
lines changed

8 files changed

+48
-25
lines changed

docs/generator.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ func (g *Generator) Generate(dir string, format Format) error {
127127
}
128128
}
129129

130+
func (g *Generator) GenerateJSON(dir string, format Format) error {
131+
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
132+
return err
133+
}
134+
switch format {
135+
case FormatJSON:
136+
return g.renderTablesAsJSON(dir)
137+
default:
138+
return fmt.Errorf("unsupported format: %v", format)
139+
}
140+
}
141+
130142
// setDestinationManagedCqColumns overwrites or adds the CQ columns that are managed by the destination plugins (_cq_sync_time, _cq_source_name).
131143
// func setDestinationManagedCqColumns(tables []*schema.Table) {
132144
// for _, table := range tables {

examples/simple_plugin/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ require (
5959
github.com/pmezard/go-difflib v1.0.0 // indirect
6060
github.com/samber/lo v1.49.1 // indirect
6161
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect
62-
github.com/spf13/cobra v1.8.1 // indirect
63-
github.com/spf13/pflag v1.0.5 // indirect
62+
github.com/spf13/cobra v1.9.0 // indirect
63+
github.com/spf13/pflag v1.0.6 // indirect
6464
github.com/stretchr/testify v1.10.0 // indirect
6565
github.com/thoas/go-funk v0.9.3 // indirect
6666
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect

examples/simple_plugin/go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ github.com/cloudquery/plugin-pb-go v1.26.11/go.mod h1:S65IWZQejnUHxY/411F+vTt/9T
5959
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=
6060
github.com/cloudquery/plugin-sdk/v2 v2.7.0/go.mod h1:pAX6ojIW99b/Vg4CkhnsGkRIzNaVEceYMR+Bdit73ug=
6161
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
62-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
62+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
6363
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6464
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
6565
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -144,10 +144,10 @@ github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
144144
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
145145
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
146146
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
147-
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
148-
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
149-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
150-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
147+
github.com/spf13/cobra v1.9.0 h1:Py5fIuq/lJsRYxcxfOtsJqpmwJWCMOUy2tMJYV8TNHE=
148+
github.com/spf13/cobra v1.9.0/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
149+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
150+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
151151
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
152152
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
153153
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/rs/zerolog v1.34.0
2727
github.com/samber/lo v1.49.1
2828
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
29-
github.com/spf13/cobra v1.8.1
29+
github.com/spf13/cobra v1.9.0
3030
github.com/stretchr/testify v1.10.0
3131
github.com/thoas/go-funk v0.9.3
3232
go.opentelemetry.io/otel v1.34.0
@@ -82,7 +82,7 @@ require (
8282
github.com/oapi-codegen/runtime v1.1.1 // indirect
8383
github.com/pierrec/lz4/v4 v4.1.22 // indirect
8484
github.com/pmezard/go-difflib v1.0.0 // indirect
85-
github.com/spf13/pflag v1.0.5 // indirect
85+
github.com/spf13/pflag v1.0.6 // indirect
8686
github.com/stoewer/go-strcase v1.3.0 // indirect
8787
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
8888
github.com/zeebo/xxh3 v1.0.2 // indirect

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ github.com/cloudquery/plugin-pb-go v1.26.11/go.mod h1:S65IWZQejnUHxY/411F+vTt/9T
6161
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=
6262
github.com/cloudquery/plugin-sdk/v2 v2.7.0/go.mod h1:pAX6ojIW99b/Vg4CkhnsGkRIzNaVEceYMR+Bdit73ug=
6363
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
64-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
64+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
6565
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6666
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
6767
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -146,10 +146,10 @@ github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
146146
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
147147
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
148148
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
149-
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
150-
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
151-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
152-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
149+
github.com/spf13/cobra v1.9.0 h1:Py5fIuq/lJsRYxcxfOtsJqpmwJWCMOUy2tMJYV8TNHE=
150+
github.com/spf13/cobra v1.9.0/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
151+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
152+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
153153
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
154154
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
155155
github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=

plugin/plugin_package.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package plugin
22

33
import (
44
"errors"
5+
"strings"
56
)
67

78
const (
@@ -41,14 +42,23 @@ type BuildTarget struct {
4142
Arch string `json:"arch"`
4243
CGO bool `json:"cgo"`
4344
Env []string `json:"env"`
45+
Tags []string `json:"tags"`
4446
IncludeSymbols bool `json:"include_symbols"`
4547
}
4648

4749
func (t BuildTarget) EnvVariables() []string {
48-
variables := append(t.cgoEnvVariables(), "GOOS="+t.OS, "GOARCH="+t.Arch)
50+
variables := append(t.cgoEnvVariables(), "GOOS="+t.OS, "GOARCH="+t.Arch, t.tags())
4951
return append(variables, t.Env...)
5052
}
5153

54+
func (t BuildTarget) tags() string {
55+
if len(t.Tags) == 0 {
56+
return ""
57+
}
58+
tagString := strings.Join(t.Tags, ",")
59+
return "GOFLAGS=-tags=" + tagString
60+
}
61+
5262
func (t BuildTarget) cgoEnvVariables() []string {
5363
// default is to tool at the param. Can be overridden by adding `CGO_ENABLED=1` to BuildTarget.Env
5464
if !t.CGO {
@@ -78,9 +88,9 @@ func (t BuildTarget) cgoEnvVariables() []string {
7888
}
7989

8090
var DefaultBuildTargets = []BuildTarget{
81-
{OS: GoOSLinux, Arch: GoArchAmd64},
82-
{OS: GoOSLinux, Arch: GoArchArm64},
83-
{OS: GoOSWindows, Arch: GoArchAmd64},
84-
{OS: GoOSDarwin, Arch: GoArchAmd64},
85-
{OS: GoOSDarwin, Arch: GoArchArm64},
91+
{OS: GoOSLinux, Arch: GoArchAmd64, Tags: []string{"grpcnotrace"}},
92+
{OS: GoOSLinux, Arch: GoArchArm64, Tags: []string{"grpcnotrace"}},
93+
{OS: GoOSWindows, Arch: GoArchAmd64, Tags: []string{"grpcnotrace"}},
94+
{OS: GoOSDarwin, Arch: GoArchAmd64, Tags: []string{"grpcnotrace"}},
95+
{OS: GoOSDarwin, Arch: GoArchArm64, Tags: []string{"grpcnotrace"}},
8696
}

serve/docs.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package serve
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67

@@ -43,11 +44,11 @@ func (s *PluginServe) newCmdPluginDoc() *cobra.Command {
4344
return err
4445
}
4546
g := docs.NewGenerator(s.plugin.Name(), tables)
46-
f := docs.FormatMarkdown
47-
if format.Value == "json" {
48-
f = docs.FormatJSON
47+
if format.Value != "json" {
48+
return errors.New("only json format is supported. If need to generate markdown, use the `cloudquery tables` command")
4949
}
50-
return g.Generate(args[0], f)
50+
51+
return g.GenerateJSON(args[0], docs.FormatJSON)
5152
},
5253
}
5354
cmd.Flags().Var(format, "format", fmt.Sprintf("output format. one of: %s", strings.Join(format.Allowed, ",")))

serve/docs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestPluginDocs(t *testing.T) {
1515
memdb.NewMemDBClient)
1616
srv := Plugin(p)
1717
cmd := srv.newCmdPluginRoot()
18-
cmd.SetArgs([]string{"doc", tmpDir})
18+
cmd.SetArgs([]string{"doc", tmpDir, "--format", "json"})
1919
if err := cmd.Execute(); err != nil {
2020
t.Fatal(err)
2121
}

0 commit comments

Comments
 (0)