mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
fixed import extraction on array types
This commit is contained in:
parent
b891b77108
commit
c4193cf8d8
41
go.go
41
go.go
@ -133,27 +133,32 @@ func renderServiceProxies(services map[string]*Service, fullPackageName string,
|
|||||||
"github.com/foomo/gotsrpc": "gotsrpc",
|
"github.com/foomo/gotsrpc": "gotsrpc",
|
||||||
}
|
}
|
||||||
r := strings.NewReplacer(".", "_", "/", "_", "-", "_")
|
r := strings.NewReplacer(".", "_", "/", "_", "-", "_")
|
||||||
|
|
||||||
|
extractImport := func(st *StructType) {
|
||||||
|
if st.Package != fullPackageName {
|
||||||
|
alias, ok := aliases[st.Package]
|
||||||
|
if !ok {
|
||||||
|
packageParts := strings.Split(st.Package, "/")
|
||||||
|
beautifulAlias := packageParts[len(packageParts)-1]
|
||||||
|
uglyAlias := r.Replace(st.Package)
|
||||||
|
alias = beautifulAlias
|
||||||
|
for _, otherAlias := range aliases {
|
||||||
|
if otherAlias == beautifulAlias {
|
||||||
|
alias = uglyAlias
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
aliases[st.Package] = alias
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extractImports := func(fields []*Field) {
|
extractImports := func(fields []*Field) {
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
if f.Value.StructType != nil {
|
if f.Value.StructType != nil {
|
||||||
st := f.Value.StructType
|
extractImport(f.Value.StructType)
|
||||||
if st.Package != fullPackageName {
|
} else if f.Value.Array != nil && f.Value.Array.Value.StructType != nil {
|
||||||
alias, ok := aliases[st.Package]
|
extractImport(f.Value.Array.Value.StructType)
|
||||||
if !ok {
|
|
||||||
packageParts := strings.Split(st.Package, "/")
|
|
||||||
beautifulAlias := packageParts[len(packageParts)-1]
|
|
||||||
uglyAlias := r.Replace(st.Package)
|
|
||||||
alias = beautifulAlias
|
|
||||||
for _, otherAlias := range aliases {
|
|
||||||
if otherAlias == beautifulAlias {
|
|
||||||
alias = uglyAlias
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
aliases[st.Package] = alias
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user