archrules

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 8 Imported by: 0

README

archrules

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.

Why?

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!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(rulePath string, rule *Rule) error

Types

type Rule

type Rule struct {

	// Skip files in the Rule path.
	// Example: say that we have a directory for a CRUD CLI tool:
	// [".", "root.go", "get.go", "post.go", "delete.go"]
	// If we only want to test the CRUD files, we would skip "." and "root.go"
	//
	// Thinking about reversing this into just Files, with {} being all.
	SkipFiles []string

	// Imports that should not be in a file
	// Can be used to enforce things like dependency injection (No dbmodels in handler)
	ForbiddenImports []string

	// Imports that are necessary in a file
	// Useful for making things like challenges
	NecessaryImports []string

	// Should the files only use modules include
	// in [NecessaryImports]?
	OnlyNecessaryImports bool
	// contains filtered or unexported fields
}

Rule is a struct to define rules to be enforced in the Go codebase. Define a rule and pass them into [RunRule]

Jump to

Keyboard shortcuts

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