Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atotto/gogroupimports
Similar to goimport, but makes the grouping clearer.
https://github.com/atotto/gogroupimports
go gofmt goimports golang
Last synced: 24 days ago
JSON representation
Similar to goimport, but makes the grouping clearer.
- Host: GitHub
- URL: https://github.com/atotto/gogroupimports
- Owner: atotto
- Created: 2022-10-03T23:48:58.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-03T23:55:09.000Z (about 2 years ago)
- Last Synced: 2024-06-21T03:15:34.320Z (5 months ago)
- Topics: go, gofmt, goimports, golang
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gogroupimports
Similar to goimport, but makes the grouping clearer.
The gogroupimports tool organizes the Go imports and rewrites them according to the following:
- First group: The standard library packages
- Next group: 3rd party library packages
- Last group: local packagesexample:
```go
import (
// The standard library packages
"context"
"fmt"
"testing"// 3rd party library packages
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"// local packages
"github.com/atotto/awesome"
)
```## Installation
```
go install github.com/atotto/gogroupimports@latest
go install golang.org/x/tools/cmd/goimports@latest
```## Example of use
before:
```go
import (
"testing""context"
"fmt"
"github.com/atotto/awesome"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
``````
gogroupimports -local github.com/atotto/awesome -w foo.go
```after:
```go
import (
"context"
"fmt"
"testing""google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto""github.com/atotto/awesome"
)
```### vs goimports
The [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) tool does not delete empty line. Like this:
```
goimports -local github.com/atotto/awesome -w foo.go
``````go
import (
"context"
"fmt"
"testing""google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status""github.com/atotto/awesome"
"google.golang.org/protobuf/proto"
)
```