A Go library for enforcing architectural rules in your Go codebase.
Caution
go-archrules is still in active development and may face breaking changes on the road to stabilization.
I originally made a proposal for a custom lintier on an open source api at my school, I felt like many students who wanted to try their hands at backend would not recognize concepts like dependency injections and such, so hence the proposal of a custom linter to enforce these rules (like not importing db models in handlers, etc...). I figured it might be a fun idea to turn it into a bigger library with more options and for others to use! Whether it be for enforcing rules like mentioned above, or making coding challanges!
Simply run
go get github.com/GaballaGit/go-archrules@latest
Here is an example in action
package main
import (
"fmt"
"github.com/GaballaGit/go-archrules"
)
func main() {
test := &archrules.Rule{
NecessaryImports: []string{"fmt", "time"},
OnlyNecessaryImports: true,
}
fmt.Println("Running archrules!")
err := archrules.Run(".", test)
if err != nil {
fmt.Println(err, "\n", "Whats the time again?")
}
}Output
Running archrules!
Missing necessary imports: "time" in main.go
Whats the time again?
- Skip directory
- Necessary and Forbidden Functions
- Necessary and Forbidden Operators
- Necessary and Forbidden Methods