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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
jroimartin/gocui | keybinding.go | matchKeypress | func (kb *keybinding) matchKeypress(key Key, ch rune, mod Modifier) bool {
return kb.key == key && kb.ch == ch && kb.mod == mod
} | go | func (kb *keybinding) matchKeypress(key Key, ch rune, mod Modifier) bool {
return kb.key == key && kb.ch == ch && kb.mod == mod
} | [
"func",
"(",
"kb",
"*",
"keybinding",
")",
"matchKeypress",
"(",
"key",
"Key",
",",
"ch",
"rune",
",",
"mod",
"Modifier",
")",
"bool",
"{",
"return",
"kb",
".",
"key",
"==",
"key",
"&&",
"kb",
".",
"ch",
"==",
"ch",
"&&",
"kb",
".",
"mod",
"==",
... | // matchKeypress returns if the keybinding matches the keypress. | [
"matchKeypress",
"returns",
"if",
"the",
"keybinding",
"matches",
"the",
"keypress",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L31-L33 | train |
jroimartin/gocui | keybinding.go | matchView | func (kb *keybinding) matchView(v *View) bool {
if kb.viewName == "" {
return true
}
return v != nil && kb.viewName == v.name
} | go | func (kb *keybinding) matchView(v *View) bool {
if kb.viewName == "" {
return true
}
return v != nil && kb.viewName == v.name
} | [
"func",
"(",
"kb",
"*",
"keybinding",
")",
"matchView",
"(",
"v",
"*",
"View",
")",
"bool",
"{",
"if",
"kb",
".",
"viewName",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"v",
"!=",
"nil",
"&&",
"kb",
".",
"viewName",
"==",... | // matchView returns if the keybinding matches the current view. | [
"matchView",
"returns",
"if",
"the",
"keybinding",
"matches",
"the",
"current",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/keybinding.go#L36-L41 | train |
jroimartin/gocui | view.go | String | func (l lineType) String() string {
str := ""
for _, c := range l {
str += string(c.chr)
}
return str
} | go | func (l lineType) String() string {
str := ""
for _, c := range l {
str += string(c.chr)
}
return str
} | [
"func",
"(",
"l",
"lineType",
")",
"String",
"(",
")",
"string",
"{",
"str",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"l",
"{",
"str",
"+=",
"string",
"(",
"c",
".",
"chr",
")",
"\n",
"}",
"\n",
"return",
"str",
"\n",
"}"
... | // String returns a string from a given cell slice. | [
"String",
"returns",
"a",
"string",
"from",
"a",
"given",
"cell",
"slice",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L89-L95 | train |
jroimartin/gocui | view.go | newView | func newView(name string, x0, y0, x1, y1 int, mode OutputMode) *View {
v := &View{
name: name,
x0: x0,
y0: y0,
x1: x1,
y1: y1,
Frame: true,
Editor: DefaultEditor,
tainted: true,
ei: newEscapeInterpreter(mode),
}
return v
} | go | func newView(name string, x0, y0, x1, y1 int, mode OutputMode) *View {
v := &View{
name: name,
x0: x0,
y0: y0,
x1: x1,
y1: y1,
Frame: true,
Editor: DefaultEditor,
tainted: true,
ei: newEscapeInterpreter(mode),
}
return v
} | [
"func",
"newView",
"(",
"name",
"string",
",",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
"int",
",",
"mode",
"OutputMode",
")",
"*",
"View",
"{",
"v",
":=",
"&",
"View",
"{",
"name",
":",
"name",
",",
"x0",
":",
"x0",
",",
"y0",
":",
"y0",
",",
... | // newView returns a new View object. | [
"newView",
"returns",
"a",
"new",
"View",
"object",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L98-L111 | train |
jroimartin/gocui | view.go | Size | func (v *View) Size() (x, y int) {
return v.x1 - v.x0 - 1, v.y1 - v.y0 - 1
} | go | func (v *View) Size() (x, y int) {
return v.x1 - v.x0 - 1, v.y1 - v.y0 - 1
} | [
"func",
"(",
"v",
"*",
"View",
")",
"Size",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"return",
"v",
".",
"x1",
"-",
"v",
".",
"x0",
"-",
"1",
",",
"v",
".",
"y1",
"-",
"v",
".",
"y0",
"-",
"1",
"\n",
"}"
] | // Size returns the number of visible columns and rows in the View. | [
"Size",
"returns",
"the",
"number",
"of",
"visible",
"columns",
"and",
"rows",
"in",
"the",
"View",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L114-L116 | train |
jroimartin/gocui | view.go | setRune | func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
maxX, maxY := v.Size()
if x < 0 || x >= maxX || y < 0 || y >= maxY {
return errors.New("invalid point")
}
var (
ry, rcy int
err error
)
if v.Highlight {
_, ry, err = v.realPosition(x, y)
if err != nil {
return err
}
... | go | func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
maxX, maxY := v.Size()
if x < 0 || x >= maxX || y < 0 || y >= maxY {
return errors.New("invalid point")
}
var (
ry, rcy int
err error
)
if v.Highlight {
_, ry, err = v.realPosition(x, y)
if err != nil {
return err
}
... | [
"func",
"(",
"v",
"*",
"View",
")",
"setRune",
"(",
"x",
",",
"y",
"int",
",",
"ch",
"rune",
",",
"fgColor",
",",
"bgColor",
"Attribute",
")",
"error",
"{",
"maxX",
",",
"maxY",
":=",
"v",
".",
"Size",
"(",
")",
"\n",
"if",
"x",
"<",
"0",
"||... | // setRune sets a rune at the given point relative to the view. It applies the
// specified colors, taking into account if the cell must be highlighted. Also,
// it checks if the position is valid. | [
"setRune",
"sets",
"a",
"rune",
"at",
"the",
"given",
"point",
"relative",
"to",
"the",
"view",
".",
"It",
"applies",
"the",
"specified",
"colors",
"taking",
"into",
"account",
"if",
"the",
"cell",
"must",
"be",
"highlighted",
".",
"Also",
"it",
"checks",
... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L126-L160 | train |
jroimartin/gocui | view.go | SetCursor | func (v *View) SetCursor(x, y int) error {
maxX, maxY := v.Size()
if x < 0 || x >= maxX || y < 0 || y >= maxY {
return errors.New("invalid point")
}
v.cx = x
v.cy = y
return nil
} | go | func (v *View) SetCursor(x, y int) error {
maxX, maxY := v.Size()
if x < 0 || x >= maxX || y < 0 || y >= maxY {
return errors.New("invalid point")
}
v.cx = x
v.cy = y
return nil
} | [
"func",
"(",
"v",
"*",
"View",
")",
"SetCursor",
"(",
"x",
",",
"y",
"int",
")",
"error",
"{",
"maxX",
",",
"maxY",
":=",
"v",
".",
"Size",
"(",
")",
"\n",
"if",
"x",
"<",
"0",
"||",
"x",
">=",
"maxX",
"||",
"y",
"<",
"0",
"||",
"y",
">="... | // SetCursor sets the cursor position of the view at the given point,
// relative to the view. It checks if the position is valid. | [
"SetCursor",
"sets",
"the",
"cursor",
"position",
"of",
"the",
"view",
"at",
"the",
"given",
"point",
"relative",
"to",
"the",
"view",
".",
"It",
"checks",
"if",
"the",
"position",
"is",
"valid",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L164-L172 | train |
jroimartin/gocui | view.go | Cursor | func (v *View) Cursor() (x, y int) {
return v.cx, v.cy
} | go | func (v *View) Cursor() (x, y int) {
return v.cx, v.cy
} | [
"func",
"(",
"v",
"*",
"View",
")",
"Cursor",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"return",
"v",
".",
"cx",
",",
"v",
".",
"cy",
"\n",
"}"
] | // Cursor returns the cursor position of the view. | [
"Cursor",
"returns",
"the",
"cursor",
"position",
"of",
"the",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L175-L177 | train |
jroimartin/gocui | view.go | SetOrigin | func (v *View) SetOrigin(x, y int) error {
if x < 0 || y < 0 {
return errors.New("invalid point")
}
v.ox = x
v.oy = y
return nil
} | go | func (v *View) SetOrigin(x, y int) error {
if x < 0 || y < 0 {
return errors.New("invalid point")
}
v.ox = x
v.oy = y
return nil
} | [
"func",
"(",
"v",
"*",
"View",
")",
"SetOrigin",
"(",
"x",
",",
"y",
"int",
")",
"error",
"{",
"if",
"x",
"<",
"0",
"||",
"y",
"<",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"v",
".",
"ox",
"=",
"x",... | // SetOrigin sets the origin position of the view's internal buffer,
// so the buffer starts to be printed from this point, which means that
// it is linked with the origin point of view. It can be used to
// implement Horizontal and Vertical scrolling with just incrementing
// or decrementing ox and oy. | [
"SetOrigin",
"sets",
"the",
"origin",
"position",
"of",
"the",
"view",
"s",
"internal",
"buffer",
"so",
"the",
"buffer",
"starts",
"to",
"be",
"printed",
"from",
"this",
"point",
"which",
"means",
"that",
"it",
"is",
"linked",
"with",
"the",
"origin",
"poi... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L184-L191 | train |
jroimartin/gocui | view.go | Origin | func (v *View) Origin() (x, y int) {
return v.ox, v.oy
} | go | func (v *View) Origin() (x, y int) {
return v.ox, v.oy
} | [
"func",
"(",
"v",
"*",
"View",
")",
"Origin",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"return",
"v",
".",
"ox",
",",
"v",
".",
"oy",
"\n",
"}"
] | // Origin returns the origin position of the view. | [
"Origin",
"returns",
"the",
"origin",
"position",
"of",
"the",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L194-L196 | train |
jroimartin/gocui | view.go | Write | func (v *View) Write(p []byte) (n int, err error) {
v.tainted = true
for _, ch := range bytes.Runes(p) {
switch ch {
case '\n':
v.lines = append(v.lines, nil)
case '\r':
nl := len(v.lines)
if nl > 0 {
v.lines[nl-1] = nil
} else {
v.lines = make([][]cell, 1)
}
default:
cells := v.par... | go | func (v *View) Write(p []byte) (n int, err error) {
v.tainted = true
for _, ch := range bytes.Runes(p) {
switch ch {
case '\n':
v.lines = append(v.lines, nil)
case '\r':
nl := len(v.lines)
if nl > 0 {
v.lines[nl-1] = nil
} else {
v.lines = make([][]cell, 1)
}
default:
cells := v.par... | [
"func",
"(",
"v",
"*",
"View",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"v",
".",
"tainted",
"=",
"true",
"\n\n",
"for",
"_",
",",
"ch",
":=",
"range",
"bytes",
".",
"Runes",
"(",
"p",
"... | // Write appends a byte slice into the view's internal buffer. Because
// View implements the io.Writer interface, it can be passed as parameter
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
// be called to clear the view's buffer. | [
"Write",
"appends",
"a",
"byte",
"slice",
"into",
"the",
"view",
"s",
"internal",
"buffer",
".",
"Because",
"View",
"implements",
"the",
"io",
".",
"Writer",
"interface",
"it",
"can",
"be",
"passed",
"as",
"parameter",
"of",
"functions",
"like",
"fmt",
"."... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L202-L231 | train |
jroimartin/gocui | view.go | parseInput | func (v *View) parseInput(ch rune) []cell {
cells := []cell{}
isEscape, err := v.ei.parseOne(ch)
if err != nil {
for _, r := range v.ei.runes() {
c := cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: r,
}
cells = append(cells, c)
}
v.ei.reset()
} else {
if isEscape {
return ni... | go | func (v *View) parseInput(ch rune) []cell {
cells := []cell{}
isEscape, err := v.ei.parseOne(ch)
if err != nil {
for _, r := range v.ei.runes() {
c := cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: r,
}
cells = append(cells, c)
}
v.ei.reset()
} else {
if isEscape {
return ni... | [
"func",
"(",
"v",
"*",
"View",
")",
"parseInput",
"(",
"ch",
"rune",
")",
"[",
"]",
"cell",
"{",
"cells",
":=",
"[",
"]",
"cell",
"{",
"}",
"\n\n",
"isEscape",
",",
"err",
":=",
"v",
".",
"ei",
".",
"parseOne",
"(",
"ch",
")",
"\n",
"if",
"er... | // parseInput parses char by char the input written to the View. It returns nil
// while processing ESC sequences. Otherwise, it returns a cell slice that
// contains the processed data. | [
"parseInput",
"parses",
"char",
"by",
"char",
"the",
"input",
"written",
"to",
"the",
"View",
".",
"It",
"returns",
"nil",
"while",
"processing",
"ESC",
"sequences",
".",
"Otherwise",
"it",
"returns",
"a",
"cell",
"slice",
"that",
"contains",
"the",
"process... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L236-L263 | train |
jroimartin/gocui | view.go | draw | func (v *View) draw() error {
maxX, maxY := v.Size()
if v.Wrap {
if maxX == 0 {
return errors.New("X size of the view cannot be 0")
}
v.ox = 0
}
if v.tainted {
v.viewLines = nil
for i, line := range v.lines {
if v.Wrap {
if len(line) < maxX {
vline := viewLine{linesX: 0, linesY: i, line: l... | go | func (v *View) draw() error {
maxX, maxY := v.Size()
if v.Wrap {
if maxX == 0 {
return errors.New("X size of the view cannot be 0")
}
v.ox = 0
}
if v.tainted {
v.viewLines = nil
for i, line := range v.lines {
if v.Wrap {
if len(line) < maxX {
vline := viewLine{linesX: 0, linesY: i, line: l... | [
"func",
"(",
"v",
"*",
"View",
")",
"draw",
"(",
")",
"error",
"{",
"maxX",
",",
"maxY",
":=",
"v",
".",
"Size",
"(",
")",
"\n\n",
"if",
"v",
".",
"Wrap",
"{",
"if",
"maxX",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"... | // draw re-draws the view's contents. | [
"draw",
"re",
"-",
"draws",
"the",
"view",
"s",
"contents",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L288-L361 | train |
jroimartin/gocui | view.go | Clear | func (v *View) Clear() {
v.tainted = true
v.lines = nil
v.viewLines = nil
v.readOffset = 0
v.clearRunes()
} | go | func (v *View) Clear() {
v.tainted = true
v.lines = nil
v.viewLines = nil
v.readOffset = 0
v.clearRunes()
} | [
"func",
"(",
"v",
"*",
"View",
")",
"Clear",
"(",
")",
"{",
"v",
".",
"tainted",
"=",
"true",
"\n\n",
"v",
".",
"lines",
"=",
"nil",
"\n",
"v",
".",
"viewLines",
"=",
"nil",
"\n",
"v",
".",
"readOffset",
"=",
"0",
"\n",
"v",
".",
"clearRunes",
... | // Clear empties the view's internal buffer. | [
"Clear",
"empties",
"the",
"view",
"s",
"internal",
"buffer",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L391-L398 | train |
jroimartin/gocui | view.go | clearRunes | func (v *View) clearRunes() {
maxX, maxY := v.Size()
for x := 0; x < maxX; x++ {
for y := 0; y < maxY; y++ {
termbox.SetCell(v.x0+x+1, v.y0+y+1, ' ',
termbox.Attribute(v.FgColor), termbox.Attribute(v.BgColor))
}
}
} | go | func (v *View) clearRunes() {
maxX, maxY := v.Size()
for x := 0; x < maxX; x++ {
for y := 0; y < maxY; y++ {
termbox.SetCell(v.x0+x+1, v.y0+y+1, ' ',
termbox.Attribute(v.FgColor), termbox.Attribute(v.BgColor))
}
}
} | [
"func",
"(",
"v",
"*",
"View",
")",
"clearRunes",
"(",
")",
"{",
"maxX",
",",
"maxY",
":=",
"v",
".",
"Size",
"(",
")",
"\n",
"for",
"x",
":=",
"0",
";",
"x",
"<",
"maxX",
";",
"x",
"++",
"{",
"for",
"y",
":=",
"0",
";",
"y",
"<",
"maxY",... | // clearRunes erases all the cells in the view. | [
"clearRunes",
"erases",
"all",
"the",
"cells",
"in",
"the",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L401-L409 | train |
jroimartin/gocui | view.go | BufferLines | func (v *View) BufferLines() []string {
lines := make([]string, len(v.lines))
for i, l := range v.lines {
str := lineType(l).String()
str = strings.Replace(str, "\x00", " ", -1)
lines[i] = str
}
return lines
} | go | func (v *View) BufferLines() []string {
lines := make([]string, len(v.lines))
for i, l := range v.lines {
str := lineType(l).String()
str = strings.Replace(str, "\x00", " ", -1)
lines[i] = str
}
return lines
} | [
"func",
"(",
"v",
"*",
"View",
")",
"BufferLines",
"(",
")",
"[",
"]",
"string",
"{",
"lines",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"v",
".",
"lines",
")",
")",
"\n",
"for",
"i",
",",
"l",
":=",
"range",
"v",
".",
"lines",
... | // BufferLines returns the lines in the view's internal
// buffer. | [
"BufferLines",
"returns",
"the",
"lines",
"in",
"the",
"view",
"s",
"internal",
"buffer",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L413-L421 | train |
jroimartin/gocui | view.go | Buffer | func (v *View) Buffer() string {
str := ""
for _, l := range v.lines {
str += lineType(l).String() + "\n"
}
return strings.Replace(str, "\x00", " ", -1)
} | go | func (v *View) Buffer() string {
str := ""
for _, l := range v.lines {
str += lineType(l).String() + "\n"
}
return strings.Replace(str, "\x00", " ", -1)
} | [
"func",
"(",
"v",
"*",
"View",
")",
"Buffer",
"(",
")",
"string",
"{",
"str",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"v",
".",
"lines",
"{",
"str",
"+=",
"lineType",
"(",
"l",
")",
".",
"String",
"(",
")",
"+",
"\"",
"... | // Buffer returns a string with the contents of the view's internal
// buffer. | [
"Buffer",
"returns",
"a",
"string",
"with",
"the",
"contents",
"of",
"the",
"view",
"s",
"internal",
"buffer",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L425-L431 | train |
jroimartin/gocui | view.go | ViewBufferLines | func (v *View) ViewBufferLines() []string {
lines := make([]string, len(v.viewLines))
for i, l := range v.viewLines {
str := lineType(l.line).String()
str = strings.Replace(str, "\x00", " ", -1)
lines[i] = str
}
return lines
} | go | func (v *View) ViewBufferLines() []string {
lines := make([]string, len(v.viewLines))
for i, l := range v.viewLines {
str := lineType(l.line).String()
str = strings.Replace(str, "\x00", " ", -1)
lines[i] = str
}
return lines
} | [
"func",
"(",
"v",
"*",
"View",
")",
"ViewBufferLines",
"(",
")",
"[",
"]",
"string",
"{",
"lines",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"v",
".",
"viewLines",
")",
")",
"\n",
"for",
"i",
",",
"l",
":=",
"range",
"v",
".",
"... | // ViewBufferLines returns the lines in the view's internal
// buffer that is shown to the user. | [
"ViewBufferLines",
"returns",
"the",
"lines",
"in",
"the",
"view",
"s",
"internal",
"buffer",
"that",
"is",
"shown",
"to",
"the",
"user",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L435-L443 | train |
jroimartin/gocui | view.go | ViewBuffer | func (v *View) ViewBuffer() string {
str := ""
for _, l := range v.viewLines {
str += lineType(l.line).String() + "\n"
}
return strings.Replace(str, "\x00", " ", -1)
} | go | func (v *View) ViewBuffer() string {
str := ""
for _, l := range v.viewLines {
str += lineType(l.line).String() + "\n"
}
return strings.Replace(str, "\x00", " ", -1)
} | [
"func",
"(",
"v",
"*",
"View",
")",
"ViewBuffer",
"(",
")",
"string",
"{",
"str",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"v",
".",
"viewLines",
"{",
"str",
"+=",
"lineType",
"(",
"l",
".",
"line",
")",
".",
"String",
"(",
... | // ViewBuffer returns a string with the contents of the view's buffer that is
// shown to the user. | [
"ViewBuffer",
"returns",
"a",
"string",
"with",
"the",
"contents",
"of",
"the",
"view",
"s",
"buffer",
"that",
"is",
"shown",
"to",
"the",
"user",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/view.go#L447-L453 | train |
jroimartin/gocui | escape.go | runes | func (ei *escapeInterpreter) runes() []rune {
switch ei.state {
case stateNone:
return []rune{0x1b}
case stateEscape:
return []rune{0x1b, ei.curch}
case stateCSI:
return []rune{0x1b, '[', ei.curch}
case stateParams:
ret := []rune{0x1b, '['}
for _, s := range ei.csiParam {
ret = append(ret, []rune(s)..... | go | func (ei *escapeInterpreter) runes() []rune {
switch ei.state {
case stateNone:
return []rune{0x1b}
case stateEscape:
return []rune{0x1b, ei.curch}
case stateCSI:
return []rune{0x1b, '[', ei.curch}
case stateParams:
ret := []rune{0x1b, '['}
for _, s := range ei.csiParam {
ret = append(ret, []rune(s)..... | [
"func",
"(",
"ei",
"*",
"escapeInterpreter",
")",
"runes",
"(",
")",
"[",
"]",
"rune",
"{",
"switch",
"ei",
".",
"state",
"{",
"case",
"stateNone",
":",
"return",
"[",
"]",
"rune",
"{",
"0x1b",
"}",
"\n",
"case",
"stateEscape",
":",
"return",
"[",
... | // runes in case of error will output the non-parsed runes as a string. | [
"runes",
"in",
"case",
"of",
"error",
"will",
"output",
"the",
"non",
"-",
"parsed",
"runes",
"as",
"a",
"string",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L36-L53 | train |
jroimartin/gocui | escape.go | newEscapeInterpreter | func newEscapeInterpreter(mode OutputMode) *escapeInterpreter {
ei := &escapeInterpreter{
state: stateNone,
curFgColor: ColorDefault,
curBgColor: ColorDefault,
mode: mode,
}
return ei
} | go | func newEscapeInterpreter(mode OutputMode) *escapeInterpreter {
ei := &escapeInterpreter{
state: stateNone,
curFgColor: ColorDefault,
curBgColor: ColorDefault,
mode: mode,
}
return ei
} | [
"func",
"newEscapeInterpreter",
"(",
"mode",
"OutputMode",
")",
"*",
"escapeInterpreter",
"{",
"ei",
":=",
"&",
"escapeInterpreter",
"{",
"state",
":",
"stateNone",
",",
"curFgColor",
":",
"ColorDefault",
",",
"curBgColor",
":",
"ColorDefault",
",",
"mode",
":",... | // newEscapeInterpreter returns an escapeInterpreter that will be able to parse
// terminal escape sequences. | [
"newEscapeInterpreter",
"returns",
"an",
"escapeInterpreter",
"that",
"will",
"be",
"able",
"to",
"parse",
"terminal",
"escape",
"sequences",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L57-L65 | train |
jroimartin/gocui | escape.go | reset | func (ei *escapeInterpreter) reset() {
ei.state = stateNone
ei.curFgColor = ColorDefault
ei.curBgColor = ColorDefault
ei.csiParam = nil
} | go | func (ei *escapeInterpreter) reset() {
ei.state = stateNone
ei.curFgColor = ColorDefault
ei.curBgColor = ColorDefault
ei.csiParam = nil
} | [
"func",
"(",
"ei",
"*",
"escapeInterpreter",
")",
"reset",
"(",
")",
"{",
"ei",
".",
"state",
"=",
"stateNone",
"\n",
"ei",
".",
"curFgColor",
"=",
"ColorDefault",
"\n",
"ei",
".",
"curBgColor",
"=",
"ColorDefault",
"\n",
"ei",
".",
"csiParam",
"=",
"n... | // reset sets the escapeInterpreter in initial state. | [
"reset",
"sets",
"the",
"escapeInterpreter",
"in",
"initial",
"state",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L68-L73 | train |
jroimartin/gocui | escape.go | parseOne | func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) {
// Sanity checks
if len(ei.csiParam) > 20 {
return false, errCSITooLong
}
if len(ei.csiParam) > 0 && len(ei.csiParam[len(ei.csiParam)-1]) > 255 {
return false, errCSITooLong
}
ei.curch = ch
switch ei.state {
case stateNone:
if c... | go | func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) {
// Sanity checks
if len(ei.csiParam) > 20 {
return false, errCSITooLong
}
if len(ei.csiParam) > 0 && len(ei.csiParam[len(ei.csiParam)-1]) > 255 {
return false, errCSITooLong
}
ei.curch = ch
switch ei.state {
case stateNone:
if c... | [
"func",
"(",
"ei",
"*",
"escapeInterpreter",
")",
"parseOne",
"(",
"ch",
"rune",
")",
"(",
"isEscape",
"bool",
",",
"err",
"error",
")",
"{",
"// Sanity checks",
"if",
"len",
"(",
"ei",
".",
"csiParam",
")",
">",
"20",
"{",
"return",
"false",
",",
"e... | // parseOne parses a rune. If isEscape is true, it means that the rune is part
// of an escape sequence, and as such should not be printed verbatim. Otherwise,
// it's not an escape sequence. | [
"parseOne",
"parses",
"a",
"rune",
".",
"If",
"isEscape",
"is",
"true",
"it",
"means",
"that",
"the",
"rune",
"is",
"part",
"of",
"an",
"escape",
"sequence",
"and",
"as",
"such",
"should",
"not",
"be",
"printed",
"verbatim",
".",
"Otherwise",
"it",
"s",
... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/escape.go#L78-L141 | train |
jroimartin/gocui | gui.go | NewGui | func NewGui(mode OutputMode) (*Gui, error) {
if err := termbox.Init(); err != nil {
return nil, err
}
g := &Gui{}
g.outputMode = mode
termbox.SetOutputMode(termbox.OutputMode(mode))
g.tbEvents = make(chan termbox.Event, 20)
g.userEvents = make(chan userEvent, 20)
g.maxX, g.maxY = termbox.Size()
g.BgColo... | go | func NewGui(mode OutputMode) (*Gui, error) {
if err := termbox.Init(); err != nil {
return nil, err
}
g := &Gui{}
g.outputMode = mode
termbox.SetOutputMode(termbox.OutputMode(mode))
g.tbEvents = make(chan termbox.Event, 20)
g.userEvents = make(chan userEvent, 20)
g.maxX, g.maxY = termbox.Size()
g.BgColo... | [
"func",
"NewGui",
"(",
"mode",
"OutputMode",
")",
"(",
"*",
"Gui",
",",
"error",
")",
"{",
"if",
"err",
":=",
"termbox",
".",
"Init",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"g",
":=",
"&",
"Gui",... | // NewGui returns a new Gui object with a given output mode. | [
"NewGui",
"returns",
"a",
"new",
"Gui",
"object",
"with",
"a",
"given",
"output",
"mode",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L72-L91 | train |
jroimartin/gocui | gui.go | Size | func (g *Gui) Size() (x, y int) {
return g.maxX, g.maxY
} | go | func (g *Gui) Size() (x, y int) {
return g.maxX, g.maxY
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"Size",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"return",
"g",
".",
"maxX",
",",
"g",
".",
"maxY",
"\n",
"}"
] | // Size returns the terminal's size. | [
"Size",
"returns",
"the",
"terminal",
"s",
"size",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L100-L102 | train |
jroimartin/gocui | gui.go | SetRune | func (g *Gui) SetRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY {
return errors.New("invalid point")
}
termbox.SetCell(x, y, ch, termbox.Attribute(fgColor), termbox.Attribute(bgColor))
return nil
} | go | func (g *Gui) SetRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY {
return errors.New("invalid point")
}
termbox.SetCell(x, y, ch, termbox.Attribute(fgColor), termbox.Attribute(bgColor))
return nil
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"SetRune",
"(",
"x",
",",
"y",
"int",
",",
"ch",
"rune",
",",
"fgColor",
",",
"bgColor",
"Attribute",
")",
"error",
"{",
"if",
"x",
"<",
"0",
"||",
"y",
"<",
"0",
"||",
"x",
">=",
"g",
".",
"maxX",
"||",
"... | // SetRune writes a rune at the given point, relative to the top-left
// corner of the terminal. It checks if the position is valid and applies
// the given colors. | [
"SetRune",
"writes",
"a",
"rune",
"at",
"the",
"given",
"point",
"relative",
"to",
"the",
"top",
"-",
"left",
"corner",
"of",
"the",
"terminal",
".",
"It",
"checks",
"if",
"the",
"position",
"is",
"valid",
"and",
"applies",
"the",
"given",
"colors",
"."
... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L107-L113 | train |
jroimartin/gocui | gui.go | Rune | func (g *Gui) Rune(x, y int) (rune, error) {
if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY {
return ' ', errors.New("invalid point")
}
c := termbox.CellBuffer()[y*g.maxX+x]
return c.Ch, nil
} | go | func (g *Gui) Rune(x, y int) (rune, error) {
if x < 0 || y < 0 || x >= g.maxX || y >= g.maxY {
return ' ', errors.New("invalid point")
}
c := termbox.CellBuffer()[y*g.maxX+x]
return c.Ch, nil
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"Rune",
"(",
"x",
",",
"y",
"int",
")",
"(",
"rune",
",",
"error",
")",
"{",
"if",
"x",
"<",
"0",
"||",
"y",
"<",
"0",
"||",
"x",
">=",
"g",
".",
"maxX",
"||",
"y",
">=",
"g",
".",
"maxY",
"{",
"return... | // Rune returns the rune contained in the cell at the given position.
// It checks if the position is valid. | [
"Rune",
"returns",
"the",
"rune",
"contained",
"in",
"the",
"cell",
"at",
"the",
"given",
"position",
".",
"It",
"checks",
"if",
"the",
"position",
"is",
"valid",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L117-L123 | train |
jroimartin/gocui | gui.go | SetViewOnTop | func (g *Gui) SetViewOnTop(name string) (*View, error) {
for i, v := range g.views {
if v.name == name {
s := append(g.views[:i], g.views[i+1:]...)
g.views = append(s, v)
return v, nil
}
}
return nil, ErrUnknownView
} | go | func (g *Gui) SetViewOnTop(name string) (*View, error) {
for i, v := range g.views {
if v.name == name {
s := append(g.views[:i], g.views[i+1:]...)
g.views = append(s, v)
return v, nil
}
}
return nil, ErrUnknownView
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"SetViewOnTop",
"(",
"name",
"string",
")",
"(",
"*",
"View",
",",
"error",
")",
"{",
"for",
"i",
",",
"v",
":=",
"range",
"g",
".",
"views",
"{",
"if",
"v",
".",
"name",
"==",
"name",
"{",
"s",
":=",
"appen... | // SetViewOnTop sets the given view on top of the existing ones. | [
"SetViewOnTop",
"sets",
"the",
"given",
"view",
"on",
"top",
"of",
"the",
"existing",
"ones",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L155-L164 | train |
jroimartin/gocui | gui.go | View | func (g *Gui) View(name string) (*View, error) {
for _, v := range g.views {
if v.name == name {
return v, nil
}
}
return nil, ErrUnknownView
} | go | func (g *Gui) View(name string) (*View, error) {
for _, v := range g.views {
if v.name == name {
return v, nil
}
}
return nil, ErrUnknownView
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"View",
"(",
"name",
"string",
")",
"(",
"*",
"View",
",",
"error",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"g",
".",
"views",
"{",
"if",
"v",
".",
"name",
"==",
"name",
"{",
"return",
"v",
",",
"ni... | // View returns a pointer to the view with the given name, or error
// ErrUnknownView if a view with that name does not exist. | [
"View",
"returns",
"a",
"pointer",
"to",
"the",
"view",
"with",
"the",
"given",
"name",
"or",
"error",
"ErrUnknownView",
"if",
"a",
"view",
"with",
"that",
"name",
"does",
"not",
"exist",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L185-L192 | train |
jroimartin/gocui | gui.go | ViewByPosition | func (g *Gui) ViewByPosition(x, y int) (*View, error) {
// traverse views in reverse order checking top views first
for i := len(g.views); i > 0; i-- {
v := g.views[i-1]
if x > v.x0 && x < v.x1 && y > v.y0 && y < v.y1 {
return v, nil
}
}
return nil, ErrUnknownView
} | go | func (g *Gui) ViewByPosition(x, y int) (*View, error) {
// traverse views in reverse order checking top views first
for i := len(g.views); i > 0; i-- {
v := g.views[i-1]
if x > v.x0 && x < v.x1 && y > v.y0 && y < v.y1 {
return v, nil
}
}
return nil, ErrUnknownView
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"ViewByPosition",
"(",
"x",
",",
"y",
"int",
")",
"(",
"*",
"View",
",",
"error",
")",
"{",
"// traverse views in reverse order checking top views first",
"for",
"i",
":=",
"len",
"(",
"g",
".",
"views",
")",
";",
"i",
... | // ViewByPosition returns a pointer to a view matching the given position, or
// error ErrUnknownView if a view in that position does not exist. | [
"ViewByPosition",
"returns",
"a",
"pointer",
"to",
"a",
"view",
"matching",
"the",
"given",
"position",
"or",
"error",
"ErrUnknownView",
"if",
"a",
"view",
"in",
"that",
"position",
"does",
"not",
"exist",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L196-L205 | train |
jroimartin/gocui | gui.go | ViewPosition | func (g *Gui) ViewPosition(name string) (x0, y0, x1, y1 int, err error) {
for _, v := range g.views {
if v.name == name {
return v.x0, v.y0, v.x1, v.y1, nil
}
}
return 0, 0, 0, 0, ErrUnknownView
} | go | func (g *Gui) ViewPosition(name string) (x0, y0, x1, y1 int, err error) {
for _, v := range g.views {
if v.name == name {
return v.x0, v.y0, v.x1, v.y1, nil
}
}
return 0, 0, 0, 0, ErrUnknownView
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"ViewPosition",
"(",
"name",
"string",
")",
"(",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
"int",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"g",
".",
"views",
"{",
"if",
"v",
".",
"n... | // ViewPosition returns the coordinates of the view with the given name, or
// error ErrUnknownView if a view with that name does not exist. | [
"ViewPosition",
"returns",
"the",
"coordinates",
"of",
"the",
"view",
"with",
"the",
"given",
"name",
"or",
"error",
"ErrUnknownView",
"if",
"a",
"view",
"with",
"that",
"name",
"does",
"not",
"exist",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L209-L216 | train |
jroimartin/gocui | gui.go | DeleteView | func (g *Gui) DeleteView(name string) error {
for i, v := range g.views {
if v.name == name {
g.views = append(g.views[:i], g.views[i+1:]...)
return nil
}
}
return ErrUnknownView
} | go | func (g *Gui) DeleteView(name string) error {
for i, v := range g.views {
if v.name == name {
g.views = append(g.views[:i], g.views[i+1:]...)
return nil
}
}
return ErrUnknownView
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"DeleteView",
"(",
"name",
"string",
")",
"error",
"{",
"for",
"i",
",",
"v",
":=",
"range",
"g",
".",
"views",
"{",
"if",
"v",
".",
"name",
"==",
"name",
"{",
"g",
".",
"views",
"=",
"append",
"(",
"g",
"."... | // DeleteView deletes a view by name. | [
"DeleteView",
"deletes",
"a",
"view",
"by",
"name",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L219-L227 | train |
jroimartin/gocui | gui.go | DeleteKeybinding | func (g *Gui) DeleteKeybinding(viewname string, key interface{}, mod Modifier) error {
k, ch, err := getKey(key)
if err != nil {
return err
}
for i, kb := range g.keybindings {
if kb.viewName == viewname && kb.ch == ch && kb.key == k && kb.mod == mod {
g.keybindings = append(g.keybindings[:i], g.keybindings... | go | func (g *Gui) DeleteKeybinding(viewname string, key interface{}, mod Modifier) error {
k, ch, err := getKey(key)
if err != nil {
return err
}
for i, kb := range g.keybindings {
if kb.viewName == viewname && kb.ch == ch && kb.key == k && kb.mod == mod {
g.keybindings = append(g.keybindings[:i], g.keybindings... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"DeleteKeybinding",
"(",
"viewname",
"string",
",",
"key",
"interface",
"{",
"}",
",",
"mod",
"Modifier",
")",
"error",
"{",
"k",
",",
"ch",
",",
"err",
":=",
"getKey",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
... | // DeleteKeybinding deletes a keybinding. | [
"DeleteKeybinding",
"deletes",
"a",
"keybinding",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L262-L275 | train |
jroimartin/gocui | gui.go | DeleteKeybindings | func (g *Gui) DeleteKeybindings(viewname string) {
var s []*keybinding
for _, kb := range g.keybindings {
if kb.viewName != viewname {
s = append(s, kb)
}
}
g.keybindings = s
} | go | func (g *Gui) DeleteKeybindings(viewname string) {
var s []*keybinding
for _, kb := range g.keybindings {
if kb.viewName != viewname {
s = append(s, kb)
}
}
g.keybindings = s
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"DeleteKeybindings",
"(",
"viewname",
"string",
")",
"{",
"var",
"s",
"[",
"]",
"*",
"keybinding",
"\n",
"for",
"_",
",",
"kb",
":=",
"range",
"g",
".",
"keybindings",
"{",
"if",
"kb",
".",
"viewName",
"!=",
"view... | // DeleteKeybindings deletes all keybindings of view. | [
"DeleteKeybindings",
"deletes",
"all",
"keybindings",
"of",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L278-L286 | train |
jroimartin/gocui | gui.go | getKey | func getKey(key interface{}) (Key, rune, error) {
switch t := key.(type) {
case Key:
return t, 0, nil
case rune:
return 0, t, nil
default:
return 0, 0, errors.New("unknown type")
}
} | go | func getKey(key interface{}) (Key, rune, error) {
switch t := key.(type) {
case Key:
return t, 0, nil
case rune:
return 0, t, nil
default:
return 0, 0, errors.New("unknown type")
}
} | [
"func",
"getKey",
"(",
"key",
"interface",
"{",
"}",
")",
"(",
"Key",
",",
"rune",
",",
"error",
")",
"{",
"switch",
"t",
":=",
"key",
".",
"(",
"type",
")",
"{",
"case",
"Key",
":",
"return",
"t",
",",
"0",
",",
"nil",
"\n",
"case",
"rune",
... | // getKey takes an empty interface with a key and returns the corresponding
// typed Key or rune. | [
"getKey",
"takes",
"an",
"empty",
"interface",
"with",
"a",
"key",
"and",
"returns",
"the",
"corresponding",
"typed",
"Key",
"or",
"rune",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L290-L299 | train |
jroimartin/gocui | gui.go | Update | func (g *Gui) Update(f func(*Gui) error) {
go func() { g.userEvents <- userEvent{f: f} }()
} | go | func (g *Gui) Update(f func(*Gui) error) {
go func() { g.userEvents <- userEvent{f: f} }()
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"Update",
"(",
"f",
"func",
"(",
"*",
"Gui",
")",
"error",
")",
"{",
"go",
"func",
"(",
")",
"{",
"g",
".",
"userEvents",
"<-",
"userEvent",
"{",
"f",
":",
"f",
"}",
"}",
"(",
")",
"\n",
"}"
] | // Update executes the passed function. This method can be called safely from a
// goroutine in order to update the GUI. It is important to note that the
// passed function won't be executed immediately, instead it will be added to
// the user events queue. Given that Update spawns a goroutine, the order in
// which th... | [
"Update",
"executes",
"the",
"passed",
"function",
".",
"This",
"method",
"can",
"be",
"called",
"safely",
"from",
"a",
"goroutine",
"in",
"order",
"to",
"update",
"the",
"GUI",
".",
"It",
"is",
"important",
"to",
"note",
"that",
"the",
"passed",
"function... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L311-L313 | train |
jroimartin/gocui | gui.go | SetManager | func (g *Gui) SetManager(managers ...Manager) {
g.managers = managers
g.currentView = nil
g.views = nil
g.keybindings = nil
go func() { g.tbEvents <- termbox.Event{Type: termbox.EventResize} }()
} | go | func (g *Gui) SetManager(managers ...Manager) {
g.managers = managers
g.currentView = nil
g.views = nil
g.keybindings = nil
go func() { g.tbEvents <- termbox.Event{Type: termbox.EventResize} }()
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"SetManager",
"(",
"managers",
"...",
"Manager",
")",
"{",
"g",
".",
"managers",
"=",
"managers",
"\n",
"g",
".",
"currentView",
"=",
"nil",
"\n",
"g",
".",
"views",
"=",
"nil",
"\n",
"g",
".",
"keybindings",
"=",... | // SetManager sets the given GUI managers. It deletes all views and
// keybindings. | [
"SetManager",
"sets",
"the",
"given",
"GUI",
"managers",
".",
"It",
"deletes",
"all",
"views",
"and",
"keybindings",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L334-L341 | train |
jroimartin/gocui | gui.go | SetManagerFunc | func (g *Gui) SetManagerFunc(manager func(*Gui) error) {
g.SetManager(ManagerFunc(manager))
} | go | func (g *Gui) SetManagerFunc(manager func(*Gui) error) {
g.SetManager(ManagerFunc(manager))
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"SetManagerFunc",
"(",
"manager",
"func",
"(",
"*",
"Gui",
")",
"error",
")",
"{",
"g",
".",
"SetManager",
"(",
"ManagerFunc",
"(",
"manager",
")",
")",
"\n",
"}"
] | // SetManagerFunc sets the given manager function. It deletes all views and
// keybindings. | [
"SetManagerFunc",
"sets",
"the",
"given",
"manager",
"function",
".",
"It",
"deletes",
"all",
"views",
"and",
"keybindings",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L345-L347 | train |
jroimartin/gocui | gui.go | MainLoop | func (g *Gui) MainLoop() error {
go func() {
for {
g.tbEvents <- termbox.PollEvent()
}
}()
inputMode := termbox.InputAlt
if g.InputEsc {
inputMode = termbox.InputEsc
}
if g.Mouse {
inputMode |= termbox.InputMouse
}
termbox.SetInputMode(inputMode)
if err := g.flush(); err != nil {
return err
}
... | go | func (g *Gui) MainLoop() error {
go func() {
for {
g.tbEvents <- termbox.PollEvent()
}
}()
inputMode := termbox.InputAlt
if g.InputEsc {
inputMode = termbox.InputEsc
}
if g.Mouse {
inputMode |= termbox.InputMouse
}
termbox.SetInputMode(inputMode)
if err := g.flush(); err != nil {
return err
}
... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"MainLoop",
"(",
")",
"error",
"{",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"g",
".",
"tbEvents",
"<-",
"termbox",
".",
"PollEvent",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"inputMode",
":=",
"termb... | // MainLoop runs the main loop until an error is returned. A successful
// finish should return ErrQuit. | [
"MainLoop",
"runs",
"the",
"main",
"loop",
"until",
"an",
"error",
"is",
"returned",
".",
"A",
"successful",
"finish",
"should",
"return",
"ErrQuit",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L351-L388 | train |
jroimartin/gocui | gui.go | consumeevents | func (g *Gui) consumeevents() error {
for {
select {
case ev := <-g.tbEvents:
if err := g.handleEvent(&ev); err != nil {
return err
}
case ev := <-g.userEvents:
if err := ev.f(g); err != nil {
return err
}
default:
return nil
}
}
} | go | func (g *Gui) consumeevents() error {
for {
select {
case ev := <-g.tbEvents:
if err := g.handleEvent(&ev); err != nil {
return err
}
case ev := <-g.userEvents:
if err := ev.f(g); err != nil {
return err
}
default:
return nil
}
}
} | [
"func",
"(",
"g",
"*",
"Gui",
")",
"consumeevents",
"(",
")",
"error",
"{",
"for",
"{",
"select",
"{",
"case",
"ev",
":=",
"<-",
"g",
".",
"tbEvents",
":",
"if",
"err",
":=",
"g",
".",
"handleEvent",
"(",
"&",
"ev",
")",
";",
"err",
"!=",
"nil"... | // consumeevents handles the remaining events in the events pool. | [
"consumeevents",
"handles",
"the",
"remaining",
"events",
"in",
"the",
"events",
"pool",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L391-L406 | train |
jroimartin/gocui | gui.go | flush | func (g *Gui) flush() error {
termbox.Clear(termbox.Attribute(g.FgColor), termbox.Attribute(g.BgColor))
maxX, maxY := termbox.Size()
// if GUI's size has changed, we need to redraw all views
if maxX != g.maxX || maxY != g.maxY {
for _, v := range g.views {
v.tainted = true
}
}
g.maxX, g.maxY = maxX, maxY
... | go | func (g *Gui) flush() error {
termbox.Clear(termbox.Attribute(g.FgColor), termbox.Attribute(g.BgColor))
maxX, maxY := termbox.Size()
// if GUI's size has changed, we need to redraw all views
if maxX != g.maxX || maxY != g.maxY {
for _, v := range g.views {
v.tainted = true
}
}
g.maxX, g.maxY = maxX, maxY
... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"flush",
"(",
")",
"error",
"{",
"termbox",
".",
"Clear",
"(",
"termbox",
".",
"Attribute",
"(",
"g",
".",
"FgColor",
")",
",",
"termbox",
".",
"Attribute",
"(",
"g",
".",
"BgColor",
")",
")",
"\n\n",
"maxX",
",... | // flush updates the gui, re-drawing frames and buffers. | [
"flush",
"updates",
"the",
"gui",
"re",
"-",
"drawing",
"frames",
"and",
"buffers",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L422-L468 | train |
jroimartin/gocui | gui.go | drawFrameEdges | func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error {
runeH, runeV := '─', '│'
if g.ASCII {
runeH, runeV = '-', '|'
}
for x := v.x0 + 1; x < v.x1 && x < g.maxX; x++ {
if x < 0 {
continue
}
if v.y0 > -1 && v.y0 < g.maxY {
if err := g.SetRune(x, v.y0, runeH, fgColor, bgColor); err !... | go | func (g *Gui) drawFrameEdges(v *View, fgColor, bgColor Attribute) error {
runeH, runeV := '─', '│'
if g.ASCII {
runeH, runeV = '-', '|'
}
for x := v.x0 + 1; x < v.x1 && x < g.maxX; x++ {
if x < 0 {
continue
}
if v.y0 > -1 && v.y0 < g.maxY {
if err := g.SetRune(x, v.y0, runeH, fgColor, bgColor); err !... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"drawFrameEdges",
"(",
"v",
"*",
"View",
",",
"fgColor",
",",
"bgColor",
"Attribute",
")",
"error",
"{",
"runeH",
",",
"runeV",
":=",
"'─', ",
"'",
"'",
"\n",
"if",
"g",
".",
"ASCII",
"{",
"runeH",
",",
"runeV",
... | // drawFrameEdges draws the horizontal and vertical edges of a view. | [
"drawFrameEdges",
"draws",
"the",
"horizontal",
"and",
"vertical",
"edges",
"of",
"a",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L471-L508 | train |
jroimartin/gocui | gui.go | drawFrameCorners | func (g *Gui) drawFrameCorners(v *View, fgColor, bgColor Attribute) error {
runeTL, runeTR, runeBL, runeBR := '┌', '┐', '└', '┘'
if g.ASCII {
runeTL, runeTR, runeBL, runeBR = '+', '+', '+', '+'
}
corners := []struct {
x, y int
ch rune
}{{v.x0, v.y0, runeTL}, {v.x1, v.y0, runeTR}, {v.x0, v.y1, runeBL}, {v.... | go | func (g *Gui) drawFrameCorners(v *View, fgColor, bgColor Attribute) error {
runeTL, runeTR, runeBL, runeBR := '┌', '┐', '└', '┘'
if g.ASCII {
runeTL, runeTR, runeBL, runeBR = '+', '+', '+', '+'
}
corners := []struct {
x, y int
ch rune
}{{v.x0, v.y0, runeTL}, {v.x1, v.y0, runeTR}, {v.x0, v.y1, runeBL}, {v.... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"drawFrameCorners",
"(",
"v",
"*",
"View",
",",
"fgColor",
",",
"bgColor",
"Attribute",
")",
"error",
"{",
"runeTL",
",",
"runeTR",
",",
"runeBL",
",",
"runeBR",
":=",
"'┌', ",
"'",
"', '└",
"'",
" '┘'",
"",
"",
"... | // drawFrameCorners draws the corners of the view. | [
"drawFrameCorners",
"draws",
"the",
"corners",
"of",
"the",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L511-L530 | train |
jroimartin/gocui | gui.go | drawTitle | func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error {
if v.y0 < 0 || v.y0 >= g.maxY {
return nil
}
for i, ch := range v.Title {
x := v.x0 + i + 2
if x < 0 {
continue
} else if x > v.x1-2 || x >= g.maxX {
break
}
if err := g.SetRune(x, v.y0, ch, fgColor, bgColor); err != nil {
ret... | go | func (g *Gui) drawTitle(v *View, fgColor, bgColor Attribute) error {
if v.y0 < 0 || v.y0 >= g.maxY {
return nil
}
for i, ch := range v.Title {
x := v.x0 + i + 2
if x < 0 {
continue
} else if x > v.x1-2 || x >= g.maxX {
break
}
if err := g.SetRune(x, v.y0, ch, fgColor, bgColor); err != nil {
ret... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"drawTitle",
"(",
"v",
"*",
"View",
",",
"fgColor",
",",
"bgColor",
"Attribute",
")",
"error",
"{",
"if",
"v",
".",
"y0",
"<",
"0",
"||",
"v",
".",
"y0",
">=",
"g",
".",
"maxY",
"{",
"return",
"nil",
"\n",
"... | // drawTitle draws the title of the view. | [
"drawTitle",
"draws",
"the",
"title",
"of",
"the",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L533-L550 | train |
jroimartin/gocui | gui.go | draw | func (g *Gui) draw(v *View) error {
if g.Cursor {
if curview := g.currentView; curview != nil {
vMaxX, vMaxY := curview.Size()
if curview.cx < 0 {
curview.cx = 0
} else if curview.cx >= vMaxX {
curview.cx = vMaxX - 1
}
if curview.cy < 0 {
curview.cy = 0
} else if curview.cy >= vMaxY {
... | go | func (g *Gui) draw(v *View) error {
if g.Cursor {
if curview := g.currentView; curview != nil {
vMaxX, vMaxY := curview.Size()
if curview.cx < 0 {
curview.cx = 0
} else if curview.cx >= vMaxX {
curview.cx = vMaxX - 1
}
if curview.cy < 0 {
curview.cy = 0
} else if curview.cy >= vMaxY {
... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"draw",
"(",
"v",
"*",
"View",
")",
"error",
"{",
"if",
"g",
".",
"Cursor",
"{",
"if",
"curview",
":=",
"g",
".",
"currentView",
";",
"curview",
"!=",
"nil",
"{",
"vMaxX",
",",
"vMaxY",
":=",
"curview",
".",
"... | // draw manages the cursor and calls the draw function of a view. | [
"draw",
"manages",
"the",
"cursor",
"and",
"calls",
"the",
"draw",
"function",
"of",
"a",
"view",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L553-L585 | train |
jroimartin/gocui | gui.go | onKey | func (g *Gui) onKey(ev *termbox.Event) error {
switch ev.Type {
case termbox.EventKey:
matched, err := g.execKeybindings(g.currentView, ev)
if err != nil {
return err
}
if matched {
break
}
if g.currentView != nil && g.currentView.Editable && g.currentView.Editor != nil {
g.currentView.Editor.Edi... | go | func (g *Gui) onKey(ev *termbox.Event) error {
switch ev.Type {
case termbox.EventKey:
matched, err := g.execKeybindings(g.currentView, ev)
if err != nil {
return err
}
if matched {
break
}
if g.currentView != nil && g.currentView.Editable && g.currentView.Editor != nil {
g.currentView.Editor.Edi... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"onKey",
"(",
"ev",
"*",
"termbox",
".",
"Event",
")",
"error",
"{",
"switch",
"ev",
".",
"Type",
"{",
"case",
"termbox",
".",
"EventKey",
":",
"matched",
",",
"err",
":=",
"g",
".",
"execKeybindings",
"(",
"g",
... | // onKey manages key-press events. A keybinding handler is called when
// a key-press or mouse event satisfies a configured keybinding. Furthermore,
// currentView's internal buffer is modified if currentView.Editable is true. | [
"onKey",
"manages",
"key",
"-",
"press",
"events",
".",
"A",
"keybinding",
"handler",
"is",
"called",
"when",
"a",
"key",
"-",
"press",
"or",
"mouse",
"event",
"satisfies",
"a",
"configured",
"keybinding",
".",
"Furthermore",
"currentView",
"s",
"internal",
... | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L590-L618 | train |
jroimartin/gocui | gui.go | execKeybindings | func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err error) {
matched = false
for _, kb := range g.keybindings {
if kb.handler == nil {
continue
}
if kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) && kb.matchView(v) {
if err := kb.handler(g, v); err != nil {
return fals... | go | func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err error) {
matched = false
for _, kb := range g.keybindings {
if kb.handler == nil {
continue
}
if kb.matchKeypress(Key(ev.Key), ev.Ch, Modifier(ev.Mod)) && kb.matchView(v) {
if err := kb.handler(g, v); err != nil {
return fals... | [
"func",
"(",
"g",
"*",
"Gui",
")",
"execKeybindings",
"(",
"v",
"*",
"View",
",",
"ev",
"*",
"termbox",
".",
"Event",
")",
"(",
"matched",
"bool",
",",
"err",
"error",
")",
"{",
"matched",
"=",
"false",
"\n",
"for",
"_",
",",
"kb",
":=",
"range",... | // execKeybindings executes the keybinding handlers that match the passed view
// and event. The value of matched is true if there is a match and no errors. | [
"execKeybindings",
"executes",
"the",
"keybinding",
"handlers",
"that",
"match",
"the",
"passed",
"view",
"and",
"event",
".",
"The",
"value",
"of",
"matched",
"is",
"true",
"if",
"there",
"is",
"a",
"match",
"and",
"no",
"errors",
"."
] | c055c87ae801372cd74a0839b972db4f7697ae5f | https://github.com/jroimartin/gocui/blob/c055c87ae801372cd74a0839b972db4f7697ae5f/gui.go#L622-L636 | train |
envoyproxy/protoc-gen-validate | templates/java/register.go | makeInvalidClassnameCharactersUnderscores | func makeInvalidClassnameCharactersUnderscores(name string) string {
var sb strings.Builder
for _, c := range name {
switch {
case c >= '0' && c <= '9':
sb.WriteRune(c)
case c >= 'a' && c <= 'z':
sb.WriteRune(c)
case c >= 'A' && c <= 'Z':
sb.WriteRune(c)
default:
sb.WriteRune('_')
}
}
return... | go | func makeInvalidClassnameCharactersUnderscores(name string) string {
var sb strings.Builder
for _, c := range name {
switch {
case c >= '0' && c <= '9':
sb.WriteRune(c)
case c >= 'a' && c <= 'z':
sb.WriteRune(c)
case c >= 'A' && c <= 'Z':
sb.WriteRune(c)
default:
sb.WriteRune('_')
}
}
return... | [
"func",
"makeInvalidClassnameCharactersUnderscores",
"(",
"name",
"string",
")",
"string",
"{",
"var",
"sb",
"strings",
".",
"Builder",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"name",
"{",
"switch",
"{",
"case",
"c",
">=",
"'0'",
"&&",
"c",
"<=",
"'9'... | // Replace invalid identifier characters with an underscore | [
"Replace",
"invalid",
"identifier",
"characters",
"with",
"an",
"underscore"
] | fcf5978a9d1e0d26f3239a013c54dc65dae6c768 | https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/java/register.go#L193-L208 | train |
envoyproxy/protoc-gen-validate | templates/shared/reflection.go | Has | func Has(msg proto.Message, fld string) bool {
val := extractVal(msg)
return val.IsValid() &&
val.FieldByName(fld).IsValid()
} | go | func Has(msg proto.Message, fld string) bool {
val := extractVal(msg)
return val.IsValid() &&
val.FieldByName(fld).IsValid()
} | [
"func",
"Has",
"(",
"msg",
"proto",
".",
"Message",
",",
"fld",
"string",
")",
"bool",
"{",
"val",
":=",
"extractVal",
"(",
"msg",
")",
"\n",
"return",
"val",
".",
"IsValid",
"(",
")",
"&&",
"val",
".",
"FieldByName",
"(",
"fld",
")",
".",
"IsValid... | // Has returns true if the provided Message has the a field fld. | [
"Has",
"returns",
"true",
"if",
"the",
"provided",
"Message",
"has",
"the",
"a",
"field",
"fld",
"."
] | fcf5978a9d1e0d26f3239a013c54dc65dae6c768 | https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/reflection.go#L24-L28 | train |
envoyproxy/protoc-gen-validate | templates/shared/disabled.go | Disabled | func Disabled(msg pgs.Message) (disabled bool, err error) {
_, err = msg.Extension(validate.E_Disabled, &disabled)
return
} | go | func Disabled(msg pgs.Message) (disabled bool, err error) {
_, err = msg.Extension(validate.E_Disabled, &disabled)
return
} | [
"func",
"Disabled",
"(",
"msg",
"pgs",
".",
"Message",
")",
"(",
"disabled",
"bool",
",",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"msg",
".",
"Extension",
"(",
"validate",
".",
"E_Disabled",
",",
"&",
"disabled",
")",
"\n",
"return",
"\n",
... | // Disabled returns true if validations are disabled for msg | [
"Disabled",
"returns",
"true",
"if",
"validations",
"are",
"disabled",
"for",
"msg"
] | fcf5978a9d1e0d26f3239a013c54dc65dae6c768 | https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/disabled.go#L9-L12 | train |
envoyproxy/protoc-gen-validate | templates/shared/disabled.go | RequiredOneOf | func RequiredOneOf(oo pgs.OneOf) (required bool, err error) {
_, err = oo.Extension(validate.E_Required, &required)
return
} | go | func RequiredOneOf(oo pgs.OneOf) (required bool, err error) {
_, err = oo.Extension(validate.E_Required, &required)
return
} | [
"func",
"RequiredOneOf",
"(",
"oo",
"pgs",
".",
"OneOf",
")",
"(",
"required",
"bool",
",",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"oo",
".",
"Extension",
"(",
"validate",
".",
"E_Required",
",",
"&",
"required",
")",
"\n",
"return",
"\n",
... | // RequiredOneOf returns true if the oneof field requires a field to be set | [
"RequiredOneOf",
"returns",
"true",
"if",
"the",
"oneof",
"field",
"requires",
"a",
"field",
"to",
"be",
"set"
] | fcf5978a9d1e0d26f3239a013c54dc65dae6c768 | https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/disabled.go#L15-L18 | train |
envoyproxy/protoc-gen-validate | templates/shared/well_known.go | Needs | func Needs(m pgs.Message, wk WellKnown) bool {
for _, f := range m.Fields() {
var rules validate.FieldRules
if _, err := f.Extension(validate.E_Rules, &rules); err != nil {
continue
}
switch {
case f.Type().IsRepeated() && f.Type().Element().ProtoType() == pgs.StringT:
if strRulesNeeds(rules.GetRepea... | go | func Needs(m pgs.Message, wk WellKnown) bool {
for _, f := range m.Fields() {
var rules validate.FieldRules
if _, err := f.Extension(validate.E_Rules, &rules); err != nil {
continue
}
switch {
case f.Type().IsRepeated() && f.Type().Element().ProtoType() == pgs.StringT:
if strRulesNeeds(rules.GetRepea... | [
"func",
"Needs",
"(",
"m",
"pgs",
".",
"Message",
",",
"wk",
"WellKnown",
")",
"bool",
"{",
"for",
"_",
",",
"f",
":=",
"range",
"m",
".",
"Fields",
"(",
")",
"{",
"var",
"rules",
"validate",
".",
"FieldRules",
"\n",
"if",
"_",
",",
"err",
":=",
... | // Needs returns true if a well-known string validator is needed for this
// message. | [
"Needs",
"returns",
"true",
"if",
"a",
"well",
"-",
"known",
"string",
"validator",
"is",
"needed",
"for",
"this",
"message",
"."
] | fcf5978a9d1e0d26f3239a013c54dc65dae6c768 | https://github.com/envoyproxy/protoc-gen-validate/blob/fcf5978a9d1e0d26f3239a013c54dc65dae6c768/templates/shared/well_known.go#L17-L47 | train |
vishvananda/netlink | addr_linux.go | AddrSubscribe | func AddrSubscribe(ch chan<- AddrUpdate, done <-chan struct{}) error {
return addrSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | go | func AddrSubscribe(ch chan<- AddrUpdate, done <-chan struct{}) error {
return addrSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | [
"func",
"AddrSubscribe",
"(",
"ch",
"chan",
"<-",
"AddrUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"return",
"addrSubscribeAt",
"(",
"netns",
".",
"None",
"(",
")",
",",
"netns",
".",
"None",
"(",
")",
",",
"ch",
",",
... | // AddrSubscribe takes a chan down which notifications will be sent
// when addresses change. Close the 'done' chan to stop subscription. | [
"AddrSubscribe",
"takes",
"a",
"chan",
"down",
"which",
"notifications",
"will",
"be",
"sent",
"when",
"addresses",
"change",
".",
"Close",
"the",
"done",
"chan",
"to",
"stop",
"subscription",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/addr_linux.go#L272-L274 | train |
vishvananda/netlink | addr_linux.go | AddrSubscribeWithOptions | func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, options AddrSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return addrSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | go | func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, options AddrSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return addrSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | [
"func",
"AddrSubscribeWithOptions",
"(",
"ch",
"chan",
"<-",
"AddrUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
",",
"options",
"AddrSubscribeOptions",
")",
"error",
"{",
"if",
"options",
".",
"Namespace",
"==",
"nil",
"{",
"none",
":=",
"netns",
... | // AddrSubscribeWithOptions work like AddrSubscribe but enable to
// provide additional options to modify the behavior. Currently, the
// namespace can be provided as well as an error callback. | [
"AddrSubscribeWithOptions",
"work",
"like",
"AddrSubscribe",
"but",
"enable",
"to",
"provide",
"additional",
"options",
"to",
"modify",
"the",
"behavior",
".",
"Currently",
"the",
"namespace",
"can",
"be",
"provided",
"as",
"well",
"as",
"an",
"error",
"callback",... | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/addr_linux.go#L293-L299 | train |
vishvananda/netlink | nl/nl_linux.go | GetIPFamily | func GetIPFamily(ip net.IP) int {
if len(ip) <= net.IPv4len {
return FAMILY_V4
}
if ip.To4() != nil {
return FAMILY_V4
}
return FAMILY_V6
} | go | func GetIPFamily(ip net.IP) int {
if len(ip) <= net.IPv4len {
return FAMILY_V4
}
if ip.To4() != nil {
return FAMILY_V4
}
return FAMILY_V6
} | [
"func",
"GetIPFamily",
"(",
"ip",
"net",
".",
"IP",
")",
"int",
"{",
"if",
"len",
"(",
"ip",
")",
"<=",
"net",
".",
"IPv4len",
"{",
"return",
"FAMILY_V4",
"\n",
"}",
"\n",
"if",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"FAMILY_V4",... | // GetIPFamily returns the family type of a net.IP. | [
"GetIPFamily",
"returns",
"the",
"family",
"type",
"of",
"a",
"net",
".",
"IP",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L37-L45 | train |
vishvananda/netlink | nl/nl_linux.go | NewIfInfomsg | func NewIfInfomsg(family int) *IfInfomsg {
return &IfInfomsg{
IfInfomsg: unix.IfInfomsg{
Family: uint8(family),
},
}
} | go | func NewIfInfomsg(family int) *IfInfomsg {
return &IfInfomsg{
IfInfomsg: unix.IfInfomsg{
Family: uint8(family),
},
}
} | [
"func",
"NewIfInfomsg",
"(",
"family",
"int",
")",
"*",
"IfInfomsg",
"{",
"return",
"&",
"IfInfomsg",
"{",
"IfInfomsg",
":",
"unix",
".",
"IfInfomsg",
"{",
"Family",
":",
"uint8",
"(",
"family",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // Create an IfInfomsg with family specified | [
"Create",
"an",
"IfInfomsg",
"with",
"family",
"specified"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L89-L95 | train |
vishvananda/netlink | nl/nl_linux.go | NewRtAttr | func NewRtAttr(attrType int, data []byte) *RtAttr {
return &RtAttr{
RtAttr: unix.RtAttr{
Type: uint16(attrType),
},
children: []NetlinkRequestData{},
Data: data,
}
} | go | func NewRtAttr(attrType int, data []byte) *RtAttr {
return &RtAttr{
RtAttr: unix.RtAttr{
Type: uint16(attrType),
},
children: []NetlinkRequestData{},
Data: data,
}
} | [
"func",
"NewRtAttr",
"(",
"attrType",
"int",
",",
"data",
"[",
"]",
"byte",
")",
"*",
"RtAttr",
"{",
"return",
"&",
"RtAttr",
"{",
"RtAttr",
":",
"unix",
".",
"RtAttr",
"{",
"Type",
":",
"uint16",
"(",
"attrType",
")",
",",
"}",
",",
"children",
":... | // Create a new Extended RtAttr object | [
"Create",
"a",
"new",
"Extended",
"RtAttr",
"object"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L268-L276 | train |
vishvananda/netlink | nl/nl_linux.go | AddRtAttr | func (a *RtAttr) AddRtAttr(attrType int, data []byte) *RtAttr {
attr := NewRtAttr(attrType, data)
a.children = append(a.children, attr)
return attr
} | go | func (a *RtAttr) AddRtAttr(attrType int, data []byte) *RtAttr {
attr := NewRtAttr(attrType, data)
a.children = append(a.children, attr)
return attr
} | [
"func",
"(",
"a",
"*",
"RtAttr",
")",
"AddRtAttr",
"(",
"attrType",
"int",
",",
"data",
"[",
"]",
"byte",
")",
"*",
"RtAttr",
"{",
"attr",
":=",
"NewRtAttr",
"(",
"attrType",
",",
"data",
")",
"\n",
"a",
".",
"children",
"=",
"append",
"(",
"a",
... | // AddRtAttr adds an RtAttr as a child and returns the new attribute | [
"AddRtAttr",
"adds",
"an",
"RtAttr",
"as",
"a",
"child",
"and",
"returns",
"the",
"new",
"attribute"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L286-L290 | train |
vishvananda/netlink | nl/nl_linux.go | AddChild | func (a *RtAttr) AddChild(attr NetlinkRequestData) {
a.children = append(a.children, attr)
} | go | func (a *RtAttr) AddChild(attr NetlinkRequestData) {
a.children = append(a.children, attr)
} | [
"func",
"(",
"a",
"*",
"RtAttr",
")",
"AddChild",
"(",
"attr",
"NetlinkRequestData",
")",
"{",
"a",
".",
"children",
"=",
"append",
"(",
"a",
".",
"children",
",",
"attr",
")",
"\n",
"}"
] | // AddChild adds an existing NetlinkRequestData as a child. | [
"AddChild",
"adds",
"an",
"existing",
"NetlinkRequestData",
"as",
"a",
"child",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L293-L295 | train |
vishvananda/netlink | nl/nl_linux.go | Serialize | func (req *NetlinkRequest) Serialize() []byte {
length := unix.SizeofNlMsghdr
dataBytes := make([][]byte, len(req.Data))
for i, data := range req.Data {
dataBytes[i] = data.Serialize()
length = length + len(dataBytes[i])
}
length += len(req.RawData)
req.Len = uint32(length)
b := make([]byte, length)
hdr :=... | go | func (req *NetlinkRequest) Serialize() []byte {
length := unix.SizeofNlMsghdr
dataBytes := make([][]byte, len(req.Data))
for i, data := range req.Data {
dataBytes[i] = data.Serialize()
length = length + len(dataBytes[i])
}
length += len(req.RawData)
req.Len = uint32(length)
b := make([]byte, length)
hdr :=... | [
"func",
"(",
"req",
"*",
"NetlinkRequest",
")",
"Serialize",
"(",
")",
"[",
"]",
"byte",
"{",
"length",
":=",
"unix",
".",
"SizeofNlMsghdr",
"\n",
"dataBytes",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"len",
"(",
"req",
".",
"Data",
")",... | // Serialize the Netlink Request into a byte array | [
"Serialize",
"the",
"Netlink",
"Request",
"into",
"a",
"byte",
"array"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L346-L371 | train |
vishvananda/netlink | nl/nl_linux.go | AddRawData | func (req *NetlinkRequest) AddRawData(data []byte) {
req.RawData = append(req.RawData, data...)
} | go | func (req *NetlinkRequest) AddRawData(data []byte) {
req.RawData = append(req.RawData, data...)
} | [
"func",
"(",
"req",
"*",
"NetlinkRequest",
")",
"AddRawData",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"req",
".",
"RawData",
"=",
"append",
"(",
"req",
".",
"RawData",
",",
"data",
"...",
")",
"\n",
"}"
] | // AddRawData adds raw bytes to the end of the NetlinkRequest object during serialization | [
"AddRawData",
"adds",
"raw",
"bytes",
"to",
"the",
"end",
"of",
"the",
"NetlinkRequest",
"object",
"during",
"serialization"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L378-L380 | train |
vishvananda/netlink | nl/nl_linux.go | Execute | func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error) {
var (
s *NetlinkSocket
err error
)
if req.Sockets != nil {
if sh, ok := req.Sockets[sockType]; ok {
s = sh.Socket
req.Seq = atomic.AddUint32(&sh.Seq, 1)
}
}
sharedSocket := s != nil
if s == nil {
s, err = getN... | go | func (req *NetlinkRequest) Execute(sockType int, resType uint16) ([][]byte, error) {
var (
s *NetlinkSocket
err error
)
if req.Sockets != nil {
if sh, ok := req.Sockets[sockType]; ok {
s = sh.Socket
req.Seq = atomic.AddUint32(&sh.Seq, 1)
}
}
sharedSocket := s != nil
if s == nil {
s, err = getN... | [
"func",
"(",
"req",
"*",
"NetlinkRequest",
")",
"Execute",
"(",
"sockType",
"int",
",",
"resType",
"uint16",
")",
"(",
"[",
"]",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"(",
"s",
"*",
"NetlinkSocket",
"\n",
"err",
"error",
"\n",
")",
"\n\n... | // Execute the request against a the given sockType.
// Returns a list of netlink messages in serialized format, optionally filtered
// by resType. | [
"Execute",
"the",
"request",
"against",
"a",
"the",
"given",
"sockType",
".",
"Returns",
"a",
"list",
"of",
"netlink",
"messages",
"in",
"serialized",
"format",
"optionally",
"filtered",
"by",
"resType",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L385-L458 | train |
vishvananda/netlink | nl/nl_linux.go | NewNetlinkRequest | func NewNetlinkRequest(proto, flags int) *NetlinkRequest {
return &NetlinkRequest{
NlMsghdr: unix.NlMsghdr{
Len: uint32(unix.SizeofNlMsghdr),
Type: uint16(proto),
Flags: unix.NLM_F_REQUEST | uint16(flags),
Seq: atomic.AddUint32(&nextSeqNr, 1),
},
}
} | go | func NewNetlinkRequest(proto, flags int) *NetlinkRequest {
return &NetlinkRequest{
NlMsghdr: unix.NlMsghdr{
Len: uint32(unix.SizeofNlMsghdr),
Type: uint16(proto),
Flags: unix.NLM_F_REQUEST | uint16(flags),
Seq: atomic.AddUint32(&nextSeqNr, 1),
},
}
} | [
"func",
"NewNetlinkRequest",
"(",
"proto",
",",
"flags",
"int",
")",
"*",
"NetlinkRequest",
"{",
"return",
"&",
"NetlinkRequest",
"{",
"NlMsghdr",
":",
"unix",
".",
"NlMsghdr",
"{",
"Len",
":",
"uint32",
"(",
"unix",
".",
"SizeofNlMsghdr",
")",
",",
"Type"... | // Create a new netlink request from proto and flags
// Note the Len value will be inaccurate once data is added until
// the message is serialized | [
"Create",
"a",
"new",
"netlink",
"request",
"from",
"proto",
"and",
"flags",
"Note",
"the",
"Len",
"value",
"will",
"be",
"inaccurate",
"once",
"data",
"is",
"added",
"until",
"the",
"message",
"is",
"serialized"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L463-L472 | train |
vishvananda/netlink | nl/nl_linux.go | GetNetlinkSocketAt | func GetNetlinkSocketAt(newNs, curNs netns.NsHandle, protocol int) (*NetlinkSocket, error) {
c, err := executeInNetns(newNs, curNs)
if err != nil {
return nil, err
}
defer c()
return getNetlinkSocket(protocol)
} | go | func GetNetlinkSocketAt(newNs, curNs netns.NsHandle, protocol int) (*NetlinkSocket, error) {
c, err := executeInNetns(newNs, curNs)
if err != nil {
return nil, err
}
defer c()
return getNetlinkSocket(protocol)
} | [
"func",
"GetNetlinkSocketAt",
"(",
"newNs",
",",
"curNs",
"netns",
".",
"NsHandle",
",",
"protocol",
"int",
")",
"(",
"*",
"NetlinkSocket",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"executeInNetns",
"(",
"newNs",
",",
"curNs",
")",
"\n",
"if",
"e... | // GetNetlinkSocketAt opens a netlink socket in the network namespace newNs
// and positions the thread back into the network namespace specified by curNs,
// when done. If curNs is close, the function derives the current namespace and
// moves back into it when done. If newNs is close, the socket will be opened
// in ... | [
"GetNetlinkSocketAt",
"opens",
"a",
"netlink",
"socket",
"in",
"the",
"network",
"namespace",
"newNs",
"and",
"positions",
"the",
"thread",
"back",
"into",
"the",
"network",
"namespace",
"specified",
"by",
"curNs",
"when",
"done",
".",
"If",
"curNs",
"is",
"cl... | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L502-L509 | train |
vishvananda/netlink | nl/nl_linux.go | SetSendTimeout | func (s *NetlinkSocket) SetSendTimeout(timeout *unix.Timeval) error {
// Set a send timeout of SOCKET_SEND_TIMEOUT, this will allow the Send to periodically unblock and avoid that a routine
// remains stuck on a send on a closed fd
return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_SNDTIMEO, timeout)
... | go | func (s *NetlinkSocket) SetSendTimeout(timeout *unix.Timeval) error {
// Set a send timeout of SOCKET_SEND_TIMEOUT, this will allow the Send to periodically unblock and avoid that a routine
// remains stuck on a send on a closed fd
return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_SNDTIMEO, timeout)
... | [
"func",
"(",
"s",
"*",
"NetlinkSocket",
")",
"SetSendTimeout",
"(",
"timeout",
"*",
"unix",
".",
"Timeval",
")",
"error",
"{",
"// Set a send timeout of SOCKET_SEND_TIMEOUT, this will allow the Send to periodically unblock and avoid that a routine",
"// remains stuck on a send on a... | // SetSendTimeout allows to set a send timeout on the socket | [
"SetSendTimeout",
"allows",
"to",
"set",
"a",
"send",
"timeout",
"on",
"the",
"socket"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L639-L643 | train |
vishvananda/netlink | nl/nl_linux.go | SetReceiveTimeout | func (s *NetlinkSocket) SetReceiveTimeout(timeout *unix.Timeval) error {
// Set a read timeout of SOCKET_READ_TIMEOUT, this will allow the Read to periodically unblock and avoid that a routine
// remains stuck on a recvmsg on a closed fd
return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_RCVTIMEO, tim... | go | func (s *NetlinkSocket) SetReceiveTimeout(timeout *unix.Timeval) error {
// Set a read timeout of SOCKET_READ_TIMEOUT, this will allow the Read to periodically unblock and avoid that a routine
// remains stuck on a recvmsg on a closed fd
return unix.SetsockoptTimeval(int(s.fd), unix.SOL_SOCKET, unix.SO_RCVTIMEO, tim... | [
"func",
"(",
"s",
"*",
"NetlinkSocket",
")",
"SetReceiveTimeout",
"(",
"timeout",
"*",
"unix",
".",
"Timeval",
")",
"error",
"{",
"// Set a read timeout of SOCKET_READ_TIMEOUT, this will allow the Read to periodically unblock and avoid that a routine",
"// remains stuck on a recvms... | // SetReceiveTimeout allows to set a receive timeout on the socket | [
"SetReceiveTimeout",
"allows",
"to",
"set",
"a",
"receive",
"timeout",
"on",
"the",
"socket"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/nl/nl_linux.go#L646-L650 | train |
vishvananda/netlink | neigh_linux.go | NeighListExecute | func (h *Handle) NeighListExecute(msg Ndmsg) ([]Neigh, error) {
req := h.newNetlinkRequest(unix.RTM_GETNEIGH, unix.NLM_F_DUMP)
req.AddData(&msg)
msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNEIGH)
if err != nil {
return nil, err
}
var res []Neigh
for _, m := range msgs {
ndm := deserializeNdmsg... | go | func (h *Handle) NeighListExecute(msg Ndmsg) ([]Neigh, error) {
req := h.newNetlinkRequest(unix.RTM_GETNEIGH, unix.NLM_F_DUMP)
req.AddData(&msg)
msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWNEIGH)
if err != nil {
return nil, err
}
var res []Neigh
for _, m := range msgs {
ndm := deserializeNdmsg... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"NeighListExecute",
"(",
"msg",
"Ndmsg",
")",
"(",
"[",
"]",
"Neigh",
",",
"error",
")",
"{",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_GETNEIGH",
",",
"unix",
".",
"NLM_F_DUMP",
")",
"\n... | // NeighListExecute returns a list of neighbour entries filtered by link, ip family, flag and state. | [
"NeighListExecute",
"returns",
"a",
"list",
"of",
"neighbour",
"entries",
"filtered",
"by",
"link",
"ip",
"family",
"flag",
"and",
"state",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L221-L247 | train |
vishvananda/netlink | neigh_linux.go | NeighSubscribe | func NeighSubscribe(ch chan<- NeighUpdate, done <-chan struct{}) error {
return neighSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | go | func NeighSubscribe(ch chan<- NeighUpdate, done <-chan struct{}) error {
return neighSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | [
"func",
"NeighSubscribe",
"(",
"ch",
"chan",
"<-",
"NeighUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"return",
"neighSubscribeAt",
"(",
"netns",
".",
"None",
"(",
")",
",",
"netns",
".",
"None",
"(",
")",
",",
"ch",
","... | // NeighSubscribe takes a chan down which notifications will be sent
// when neighbors are added or deleted. Close the 'done' chan to stop subscription. | [
"NeighSubscribe",
"takes",
"a",
"chan",
"down",
"which",
"notifications",
"will",
"be",
"sent",
"when",
"neighbors",
"are",
"added",
"or",
"deleted",
".",
"Close",
"the",
"done",
"chan",
"to",
"stop",
"subscription",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L299-L301 | train |
vishvananda/netlink | neigh_linux.go | NeighSubscribeWithOptions | func NeighSubscribeWithOptions(ch chan<- NeighUpdate, done <-chan struct{}, options NeighSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return neighSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | go | func NeighSubscribeWithOptions(ch chan<- NeighUpdate, done <-chan struct{}, options NeighSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return neighSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | [
"func",
"NeighSubscribeWithOptions",
"(",
"ch",
"chan",
"<-",
"NeighUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
",",
"options",
"NeighSubscribeOptions",
")",
"error",
"{",
"if",
"options",
".",
"Namespace",
"==",
"nil",
"{",
"none",
":=",
"netns"... | // NeighSubscribeWithOptions work like NeighSubscribe but enable to
// provide additional options to modify the behavior. Currently, the
// namespace can be provided as well as an error callback. | [
"NeighSubscribeWithOptions",
"work",
"like",
"NeighSubscribe",
"but",
"enable",
"to",
"provide",
"additional",
"options",
"to",
"modify",
"the",
"behavior",
".",
"Currently",
"the",
"namespace",
"can",
"be",
"provided",
"as",
"well",
"as",
"an",
"error",
"callback... | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/neigh_linux.go#L320-L326 | train |
vishvananda/netlink | conntrack_linux.go | AddIP | func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error {
if f.ipFilter == nil {
f.ipFilter = make(map[ConntrackFilterType]net.IP)
}
if _, ok := f.ipFilter[tp]; ok {
return errors.New("Filter attribute already present")
}
f.ipFilter[tp] = ip
return nil
} | go | func (f *ConntrackFilter) AddIP(tp ConntrackFilterType, ip net.IP) error {
if f.ipFilter == nil {
f.ipFilter = make(map[ConntrackFilterType]net.IP)
}
if _, ok := f.ipFilter[tp]; ok {
return errors.New("Filter attribute already present")
}
f.ipFilter[tp] = ip
return nil
} | [
"func",
"(",
"f",
"*",
"ConntrackFilter",
")",
"AddIP",
"(",
"tp",
"ConntrackFilterType",
",",
"ip",
"net",
".",
"IP",
")",
"error",
"{",
"if",
"f",
".",
"ipFilter",
"==",
"nil",
"{",
"f",
".",
"ipFilter",
"=",
"make",
"(",
"map",
"[",
"ConntrackFilt... | // AddIP adds an IP to the conntrack filter | [
"AddIP",
"adds",
"an",
"IP",
"to",
"the",
"conntrack",
"filter"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L350-L359 | train |
vishvananda/netlink | conntrack_linux.go | MatchConntrackFlow | func (f *ConntrackFilter) MatchConntrackFlow(flow *ConntrackFlow) bool {
if len(f.ipFilter) == 0 {
// empty filter always not match
return false
}
match := true
// -orig-src ip Source address from original direction
if elem, found := f.ipFilter[ConntrackOrigSrcIP]; found {
match = match && elem.Equal(flow... | go | func (f *ConntrackFilter) MatchConntrackFlow(flow *ConntrackFlow) bool {
if len(f.ipFilter) == 0 {
// empty filter always not match
return false
}
match := true
// -orig-src ip Source address from original direction
if elem, found := f.ipFilter[ConntrackOrigSrcIP]; found {
match = match && elem.Equal(flow... | [
"func",
"(",
"f",
"*",
"ConntrackFilter",
")",
"MatchConntrackFlow",
"(",
"flow",
"*",
"ConntrackFlow",
")",
"bool",
"{",
"if",
"len",
"(",
"f",
".",
"ipFilter",
")",
"==",
"0",
"{",
"// empty filter always not match",
"return",
"false",
"\n",
"}",
"\n\n",
... | // MatchConntrackFlow applies the filter to the flow and returns true if the flow matches the filter
// false otherwise | [
"MatchConntrackFlow",
"applies",
"the",
"filter",
"to",
"the",
"flow",
"and",
"returns",
"true",
"if",
"the",
"flow",
"matches",
"the",
"filter",
"false",
"otherwise"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/conntrack_linux.go#L363-L396 | train |
vishvananda/netlink | protinfo.go | String | func (prot *Protinfo) String() string {
if prot == nil {
return "<nil>"
}
var boolStrings []string
if prot.Hairpin {
boolStrings = append(boolStrings, "Hairpin")
}
if prot.Guard {
boolStrings = append(boolStrings, "Guard")
}
if prot.FastLeave {
boolStrings = append(boolStrings, "FastLeave")
}
if prot... | go | func (prot *Protinfo) String() string {
if prot == nil {
return "<nil>"
}
var boolStrings []string
if prot.Hairpin {
boolStrings = append(boolStrings, "Hairpin")
}
if prot.Guard {
boolStrings = append(boolStrings, "Guard")
}
if prot.FastLeave {
boolStrings = append(boolStrings, "FastLeave")
}
if prot... | [
"func",
"(",
"prot",
"*",
"Protinfo",
")",
"String",
"(",
")",
"string",
"{",
"if",
"prot",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"var",
"boolStrings",
"[",
"]",
"string",
"\n",
"if",
"prot",
".",
"Hairpin",
"{",
"boolStrings",
... | // String returns a list of enabled flags | [
"String",
"returns",
"a",
"list",
"of",
"enabled",
"flags"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/protinfo.go#L20-L51 | train |
vishvananda/netlink | class.go | Attrs | func (c *ServiceCurve) Attrs() (uint32, uint32, uint32) {
return c.m1, c.d, c.m2
} | go | func (c *ServiceCurve) Attrs() (uint32, uint32, uint32) {
return c.m1, c.d, c.m2
} | [
"func",
"(",
"c",
"*",
"ServiceCurve",
")",
"Attrs",
"(",
")",
"(",
"uint32",
",",
"uint32",
",",
"uint32",
")",
"{",
"return",
"c",
".",
"m1",
",",
"c",
".",
"d",
",",
"c",
".",
"m2",
"\n",
"}"
] | // Attrs return the parameters of the service curve | [
"Attrs",
"return",
"the",
"parameters",
"of",
"the",
"service",
"curve"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L143-L145 | train |
vishvananda/netlink | class.go | SetRsc | func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32) {
hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | go | func (hfsc *HfscClass) SetRsc(m1 uint32, d uint32, m2 uint32) {
hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | [
"func",
"(",
"hfsc",
"*",
"HfscClass",
")",
"SetRsc",
"(",
"m1",
"uint32",
",",
"d",
"uint32",
",",
"m2",
"uint32",
")",
"{",
"hfsc",
".",
"Rsc",
"=",
"ServiceCurve",
"{",
"m1",
":",
"m1",
"/",
"8",
",",
"d",
":",
"d",
",",
"m2",
":",
"m2",
"... | // SetRsc sets the Rsc curve | [
"SetRsc",
"sets",
"the",
"Rsc",
"curve"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L166-L168 | train |
vishvananda/netlink | class.go | SetSC | func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32) {
hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | go | func (hfsc *HfscClass) SetSC(m1 uint32, d uint32, m2 uint32) {
hfsc.Rsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | [
"func",
"(",
"hfsc",
"*",
"HfscClass",
")",
"SetSC",
"(",
"m1",
"uint32",
",",
"d",
"uint32",
",",
"m2",
"uint32",
")",
"{",
"hfsc",
".",
"Rsc",
"=",
"ServiceCurve",
"{",
"m1",
":",
"m1",
"/",
"8",
",",
"d",
":",
"d",
",",
"m2",
":",
"m2",
"/... | // SetSC implements the SC from the tc CLI | [
"SetSC",
"implements",
"the",
"SC",
"from",
"the",
"tc",
"CLI"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L171-L174 | train |
vishvananda/netlink | class.go | SetUL | func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32) {
hfsc.Usc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | go | func (hfsc *HfscClass) SetUL(m1 uint32, d uint32, m2 uint32) {
hfsc.Usc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | [
"func",
"(",
"hfsc",
"*",
"HfscClass",
")",
"SetUL",
"(",
"m1",
"uint32",
",",
"d",
"uint32",
",",
"m2",
"uint32",
")",
"{",
"hfsc",
".",
"Usc",
"=",
"ServiceCurve",
"{",
"m1",
":",
"m1",
"/",
"8",
",",
"d",
":",
"d",
",",
"m2",
":",
"m2",
"/... | // SetUL implements the UL from the tc CLI | [
"SetUL",
"implements",
"the",
"UL",
"from",
"the",
"tc",
"CLI"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L177-L179 | train |
vishvananda/netlink | class.go | SetLS | func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32) {
hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | go | func (hfsc *HfscClass) SetLS(m1 uint32, d uint32, m2 uint32) {
hfsc.Fsc = ServiceCurve{m1: m1 / 8, d: d, m2: m2 / 8}
} | [
"func",
"(",
"hfsc",
"*",
"HfscClass",
")",
"SetLS",
"(",
"m1",
"uint32",
",",
"d",
"uint32",
",",
"m2",
"uint32",
")",
"{",
"hfsc",
".",
"Fsc",
"=",
"ServiceCurve",
"{",
"m1",
":",
"m1",
"/",
"8",
",",
"d",
":",
"d",
",",
"m2",
":",
"m2",
"/... | // SetLS implements the LS from the tc CLI | [
"SetLS",
"implements",
"the",
"LS",
"from",
"the",
"tc",
"CLI"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L182-L184 | train |
vishvananda/netlink | class.go | NewHfscClass | func NewHfscClass(attrs ClassAttrs) *HfscClass {
return &HfscClass{
ClassAttrs: attrs,
Rsc: ServiceCurve{},
Fsc: ServiceCurve{},
Usc: ServiceCurve{},
}
} | go | func NewHfscClass(attrs ClassAttrs) *HfscClass {
return &HfscClass{
ClassAttrs: attrs,
Rsc: ServiceCurve{},
Fsc: ServiceCurve{},
Usc: ServiceCurve{},
}
} | [
"func",
"NewHfscClass",
"(",
"attrs",
"ClassAttrs",
")",
"*",
"HfscClass",
"{",
"return",
"&",
"HfscClass",
"{",
"ClassAttrs",
":",
"attrs",
",",
"Rsc",
":",
"ServiceCurve",
"{",
"}",
",",
"Fsc",
":",
"ServiceCurve",
"{",
"}",
",",
"Usc",
":",
"ServiceCu... | // NewHfscClass returns a new HFSC struct with the set parameters | [
"NewHfscClass",
"returns",
"a",
"new",
"HFSC",
"struct",
"with",
"the",
"set",
"parameters"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/class.go#L187-L194 | train |
vishvananda/netlink | link.go | StringToBondMode | func StringToBondMode(s string) BondMode {
mode, ok := StringToBondModeMap[s]
if !ok {
return BOND_MODE_UNKNOWN
}
return mode
} | go | func StringToBondMode(s string) BondMode {
mode, ok := StringToBondModeMap[s]
if !ok {
return BOND_MODE_UNKNOWN
}
return mode
} | [
"func",
"StringToBondMode",
"(",
"s",
"string",
")",
"BondMode",
"{",
"mode",
",",
"ok",
":=",
"StringToBondModeMap",
"[",
"s",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BOND_MODE_UNKNOWN",
"\n",
"}",
"\n",
"return",
"mode",
"\n",
"}"
] | // StringToBondMode returns bond mode, or uknonw is the s is invalid. | [
"StringToBondMode",
"returns",
"bond",
"mode",
"or",
"uknonw",
"is",
"the",
"s",
"is",
"invalid",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L420-L426 | train |
vishvananda/netlink | link.go | StringToBondXmitHashPolicy | func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy {
lacp, ok := StringToBondXmitHashPolicyMap[s]
if !ok {
return BOND_XMIT_HASH_POLICY_UNKNOWN
}
return lacp
} | go | func StringToBondXmitHashPolicy(s string) BondXmitHashPolicy {
lacp, ok := StringToBondXmitHashPolicyMap[s]
if !ok {
return BOND_XMIT_HASH_POLICY_UNKNOWN
}
return lacp
} | [
"func",
"StringToBondXmitHashPolicy",
"(",
"s",
"string",
")",
"BondXmitHashPolicy",
"{",
"lacp",
",",
"ok",
":=",
"StringToBondXmitHashPolicyMap",
"[",
"s",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BOND_XMIT_HASH_POLICY_UNKNOWN",
"\n",
"}",
"\n",
"return",
"... | // StringToBondXmitHashPolicy returns bond lacp arte, or uknonw is the s is invalid. | [
"StringToBondXmitHashPolicy",
"returns",
"bond",
"lacp",
"arte",
"or",
"uknonw",
"is",
"the",
"s",
"is",
"invalid",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L511-L517 | train |
vishvananda/netlink | link.go | StringToBondLacpRate | func StringToBondLacpRate(s string) BondLacpRate {
lacp, ok := StringToBondLacpRateMap[s]
if !ok {
return BOND_LACP_RATE_UNKNOWN
}
return lacp
} | go | func StringToBondLacpRate(s string) BondLacpRate {
lacp, ok := StringToBondLacpRateMap[s]
if !ok {
return BOND_LACP_RATE_UNKNOWN
}
return lacp
} | [
"func",
"StringToBondLacpRate",
"(",
"s",
"string",
")",
"BondLacpRate",
"{",
"lacp",
",",
"ok",
":=",
"StringToBondLacpRateMap",
"[",
"s",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"BOND_LACP_RATE_UNKNOWN",
"\n",
"}",
"\n",
"return",
"lacp",
"\n",
"}"
] | // StringToBondLacpRate returns bond lacp arte, or uknonw is the s is invalid. | [
"StringToBondLacpRate",
"returns",
"bond",
"lacp",
"arte",
"or",
"uknonw",
"is",
"the",
"s",
"is",
"invalid",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link.go#L556-L562 | train |
vishvananda/netlink | devlink_linux.go | DevLinkGetDeviceList | func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error) {
f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME)
if err != nil {
return nil, err
}
msg := &nl.Genlmsg{
Command: nl.DEVLINK_CMD_GET,
Version: nl.GENL_DEVLINK_VERSION,
}
req := h.newNetlinkRequest(int(f.ID),
unix.NLM_F_REQUEST|unix.NLM_F_ACK... | go | func (h *Handle) DevLinkGetDeviceList() ([]*DevlinkDevice, error) {
f, err := h.GenlFamilyGet(nl.GENL_DEVLINK_NAME)
if err != nil {
return nil, err
}
msg := &nl.Genlmsg{
Command: nl.DEVLINK_CMD_GET,
Version: nl.GENL_DEVLINK_VERSION,
}
req := h.newNetlinkRequest(int(f.ID),
unix.NLM_F_REQUEST|unix.NLM_F_ACK... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"DevLinkGetDeviceList",
"(",
")",
"(",
"[",
"]",
"*",
"DevlinkDevice",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"h",
".",
"GenlFamilyGet",
"(",
"nl",
".",
"GENL_DEVLINK_NAME",
")",
"\n",
"if",
"err",
"!=",
... | // DevLinkGetDeviceList provides a pointer to devlink devices and nil error,
// otherwise returns an error code. | [
"DevLinkGetDeviceList",
"provides",
"a",
"pointer",
"to",
"devlink",
"devices",
"and",
"nil",
"error",
"otherwise",
"returns",
"an",
"error",
"code",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/devlink_linux.go#L148-L172 | train |
vishvananda/netlink | rdma_link_linux.go | RdmaLinkByName | func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error) {
proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_GET)
req := h.newNetlinkRequest(proto, unix.NLM_F_ACK|unix.NLM_F_DUMP)
return execRdmaGetLink(req, name)
} | go | func (h *Handle) RdmaLinkByName(name string) (*RdmaLink, error) {
proto := getProtoField(nl.RDMA_NL_NLDEV, nl.RDMA_NLDEV_CMD_GET)
req := h.newNetlinkRequest(proto, unix.NLM_F_ACK|unix.NLM_F_DUMP)
return execRdmaGetLink(req, name)
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"RdmaLinkByName",
"(",
"name",
"string",
")",
"(",
"*",
"RdmaLink",
",",
"error",
")",
"{",
"proto",
":=",
"getProtoField",
"(",
"nl",
".",
"RDMA_NL_NLDEV",
",",
"nl",
".",
"RDMA_NLDEV_CMD_GET",
")",
"\n",
"req",
"... | // RdmaLinkByName finds a link by name and returns a pointer to the object if
// found and nil error, otherwise returns error code. | [
"RdmaLinkByName",
"finds",
"a",
"link",
"by",
"name",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
"if",
"found",
"and",
"nil",
"error",
"otherwise",
"returns",
"error",
"code",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/rdma_link_linux.go#L112-L118 | train |
vishvananda/netlink | netlink.go | NewIPNet | func NewIPNet(ip net.IP) *net.IPNet {
if ip.To4() != nil {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)}
}
return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)}
} | go | func NewIPNet(ip net.IP) *net.IPNet {
if ip.To4() != nil {
return &net.IPNet{IP: ip, Mask: net.CIDRMask(32, 32)}
}
return &net.IPNet{IP: ip, Mask: net.CIDRMask(128, 128)}
} | [
"func",
"NewIPNet",
"(",
"ip",
"net",
".",
"IP",
")",
"*",
"net",
".",
"IPNet",
"{",
"if",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"ip",
",",
"Mask",
":",
"net",
".",
"CIDRMask",
"(",
... | // NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128. | [
"NewIPNet",
"generates",
"an",
"IPNet",
"from",
"an",
"ip",
"address",
"using",
"a",
"netmask",
"of",
"32",
"or",
"128",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netlink.go#L35-L40 | train |
vishvananda/netlink | link_linux.go | LinkSetVfGUID | func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error {
var err error
var guid uint64
buf := bytes.NewBuffer(vfGuid)
err = binary.Read(buf, binary.LittleEndian, &guid)
if err != nil {
return err
}
base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(u... | go | func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidType int) error {
var err error
var guid uint64
buf := bytes.NewBuffer(vfGuid)
err = binary.Read(buf, binary.LittleEndian, &guid)
if err != nil {
return err
}
base := link.Attrs()
h.ensureIndex(base)
req := h.newNetlinkRequest(u... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkSetVfGUID",
"(",
"link",
"Link",
",",
"vf",
"int",
",",
"vfGuid",
"net",
".",
"HardwareAddr",
",",
"guidType",
"int",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"guid",
"uint64",
"\n\n",
"buf",
"... | // LinkSetVfGUID sets the node or port GUID of a vf for the link. | [
"LinkSetVfGUID",
"sets",
"the",
"node",
"or",
"port",
"GUID",
"of",
"a",
"vf",
"for",
"the",
"link",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L579-L608 | train |
vishvananda/netlink | link_linux.go | LinkByName | func (h *Handle) LinkByName(name string) (Link, error) {
if h.lookupByDump {
return h.linkByNameDump(name)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.Ad... | go | func (h *Handle) LinkByName(name string) (Link, error) {
if h.lookupByDump {
return h.linkByNameDump(name)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.Ad... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkByName",
"(",
"name",
"string",
")",
"(",
"Link",
",",
"error",
")",
"{",
"if",
"h",
".",
"lookupByDump",
"{",
"return",
"h",
".",
"linkByNameDump",
"(",
"name",
")",
"\n",
"}",
"\n\n",
"req",
":=",
"h",
... | // LinkByName finds a link by name and returns a pointer to the object. | [
"LinkByName",
"finds",
"a",
"link",
"by",
"name",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1283-L1308 | train |
vishvananda/netlink | link_linux.go | LinkByAlias | func (h *Handle) LinkByAlias(alias string) (Link, error) {
if h.lookupByDump {
return h.linkByAliasDump(alias)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
re... | go | func (h *Handle) LinkByAlias(alias string) (Link, error) {
if h.lookupByDump {
return h.linkByAliasDump(alias)
}
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
re... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkByAlias",
"(",
"alias",
"string",
")",
"(",
"Link",
",",
"error",
")",
"{",
"if",
"h",
".",
"lookupByDump",
"{",
"return",
"h",
".",
"linkByAliasDump",
"(",
"alias",
")",
"\n",
"}",
"\n\n",
"req",
":=",
"h... | // LinkByAlias finds a link by its alias and returns a pointer to the object.
// If there are multiple links with the alias it returns the first one | [
"LinkByAlias",
"finds",
"a",
"link",
"by",
"its",
"alias",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
".",
"If",
"there",
"are",
"multiple",
"links",
"with",
"the",
"alias",
"it",
"returns",
"the",
"first",
"one"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1318-L1343 | train |
vishvananda/netlink | link_linux.go | LinkByIndex | func (h *Handle) LinkByIndex(index int) (Link, error) {
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(index)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
return execGetLink(... | go | func (h *Handle) LinkByIndex(index int) (Link, error) {
req := h.newNetlinkRequest(unix.RTM_GETLINK, unix.NLM_F_ACK)
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(index)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
return execGetLink(... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"LinkByIndex",
"(",
"index",
"int",
")",
"(",
"Link",
",",
"error",
")",
"{",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_GETLINK",
",",
"unix",
".",
"NLM_F_ACK",
")",
"\n\n",
"msg",
":=",
... | // LinkByIndex finds a link by index and returns a pointer to the object. | [
"LinkByIndex",
"finds",
"a",
"link",
"by",
"index",
"and",
"returns",
"a",
"pointer",
"to",
"the",
"object",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1351-L1361 | train |
vishvananda/netlink | link_linux.go | LinkSubscribe | func LinkSubscribe(ch chan<- LinkUpdate, done <-chan struct{}) error {
return linkSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | go | func LinkSubscribe(ch chan<- LinkUpdate, done <-chan struct{}) error {
return linkSubscribeAt(netns.None(), netns.None(), ch, done, nil, false)
} | [
"func",
"LinkSubscribe",
"(",
"ch",
"chan",
"<-",
"LinkUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"return",
"linkSubscribeAt",
"(",
"netns",
".",
"None",
"(",
")",
",",
"netns",
".",
"None",
"(",
")",
",",
"ch",
",",
... | // LinkSubscribe takes a chan down which notifications will be sent
// when links change. Close the 'done' chan to stop subscription. | [
"LinkSubscribe",
"takes",
"a",
"chan",
"down",
"which",
"notifications",
"will",
"be",
"sent",
"when",
"links",
"change",
".",
"Close",
"the",
"done",
"chan",
"to",
"stop",
"subscription",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1626-L1628 | train |
vishvananda/netlink | link_linux.go | LinkSubscribeWithOptions | func LinkSubscribeWithOptions(ch chan<- LinkUpdate, done <-chan struct{}, options LinkSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return linkSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | go | func LinkSubscribeWithOptions(ch chan<- LinkUpdate, done <-chan struct{}, options LinkSubscribeOptions) error {
if options.Namespace == nil {
none := netns.None()
options.Namespace = &none
}
return linkSubscribeAt(*options.Namespace, netns.None(), ch, done, options.ErrorCallback, options.ListExisting)
} | [
"func",
"LinkSubscribeWithOptions",
"(",
"ch",
"chan",
"<-",
"LinkUpdate",
",",
"done",
"<-",
"chan",
"struct",
"{",
"}",
",",
"options",
"LinkSubscribeOptions",
")",
"error",
"{",
"if",
"options",
".",
"Namespace",
"==",
"nil",
"{",
"none",
":=",
"netns",
... | // LinkSubscribeWithOptions work like LinkSubscribe but enable to
// provide additional options to modify the behavior. Currently, the
// namespace can be provided as well as an error callback. | [
"LinkSubscribeWithOptions",
"work",
"like",
"LinkSubscribe",
"but",
"enable",
"to",
"provide",
"additional",
"options",
"to",
"modify",
"the",
"behavior",
".",
"Currently",
"the",
"namespace",
"can",
"be",
"provided",
"as",
"well",
"as",
"an",
"error",
"callback",... | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L1647-L1653 | train |
vishvananda/netlink | link_linux.go | LinkSetBondSlave | func LinkSetBondSlave(link Link, master *Bond) error {
fd, err := getSocketUDP()
if err != nil {
return err
}
defer syscall.Close(fd)
ifreq := newIocltSlaveReq(link.Attrs().Name, master.Attrs().Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), unix.SIOCBONDENSLAVE, uintptr(unsafe.Pointer(if... | go | func LinkSetBondSlave(link Link, master *Bond) error {
fd, err := getSocketUDP()
if err != nil {
return err
}
defer syscall.Close(fd)
ifreq := newIocltSlaveReq(link.Attrs().Name, master.Attrs().Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), unix.SIOCBONDENSLAVE, uintptr(unsafe.Pointer(if... | [
"func",
"LinkSetBondSlave",
"(",
"link",
"Link",
",",
"master",
"*",
"Bond",
")",
"error",
"{",
"fd",
",",
"err",
":=",
"getSocketUDP",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"syscall",
".",
"Close",... | // LinkSetBondSlave add slave to bond link via ioctl interface. | [
"LinkSetBondSlave",
"add",
"slave",
"to",
"bond",
"link",
"via",
"ioctl",
"interface",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L2531-L2545 | train |
vishvananda/netlink | link_linux.go | VethPeerIndex | func VethPeerIndex(link *Veth) (int, error) {
fd, err := getSocketUDP()
if err != nil {
return -1, err
}
defer syscall.Close(fd)
ifreq, sSet := newIocltStringSetReq(link.Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -... | go | func VethPeerIndex(link *Veth) (int, error) {
fd, err := getSocketUDP()
if err != nil {
return -1, err
}
defer syscall.Close(fd)
ifreq, sSet := newIocltStringSetReq(link.Name)
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), SIOCETHTOOL, uintptr(unsafe.Pointer(ifreq)))
if errno != 0 {
return -... | [
"func",
"VethPeerIndex",
"(",
"link",
"*",
"Veth",
")",
"(",
"int",
",",
"error",
")",
"{",
"fd",
",",
"err",
":=",
"getSocketUDP",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"defer",
"syscall"... | // VethPeerIndex get veth peer index. | [
"VethPeerIndex",
"get",
"veth",
"peer",
"index",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/link_linux.go#L2548-L2582 | train |
vishvananda/netlink | netns_linux.go | GetNetNsIdByFd | func (h *Handle) GetNetNsIdByFd(fd int) (int, error) {
return h.getNetNsId(NETNSA_FD, uint32(fd))
} | go | func (h *Handle) GetNetNsIdByFd(fd int) (int, error) {
return h.getNetNsId(NETNSA_FD, uint32(fd))
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"GetNetNsIdByFd",
"(",
"fd",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"h",
".",
"getNetNsId",
"(",
"NETNSA_FD",
",",
"uint32",
"(",
"fd",
")",
")",
"\n",
"}"
] | // GetNetNsIdByFd looks up the network namespace ID for a given fd.
// fd must be an open file descriptor to a namespace file.
// Returns -1 if the namespace does not have an ID set. | [
"GetNetNsIdByFd",
"looks",
"up",
"the",
"network",
"namespace",
"ID",
"for",
"a",
"given",
"fd",
".",
"fd",
"must",
"be",
"an",
"open",
"file",
"descriptor",
"to",
"a",
"namespace",
"file",
".",
"Returns",
"-",
"1",
"if",
"the",
"namespace",
"does",
"not... | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L57-L59 | train |
vishvananda/netlink | netns_linux.go | SetNetNsIdByFd | func (h *Handle) SetNetNsIdByFd(fd, nsid int) error {
return h.setNetNsId(NETNSA_FD, uint32(fd), uint32(nsid))
} | go | func (h *Handle) SetNetNsIdByFd(fd, nsid int) error {
return h.setNetNsId(NETNSA_FD, uint32(fd), uint32(nsid))
} | [
"func",
"(",
"h",
"*",
"Handle",
")",
"SetNetNsIdByFd",
"(",
"fd",
",",
"nsid",
"int",
")",
"error",
"{",
"return",
"h",
".",
"setNetNsId",
"(",
"NETNSA_FD",
",",
"uint32",
"(",
"fd",
")",
",",
"uint32",
"(",
"nsid",
")",
")",
"\n",
"}"
] | // SetNetNSIdByFd sets the ID of the network namespace for a given fd.
// fd must be an open file descriptor to a namespace file.
// The ID can only be set for namespaces without an ID already set. | [
"SetNetNSIdByFd",
"sets",
"the",
"ID",
"of",
"the",
"network",
"namespace",
"for",
"a",
"given",
"fd",
".",
"fd",
"must",
"be",
"an",
"open",
"file",
"descriptor",
"to",
"a",
"namespace",
"file",
".",
"The",
"ID",
"can",
"only",
"be",
"set",
"for",
"na... | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L71-L73 | train |
vishvananda/netlink | netns_linux.go | getNetNsId | func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) {
req := h.newNetlinkRequest(unix.RTM_GETNSID, unix.NLM_F_REQUEST)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
msgs, err := req.Execute(unix... | go | func (h *Handle) getNetNsId(attrType int, val uint32) (int, error) {
req := h.newNetlinkRequest(unix.RTM_GETNSID, unix.NLM_F_REQUEST)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
msgs, err := req.Execute(unix... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"getNetNsId",
"(",
"attrType",
"int",
",",
"val",
"uint32",
")",
"(",
"int",
",",
"error",
")",
"{",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_GETNSID",
",",
"unix",
".",
"NLM_F_REQUEST",
... | // getNetNsId requests the netnsid for a given type-val pair
// type should be either NETNSA_PID or NETNSA_FD | [
"getNetNsId",
"requests",
"the",
"netnsid",
"for",
"a",
"given",
"type",
"-",
"val",
"pair",
"type",
"should",
"be",
"either",
"NETNSA_PID",
"or",
"NETNSA_FD"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L84-L118 | train |
vishvananda/netlink | netns_linux.go | setNetNsId | func (h *Handle) setNetNsId(attrType int, val uint32, newnsid uint32) error {
req := h.newNetlinkRequest(unix.RTM_NEWNSID, unix.NLM_F_REQUEST|unix.NLM_F_ACK)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
b1 :=... | go | func (h *Handle) setNetNsId(attrType int, val uint32, newnsid uint32) error {
req := h.newNetlinkRequest(unix.RTM_NEWNSID, unix.NLM_F_REQUEST|unix.NLM_F_ACK)
rtgen := nl.NewRtGenMsg()
req.AddData(rtgen)
b := make([]byte, 4, 4)
native.PutUint32(b, val)
attr := nl.NewRtAttr(attrType, b)
req.AddData(attr)
b1 :=... | [
"func",
"(",
"h",
"*",
"Handle",
")",
"setNetNsId",
"(",
"attrType",
"int",
",",
"val",
"uint32",
",",
"newnsid",
"uint32",
")",
"error",
"{",
"req",
":=",
"h",
".",
"newNetlinkRequest",
"(",
"unix",
".",
"RTM_NEWNSID",
",",
"unix",
".",
"NLM_F_REQUEST",... | // setNetNsId sets the netnsid for a given type-val pair
// type should be either NETNSA_PID or NETNSA_FD
// The ID can only be set for namespaces without an ID already set | [
"setNetNsId",
"sets",
"the",
"netnsid",
"for",
"a",
"given",
"type",
"-",
"val",
"pair",
"type",
"should",
"be",
"either",
"NETNSA_PID",
"or",
"NETNSA_FD",
"The",
"ID",
"can",
"only",
"be",
"set",
"for",
"namespaces",
"without",
"an",
"ID",
"already",
"set... | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/netns_linux.go#L123-L141 | train |
vishvananda/netlink | route.go | ipNetEqual | func ipNetEqual(ipn1 *net.IPNet, ipn2 *net.IPNet) bool {
if ipn1 == ipn2 {
return true
}
if ipn1 == nil || ipn2 == nil {
return false
}
m1, _ := ipn1.Mask.Size()
m2, _ := ipn2.Mask.Size()
return m1 == m2 && ipn1.IP.Equal(ipn2.IP)
} | go | func ipNetEqual(ipn1 *net.IPNet, ipn2 *net.IPNet) bool {
if ipn1 == ipn2 {
return true
}
if ipn1 == nil || ipn2 == nil {
return false
}
m1, _ := ipn1.Mask.Size()
m2, _ := ipn2.Mask.Size()
return m1 == m2 && ipn1.IP.Equal(ipn2.IP)
} | [
"func",
"ipNetEqual",
"(",
"ipn1",
"*",
"net",
".",
"IPNet",
",",
"ipn2",
"*",
"net",
".",
"IPNet",
")",
"bool",
"{",
"if",
"ipn1",
"==",
"ipn2",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"ipn1",
"==",
"nil",
"||",
"ipn2",
"==",
"nil",
"{",
... | // ipNetEqual returns true iff both IPNet are equal | [
"ipNetEqual",
"returns",
"true",
"iff",
"both",
"IPNet",
"are",
"equal"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/route.go#L170-L180 | train |
vishvananda/netlink | ioctl_linux.go | newIocltSlaveReq | func newIocltSlaveReq(slave, master string) *IfreqSlave {
ifreq := &IfreqSlave{}
copy(ifreq.Name[:unix.IFNAMSIZ-1], master)
copy(ifreq.Slave[:unix.IFNAMSIZ-1], slave)
return ifreq
} | go | func newIocltSlaveReq(slave, master string) *IfreqSlave {
ifreq := &IfreqSlave{}
copy(ifreq.Name[:unix.IFNAMSIZ-1], master)
copy(ifreq.Slave[:unix.IFNAMSIZ-1], slave)
return ifreq
} | [
"func",
"newIocltSlaveReq",
"(",
"slave",
",",
"master",
"string",
")",
"*",
"IfreqSlave",
"{",
"ifreq",
":=",
"&",
"IfreqSlave",
"{",
"}",
"\n",
"copy",
"(",
"ifreq",
".",
"Name",
"[",
":",
"unix",
".",
"IFNAMSIZ",
"-",
"1",
"]",
",",
"master",
")",... | // newIocltSlaveReq returns filled IfreqSlave with proper interface names
// It is used by ioctl to assign slave to bond master | [
"newIocltSlaveReq",
"returns",
"filled",
"IfreqSlave",
"with",
"proper",
"interface",
"names",
"It",
"is",
"used",
"by",
"ioctl",
"to",
"assign",
"slave",
"to",
"bond",
"master"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/ioctl_linux.go#L75-L80 | train |
vishvananda/netlink | ioctl_linux.go | newIocltStringSetReq | func newIocltStringSetReq(linkName string) (*Ifreq, *ethtoolSset) {
e := ðtoolSset{
cmd: ETHTOOL_GSSET_INFO,
mask: 1 << ETH_SS_STATS,
}
ifreq := &Ifreq{Data: uintptr(unsafe.Pointer(e))}
copy(ifreq.Name[:unix.IFNAMSIZ-1], linkName)
return ifreq, e
} | go | func newIocltStringSetReq(linkName string) (*Ifreq, *ethtoolSset) {
e := ðtoolSset{
cmd: ETHTOOL_GSSET_INFO,
mask: 1 << ETH_SS_STATS,
}
ifreq := &Ifreq{Data: uintptr(unsafe.Pointer(e))}
copy(ifreq.Name[:unix.IFNAMSIZ-1], linkName)
return ifreq, e
} | [
"func",
"newIocltStringSetReq",
"(",
"linkName",
"string",
")",
"(",
"*",
"Ifreq",
",",
"*",
"ethtoolSset",
")",
"{",
"e",
":=",
"&",
"ethtoolSset",
"{",
"cmd",
":",
"ETHTOOL_GSSET_INFO",
",",
"mask",
":",
"1",
"<<",
"ETH_SS_STATS",
",",
"}",
"\n\n",
"if... | // newIocltStringSetReq creates request to get interface string set | [
"newIocltStringSetReq",
"creates",
"request",
"to",
"get",
"interface",
"string",
"set"
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/ioctl_linux.go#L83-L92 | train |
vishvananda/netlink | addr.go | Equal | func (a Addr) Equal(x Addr) bool {
sizea, _ := a.Mask.Size()
sizeb, _ := x.Mask.Size()
// ignore label for comparison
return a.IP.Equal(x.IP) && sizea == sizeb
} | go | func (a Addr) Equal(x Addr) bool {
sizea, _ := a.Mask.Size()
sizeb, _ := x.Mask.Size()
// ignore label for comparison
return a.IP.Equal(x.IP) && sizea == sizeb
} | [
"func",
"(",
"a",
"Addr",
")",
"Equal",
"(",
"x",
"Addr",
")",
"bool",
"{",
"sizea",
",",
"_",
":=",
"a",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"sizeb",
",",
"_",
":=",
"x",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"// ignore label for com... | // Equal returns true if both Addrs have the same net.IPNet value. | [
"Equal",
"returns",
"true",
"if",
"both",
"Addrs",
"have",
"the",
"same",
"net",
".",
"IPNet",
"value",
"."
] | fd97bf4e47867b5e794234baa6b8a7746135ec10 | https://github.com/vishvananda/netlink/blob/fd97bf4e47867b5e794234baa6b8a7746135ec10/addr.go#L44-L49 | 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.