id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
18,500 | hashicorp/go-sockaddr | rfc.go | VisitAllRFCs | func VisitAllRFCs(fn func(rfcNum uint, sockaddrs SockAddrs)) {
rfcNetMap := KnownRFCs()
// Blacklist of faux-RFCs. Don't show the world that we're abusing the
// RFC system in this library.
rfcBlacklist := map[uint]struct{}{
ForwardingBlacklist: {},
}
for rfcNum, sas := range rfcNetMap {
if _, found := rfcBlacklist[rfcNum]; !found {
fn(rfcNum, sas)
}
}
} | go | func VisitAllRFCs(fn func(rfcNum uint, sockaddrs SockAddrs)) {
rfcNetMap := KnownRFCs()
// Blacklist of faux-RFCs. Don't show the world that we're abusing the
// RFC system in this library.
rfcBlacklist := map[uint]struct{}{
ForwardingBlacklist: {},
}
for rfcNum, sas := range rfcNetMap {
if _, found := rfcBlacklist[rfcNum]; !found {
fn(rfcNum, sas)
}
}
} | [
"func",
"VisitAllRFCs",
"(",
"fn",
"func",
"(",
"rfcNum",
"uint",
",",
"sockaddrs",
"SockAddrs",
")",
")",
"{",
"rfcNetMap",
":=",
"KnownRFCs",
"(",
")",
"\n\n",
"// Blacklist of faux-RFCs. Don't show the world that we're abusing the",
"// RFC system in this library.",
"... | // VisitAllRFCs iterates over all known RFCs and calls the visitor | [
"VisitAllRFCs",
"iterates",
"over",
"all",
"known",
"RFCs",
"and",
"calls",
"the",
"visitor"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/rfc.go#L934-L948 |
18,501 | hashicorp/go-sockaddr | route_info.go | VisitCommands | func (ri routeInfo) VisitCommands(fn func(name string, cmd []string)) {
for k, v := range ri.cmds {
cmds := append([]string(nil), v...)
fn(k, cmds)
}
} | go | func (ri routeInfo) VisitCommands(fn func(name string, cmd []string)) {
for k, v := range ri.cmds {
cmds := append([]string(nil), v...)
fn(k, cmds)
}
} | [
"func",
"(",
"ri",
"routeInfo",
")",
"VisitCommands",
"(",
"fn",
"func",
"(",
"name",
"string",
",",
"cmd",
"[",
"]",
"string",
")",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"ri",
".",
"cmds",
"{",
"cmds",
":=",
"append",
"(",
"[",
"]",
"... | // VisitCommands visits each command used by the platform-specific RouteInfo
// implementation. | [
"VisitCommands",
"visits",
"each",
"command",
"used",
"by",
"the",
"platform",
"-",
"specific",
"RouteInfo",
"implementation",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/route_info.go#L14-L19 |
18,502 | hashicorp/go-sockaddr | ifaddrs.go | Sort | func (ms *multiIfAddrSorter) Sort(ifAddrs IfAddrs) {
ms.ifAddrs = ifAddrs
sort.Sort(ms)
} | go | func (ms *multiIfAddrSorter) Sort(ifAddrs IfAddrs) {
ms.ifAddrs = ifAddrs
sort.Sort(ms)
} | [
"func",
"(",
"ms",
"*",
"multiIfAddrSorter",
")",
"Sort",
"(",
"ifAddrs",
"IfAddrs",
")",
"{",
"ms",
".",
"ifAddrs",
"=",
"ifAddrs",
"\n",
"sort",
".",
"Sort",
"(",
"ms",
")",
"\n",
"}"
] | // Sort sorts the argument slice according to the Cmp functions passed to
// OrderedIfAddrBy. | [
"Sort",
"sorts",
"the",
"argument",
"slice",
"according",
"to",
"the",
"Cmp",
"functions",
"passed",
"to",
"OrderedIfAddrBy",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L40-L43 |
18,503 | hashicorp/go-sockaddr | ifaddrs.go | AscIfAddress | func AscIfAddress(p1Ptr, p2Ptr *IfAddr) int {
return AscAddress(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func AscIfAddress(p1Ptr, p2Ptr *IfAddr) int {
return AscAddress(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"AscIfAddress",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"AscAddress",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // AscIfAddress is a sorting function to sort IfAddrs by their respective
// address type. Non-equal types are deferred in the sort. | [
"AscIfAddress",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"IfAddrs",
"by",
"their",
"respective",
"address",
"type",
".",
"Non",
"-",
"equal",
"types",
"are",
"deferred",
"in",
"the",
"sort",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L100-L102 |
18,504 | hashicorp/go-sockaddr | ifaddrs.go | AscIfName | func AscIfName(p1Ptr, p2Ptr *IfAddr) int {
return strings.Compare(p1Ptr.Name, p2Ptr.Name)
} | go | func AscIfName(p1Ptr, p2Ptr *IfAddr) int {
return strings.Compare(p1Ptr.Name, p2Ptr.Name)
} | [
"func",
"AscIfName",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"strings",
".",
"Compare",
"(",
"p1Ptr",
".",
"Name",
",",
"p2Ptr",
".",
"Name",
")",
"\n",
"}"
] | // AscIfName is a sorting function to sort IfAddrs by their interface names. | [
"AscIfName",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"IfAddrs",
"by",
"their",
"interface",
"names",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L139-L141 |
18,505 | hashicorp/go-sockaddr | ifaddrs.go | AscIfNetworkSize | func AscIfNetworkSize(p1Ptr, p2Ptr *IfAddr) int {
return AscNetworkSize(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func AscIfNetworkSize(p1Ptr, p2Ptr *IfAddr) int {
return AscNetworkSize(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"AscIfNetworkSize",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"AscNetworkSize",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // AscIfNetworkSize is a sorting function to sort IfAddrs by their respective
// network mask size. | [
"AscIfNetworkSize",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"IfAddrs",
"by",
"their",
"respective",
"network",
"mask",
"size",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L145-L147 |
18,506 | hashicorp/go-sockaddr | ifaddrs.go | AscIfPort | func AscIfPort(p1Ptr, p2Ptr *IfAddr) int {
return AscPort(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func AscIfPort(p1Ptr, p2Ptr *IfAddr) int {
return AscPort(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"AscIfPort",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"AscPort",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // AscIfPort is a sorting function to sort IfAddrs by their respective
// port type. Non-equal types are deferred in the sort. | [
"AscIfPort",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"IfAddrs",
"by",
"their",
"respective",
"port",
"type",
".",
"Non",
"-",
"equal",
"types",
"are",
"deferred",
"in",
"the",
"sort",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L151-L153 |
18,507 | hashicorp/go-sockaddr | ifaddrs.go | AscIfType | func AscIfType(p1Ptr, p2Ptr *IfAddr) int {
return AscType(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func AscIfType(p1Ptr, p2Ptr *IfAddr) int {
return AscType(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"AscIfType",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"AscType",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // AscIfType is a sorting function to sort IfAddrs by their respective address
// type. Non-equal types are deferred in the sort. | [
"AscIfType",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"IfAddrs",
"by",
"their",
"respective",
"address",
"type",
".",
"Non",
"-",
"equal",
"types",
"are",
"deferred",
"in",
"the",
"sort",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L165-L167 |
18,508 | hashicorp/go-sockaddr | ifaddrs.go | DescIfAddress | func DescIfAddress(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscAddress(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func DescIfAddress(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscAddress(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"DescIfAddress",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"-",
"1",
"*",
"AscAddress",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // DescIfAddress is identical to AscIfAddress but reverse ordered. | [
"DescIfAddress",
"is",
"identical",
"to",
"AscIfAddress",
"but",
"reverse",
"ordered",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L170-L172 |
18,509 | hashicorp/go-sockaddr | ifaddrs.go | DescIfName | func DescIfName(p1Ptr, p2Ptr *IfAddr) int {
return -1 * strings.Compare(p1Ptr.Name, p2Ptr.Name)
} | go | func DescIfName(p1Ptr, p2Ptr *IfAddr) int {
return -1 * strings.Compare(p1Ptr.Name, p2Ptr.Name)
} | [
"func",
"DescIfName",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"-",
"1",
"*",
"strings",
".",
"Compare",
"(",
"p1Ptr",
".",
"Name",
",",
"p2Ptr",
".",
"Name",
")",
"\n",
"}"
] | // DescIfName is identical to AscIfName but reverse ordered. | [
"DescIfName",
"is",
"identical",
"to",
"AscIfName",
"but",
"reverse",
"ordered",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L180-L182 |
18,510 | hashicorp/go-sockaddr | ifaddrs.go | DescIfNetworkSize | func DescIfNetworkSize(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscNetworkSize(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func DescIfNetworkSize(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscNetworkSize(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"DescIfNetworkSize",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"-",
"1",
"*",
"AscNetworkSize",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // DescIfNetworkSize is identical to AscIfNetworkSize but reverse ordered. | [
"DescIfNetworkSize",
"is",
"identical",
"to",
"AscIfNetworkSize",
"but",
"reverse",
"ordered",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L185-L187 |
18,511 | hashicorp/go-sockaddr | ifaddrs.go | DescIfPort | func DescIfPort(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscPort(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func DescIfPort(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscPort(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"DescIfPort",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"-",
"1",
"*",
"AscPort",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // DescIfPort is identical to AscIfPort but reverse ordered. | [
"DescIfPort",
"is",
"identical",
"to",
"AscIfPort",
"but",
"reverse",
"ordered",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L190-L192 |
18,512 | hashicorp/go-sockaddr | ifaddrs.go | DescIfPrivate | func DescIfPrivate(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscPrivate(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func DescIfPrivate(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscPrivate(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"DescIfPrivate",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"-",
"1",
"*",
"AscPrivate",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // DescIfPrivate is identical to AscIfPrivate but reverse ordered. | [
"DescIfPrivate",
"is",
"identical",
"to",
"AscIfPrivate",
"but",
"reverse",
"ordered",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L195-L197 |
18,513 | hashicorp/go-sockaddr | ifaddrs.go | DescIfType | func DescIfType(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscType(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | go | func DescIfType(p1Ptr, p2Ptr *IfAddr) int {
return -1 * AscType(&p1Ptr.SockAddr, &p2Ptr.SockAddr)
} | [
"func",
"DescIfType",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"IfAddr",
")",
"int",
"{",
"return",
"-",
"1",
"*",
"AscType",
"(",
"&",
"p1Ptr",
".",
"SockAddr",
",",
"&",
"p2Ptr",
".",
"SockAddr",
")",
"\n",
"}"
] | // DescIfType is identical to AscIfType but reverse ordered. | [
"DescIfType",
"is",
"identical",
"to",
"AscIfType",
"but",
"reverse",
"ordered",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L200-L202 |
18,514 | hashicorp/go-sockaddr | ifaddrs.go | FilterIfByType | func FilterIfByType(ifAddrs IfAddrs, type_ SockAddrType) (matchedIfs, excludedIfs IfAddrs) {
excludedIfs = make(IfAddrs, 0, len(ifAddrs))
matchedIfs = make(IfAddrs, 0, len(ifAddrs))
for _, ifAddr := range ifAddrs {
if ifAddr.SockAddr.Type()&type_ != 0 {
matchedIfs = append(matchedIfs, ifAddr)
} else {
excludedIfs = append(excludedIfs, ifAddr)
}
}
return matchedIfs, excludedIfs
} | go | func FilterIfByType(ifAddrs IfAddrs, type_ SockAddrType) (matchedIfs, excludedIfs IfAddrs) {
excludedIfs = make(IfAddrs, 0, len(ifAddrs))
matchedIfs = make(IfAddrs, 0, len(ifAddrs))
for _, ifAddr := range ifAddrs {
if ifAddr.SockAddr.Type()&type_ != 0 {
matchedIfs = append(matchedIfs, ifAddr)
} else {
excludedIfs = append(excludedIfs, ifAddr)
}
}
return matchedIfs, excludedIfs
} | [
"func",
"FilterIfByType",
"(",
"ifAddrs",
"IfAddrs",
",",
"type_",
"SockAddrType",
")",
"(",
"matchedIfs",
",",
"excludedIfs",
"IfAddrs",
")",
"{",
"excludedIfs",
"=",
"make",
"(",
"IfAddrs",
",",
"0",
",",
"len",
"(",
"ifAddrs",
")",
")",
"\n",
"matchedIf... | // FilterIfByType filters IfAddrs and returns a list of the matching type | [
"FilterIfByType",
"filters",
"IfAddrs",
"and",
"returns",
"a",
"list",
"of",
"the",
"matching",
"type"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L205-L217 |
18,515 | hashicorp/go-sockaddr | ifaddrs.go | GetAllInterfaces | func GetAllInterfaces() (IfAddrs, error) {
ifs, err := net.Interfaces()
if err != nil {
return nil, err
}
ifAddrs := make(IfAddrs, 0, len(ifs))
for _, intf := range ifs {
addrs, err := intf.Addrs()
if err != nil {
return nil, err
}
for _, addr := range addrs {
var ipAddr IPAddr
ipAddr, err = NewIPAddr(addr.String())
if err != nil {
return IfAddrs{}, fmt.Errorf("unable to create an IP address from %q", addr.String())
}
ifAddr := IfAddr{
SockAddr: ipAddr,
Interface: intf,
}
ifAddrs = append(ifAddrs, ifAddr)
}
}
return ifAddrs, nil
} | go | func GetAllInterfaces() (IfAddrs, error) {
ifs, err := net.Interfaces()
if err != nil {
return nil, err
}
ifAddrs := make(IfAddrs, 0, len(ifs))
for _, intf := range ifs {
addrs, err := intf.Addrs()
if err != nil {
return nil, err
}
for _, addr := range addrs {
var ipAddr IPAddr
ipAddr, err = NewIPAddr(addr.String())
if err != nil {
return IfAddrs{}, fmt.Errorf("unable to create an IP address from %q", addr.String())
}
ifAddr := IfAddr{
SockAddr: ipAddr,
Interface: intf,
}
ifAddrs = append(ifAddrs, ifAddr)
}
}
return ifAddrs, nil
} | [
"func",
"GetAllInterfaces",
"(",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"ifs",
",",
"err",
":=",
"net",
".",
"Interfaces",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ifAddrs",
":=",
"make",... | // GetAllInterfaces iterates over all available network interfaces and finds all
// available IP addresses on each interface and converts them to
// sockaddr.IPAddrs, and returning the result as an array of IfAddr. | [
"GetAllInterfaces",
"iterates",
"over",
"all",
"available",
"network",
"interfaces",
"and",
"finds",
"all",
"available",
"IP",
"addresses",
"on",
"each",
"interface",
"and",
"converts",
"them",
"to",
"sockaddr",
".",
"IPAddrs",
"and",
"returning",
"the",
"result",... | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L242-L271 |
18,516 | hashicorp/go-sockaddr | ifaddrs.go | GetDefaultInterfaces | func GetDefaultInterfaces() (IfAddrs, error) {
ri, err := NewRouteInfo()
if err != nil {
return nil, err
}
defaultIfName, err := ri.GetDefaultInterfaceName()
if err != nil {
return nil, err
}
var defaultIfs, ifAddrs IfAddrs
ifAddrs, err = GetAllInterfaces()
for _, ifAddr := range ifAddrs {
if ifAddr.Name == defaultIfName {
defaultIfs = append(defaultIfs, ifAddr)
}
}
return defaultIfs, nil
} | go | func GetDefaultInterfaces() (IfAddrs, error) {
ri, err := NewRouteInfo()
if err != nil {
return nil, err
}
defaultIfName, err := ri.GetDefaultInterfaceName()
if err != nil {
return nil, err
}
var defaultIfs, ifAddrs IfAddrs
ifAddrs, err = GetAllInterfaces()
for _, ifAddr := range ifAddrs {
if ifAddr.Name == defaultIfName {
defaultIfs = append(defaultIfs, ifAddr)
}
}
return defaultIfs, nil
} | [
"func",
"GetDefaultInterfaces",
"(",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"ri",
",",
"err",
":=",
"NewRouteInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"defaultIfName",
",",
"err",
":="... | // GetDefaultInterfaces returns IfAddrs of the addresses attached to the default
// route. | [
"GetDefaultInterfaces",
"returns",
"IfAddrs",
"of",
"the",
"addresses",
"attached",
"to",
"the",
"default",
"route",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L275-L295 |
18,517 | hashicorp/go-sockaddr | ifaddrs.go | IfByAddress | func IfByAddress(inputRe string, ifAddrs IfAddrs) (matched, remainder IfAddrs, err error) {
re, err := regexp.Compile(inputRe)
if err != nil {
return nil, nil, fmt.Errorf("Unable to compile address regexp %+q: %v", inputRe, err)
}
matchedAddrs := make(IfAddrs, 0, len(ifAddrs))
excludedAddrs := make(IfAddrs, 0, len(ifAddrs))
for _, addr := range ifAddrs {
if re.MatchString(addr.SockAddr.String()) {
matchedAddrs = append(matchedAddrs, addr)
} else {
excludedAddrs = append(excludedAddrs, addr)
}
}
return matchedAddrs, excludedAddrs, nil
} | go | func IfByAddress(inputRe string, ifAddrs IfAddrs) (matched, remainder IfAddrs, err error) {
re, err := regexp.Compile(inputRe)
if err != nil {
return nil, nil, fmt.Errorf("Unable to compile address regexp %+q: %v", inputRe, err)
}
matchedAddrs := make(IfAddrs, 0, len(ifAddrs))
excludedAddrs := make(IfAddrs, 0, len(ifAddrs))
for _, addr := range ifAddrs {
if re.MatchString(addr.SockAddr.String()) {
matchedAddrs = append(matchedAddrs, addr)
} else {
excludedAddrs = append(excludedAddrs, addr)
}
}
return matchedAddrs, excludedAddrs, nil
} | [
"func",
"IfByAddress",
"(",
"inputRe",
"string",
",",
"ifAddrs",
"IfAddrs",
")",
"(",
"matched",
",",
"remainder",
"IfAddrs",
",",
"err",
"error",
")",
"{",
"re",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"inputRe",
")",
"\n",
"if",
"err",
"!=",... | // IfByAddress returns a list of matched and non-matched IfAddrs, or an error if
// the regexp fails to compile. | [
"IfByAddress",
"returns",
"a",
"list",
"of",
"matched",
"and",
"non",
"-",
"matched",
"IfAddrs",
"or",
"an",
"error",
"if",
"the",
"regexp",
"fails",
"to",
"compile",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L395-L412 |
18,518 | hashicorp/go-sockaddr | ifaddrs.go | IfByPort | func IfByPort(inputRe string, ifAddrs IfAddrs) (matchedIfs, excludedIfs IfAddrs, err error) {
re, err := regexp.Compile(inputRe)
if err != nil {
return nil, nil, fmt.Errorf("Unable to compile port regexp %+q: %v", inputRe, err)
}
ipIfs, nonIfs := FilterIfByType(ifAddrs, TypeIP)
matchedIfs = make(IfAddrs, 0, len(ipIfs))
excludedIfs = append(IfAddrs(nil), nonIfs...)
for _, addr := range ipIfs {
ipAddr := ToIPAddr(addr.SockAddr)
if ipAddr == nil {
continue
}
port := strconv.FormatInt(int64((*ipAddr).IPPort()), 10)
if re.MatchString(port) {
matchedIfs = append(matchedIfs, addr)
} else {
excludedIfs = append(excludedIfs, addr)
}
}
return matchedIfs, excludedIfs, nil
} | go | func IfByPort(inputRe string, ifAddrs IfAddrs) (matchedIfs, excludedIfs IfAddrs, err error) {
re, err := regexp.Compile(inputRe)
if err != nil {
return nil, nil, fmt.Errorf("Unable to compile port regexp %+q: %v", inputRe, err)
}
ipIfs, nonIfs := FilterIfByType(ifAddrs, TypeIP)
matchedIfs = make(IfAddrs, 0, len(ipIfs))
excludedIfs = append(IfAddrs(nil), nonIfs...)
for _, addr := range ipIfs {
ipAddr := ToIPAddr(addr.SockAddr)
if ipAddr == nil {
continue
}
port := strconv.FormatInt(int64((*ipAddr).IPPort()), 10)
if re.MatchString(port) {
matchedIfs = append(matchedIfs, addr)
} else {
excludedIfs = append(excludedIfs, addr)
}
}
return matchedIfs, excludedIfs, nil
} | [
"func",
"IfByPort",
"(",
"inputRe",
"string",
",",
"ifAddrs",
"IfAddrs",
")",
"(",
"matchedIfs",
",",
"excludedIfs",
"IfAddrs",
",",
"err",
"error",
")",
"{",
"re",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"inputRe",
")",
"\n",
"if",
"err",
"!=... | // IfByPort returns a list of matched and non-matched IfAddrs, or an error if
// the regexp fails to compile. | [
"IfByPort",
"returns",
"a",
"list",
"of",
"matched",
"and",
"non",
"-",
"matched",
"IfAddrs",
"or",
"an",
"error",
"if",
"the",
"regexp",
"fails",
"to",
"compile",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L437-L461 |
18,519 | hashicorp/go-sockaddr | ifaddrs.go | IfByRFC | func IfByRFC(selectorParam string, ifAddrs IfAddrs) (matched, remainder IfAddrs, err error) {
inputRFC, err := strconv.ParseUint(selectorParam, 10, 64)
if err != nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("unable to parse RFC number %q: %v", selectorParam, err)
}
matchedIfAddrs := make(IfAddrs, 0, len(ifAddrs))
remainingIfAddrs := make(IfAddrs, 0, len(ifAddrs))
rfcNetMap := KnownRFCs()
rfcNets, ok := rfcNetMap[uint(inputRFC)]
if !ok {
return nil, nil, fmt.Errorf("unsupported RFC %d", inputRFC)
}
for _, ifAddr := range ifAddrs {
var contained bool
for _, rfcNet := range rfcNets {
if rfcNet.Contains(ifAddr.SockAddr) {
matchedIfAddrs = append(matchedIfAddrs, ifAddr)
contained = true
break
}
}
if !contained {
remainingIfAddrs = append(remainingIfAddrs, ifAddr)
}
}
return matchedIfAddrs, remainingIfAddrs, nil
} | go | func IfByRFC(selectorParam string, ifAddrs IfAddrs) (matched, remainder IfAddrs, err error) {
inputRFC, err := strconv.ParseUint(selectorParam, 10, 64)
if err != nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("unable to parse RFC number %q: %v", selectorParam, err)
}
matchedIfAddrs := make(IfAddrs, 0, len(ifAddrs))
remainingIfAddrs := make(IfAddrs, 0, len(ifAddrs))
rfcNetMap := KnownRFCs()
rfcNets, ok := rfcNetMap[uint(inputRFC)]
if !ok {
return nil, nil, fmt.Errorf("unsupported RFC %d", inputRFC)
}
for _, ifAddr := range ifAddrs {
var contained bool
for _, rfcNet := range rfcNets {
if rfcNet.Contains(ifAddr.SockAddr) {
matchedIfAddrs = append(matchedIfAddrs, ifAddr)
contained = true
break
}
}
if !contained {
remainingIfAddrs = append(remainingIfAddrs, ifAddr)
}
}
return matchedIfAddrs, remainingIfAddrs, nil
} | [
"func",
"IfByRFC",
"(",
"selectorParam",
"string",
",",
"ifAddrs",
"IfAddrs",
")",
"(",
"matched",
",",
"remainder",
"IfAddrs",
",",
"err",
"error",
")",
"{",
"inputRFC",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"selectorParam",
",",
"10",
",",
... | // IfByRFC returns a list of matched and non-matched IfAddrs that contain the
// relevant RFC-specified traits. | [
"IfByRFC",
"returns",
"a",
"list",
"of",
"matched",
"and",
"non",
"-",
"matched",
"IfAddrs",
"that",
"contain",
"the",
"relevant",
"RFC",
"-",
"specified",
"traits",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L465-L495 |
18,520 | hashicorp/go-sockaddr | ifaddrs.go | IfByRFCs | func IfByRFCs(selectorParam string, ifAddrs IfAddrs) (matched, remainder IfAddrs, err error) {
var includedIfs, excludedIfs IfAddrs
for _, rfcStr := range strings.Split(selectorParam, "|") {
includedRFCIfs, excludedRFCIfs, err := IfByRFC(rfcStr, ifAddrs)
if err != nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("unable to lookup RFC number %q: %v", rfcStr, err)
}
includedIfs = append(includedIfs, includedRFCIfs...)
excludedIfs = append(excludedIfs, excludedRFCIfs...)
}
return includedIfs, excludedIfs, nil
} | go | func IfByRFCs(selectorParam string, ifAddrs IfAddrs) (matched, remainder IfAddrs, err error) {
var includedIfs, excludedIfs IfAddrs
for _, rfcStr := range strings.Split(selectorParam, "|") {
includedRFCIfs, excludedRFCIfs, err := IfByRFC(rfcStr, ifAddrs)
if err != nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("unable to lookup RFC number %q: %v", rfcStr, err)
}
includedIfs = append(includedIfs, includedRFCIfs...)
excludedIfs = append(excludedIfs, excludedRFCIfs...)
}
return includedIfs, excludedIfs, nil
} | [
"func",
"IfByRFCs",
"(",
"selectorParam",
"string",
",",
"ifAddrs",
"IfAddrs",
")",
"(",
"matched",
",",
"remainder",
"IfAddrs",
",",
"err",
"error",
")",
"{",
"var",
"includedIfs",
",",
"excludedIfs",
"IfAddrs",
"\n",
"for",
"_",
",",
"rfcStr",
":=",
"ran... | // IfByRFCs returns a list of matched and non-matched IfAddrs that contain the
// relevant RFC-specified traits. Multiple RFCs can be specified and separated
// by the `|` symbol. No protection is taken to ensure an IfAddr does not end
// up in both the included and excluded list. | [
"IfByRFCs",
"returns",
"a",
"list",
"of",
"matched",
"and",
"non",
"-",
"matched",
"IfAddrs",
"that",
"contain",
"the",
"relevant",
"RFC",
"-",
"specified",
"traits",
".",
"Multiple",
"RFCs",
"can",
"be",
"specified",
"and",
"separated",
"by",
"the",
"|",
... | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L501-L513 |
18,521 | hashicorp/go-sockaddr | ifaddrs.go | IfByMaskSize | func IfByMaskSize(selectorParam string, ifAddrs IfAddrs) (matchedIfs, excludedIfs IfAddrs, err error) {
maskSize, err := strconv.ParseUint(selectorParam, 10, 64)
if err != nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("invalid exclude size argument (%q): %v", selectorParam, err)
}
ipIfs, nonIfs := FilterIfByType(ifAddrs, TypeIP)
matchedIfs = make(IfAddrs, 0, len(ipIfs))
excludedIfs = append(IfAddrs(nil), nonIfs...)
for _, addr := range ipIfs {
ipAddr := ToIPAddr(addr.SockAddr)
if ipAddr == nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("unable to filter mask sizes on non-IP type %s: %v", addr.SockAddr.Type().String(), addr.SockAddr.String())
}
switch {
case (*ipAddr).Type()&TypeIPv4 != 0 && maskSize > 32:
return IfAddrs{}, IfAddrs{}, fmt.Errorf("mask size out of bounds for IPv4 address: %d", maskSize)
case (*ipAddr).Type()&TypeIPv6 != 0 && maskSize > 128:
return IfAddrs{}, IfAddrs{}, fmt.Errorf("mask size out of bounds for IPv6 address: %d", maskSize)
}
if (*ipAddr).Maskbits() == int(maskSize) {
matchedIfs = append(matchedIfs, addr)
} else {
excludedIfs = append(excludedIfs, addr)
}
}
return matchedIfs, excludedIfs, nil
} | go | func IfByMaskSize(selectorParam string, ifAddrs IfAddrs) (matchedIfs, excludedIfs IfAddrs, err error) {
maskSize, err := strconv.ParseUint(selectorParam, 10, 64)
if err != nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("invalid exclude size argument (%q): %v", selectorParam, err)
}
ipIfs, nonIfs := FilterIfByType(ifAddrs, TypeIP)
matchedIfs = make(IfAddrs, 0, len(ipIfs))
excludedIfs = append(IfAddrs(nil), nonIfs...)
for _, addr := range ipIfs {
ipAddr := ToIPAddr(addr.SockAddr)
if ipAddr == nil {
return IfAddrs{}, IfAddrs{}, fmt.Errorf("unable to filter mask sizes on non-IP type %s: %v", addr.SockAddr.Type().String(), addr.SockAddr.String())
}
switch {
case (*ipAddr).Type()&TypeIPv4 != 0 && maskSize > 32:
return IfAddrs{}, IfAddrs{}, fmt.Errorf("mask size out of bounds for IPv4 address: %d", maskSize)
case (*ipAddr).Type()&TypeIPv6 != 0 && maskSize > 128:
return IfAddrs{}, IfAddrs{}, fmt.Errorf("mask size out of bounds for IPv6 address: %d", maskSize)
}
if (*ipAddr).Maskbits() == int(maskSize) {
matchedIfs = append(matchedIfs, addr)
} else {
excludedIfs = append(excludedIfs, addr)
}
}
return matchedIfs, excludedIfs, nil
} | [
"func",
"IfByMaskSize",
"(",
"selectorParam",
"string",
",",
"ifAddrs",
"IfAddrs",
")",
"(",
"matchedIfs",
",",
"excludedIfs",
"IfAddrs",
",",
"err",
"error",
")",
"{",
"maskSize",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"selectorParam",
",",
"10... | // IfByMaskSize returns a list of matched and non-matched IfAddrs that have the
// matching mask size. | [
"IfByMaskSize",
"returns",
"a",
"list",
"of",
"matched",
"and",
"non",
"-",
"matched",
"IfAddrs",
"that",
"have",
"the",
"matching",
"mask",
"size",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L517-L547 |
18,522 | hashicorp/go-sockaddr | ifaddrs.go | IfByNetwork | func IfByNetwork(selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, IfAddrs, error) {
var includedIfs, excludedIfs IfAddrs
for _, netStr := range strings.Split(selectorParam, "|") {
netAddr, err := NewIPAddr(netStr)
if err != nil {
return nil, nil, fmt.Errorf("unable to create an IP address from %+q: %v", netStr, err)
}
for _, ifAddr := range inputIfAddrs {
if netAddr.Contains(ifAddr.SockAddr) {
includedIfs = append(includedIfs, ifAddr)
} else {
excludedIfs = append(excludedIfs, ifAddr)
}
}
}
return includedIfs, excludedIfs, nil
} | go | func IfByNetwork(selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, IfAddrs, error) {
var includedIfs, excludedIfs IfAddrs
for _, netStr := range strings.Split(selectorParam, "|") {
netAddr, err := NewIPAddr(netStr)
if err != nil {
return nil, nil, fmt.Errorf("unable to create an IP address from %+q: %v", netStr, err)
}
for _, ifAddr := range inputIfAddrs {
if netAddr.Contains(ifAddr.SockAddr) {
includedIfs = append(includedIfs, ifAddr)
} else {
excludedIfs = append(excludedIfs, ifAddr)
}
}
}
return includedIfs, excludedIfs, nil
} | [
"func",
"IfByNetwork",
"(",
"selectorParam",
"string",
",",
"inputIfAddrs",
"IfAddrs",
")",
"(",
"IfAddrs",
",",
"IfAddrs",
",",
"error",
")",
"{",
"var",
"includedIfs",
",",
"excludedIfs",
"IfAddrs",
"\n",
"for",
"_",
",",
"netStr",
":=",
"range",
"strings"... | // IfByNetwork returns an IfAddrs that are equal to or included within the
// network passed in by selector. | [
"IfByNetwork",
"returns",
"an",
"IfAddrs",
"that",
"are",
"equal",
"to",
"or",
"included",
"within",
"the",
"network",
"passed",
"in",
"by",
"selector",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L704-L722 |
18,523 | hashicorp/go-sockaddr | ifaddrs.go | IfAddrsMath | func IfAddrsMath(operation, value string, inputIfAddrs IfAddrs) (IfAddrs, error) {
outputAddrs := make(IfAddrs, 0, len(inputIfAddrs))
for _, ifAddr := range inputIfAddrs {
result, err := IfAddrMath(operation, value, ifAddr)
if err != nil {
return IfAddrs{}, fmt.Errorf("unable to perform an IPMath operation on %s: %v", ifAddr, err)
}
outputAddrs = append(outputAddrs, result)
}
return outputAddrs, nil
} | go | func IfAddrsMath(operation, value string, inputIfAddrs IfAddrs) (IfAddrs, error) {
outputAddrs := make(IfAddrs, 0, len(inputIfAddrs))
for _, ifAddr := range inputIfAddrs {
result, err := IfAddrMath(operation, value, ifAddr)
if err != nil {
return IfAddrs{}, fmt.Errorf("unable to perform an IPMath operation on %s: %v", ifAddr, err)
}
outputAddrs = append(outputAddrs, result)
}
return outputAddrs, nil
} | [
"func",
"IfAddrsMath",
"(",
"operation",
",",
"value",
"string",
",",
"inputIfAddrs",
"IfAddrs",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"outputAddrs",
":=",
"make",
"(",
"IfAddrs",
",",
"0",
",",
"len",
"(",
"inputIfAddrs",
")",
")",
"\n",
"for",
... | // IfAddrsMath will apply an IfAddrMath operation each IfAddr struct. Any
// failure will result in zero results. | [
"IfAddrsMath",
"will",
"apply",
"an",
"IfAddrMath",
"operation",
"each",
"IfAddr",
"struct",
".",
"Any",
"failure",
"will",
"result",
"in",
"zero",
"results",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L951-L961 |
18,524 | hashicorp/go-sockaddr | ifaddrs.go | ExcludeIfs | func ExcludeIfs(selectorName, selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, error) {
var excludedIfs IfAddrs
var err error
switch strings.ToLower(selectorName) {
case "address":
_, excludedIfs, err = IfByAddress(selectorParam, inputIfAddrs)
case "flag", "flags":
_, excludedIfs, err = IfByFlag(selectorParam, inputIfAddrs)
case "name":
_, excludedIfs, err = IfByName(selectorParam, inputIfAddrs)
case "network":
_, excludedIfs, err = IfByNetwork(selectorParam, inputIfAddrs)
case "port":
_, excludedIfs, err = IfByPort(selectorParam, inputIfAddrs)
case "rfc", "rfcs":
_, excludedIfs, err = IfByRFCs(selectorParam, inputIfAddrs)
case "size":
_, excludedIfs, err = IfByMaskSize(selectorParam, inputIfAddrs)
case "type":
_, excludedIfs, err = IfByType(selectorParam, inputIfAddrs)
default:
return IfAddrs{}, fmt.Errorf("invalid exclude selector %q", selectorName)
}
if err != nil {
return IfAddrs{}, err
}
return excludedIfs, nil
} | go | func ExcludeIfs(selectorName, selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, error) {
var excludedIfs IfAddrs
var err error
switch strings.ToLower(selectorName) {
case "address":
_, excludedIfs, err = IfByAddress(selectorParam, inputIfAddrs)
case "flag", "flags":
_, excludedIfs, err = IfByFlag(selectorParam, inputIfAddrs)
case "name":
_, excludedIfs, err = IfByName(selectorParam, inputIfAddrs)
case "network":
_, excludedIfs, err = IfByNetwork(selectorParam, inputIfAddrs)
case "port":
_, excludedIfs, err = IfByPort(selectorParam, inputIfAddrs)
case "rfc", "rfcs":
_, excludedIfs, err = IfByRFCs(selectorParam, inputIfAddrs)
case "size":
_, excludedIfs, err = IfByMaskSize(selectorParam, inputIfAddrs)
case "type":
_, excludedIfs, err = IfByType(selectorParam, inputIfAddrs)
default:
return IfAddrs{}, fmt.Errorf("invalid exclude selector %q", selectorName)
}
if err != nil {
return IfAddrs{}, err
}
return excludedIfs, nil
} | [
"func",
"ExcludeIfs",
"(",
"selectorName",
",",
"selectorParam",
"string",
",",
"inputIfAddrs",
"IfAddrs",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"var",
"excludedIfs",
"IfAddrs",
"\n",
"var",
"err",
"error",
"\n\n",
"switch",
"strings",
".",
"ToLower",
... | // ExcludeIfs returns an IfAddrs based on the passed in selector. | [
"ExcludeIfs",
"returns",
"an",
"IfAddrs",
"based",
"on",
"the",
"passed",
"in",
"selector",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L997-L1027 |
18,525 | hashicorp/go-sockaddr | ifaddrs.go | SortIfBy | func SortIfBy(selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, error) {
sortedIfs := append(IfAddrs(nil), inputIfAddrs...)
clauses := strings.Split(selectorParam, ",")
sortFuncs := make([]CmpIfAddrFunc, len(clauses))
for i, clause := range clauses {
switch strings.TrimSpace(strings.ToLower(clause)) {
case "+address", "address":
// The "address" selector returns an array of IfAddrs
// ordered by the network address. IfAddrs that are not
// comparable will be at the end of the list and in a
// non-deterministic order.
sortFuncs[i] = AscIfAddress
case "-address":
sortFuncs[i] = DescIfAddress
case "+default", "default":
sortFuncs[i] = AscIfDefault
case "-default":
sortFuncs[i] = DescIfDefault
case "+name", "name":
// The "name" selector returns an array of IfAddrs
// ordered by the interface name.
sortFuncs[i] = AscIfName
case "-name":
sortFuncs[i] = DescIfName
case "+port", "port":
// The "port" selector returns an array of IfAddrs
// ordered by the port, if included in the IfAddr.
// IfAddrs that are not comparable will be at the end of
// the list and in a non-deterministic order.
sortFuncs[i] = AscIfPort
case "-port":
sortFuncs[i] = DescIfPort
case "+private", "private":
// The "private" selector returns an array of IfAddrs
// ordered by private addresses first. IfAddrs that are
// not comparable will be at the end of the list and in
// a non-deterministic order.
sortFuncs[i] = AscIfPrivate
case "-private":
sortFuncs[i] = DescIfPrivate
case "+size", "size":
// The "size" selector returns an array of IfAddrs
// ordered by the size of the network mask, smaller mask
// (larger number of hosts per network) to largest
// (e.g. a /24 sorts before a /32).
sortFuncs[i] = AscIfNetworkSize
case "-size":
sortFuncs[i] = DescIfNetworkSize
case "+type", "type":
// The "type" selector returns an array of IfAddrs
// ordered by the type of the IfAddr. The sort order is
// Unix, IPv4, then IPv6.
sortFuncs[i] = AscIfType
case "-type":
sortFuncs[i] = DescIfType
default:
// Return an empty list for invalid sort types.
return IfAddrs{}, fmt.Errorf("unknown sort type: %q", clause)
}
}
OrderedIfAddrBy(sortFuncs...).Sort(sortedIfs)
return sortedIfs, nil
} | go | func SortIfBy(selectorParam string, inputIfAddrs IfAddrs) (IfAddrs, error) {
sortedIfs := append(IfAddrs(nil), inputIfAddrs...)
clauses := strings.Split(selectorParam, ",")
sortFuncs := make([]CmpIfAddrFunc, len(clauses))
for i, clause := range clauses {
switch strings.TrimSpace(strings.ToLower(clause)) {
case "+address", "address":
// The "address" selector returns an array of IfAddrs
// ordered by the network address. IfAddrs that are not
// comparable will be at the end of the list and in a
// non-deterministic order.
sortFuncs[i] = AscIfAddress
case "-address":
sortFuncs[i] = DescIfAddress
case "+default", "default":
sortFuncs[i] = AscIfDefault
case "-default":
sortFuncs[i] = DescIfDefault
case "+name", "name":
// The "name" selector returns an array of IfAddrs
// ordered by the interface name.
sortFuncs[i] = AscIfName
case "-name":
sortFuncs[i] = DescIfName
case "+port", "port":
// The "port" selector returns an array of IfAddrs
// ordered by the port, if included in the IfAddr.
// IfAddrs that are not comparable will be at the end of
// the list and in a non-deterministic order.
sortFuncs[i] = AscIfPort
case "-port":
sortFuncs[i] = DescIfPort
case "+private", "private":
// The "private" selector returns an array of IfAddrs
// ordered by private addresses first. IfAddrs that are
// not comparable will be at the end of the list and in
// a non-deterministic order.
sortFuncs[i] = AscIfPrivate
case "-private":
sortFuncs[i] = DescIfPrivate
case "+size", "size":
// The "size" selector returns an array of IfAddrs
// ordered by the size of the network mask, smaller mask
// (larger number of hosts per network) to largest
// (e.g. a /24 sorts before a /32).
sortFuncs[i] = AscIfNetworkSize
case "-size":
sortFuncs[i] = DescIfNetworkSize
case "+type", "type":
// The "type" selector returns an array of IfAddrs
// ordered by the type of the IfAddr. The sort order is
// Unix, IPv4, then IPv6.
sortFuncs[i] = AscIfType
case "-type":
sortFuncs[i] = DescIfType
default:
// Return an empty list for invalid sort types.
return IfAddrs{}, fmt.Errorf("unknown sort type: %q", clause)
}
}
OrderedIfAddrBy(sortFuncs...).Sort(sortedIfs)
return sortedIfs, nil
} | [
"func",
"SortIfBy",
"(",
"selectorParam",
"string",
",",
"inputIfAddrs",
"IfAddrs",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"sortedIfs",
":=",
"append",
"(",
"IfAddrs",
"(",
"nil",
")",
",",
"inputIfAddrs",
"...",
")",
"\n\n",
"clauses",
":=",
"string... | // SortIfBy returns an IfAddrs sorted based on the passed in selector. Multiple
// sort clauses can be passed in as a comma delimited list without whitespace. | [
"SortIfBy",
"returns",
"an",
"IfAddrs",
"sorted",
"based",
"on",
"the",
"passed",
"in",
"selector",
".",
"Multiple",
"sort",
"clauses",
"can",
"be",
"passed",
"in",
"as",
"a",
"comma",
"delimited",
"list",
"without",
"whitespace",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L1031-L1097 |
18,526 | hashicorp/go-sockaddr | ifaddrs.go | UniqueIfAddrsBy | func UniqueIfAddrsBy(selectorName string, inputIfAddrs IfAddrs) (IfAddrs, error) {
attrName := strings.ToLower(selectorName)
ifs := make(IfAddrs, 0, len(inputIfAddrs))
var lastMatch string
for _, ifAddr := range inputIfAddrs {
var out string
switch attrName {
case "address":
out = ifAddr.SockAddr.String()
case "name":
out = ifAddr.Name
default:
return nil, fmt.Errorf("unsupported unique constraint %+q", selectorName)
}
switch {
case lastMatch == "", lastMatch != out:
lastMatch = out
ifs = append(ifs, ifAddr)
case lastMatch == out:
continue
}
}
return ifs, nil
} | go | func UniqueIfAddrsBy(selectorName string, inputIfAddrs IfAddrs) (IfAddrs, error) {
attrName := strings.ToLower(selectorName)
ifs := make(IfAddrs, 0, len(inputIfAddrs))
var lastMatch string
for _, ifAddr := range inputIfAddrs {
var out string
switch attrName {
case "address":
out = ifAddr.SockAddr.String()
case "name":
out = ifAddr.Name
default:
return nil, fmt.Errorf("unsupported unique constraint %+q", selectorName)
}
switch {
case lastMatch == "", lastMatch != out:
lastMatch = out
ifs = append(ifs, ifAddr)
case lastMatch == out:
continue
}
}
return ifs, nil
} | [
"func",
"UniqueIfAddrsBy",
"(",
"selectorName",
"string",
",",
"inputIfAddrs",
"IfAddrs",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"attrName",
":=",
"strings",
".",
"ToLower",
"(",
"selectorName",
")",
"\n\n",
"ifs",
":=",
"make",
"(",
"IfAddrs",
",",
... | // UniqueIfAddrsBy creates a unique set of IfAddrs based on the matching
// selector. UniqueIfAddrsBy assumes the input has already been sorted. | [
"UniqueIfAddrsBy",
"creates",
"a",
"unique",
"set",
"of",
"IfAddrs",
"based",
"on",
"the",
"matching",
"selector",
".",
"UniqueIfAddrsBy",
"assumes",
"the",
"input",
"has",
"already",
"been",
"sorted",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L1101-L1127 |
18,527 | hashicorp/go-sockaddr | ifaddrs.go | JoinIfAddrs | func JoinIfAddrs(selectorName string, joinStr string, inputIfAddrs IfAddrs) (string, error) {
outputs := make([]string, 0, len(inputIfAddrs))
attrName := AttrName(strings.ToLower(selectorName))
for _, ifAddr := range inputIfAddrs {
var attrVal string
var err error
attrVal, err = ifAddr.Attr(attrName)
if err != nil {
return "", err
}
outputs = append(outputs, attrVal)
}
return strings.Join(outputs, joinStr), nil
} | go | func JoinIfAddrs(selectorName string, joinStr string, inputIfAddrs IfAddrs) (string, error) {
outputs := make([]string, 0, len(inputIfAddrs))
attrName := AttrName(strings.ToLower(selectorName))
for _, ifAddr := range inputIfAddrs {
var attrVal string
var err error
attrVal, err = ifAddr.Attr(attrName)
if err != nil {
return "", err
}
outputs = append(outputs, attrVal)
}
return strings.Join(outputs, joinStr), nil
} | [
"func",
"JoinIfAddrs",
"(",
"selectorName",
"string",
",",
"joinStr",
"string",
",",
"inputIfAddrs",
"IfAddrs",
")",
"(",
"string",
",",
"error",
")",
"{",
"outputs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"inputIfAddrs",
")",
... | // JoinIfAddrs joins an IfAddrs and returns a string | [
"JoinIfAddrs",
"joins",
"an",
"IfAddrs",
"and",
"returns",
"a",
"string"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L1130-L1144 |
18,528 | hashicorp/go-sockaddr | ifaddrs.go | LimitIfAddrs | func LimitIfAddrs(lim uint, in IfAddrs) (IfAddrs, error) {
// Clamp the limit to the length of the array
if int(lim) > len(in) {
lim = uint(len(in))
}
return in[0:lim], nil
} | go | func LimitIfAddrs(lim uint, in IfAddrs) (IfAddrs, error) {
// Clamp the limit to the length of the array
if int(lim) > len(in) {
lim = uint(len(in))
}
return in[0:lim], nil
} | [
"func",
"LimitIfAddrs",
"(",
"lim",
"uint",
",",
"in",
"IfAddrs",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"// Clamp the limit to the length of the array",
"if",
"int",
"(",
"lim",
")",
">",
"len",
"(",
"in",
")",
"{",
"lim",
"=",
"uint",
"(",
"len",... | // LimitIfAddrs returns a slice of IfAddrs based on the specified limit. | [
"LimitIfAddrs",
"returns",
"a",
"slice",
"of",
"IfAddrs",
"based",
"on",
"the",
"specified",
"limit",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L1147-L1154 |
18,529 | hashicorp/go-sockaddr | ifaddrs.go | OffsetIfAddrs | func OffsetIfAddrs(off int, in IfAddrs) (IfAddrs, error) {
var end bool
if off < 0 {
end = true
off = off * -1
}
if off > len(in) {
return IfAddrs{}, fmt.Errorf("unable to seek past the end of the interface array: offset (%d) exceeds the number of interfaces (%d)", off, len(in))
}
if end {
return in[len(in)-off:], nil
}
return in[off:], nil
} | go | func OffsetIfAddrs(off int, in IfAddrs) (IfAddrs, error) {
var end bool
if off < 0 {
end = true
off = off * -1
}
if off > len(in) {
return IfAddrs{}, fmt.Errorf("unable to seek past the end of the interface array: offset (%d) exceeds the number of interfaces (%d)", off, len(in))
}
if end {
return in[len(in)-off:], nil
}
return in[off:], nil
} | [
"func",
"OffsetIfAddrs",
"(",
"off",
"int",
",",
"in",
"IfAddrs",
")",
"(",
"IfAddrs",
",",
"error",
")",
"{",
"var",
"end",
"bool",
"\n",
"if",
"off",
"<",
"0",
"{",
"end",
"=",
"true",
"\n",
"off",
"=",
"off",
"*",
"-",
"1",
"\n",
"}",
"\n\n"... | // OffsetIfAddrs returns a slice of IfAddrs based on the specified offset. | [
"OffsetIfAddrs",
"returns",
"a",
"slice",
"of",
"IfAddrs",
"based",
"on",
"the",
"specified",
"offset",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L1157-L1172 |
18,530 | hashicorp/go-sockaddr | ifaddrs.go | parseDefaultIfNameWindows | func parseDefaultIfNameWindows(routeOut, ipconfigOut string) (string, error) {
defaultIPAddr, err := parseDefaultIPAddrWindowsRoute(routeOut)
if err != nil {
return "", err
}
ifName, err := parseDefaultIfNameWindowsIPConfig(defaultIPAddr, ipconfigOut)
if err != nil {
return "", err
}
return ifName, nil
} | go | func parseDefaultIfNameWindows(routeOut, ipconfigOut string) (string, error) {
defaultIPAddr, err := parseDefaultIPAddrWindowsRoute(routeOut)
if err != nil {
return "", err
}
ifName, err := parseDefaultIfNameWindowsIPConfig(defaultIPAddr, ipconfigOut)
if err != nil {
return "", err
}
return ifName, nil
} | [
"func",
"parseDefaultIfNameWindows",
"(",
"routeOut",
",",
"ipconfigOut",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"defaultIPAddr",
",",
"err",
":=",
"parseDefaultIPAddrWindowsRoute",
"(",
"routeOut",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ret... | // parseDefaultIfNameWindows parses the default interface from `netstat -rn` and
// `ipconfig` on Windows. | [
"parseDefaultIfNameWindows",
"parses",
"the",
"default",
"interface",
"from",
"netstat",
"-",
"rn",
"and",
"ipconfig",
"on",
"Windows",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L1244-L1256 |
18,531 | hashicorp/go-sockaddr | ifaddrs.go | parseDefaultIfNameWindowsIPConfig | func parseDefaultIfNameWindowsIPConfig(defaultIPAddr, routeOut string) (string, error) {
lines := strings.Split(routeOut, "\n")
ifNameRe := ifNameRE.Copy()
ipAddrRe := ipAddrRE.Copy()
var ifName string
for _, line := range lines {
switch ifNameMatches := ifNameRe.FindStringSubmatch(line); {
case len(ifNameMatches) > 1:
ifName = ifNameMatches[1]
continue
}
switch ipAddrMatches := ipAddrRe.FindStringSubmatch(line); {
case len(ipAddrMatches) > 1 && ipAddrMatches[1] == defaultIPAddr:
return ifName, nil
}
}
return "", errors.New("No default interface found with matching IP")
} | go | func parseDefaultIfNameWindowsIPConfig(defaultIPAddr, routeOut string) (string, error) {
lines := strings.Split(routeOut, "\n")
ifNameRe := ifNameRE.Copy()
ipAddrRe := ipAddrRE.Copy()
var ifName string
for _, line := range lines {
switch ifNameMatches := ifNameRe.FindStringSubmatch(line); {
case len(ifNameMatches) > 1:
ifName = ifNameMatches[1]
continue
}
switch ipAddrMatches := ipAddrRe.FindStringSubmatch(line); {
case len(ipAddrMatches) > 1 && ipAddrMatches[1] == defaultIPAddr:
return ifName, nil
}
}
return "", errors.New("No default interface found with matching IP")
} | [
"func",
"parseDefaultIfNameWindowsIPConfig",
"(",
"defaultIPAddr",
",",
"routeOut",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"lines",
":=",
"strings",
".",
"Split",
"(",
"routeOut",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"ifNameRe",
":=",
"ifNameRE"... | // parseDefaultIfNameWindowsIPConfig parses the output of `ipconfig` to find the
// interface name forwarding traffic to the default gateway. | [
"parseDefaultIfNameWindowsIPConfig",
"parses",
"the",
"output",
"of",
"ipconfig",
"to",
"find",
"the",
"interface",
"name",
"forwarding",
"traffic",
"to",
"the",
"default",
"gateway",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddrs.go#L1285-L1304 |
18,532 | hashicorp/go-sockaddr | ipv4addr.go | AddressBinString | func (ipv4 IPv4Addr) AddressBinString() string {
return fmt.Sprintf("%032s", strconv.FormatUint(uint64(ipv4.Address), 2))
} | go | func (ipv4 IPv4Addr) AddressBinString() string {
return fmt.Sprintf("%032s", strconv.FormatUint(uint64(ipv4.Address), 2))
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"AddressBinString",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"ipv4",
".",
"Address",
")",
",",
"2",
")",
")",
"\n",
"}"
] | // AddressBinString returns a string with the IPv4Addr's Address represented
// as a sequence of '0' and '1' characters. This method is useful for
// debugging or by operators who want to inspect an address. | [
"AddressBinString",
"returns",
"a",
"string",
"with",
"the",
"IPv4Addr",
"s",
"Address",
"represented",
"as",
"a",
"sequence",
"of",
"0",
"and",
"1",
"characters",
".",
"This",
"method",
"is",
"useful",
"for",
"debugging",
"or",
"by",
"operators",
"who",
"wa... | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L136-L138 |
18,533 | hashicorp/go-sockaddr | ipv4addr.go | BroadcastAddress | func (ipv4 IPv4Addr) BroadcastAddress() IPv4Network {
return IPv4Network(uint32(ipv4.Address)&uint32(ipv4.Mask) | ^uint32(ipv4.Mask))
} | go | func (ipv4 IPv4Addr) BroadcastAddress() IPv4Network {
return IPv4Network(uint32(ipv4.Address)&uint32(ipv4.Mask) | ^uint32(ipv4.Mask))
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"BroadcastAddress",
"(",
")",
"IPv4Network",
"{",
"return",
"IPv4Network",
"(",
"uint32",
"(",
"ipv4",
".",
"Address",
")",
"&",
"uint32",
"(",
"ipv4",
".",
"Mask",
")",
"|",
"^",
"uint32",
"(",
"ipv4",
".",
"Mask"... | // BroadcastAddress returns a IPv4Network of the IPv4Addr's broadcast
// address. | [
"BroadcastAddress",
"returns",
"a",
"IPv4Network",
"of",
"the",
"IPv4Addr",
"s",
"broadcast",
"address",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L162-L164 |
18,534 | hashicorp/go-sockaddr | ipv4addr.go | ContainsAddress | func (ipv4 IPv4Addr) ContainsAddress(x IPv4Address) bool {
return IPv4Address(ipv4.NetworkAddress()) <= x &&
IPv4Address(ipv4.BroadcastAddress()) >= x
} | go | func (ipv4 IPv4Addr) ContainsAddress(x IPv4Address) bool {
return IPv4Address(ipv4.NetworkAddress()) <= x &&
IPv4Address(ipv4.BroadcastAddress()) >= x
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"ContainsAddress",
"(",
"x",
"IPv4Address",
")",
"bool",
"{",
"return",
"IPv4Address",
"(",
"ipv4",
".",
"NetworkAddress",
"(",
")",
")",
"<=",
"x",
"&&",
"IPv4Address",
"(",
"ipv4",
".",
"BroadcastAddress",
"(",
")",
... | // ContainsAddress returns true if the IPv4Address is contained within the
// receiver. | [
"ContainsAddress",
"returns",
"true",
"if",
"the",
"IPv4Address",
"is",
"contained",
"within",
"the",
"receiver",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L262-L265 |
18,535 | hashicorp/go-sockaddr | ipv4addr.go | ContainsNetwork | func (ipv4 IPv4Addr) ContainsNetwork(x IPv4Addr) bool {
return ipv4.NetworkAddress() <= x.NetworkAddress() &&
ipv4.BroadcastAddress() >= x.BroadcastAddress()
} | go | func (ipv4 IPv4Addr) ContainsNetwork(x IPv4Addr) bool {
return ipv4.NetworkAddress() <= x.NetworkAddress() &&
ipv4.BroadcastAddress() >= x.BroadcastAddress()
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"ContainsNetwork",
"(",
"x",
"IPv4Addr",
")",
"bool",
"{",
"return",
"ipv4",
".",
"NetworkAddress",
"(",
")",
"<=",
"x",
".",
"NetworkAddress",
"(",
")",
"&&",
"ipv4",
".",
"BroadcastAddress",
"(",
")",
">=",
"x",
... | // ContainsNetwork returns true if the network from IPv4Addr is contained
// within the receiver. | [
"ContainsNetwork",
"returns",
"true",
"if",
"the",
"network",
"from",
"IPv4Addr",
"is",
"contained",
"within",
"the",
"receiver",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L269-L272 |
18,536 | hashicorp/go-sockaddr | ipv4addr.go | LastUsable | func (ipv4 IPv4Addr) LastUsable() IPAddr {
addr := ipv4.BroadcastAddress()
// If /32, return the address itself. If /31 assume a point-to-point
// link and return the upper address.
if ipv4.Maskbits() < 31 {
addr--
}
return IPv4Addr{
Address: IPv4Address(addr),
Mask: IPv4HostMask,
}
} | go | func (ipv4 IPv4Addr) LastUsable() IPAddr {
addr := ipv4.BroadcastAddress()
// If /32, return the address itself. If /31 assume a point-to-point
// link and return the upper address.
if ipv4.Maskbits() < 31 {
addr--
}
return IPv4Addr{
Address: IPv4Address(addr),
Mask: IPv4HostMask,
}
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"LastUsable",
"(",
")",
"IPAddr",
"{",
"addr",
":=",
"ipv4",
".",
"BroadcastAddress",
"(",
")",
"\n\n",
"// If /32, return the address itself. If /31 assume a point-to-point",
"// link and return the upper address.",
"if",
"ipv4",
"."... | // LastUsable returns the last address before the broadcast address in a
// given network. | [
"LastUsable",
"returns",
"the",
"last",
"address",
"before",
"the",
"broadcast",
"address",
"in",
"a",
"given",
"network",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L359-L372 |
18,537 | hashicorp/go-sockaddr | ipv4addr.go | MustIPv4Addr | func MustIPv4Addr(addr string) IPv4Addr {
ipv4, err := NewIPv4Addr(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create an IPv4Addr from %+q: %v", addr, err))
}
return ipv4
} | go | func MustIPv4Addr(addr string) IPv4Addr {
ipv4, err := NewIPv4Addr(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create an IPv4Addr from %+q: %v", addr, err))
}
return ipv4
} | [
"func",
"MustIPv4Addr",
"(",
"addr",
"string",
")",
"IPv4Addr",
"{",
"ipv4",
",",
"err",
":=",
"NewIPv4Addr",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"addr",
",",
"err",
")",... | // MustIPv4Addr is a helper method that must return an IPv4Addr or panic on
// invalid input. | [
"MustIPv4Addr",
"is",
"a",
"helper",
"method",
"that",
"must",
"return",
"an",
"IPv4Addr",
"or",
"panic",
"on",
"invalid",
"input",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L405-L411 |
18,538 | hashicorp/go-sockaddr | ipv4addr.go | NetIPMask | func (ipv4 IPv4Addr) NetIPMask() *net.IPMask {
ipv4Mask := net.IPMask{}
ipv4Mask = make(net.IPMask, IPv4len)
binary.BigEndian.PutUint32(ipv4Mask, uint32(ipv4.Mask))
return &ipv4Mask
} | go | func (ipv4 IPv4Addr) NetIPMask() *net.IPMask {
ipv4Mask := net.IPMask{}
ipv4Mask = make(net.IPMask, IPv4len)
binary.BigEndian.PutUint32(ipv4Mask, uint32(ipv4.Mask))
return &ipv4Mask
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"NetIPMask",
"(",
")",
"*",
"net",
".",
"IPMask",
"{",
"ipv4Mask",
":=",
"net",
".",
"IPMask",
"{",
"}",
"\n",
"ipv4Mask",
"=",
"make",
"(",
"net",
".",
"IPMask",
",",
"IPv4len",
")",
"\n",
"binary",
".",
"BigE... | // NetIPMask create a new net.IPMask from the IPv4Addr. | [
"NetIPMask",
"create",
"a",
"new",
"net",
".",
"IPMask",
"from",
"the",
"IPv4Addr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L422-L427 |
18,539 | hashicorp/go-sockaddr | ipv4addr.go | NetIPNet | func (ipv4 IPv4Addr) NetIPNet() *net.IPNet {
ipv4net := &net.IPNet{}
ipv4net.IP = make(net.IP, IPv4len)
binary.BigEndian.PutUint32(ipv4net.IP, uint32(ipv4.NetworkAddress()))
ipv4net.Mask = *ipv4.NetIPMask()
return ipv4net
} | go | func (ipv4 IPv4Addr) NetIPNet() *net.IPNet {
ipv4net := &net.IPNet{}
ipv4net.IP = make(net.IP, IPv4len)
binary.BigEndian.PutUint32(ipv4net.IP, uint32(ipv4.NetworkAddress()))
ipv4net.Mask = *ipv4.NetIPMask()
return ipv4net
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"NetIPNet",
"(",
")",
"*",
"net",
".",
"IPNet",
"{",
"ipv4net",
":=",
"&",
"net",
".",
"IPNet",
"{",
"}",
"\n",
"ipv4net",
".",
"IP",
"=",
"make",
"(",
"net",
".",
"IP",
",",
"IPv4len",
")",
"\n",
"binary",
... | // NetIPNet create a new net.IPNet from the IPv4Addr. | [
"NetIPNet",
"create",
"a",
"new",
"net",
".",
"IPNet",
"from",
"the",
"IPv4Addr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L430-L436 |
18,540 | hashicorp/go-sockaddr | ipv4addr.go | NetworkAddress | func (ipv4 IPv4Addr) NetworkAddress() IPv4Network {
return IPv4Network(uint32(ipv4.Address) & uint32(ipv4.Mask))
} | go | func (ipv4 IPv4Addr) NetworkAddress() IPv4Network {
return IPv4Network(uint32(ipv4.Address) & uint32(ipv4.Mask))
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"NetworkAddress",
"(",
")",
"IPv4Network",
"{",
"return",
"IPv4Network",
"(",
"uint32",
"(",
"ipv4",
".",
"Address",
")",
"&",
"uint32",
"(",
"ipv4",
".",
"Mask",
")",
")",
"\n",
"}"
] | // NetworkAddress returns an IPv4Network of the IPv4Addr's network address. | [
"NetworkAddress",
"returns",
"an",
"IPv4Network",
"of",
"the",
"IPv4Addr",
"s",
"network",
"address",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L447-L449 |
18,541 | hashicorp/go-sockaddr | ipv4addr.go | Octets | func (ipv4 IPv4Addr) Octets() []int {
return []int{
int(ipv4.Address >> 24),
int((ipv4.Address >> 16) & 0xff),
int((ipv4.Address >> 8) & 0xff),
int(ipv4.Address & 0xff),
}
} | go | func (ipv4 IPv4Addr) Octets() []int {
return []int{
int(ipv4.Address >> 24),
int((ipv4.Address >> 16) & 0xff),
int((ipv4.Address >> 8) & 0xff),
int(ipv4.Address & 0xff),
}
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"Octets",
"(",
")",
"[",
"]",
"int",
"{",
"return",
"[",
"]",
"int",
"{",
"int",
"(",
"ipv4",
".",
"Address",
">>",
"24",
")",
",",
"int",
"(",
"(",
"ipv4",
".",
"Address",
">>",
"16",
")",
"&",
"0xff",
"... | // Octets returns a slice of the four octets in an IPv4Addr's Address. The
// order of the bytes is big endian. | [
"Octets",
"returns",
"a",
"slice",
"of",
"the",
"four",
"octets",
"in",
"an",
"IPv4Addr",
"s",
"Address",
".",
"The",
"order",
"of",
"the",
"bytes",
"is",
"big",
"endian",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L453-L460 |
18,542 | hashicorp/go-sockaddr | ipv4addr.go | String | func (ipv4 IPv4Addr) String() string {
if ipv4.Port != 0 {
return fmt.Sprintf("%s:%d", ipv4.NetIP().String(), ipv4.Port)
}
if ipv4.Maskbits() == 32 {
return ipv4.NetIP().String()
}
return fmt.Sprintf("%s/%d", ipv4.NetIP().String(), ipv4.Maskbits())
} | go | func (ipv4 IPv4Addr) String() string {
if ipv4.Port != 0 {
return fmt.Sprintf("%s:%d", ipv4.NetIP().String(), ipv4.Port)
}
if ipv4.Maskbits() == 32 {
return ipv4.NetIP().String()
}
return fmt.Sprintf("%s/%d", ipv4.NetIP().String(), ipv4.Maskbits())
} | [
"func",
"(",
"ipv4",
"IPv4Addr",
")",
"String",
"(",
")",
"string",
"{",
"if",
"ipv4",
".",
"Port",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ipv4",
".",
"NetIP",
"(",
")",
".",
"String",
"(",
")",
",",
"ipv4",
"."... | // String returns a string representation of the IPv4Addr | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"IPv4Addr"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L463-L473 |
18,543 | hashicorp/go-sockaddr | ipv4addr.go | IPv4AddrAttr | func IPv4AddrAttr(ipv4 IPv4Addr, selector AttrName) string {
fn, found := ipv4AddrAttrMap[selector]
if !found {
return ""
}
return fn(ipv4)
} | go | func IPv4AddrAttr(ipv4 IPv4Addr, selector AttrName) string {
fn, found := ipv4AddrAttrMap[selector]
if !found {
return ""
}
return fn(ipv4)
} | [
"func",
"IPv4AddrAttr",
"(",
"ipv4",
"IPv4Addr",
",",
"selector",
"AttrName",
")",
"string",
"{",
"fn",
",",
"found",
":=",
"ipv4AddrAttrMap",
"[",
"selector",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fn",
... | // IPv4AddrAttr returns a string representation of an attribute for the given
// IPv4Addr. | [
"IPv4AddrAttr",
"returns",
"a",
"string",
"representation",
"of",
"an",
"attribute",
"for",
"the",
"given",
"IPv4Addr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv4addr.go#L482-L489 |
18,544 | hashicorp/go-sockaddr | ipaddr.go | NewIPAddr | func NewIPAddr(addr string) (IPAddr, error) {
ipv4Addr, err := NewIPv4Addr(addr)
if err == nil {
return ipv4Addr, nil
}
ipv6Addr, err := NewIPv6Addr(addr)
if err == nil {
return ipv6Addr, nil
}
return nil, fmt.Errorf("invalid IPAddr %v", addr)
} | go | func NewIPAddr(addr string) (IPAddr, error) {
ipv4Addr, err := NewIPv4Addr(addr)
if err == nil {
return ipv4Addr, nil
}
ipv6Addr, err := NewIPv6Addr(addr)
if err == nil {
return ipv6Addr, nil
}
return nil, fmt.Errorf("invalid IPAddr %v", addr)
} | [
"func",
"NewIPAddr",
"(",
"addr",
"string",
")",
"(",
"IPAddr",
",",
"error",
")",
"{",
"ipv4Addr",
",",
"err",
":=",
"NewIPv4Addr",
"(",
"addr",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"ipv4Addr",
",",
"nil",
"\n",
"}",
"\n\n",
"ipv6Addr... | // NewIPAddr creates a new IPAddr from a string. Returns nil if the string is
// not an IPv4 or an IPv6 address. | [
"NewIPAddr",
"creates",
"a",
"new",
"IPAddr",
"from",
"a",
"string",
".",
"Returns",
"nil",
"if",
"the",
"string",
"is",
"not",
"an",
"IPv4",
"or",
"an",
"IPv6",
"address",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipaddr.go#L55-L67 |
18,545 | hashicorp/go-sockaddr | ipaddr.go | IPAddrAttr | func IPAddrAttr(ip IPAddr, selector AttrName) string {
fn, found := ipAddrAttrMap[selector]
if !found {
return ""
}
return fn(ip)
} | go | func IPAddrAttr(ip IPAddr, selector AttrName) string {
fn, found := ipAddrAttrMap[selector]
if !found {
return ""
}
return fn(ip)
} | [
"func",
"IPAddrAttr",
"(",
"ip",
"IPAddr",
",",
"selector",
"AttrName",
")",
"string",
"{",
"fn",
",",
"found",
":=",
"ipAddrAttrMap",
"[",
"selector",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fn",
"(",
... | // IPAddrAttr returns a string representation of an attribute for the given
// IPAddr. | [
"IPAddrAttr",
"returns",
"a",
"string",
"representation",
"of",
"an",
"attribute",
"for",
"the",
"given",
"IPAddr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipaddr.go#L71-L78 |
18,546 | hashicorp/go-sockaddr | ipaddr.go | MustIPAddr | func MustIPAddr(addr string) IPAddr {
ip, err := NewIPAddr(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create an IPAddr from %+q: %v", addr, err))
}
return ip
} | go | func MustIPAddr(addr string) IPAddr {
ip, err := NewIPAddr(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create an IPAddr from %+q: %v", addr, err))
}
return ip
} | [
"func",
"MustIPAddr",
"(",
"addr",
"string",
")",
"IPAddr",
"{",
"ip",
",",
"err",
":=",
"NewIPAddr",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"addr",
",",
"err",
")",
")",
... | // MustIPAddr is a helper method that must return an IPAddr or panic on invalid
// input. | [
"MustIPAddr",
"is",
"a",
"helper",
"method",
"that",
"must",
"return",
"an",
"IPAddr",
"or",
"panic",
"on",
"invalid",
"input",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipaddr.go#L87-L93 |
18,547 | hashicorp/go-sockaddr | sockaddrs.go | Sort | func (ms *multiAddrSorter) Sort(sockAddrs SockAddrs) {
ms.addrs = sockAddrs
sort.Sort(ms)
} | go | func (ms *multiAddrSorter) Sort(sockAddrs SockAddrs) {
ms.addrs = sockAddrs
sort.Sort(ms)
} | [
"func",
"(",
"ms",
"*",
"multiAddrSorter",
")",
"Sort",
"(",
"sockAddrs",
"SockAddrs",
")",
"{",
"ms",
".",
"addrs",
"=",
"sockAddrs",
"\n",
"sort",
".",
"Sort",
"(",
"ms",
")",
"\n",
"}"
] | // Sort sorts the argument slice according to the Cmp functions passed to
// OrderedAddrBy. | [
"Sort",
"sorts",
"the",
"argument",
"slice",
"according",
"to",
"the",
"Cmp",
"functions",
"passed",
"to",
"OrderedAddrBy",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/sockaddrs.go#L26-L29 |
18,548 | hashicorp/go-sockaddr | sockaddrs.go | AscAddress | func AscAddress(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
switch v := p1.(type) {
case IPv4Addr:
return v.CmpAddress(p2)
case IPv6Addr:
return v.CmpAddress(p2)
case UnixSock:
return v.CmpAddress(p2)
default:
return sortDeferDecision
}
} | go | func AscAddress(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
switch v := p1.(type) {
case IPv4Addr:
return v.CmpAddress(p2)
case IPv6Addr:
return v.CmpAddress(p2)
case UnixSock:
return v.CmpAddress(p2)
default:
return sortDeferDecision
}
} | [
"func",
"AscAddress",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"SockAddr",
")",
"int",
"{",
"p1",
":=",
"*",
"p1Ptr",
"\n",
"p2",
":=",
"*",
"p2Ptr",
"\n\n",
"switch",
"v",
":=",
"p1",
".",
"(",
"type",
")",
"{",
"case",
"IPv4Addr",
":",
"return",
"v",
"... | // AscAddress is a sorting function to sort SockAddrs by their respective
// address type. Non-equal types are deferred in the sort. | [
"AscAddress",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"SockAddrs",
"by",
"their",
"respective",
"address",
"type",
".",
"Non",
"-",
"equal",
"types",
"are",
"deferred",
"in",
"the",
"sort",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/sockaddrs.go#L94-L108 |
18,549 | hashicorp/go-sockaddr | sockaddrs.go | AscPort | func AscPort(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
switch v := p1.(type) {
case IPv4Addr:
return v.CmpPort(p2)
case IPv6Addr:
return v.CmpPort(p2)
default:
return sortDeferDecision
}
} | go | func AscPort(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
switch v := p1.(type) {
case IPv4Addr:
return v.CmpPort(p2)
case IPv6Addr:
return v.CmpPort(p2)
default:
return sortDeferDecision
}
} | [
"func",
"AscPort",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"SockAddr",
")",
"int",
"{",
"p1",
":=",
"*",
"p1Ptr",
"\n",
"p2",
":=",
"*",
"p2Ptr",
"\n\n",
"switch",
"v",
":=",
"p1",
".",
"(",
"type",
")",
"{",
"case",
"IPv4Addr",
":",
"return",
"v",
".",... | // AscPort is a sorting function to sort SockAddrs by their respective address
// type. Non-equal types are deferred in the sort. | [
"AscPort",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"SockAddrs",
"by",
"their",
"respective",
"address",
"type",
".",
"Non",
"-",
"equal",
"types",
"are",
"deferred",
"in",
"the",
"sort",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/sockaddrs.go#L112-L124 |
18,550 | hashicorp/go-sockaddr | sockaddrs.go | AscNetworkSize | func AscNetworkSize(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
p1Type := p1.Type()
p2Type := p2.Type()
// Network size operations on non-IP types make no sense
if p1Type != p2Type && p1Type != TypeIP {
return sortDeferDecision
}
ipA := p1.(IPAddr)
ipB := p2.(IPAddr)
return bytes.Compare([]byte(*ipA.NetIPMask()), []byte(*ipB.NetIPMask()))
} | go | func AscNetworkSize(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
p1Type := p1.Type()
p2Type := p2.Type()
// Network size operations on non-IP types make no sense
if p1Type != p2Type && p1Type != TypeIP {
return sortDeferDecision
}
ipA := p1.(IPAddr)
ipB := p2.(IPAddr)
return bytes.Compare([]byte(*ipA.NetIPMask()), []byte(*ipB.NetIPMask()))
} | [
"func",
"AscNetworkSize",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"SockAddr",
")",
"int",
"{",
"p1",
":=",
"*",
"p1Ptr",
"\n",
"p2",
":=",
"*",
"p2Ptr",
"\n",
"p1Type",
":=",
"p1",
".",
"Type",
"(",
")",
"\n",
"p2Type",
":=",
"p2",
".",
"Type",
"(",
")"... | // AscNetworkSize is a sorting function to sort SockAddrs based on their network
// size. Non-equal types are deferred in the sort. | [
"AscNetworkSize",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"SockAddrs",
"based",
"on",
"their",
"network",
"size",
".",
"Non",
"-",
"equal",
"types",
"are",
"deferred",
"in",
"the",
"sort",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/sockaddrs.go#L144-L159 |
18,551 | hashicorp/go-sockaddr | sockaddrs.go | AscType | func AscType(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
p1Type := p1.Type()
p2Type := p2.Type()
switch {
case p1Type < p2Type:
return sortReceiverBeforeArg
case p1Type == p2Type:
return sortDeferDecision
case p1Type > p2Type:
return sortArgBeforeReceiver
default:
return sortDeferDecision
}
} | go | func AscType(p1Ptr, p2Ptr *SockAddr) int {
p1 := *p1Ptr
p2 := *p2Ptr
p1Type := p1.Type()
p2Type := p2.Type()
switch {
case p1Type < p2Type:
return sortReceiverBeforeArg
case p1Type == p2Type:
return sortDeferDecision
case p1Type > p2Type:
return sortArgBeforeReceiver
default:
return sortDeferDecision
}
} | [
"func",
"AscType",
"(",
"p1Ptr",
",",
"p2Ptr",
"*",
"SockAddr",
")",
"int",
"{",
"p1",
":=",
"*",
"p1Ptr",
"\n",
"p2",
":=",
"*",
"p2Ptr",
"\n",
"p1Type",
":=",
"p1",
".",
"Type",
"(",
")",
"\n",
"p2Type",
":=",
"p2",
".",
"Type",
"(",
")",
"\n... | // AscType is a sorting function to sort "more secure" types before
// "less-secure" types. | [
"AscType",
"is",
"a",
"sorting",
"function",
"to",
"sort",
"more",
"secure",
"types",
"before",
"less",
"-",
"secure",
"types",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/sockaddrs.go#L163-L178 |
18,552 | hashicorp/go-sockaddr | sockaddr.go | ToIPAddr | func ToIPAddr(sa SockAddr) *IPAddr {
ipa, ok := sa.(IPAddr)
if !ok {
return nil
}
return &ipa
} | go | func ToIPAddr(sa SockAddr) *IPAddr {
ipa, ok := sa.(IPAddr)
if !ok {
return nil
}
return &ipa
} | [
"func",
"ToIPAddr",
"(",
"sa",
"SockAddr",
")",
"*",
"IPAddr",
"{",
"ipa",
",",
"ok",
":=",
"sa",
".",
"(",
"IPAddr",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"ipa",
"\n",
"}"
] | // ToIPAddr returns an IPAddr type or nil if the type conversion fails. | [
"ToIPAddr",
"returns",
"an",
"IPAddr",
"type",
"or",
"nil",
"if",
"the",
"type",
"conversion",
"fails",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/sockaddr.go#L92-L98 |
18,553 | hashicorp/go-sockaddr | sockaddr.go | SockAddrAttr | func SockAddrAttr(sa SockAddr, selector AttrName) string {
fn, found := sockAddrAttrMap[selector]
if !found {
return ""
}
return fn(sa)
} | go | func SockAddrAttr(sa SockAddr, selector AttrName) string {
fn, found := sockAddrAttrMap[selector]
if !found {
return ""
}
return fn(sa)
} | [
"func",
"SockAddrAttr",
"(",
"sa",
"SockAddr",
",",
"selector",
"AttrName",
")",
"string",
"{",
"fn",
",",
"found",
":=",
"sockAddrAttrMap",
"[",
"selector",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fn",
"... | // SockAddrAttr returns a string representation of an attribute for the given
// SockAddr. | [
"SockAddrAttr",
"returns",
"a",
"string",
"representation",
"of",
"an",
"attribute",
"for",
"the",
"given",
"SockAddr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/sockaddr.go#L132-L139 |
18,554 | Jeffail/gabs | gabs.go | Search | func (g *Container) Search(hierarchy ...string) *Container {
var object interface{}
object = g.Data()
for target := 0; target < len(hierarchy); target++ {
if mmap, ok := object.(map[string]interface{}); ok {
object, ok = mmap[hierarchy[target]]
if !ok {
return nil
}
} else if marray, ok := object.([]interface{}); ok {
tmpArray := []interface{}{}
for _, val := range marray {
tmpGabs := &Container{val}
res := tmpGabs.Search(hierarchy[target:]...)
if res != nil {
tmpArray = append(tmpArray, res.Data())
}
}
if len(tmpArray) == 0 {
return nil
}
return &Container{tmpArray}
} else {
return nil
}
}
return &Container{object}
} | go | func (g *Container) Search(hierarchy ...string) *Container {
var object interface{}
object = g.Data()
for target := 0; target < len(hierarchy); target++ {
if mmap, ok := object.(map[string]interface{}); ok {
object, ok = mmap[hierarchy[target]]
if !ok {
return nil
}
} else if marray, ok := object.([]interface{}); ok {
tmpArray := []interface{}{}
for _, val := range marray {
tmpGabs := &Container{val}
res := tmpGabs.Search(hierarchy[target:]...)
if res != nil {
tmpArray = append(tmpArray, res.Data())
}
}
if len(tmpArray) == 0 {
return nil
}
return &Container{tmpArray}
} else {
return nil
}
}
return &Container{object}
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Search",
"(",
"hierarchy",
"...",
"string",
")",
"*",
"Container",
"{",
"var",
"object",
"interface",
"{",
"}",
"\n\n",
"object",
"=",
"g",
".",
"Data",
"(",
")",
"\n",
"for",
"target",
":=",
"0",
";",
"tar... | // Search - Attempt to find and return an object within the JSON structure by specifying the
// hierarchy of field names to locate the target. If the search encounters an array and has not
// reached the end target then it will iterate each object of the array for the target and return
// all of the results in a JSON array. | [
"Search",
"-",
"Attempt",
"to",
"find",
"and",
"return",
"an",
"object",
"within",
"the",
"JSON",
"structure",
"by",
"specifying",
"the",
"hierarchy",
"of",
"field",
"names",
"to",
"locate",
"the",
"target",
".",
"If",
"the",
"search",
"encounters",
"an",
... | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L93-L121 |
18,555 | Jeffail/gabs | gabs.go | Exists | func (g *Container) Exists(hierarchy ...string) bool {
return g.Search(hierarchy...) != nil
} | go | func (g *Container) Exists(hierarchy ...string) bool {
return g.Search(hierarchy...) != nil
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Exists",
"(",
"hierarchy",
"...",
"string",
")",
"bool",
"{",
"return",
"g",
".",
"Search",
"(",
"hierarchy",
"...",
")",
"!=",
"nil",
"\n",
"}"
] | // Exists - Checks whether a path exists. | [
"Exists",
"-",
"Checks",
"whether",
"a",
"path",
"exists",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L129-L131 |
18,556 | Jeffail/gabs | gabs.go | ExistsP | func (g *Container) ExistsP(path string) bool {
return g.Exists(strings.Split(path, ".")...)
} | go | func (g *Container) ExistsP(path string) bool {
return g.Exists(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ExistsP",
"(",
"path",
"string",
")",
"bool",
"{",
"return",
"g",
".",
"Exists",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ExistsP - Checks whether a dot notation path exists. | [
"ExistsP",
"-",
"Checks",
"whether",
"a",
"dot",
"notation",
"path",
"exists",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L134-L136 |
18,557 | Jeffail/gabs | gabs.go | Index | func (g *Container) Index(index int) *Container {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}
}
return &Container{array[index]}
}
return &Container{nil}
} | go | func (g *Container) Index(index int) *Container {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}
}
return &Container{array[index]}
}
return &Container{nil}
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Index",
"(",
"index",
"int",
")",
"*",
"Container",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"if",
"index",
">="... | // Index - Attempt to find and return an object within a JSON array by index. | [
"Index",
"-",
"Attempt",
"to",
"find",
"and",
"return",
"an",
"object",
"within",
"a",
"JSON",
"array",
"by",
"index",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L139-L147 |
18,558 | Jeffail/gabs | gabs.go | Children | func (g *Container) Children() ([]*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
children := make([]*Container, len(array))
for i := 0; i < len(array); i++ {
children[i] = &Container{array[i]}
}
return children, nil
}
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := []*Container{}
for _, obj := range mmap {
children = append(children, &Container{obj})
}
return children, nil
}
return nil, ErrNotObjOrArray
} | go | func (g *Container) Children() ([]*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
children := make([]*Container, len(array))
for i := 0; i < len(array); i++ {
children[i] = &Container{array[i]}
}
return children, nil
}
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := []*Container{}
for _, obj := range mmap {
children = append(children, &Container{obj})
}
return children, nil
}
return nil, ErrNotObjOrArray
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Children",
"(",
")",
"(",
"[",
"]",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"... | // Children - Return a slice of all the children of the array. This also works for objects, however,
// the children returned for an object will NOT be in order and you lose the names of the returned
// objects this way. | [
"Children",
"-",
"Return",
"a",
"slice",
"of",
"all",
"the",
"children",
"of",
"the",
"array",
".",
"This",
"also",
"works",
"for",
"objects",
"however",
"the",
"children",
"returned",
"for",
"an",
"object",
"will",
"NOT",
"be",
"in",
"order",
"and",
"yo... | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L152-L168 |
18,559 | Jeffail/gabs | gabs.go | ChildrenMap | func (g *Container) ChildrenMap() (map[string]*Container, error) {
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := map[string]*Container{}
for name, obj := range mmap {
children[name] = &Container{obj}
}
return children, nil
}
return nil, ErrNotObj
} | go | func (g *Container) ChildrenMap() (map[string]*Container, error) {
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := map[string]*Container{}
for name, obj := range mmap {
children[name] = &Container{obj}
}
return children, nil
}
return nil, ErrNotObj
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ChildrenMap",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"mmap",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"map",
"[",
"string",
"]",
"interfa... | // ChildrenMap - Return a map of all the children of an object. | [
"ChildrenMap",
"-",
"Return",
"a",
"map",
"of",
"all",
"the",
"children",
"of",
"an",
"object",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L171-L180 |
18,560 | Jeffail/gabs | gabs.go | SetP | func (g *Container) SetP(value interface{}, path string) (*Container, error) {
return g.Set(value, strings.Split(path, ".")...)
} | go | func (g *Container) SetP(value interface{}, path string) (*Container, error) {
return g.Set(value, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"SetP",
"(",
"value",
"interface",
"{",
"}",
",",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Set",
"(",
"value",
",",
"strings",
".",
"Split",
"(",
"path",
"... | // SetP - Does the same as Set, but using a dot notation JSON path. | [
"SetP",
"-",
"Does",
"the",
"same",
"as",
"Set",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L213-L215 |
18,561 | Jeffail/gabs | gabs.go | SetIndex | func (g *Container) SetIndex(value interface{}, index int) (*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}, ErrOutOfBounds
}
array[index] = value
return &Container{array[index]}, nil
}
return &Container{nil}, ErrNotArray
} | go | func (g *Container) SetIndex(value interface{}, index int) (*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}, ErrOutOfBounds
}
array[index] = value
return &Container{array[index]}, nil
}
return &Container{nil}, ErrNotArray
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"SetIndex",
"(",
"value",
"interface",
"{",
"}",
",",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
... | // SetIndex - Set a value of an array element based on the index. | [
"SetIndex",
"-",
"Set",
"a",
"value",
"of",
"an",
"array",
"element",
"based",
"on",
"the",
"index",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L218-L227 |
18,562 | Jeffail/gabs | gabs.go | Object | func (g *Container) Object(path ...string) (*Container, error) {
return g.Set(map[string]interface{}{}, path...)
} | go | func (g *Container) Object(path ...string) (*Container, error) {
return g.Set(map[string]interface{}{}, path...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Object",
"(",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Set",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"path",
"...",
... | // Object - Create a new JSON object at a path. Returns an error if the path contains a collision
// with a non object type. | [
"Object",
"-",
"Create",
"a",
"new",
"JSON",
"object",
"at",
"a",
"path",
".",
"Returns",
"an",
"error",
"if",
"the",
"path",
"contains",
"a",
"collision",
"with",
"a",
"non",
"object",
"type",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L231-L233 |
18,563 | Jeffail/gabs | gabs.go | ObjectP | func (g *Container) ObjectP(path string) (*Container, error) {
return g.Object(strings.Split(path, ".")...)
} | go | func (g *Container) ObjectP(path string) (*Container, error) {
return g.Object(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ObjectP",
"(",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Object",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ObjectP - Does the same as Object, but using a dot notation JSON path. | [
"ObjectP",
"-",
"Does",
"the",
"same",
"as",
"Object",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L236-L238 |
18,564 | Jeffail/gabs | gabs.go | ObjectI | func (g *Container) ObjectI(index int) (*Container, error) {
return g.SetIndex(map[string]interface{}{}, index)
} | go | func (g *Container) ObjectI(index int) (*Container, error) {
return g.SetIndex(map[string]interface{}{}, index)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ObjectI",
"(",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"SetIndex",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"index",
")",
"\n",... | // ObjectI - Create a new JSON object at an array index. Returns an error if the object is not an
// array or the index is out of bounds. | [
"ObjectI",
"-",
"Create",
"a",
"new",
"JSON",
"object",
"at",
"an",
"array",
"index",
".",
"Returns",
"an",
"error",
"if",
"the",
"object",
"is",
"not",
"an",
"array",
"or",
"the",
"index",
"is",
"out",
"of",
"bounds",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L242-L244 |
18,565 | Jeffail/gabs | gabs.go | Array | func (g *Container) Array(path ...string) (*Container, error) {
return g.Set([]interface{}{}, path...)
} | go | func (g *Container) Array(path ...string) (*Container, error) {
return g.Set([]interface{}{}, path...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Array",
"(",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Set",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"path",
"...",
")",
"\n",
"}"
] | // Array - Create a new JSON array at a path. Returns an error if the path contains a collision with
// a non object type. | [
"Array",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"at",
"a",
"path",
".",
"Returns",
"an",
"error",
"if",
"the",
"path",
"contains",
"a",
"collision",
"with",
"a",
"non",
"object",
"type",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L248-L250 |
18,566 | Jeffail/gabs | gabs.go | ArrayP | func (g *Container) ArrayP(path string) (*Container, error) {
return g.Array(strings.Split(path, ".")...)
} | go | func (g *Container) ArrayP(path string) (*Container, error) {
return g.Array(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayP",
"(",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Array",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayP - Does the same as Array, but using a dot notation JSON path. | [
"ArrayP",
"-",
"Does",
"the",
"same",
"as",
"Array",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L253-L255 |
18,567 | Jeffail/gabs | gabs.go | ArrayI | func (g *Container) ArrayI(index int) (*Container, error) {
return g.SetIndex([]interface{}{}, index)
} | go | func (g *Container) ArrayI(index int) (*Container, error) {
return g.SetIndex([]interface{}{}, index)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayI",
"(",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"SetIndex",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"index",
")",
"\n",
"}"
] | // ArrayI - Create a new JSON array at an array index. Returns an error if the object is not an
// array or the index is out of bounds. | [
"ArrayI",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"at",
"an",
"array",
"index",
".",
"Returns",
"an",
"error",
"if",
"the",
"object",
"is",
"not",
"an",
"array",
"or",
"the",
"index",
"is",
"out",
"of",
"bounds",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L259-L261 |
18,568 | Jeffail/gabs | gabs.go | ArrayOfSize | func (g *Container) ArrayOfSize(size int, path ...string) (*Container, error) {
a := make([]interface{}, size)
return g.Set(a, path...)
} | go | func (g *Container) ArrayOfSize(size int, path ...string) (*Container, error) {
a := make([]interface{}, size)
return g.Set(a, path...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayOfSize",
"(",
"size",
"int",
",",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"size",
")",
"\n",
"return... | // ArrayOfSize - Create a new JSON array of a particular size at a path. Returns an error if the
// path contains a collision with a non object type. | [
"ArrayOfSize",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"of",
"a",
"particular",
"size",
"at",
"a",
"path",
".",
"Returns",
"an",
"error",
"if",
"the",
"path",
"contains",
"a",
"collision",
"with",
"a",
"non",
"object",
"type",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L265-L268 |
18,569 | Jeffail/gabs | gabs.go | ArrayOfSizeP | func (g *Container) ArrayOfSizeP(size int, path string) (*Container, error) {
return g.ArrayOfSize(size, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayOfSizeP(size int, path string) (*Container, error) {
return g.ArrayOfSize(size, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayOfSizeP",
"(",
"size",
"int",
",",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"ArrayOfSize",
"(",
"size",
",",
"strings",
".",
"Split",
"(",
"path",
",",
... | // ArrayOfSizeP - Does the same as ArrayOfSize, but using a dot notation JSON path. | [
"ArrayOfSizeP",
"-",
"Does",
"the",
"same",
"as",
"ArrayOfSize",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L271-L273 |
18,570 | Jeffail/gabs | gabs.go | ArrayOfSizeI | func (g *Container) ArrayOfSizeI(size, index int) (*Container, error) {
a := make([]interface{}, size)
return g.SetIndex(a, index)
} | go | func (g *Container) ArrayOfSizeI(size, index int) (*Container, error) {
a := make([]interface{}, size)
return g.SetIndex(a, index)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayOfSizeI",
"(",
"size",
",",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"size",
")",
"\n",
"return",
"g",
".",
... | // ArrayOfSizeI - Create a new JSON array of a particular size at an array index. Returns an error
// if the object is not an array or the index is out of bounds. | [
"ArrayOfSizeI",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"of",
"a",
"particular",
"size",
"at",
"an",
"array",
"index",
".",
"Returns",
"an",
"error",
"if",
"the",
"object",
"is",
"not",
"an",
"array",
"or",
"the",
"index",
"is",
"out",
"of",
"bound... | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L277-L280 |
18,571 | Jeffail/gabs | gabs.go | Delete | func (g *Container) Delete(path ...string) error {
var object interface{}
if g.object == nil {
return ErrNotObj
}
object = g.object
for target := 0; target < len(path); target++ {
if mmap, ok := object.(map[string]interface{}); ok {
if target == len(path)-1 {
if _, ok := mmap[path[target]]; ok {
delete(mmap, path[target])
} else {
return ErrNotObj
}
}
object = mmap[path[target]]
} else {
return ErrNotObj
}
}
return nil
} | go | func (g *Container) Delete(path ...string) error {
var object interface{}
if g.object == nil {
return ErrNotObj
}
object = g.object
for target := 0; target < len(path); target++ {
if mmap, ok := object.(map[string]interface{}); ok {
if target == len(path)-1 {
if _, ok := mmap[path[target]]; ok {
delete(mmap, path[target])
} else {
return ErrNotObj
}
}
object = mmap[path[target]]
} else {
return ErrNotObj
}
}
return nil
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Delete",
"(",
"path",
"...",
"string",
")",
"error",
"{",
"var",
"object",
"interface",
"{",
"}",
"\n\n",
"if",
"g",
".",
"object",
"==",
"nil",
"{",
"return",
"ErrNotObj",
"\n",
"}",
"\n",
"object",
"=",
"... | // Delete - Delete an element at a JSON path, an error is returned if the element does not exist. | [
"Delete",
"-",
"Delete",
"an",
"element",
"at",
"a",
"JSON",
"path",
"an",
"error",
"is",
"returned",
"if",
"the",
"element",
"does",
"not",
"exist",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L283-L305 |
18,572 | Jeffail/gabs | gabs.go | DeleteP | func (g *Container) DeleteP(path string) error {
return g.Delete(strings.Split(path, ".")...)
} | go | func (g *Container) DeleteP(path string) error {
return g.Delete(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"DeleteP",
"(",
"path",
"string",
")",
"error",
"{",
"return",
"g",
".",
"Delete",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // DeleteP - Does the same as Delete, but using a dot notation JSON path. | [
"DeleteP",
"-",
"Does",
"the",
"same",
"as",
"Delete",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L308-L310 |
18,573 | Jeffail/gabs | gabs.go | ArrayAppendP | func (g *Container) ArrayAppendP(value interface{}, path string) error {
return g.ArrayAppend(value, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayAppendP(value interface{}, path string) error {
return g.ArrayAppend(value, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayAppendP",
"(",
"value",
"interface",
"{",
"}",
",",
"path",
"string",
")",
"error",
"{",
"return",
"g",
".",
"ArrayAppend",
"(",
"value",
",",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
... | // ArrayAppendP - Append a value onto a JSON array using a dot notation JSON path. | [
"ArrayAppendP",
"-",
"Append",
"a",
"value",
"onto",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L409-L411 |
18,574 | Jeffail/gabs | gabs.go | ArrayRemove | func (g *Container) ArrayRemove(index int, path ...string) error {
if index < 0 {
return ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return ErrNotArray
}
if index < len(array) {
array = append(array[:index], array[index+1:]...)
} else {
return ErrOutOfBounds
}
_, err := g.Set(array, path...)
return err
} | go | func (g *Container) ArrayRemove(index int, path ...string) error {
if index < 0 {
return ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return ErrNotArray
}
if index < len(array) {
array = append(array[:index], array[index+1:]...)
} else {
return ErrOutOfBounds
}
_, err := g.Set(array, path...)
return err
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayRemove",
"(",
"index",
"int",
",",
"path",
"...",
"string",
")",
"error",
"{",
"if",
"index",
"<",
"0",
"{",
"return",
"ErrOutOfBounds",
"\n",
"}",
"\n",
"array",
",",
"ok",
":=",
"g",
".",
"Search",
"... | // ArrayRemove - Remove an element from a JSON array. | [
"ArrayRemove",
"-",
"Remove",
"an",
"element",
"from",
"a",
"JSON",
"array",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L414-L429 |
18,575 | Jeffail/gabs | gabs.go | ArrayRemoveP | func (g *Container) ArrayRemoveP(index int, path string) error {
return g.ArrayRemove(index, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayRemoveP(index int, path string) error {
return g.ArrayRemove(index, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayRemoveP",
"(",
"index",
"int",
",",
"path",
"string",
")",
"error",
"{",
"return",
"g",
".",
"ArrayRemove",
"(",
"index",
",",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\... | // ArrayRemoveP - Remove an element from a JSON array using a dot notation JSON path. | [
"ArrayRemoveP",
"-",
"Remove",
"an",
"element",
"from",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L432-L434 |
18,576 | Jeffail/gabs | gabs.go | ArrayElement | func (g *Container) ArrayElement(index int, path ...string) (*Container, error) {
if index < 0 {
return &Container{nil}, ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return &Container{nil}, ErrNotArray
}
if index < len(array) {
return &Container{array[index]}, nil
}
return &Container{nil}, ErrOutOfBounds
} | go | func (g *Container) ArrayElement(index int, path ...string) (*Container, error) {
if index < 0 {
return &Container{nil}, ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return &Container{nil}, ErrNotArray
}
if index < len(array) {
return &Container{array[index]}, nil
}
return &Container{nil}, ErrOutOfBounds
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayElement",
"(",
"index",
"int",
",",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"index",
"<",
"0",
"{",
"return",
"&",
"Container",
"{",
"nil",
"}",
",",
"ErrOutO... | // ArrayElement - Access an element from a JSON array. | [
"ArrayElement",
"-",
"Access",
"an",
"element",
"from",
"a",
"JSON",
"array",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L437-L449 |
18,577 | Jeffail/gabs | gabs.go | ArrayElementP | func (g *Container) ArrayElementP(index int, path string) (*Container, error) {
return g.ArrayElement(index, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayElementP(index int, path string) (*Container, error) {
return g.ArrayElement(index, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayElementP",
"(",
"index",
"int",
",",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"ArrayElement",
"(",
"index",
",",
"strings",
".",
"Split",
"(",
"path",
","... | // ArrayElementP - Access an element from a JSON array using a dot notation JSON path. | [
"ArrayElementP",
"-",
"Access",
"an",
"element",
"from",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L452-L454 |
18,578 | Jeffail/gabs | gabs.go | ArrayCount | func (g *Container) ArrayCount(path ...string) (int, error) {
if array, ok := g.Search(path...).Data().([]interface{}); ok {
return len(array), nil
}
return 0, ErrNotArray
} | go | func (g *Container) ArrayCount(path ...string) (int, error) {
if array, ok := g.Search(path...).Data().([]interface{}); ok {
return len(array), nil
}
return 0, ErrNotArray
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayCount",
"(",
"path",
"...",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Search",
"(",
"path",
"...",
")",
".",
"Data",
"(",
")",
".",
"(",
"[",
"... | // ArrayCount - Count the number of elements in a JSON array. | [
"ArrayCount",
"-",
"Count",
"the",
"number",
"of",
"elements",
"in",
"a",
"JSON",
"array",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L457-L462 |
18,579 | Jeffail/gabs | gabs.go | ArrayCountP | func (g *Container) ArrayCountP(path string) (int, error) {
return g.ArrayCount(strings.Split(path, ".")...)
} | go | func (g *Container) ArrayCountP(path string) (int, error) {
return g.ArrayCount(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayCountP",
"(",
"path",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"g",
".",
"ArrayCount",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayCountP - Count the number of elements in a JSON array using a dot notation JSON path. | [
"ArrayCountP",
"-",
"Count",
"the",
"number",
"of",
"elements",
"in",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L465-L467 |
18,580 | Jeffail/gabs | gabs.go | StringIndent | func (g *Container) StringIndent(prefix string, indent string) string {
return string(g.BytesIndent(prefix, indent))
} | go | func (g *Container) StringIndent(prefix string, indent string) string {
return string(g.BytesIndent(prefix, indent))
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"StringIndent",
"(",
"prefix",
"string",
",",
"indent",
"string",
")",
"string",
"{",
"return",
"string",
"(",
"g",
".",
"BytesIndent",
"(",
"prefix",
",",
"indent",
")",
")",
"\n",
"}"
] | // StringIndent - Converts the contained object back to a JSON formatted string with prefix, indent. | [
"StringIndent",
"-",
"Converts",
"the",
"contained",
"object",
"back",
"to",
"a",
"JSON",
"formatted",
"string",
"with",
"prefix",
"indent",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L497-L499 |
18,581 | Jeffail/gabs | gabs.go | EncodeOptHTMLEscape | func EncodeOptHTMLEscape(doEscape bool) EncodeOpt {
return func(e *json.Encoder) {
e.SetEscapeHTML(doEscape)
}
} | go | func EncodeOptHTMLEscape(doEscape bool) EncodeOpt {
return func(e *json.Encoder) {
e.SetEscapeHTML(doEscape)
}
} | [
"func",
"EncodeOptHTMLEscape",
"(",
"doEscape",
"bool",
")",
"EncodeOpt",
"{",
"return",
"func",
"(",
"e",
"*",
"json",
".",
"Encoder",
")",
"{",
"e",
".",
"SetEscapeHTML",
"(",
"doEscape",
")",
"\n",
"}",
"\n",
"}"
] | // EncodeOptHTMLEscape sets the encoder to escape the JSON for html. | [
"EncodeOptHTMLEscape",
"sets",
"the",
"encoder",
"to",
"escape",
"the",
"JSON",
"for",
"html",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L505-L509 |
18,582 | Jeffail/gabs | gabs.go | EncodeOptIndent | func EncodeOptIndent(prefix string, indent string) EncodeOpt {
return func(e *json.Encoder) {
e.SetIndent(prefix, indent)
}
} | go | func EncodeOptIndent(prefix string, indent string) EncodeOpt {
return func(e *json.Encoder) {
e.SetIndent(prefix, indent)
}
} | [
"func",
"EncodeOptIndent",
"(",
"prefix",
"string",
",",
"indent",
"string",
")",
"EncodeOpt",
"{",
"return",
"func",
"(",
"e",
"*",
"json",
".",
"Encoder",
")",
"{",
"e",
".",
"SetIndent",
"(",
"prefix",
",",
"indent",
")",
"\n",
"}",
"\n",
"}"
] | // EncodeOptIndent sets the encoder to indent the JSON output. | [
"EncodeOptIndent",
"sets",
"the",
"encoder",
"to",
"indent",
"the",
"JSON",
"output",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L512-L516 |
18,583 | Jeffail/gabs | gabs.go | ParseJSON | func ParseJSON(sample []byte) (*Container, error) {
var gabs Container
if err := json.Unmarshal(sample, &gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | go | func ParseJSON(sample []byte) (*Container, error) {
var gabs Container
if err := json.Unmarshal(sample, &gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | [
"func",
"ParseJSON",
"(",
"sample",
"[",
"]",
"byte",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"var",
"gabs",
"Container",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"sample",
",",
"&",
"gabs",
".",
"object",
")",
";",
"er... | // ParseJSON - Convert a string into a representation of the parsed JSON. | [
"ParseJSON",
"-",
"Convert",
"a",
"string",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L550-L558 |
18,584 | Jeffail/gabs | gabs.go | ParseJSONDecoder | func ParseJSONDecoder(decoder *json.Decoder) (*Container, error) {
var gabs Container
if err := decoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | go | func ParseJSONDecoder(decoder *json.Decoder) (*Container, error) {
var gabs Container
if err := decoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | [
"func",
"ParseJSONDecoder",
"(",
"decoder",
"*",
"json",
".",
"Decoder",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"var",
"gabs",
"Container",
"\n\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"gabs",
".",
"object",
")",
";",
"... | // ParseJSONDecoder - Convert a json.Decoder into a representation of the parsed JSON. | [
"ParseJSONDecoder",
"-",
"Convert",
"a",
"json",
".",
"Decoder",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L561-L569 |
18,585 | Jeffail/gabs | gabs.go | ParseJSONFile | func ParseJSONFile(path string) (*Container, error) {
if len(path) > 0 {
cBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
container, err := ParseJSON(cBytes)
if err != nil {
return nil, err
}
return container, nil
}
return nil, ErrInvalidPath
} | go | func ParseJSONFile(path string) (*Container, error) {
if len(path) > 0 {
cBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
container, err := ParseJSON(cBytes)
if err != nil {
return nil, err
}
return container, nil
}
return nil, ErrInvalidPath
} | [
"func",
"ParseJSONFile",
"(",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"len",
"(",
"path",
")",
">",
"0",
"{",
"cBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"n... | // ParseJSONFile - Read a file and convert into a representation of the parsed JSON. | [
"ParseJSONFile",
"-",
"Read",
"a",
"file",
"and",
"convert",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L572-L587 |
18,586 | Jeffail/gabs | gabs.go | ParseJSONBuffer | func ParseJSONBuffer(buffer io.Reader) (*Container, error) {
var gabs Container
jsonDecoder := json.NewDecoder(buffer)
if err := jsonDecoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | go | func ParseJSONBuffer(buffer io.Reader) (*Container, error) {
var gabs Container
jsonDecoder := json.NewDecoder(buffer)
if err := jsonDecoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | [
"func",
"ParseJSONBuffer",
"(",
"buffer",
"io",
".",
"Reader",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"var",
"gabs",
"Container",
"\n",
"jsonDecoder",
":=",
"json",
".",
"NewDecoder",
"(",
"buffer",
")",
"\n",
"if",
"err",
":=",
"jsonDecoder... | // ParseJSONBuffer - Read the contents of a buffer into a representation of the parsed JSON. | [
"ParseJSONBuffer",
"-",
"Read",
"the",
"contents",
"of",
"a",
"buffer",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L590-L598 |
18,587 | h2non/filetype | kind.go | Image | func Image(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Image)
} | go | func Image(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Image)
} | [
"func",
"Image",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Image",
")",
"\n",
"}"
] | // Image tries to match a file as image type | [
"Image",
"tries",
"to",
"match",
"a",
"file",
"as",
"image",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L9-L11 |
18,588 | h2non/filetype | kind.go | IsImage | func IsImage(buf []byte) bool {
kind, _ := Image(buf)
return kind != types.Unknown
} | go | func IsImage(buf []byte) bool {
kind, _ := Image(buf)
return kind != types.Unknown
} | [
"func",
"IsImage",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Image",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsImage checks if the given buffer is an image type | [
"IsImage",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"image",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L14-L17 |
18,589 | h2non/filetype | kind.go | Audio | func Audio(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Audio)
} | go | func Audio(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Audio)
} | [
"func",
"Audio",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Audio",
")",
"\n",
"}"
] | // Audio tries to match a file as audio type | [
"Audio",
"tries",
"to",
"match",
"a",
"file",
"as",
"audio",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L20-L22 |
18,590 | h2non/filetype | kind.go | IsAudio | func IsAudio(buf []byte) bool {
kind, _ := Audio(buf)
return kind != types.Unknown
} | go | func IsAudio(buf []byte) bool {
kind, _ := Audio(buf)
return kind != types.Unknown
} | [
"func",
"IsAudio",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Audio",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsAudio checks if the given buffer is an audio type | [
"IsAudio",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"audio",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L25-L28 |
18,591 | h2non/filetype | kind.go | Video | func Video(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Video)
} | go | func Video(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Video)
} | [
"func",
"Video",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Video",
")",
"\n",
"}"
] | // Video tries to match a file as video type | [
"Video",
"tries",
"to",
"match",
"a",
"file",
"as",
"video",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L31-L33 |
18,592 | h2non/filetype | kind.go | IsVideo | func IsVideo(buf []byte) bool {
kind, _ := Video(buf)
return kind != types.Unknown
} | go | func IsVideo(buf []byte) bool {
kind, _ := Video(buf)
return kind != types.Unknown
} | [
"func",
"IsVideo",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Video",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsVideo checks if the given buffer is a video type | [
"IsVideo",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"a",
"video",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L36-L39 |
18,593 | h2non/filetype | kind.go | Font | func Font(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Font)
} | go | func Font(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Font)
} | [
"func",
"Font",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Font",
")",
"\n",
"}"
] | // Font tries to match a file as text font type | [
"Font",
"tries",
"to",
"match",
"a",
"file",
"as",
"text",
"font",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L42-L44 |
18,594 | h2non/filetype | kind.go | IsFont | func IsFont(buf []byte) bool {
kind, _ := Font(buf)
return kind != types.Unknown
} | go | func IsFont(buf []byte) bool {
kind, _ := Font(buf)
return kind != types.Unknown
} | [
"func",
"IsFont",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Font",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsFont checks if the given buffer is a font type | [
"IsFont",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"a",
"font",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L47-L50 |
18,595 | h2non/filetype | kind.go | Archive | func Archive(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Archive)
} | go | func Archive(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Archive)
} | [
"func",
"Archive",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Archive",
")",
"\n",
"}"
] | // Archive tries to match a file as generic archive type | [
"Archive",
"tries",
"to",
"match",
"a",
"file",
"as",
"generic",
"archive",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L53-L55 |
18,596 | h2non/filetype | kind.go | IsArchive | func IsArchive(buf []byte) bool {
kind, _ := Archive(buf)
return kind != types.Unknown
} | go | func IsArchive(buf []byte) bool {
kind, _ := Archive(buf)
return kind != types.Unknown
} | [
"func",
"IsArchive",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Archive",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsArchive checks if the given buffer is an archive type | [
"IsArchive",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"archive",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L58-L61 |
18,597 | h2non/filetype | kind.go | Document | func Document(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Document)
} | go | func Document(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Document)
} | [
"func",
"Document",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Document",
")",
"\n",
"}"
] | // Document tries to match a file as document type | [
"Document",
"tries",
"to",
"match",
"a",
"file",
"as",
"document",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L64-L66 |
18,598 | h2non/filetype | kind.go | IsDocument | func IsDocument(buf []byte) bool {
kind, _ := Document(buf)
return kind != types.Unknown
} | go | func IsDocument(buf []byte) bool {
kind, _ := Document(buf)
return kind != types.Unknown
} | [
"func",
"IsDocument",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Document",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsDocument checks if the given buffer is an document type | [
"IsDocument",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"document",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L69-L72 |
18,599 | h2non/filetype | matchers/application.go | Wasm | func Wasm(buf []byte) bool {
// WASM has starts with `\0asm`, followed by the version.
// http://webassembly.github.io/spec/core/binary/modules.html#binary-magic
return len(buf) >= 8 &&
buf[0] == 0x00 && buf[1] == 0x61 &&
buf[2] == 0x73 && buf[3] == 0x6D &&
buf[4] == 0x01 && buf[5] == 0x00 &&
buf[6] == 0x00 && buf[7] == 0x00
} | go | func Wasm(buf []byte) bool {
// WASM has starts with `\0asm`, followed by the version.
// http://webassembly.github.io/spec/core/binary/modules.html#binary-magic
return len(buf) >= 8 &&
buf[0] == 0x00 && buf[1] == 0x61 &&
buf[2] == 0x73 && buf[3] == 0x6D &&
buf[4] == 0x01 && buf[5] == 0x00 &&
buf[6] == 0x00 && buf[7] == 0x00
} | [
"func",
"Wasm",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"// WASM has starts with `\\0asm`, followed by the version.",
"// http://webassembly.github.io/spec/core/binary/modules.html#binary-magic",
"return",
"len",
"(",
"buf",
")",
">=",
"8",
"&&",
"buf",
"[",
"0",
... | // Wasm detects a Web Assembly 1.0 filetype. | [
"Wasm",
"detects",
"a",
"Web",
"Assembly",
"1",
".",
"0",
"filetype",
"."
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/application.go#L12-L20 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.