| 1 | package utilsscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ |
| 2 | |
| 3 | import ( |
| 4 | "net/netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 6 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 7 | |
| 8 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/" |
| 9 | ) |
| 10 | |
| 11 | func parseIPSamplesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/parseIPSamples().() []string { |
| 12 | return []string{ |
| 13 | // IPv4 |
| 14 | "0.0.0.0", |
| 15 | "127.0.0.1", |
| 16 | "203.0.113.195", |
| 17 | "255.255.255.255", |
| 18 | "1.2.3.4", |
| 19 | "256.1.1.1", |
| 20 | "1.2.3.4.5", |
| 21 | "1.2.3", |
| 22 | "01.2.3.4", |
| 23 | "1.02.3.4", |
| 24 | "1.2.3.04", |
| 25 | "1.2.3.4 ", |
| 26 | " 1.2.3.4", |
| 27 | "1..3.4", |
| 28 | "1.2.3.", |
| 29 | ".1.2.3", |
| 30 | "1.2.3.4567", |
| 31 | "a.b.c.d", |
| 32 | "1.2.3.-4", |
| 33 | "", |
| 34 | // IPv6 |
| 35 | "::", |
| 36 | "::1", |
| 37 | "1::", |
| 38 | "2001:db8::8a2e:370:7334", |
| 39 | "2001:0db8:0000:0000:0000:ff00:0042:8329", |
| 40 | "1:2:3:4:5:6:7:8", |
| 41 | "1:2:3:4:5:6:7:8:9", |
| 42 | "1:2:3:4:5:6:7::", |
| 43 | "1::2:3:4:5:6:7:8", |
| 44 | "1:::2", |
| 45 | "1::2::3", |
| 46 | ":1:2:3", |
| 47 | "1:2:3:", |
| 48 | ":", |
| 49 | ":::", |
| 50 | "fe80::1%eth0", |
| 51 | "fe80::1%", |
| 52 | "%eth0", |
| 53 | "::%25eth0", |
| 54 | "::ffff:192.168.0.1", |
| 55 | "::ffff:1.2.3.400", |
| 56 | "1:2:3:4:5:6:1.2.3.4", |
| 57 | "1:2:3:4:5:6:7:1.2.3.4", |
| 58 | "::1.2.3.4", |
| 59 | "1.2.3.4::", |
| 60 | "12345::", |
| 61 | "g::1", |
| 62 | "FE80::A:b", |
| 63 | "0:0:0:0:0:0:0:0", |
| 64 | "1:2::10.0.0.1", |
| 65 | "::.1.2.3", |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | func Test_ParseIPv4scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_ParseIPv4().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 70 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 71 | for _, in := range parseIPSamplesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/parseIPSamples().() { |
| 72 | want, wantErr := netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/ParseAddr().(in) |
| 73 | wantOK := wantErr == nil && !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(in, ":") |
| 74 | got, ok := ParseIPv4scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv4().(in) |
| 75 | gotBytes, okBytes := ParseIPv4scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv4().([]byte(in)) |
| 76 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantOK, ok, "input %q", in) |
| 77 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantOK, okBytes, "input %q", in) |
| 78 | if wantOK { |
| 79 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, got, "input %q", in) |
| 80 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, gotBytes, "input %q", in) |
| 81 | } else { |
| 82 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.Addrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/Addr#{}, got, "input %q", in) |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | func Test_ParseIPv6scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Test_ParseIPv6().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 88 | t.Parallelscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Parallel().() |
| 89 | for _, in := range parseIPSamplesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/parseIPSamples().() { |
| 90 | want, wantErr := netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/ParseAddr().(in) |
| 91 | wantOK := wantErr == nil && stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(in, ":") |
| 92 | got, ok := ParseIPv6scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv6().(in) |
| 93 | gotBytes, okBytes := ParseIPv6scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv6().([]byte(in)) |
| 94 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantOK, ok, "input %q", in) |
| 95 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, wantOK, okBytes, "input %q", in) |
| 96 | if wantOK { |
| 97 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, got, "input %q", in) |
| 98 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, want, gotBytes, "input %q", in) |
| 99 | } else { |
| 100 | requirescip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/.Equalscip-go gomod github.com/stretchr/testify v1.12.1 `github.com/stretchr/testify/require`/Equal().(t, netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.Addrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/Addr#{}, got, "input %q", in) |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func Benchmark_ParseIPv4scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Benchmark_ParseIPv4().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 106 | input := "203.0.113.195" |
| 107 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 108 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 109 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 110 | if _, ok := ParseIPv4scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv4().(input); !ok { |
| 111 | b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to parse") |
| 112 | } |
| 113 | } |
| 114 | }) |
| 115 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().("default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 116 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 117 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 118 | if _, err := netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/ParseAddr().(input); err != nil { |
| 119 | b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 120 | } |
| 121 | } |
| 122 | }) |
| 123 | } |
| 124 | |
| 125 | func Benchmark_ParseIPv6scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/Benchmark_ParseIPv6().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 126 | inputs := []struct { |
| 127 | name string |
| 128 | value string |
| 129 | }{ |
| 130 | {"compressed", "2001:db8::8a2e:370:7334"}, |
| 131 | {"full", "2001:0db8:0000:0000:0000:ff00:0042:8329"}, |
| 132 | } |
| 133 | for _, input := range inputs { |
| 134 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(input.name+"/fiber", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 135 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 136 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 137 | if _, ok := ParseIPv6scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2`/ParseIPv6().(input.value); !ok { |
| 138 | b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("failed to parse") |
| 139 | } |
| 140 | } |
| 141 | }) |
| 142 | b.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Run().(input.name+"/default", func(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) { |
| 143 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.25.0 testing/B#ReportAllocs().() |
| 144 | for b.Loopscip-go gomod github.com/golang/go/src go1.25.0 testing/B#Loop().() { |
| 145 | if _, err := netipscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/.ParseAddrscip-go gomod github.com/golang/go/src go1.25.0 `net/netip`/ParseAddr().(input.value); err != nil { |
| 146 | b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err) |
| 147 | } |
| 148 | } |
| 149 | }) |
| 150 | } |
| 151 | } |