https://github.com/zmb3/goaddimport
Add imports to Go source files
https://github.com/zmb3/goaddimport
Last synced: about 2 months ago
JSON representation
Add imports to Go source files
- Host: GitHub
- URL: https://github.com/zmb3/goaddimport
- Owner: zmb3
- License: mit
- Created: 2017-08-10T01:20:56.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-10T01:37:09.000Z (almost 9 years ago)
- Last Synced: 2025-12-26T12:54:28.748Z (6 months ago)
- Language: Go
- Size: 2.25 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goaddimport
A simple utility for editors to add imports to Go source files.
Several Go editors have commands for automatically adding import statements to Go files.
This allows users to quickly add an import without scrolling to the top of the file
and potentially losing context.
Implementing this logic in a language other than Go can be tricky:
If the source file doesn't yet have any imports, a single line import declaration
should be chosen:
```
import "fmt"
```
If the source file already contains imports, a multi-line import declaration is preferred:
```
import (
"fmt"
"io"
)
```
Additionally imports should be sorted, and standard library imports should be grouped
separately from third-party imports (a la `goimports`).
`goaddimport` is a small tool that handles these cases for you.
## Usage:
The tool accepts the input file on stdin and writes its output to stdout.
It takes a single argument - the import path that should be added.
`$ goaddimport io/ioutil < main.go`