Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

docs: define go import convention #258

Merged
merged 1 commit into from
Sep 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,29 @@ Inspired from: [github.com/kubernetes/community/contributors/devel/api-conventio
- Add an example in docs/example with its explanation README, for e.g. [health](https://github.com/kedgeproject/kedge/tree/master/docs/examples/health).
- Add an e2e test on above example, for e.g. see test code for [health](https://github.com/kedgeproject/kedge/blob/cfee15ffde02c611d08420699a43869706be2d53/tests/e2e/e2e_test.go#L272).
- Add this feature information to file-reference, for e.g. see [health section](https://github.com/kedgeproject/kedge/blob/master/docs/file-reference.md#health).

### golang dependency import conventions

Imports MUST be arranged in three sections, separated by an empty line.

```go
stdlib
kedge
thirdparty
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also add a named import section here like done in https://github.com/kedgeproject/kedge/blob/master/pkg/spec/resources.go#L19-L38, this makes the imports look a lot cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is for knowing what imports are coming from where, also even if the imports are named or not the sorting happens the same way.

And same convention k8s also follows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use named imports only when there is a collision between multiple package names. Otherwise, it just adds confusion

```

For example:

```go
"fmt"
"io"
"os/exec"

pkgcmd "github.com/kedgeproject/kedge/pkg/cmd"
"github.com/kedgeproject/kedge/pkg/spec"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
```

Once arranged, let `gofmt` sort the sequence of imports.