mirror of
https://github.com/grafana/grafana.git
synced 2025-01-06 14:13:11 -06:00
Chore: Remove DecoderCompactor() (#61706)
* Remove ApplyFunc and set NoOptionalPointers to true * Update go mod
This commit is contained in:
parent
f62f3cb0e9
commit
1e5eae5fca
4
go.mod
4
go.mod
@ -274,8 +274,9 @@ require (
|
||||
require (
|
||||
buf.build/gen/go/parca-dev/parca/bufbuild/connect-go v1.4.1-20221222094228-8b1d3d0f62e6.1
|
||||
buf.build/gen/go/parca-dev/parca/protocolbuffers/go v1.28.1-20221222094228-8b1d3d0f62e6.4
|
||||
github.com/Masterminds/semver/v3 v3.1.1
|
||||
github.com/dave/dst v0.27.2
|
||||
github.com/grafana/thema v0.0.0-20230113164405-e0e8893756cf
|
||||
github.com/grafana/thema v0.0.0-20230122235053-b4b6714dd1c9
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f
|
||||
k8s.io/apimachinery v0.25.3
|
||||
)
|
||||
@ -286,7 +287,6 @@ require (
|
||||
github.com/Azure/azure-pipeline-go v0.2.3 // indirect
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.1.1 // indirect
|
||||
github.com/armon/go-metrics v0.4.1 // indirect
|
||||
github.com/bmatcuk/doublestar v1.1.1 // indirect
|
||||
github.com/buildkite/yaml v2.1.0+incompatible // indirect
|
||||
|
4
go.sum
4
go.sum
@ -1418,8 +1418,8 @@ github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7
|
||||
github.com/grafana/prometheus-alertmanager v0.25.1-0.20230119183635-ec19b0a443b7/go.mod h1:MnBfDPXJqXmmfPwQlCLvVUdqfnvrAw+hSPtDeaaFwj4=
|
||||
github.com/grafana/saml v0.4.9-0.20220727151557-61cd9c9353fc h1:1PY8n+rXuBNr3r1JQhoytWDCpc+pq+BibxV0SZv+Cr4=
|
||||
github.com/grafana/saml v0.4.9-0.20220727151557-61cd9c9353fc/go.mod h1:9Zh6dWPtB3MSzTRt8fIFH60Z351QQ+s7hCU3J/tTlA4=
|
||||
github.com/grafana/thema v0.0.0-20230113164405-e0e8893756cf h1:jl1iWUlJt5GJWaafOqtaEp46MDFBCni7bmv75VGFkq0=
|
||||
github.com/grafana/thema v0.0.0-20230113164405-e0e8893756cf/go.mod h1:5j2nf4xmWhKr+1vyGouML8eJ8xERS5Jw/lhjs0eyz78=
|
||||
github.com/grafana/thema v0.0.0-20230122235053-b4b6714dd1c9 h1:nAdsZkvPYNH6wDPkAi9JaDSIf5i2iVz4+Rqk4AOt6sE=
|
||||
github.com/grafana/thema v0.0.0-20230122235053-b4b6714dd1c9/go.mod h1:5j2nf4xmWhKr+1vyGouML8eJ8xERS5Jw/lhjs0eyz78=
|
||||
github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda7565af6 h1:I9dh1MXGX0wGyxdV/Sl7+ugnki4Dfsy8lv2s5Yf887o=
|
||||
github.com/grafana/xorm v0.8.3-0.20220614223926-2fcda7565af6/go.mod h1:ZkJLEYLoVyg7amJK/5r779bHyzs2AU8f8VMiP6BM7uY=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
|
@ -30,7 +30,7 @@ func (j GoTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error) {
|
||||
},
|
||||
},
|
||||
PackageName: sfg.Schema.Lineage().Name(),
|
||||
ApplyFuncs: append(j.ApplyFuncs, PrefixDropper(sfg.Name), DecoderCompactor()),
|
||||
ApplyFuncs: append(j.ApplyFuncs, PrefixDropper(sfg.Name)),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -172,75 +172,3 @@ func (d prefixmod) do(n *dst.Ident) {
|
||||
n.Name = d.replace
|
||||
}
|
||||
}
|
||||
|
||||
func isSingleTypeDecl(gd *dst.GenDecl) bool {
|
||||
if gd.Tok == token.TYPE && len(gd.Specs) == 1 {
|
||||
_, is := gd.Specs[0].(*dst.TypeSpec)
|
||||
return is
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isAdditionalPropertiesStruct(tspec *dst.TypeSpec) (dst.Expr, bool) {
|
||||
strct, is := tspec.Type.(*dst.StructType)
|
||||
if is && len(strct.Fields.List) == 1 && strct.Fields.List[0].Names[0].Name == "AdditionalProperties" {
|
||||
return strct.Fields.List[0].Type, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func DecoderCompactor() dstutil.ApplyFunc {
|
||||
return func(c *dstutil.Cursor) bool {
|
||||
f, is := c.Node().(*dst.File)
|
||||
if !is {
|
||||
return false
|
||||
}
|
||||
|
||||
compact := make(map[string]bool)
|
||||
// walk the file decls
|
||||
for _, decl := range f.Decls {
|
||||
if fd, is := decl.(*dst.FuncDecl); is {
|
||||
compact[ddepoint(fd.Recv.List[0].Type).(*dst.Ident).Name] = true
|
||||
}
|
||||
}
|
||||
if len(compact) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
replace := make(map[string]dst.Expr)
|
||||
// Walk again, looking for types we found
|
||||
for _, decl := range f.Decls {
|
||||
if gd, is := decl.(*dst.GenDecl); is && isSingleTypeDecl(gd) {
|
||||
if tspec := gd.Specs[0].(*dst.TypeSpec); compact[tspec.Name.Name] {
|
||||
if expr, is := isAdditionalPropertiesStruct(tspec); is {
|
||||
replace[tspec.Name.Name] = expr
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dstutil.Apply(f, func(c *dstutil.Cursor) bool {
|
||||
switch x := c.Node().(type) {
|
||||
case *dst.FuncDecl:
|
||||
c.Delete()
|
||||
case *dst.GenDecl:
|
||||
if isSingleTypeDecl(x) && compact[x.Specs[0].(*dst.TypeSpec).Name.Name] {
|
||||
c.Delete()
|
||||
}
|
||||
case *dst.Field:
|
||||
if id, is := ddepoint(x.Type).(*dst.Ident); is {
|
||||
if expr, has := replace[id.Name]; has {
|
||||
x.Type = expr
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}, nil)
|
||||
return false
|
||||
}
|
||||
}
|
||||
func ddepoint(e dst.Expr) dst.Expr {
|
||||
if star, is := e.(*dst.StarExpr); is {
|
||||
return star.X
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user