Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd/gf): add interface functions generating for embedded struct of logic struct in command gen service #3802

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

joy999
Copy link
Contributor

@joy999 joy999 commented Sep 24, 2024

实现logic中内嵌其它logic时,生成service可以合并内嵌logic的接口生成。
比如 type sAdmin struct {
sMember
}
生成的service.IAdmin将存在sMember的接口合并,并不会只有sAdmin的接口。

@gqcn gqcn changed the title Feature/gf service embed feat(cmd/gf): add interface functions generating for embedded struct of logic strut in command gen service Sep 24, 2024
@gqcn gqcn changed the title feat(cmd/gf): add interface functions generating for embedded struct of logic strut in command gen service feat(cmd/gf): add interface functions generating for embedded struct of logic struct in command gen service Sep 24, 2024
@joy999 joy999 requested a review from gqcn September 26, 2024 03:52
@gqcn
Copy link
Member

gqcn commented Oct 9, 2024

这个PR @hailaz@oldme-git 一起帮忙review下呢?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Can @hailaz and @oldme-git help review this PR?

cmd/gf/internal/cmd/genservice/genservice.go Outdated Show resolved Hide resolved
cmd/gf/internal/cmd/genservice/genservice_ast_parse.go Outdated Show resolved Hide resolved
cmd/gf/internal/cmd/genservice/genservice_ast_parse.go Outdated Show resolved Hide resolved
@oldme-git
Copy link
Member

oldme-git commented Oct 10, 2024

@gqcn @joy999 这个功能是否需要,如果存在多层嵌套该怎么处理

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn Is this function necessary? What to do if there are multiple levels of nesting?

@joy999
Copy link
Contributor Author

joy999 commented Oct 10, 2024

@gqcn @joy999 这个功能是否需要,如果存在多层嵌套该怎么处理

多层嵌套有处理过。内层的同名函数会被外层的同名函数定义覆盖。有些场景是需要这样处理的。比如先有一个sMember,然后要再定义一个sAdmin继承自sMember,sAdmin只重载一些特定方法,其它的沿用sMember的。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn @joy999 Is this function necessary? What to do if there are multiple levels of nesting?

Multiple levels of nesting have been handled. Functions with the same name in the inner layer will be overwritten by function definitions with the same name in the outer layer. Some scenarios need to be handled this way. For example, there is an sMember first, and then you need to define an sAdmin to inherit from sMember. sAdmin only overloads some specific methods, and the others follow sMember.

@gqcn
Copy link
Member

gqcn commented Oct 10, 2024

@gqcn @joy999 这个功能是否需要,如果存在多层嵌套该怎么处理

@joy999 这里能否做个开关控制一下,通常用不着,可以让用户自己打开。另外,麻烦在关键逻辑多加点注释,方便长期维护。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn @joy999 Is this function necessary? What to do if there are multiple levels of nesting?

@joy999 Well, can you make a switch to control it? Usually it is not needed and the user can turn it on by himself. In addition, please add more comments on the key logic to facilitate long-term maintenance.

@joy999
Copy link
Contributor Author

joy999 commented Oct 11, 2024

@gqcn @joy999 这个功能是否需要,如果存在多层嵌套该怎么处理

@joy999 这里能否做个开关控制一下,通常用不着,可以让用户自己打开。另外,麻烦在关键逻辑多加点注释,方便长期维护。

现在已经去除了通过结构体s开头来判定是否要内嵌识别的处理逻辑。而是改用在内嵌结构体名后加tag的方式,这样不管是s开头或者是其它的结构体都可以嵌入,同时,现在也可以跨包内嵌了。tag现在定义了 gen:"extend" 则会内嵌识别。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn @joy999 Is this function necessary? What to do if there are multiple levels of nesting?

@joy999 Can you make a switch to control it? Usually it is not needed and the user can turn it on by himself. In addition, please add more comments on the key logic to facilitate long-term maintenance.

The processing logic of determining whether to inline recognition through the beginning of the structure s has now been removed. Instead, we use the method of adding a tag after the embedded structure name, so that no matter it starts with s or other structures, it can be embedded. At the same time, it can also be embedded across packages. If the tag now defines gen:"extend", it will be recognized inline.

@gqcn
Copy link
Member

gqcn commented Oct 12, 2024

@gqcn @joy999 这个功能是否需要,如果存在多层嵌套该怎么处理

@joy999 这里能否做个开关控制一下,通常用不着,可以让用户自己打开。另外,麻烦在关键逻辑多加点注释,方便长期维护。

现在已经去除了通过结构体s开头来判定是否要内嵌识别的处理逻辑。而是改用在内嵌结构体名后加tag的方式,这样不管是s开头或者是其它的结构体都可以嵌入,同时,现在也可以跨包内嵌了。tag现在定义了 gen:"extend" 则会内嵌识别。

识别s开头是因为logic下面会有很多struct,需要区分那些struct是需要生成service的。你去掉了s*名称判断后,怎么来识别呢?我看你加的gen标签只是为了识别结构体中的属性是否识别扩展方法。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn @joy999 Is this function necessary? What to do if there are multiple levels of nesting?

@joy999 Can you make a switch to control it? It is usually not needed and can be turned on by the user. In addition, please add more comments on the key logic to facilitate long-term maintenance.

The processing logic of determining whether to inline recognition through the beginning of structure s has now been removed. Instead, we use the method of adding a tag after the embedded structure name, so that no matter it starts with s or other structures, it can be embedded. At the same time, it can now be embedded across packages. If the tag now defines gen:"extend", it will be recognized inline.

The reason for identifying the beginning of s is because there will be many struct under logic, and you need to distinguish which structs need to generate services. After you remove the s* name judgment, how do you identify it? I see that the gen tag you added is just to identify whether the attributes in the structure recognize extension methods.

@joy999
Copy link
Contributor Author

joy999 commented Oct 12, 2024

@gqcn @joy999 这个功能是否需要,如果存在多层嵌套该怎么处理

@joy999 这里能否做个开关控制一下,通常用不着,可以让用户自己打开。另外,麻烦在关键逻辑多加点注释,方便长期维护。

现在已经去除了通过结构体s开头来判定是否要内嵌识别的处理逻辑。而是改用在内嵌结构体名后加tag的方式,这样不管是s开头或者是其它的结构体都可以嵌入,同时,现在也可以跨包内嵌了。tag现在定义了 gen:"extend" 则会内嵌识别。

识别s开头是因为logic下面会有很多struct,需要区分那些struct是需要生成service的。你去掉了s*名称判断后,怎么来识别呢?我看你加的gen标签只是为了识别结构体中的属性是否识别扩展方法。

并没有改动原来的sXXX的生成判定。我去掉的是我用来判定内嵌识别的那部分我自己添加的代码,之前是以sXXX为嵌入结构体,其它的命名的结构体不会被识别为嵌入方法继承,所以只能在本目录下引入。现在这个调整为了通过tag来识别,所以,理论上任意位置的结构体现在都可以嵌入了。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn @joy999 Is this function necessary? What to do if there are multiple levels of nesting?

@joy999 Can you make a switch to control it? It is usually not needed and can be turned on by the user. In addition, please add more comments on the key logic to facilitate long-term maintenance.

The processing logic of determining whether to inline recognition through the beginning of the structure s has now been removed. Instead, we use the method of adding a tag after the embedded structure name, so that no matter it starts with s or other structures, it can be embedded. At the same time, it can now be embedded across packages. If the tag now defines gen:"extend", it will be recognized inline.

The reason for identifying the beginning of s is because there will be many struct under logic, and it is necessary to distinguish those structs that need to generate services. After you remove the s* name judgment, how do you identify it? I see that the gen tag you added is just to identify whether the attributes in the structure recognize extension methods.

The original sXXX generation judgment has not been changed. What I removed is the part of the code I added myself to determine the embedded recognition. Previously, sXXX was used as the embedded structure. Other named structures will not be recognized as embedded method inheritance, so they can only be used in this directory. introduced below. Now this adjustment is to identify it through tags, so in theory, the structure at any position can now be embedded.

@gqcn gqcn requested a review from oldme-git October 14, 2024 13:22
@gqcn gqcn added this to the v2.9.x milestone Nov 11, 2024
@gqcn gqcn added the ready to merge Used in PR, which means this PR is reviewed. label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Used in PR, which means this PR is reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants