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

关于 import 的包分组写法的疑问 #14

Closed
JuwanXu opened this issue Jun 29, 2020 · 2 comments
Closed

关于 import 的包分组写法的疑问 #14

JuwanXu opened this issue Jun 29, 2020 · 2 comments

Comments

@JuwanXu
Copy link

JuwanXu commented Jun 29, 2020

import (
	"time"
)

import (
	"github.com/dubbogo/getty"
	"github.com/pkg/errors"
)

import (
	"github.com/dk-lockdown/seata-golang/base/getty/config"
)

为什么把 import 的包通过多个 import 来拆分呢?我在其他开源项目里没看到过这种写法,如果写成通过空行来分组是不是更好一些?如下:

import (
	"time"

	"github.com/dubbogo/getty"
	"github.com/pkg/errors"

	"github.com/dk-lockdown/seata-golang/base/getty/config"
)
@JuwanXu JuwanXu changed the title 关于 import 的包拆分开的疑问 关于 import 的包拆分的疑问 Jun 29, 2020
@JuwanXu JuwanXu changed the title 关于 import 的包拆分的疑问 关于 import 的包分组写法的疑问 Jun 29, 2020
@dk-lockdown
Copy link

import (
	"time"
)

import (
	"github.com/dubbogo/getty"
	"github.com/pkg/errors"
)

import (
	"github.com/dk-lockdown/seata-golang/base/getty/config"
)

为什么把 import 的包通过多个 import 来拆分呢?我在其他开源项目里没看到过这种写法,如果写成通过空行来分组是不是更好一些?如下:

import (
	"time"

	"github.com/dubbogo/getty"
	"github.com/pkg/errors"

	"github.com/dk-lockdown/seata-golang/base/getty/config"
)

这其实是习惯问题,如果是 import 块里面通过空行来分组,goland 可能会自动格式化。这个拆分的方法是,go sdk 的包一个块,第三方包一个块,项目内的引用一个块,这样看着比较清晰

@JuwanXu
Copy link
Author

JuwanXu commented Jun 29, 2020

这其实是习惯问题,如果是 import 块里面通过空行来分组,goland 可能会自动格式化。这个拆分的方法是,go sdk 的包一个块,第三方包一个块,项目内的引用一个块,这样看着比较清晰

goland 格式化的话也是根据库名做排序,这样一来标准库和自三方库自然而然的不会排在一起,即便是分组的话也确实是没有在其他 golang 开源系统中见到过分成多个 import 的写法。
我看了一些比较知名的开源系统都是采用的空行分组的写法,包括:etcdmoby(docker 开源版)k8s@dk-lockdown

@JuwanXu JuwanXu closed this as completed Jul 2, 2020
luky116 pushed a commit that referenced this issue Jul 9, 2022
fix commit and rollback codec bug #14
wang1309 pushed a commit to wang1309/seata-go that referenced this issue Jan 7, 2023
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