banimport

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 5 Imported by: 0

README

banimport

This tool detects prohibited imports. You can control "import dependencies" among go packages, for example, in your monorepo.

Install

go install github.com/nrnrk/banimport@latest

How to use

  1. Install command
go install github.com/nrnrk/banimport@latest
  1. Prepare config file
    • Edit a config file to prohibit "import dependencies"
cd <your repository root>
vi .banimport.json

example: .banimport.json

{
  "pattern": {
    "github.com/example/monorepo/svca": [
        "github.com/example/monorepo/svcb",
        "github.com/example/monorepo/svcc",
    ],
    "github.com/example/monorepo/svcb": [
        "github.com/example/monorepo/svcc",
        "github.com/example/monorepo/svca",
    ],
    "github.com/example/monorepo/svcc": [
        "github.com/example/monorepo/svca",
        "github.com/example/monorepo/svcb",
    ]
  }
}
  1. Execute by go vet
go vet vettool=$(which banimport) -banimport.config=$(cat .banimport.json) ./...

Usecase

├── libA
├── libB
├── svcA
├── svcB
└── svcC
  • libA andlibB are intended to be used by other packages.
  • svcA, svcB, and svcC sholud not be used by other packaes even in the module.

In the above case, you can prohibit "import dependencies" on svcA, svcB, and svcC to use the following config file.

.banimport.json

{
  "pattern": {
    "github.com/nrnrk/monorepo/libA": [
        "github.com/nrnrk/monorepo/svcA",
        "github.com/nrnrk/monorepo/svcB",
        "github.com/nrnrk/monorepo/svcC"
    ],
    "github.com/nrnrk/monorepo/libB": [
        "github.com/nrnrk/monorepo/svcA",
        "github.com/nrnrk/monorepo/svcB",
        "github.com/nrnrk/monorepo/svcC"
    ],
    "github.com/nrnrk/monorepo/svcA": [
        "github.com/nrnrk/monorepo/svcB",
        "github.com/nrnrk/monorepo/svcC"
    ],
    "github.com/nrnrk/monorepo/svcB": [
        "github.com/nrnrk/monorepo/svcC",
        "github.com/nrnrk/monorepo/svcA"
    ],
    "github.com/nrnrk/monorepo/svcC": [
        "github.com/nrnrk/monorepo/svcA",
        "github.com/nrnrk/monorepo/svcB"
    ]
  }
}

Hints

  • If your service packages include some packages used by other external packages, you might want to use internal package. This checker is useful when your service packages do not have any packages supposed to be used by external packages.
    • You can check the details about internal package here.

This repository is originally created using skeleton.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "banimport",
	Doc:  doc,
	Run:  run,
}

Analyzer is ...

Functions

This section is empty.

Types

type BanList

type BanList []string

type BanPattern

type BanPattern map[string]BanList

type Config

type Config struct {
	BanPattern BanPattern `json:"pattern"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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