Skip to content
/ goif Public

Tool to format Go imports into groups (stdlib, your namespace, others)

License

Notifications You must be signed in to change notification settings

mingan/goif

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go import formatter - goif

Goif groups and orders imports in your Go source files. By default, it separates imports into two groups: standard library and everything else, each is then sorted. If you provide --prefix option, it will make a third group between these two containing all imports starting with this prefix.

Example

package main

import (
	"github.com/pressly/sup"
	"github.com/some/package"

	"github.com/different/library"

	"fmt"
	"github.com/some/otherpackage"
)

is with --prefix=github.com/some transformed into

package main

import (
	"fmt"

	"github.com/some/otherpackage"
	"github.com/some/package"

	"github.com/different/library"
	"github.com/pressly/sup"
)

Installation

go get -u github.com/mingan/goif/cmd/goif

Usage

By default, vendor/ folder is ignored by default. List of paths to exclude can be provided as --exclude=vendor,something,some/nested/prefix, the prefixes are evaluated relative to the current working directory.

I recommend setting goif to be run as a Git pre-commit hook, after go fmt.

Contribution

Contributions and issues are welcome.

About

Tool to format Go imports into groups (stdlib, your namespace, others)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages