Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
/ readonly Public archive

Go linter that enforces the immutability of struct fields

License

Notifications You must be signed in to change notification settings

devinalvaro/readonly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

readonly

readonly is a Go linter that enforces the immutability of struct fields, preventing modifications from outside their package.

This tool offers a simpler alternative to getter methods.

Installation

go install github.com/devinalvaro/readonly/cmd/readonly@latest

Usage

readonly [package]

Example

Consider the following struct:

package example

type Config struct {
	Name  string `readonly:"enforce"`
	Value string
}

readonly will report an error if Config.Name is modified from outside the example package.

Another example:

package example

type Config struct {
	Name  string `readonly:"enforce_all"`
	Value string
}

readonly now enforces both Config.Name and Config.Value.

Testing

The test file shows all cases that readonly covers.

About

Go linter that enforces the immutability of struct fields

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages