nidus-sync/public-report/report.go
Eli Ribble b35c9496b6
Add the ability to register for updates on quick reports
At this point it also appears that I'm correctly capturing the GPS
location as both PostGIS data and as an H3 cell.
2026-01-08 15:34:48 +00:00

33 lines
822 B
Go

package publicreport
import (
"crypto/rand"
"fmt"
"math/big"
"strings"
)
// GenerateReportID creates a 12-character random string using only unambiguous
// capital letters and numbers
func GenerateReportID() (string, error) {
// Define character set (no O, I, Z to avoid confusion)
const charset = "ABCDEFGHJKLMNPQRSTUVWXY0123456789"
const length = 12
var builder strings.Builder
builder.Grow(length)
// Use crypto/rand for secure randomness
for i := 0; i < length; i++ {
// Generate a random index within our charset
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))
if err != nil {
return "", fmt.Errorf("failed to generate random number: %w", err)
}
// Add the randomly selected character to our ID
builder.WriteByte(charset[n.Int64()])
}
return builder.String(), nil
}