https://github.com/ferdypruis/go-luhn
Create or validate a Lühn (mod 10) check digit in a numeric string in Go.
https://github.com/ferdypruis/go-luhn
checksum go golang luhn mod10
Last synced: 5 months ago
JSON representation
Create or validate a Lühn (mod 10) check digit in a numeric string in Go.
- Host: GitHub
- URL: https://github.com/ferdypruis/go-luhn
- Owner: ferdypruis
- License: mit
- Created: 2019-11-19T15:08:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-17T16:59:41.000Z (over 4 years ago)
- Last Synced: 2025-08-14T17:54:20.315Z (10 months ago)
- Topics: checksum, go, golang, luhn, mod10
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-luhn
[](https://travis-ci.com/ferdypruis/go-luhn)
[](https://pkg.go.dev/github.com/ferdypruis/go-luhn)
Create or validate a Lühn (mod 10) check digit in a numeric string in Go.
## Examples
Checksum returns the Lühn check digit for number.
```go
number := "7992739871"
checkdigit, _ := luhn.Checksum(number) // Ignoring error for simplicity
fmt.Println("The Lühn check digit for", number, "is", checkdigit)
// Output:
// The Lühn check digit for 7992739871 is 3
```
Sign returns number with its Lühn check digit appended
```go
number := "7992739871"
number, _ = luhn.Sign(number) // Ignoring error for simplicity
fmt.Println("Your account number is", number)
// Output:
// Your account number is 79927398713
```
Valid returns whether number verifies against its appended check digit
```go
number := "79927398713"
if luhn.Valid(number) {
fmt.Println("The number is valid")
} else {
fmt.Println("The number is not valid")
}
// Output:
// The number is valid
```