uint64 what and why
uint = unsigned integer, no negative numbers. Range is 0 to a very large positive number.
var x int // -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
var x uint64 // 0 to 18,446,744,073,709,551,615In a commit log specifically:
type Record struct {
Value []byte
Offset uint64 // position in the log
}Offset is the index of a record in the log... It answers "where is this record?"
uint64 makes perfect sense here for two reasons:
1. An offset can never be negative i.e. index -3 makes no sense
2. Logs can get HUGE, uint64 gives you 18 quintillion records
before you run out of space. Amazing!It's intentional type choice, encoding a business rule ("offsets are never negative") directly into the type. If someone passes -1, the compiler refuses. The compiler becomes your first line of defence!