Documentation ¶
Overview ¶
Package genrawid provides functions to generate rawid.
For the sample implementation see: ./cmd/genrawid/main.go
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var IsModeFast = false
IsModeFast is the flag to use fast mode. It will use the last 16bit of the hash as the xor16 checksum.
var OsStdin = os.Stdin
OsStdin is a copy of os.Stdin to ease testing. Mock this variable during tests.
Functions ¶
func FromFile ¶
FromFile returns the rawid generated from the input file.
Example ¶
const pathFile = "./testdata/msg.txt" // msg.txt ==> "abcdefgh" rawid, err := genrawid.FromFile(pathFile) if err != nil { log.Fatal(err) } fmt.Println(rawid.Hex()) fmt.Println(rawid.Dec())
Output: ddaa2ac39b79058a -2474118025671277174
Example (Fast_mode) ¶
oldMode := genrawid.IsModeFast defer func() { genrawid.IsModeFast = oldMode }() // Set to fast mode genrawid.IsModeFast = true pathFile := "./testdata/msg.txt" // msg.txt ==> "abcdefgh" rawid, err := genrawid.FromFile(pathFile) if err != nil { fmt.Println(err.Error()) return } fmt.Println(rawid.Hex()) fmt.Println(rawid.Dec())
Output: ddaa2ac30a98963b -2474118028101904837
func FromStdin ¶
FromStdin returns the rawid generated from stdin as its input.
Example ¶
ExampleFromStdin
Since we can not receive input from stdin during the example run, we mock the OsStdin, the copy of os.Stdin in the package, by assigning a dummy file as its input.
// Backup and defer recover the stdin oldStdin := genrawid.OsStdin defer func() { genrawid.OsStdin = oldStdin }() // Mock the stdin by assigning a file to stdin. pathFile := "./testdata/msg.txt" // msg.txt ==> "abcdefgh" osFile, err := os.Open(pathFile) if err != nil { fmt.Println(err.Error()) return } genrawid.OsStdin = osFile // <-- mock! // Here is the actual example usage of FromStdin method to get the input from // stdin and generate a rawid. rawid, err := genrawid.FromStdin() if err != nil { fmt.Println(err.Error()) return } fmt.Println(rawid.Hex()) fmt.Println(rawid.Dec())
Output: ddaa2ac39b79058a -2474118025671277174
func FromString ¶
FromString returns the rawid generated from the input string.
Example ¶
input := "abcdefgh" rawid, err := genrawid.FromString(input) if err != nil { log.Fatal(err) } fmt.Println(rawid.Hex()) fmt.Println(rawid.Dec())
Output: ddaa2ac39b79058a -2474118025671277174
Types ¶
This section is empty.