every byte is 4-bits of randomness
(numHexDigits int)
| 878 | |
| 879 | // every byte is 4-bits of randomness |
| 880 | func RandomHexString(numHexDigits int) (string, error) { |
| 881 | numBytes := (numHexDigits + 1) / 2 // Calculate the number of bytes needed |
| 882 | bytes := make([]byte, numBytes) |
| 883 | if _, err := rand.Read(bytes); err != nil { |
| 884 | return "", err |
| 885 | } |
| 886 | |
| 887 | hexStr := hex.EncodeToString(bytes) |
| 888 | return hexStr[:numHexDigits], nil // Return the exact number of hex digits |
| 889 | } |
| 890 | |
| 891 | func GetJsonTag(field reflect.StructField) string { |
| 892 | jsonTag := field.Tag.Get("json") |
no test coverage detected