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

建议支持只导入一个包名,就可以使用所有函数的方式 #219

Closed
CcccFz opened this issue May 15, 2024 · 1 comment
Closed

Comments

@CcccFz
Copy link

CcccFz commented May 15, 2024

如:
import "github.com/duke-git/lancet/v2
便可以通过lancet.XXX()的方式使用到所有函数

否则,若大量使用到lancet各包中的函数时,代码中可能会出现如下情况

import (
  "github.com/duke-git/lancet/v2/xx1`
  "github.com/duke-git/lancet/v2/xx2`
  "github.com/duke-git/lancet/v2/xx3`
  ...
)

这样加重了使用负担,每使用一个函数都会去查看是属于哪个子包下的函数,且容易造成和其它包的包名冲突,不得不给包名起导入别名

若在意编译了多余的不使用的子代码包(比如部分用户可能只会用到个别函数,却编译了整个包),可以2种方式都同时支持。但个人觉得微乎其微

@duke-git
Copy link
Owner

入别名

@CcccFz lancet中有很多重名方法(例如slice/filter, maputil/filter), package的作用一是代码复用,二是做命名空间。go不支持命名空间语法。兼容性很重要,2种方式都需要支持。如果所有方法都在一个lancet包下,需要导入所有对应的子包,然后定义对应方法的包全局变量。针对重名方法还要重新命名。代码复杂度增加,维护困难,投入产出比低。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants