go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

api file anonymous struct syntax

Open xmwilldo opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? Please describe. When I am writing the api file, I want to strictly control the returned fields, then there will be type declarations like AAA, AAA1, but I don't want this kind of declaration and I think the readability is not good.

Describe the solution you'd like I want to support anonymous types when writing api files, like:

type (
 AAA {
  Field1 int64 `json:"field1"`
  Field2 int64 `json:"field2"`
  BBB struct {
   Field1 int64 `json:"field1"`
   Field2 int64 `json:"field2"`
  }
 }
)

and then generate a struct like this in the generated types.go file

type AAA struct {
 Field1 int64 `json:"field1"`
 Field2 int64 `json:"field2"`
 BBB  AAA_BBB `json:"bbb"`
}
type AAA_BBB struct {
 Field1 int64 `json:"field1"`
 Field2 int64 `json:"field2"`
}

xmwilldo avatar Jan 13 '23 11:01 xmwilldo

First of all, this syntax itself is not currently supported, and a syntax error will be reported. However, in the future, pr #2585 will support some new features

kesonan avatar Jan 15 '23 13:01 kesonan

Amazing!

xmwilldo avatar Jan 16 '23 01:01 xmwilldo

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jan 16 '24 01:01 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Apr 17 '24 01:04 github-actions[bot]