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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pelletier/go-toml | toml.go | GetPosition | func (t *Tree) GetPosition(key string) Position {
if key == "" {
return t.position
}
return t.GetPositionPath(strings.Split(key, "."))
} | go | func (t *Tree) GetPosition(key string) Position {
if key == "" {
return t.position
}
return t.GetPositionPath(strings.Split(key, "."))
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"GetPosition",
"(",
"key",
"string",
")",
"Position",
"{",
"if",
"key",
"==",
"\"",
"\"",
"{",
"return",
"t",
".",
"position",
"\n",
"}",
"\n",
"return",
"t",
".",
"GetPositionPath",
"(",
"strings",
".",
"Split",
... | // GetPosition returns the position of the given key. | [
"GetPosition",
"returns",
"the",
"position",
"of",
"the",
"given",
"key",
"."
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L125-L130 | train |
pelletier/go-toml | toml.go | GetPositionPath | func (t *Tree) GetPositionPath(keys []string) Position {
if len(keys) == 0 {
return t.position
}
subtree := t
for _, intermediateKey := range keys[:len(keys)-1] {
value, exists := subtree.values[intermediateKey]
if !exists {
return Position{0, 0}
}
switch node := value.(type) {
case *Tree:
subtree... | go | func (t *Tree) GetPositionPath(keys []string) Position {
if len(keys) == 0 {
return t.position
}
subtree := t
for _, intermediateKey := range keys[:len(keys)-1] {
value, exists := subtree.values[intermediateKey]
if !exists {
return Position{0, 0}
}
switch node := value.(type) {
case *Tree:
subtree... | [
"func",
"(",
"t",
"*",
"Tree",
")",
"GetPositionPath",
"(",
"keys",
"[",
"]",
"string",
")",
"Position",
"{",
"if",
"len",
"(",
"keys",
")",
"==",
"0",
"{",
"return",
"t",
".",
"position",
"\n",
"}",
"\n",
"subtree",
":=",
"t",
"\n",
"for",
"_",
... | // GetPositionPath returns the element in the tree indicated by 'keys'.
// If keys is of length zero, the current tree is returned. | [
"GetPositionPath",
"returns",
"the",
"element",
"in",
"the",
"tree",
"indicated",
"by",
"keys",
".",
"If",
"keys",
"is",
"of",
"length",
"zero",
"the",
"current",
"tree",
"is",
"returned",
"."
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L134-L172 | train |
pelletier/go-toml | toml.go | GetDefault | func (t *Tree) GetDefault(key string, def interface{}) interface{} {
val := t.Get(key)
if val == nil {
return def
}
return val
} | go | func (t *Tree) GetDefault(key string, def interface{}) interface{} {
val := t.Get(key)
if val == nil {
return def
}
return val
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"GetDefault",
"(",
"key",
"string",
",",
"def",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"val",
":=",
"t",
".",
"Get",
"(",
"key",
")",
"\n",
"if",
"val",
"==",
"nil",
"{",
"return",
"def",
"\n... | // GetDefault works like Get but with a default value | [
"GetDefault",
"works",
"like",
"Get",
"but",
"with",
"a",
"default",
"value"
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L175-L181 | train |
pelletier/go-toml | toml.go | LoadReader | func LoadReader(reader io.Reader) (tree *Tree, err error) {
inputBytes, err := ioutil.ReadAll(reader)
if err != nil {
return
}
tree, err = LoadBytes(inputBytes)
return
} | go | func LoadReader(reader io.Reader) (tree *Tree, err error) {
inputBytes, err := ioutil.ReadAll(reader)
if err != nil {
return
}
tree, err = LoadBytes(inputBytes)
return
} | [
"func",
"LoadReader",
"(",
"reader",
"io",
".",
"Reader",
")",
"(",
"tree",
"*",
"Tree",
",",
"err",
"error",
")",
"{",
"inputBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n... | // LoadReader creates a Tree from any io.Reader. | [
"LoadReader",
"creates",
"a",
"Tree",
"from",
"any",
"io",
".",
"Reader",
"."
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L371-L378 | train |
pelletier/go-toml | toml.go | Load | func Load(content string) (tree *Tree, err error) {
return LoadBytes([]byte(content))
} | go | func Load(content string) (tree *Tree, err error) {
return LoadBytes([]byte(content))
} | [
"func",
"Load",
"(",
"content",
"string",
")",
"(",
"tree",
"*",
"Tree",
",",
"err",
"error",
")",
"{",
"return",
"LoadBytes",
"(",
"[",
"]",
"byte",
"(",
"content",
")",
")",
"\n",
"}"
] | // Load creates a Tree from a string. | [
"Load",
"creates",
"a",
"Tree",
"from",
"a",
"string",
"."
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L381-L383 | train |
pelletier/go-toml | toml.go | LoadFile | func LoadFile(path string) (tree *Tree, err error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
return LoadReader(file)
} | go | func LoadFile(path string) (tree *Tree, err error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
return LoadReader(file)
} | [
"func",
"LoadFile",
"(",
"path",
"string",
")",
"(",
"tree",
"*",
"Tree",
",",
"err",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",... | // LoadFile creates a Tree from a file. | [
"LoadFile",
"creates",
"a",
"Tree",
"from",
"a",
"file",
"."
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/toml.go#L386-L393 | train |
pelletier/go-toml | tomltree_write.go | encodeMultilineTomlString | func encodeMultilineTomlString(value string) string {
var b bytes.Buffer
for _, rr := range value {
switch rr {
case '\b':
b.WriteString(`\b`)
case '\t':
b.WriteString("\t")
case '\n':
b.WriteString("\n")
case '\f':
b.WriteString(`\f`)
case '\r':
b.WriteString("\r")
case '"':
b.WriteS... | go | func encodeMultilineTomlString(value string) string {
var b bytes.Buffer
for _, rr := range value {
switch rr {
case '\b':
b.WriteString(`\b`)
case '\t':
b.WriteString("\t")
case '\n':
b.WriteString("\n")
case '\f':
b.WriteString(`\f`)
case '\r':
b.WriteString("\r")
case '"':
b.WriteS... | [
"func",
"encodeMultilineTomlString",
"(",
"value",
"string",
")",
"string",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n\n",
"for",
"_",
",",
"rr",
":=",
"range",
"value",
"{",
"switch",
"rr",
"{",
"case",
"'\\b'",
":",
"b",
".",
"WriteString",
"(",
"`... | // Encodes a string to a TOML-compliant multi-line string value
// This function is a clone of the existing encodeTomlString function, except that whitespace characters
// are preserved. Quotation marks and backslashes are also not escaped. | [
"Encodes",
"a",
"string",
"to",
"a",
"TOML",
"-",
"compliant",
"multi",
"-",
"line",
"string",
"value",
"This",
"function",
"is",
"a",
"clone",
"of",
"the",
"existing",
"encodeTomlString",
"function",
"except",
"that",
"whitespace",
"characters",
"are",
"prese... | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/tomltree_write.go#L30-L59 | train |
pelletier/go-toml | tomltree_write.go | WriteTo | func (t *Tree) WriteTo(w io.Writer) (int64, error) {
return t.writeTo(w, "", "", 0, false)
} | go | func (t *Tree) WriteTo(w io.Writer) (int64, error) {
return t.writeTo(w, "", "", 0, false)
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"return",
"t",
".",
"writeTo",
"(",
"w",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"0",
",",
"false",
")",
"\n",
"}"
] | // WriteTo encode the Tree as Toml and writes it to the writer w.
// Returns the number of bytes written in case of success, or an error if anything happened. | [
"WriteTo",
"encode",
"the",
"Tree",
"as",
"Toml",
"and",
"writes",
"it",
"to",
"the",
"writer",
"w",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"in",
"case",
"of",
"success",
"or",
"an",
"error",
"if",
"anything",
"happened",
"."
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/tomltree_write.go#L382-L384 | train |
pelletier/go-toml | tomltree_write.go | ToTomlString | func (t *Tree) ToTomlString() (string, error) {
var buf bytes.Buffer
_, err := t.WriteTo(&buf)
if err != nil {
return "", err
}
return buf.String(), nil
} | go | func (t *Tree) ToTomlString() (string, error) {
var buf bytes.Buffer
_, err := t.WriteTo(&buf)
if err != nil {
return "", err
}
return buf.String(), nil
} | [
"func",
"(",
"t",
"*",
"Tree",
")",
"ToTomlString",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"_",
",",
"err",
":=",
"t",
".",
"WriteTo",
"(",
"&",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // ToTomlString generates a human-readable representation of the current tree.
// Output spans multiple lines, and is suitable for ingest by a TOML parser.
// If the conversion cannot be performed, ToString returns a non-nil error. | [
"ToTomlString",
"generates",
"a",
"human",
"-",
"readable",
"representation",
"of",
"the",
"current",
"tree",
".",
"Output",
"spans",
"multiple",
"lines",
"and",
"is",
"suitable",
"for",
"ingest",
"by",
"a",
"TOML",
"parser",
".",
"If",
"the",
"conversion",
... | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/tomltree_write.go#L389-L396 | train |
pelletier/go-toml | query/query.go | Execute | func (q *Query) Execute(tree *toml.Tree) *Result {
result := &Result{
items: []interface{}{},
positions: []toml.Position{},
}
if q.root == nil {
result.appendResult(tree, tree.GetPosition(""))
} else {
ctx := &queryContext{
result: result,
filters: q.filters,
}
ctx.lastPosition = tree.Positio... | go | func (q *Query) Execute(tree *toml.Tree) *Result {
result := &Result{
items: []interface{}{},
positions: []toml.Position{},
}
if q.root == nil {
result.appendResult(tree, tree.GetPosition(""))
} else {
ctx := &queryContext{
result: result,
filters: q.filters,
}
ctx.lastPosition = tree.Positio... | [
"func",
"(",
"q",
"*",
"Query",
")",
"Execute",
"(",
"tree",
"*",
"toml",
".",
"Tree",
")",
"*",
"Result",
"{",
"result",
":=",
"&",
"Result",
"{",
"items",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"positions",
":",
"[",
"]",
"toml"... | // Execute executes a query against a Tree, and returns the result of the query. | [
"Execute",
"executes",
"a",
"query",
"against",
"a",
"Tree",
"and",
"returns",
"the",
"result",
"of",
"the",
"query",
"."
] | 728039f679cbcd4f6a54e080d2219a4c4928c546 | https://github.com/pelletier/go-toml/blob/728039f679cbcd4f6a54e080d2219a4c4928c546/query/query.go#L93-L109 | train |
spf13/cast | caste.go | ToTimeE | func ToTimeE(i interface{}) (tim time.Time, err error) {
i = indirect(i)
switch v := i.(type) {
case time.Time:
return v, nil
case string:
return StringToDate(v)
case int:
return time.Unix(int64(v), 0), nil
case int64:
return time.Unix(v, 0), nil
case int32:
return time.Unix(int64(v), 0), nil
case ui... | go | func ToTimeE(i interface{}) (tim time.Time, err error) {
i = indirect(i)
switch v := i.(type) {
case time.Time:
return v, nil
case string:
return StringToDate(v)
case int:
return time.Unix(int64(v), 0), nil
case int64:
return time.Unix(v, 0), nil
case int32:
return time.Unix(int64(v), 0), nil
case ui... | [
"func",
"ToTimeE",
"(",
"i",
"interface",
"{",
"}",
")",
"(",
"tim",
"time",
".",
"Time",
",",
"err",
"error",
")",
"{",
"i",
"=",
"indirect",
"(",
"i",
")",
"\n\n",
"switch",
"v",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"time",
".",
"... | // ToTimeE casts an interface to a time.Time type. | [
"ToTimeE",
"casts",
"an",
"interface",
"to",
"a",
"time",
".",
"Time",
"type",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L22-L45 | train |
spf13/cast | caste.go | ToDurationE | func ToDurationE(i interface{}) (d time.Duration, err error) {
i = indirect(i)
switch s := i.(type) {
case time.Duration:
return s, nil
case int, int64, int32, int16, int8, uint, uint64, uint32, uint16, uint8:
d = time.Duration(ToInt64(s))
return
case float32, float64:
d = time.Duration(ToFloat64(s))
re... | go | func ToDurationE(i interface{}) (d time.Duration, err error) {
i = indirect(i)
switch s := i.(type) {
case time.Duration:
return s, nil
case int, int64, int32, int16, int8, uint, uint64, uint32, uint16, uint8:
d = time.Duration(ToInt64(s))
return
case float32, float64:
d = time.Duration(ToFloat64(s))
re... | [
"func",
"ToDurationE",
"(",
"i",
"interface",
"{",
"}",
")",
"(",
"d",
"time",
".",
"Duration",
",",
"err",
"error",
")",
"{",
"i",
"=",
"indirect",
"(",
"i",
")",
"\n\n",
"switch",
"s",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"time",
".... | // ToDurationE casts an interface to a time.Duration type. | [
"ToDurationE",
"casts",
"an",
"interface",
"to",
"a",
"time",
".",
"Duration",
"type",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L48-L71 | train |
spf13/cast | caste.go | ToBoolE | func ToBoolE(i interface{}) (bool, error) {
i = indirect(i)
switch b := i.(type) {
case bool:
return b, nil
case nil:
return false, nil
case int:
if i.(int) != 0 {
return true, nil
}
return false, nil
case string:
return strconv.ParseBool(i.(string))
default:
return false, fmt.Errorf("unable to... | go | func ToBoolE(i interface{}) (bool, error) {
i = indirect(i)
switch b := i.(type) {
case bool:
return b, nil
case nil:
return false, nil
case int:
if i.(int) != 0 {
return true, nil
}
return false, nil
case string:
return strconv.ParseBool(i.(string))
default:
return false, fmt.Errorf("unable to... | [
"func",
"ToBoolE",
"(",
"i",
"interface",
"{",
"}",
")",
"(",
"bool",
",",
"error",
")",
"{",
"i",
"=",
"indirect",
"(",
"i",
")",
"\n\n",
"switch",
"b",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"bool",
":",
"return",
"b",
",",
"nil",
"... | // ToBoolE casts an interface to a bool type. | [
"ToBoolE",
"casts",
"an",
"interface",
"to",
"a",
"bool",
"type",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L74-L92 | train |
spf13/cast | caste.go | ToFloat64E | func ToFloat64E(i interface{}) (float64, error) {
i = indirect(i)
switch s := i.(type) {
case float64:
return s, nil
case float32:
return float64(s), nil
case int:
return float64(s), nil
case int64:
return float64(s), nil
case int32:
return float64(s), nil
case int16:
return float64(s), nil
case i... | go | func ToFloat64E(i interface{}) (float64, error) {
i = indirect(i)
switch s := i.(type) {
case float64:
return s, nil
case float32:
return float64(s), nil
case int:
return float64(s), nil
case int64:
return float64(s), nil
case int32:
return float64(s), nil
case int16:
return float64(s), nil
case i... | [
"func",
"ToFloat64E",
"(",
"i",
"interface",
"{",
"}",
")",
"(",
"float64",
",",
"error",
")",
"{",
"i",
"=",
"indirect",
"(",
"i",
")",
"\n\n",
"switch",
"s",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"float64",
":",
"return",
"s",
",",
"... | // ToFloat64E casts an interface to a float64 type. | [
"ToFloat64E",
"casts",
"an",
"interface",
"to",
"a",
"float64",
"type",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L95-L137 | train |
spf13/cast | caste.go | ToInt32E | func ToInt32E(i interface{}) (int32, error) {
i = indirect(i)
switch s := i.(type) {
case int:
return int32(s), nil
case int64:
return int32(s), nil
case int32:
return s, nil
case int16:
return int32(s), nil
case int8:
return int32(s), nil
case uint:
return int32(s), nil
case uint64:
return int3... | go | func ToInt32E(i interface{}) (int32, error) {
i = indirect(i)
switch s := i.(type) {
case int:
return int32(s), nil
case int64:
return int32(s), nil
case int32:
return s, nil
case int16:
return int32(s), nil
case int8:
return int32(s), nil
case uint:
return int32(s), nil
case uint64:
return int3... | [
"func",
"ToInt32E",
"(",
"i",
"interface",
"{",
"}",
")",
"(",
"int32",
",",
"error",
")",
"{",
"i",
"=",
"indirect",
"(",
"i",
")",
"\n\n",
"switch",
"s",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"int",
":",
"return",
"int32",
"(",
"s",
... | // ToInt32E casts an interface to an int32 type. | [
"ToInt32E",
"casts",
"an",
"interface",
"to",
"an",
"int32",
"type",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L232-L276 | train |
spf13/cast | caste.go | ToUintE | func ToUintE(i interface{}) (uint, error) {
i = indirect(i)
switch s := i.(type) {
case string:
v, err := strconv.ParseUint(s, 0, 0)
if err == nil {
return uint(v), nil
}
return 0, fmt.Errorf("unable to cast %#v to uint: %s", i, err)
case int:
if s < 0 {
return 0, errNegativeNotAllowed
}
return... | go | func ToUintE(i interface{}) (uint, error) {
i = indirect(i)
switch s := i.(type) {
case string:
v, err := strconv.ParseUint(s, 0, 0)
if err == nil {
return uint(v), nil
}
return 0, fmt.Errorf("unable to cast %#v to uint: %s", i, err)
case int:
if s < 0 {
return 0, errNegativeNotAllowed
}
return... | [
"func",
"ToUintE",
"(",
"i",
"interface",
"{",
"}",
")",
"(",
"uint",
",",
"error",
")",
"{",
"i",
"=",
"indirect",
"(",
"i",
")",
"\n\n",
"switch",
"s",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"v",
",",
"err",
":=",
"st... | // ToUintE casts an interface to a uint type. | [
"ToUintE",
"casts",
"an",
"interface",
"to",
"a",
"uint",
"type",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L420-L485 | train |
spf13/cast | caste.go | ToStringE | func ToStringE(i interface{}) (string, error) {
i = indirectToStringerOrError(i)
switch s := i.(type) {
case string:
return s, nil
case bool:
return strconv.FormatBool(s), nil
case float64:
return strconv.FormatFloat(s, 'f', -1, 64), nil
case float32:
return strconv.FormatFloat(float64(s), 'f', -1, 32), ... | go | func ToStringE(i interface{}) (string, error) {
i = indirectToStringerOrError(i)
switch s := i.(type) {
case string:
return s, nil
case bool:
return strconv.FormatBool(s), nil
case float64:
return strconv.FormatFloat(s, 'f', -1, 64), nil
case float32:
return strconv.FormatFloat(float64(s), 'f', -1, 32), ... | [
"func",
"ToStringE",
"(",
"i",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"i",
"=",
"indirectToStringerOrError",
"(",
"i",
")",
"\n\n",
"switch",
"s",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"... | // ToStringE casts an interface to a string type. | [
"ToStringE",
"casts",
"an",
"interface",
"to",
"a",
"string",
"type",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L799-L852 | train |
spf13/cast | caste.go | StringToDate | func StringToDate(s string) (time.Time, error) {
return parseDateWith(s, []string{
time.RFC3339,
"2006-01-02T15:04:05", // iso8601 without timezone
time.RFC1123Z,
time.RFC1123,
time.RFC822Z,
time.RFC822,
time.RFC850,
time.ANSIC,
time.UnixDate,
time.RubyDate,
"2006-01-02 15:04:05.999999999 -0700 M... | go | func StringToDate(s string) (time.Time, error) {
return parseDateWith(s, []string{
time.RFC3339,
"2006-01-02T15:04:05", // iso8601 without timezone
time.RFC1123Z,
time.RFC1123,
time.RFC822Z,
time.RFC822,
time.RFC850,
time.ANSIC,
time.UnixDate,
time.RubyDate,
"2006-01-02 15:04:05.999999999 -0700 M... | [
"func",
"StringToDate",
"(",
"s",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"parseDateWith",
"(",
"s",
",",
"[",
"]",
"string",
"{",
"time",
".",
"RFC3339",
",",
"\"",
"\"",
",",
"// iso8601 without timezone",
"time",
"... | // StringToDate attempts to parse a string into a time.Time type using a
// predefined list of formats. If no suitable format is found, an error is
// returned. | [
"StringToDate",
"attempts",
"to",
"parse",
"a",
"string",
"into",
"a",
"time",
".",
"Time",
"type",
"using",
"a",
"predefined",
"list",
"of",
"formats",
".",
"If",
"no",
"suitable",
"format",
"is",
"found",
"an",
"error",
"is",
"returned",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L1206-L1233 | train |
spf13/cast | caste.go | jsonStringToObject | func jsonStringToObject(s string, v interface{}) error {
data := []byte(s)
return json.Unmarshal(data, v)
} | go | func jsonStringToObject(s string, v interface{}) error {
data := []byte(s)
return json.Unmarshal(data, v)
} | [
"func",
"jsonStringToObject",
"(",
"s",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"data",
":=",
"[",
"]",
"byte",
"(",
"s",
")",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"v",
")",
"\n",
"}"
] | // jsonStringToObject attempts to unmarshall a string as JSON into
// the object passed as pointer. | [
"jsonStringToObject",
"attempts",
"to",
"unmarshall",
"a",
"string",
"as",
"JSON",
"into",
"the",
"object",
"passed",
"as",
"pointer",
"."
] | 8c9545af88b134710ab1cd196795e7f2388358d7 | https://github.com/spf13/cast/blob/8c9545af88b134710ab1cd196795e7f2388358d7/caste.go#L1246-L1249 | train |
hashicorp/go-sockaddr | route_info_linux.go | NewRouteInfo | func NewRouteInfo() (routeInfo, error) {
// CoreOS Container Linux moved ip to /usr/bin/ip, so look it up on
// $PATH and fallback to /sbin/ip on error.
path, _ := exec.LookPath("ip")
if path == "" {
path = "/sbin/ip"
}
return routeInfo{
cmds: map[string][]string{"ip": {path, "route"}},
}, nil
} | go | func NewRouteInfo() (routeInfo, error) {
// CoreOS Container Linux moved ip to /usr/bin/ip, so look it up on
// $PATH and fallback to /sbin/ip on error.
path, _ := exec.LookPath("ip")
if path == "" {
path = "/sbin/ip"
}
return routeInfo{
cmds: map[string][]string{"ip": {path, "route"}},
}, nil
} | [
"func",
"NewRouteInfo",
"(",
")",
"(",
"routeInfo",
",",
"error",
")",
"{",
"// CoreOS Container Linux moved ip to /usr/bin/ip, so look it up on",
"// $PATH and fallback to /sbin/ip on error.",
"path",
",",
"_",
":=",
"exec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
"\n",... | // NewRouteInfo returns a Linux-specific implementation of the RouteInfo
// interface. | [
"NewRouteInfo",
"returns",
"a",
"Linux",
"-",
"specific",
"implementation",
"of",
"the",
"RouteInfo",
"interface",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/route_info_linux.go#L16-L27 | train |
hashicorp/go-sockaddr | template/template.go | Attr | func Attr(selectorName string, ifAddrsRaw interface{}) (string, error) {
switch v := ifAddrsRaw.(type) {
case sockaddr.IfAddr:
return sockaddr.IfAttr(selectorName, v)
case sockaddr.IfAddrs:
return sockaddr.IfAttrs(selectorName, v)
default:
return "", fmt.Errorf("unable to obtain attribute %s from type %T (%v)... | go | func Attr(selectorName string, ifAddrsRaw interface{}) (string, error) {
switch v := ifAddrsRaw.(type) {
case sockaddr.IfAddr:
return sockaddr.IfAttr(selectorName, v)
case sockaddr.IfAddrs:
return sockaddr.IfAttrs(selectorName, v)
default:
return "", fmt.Errorf("unable to obtain attribute %s from type %T (%v)... | [
"func",
"Attr",
"(",
"selectorName",
"string",
",",
"ifAddrsRaw",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"switch",
"v",
":=",
"ifAddrsRaw",
".",
"(",
"type",
")",
"{",
"case",
"sockaddr",
".",
"IfAddr",
":",
"return",
"socka... | // Attr returns the attribute from the ifAddrRaw argument. If the argument is
// an IfAddrs, only the first element will be evaluated for resolution. | [
"Attr",
"returns",
"the",
"attribute",
"from",
"the",
"ifAddrRaw",
"argument",
".",
"If",
"the",
"argument",
"is",
"an",
"IfAddrs",
"only",
"the",
"first",
"element",
"will",
"be",
"evaluated",
"for",
"resolution",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L106-L115 | train |
hashicorp/go-sockaddr | template/template.go | Parse | func Parse(input string) (string, error) {
addrs, err := sockaddr.GetAllInterfaces()
if err != nil {
return "", errwrap.Wrapf("unable to query interface addresses: {{err}}", err)
}
return ParseIfAddrs(input, addrs)
} | go | func Parse(input string) (string, error) {
addrs, err := sockaddr.GetAllInterfaces()
if err != nil {
return "", errwrap.Wrapf("unable to query interface addresses: {{err}}", err)
}
return ParseIfAddrs(input, addrs)
} | [
"func",
"Parse",
"(",
"input",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"addrs",
",",
"err",
":=",
"sockaddr",
".",
"GetAllInterfaces",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errwrap",
".",
"Wrapf",
... | // Parse parses input as template input using the addresses available on the
// host, then returns the string output if there are no errors. | [
"Parse",
"parses",
"input",
"as",
"template",
"input",
"using",
"the",
"addresses",
"available",
"on",
"the",
"host",
"then",
"returns",
"the",
"string",
"output",
"if",
"there",
"are",
"no",
"errors",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L119-L126 | train |
hashicorp/go-sockaddr | template/template.go | ParseIfAddrs | func ParseIfAddrs(input string, ifAddrs sockaddr.IfAddrs) (string, error) {
return ParseIfAddrsTemplate(input, ifAddrs, template.New("sockaddr.Parse"))
} | go | func ParseIfAddrs(input string, ifAddrs sockaddr.IfAddrs) (string, error) {
return ParseIfAddrsTemplate(input, ifAddrs, template.New("sockaddr.Parse"))
} | [
"func",
"ParseIfAddrs",
"(",
"input",
"string",
",",
"ifAddrs",
"sockaddr",
".",
"IfAddrs",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"ParseIfAddrsTemplate",
"(",
"input",
",",
"ifAddrs",
",",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
")"... | // ParseIfAddrs parses input as template input using the IfAddrs inputs, then
// returns the string output if there are no errors. | [
"ParseIfAddrs",
"parses",
"input",
"as",
"template",
"input",
"using",
"the",
"IfAddrs",
"inputs",
"then",
"returns",
"the",
"string",
"output",
"if",
"there",
"are",
"no",
"errors",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L130-L132 | train |
hashicorp/go-sockaddr | template/template.go | ParseIfAddrsTemplate | func ParseIfAddrsTemplate(input string, ifAddrs sockaddr.IfAddrs, tmplIn *template.Template) (string, error) {
// Create a template, add the function map, and parse the text.
tmpl, err := tmplIn.Option("missingkey=error").
Funcs(SourceFuncs).
Funcs(SortFuncs).
Funcs(FilterFuncs).
Funcs(HelperFuncs).
Parse(i... | go | func ParseIfAddrsTemplate(input string, ifAddrs sockaddr.IfAddrs, tmplIn *template.Template) (string, error) {
// Create a template, add the function map, and parse the text.
tmpl, err := tmplIn.Option("missingkey=error").
Funcs(SourceFuncs).
Funcs(SortFuncs).
Funcs(FilterFuncs).
Funcs(HelperFuncs).
Parse(i... | [
"func",
"ParseIfAddrsTemplate",
"(",
"input",
"string",
",",
"ifAddrs",
"sockaddr",
".",
"IfAddrs",
",",
"tmplIn",
"*",
"template",
".",
"Template",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Create a template, add the function map, and parse the text.",
"tmpl",
... | // ParseIfAddrsTemplate parses input as template input using the IfAddrs inputs,
// then returns the string output if there are no errors. | [
"ParseIfAddrsTemplate",
"parses",
"input",
"as",
"template",
"input",
"using",
"the",
"IfAddrs",
"inputs",
"then",
"returns",
"the",
"string",
"output",
"if",
"there",
"are",
"no",
"errors",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/template/template.go#L136-L155 | train |
hashicorp/go-sockaddr | ipv6addr.go | AddressBinString | func (ipv6 IPv6Addr) AddressBinString() string {
bi := big.Int(*ipv6.Address)
return fmt.Sprintf("%0128s", bi.Text(2))
} | go | func (ipv6 IPv6Addr) AddressBinString() string {
bi := big.Int(*ipv6.Address)
return fmt.Sprintf("%0128s", bi.Text(2))
} | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"AddressBinString",
"(",
")",
"string",
"{",
"bi",
":=",
"big",
".",
"Int",
"(",
"*",
"ipv6",
".",
"Address",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"bi",
".",
"Text",
"(",
"2",
")"... | // AddressBinString returns a string with the IPv6Addr'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",
"IPv6Addr",
"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/ipv6addr.go#L161-L164 | train |
hashicorp/go-sockaddr | ipv6addr.go | ContainsAddress | func (ipv6 IPv6Addr) ContainsAddress(x IPv6Address) bool {
xAddr := IPv6Addr{
Address: x,
Mask: ipv6HostMask,
}
{
xIPv6 := xAddr.FirstUsable().(IPv6Addr)
yIPv6 := ipv6.FirstUsable().(IPv6Addr)
if xIPv6.CmpAddress(yIPv6) >= 1 {
return false
}
}
{
xIPv6 := xAddr.LastUsable().(IPv6Addr)
yIPv6 ... | go | func (ipv6 IPv6Addr) ContainsAddress(x IPv6Address) bool {
xAddr := IPv6Addr{
Address: x,
Mask: ipv6HostMask,
}
{
xIPv6 := xAddr.FirstUsable().(IPv6Addr)
yIPv6 := ipv6.FirstUsable().(IPv6Addr)
if xIPv6.CmpAddress(yIPv6) >= 1 {
return false
}
}
{
xIPv6 := xAddr.LastUsable().(IPv6Addr)
yIPv6 ... | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"ContainsAddress",
"(",
"x",
"IPv6Address",
")",
"bool",
"{",
"xAddr",
":=",
"IPv6Addr",
"{",
"Address",
":",
"x",
",",
"Mask",
":",
"ipv6HostMask",
",",
"}",
"\n\n",
"{",
"xIPv6",
":=",
"xAddr",
".",
"FirstUsable",
... | // ContainsAddress returns true if the IPv6Address is contained within the
// receiver. | [
"ContainsAddress",
"returns",
"true",
"if",
"the",
"IPv6Address",
"is",
"contained",
"within",
"the",
"receiver",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L267-L289 | train |
hashicorp/go-sockaddr | ipv6addr.go | ContainsNetwork | func (x IPv6Addr) ContainsNetwork(y IPv6Addr) bool {
{
xIPv6 := x.FirstUsable().(IPv6Addr)
yIPv6 := y.FirstUsable().(IPv6Addr)
if ret := xIPv6.CmpAddress(yIPv6); ret >= 1 {
return false
}
}
{
xIPv6 := x.LastUsable().(IPv6Addr)
yIPv6 := y.LastUsable().(IPv6Addr)
if ret := xIPv6.CmpAddress(yIPv6); re... | go | func (x IPv6Addr) ContainsNetwork(y IPv6Addr) bool {
{
xIPv6 := x.FirstUsable().(IPv6Addr)
yIPv6 := y.FirstUsable().(IPv6Addr)
if ret := xIPv6.CmpAddress(yIPv6); ret >= 1 {
return false
}
}
{
xIPv6 := x.LastUsable().(IPv6Addr)
yIPv6 := y.LastUsable().(IPv6Addr)
if ret := xIPv6.CmpAddress(yIPv6); re... | [
"func",
"(",
"x",
"IPv6Addr",
")",
"ContainsNetwork",
"(",
"y",
"IPv6Addr",
")",
"bool",
"{",
"{",
"xIPv6",
":=",
"x",
".",
"FirstUsable",
"(",
")",
".",
"(",
"IPv6Addr",
")",
"\n",
"yIPv6",
":=",
"y",
".",
"FirstUsable",
"(",
")",
".",
"(",
"IPv6A... | // ContainsNetwork returns true if the network from IPv6Addr is contained within
// the receiver. | [
"ContainsNetwork",
"returns",
"true",
"if",
"the",
"network",
"from",
"IPv6Addr",
"is",
"contained",
"within",
"the",
"receiver",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L293-L310 | train |
hashicorp/go-sockaddr | ipv6addr.go | LastUsable | func (ipv6 IPv6Addr) LastUsable() IPAddr {
addr := new(big.Int)
addr.Set(ipv6.Address)
mask := new(big.Int)
mask.Set(ipv6.Mask)
negMask := new(big.Int)
negMask.Xor(ipv6HostMask, mask)
lastAddr := new(big.Int)
lastAddr.And(addr, mask)
lastAddr.Or(lastAddr, negMask)
return IPv6Addr{
Address: IPv6Address(l... | go | func (ipv6 IPv6Addr) LastUsable() IPAddr {
addr := new(big.Int)
addr.Set(ipv6.Address)
mask := new(big.Int)
mask.Set(ipv6.Mask)
negMask := new(big.Int)
negMask.Xor(ipv6HostMask, mask)
lastAddr := new(big.Int)
lastAddr.And(addr, mask)
lastAddr.Or(lastAddr, negMask)
return IPv6Addr{
Address: IPv6Address(l... | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"LastUsable",
"(",
")",
"IPAddr",
"{",
"addr",
":=",
"new",
"(",
"big",
".",
"Int",
")",
"\n",
"addr",
".",
"Set",
"(",
"ipv6",
".",
"Address",
")",
"\n\n",
"mask",
":=",
"new",
"(",
"big",
".",
"Int",
")",
... | // LastUsable returns the last address in a given network. | [
"LastUsable",
"returns",
"the",
"last",
"address",
"in",
"a",
"given",
"network",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L390-L408 | train |
hashicorp/go-sockaddr | ipv6addr.go | MustIPv6Addr | func MustIPv6Addr(addr string) IPv6Addr {
ipv6, err := NewIPv6Addr(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create an IPv6Addr from %+q: %v", addr, err))
}
return ipv6
} | go | func MustIPv6Addr(addr string) IPv6Addr {
ipv6, err := NewIPv6Addr(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create an IPv6Addr from %+q: %v", addr, err))
}
return ipv6
} | [
"func",
"MustIPv6Addr",
"(",
"addr",
"string",
")",
"IPv6Addr",
"{",
"ipv6",
",",
"err",
":=",
"NewIPv6Addr",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"addr",
",",
"err",
")",... | // MustIPv6Addr is a helper method that must return an IPv6Addr or panic on
// invalid input. | [
"MustIPv6Addr",
"is",
"a",
"helper",
"method",
"that",
"must",
"return",
"an",
"IPv6Addr",
"or",
"panic",
"on",
"invalid",
"input",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L442-L448 | train |
hashicorp/go-sockaddr | ipv6addr.go | NetIPMask | func (ipv6 IPv6Addr) NetIPMask() *net.IPMask {
ipv6Mask := make(net.IPMask, IPv6len)
m := big.Int(*ipv6.Mask)
copy(ipv6Mask, m.Bytes())
return &ipv6Mask
} | go | func (ipv6 IPv6Addr) NetIPMask() *net.IPMask {
ipv6Mask := make(net.IPMask, IPv6len)
m := big.Int(*ipv6.Mask)
copy(ipv6Mask, m.Bytes())
return &ipv6Mask
} | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"NetIPMask",
"(",
")",
"*",
"net",
".",
"IPMask",
"{",
"ipv6Mask",
":=",
"make",
"(",
"net",
".",
"IPMask",
",",
"IPv6len",
")",
"\n",
"m",
":=",
"big",
".",
"Int",
"(",
"*",
"ipv6",
".",
"Mask",
")",
"\n",
... | // NetIPMask create a new net.IPMask from the IPv6Addr. | [
"NetIPMask",
"create",
"a",
"new",
"net",
".",
"IPMask",
"from",
"the",
"IPv6Addr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L456-L461 | train |
hashicorp/go-sockaddr | ipv6addr.go | NetIPNet | func (ipv6 IPv6Addr) NetIPNet() *net.IPNet {
ipv6net := &net.IPNet{}
ipv6net.IP = make(net.IP, IPv6len)
copy(ipv6net.IP, *ipv6.NetIP())
ipv6net.Mask = *ipv6.NetIPMask()
return ipv6net
} | go | func (ipv6 IPv6Addr) NetIPNet() *net.IPNet {
ipv6net := &net.IPNet{}
ipv6net.IP = make(net.IP, IPv6len)
copy(ipv6net.IP, *ipv6.NetIP())
ipv6net.Mask = *ipv6.NetIPMask()
return ipv6net
} | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"NetIPNet",
"(",
")",
"*",
"net",
".",
"IPNet",
"{",
"ipv6net",
":=",
"&",
"net",
".",
"IPNet",
"{",
"}",
"\n",
"ipv6net",
".",
"IP",
"=",
"make",
"(",
"net",
".",
"IP",
",",
"IPv6len",
")",
"\n",
"copy",
"... | // Network returns a pointer to the net.IPNet within IPv4Addr receiver. | [
"Network",
"returns",
"a",
"pointer",
"to",
"the",
"net",
".",
"IPNet",
"within",
"IPv4Addr",
"receiver",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L464-L470 | train |
hashicorp/go-sockaddr | ipv6addr.go | NetworkAddress | func (ipv6 IPv6Addr) NetworkAddress() IPv6Network {
addr := new(big.Int)
addr.SetBytes((*ipv6.Address).Bytes())
mask := new(big.Int)
mask.SetBytes(*ipv6.NetIPMask())
netAddr := new(big.Int)
netAddr.And(addr, mask)
return IPv6Network(netAddr)
} | go | func (ipv6 IPv6Addr) NetworkAddress() IPv6Network {
addr := new(big.Int)
addr.SetBytes((*ipv6.Address).Bytes())
mask := new(big.Int)
mask.SetBytes(*ipv6.NetIPMask())
netAddr := new(big.Int)
netAddr.And(addr, mask)
return IPv6Network(netAddr)
} | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"NetworkAddress",
"(",
")",
"IPv6Network",
"{",
"addr",
":=",
"new",
"(",
"big",
".",
"Int",
")",
"\n",
"addr",
".",
"SetBytes",
"(",
"(",
"*",
"ipv6",
".",
"Address",
")",
".",
"Bytes",
"(",
")",
")",
"\n\n",
... | // NetworkAddress returns an IPv6Network of the IPv6Addr's network address. | [
"NetworkAddress",
"returns",
"an",
"IPv6Network",
"of",
"the",
"IPv6Addr",
"s",
"network",
"address",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L481-L492 | train |
hashicorp/go-sockaddr | ipv6addr.go | Octets | func (ipv6 IPv6Addr) Octets() []int {
x := make([]int, IPv6len)
for i, b := range *bigIntToNetIPv6(ipv6.Address) {
x[i] = int(b)
}
return x
} | go | func (ipv6 IPv6Addr) Octets() []int {
x := make([]int, IPv6len)
for i, b := range *bigIntToNetIPv6(ipv6.Address) {
x[i] = int(b)
}
return x
} | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"Octets",
"(",
")",
"[",
"]",
"int",
"{",
"x",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"IPv6len",
")",
"\n",
"for",
"i",
",",
"b",
":=",
"range",
"*",
"bigIntToNetIPv6",
"(",
"ipv6",
".",
"Address",
")",
"... | // Octets returns a slice of the 16 octets in an IPv6Addr's Address. The
// order of the bytes is big endian. | [
"Octets",
"returns",
"a",
"slice",
"of",
"the",
"16",
"octets",
"in",
"an",
"IPv6Addr",
"s",
"Address",
".",
"The",
"order",
"of",
"the",
"bytes",
"is",
"big",
"endian",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L496-L503 | train |
hashicorp/go-sockaddr | ipv6addr.go | String | func (ipv6 IPv6Addr) String() string {
if ipv6.Port != 0 {
return fmt.Sprintf("[%s]:%d", ipv6.NetIP().String(), ipv6.Port)
}
if ipv6.Maskbits() == 128 {
return ipv6.NetIP().String()
}
return fmt.Sprintf("%s/%d", ipv6.NetIP().String(), ipv6.Maskbits())
} | go | func (ipv6 IPv6Addr) String() string {
if ipv6.Port != 0 {
return fmt.Sprintf("[%s]:%d", ipv6.NetIP().String(), ipv6.Port)
}
if ipv6.Maskbits() == 128 {
return ipv6.NetIP().String()
}
return fmt.Sprintf("%s/%d", ipv6.NetIP().String(), ipv6.Maskbits())
} | [
"func",
"(",
"ipv6",
"IPv6Addr",
")",
"String",
"(",
")",
"string",
"{",
"if",
"ipv6",
".",
"Port",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ipv6",
".",
"NetIP",
"(",
")",
".",
"String",
"(",
")",
",",
"ipv6",
"."... | // String returns a string representation of the IPv6Addr | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"IPv6Addr"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L506-L516 | train |
hashicorp/go-sockaddr | ipv6addr.go | IPv6AddrAttr | func IPv6AddrAttr(ipv6 IPv6Addr, selector AttrName) string {
fn, found := ipv6AddrAttrMap[selector]
if !found {
return ""
}
return fn(ipv6)
} | go | func IPv6AddrAttr(ipv6 IPv6Addr, selector AttrName) string {
fn, found := ipv6AddrAttrMap[selector]
if !found {
return ""
}
return fn(ipv6)
} | [
"func",
"IPv6AddrAttr",
"(",
"ipv6",
"IPv6Addr",
",",
"selector",
"AttrName",
")",
"string",
"{",
"fn",
",",
"found",
":=",
"ipv6AddrAttrMap",
"[",
"selector",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fn",
... | // IPv6AddrAttr returns a string representation of an attribute for the given
// IPv6Addr. | [
"IPv6AddrAttr",
"returns",
"a",
"string",
"representation",
"of",
"an",
"attribute",
"for",
"the",
"given",
"IPv6Addr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L530-L537 | train |
hashicorp/go-sockaddr | ipv6addr.go | bigIntToNetIPv6 | func bigIntToNetIPv6(bi *big.Int) *net.IP {
x := make(net.IP, IPv6len)
ipv6Bytes := bi.Bytes()
// It's possibe for ipv6Bytes to be less than IPv6len bytes in size. If
// they are different sizes we to pad the size of response.
if len(ipv6Bytes) < IPv6len {
buf := new(bytes.Buffer)
buf.Grow(IPv6len)
for i ... | go | func bigIntToNetIPv6(bi *big.Int) *net.IP {
x := make(net.IP, IPv6len)
ipv6Bytes := bi.Bytes()
// It's possibe for ipv6Bytes to be less than IPv6len bytes in size. If
// they are different sizes we to pad the size of response.
if len(ipv6Bytes) < IPv6len {
buf := new(bytes.Buffer)
buf.Grow(IPv6len)
for i ... | [
"func",
"bigIntToNetIPv6",
"(",
"bi",
"*",
"big",
".",
"Int",
")",
"*",
"net",
".",
"IP",
"{",
"x",
":=",
"make",
"(",
"net",
".",
"IP",
",",
"IPv6len",
")",
"\n",
"ipv6Bytes",
":=",
"bi",
".",
"Bytes",
"(",
")",
"\n\n",
"// It's possibe for ipv6Byte... | // bigIntToNetIPv6 is a helper function that correctly returns a net.IP with the
// correctly padded values. | [
"bigIntToNetIPv6",
"is",
"a",
"helper",
"function",
"that",
"correctly",
"returns",
"a",
"net",
".",
"IP",
"with",
"the",
"correctly",
"padded",
"values",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ipv6addr.go#L562-L591 | train |
hashicorp/go-sockaddr | cmd/sockaddr/command/autohelp.go | MakeHelp | func MakeHelp(c AutoHelp) string {
usageText := c.Usage()
// If the length of Usage() is zero, then assume this is a hidden
// command.
if len(usageText) == 0 {
return ""
}
descriptionText := wordwrap.WrapString(c.Description(), 60)
descrLines := strings.Split(descriptionText, "\n")
prefixedLines := make([]... | go | func MakeHelp(c AutoHelp) string {
usageText := c.Usage()
// If the length of Usage() is zero, then assume this is a hidden
// command.
if len(usageText) == 0 {
return ""
}
descriptionText := wordwrap.WrapString(c.Description(), 60)
descrLines := strings.Split(descriptionText, "\n")
prefixedLines := make([]... | [
"func",
"MakeHelp",
"(",
"c",
"AutoHelp",
")",
"string",
"{",
"usageText",
":=",
"c",
".",
"Usage",
"(",
")",
"\n\n",
"// If the length of Usage() is zero, then assume this is a hidden",
"// command.",
"if",
"len",
"(",
"usageText",
")",
"==",
"0",
"{",
"return",
... | // MakeHelp generates a help string based on the capabilities of the Command | [
"MakeHelp",
"generates",
"a",
"help",
"string",
"based",
"on",
"the",
"capabilities",
"of",
"the",
"Command"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/cmd/sockaddr/command/autohelp.go#L23-L75 | train |
hashicorp/go-sockaddr | cmd/sockaddr/command/autohelp.go | OptionsHelpOutput | func OptionsHelpOutput(flags []*flag.Flag) string {
sort.Sort(ByName(flags))
var output []string
for _, f := range flags {
if len(f.Usage) == 0 {
continue
}
output = append(output, fmt.Sprintf("-%s | %s", f.Name, f.Usage))
}
optionsOutput := columnize.Format(output, &columnize.Config{
Delim: "|",
... | go | func OptionsHelpOutput(flags []*flag.Flag) string {
sort.Sort(ByName(flags))
var output []string
for _, f := range flags {
if len(f.Usage) == 0 {
continue
}
output = append(output, fmt.Sprintf("-%s | %s", f.Name, f.Usage))
}
optionsOutput := columnize.Format(output, &columnize.Config{
Delim: "|",
... | [
"func",
"OptionsHelpOutput",
"(",
"flags",
"[",
"]",
"*",
"flag",
".",
"Flag",
")",
"string",
"{",
"sort",
".",
"Sort",
"(",
"ByName",
"(",
"flags",
")",
")",
"\n\n",
"var",
"output",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
... | // OptionsHelpOutput returns a string of formatted options | [
"OptionsHelpOutput",
"returns",
"a",
"string",
"of",
"formatted",
"options"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/cmd/sockaddr/command/autohelp.go#L102-L121 | train |
hashicorp/go-sockaddr | unixsock.go | Equal | func (us UnixSock) Equal(sa SockAddr) bool {
usb, ok := sa.(UnixSock)
if !ok {
return false
}
if us.Path() != usb.Path() {
return false
}
return true
} | go | func (us UnixSock) Equal(sa SockAddr) bool {
usb, ok := sa.(UnixSock)
if !ok {
return false
}
if us.Path() != usb.Path() {
return false
}
return true
} | [
"func",
"(",
"us",
"UnixSock",
")",
"Equal",
"(",
"sa",
"SockAddr",
")",
"bool",
"{",
"usb",
",",
"ok",
":=",
"sa",
".",
"(",
"UnixSock",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"us",
".",
"Path",
"(",
")",
... | // Equal returns true if a SockAddr is equal to the receiving UnixSock. | [
"Equal",
"returns",
"true",
"if",
"a",
"SockAddr",
"is",
"equal",
"to",
"the",
"receiving",
"UnixSock",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/unixsock.go#L57-L68 | train |
hashicorp/go-sockaddr | unixsock.go | MustUnixSock | func MustUnixSock(addr string) UnixSock {
us, err := NewUnixSock(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create a UnixSock from %+q: %v", addr, err))
}
return us
} | go | func MustUnixSock(addr string) UnixSock {
us, err := NewUnixSock(addr)
if err != nil {
panic(fmt.Sprintf("Unable to create a UnixSock from %+q: %v", addr, err))
}
return us
} | [
"func",
"MustUnixSock",
"(",
"addr",
"string",
")",
"UnixSock",
"{",
"us",
",",
"err",
":=",
"NewUnixSock",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"addr",
",",
"err",
")",
... | // MustUnixSock is a helper method that must return an UnixSock or panic on
// invalid input. | [
"MustUnixSock",
"is",
"a",
"helper",
"method",
"that",
"must",
"return",
"an",
"UnixSock",
"or",
"panic",
"on",
"invalid",
"input",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/unixsock.go#L84-L90 | train |
hashicorp/go-sockaddr | unixsock.go | UnixSockAttr | func UnixSockAttr(us UnixSock, attrName AttrName) string {
fn, found := unixAttrMap[attrName]
if !found {
return ""
}
return fn(us)
} | go | func UnixSockAttr(us UnixSock, attrName AttrName) string {
fn, found := unixAttrMap[attrName]
if !found {
return ""
}
return fn(us)
} | [
"func",
"UnixSockAttr",
"(",
"us",
"UnixSock",
",",
"attrName",
"AttrName",
")",
"string",
"{",
"fn",
",",
"found",
":=",
"unixAttrMap",
"[",
"attrName",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fn",
"(",
... | // UnixSockAttr returns a string representation of an attribute for the given
// UnixSock. | [
"UnixSockAttr",
"returns",
"a",
"string",
"representation",
"of",
"an",
"attribute",
"for",
"the",
"given",
"UnixSock",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/unixsock.go#L114-L121 | train |
hashicorp/go-sockaddr | ifaddr.go | IfAddrAttr | func IfAddrAttr(ifAddr IfAddr, attrName AttrName) string {
fn, found := ifAddrAttrMap[attrName]
if !found {
return ""
}
return fn(ifAddr)
} | go | func IfAddrAttr(ifAddr IfAddr, attrName AttrName) string {
fn, found := ifAddrAttrMap[attrName]
if !found {
return ""
}
return fn(ifAddr)
} | [
"func",
"IfAddrAttr",
"(",
"ifAddr",
"IfAddr",
",",
"attrName",
"AttrName",
")",
"string",
"{",
"fn",
",",
"found",
":=",
"ifAddrAttrMap",
"[",
"attrName",
"]",
"\n",
"if",
"!",
"found",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fn",
"("... | // IfAddrAttr returns a string representation of an attribute for the given
// IfAddr. | [
"IfAddrAttr",
"returns",
"a",
"string",
"representation",
"of",
"an",
"attribute",
"for",
"the",
"given",
"IfAddr",
"."
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/ifaddr.go#L229-L236 | train |
hashicorp/go-sockaddr | rfc.go | IsRFC | func IsRFC(rfcNum uint, sa SockAddr) bool {
rfcNetMap := KnownRFCs()
rfcNets, ok := rfcNetMap[rfcNum]
if !ok {
return false
}
var contained bool
for _, rfcNet := range rfcNets {
if rfcNet.Contains(sa) {
contained = true
break
}
}
return contained
} | go | func IsRFC(rfcNum uint, sa SockAddr) bool {
rfcNetMap := KnownRFCs()
rfcNets, ok := rfcNetMap[rfcNum]
if !ok {
return false
}
var contained bool
for _, rfcNet := range rfcNets {
if rfcNet.Contains(sa) {
contained = true
break
}
}
return contained
} | [
"func",
"IsRFC",
"(",
"rfcNum",
"uint",
",",
"sa",
"SockAddr",
")",
"bool",
"{",
"rfcNetMap",
":=",
"KnownRFCs",
"(",
")",
"\n",
"rfcNets",
",",
"ok",
":=",
"rfcNetMap",
"[",
"rfcNum",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
... | // IsRFC tests to see if an SockAddr matches the specified RFC | [
"IsRFC",
"tests",
"to",
"see",
"if",
"an",
"SockAddr",
"matches",
"the",
"specified",
"RFC"
] | c7188e74f6acae5a989bdc959aa779f8b9f42faf | https://github.com/hashicorp/go-sockaddr/blob/c7188e74f6acae5a989bdc959aa779f8b9f42faf/rfc.go#L9-L24 | train |
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 := rfc... | 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 := rfc... | [
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 {
exc... | 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 {
exc... | [
"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 | train |
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 = N... | 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 = N... | [
"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 | train |
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.Na... | 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.Na... | [
"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 | train |
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, ... | 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, ... | [
"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 | train |
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... | 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... | [
"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 | train |
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... | 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... | [
"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 | train |
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(... | 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(... | [
"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 | train |
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... | 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... | [
"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 | train |
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", n... | 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", n... | [
"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 | train |
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 ... | 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 ... | [
"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 | train |
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(selector... | 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(selector... | [
"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 | train |
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)) {
cas... | 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)) {
cas... | [
"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 | train |
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()... | 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()... | [
"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 | train |
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... | 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... | [
"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 | train |
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 | train |
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... | 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... | [
"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 | train |
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 | train |
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(ifNameMatc... | 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(ifNameMatc... | [
"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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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([]by... | 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([]by... | [
"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 | train |
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 | train |
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 | train |
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 | train |
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.(... | 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.(... | [
"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 a... | [
"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 | train |
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 | train |
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 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.