MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / AddSortIPAddressList

Function AddSortIPAddressList

jsext/addrutil.go:198–216  ·  view source on GitHub ↗
(vm *goja.Runtime)

Source from the content-addressed store, hash-verified

196}
197
198func AddSortIPAddressList(vm *goja.Runtime) error {
199 return vm.GlobalObject().Set("sortIpAddressList", func(call goja.FunctionCall) goja.Value {
200 if len(call.Arguments) != 1 {
201 panic(vm.NewTypeError("sortIpAddressList expects exactly 1 argument"))
202 }
203 addrParts := strings.Split(call.Argument(0).String(), ";")
204 addrs := make([]netip.Addr, 0, len(addrParts))
205 for _, part := range addrParts {
206 addr, err := netip.ParseAddr(part)
207 if err != nil {
208 return vm.ToValue("")
209 }
210 addrs = append(addrs, addr)
211 }
212 slices.SortFunc(addrs, netipAddrCmp)
213 res := mapSlice(addrs, func(a netip.Addr) string { return a.String() })
214 return vm.ToValue(strings.Join(res, ";"))
215 })
216}
217
218func dnsResolveEx(host string) []netip.Addr {
219 ctx, cl := context.WithTimeout(context.Background(), 5*time.Second)

Callers

nothing calls this directly

Calls 3

mapSliceFunction · 0.85
SetMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected