goaddimport

command module
v0.0.0-...-4ab94a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2017 License: MIT Imports: 10 Imported by: 0

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

Documentation

Overview

Command goaddimport adds an import spec to a Go source file. It reads the input file from standard in, and writes the result to standard out.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL