mirror of
https://github.com/sony/sonyflake.git
synced 2026-02-03 07:02:01 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d195df6f7 | ||
|
|
410eb250e3 | ||
|
|
94f43cfd99 | ||
|
|
b9b40b47a5 | ||
|
|
a0558cef64 | ||
|
|
fc2f84a086 |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -4,7 +4,7 @@ jobs:
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.20.x, 1.21.x]
|
||||
go-version: [1.23.x, 1.24.x]
|
||||
os: [ubuntu-latest]
|
||||
runs-on: ${{matrix.os}}
|
||||
steps:
|
||||
|
||||
@@ -83,8 +83,8 @@ the function AmazonEC2MachineID that returns the lower 16-bit private IP address
|
||||
It also works correctly on Docker
|
||||
by retrieving [instance metadata](http://docs.aws.amazon.com/en_us/AWSEC2/latest/UserGuide/ec2-instance-metadata.html).
|
||||
|
||||
[AWS VPC](http://docs.aws.amazon.com/en_us/AmazonVPC/latest/UserGuide/VPC_Subnets.html)
|
||||
is assigned a single CIDR with a netmask between /28 and /16.
|
||||
[AWS IPv4 VPC](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-cidr-blocks.html)
|
||||
is usually assigned a single CIDR with a netmask between /28 and /16.
|
||||
So if each EC2 instance has a unique private IP address in AWS VPC,
|
||||
the lower 16 bits of the address is also unique.
|
||||
In this common case, you can use AmazonEC2MachineID as Settings.MachineID.
|
||||
|
||||
@@ -178,8 +178,9 @@ func privateIPv4(interfaceAddrs types.InterfaceAddrs) (net.IP, error) {
|
||||
}
|
||||
|
||||
func isPrivateIPv4(ip net.IP) bool {
|
||||
// Allow private IP addresses (RFC1918) and link-local addresses (RFC3927)
|
||||
return ip != nil &&
|
||||
(ip[0] == 10 || ip[0] == 172 && (ip[1] >= 16 && ip[1] < 32) || ip[0] == 192 && ip[1] == 168)
|
||||
(ip[0] == 10 || ip[0] == 172 && (ip[1] >= 16 && ip[1] < 32) || ip[0] == 192 && ip[1] == 168 || ip[0] == 169 && ip[1] == 254)
|
||||
}
|
||||
|
||||
func lower16BitPrivateIP(interfaceAddrs types.InterfaceAddrs) (uint16, error) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package sonyflake
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -259,7 +258,7 @@ func TestPrivateIPv4(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if bytes.Equal(actual, tc.expected) {
|
||||
if net.IP.Equal(actual, tc.expected) {
|
||||
return
|
||||
} else {
|
||||
t.Errorf("error: expected: %s, but got: %s", tc.expected, actual)
|
||||
|
||||
Reference in New Issue
Block a user