Skip to content

Commit 45fa115

Browse files
committed
Import packages
1 parent 4ec23c9 commit 45fa115

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

en-US.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,38 @@ var Migrations embed.FS
4141

4242
## Import packages
4343

44-
TBD
44+
All package import paths must be valid Go Modules path except packages from standard library.
45+
46+
Generally, there are four types of packages a source file could import:
47+
48+
1. Packages from standard library
49+
2. Third-party packages
50+
3. Packages in the same organization but not in the same repository
51+
4. Packages in the same repository
52+
53+
Basic rules:
54+
55+
- Use different groups to separate import paths by an blank line for two or more types of packages.
56+
- Must not use `.` to simplify import path except in test files (`*_test.go`).
57+
- Must not use relative path (`./subpackage`) as import path.
58+
59+
Here is a concrete example:
60+
61+
```go
62+
import (
63+
"fmt"
64+
"html/template"
65+
"net/http"
66+
"os"
67+
68+
"github.com/urfave/cli"
69+
"gopkg.in/macaron.v1"
70+
71+
"github.com/gogs/git-module"
72+
73+
"github.com/gogs/gogs/internal/route"
74+
"github.com/gogs/gogs/internal/route/repo"
75+
"github.com/gogs/gogs/internal/route/user"
76+
)
77+
```
78+

en-US/import_packages.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)