snapshot of https://github.com/uber-go/guide.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
46
src/import-alias.md
Normal file
46
src/import-alias.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Import Aliasing
|
||||
|
||||
Import aliasing must be used if the package name does not match the last
|
||||
element of the import path.
|
||||
|
||||
```go
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
client "example.com/client-go"
|
||||
trace "example.com/trace/v2"
|
||||
)
|
||||
```
|
||||
|
||||
In all other scenarios, import aliases should be avoided unless there is a
|
||||
direct conflict between imports.
|
||||
|
||||
<table>
|
||||
<thead><tr><th>Bad</th><th>Good</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
runtimetrace "runtime/trace"
|
||||
|
||||
nettrace "golang.net/x/trace"
|
||||
)
|
||||
```
|
||||
|
||||
</td><td>
|
||||
|
||||
```go
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/trace"
|
||||
|
||||
nettrace "golang.net/x/trace"
|
||||
)
|
||||
```
|
||||
|
||||
</td></tr>
|
||||
</tbody></table>
|
||||
Reference in New Issue
Block a user