Example #1
0
// IPAddress creates an Address with given IP.
func IPAddress(ip []byte) Address {
	switch len(ip) {
	case net.IPv4len:
		var addr ipv4Address = [4]byte{ip[0], ip[1], ip[2], ip[3]}
		return addr
	case net.IPv6len:
		if predicate.BytesAll(ip[0:10], 0) && predicate.BytesAll(ip[10:12], 0xff) {
			return IPAddress(ip[12:16])
		}
		var addr ipv6Address = [16]byte{
			ip[0], ip[1], ip[2], ip[3],
			ip[4], ip[5], ip[6], ip[7],
			ip[8], ip[9], ip[10], ip[11],
			ip[12], ip[13], ip[14], ip[15],
		}
		return addr
	default:
		log.Error("Invalid IP format: ", ip)
		return nil
	}
}
Example #2
0
func TestCmdKey(t *testing.T) {
	assert := assert.On(t)

	id := NewID(uuid.New())
	assert.Bool(predicate.BytesAll(id.CmdKey(), 0)).IsFalse()
}