Simple go package that implements the Luhn algorithm.
The latest and greatest version of this software is available at github.com/tcort/luhn.
go get github.com/tcort/luhn
For complete API documentation, see godoc.org/github.com/tcort/luhn
Here's a simple command line tool that accepts a number as a command line argument and reports whether or not it passed the Luhn check:
package main
import (
"fmt"
"github.com/tcort/luhn"
"os"
)
func main() {
if len(os.Args) != 2 {
fmt.Println("Usage: lc [number]")
return
}
if luhn.Check(os.Args[1]) {
fmt.Println("The number passed the Luhn check")
} else {
fmt.Println("The number failed the Luhn check")
}
}
See LICENSE.md