Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ for upcoming, planned features.
8. [Validation plan](#validation-plan)
9. [Properties path inference](#properties-path-inference)
10. [Testing helpers](#testing-helpers)
11. [Minimal dependencies](#dependency-policy)
4. [Rationale](#rationale)
1. [Reflection](#reflection)
2. [Trivia](#trivia)
Expand Down Expand Up @@ -731,6 +732,18 @@ writing unit tests for validation rules defined with govy.
Checkout [testable examples](https://pkg.go.dev/github.com/nobl9/govy/pkg/govytest#pkg-examples)
for a concise overview of the package's capabilities.

### Dependency policy

Govy **strives** to be dependency free.
We'd rather implement the required code ourselves then burden your projects
with bloated dependency tree.
Doing otherwise is in our honest opinion lazy and not secure!

The only external dependencies you will inherit from govy are the modules
officially maintained by the Go team under [golang.org/x](https://pkg.go.dev/golang.org/x).
Here, the trade-off is in favor of the external source,
which is high quality and under constant security scrutiny and maintenance.

## Rationale

Why was this library created?
Expand Down
12 changes: 11 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
],
"ignoreRegExpList": [
"/\\|\\s+[T|G]{2,}\\s+\\|/g",
"/\\b[13mn2][0-9A-HJ-NP-Za-km-z]{25,34}\\b/g",
"/\\b(?:bc|tb)1[ac-hj-np-z02-9]{11,71}\\b/gi",
"/https?:\\/\\/.*/g",
"/github.*/g",
"/nolint.*/g",
Expand Down Expand Up @@ -42,6 +44,8 @@
"UUIDRFC",
"afbf",
"atoi",
"bech",
"bips",
"cidrv",
"devbox",
"edebfe",
Expand All @@ -61,6 +65,7 @@
"govyconfig",
"govytest",
"issn",
"keccak",
"ldflags",
"Leonean",
"luhn",
Expand All @@ -70,18 +75,23 @@
"println",
"rtmp",
"renminbi",
"segwit",
"sloctl",
"strconv",
"structs",
"tmpl",
"tpng",
"unchecksummed",
"uuidv",
"vuln",
"vulns",
"wpkh",
"Implicits",
"mygovy",
"unpadded",
"JWSB64",
"ITIN"
"ITIN",
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",
"qpzry9x8gf2tvdw0s3jn54khce6mua7l"
]
}
4 changes: 4 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Refer to this [README.md](../internal/validation/README.md) for more information

## Dependencies

The only acceptable dependencies are the
[golang.org/x](https://pkg.go.dev/golang.org/x) modules.
Any other third-party dependency is to be rejected.

Renovate is configured to automatically merge minor and patch updates.
For major versions, which sadly includes GitHub Actions, manual approval
is required.
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module github.com/nobl9/govy
go 1.25.5

require (
golang.org/x/crypto v0.54.0
golang.org/x/text v0.40.0
golang.org/x/tools v0.48.0
)

require (
golang.org/x/mod v0.38.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk=
golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40=
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.40.0 h1:Ub2Z6/xjgF1WrYQz2nuITOEegKFtiIy+rieRJ5lHZKs=
golang.org/x/text v0.40.0/go.mod h1:hpnzDAfGV753zIKo+wk3u1bVKCGPbrnF7+7LBF/UHVY=
golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE=
Expand Down
15 changes: 9 additions & 6 deletions internal/messagetemplates/templatekey_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion internal/messagetemplates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ const (
StringLatitudeTemplate
StringLongitudeTemplate
StringKubernetesQualifiedNameTemplate
StringBTCAddressTemplate
StringBTCBech32AddressTemplate
StringETHAddressTemplate
StringMongoDBObjectIDTemplate
URLTemplate
SliceUniqueTemplate
Expand Down Expand Up @@ -256,7 +259,10 @@ var rawMessageTemplates = map[templateKey]string{
string must be a valid Kubernetes Qualified Name
{{- end }}
`,
StringMongoDBObjectIDTemplate: "string must be a 24-character hexadecimal MongoDB ObjectID",
StringBTCAddressTemplate: "string must be a valid mainnet legacy Bitcoin Base58Check address",
StringBTCBech32AddressTemplate: "string must be a valid mainnet Bitcoin Bech32 address",
StringETHAddressTemplate: "string must be a valid Ethereum address (0x plus 40 hexadecimal characters)",
StringMongoDBObjectIDTemplate: "string must be a 24-character hexadecimal MongoDB ObjectID",
SliceUniqueTemplate: `elements are not unique, {{ .Custom.FirstOrdinal }} and {{ .Custom.SecondOrdinal }} elements collide
{{- if gt (len .Custom.Constraints) 0 }} based on constraints: {{ joinSlice .Custom.Constraints "" }}{{- end }}`,
UniquePropertiesTemplate: `all of [{{ joinSlice .ComparisonValue "" }}] properties must be unique, but '{{ .Custom.FirstProperty }}' collides with '{{ .Custom.SecondProperty }}'
Expand Down
3 changes: 3 additions & 0 deletions pkg/rules/error_codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const (
ErrorCodeStringAlphanumericUnicode govy.ErrorCode = "string_alphanumeric_unicode"
ErrorCodeStringFQDN govy.ErrorCode = "string_fqdn"
ErrorCodeStringKubernetesQualifiedName govy.ErrorCode = "string_kubernetes_qualified_name"
ErrorCodeStringBTCAddress govy.ErrorCode = "string_btc_address"
ErrorCodeStringBTCBech32Address govy.ErrorCode = "string_btc_bech32_address"
ErrorCodeStringETHAddress govy.ErrorCode = "string_eth_address"
ErrorCodeStringMongoDBObjectID govy.ErrorCode = "string_mongodb_object_id"
ErrorCodeSliceLength govy.ErrorCode = "slice_length"
ErrorCodeSliceMinLength govy.ErrorCode = "slice_min_length"
Expand Down
1 change: 1 addition & 0 deletions pkg/rules/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
fqdnRegexp = lazyRegexCompile(
`^([a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})(\.[a-zA-Z0-9]{1}[a-zA-Z0-9-]{0,62})*?(\.[a-zA-Z]{1}[a-zA-Z0-9]{0,62})\.?$`,
)
btcAddressRegexp = lazyRegexCompile(`^[13][1-9A-HJ-NP-Za-km-z]{25,34}$`)
)

// lazyRegexCompile returns a function that compiles the regular expression
Expand Down
Loading
Loading