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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
gdamore/tcell | views/cellarea.go | SetCursorY | func (a *CellView) SetCursorY(y int) {
a.SetCursor(a.cursorX, y)
} | go | func (a *CellView) SetCursorY(y int) {
a.SetCursor(a.cursorX, y)
} | [
"func",
"(",
"a",
"*",
"CellView",
")",
"SetCursorY",
"(",
"y",
"int",
")",
"{",
"a",
".",
"SetCursor",
"(",
"a",
".",
"cursorX",
",",
"y",
")",
"\n",
"}"
] | // SetCursorY sets the the cursor row. | [
"SetCursorY",
"sets",
"the",
"the",
"cursor",
"row",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L288-L290 | train |
gdamore/tcell | views/cellarea.go | MakeVisible | func (a *CellView) MakeVisible(x, y int) {
a.port.MakeVisible(x, y)
} | go | func (a *CellView) MakeVisible(x, y int) {
a.port.MakeVisible(x, y)
} | [
"func",
"(",
"a",
"*",
"CellView",
")",
"MakeVisible",
"(",
"x",
",",
"y",
"int",
")",
"{",
"a",
".",
"port",
".",
"MakeVisible",
"(",
"x",
",",
"y",
")",
"\n",
"}"
] | // MakeVisible makes the given coordinates visible, if they are not already.
// It does this by moving the ViewPort for the CellView. | [
"MakeVisible",
"makes",
"the",
"given",
"coordinates",
"visible",
"if",
"they",
"are",
"not",
"already",
".",
"It",
"does",
"this",
"by",
"moving",
"the",
"ViewPort",
"for",
"the",
"CellView",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L294-L296 | train |
gdamore/tcell | views/cellarea.go | Init | func (a *CellView) Init() {
a.once.Do(func() {
a.port = NewViewPort(nil, 0, 0, 0, 0)
a.style = tcell.StyleDefault
})
} | go | func (a *CellView) Init() {
a.once.Do(func() {
a.port = NewViewPort(nil, 0, 0, 0, 0)
a.style = tcell.StyleDefault
})
} | [
"func",
"(",
"a",
"*",
"CellView",
")",
"Init",
"(",
")",
"{",
"a",
".",
"once",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"a",
".",
"port",
"=",
"NewViewPort",
"(",
"nil",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"\n",
"a",
".",
"style",
"=",
"tcell",
".",
"StyleDefault",
"\n",
"}",
")",
"\n",
"}"
] | // Init initializes a new CellView for use. | [
"Init",
"initializes",
"a",
"new",
"CellView",
"for",
"use",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/cellarea.go#L304-L309 | train |
gdamore/tcell | simulation.go | NewSimulationScreen | func NewSimulationScreen(charset string) SimulationScreen {
if charset == "" {
charset = "UTF-8"
}
s := &simscreen{charset: charset}
return s
} | go | func NewSimulationScreen(charset string) SimulationScreen {
if charset == "" {
charset = "UTF-8"
}
s := &simscreen{charset: charset}
return s
} | [
"func",
"NewSimulationScreen",
"(",
"charset",
"string",
")",
"SimulationScreen",
"{",
"if",
"charset",
"==",
"\"",
"\"",
"{",
"charset",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
":=",
"&",
"simscreen",
"{",
"charset",
":",
"charset",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // NewSimulationScreen returns a SimulationScreen. Note that
// SimulationScreen is also a Screen. | [
"NewSimulationScreen",
"returns",
"a",
"SimulationScreen",
".",
"Note",
"that",
"SimulationScreen",
"is",
"also",
"a",
"Screen",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/simulation.go#L26-L32 | train |
gdamore/tcell | resize.go | NewEventResize | func NewEventResize(width, height int) *EventResize {
return &EventResize{t: time.Now(), w: width, h: height}
} | go | func NewEventResize(width, height int) *EventResize {
return &EventResize{t: time.Now(), w: width, h: height}
} | [
"func",
"NewEventResize",
"(",
"width",
",",
"height",
"int",
")",
"*",
"EventResize",
"{",
"return",
"&",
"EventResize",
"{",
"t",
":",
"time",
".",
"Now",
"(",
")",
",",
"w",
":",
"width",
",",
"h",
":",
"height",
"}",
"\n",
"}"
] | // NewEventResize creates an EventResize with the new updated window size,
// which is given in character cells. | [
"NewEventResize",
"creates",
"an",
"EventResize",
"with",
"the",
"new",
"updated",
"window",
"size",
"which",
"is",
"given",
"in",
"character",
"cells",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/resize.go#L30-L32 | train |
gdamore/tcell | terminfo/terminfo.go | End | func (pb *paramsBuffer) End() string {
s := pb.out.String()
pb.lk.Unlock()
return s
} | go | func (pb *paramsBuffer) End() string {
s := pb.out.String()
pb.lk.Unlock()
return s
} | [
"func",
"(",
"pb",
"*",
"paramsBuffer",
")",
"End",
"(",
")",
"string",
"{",
"s",
":=",
"pb",
".",
"out",
".",
"String",
"(",
")",
"\n",
"pb",
".",
"lk",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
"\n",
"}"
] | // End returns the final output from TParam, but it also releases the lock. | [
"End",
"returns",
"the",
"final",
"output",
"from",
"TParam",
"but",
"it",
"also",
"releases",
"the",
"lock",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L325-L329 | train |
gdamore/tcell | terminfo/terminfo.go | TGoto | func (t *Terminfo) TGoto(col, row int) string {
return t.TParm(t.SetCursor, row, col)
} | go | func (t *Terminfo) TGoto(col, row int) string {
return t.TParm(t.SetCursor, row, col)
} | [
"func",
"(",
"t",
"*",
"Terminfo",
")",
"TGoto",
"(",
"col",
",",
"row",
"int",
")",
"string",
"{",
"return",
"t",
".",
"TParm",
"(",
"t",
".",
"SetCursor",
",",
"row",
",",
"col",
")",
"\n",
"}"
] | // TGoto returns a string suitable for addressing the cursor at the given
// row and column. The origin 0, 0 is in the upper left corner of the screen. | [
"TGoto",
"returns",
"a",
"string",
"suitable",
"for",
"addressing",
"the",
"cursor",
"at",
"the",
"given",
"row",
"and",
"column",
".",
"The",
"origin",
"0",
"0",
"is",
"in",
"the",
"upper",
"left",
"corner",
"of",
"the",
"screen",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L675-L677 | train |
gdamore/tcell | terminfo/terminfo.go | TColor | func (t *Terminfo) TColor(fi, bi int) string {
rv := ""
// As a special case, we map bright colors to lower versions if the
// color table only holds 8. For the remaining 240 colors, the user
// is out of luck. Someday we could create a mapping table, but its
// not worth it.
if t.Colors == 8 {
if fi > 7 && fi < 16 {
fi -= 8
}
if bi > 7 && bi < 16 {
bi -= 8
}
}
if t.Colors > fi && fi >= 0 {
rv += t.TParm(t.SetFg, fi)
}
if t.Colors > bi && bi >= 0 {
rv += t.TParm(t.SetBg, bi)
}
return rv
} | go | func (t *Terminfo) TColor(fi, bi int) string {
rv := ""
// As a special case, we map bright colors to lower versions if the
// color table only holds 8. For the remaining 240 colors, the user
// is out of luck. Someday we could create a mapping table, but its
// not worth it.
if t.Colors == 8 {
if fi > 7 && fi < 16 {
fi -= 8
}
if bi > 7 && bi < 16 {
bi -= 8
}
}
if t.Colors > fi && fi >= 0 {
rv += t.TParm(t.SetFg, fi)
}
if t.Colors > bi && bi >= 0 {
rv += t.TParm(t.SetBg, bi)
}
return rv
} | [
"func",
"(",
"t",
"*",
"Terminfo",
")",
"TColor",
"(",
"fi",
",",
"bi",
"int",
")",
"string",
"{",
"rv",
":=",
"\"",
"\"",
"\n",
"// As a special case, we map bright colors to lower versions if the",
"// color table only holds 8. For the remaining 240 colors, the user",
"// is out of luck. Someday we could create a mapping table, but its",
"// not worth it.",
"if",
"t",
".",
"Colors",
"==",
"8",
"{",
"if",
"fi",
">",
"7",
"&&",
"fi",
"<",
"16",
"{",
"fi",
"-=",
"8",
"\n",
"}",
"\n",
"if",
"bi",
">",
"7",
"&&",
"bi",
"<",
"16",
"{",
"bi",
"-=",
"8",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"t",
".",
"Colors",
">",
"fi",
"&&",
"fi",
">=",
"0",
"{",
"rv",
"+=",
"t",
".",
"TParm",
"(",
"t",
".",
"SetFg",
",",
"fi",
")",
"\n",
"}",
"\n",
"if",
"t",
".",
"Colors",
">",
"bi",
"&&",
"bi",
">=",
"0",
"{",
"rv",
"+=",
"t",
".",
"TParm",
"(",
"t",
".",
"SetBg",
",",
"bi",
")",
"\n",
"}",
"\n",
"return",
"rv",
"\n",
"}"
] | // TColor returns a string corresponding to the given foreground and background
// colors. Either fg or bg can be set to -1 to elide. | [
"TColor",
"returns",
"a",
"string",
"corresponding",
"to",
"the",
"given",
"foreground",
"and",
"background",
"colors",
".",
"Either",
"fg",
"or",
"bg",
"can",
"be",
"set",
"to",
"-",
"1",
"to",
"elide",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L681-L702 | train |
gdamore/tcell | terminfo/terminfo.go | AddTerminfo | func AddTerminfo(t *Terminfo) {
dblock.Lock()
terminfos[t.Name] = t
for _, x := range t.Aliases {
terminfos[x] = t
}
dblock.Unlock()
} | go | func AddTerminfo(t *Terminfo) {
dblock.Lock()
terminfos[t.Name] = t
for _, x := range t.Aliases {
terminfos[x] = t
}
dblock.Unlock()
} | [
"func",
"AddTerminfo",
"(",
"t",
"*",
"Terminfo",
")",
"{",
"dblock",
".",
"Lock",
"(",
")",
"\n",
"terminfos",
"[",
"t",
".",
"Name",
"]",
"=",
"t",
"\n",
"for",
"_",
",",
"x",
":=",
"range",
"t",
".",
"Aliases",
"{",
"terminfos",
"[",
"x",
"]",
"=",
"t",
"\n",
"}",
"\n",
"dblock",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // AddTerminfo can be called to register a new Terminfo entry. | [
"AddTerminfo",
"can",
"be",
"called",
"to",
"register",
"a",
"new",
"Terminfo",
"entry",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/terminfo/terminfo.go#L711-L718 | train |
gdamore/tcell | screen.go | NewScreen | func NewScreen() (Screen, error) {
// Windows is happier if we try for a console screen first.
if s, _ := NewConsoleScreen(); s != nil {
return s, nil
} else if s, e := NewTerminfoScreen(); s != nil {
return s, nil
} else {
return nil, e
}
} | go | func NewScreen() (Screen, error) {
// Windows is happier if we try for a console screen first.
if s, _ := NewConsoleScreen(); s != nil {
return s, nil
} else if s, e := NewTerminfoScreen(); s != nil {
return s, nil
} else {
return nil, e
}
} | [
"func",
"NewScreen",
"(",
")",
"(",
"Screen",
",",
"error",
")",
"{",
"// Windows is happier if we try for a console screen first.",
"if",
"s",
",",
"_",
":=",
"NewConsoleScreen",
"(",
")",
";",
"s",
"!=",
"nil",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"else",
"if",
"s",
",",
"e",
":=",
"NewTerminfoScreen",
"(",
")",
";",
"s",
"!=",
"nil",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"e",
"\n",
"}",
"\n",
"}"
] | // NewScreen returns a default Screen suitable for the user's terminal
// environment. | [
"NewScreen",
"returns",
"a",
"default",
"Screen",
"suitable",
"for",
"the",
"user",
"s",
"terminal",
"environment",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/screen.go#L200-L209 | train |
gdamore/tcell | views/app.go | initialize | func (app *Application) initialize() error {
if app.screen == nil {
if app.screen, app.err = tcell.NewScreen(); app.err != nil {
return app.err
}
app.screen.SetStyle(app.style)
}
return nil
} | go | func (app *Application) initialize() error {
if app.screen == nil {
if app.screen, app.err = tcell.NewScreen(); app.err != nil {
return app.err
}
app.screen.SetStyle(app.style)
}
return nil
} | [
"func",
"(",
"app",
"*",
"Application",
")",
"initialize",
"(",
")",
"error",
"{",
"if",
"app",
".",
"screen",
"==",
"nil",
"{",
"if",
"app",
".",
"screen",
",",
"app",
".",
"err",
"=",
"tcell",
".",
"NewScreen",
"(",
")",
";",
"app",
".",
"err",
"!=",
"nil",
"{",
"return",
"app",
".",
"err",
"\n",
"}",
"\n",
"app",
".",
"screen",
".",
"SetStyle",
"(",
"app",
".",
"style",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // initialize initializes the application. It will normally attempt to
// allocate a default screen if one is not already established. | [
"initialize",
"initializes",
"the",
"application",
".",
"It",
"will",
"normally",
"attempt",
"to",
"allocate",
"a",
"default",
"screen",
"if",
"one",
"is",
"not",
"already",
"established",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L39-L47 | train |
gdamore/tcell | views/app.go | Quit | func (app *Application) Quit() {
ev := &eventAppQuit{}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | go | func (app *Application) Quit() {
ev := &eventAppQuit{}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | [
"func",
"(",
"app",
"*",
"Application",
")",
"Quit",
"(",
")",
"{",
"ev",
":=",
"&",
"eventAppQuit",
"{",
"}",
"\n",
"ev",
".",
"SetEventNow",
"(",
")",
"\n",
"if",
"scr",
":=",
"app",
".",
"screen",
";",
"scr",
"!=",
"nil",
"{",
"go",
"func",
"(",
")",
"{",
"scr",
".",
"PostEventWait",
"(",
"ev",
")",
"}",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Quit causes the application to shutdown gracefully. It does not wait
// for the application to exit, but returns immediately. | [
"Quit",
"causes",
"the",
"application",
"to",
"shutdown",
"gracefully",
".",
"It",
"does",
"not",
"wait",
"for",
"the",
"application",
"to",
"exit",
"but",
"returns",
"immediately",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L51-L57 | train |
gdamore/tcell | views/app.go | Refresh | func (app *Application) Refresh() {
ev := &eventAppRefresh{}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | go | func (app *Application) Refresh() {
ev := &eventAppRefresh{}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | [
"func",
"(",
"app",
"*",
"Application",
")",
"Refresh",
"(",
")",
"{",
"ev",
":=",
"&",
"eventAppRefresh",
"{",
"}",
"\n",
"ev",
".",
"SetEventNow",
"(",
")",
"\n",
"if",
"scr",
":=",
"app",
".",
"screen",
";",
"scr",
"!=",
"nil",
"{",
"go",
"func",
"(",
")",
"{",
"scr",
".",
"PostEventWait",
"(",
"ev",
")",
"}",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Refresh causes the application forcibly redraw everything. Use this
// to clear up screen corruption, etc. | [
"Refresh",
"causes",
"the",
"application",
"forcibly",
"redraw",
"everything",
".",
"Use",
"this",
"to",
"clear",
"up",
"screen",
"corruption",
"etc",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L61-L67 | train |
gdamore/tcell | views/app.go | Update | func (app *Application) Update() {
ev := &eventAppUpdate{}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | go | func (app *Application) Update() {
ev := &eventAppUpdate{}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | [
"func",
"(",
"app",
"*",
"Application",
")",
"Update",
"(",
")",
"{",
"ev",
":=",
"&",
"eventAppUpdate",
"{",
"}",
"\n",
"ev",
".",
"SetEventNow",
"(",
")",
"\n",
"if",
"scr",
":=",
"app",
".",
"screen",
";",
"scr",
"!=",
"nil",
"{",
"go",
"func",
"(",
")",
"{",
"scr",
".",
"PostEventWait",
"(",
"ev",
")",
"}",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Update asks the application to draw any screen updates that have not
// been drawn yet. | [
"Update",
"asks",
"the",
"application",
"to",
"draw",
"any",
"screen",
"updates",
"that",
"have",
"not",
"been",
"drawn",
"yet",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L71-L77 | train |
gdamore/tcell | views/app.go | PostFunc | func (app *Application) PostFunc(fn func()) {
ev := &eventAppFunc{fn: fn}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | go | func (app *Application) PostFunc(fn func()) {
ev := &eventAppFunc{fn: fn}
ev.SetEventNow()
if scr := app.screen; scr != nil {
go func() { scr.PostEventWait(ev) }()
}
} | [
"func",
"(",
"app",
"*",
"Application",
")",
"PostFunc",
"(",
"fn",
"func",
"(",
")",
")",
"{",
"ev",
":=",
"&",
"eventAppFunc",
"{",
"fn",
":",
"fn",
"}",
"\n",
"ev",
".",
"SetEventNow",
"(",
")",
"\n",
"if",
"scr",
":=",
"app",
".",
"screen",
";",
"scr",
"!=",
"nil",
"{",
"go",
"func",
"(",
")",
"{",
"scr",
".",
"PostEventWait",
"(",
"ev",
")",
"}",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // PostFunc posts a function to be executed in the context of the
// application's event loop. Functions that need to update displayed
// state, etc. can do this to avoid holding locks. | [
"PostFunc",
"posts",
"a",
"function",
"to",
"be",
"executed",
"in",
"the",
"context",
"of",
"the",
"application",
"s",
"event",
"loop",
".",
"Functions",
"that",
"need",
"to",
"update",
"displayed",
"state",
"etc",
".",
"can",
"do",
"this",
"to",
"avoid",
"holding",
"locks",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L82-L88 | train |
gdamore/tcell | views/app.go | SetScreen | func (app *Application) SetScreen(scr tcell.Screen) {
if app.screen == nil {
app.screen = scr
app.err = nil
}
} | go | func (app *Application) SetScreen(scr tcell.Screen) {
if app.screen == nil {
app.screen = scr
app.err = nil
}
} | [
"func",
"(",
"app",
"*",
"Application",
")",
"SetScreen",
"(",
"scr",
"tcell",
".",
"Screen",
")",
"{",
"if",
"app",
".",
"screen",
"==",
"nil",
"{",
"app",
".",
"screen",
"=",
"scr",
"\n",
"app",
".",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetScreen sets the screen to use for the application. This must be
// done before the application starts to run or is initialized. | [
"SetScreen",
"sets",
"the",
"screen",
"to",
"use",
"for",
"the",
"application",
".",
"This",
"must",
"be",
"done",
"before",
"the",
"application",
"starts",
"to",
"run",
"or",
"is",
"initialized",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/views/app.go#L92-L97 | train |
gdamore/tcell | mouse.go | NewEventMouse | func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse {
return &EventMouse{t: time.Now(), x: x, y: y, btn: btn, mod: mod}
} | go | func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse {
return &EventMouse{t: time.Now(), x: x, y: y, btn: btn, mod: mod}
} | [
"func",
"NewEventMouse",
"(",
"x",
",",
"y",
"int",
",",
"btn",
"ButtonMask",
",",
"mod",
"ModMask",
")",
"*",
"EventMouse",
"{",
"return",
"&",
"EventMouse",
"{",
"t",
":",
"time",
".",
"Now",
"(",
")",
",",
"x",
":",
"x",
",",
"y",
":",
"y",
",",
"btn",
":",
"btn",
",",
"mod",
":",
"mod",
"}",
"\n",
"}"
] | // NewEventMouse is used to create a new mouse event. Applications
// shouldn't need to use this; its mostly for screen implementors. | [
"NewEventMouse",
"is",
"used",
"to",
"create",
"a",
"new",
"mouse",
"event",
".",
"Applications",
"shouldn",
"t",
"need",
"to",
"use",
"this",
";",
"its",
"mostly",
"for",
"screen",
"implementors",
"."
] | dcf1bb30770eb1158b67005e1e472de6d74f055d | https://github.com/gdamore/tcell/blob/dcf1bb30770eb1158b67005e1e472de6d74f055d/mouse.go#L69-L71 | train |
onsi/ginkgo | ginkgo/run_command.go | moveCoverprofiles | func (r *SpecRunner) moveCoverprofiles(runners []*testrunner.TestRunner) {
for _, runner := range runners {
_, filename := filepath.Split(runner.CoverageFile)
err := os.Rename(runner.CoverageFile, filepath.Join(r.getOutputDir(), filename))
if err != nil {
fmt.Printf("Unable to move coverprofile %s, %v\n", runner.CoverageFile, err)
return
}
}
} | go | func (r *SpecRunner) moveCoverprofiles(runners []*testrunner.TestRunner) {
for _, runner := range runners {
_, filename := filepath.Split(runner.CoverageFile)
err := os.Rename(runner.CoverageFile, filepath.Join(r.getOutputDir(), filename))
if err != nil {
fmt.Printf("Unable to move coverprofile %s, %v\n", runner.CoverageFile, err)
return
}
}
} | [
"func",
"(",
"r",
"*",
"SpecRunner",
")",
"moveCoverprofiles",
"(",
"runners",
"[",
"]",
"*",
"testrunner",
".",
"TestRunner",
")",
"{",
"for",
"_",
",",
"runner",
":=",
"range",
"runners",
"{",
"_",
",",
"filename",
":=",
"filepath",
".",
"Split",
"(",
"runner",
".",
"CoverageFile",
")",
"\n",
"err",
":=",
"os",
".",
"Rename",
"(",
"runner",
".",
"CoverageFile",
",",
"filepath",
".",
"Join",
"(",
"r",
".",
"getOutputDir",
"(",
")",
",",
"filename",
")",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"runner",
".",
"CoverageFile",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Moves all generated profiles to specified directory | [
"Moves",
"all",
"generated",
"profiles",
"to",
"specified",
"directory"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/run_command.go#L144-L154 | train |
onsi/ginkgo | ginkgo/run_command.go | combineCoverprofiles | func (r *SpecRunner) combineCoverprofiles(runners []*testrunner.TestRunner) error {
path, _ := filepath.Abs(r.getOutputDir())
if !fileExists(path) {
return fmt.Errorf("Unable to create combined profile, outputdir does not exist: %s", r.getOutputDir())
}
fmt.Println("path is " + path)
combined, err := os.OpenFile(filepath.Join(path, r.getCoverprofile()),
os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Printf("Unable to create combined profile, %v\n", err)
return nil // non-fatal error
}
for _, runner := range runners {
contents, err := ioutil.ReadFile(runner.CoverageFile)
if err != nil {
fmt.Printf("Unable to read coverage file %s to combine, %v\n", runner.CoverageFile, err)
return nil // non-fatal error
}
_, err = combined.Write(contents)
if err != nil {
fmt.Printf("Unable to append to coverprofile, %v\n", err)
return nil // non-fatal error
}
}
fmt.Println("All profiles combined")
return nil
} | go | func (r *SpecRunner) combineCoverprofiles(runners []*testrunner.TestRunner) error {
path, _ := filepath.Abs(r.getOutputDir())
if !fileExists(path) {
return fmt.Errorf("Unable to create combined profile, outputdir does not exist: %s", r.getOutputDir())
}
fmt.Println("path is " + path)
combined, err := os.OpenFile(filepath.Join(path, r.getCoverprofile()),
os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Printf("Unable to create combined profile, %v\n", err)
return nil // non-fatal error
}
for _, runner := range runners {
contents, err := ioutil.ReadFile(runner.CoverageFile)
if err != nil {
fmt.Printf("Unable to read coverage file %s to combine, %v\n", runner.CoverageFile, err)
return nil // non-fatal error
}
_, err = combined.Write(contents)
if err != nil {
fmt.Printf("Unable to append to coverprofile, %v\n", err)
return nil // non-fatal error
}
}
fmt.Println("All profiles combined")
return nil
} | [
"func",
"(",
"r",
"*",
"SpecRunner",
")",
"combineCoverprofiles",
"(",
"runners",
"[",
"]",
"*",
"testrunner",
".",
"TestRunner",
")",
"error",
"{",
"path",
",",
"_",
":=",
"filepath",
".",
"Abs",
"(",
"r",
".",
"getOutputDir",
"(",
")",
")",
"\n",
"if",
"!",
"fileExists",
"(",
"path",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"getOutputDir",
"(",
")",
")",
"\n",
"}",
"\n\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
"+",
"path",
")",
"\n\n",
"combined",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"filepath",
".",
"Join",
"(",
"path",
",",
"r",
".",
"getCoverprofile",
"(",
")",
")",
",",
"os",
".",
"O_APPEND",
"|",
"os",
".",
"O_WRONLY",
"|",
"os",
".",
"O_CREATE",
",",
"0666",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"// non-fatal error",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"runner",
":=",
"range",
"runners",
"{",
"contents",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"runner",
".",
"CoverageFile",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"runner",
".",
"CoverageFile",
",",
"err",
")",
"\n",
"return",
"nil",
"// non-fatal error",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"combined",
".",
"Write",
"(",
"contents",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"// non-fatal error",
"\n",
"}",
"\n",
"}",
"\n\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Combines all generated profiles in the specified directory | [
"Combines",
"all",
"generated",
"profiles",
"in",
"the",
"specified",
"directory"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo/run_command.go#L157-L192 | train |
onsi/ginkgo | internal/remote/server.go | NewServer | func NewServer(parallelTotal int) (*Server, error) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return nil, err
}
return &Server{
listener: listener,
lock: &sync.Mutex{},
alives: make([]func() bool, parallelTotal),
beforeSuiteData: types.RemoteBeforeSuiteData{Data: nil, State: types.RemoteBeforeSuiteStatePending},
parallelTotal: parallelTotal,
}, nil
} | go | func NewServer(parallelTotal int) (*Server, error) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return nil, err
}
return &Server{
listener: listener,
lock: &sync.Mutex{},
alives: make([]func() bool, parallelTotal),
beforeSuiteData: types.RemoteBeforeSuiteData{Data: nil, State: types.RemoteBeforeSuiteStatePending},
parallelTotal: parallelTotal,
}, nil
} | [
"func",
"NewServer",
"(",
"parallelTotal",
"int",
")",
"(",
"*",
"Server",
",",
"error",
")",
"{",
"listener",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Server",
"{",
"listener",
":",
"listener",
",",
"lock",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"alives",
":",
"make",
"(",
"[",
"]",
"func",
"(",
")",
"bool",
",",
"parallelTotal",
")",
",",
"beforeSuiteData",
":",
"types",
".",
"RemoteBeforeSuiteData",
"{",
"Data",
":",
"nil",
",",
"State",
":",
"types",
".",
"RemoteBeforeSuiteStatePending",
"}",
",",
"parallelTotal",
":",
"parallelTotal",
",",
"}",
",",
"nil",
"\n",
"}"
] | //Create a new server, automatically selecting a port | [
"Create",
"a",
"new",
"server",
"automatically",
"selecting",
"a",
"port"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/internal/remote/server.go#L39-L51 | train |
onsi/ginkgo | internal/remote/server.go | readAll | func (server *Server) readAll(request *http.Request) []byte {
defer request.Body.Close()
body, _ := ioutil.ReadAll(request.Body)
return body
} | go | func (server *Server) readAll(request *http.Request) []byte {
defer request.Body.Close()
body, _ := ioutil.ReadAll(request.Body)
return body
} | [
"func",
"(",
"server",
"*",
"Server",
")",
"readAll",
"(",
"request",
"*",
"http",
".",
"Request",
")",
"[",
"]",
"byte",
"{",
"defer",
"request",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"body",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"request",
".",
"Body",
")",
"\n",
"return",
"body",
"\n",
"}"
] | //
// Streaming Endpoints
//
//The server will forward all received messages to Ginkgo reporters registered with `RegisterReporters` | [
"Streaming",
"Endpoints",
"The",
"server",
"will",
"forward",
"all",
"received",
"messages",
"to",
"Ginkgo",
"reporters",
"registered",
"with",
"RegisterReporters"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/internal/remote/server.go#L91-L95 | train |
onsi/ginkgo | ginkgo_dsl.go | Skip | func Skip(message string, callerSkip ...int) {
skip := 0
if len(callerSkip) > 0 {
skip = callerSkip[0]
}
globalFailer.Skip(message, codelocation.New(skip+1))
panic(GINKGO_PANIC)
} | go | func Skip(message string, callerSkip ...int) {
skip := 0
if len(callerSkip) > 0 {
skip = callerSkip[0]
}
globalFailer.Skip(message, codelocation.New(skip+1))
panic(GINKGO_PANIC)
} | [
"func",
"Skip",
"(",
"message",
"string",
",",
"callerSkip",
"...",
"int",
")",
"{",
"skip",
":=",
"0",
"\n",
"if",
"len",
"(",
"callerSkip",
")",
">",
"0",
"{",
"skip",
"=",
"callerSkip",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"globalFailer",
".",
"Skip",
"(",
"message",
",",
"codelocation",
".",
"New",
"(",
"skip",
"+",
"1",
")",
")",
"\n",
"panic",
"(",
"GINKGO_PANIC",
")",
"\n",
"}"
] | //Skip notifies Ginkgo that the current spec was skipped. | [
"Skip",
"notifies",
"Ginkgo",
"that",
"the",
"current",
"spec",
"was",
"skipped",
"."
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L244-L252 | train |
onsi/ginkgo | ginkgo_dsl.go | PDescribe | func PDescribe(text string, body func()) bool {
globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))
return true
} | go | func PDescribe(text string, body func()) bool {
globalSuite.PushContainerNode(text, body, types.FlagTypePending, codelocation.New(1))
return true
} | [
"func",
"PDescribe",
"(",
"text",
"string",
",",
"body",
"func",
"(",
")",
")",
"bool",
"{",
"globalSuite",
".",
"PushContainerNode",
"(",
"text",
",",
"body",
",",
"types",
".",
"FlagTypePending",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //You can mark the tests within a describe block as pending using PDescribe | [
"You",
"can",
"mark",
"the",
"tests",
"within",
"a",
"describe",
"block",
"as",
"pending",
"using",
"PDescribe"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L300-L303 | train |
onsi/ginkgo | ginkgo_dsl.go | FWhen | func FWhen(text string, body func()) bool {
globalSuite.PushContainerNode("when "+text, body, types.FlagTypeFocused, codelocation.New(1))
return true
} | go | func FWhen(text string, body func()) bool {
globalSuite.PushContainerNode("when "+text, body, types.FlagTypeFocused, codelocation.New(1))
return true
} | [
"func",
"FWhen",
"(",
"text",
"string",
",",
"body",
"func",
"(",
")",
")",
"bool",
"{",
"globalSuite",
".",
"PushContainerNode",
"(",
"\"",
"\"",
"+",
"text",
",",
"body",
",",
"types",
".",
"FlagTypeFocused",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //You can focus the tests within a describe block using FWhen | [
"You",
"can",
"focus",
"the",
"tests",
"within",
"a",
"describe",
"block",
"using",
"FWhen"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L352-L355 | train |
onsi/ginkgo | ginkgo_dsl.go | It | func It(text string, body interface{}, timeout ...float64) bool {
globalSuite.PushItNode(text, body, types.FlagTypeNone, codelocation.New(1), parseTimeout(timeout...))
return true
} | go | func It(text string, body interface{}, timeout ...float64) bool {
globalSuite.PushItNode(text, body, types.FlagTypeNone, codelocation.New(1), parseTimeout(timeout...))
return true
} | [
"func",
"It",
"(",
"text",
"string",
",",
"body",
"interface",
"{",
"}",
",",
"timeout",
"...",
"float64",
")",
"bool",
"{",
"globalSuite",
".",
"PushItNode",
"(",
"text",
",",
"body",
",",
"types",
".",
"FlagTypeNone",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"parseTimeout",
"(",
"timeout",
"...",
")",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //It blocks contain your test code and assertions. You cannot nest any other Ginkgo blocks
//within an It block.
//
//Ginkgo will normally run It blocks synchronously. To perform asynchronous tests, pass a
//function that accepts a Done channel. When you do this, you can also provide an optional timeout. | [
"It",
"blocks",
"contain",
"your",
"test",
"code",
"and",
"assertions",
".",
"You",
"cannot",
"nest",
"any",
"other",
"Ginkgo",
"blocks",
"within",
"an",
"It",
"block",
".",
"Ginkgo",
"will",
"normally",
"run",
"It",
"blocks",
"synchronously",
".",
"To",
"perform",
"asynchronous",
"tests",
"pass",
"a",
"function",
"that",
"accepts",
"a",
"Done",
"channel",
".",
"When",
"you",
"do",
"this",
"you",
"can",
"also",
"provide",
"an",
"optional",
"timeout",
"."
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L374-L377 | train |
onsi/ginkgo | ginkgo_dsl.go | FIt | func FIt(text string, body interface{}, timeout ...float64) bool {
globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...))
return true
} | go | func FIt(text string, body interface{}, timeout ...float64) bool {
globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...))
return true
} | [
"func",
"FIt",
"(",
"text",
"string",
",",
"body",
"interface",
"{",
"}",
",",
"timeout",
"...",
"float64",
")",
"bool",
"{",
"globalSuite",
".",
"PushItNode",
"(",
"text",
",",
"body",
",",
"types",
".",
"FlagTypeFocused",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"parseTimeout",
"(",
"timeout",
"...",
")",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //You can focus individual Its using FIt | [
"You",
"can",
"focus",
"individual",
"Its",
"using",
"FIt"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L380-L383 | train |
onsi/ginkgo | ginkgo_dsl.go | PIt | func PIt(text string, _ ...interface{}) bool {
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
return true
} | go | func PIt(text string, _ ...interface{}) bool {
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
return true
} | [
"func",
"PIt",
"(",
"text",
"string",
",",
"_",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"globalSuite",
".",
"PushItNode",
"(",
"text",
",",
"func",
"(",
")",
"{",
"}",
",",
"types",
".",
"FlagTypePending",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"0",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //You can mark Its as pending using PIt | [
"You",
"can",
"mark",
"Its",
"as",
"pending",
"using",
"PIt"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L386-L389 | train |
onsi/ginkgo | ginkgo_dsl.go | PSpecify | func PSpecify(text string, is ...interface{}) bool {
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
return true
} | go | func PSpecify(text string, is ...interface{}) bool {
globalSuite.PushItNode(text, func() {}, types.FlagTypePending, codelocation.New(1), 0)
return true
} | [
"func",
"PSpecify",
"(",
"text",
"string",
",",
"is",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"globalSuite",
".",
"PushItNode",
"(",
"text",
",",
"func",
"(",
")",
"{",
"}",
",",
"types",
".",
"FlagTypePending",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"0",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //You can mark Specifys as pending using PSpecify | [
"You",
"can",
"mark",
"Specifys",
"as",
"pending",
"using",
"PSpecify"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L412-L415 | train |
onsi/ginkgo | ginkgo_dsl.go | FMeasure | func FMeasure(text string, body interface{}, samples int) bool {
globalSuite.PushMeasureNode(text, body, types.FlagTypeFocused, codelocation.New(1), samples)
return true
} | go | func FMeasure(text string, body interface{}, samples int) bool {
globalSuite.PushMeasureNode(text, body, types.FlagTypeFocused, codelocation.New(1), samples)
return true
} | [
"func",
"FMeasure",
"(",
"text",
"string",
",",
"body",
"interface",
"{",
"}",
",",
"samples",
"int",
")",
"bool",
"{",
"globalSuite",
".",
"PushMeasureNode",
"(",
"text",
",",
"body",
",",
"types",
".",
"FlagTypeFocused",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"samples",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //You can focus individual Measures using FMeasure | [
"You",
"can",
"focus",
"individual",
"Measures",
"using",
"FMeasure"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L455-L458 | train |
onsi/ginkgo | ginkgo_dsl.go | PMeasure | func PMeasure(text string, _ ...interface{}) bool {
globalSuite.PushMeasureNode(text, func(b Benchmarker) {}, types.FlagTypePending, codelocation.New(1), 0)
return true
} | go | func PMeasure(text string, _ ...interface{}) bool {
globalSuite.PushMeasureNode(text, func(b Benchmarker) {}, types.FlagTypePending, codelocation.New(1), 0)
return true
} | [
"func",
"PMeasure",
"(",
"text",
"string",
",",
"_",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"globalSuite",
".",
"PushMeasureNode",
"(",
"text",
",",
"func",
"(",
"b",
"Benchmarker",
")",
"{",
"}",
",",
"types",
".",
"FlagTypePending",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"0",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //You can mark Measurements as pending using PMeasure | [
"You",
"can",
"mark",
"Measurements",
"as",
"pending",
"using",
"PMeasure"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L461-L464 | train |
onsi/ginkgo | ginkgo_dsl.go | BeforeEach | func BeforeEach(body interface{}, timeout ...float64) bool {
globalSuite.PushBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...))
return true
} | go | func BeforeEach(body interface{}, timeout ...float64) bool {
globalSuite.PushBeforeEachNode(body, codelocation.New(1), parseTimeout(timeout...))
return true
} | [
"func",
"BeforeEach",
"(",
"body",
"interface",
"{",
"}",
",",
"timeout",
"...",
"float64",
")",
"bool",
"{",
"globalSuite",
".",
"PushBeforeEachNode",
"(",
"body",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"parseTimeout",
"(",
"timeout",
"...",
")",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //BeforeEach blocks are run before It blocks. When multiple BeforeEach blocks are defined in nested
//Describe and Context blocks the outermost BeforeEach blocks are run first.
//
//Like It blocks, BeforeEach blocks can be made asynchronous by providing a body function that accepts
//a Done channel | [
"BeforeEach",
"blocks",
"are",
"run",
"before",
"It",
"blocks",
".",
"When",
"multiple",
"BeforeEach",
"blocks",
"are",
"defined",
"in",
"nested",
"Describe",
"and",
"Context",
"blocks",
"the",
"outermost",
"BeforeEach",
"blocks",
"are",
"run",
"first",
".",
"Like",
"It",
"blocks",
"BeforeEach",
"blocks",
"can",
"be",
"made",
"asynchronous",
"by",
"providing",
"a",
"body",
"function",
"that",
"accepts",
"a",
"Done",
"channel"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L578-L581 | train |
onsi/ginkgo | ginkgo_dsl.go | AfterEach | func AfterEach(body interface{}, timeout ...float64) bool {
globalSuite.PushAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...))
return true
} | go | func AfterEach(body interface{}, timeout ...float64) bool {
globalSuite.PushAfterEachNode(body, codelocation.New(1), parseTimeout(timeout...))
return true
} | [
"func",
"AfterEach",
"(",
"body",
"interface",
"{",
"}",
",",
"timeout",
"...",
"float64",
")",
"bool",
"{",
"globalSuite",
".",
"PushAfterEachNode",
"(",
"body",
",",
"codelocation",
".",
"New",
"(",
"1",
")",
",",
"parseTimeout",
"(",
"timeout",
"...",
")",
")",
"\n",
"return",
"true",
"\n",
"}"
] | //AfterEach blocks are run after It blocks. When multiple AfterEach blocks are defined in nested
//Describe and Context blocks the innermost AfterEach blocks are run first.
//
//Like It blocks, AfterEach blocks can be made asynchronous by providing a body function that accepts
//a Done channel | [
"AfterEach",
"blocks",
"are",
"run",
"after",
"It",
"blocks",
".",
"When",
"multiple",
"AfterEach",
"blocks",
"are",
"defined",
"in",
"nested",
"Describe",
"and",
"Context",
"blocks",
"the",
"innermost",
"AfterEach",
"blocks",
"are",
"run",
"first",
".",
"Like",
"It",
"blocks",
"AfterEach",
"blocks",
"can",
"be",
"made",
"asynchronous",
"by",
"providing",
"a",
"body",
"function",
"that",
"accepts",
"a",
"Done",
"channel"
] | eea6ad008b96acdaa524f5b409513bf062b500ad | https://github.com/onsi/ginkgo/blob/eea6ad008b96acdaa524f5b409513bf062b500ad/ginkgo_dsl.go#L608-L611 | train |
docker/libnetwork | drivers/macvlan/macvlan_store.go | initStore | func (d *driver) initStore(option map[string]interface{}) error {
if data, ok := option[netlabel.LocalKVClient]; ok {
var err error
dsc, ok := data.(discoverapi.DatastoreConfigData)
if !ok {
return types.InternalErrorf("incorrect data in datastore configuration: %v", data)
}
d.store, err = datastore.NewDataStoreFromConfig(dsc)
if err != nil {
return types.InternalErrorf("macvlan driver failed to initialize data store: %v", err)
}
return d.populateNetworks()
}
return nil
} | go | func (d *driver) initStore(option map[string]interface{}) error {
if data, ok := option[netlabel.LocalKVClient]; ok {
var err error
dsc, ok := data.(discoverapi.DatastoreConfigData)
if !ok {
return types.InternalErrorf("incorrect data in datastore configuration: %v", data)
}
d.store, err = datastore.NewDataStoreFromConfig(dsc)
if err != nil {
return types.InternalErrorf("macvlan driver failed to initialize data store: %v", err)
}
return d.populateNetworks()
}
return nil
} | [
"func",
"(",
"d",
"*",
"driver",
")",
"initStore",
"(",
"option",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"data",
",",
"ok",
":=",
"option",
"[",
"netlabel",
".",
"LocalKVClient",
"]",
";",
"ok",
"{",
"var",
"err",
"error",
"\n",
"dsc",
",",
"ok",
":=",
"data",
".",
"(",
"discoverapi",
".",
"DatastoreConfigData",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"data",
")",
"\n",
"}",
"\n",
"d",
".",
"store",
",",
"err",
"=",
"datastore",
".",
"NewDataStoreFromConfig",
"(",
"dsc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"types",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"populateNetworks",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // initStore drivers are responsible for caching their own persistent state | [
"initStore",
"drivers",
"are",
"responsible",
"for",
"caching",
"their",
"own",
"persistent",
"state"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_store.go#L46-L62 | train |
docker/libnetwork | drivers/macvlan/macvlan_store.go | populateNetworks | func (d *driver) populateNetworks() error {
kvol, err := d.store.List(datastore.Key(macvlanPrefix), &configuration{})
if err != nil && err != datastore.ErrKeyNotFound {
return fmt.Errorf("failed to get macvlan network configurations from store: %v", err)
}
// If empty it simply means no macvlan networks have been created yet
if err == datastore.ErrKeyNotFound {
return nil
}
for _, kvo := range kvol {
config := kvo.(*configuration)
if err = d.createNetwork(config); err != nil {
logrus.Warnf("Could not create macvlan network for id %s from persistent state", config.ID)
}
}
return nil
} | go | func (d *driver) populateNetworks() error {
kvol, err := d.store.List(datastore.Key(macvlanPrefix), &configuration{})
if err != nil && err != datastore.ErrKeyNotFound {
return fmt.Errorf("failed to get macvlan network configurations from store: %v", err)
}
// If empty it simply means no macvlan networks have been created yet
if err == datastore.ErrKeyNotFound {
return nil
}
for _, kvo := range kvol {
config := kvo.(*configuration)
if err = d.createNetwork(config); err != nil {
logrus.Warnf("Could not create macvlan network for id %s from persistent state", config.ID)
}
}
return nil
} | [
"func",
"(",
"d",
"*",
"driver",
")",
"populateNetworks",
"(",
")",
"error",
"{",
"kvol",
",",
"err",
":=",
"d",
".",
"store",
".",
"List",
"(",
"datastore",
".",
"Key",
"(",
"macvlanPrefix",
")",
",",
"&",
"configuration",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"datastore",
".",
"ErrKeyNotFound",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// If empty it simply means no macvlan networks have been created yet",
"if",
"err",
"==",
"datastore",
".",
"ErrKeyNotFound",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"kvo",
":=",
"range",
"kvol",
"{",
"config",
":=",
"kvo",
".",
"(",
"*",
"configuration",
")",
"\n",
"if",
"err",
"=",
"d",
".",
"createNetwork",
"(",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"config",
".",
"ID",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // populateNetworks is invoked at driver init to recreate persistently stored networks | [
"populateNetworks",
"is",
"invoked",
"at",
"driver",
"init",
"to",
"recreate",
"persistently",
"stored",
"networks"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_store.go#L65-L82 | train |
docker/libnetwork | drivers/ipvlan/ipvlan_endpoint.go | CreateEndpoint | func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
epOptions map[string]interface{}) error {
defer osl.InitOSContext()()
if err := validateID(nid, eid); err != nil {
return err
}
n, err := d.getNetwork(nid)
if err != nil {
return fmt.Errorf("network id %q not found", nid)
}
if ifInfo.MacAddress() != nil {
return fmt.Errorf("%s interfaces do not support custom mac address assignment", ipvlanType)
}
ep := &endpoint{
id: eid,
nid: nid,
addr: ifInfo.Address(),
addrv6: ifInfo.AddressIPv6(),
}
if ep.addr == nil {
return fmt.Errorf("create endpoint was not passed an IP address")
}
// disallow port mapping -p
if opt, ok := epOptions[netlabel.PortMap]; ok {
if _, ok := opt.([]types.PortBinding); ok {
if len(opt.([]types.PortBinding)) > 0 {
logrus.Warnf("%s driver does not support port mappings", ipvlanType)
}
}
}
// disallow port exposure --expose
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
if _, ok := opt.([]types.TransportPort); ok {
if len(opt.([]types.TransportPort)) > 0 {
logrus.Warnf("%s driver does not support port exposures", ipvlanType)
}
}
}
if err := d.storeUpdate(ep); err != nil {
return fmt.Errorf("failed to save ipvlan endpoint %.7s to store: %v", ep.id, err)
}
n.addEndpoint(ep)
return nil
} | go | func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
epOptions map[string]interface{}) error {
defer osl.InitOSContext()()
if err := validateID(nid, eid); err != nil {
return err
}
n, err := d.getNetwork(nid)
if err != nil {
return fmt.Errorf("network id %q not found", nid)
}
if ifInfo.MacAddress() != nil {
return fmt.Errorf("%s interfaces do not support custom mac address assignment", ipvlanType)
}
ep := &endpoint{
id: eid,
nid: nid,
addr: ifInfo.Address(),
addrv6: ifInfo.AddressIPv6(),
}
if ep.addr == nil {
return fmt.Errorf("create endpoint was not passed an IP address")
}
// disallow port mapping -p
if opt, ok := epOptions[netlabel.PortMap]; ok {
if _, ok := opt.([]types.PortBinding); ok {
if len(opt.([]types.PortBinding)) > 0 {
logrus.Warnf("%s driver does not support port mappings", ipvlanType)
}
}
}
// disallow port exposure --expose
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
if _, ok := opt.([]types.TransportPort); ok {
if len(opt.([]types.TransportPort)) > 0 {
logrus.Warnf("%s driver does not support port exposures", ipvlanType)
}
}
}
if err := d.storeUpdate(ep); err != nil {
return fmt.Errorf("failed to save ipvlan endpoint %.7s to store: %v", ep.id, err)
}
n.addEndpoint(ep)
return nil
} | [
"func",
"(",
"d",
"*",
"driver",
")",
"CreateEndpoint",
"(",
"nid",
",",
"eid",
"string",
",",
"ifInfo",
"driverapi",
".",
"InterfaceInfo",
",",
"epOptions",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"defer",
"osl",
".",
"InitOSContext",
"(",
")",
"(",
")",
"\n\n",
"if",
"err",
":=",
"validateID",
"(",
"nid",
",",
"eid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"d",
".",
"getNetwork",
"(",
"nid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nid",
")",
"\n",
"}",
"\n",
"if",
"ifInfo",
".",
"MacAddress",
"(",
")",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ipvlanType",
")",
"\n",
"}",
"\n",
"ep",
":=",
"&",
"endpoint",
"{",
"id",
":",
"eid",
",",
"nid",
":",
"nid",
",",
"addr",
":",
"ifInfo",
".",
"Address",
"(",
")",
",",
"addrv6",
":",
"ifInfo",
".",
"AddressIPv6",
"(",
")",
",",
"}",
"\n",
"if",
"ep",
".",
"addr",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// disallow port mapping -p",
"if",
"opt",
",",
"ok",
":=",
"epOptions",
"[",
"netlabel",
".",
"PortMap",
"]",
";",
"ok",
"{",
"if",
"_",
",",
"ok",
":=",
"opt",
".",
"(",
"[",
"]",
"types",
".",
"PortBinding",
")",
";",
"ok",
"{",
"if",
"len",
"(",
"opt",
".",
"(",
"[",
"]",
"types",
".",
"PortBinding",
")",
")",
">",
"0",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"ipvlanType",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// disallow port exposure --expose",
"if",
"opt",
",",
"ok",
":=",
"epOptions",
"[",
"netlabel",
".",
"ExposedPorts",
"]",
";",
"ok",
"{",
"if",
"_",
",",
"ok",
":=",
"opt",
".",
"(",
"[",
"]",
"types",
".",
"TransportPort",
")",
";",
"ok",
"{",
"if",
"len",
"(",
"opt",
".",
"(",
"[",
"]",
"types",
".",
"TransportPort",
")",
")",
">",
"0",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"ipvlanType",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"d",
".",
"storeUpdate",
"(",
"ep",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ep",
".",
"id",
",",
"err",
")",
"\n",
"}",
"\n\n",
"n",
".",
"addEndpoint",
"(",
"ep",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CreateEndpoint assigns the mac, ip and endpoint id for the new container | [
"CreateEndpoint",
"assigns",
"the",
"mac",
"ip",
"and",
"endpoint",
"id",
"for",
"the",
"new",
"container"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_endpoint.go#L15-L62 | train |
docker/libnetwork | drivers/ipvlan/ipvlan_endpoint.go | DeleteEndpoint | func (d *driver) DeleteEndpoint(nid, eid string) error {
defer osl.InitOSContext()()
if err := validateID(nid, eid); err != nil {
return err
}
n := d.network(nid)
if n == nil {
return fmt.Errorf("network id %q not found", nid)
}
ep := n.endpoint(eid)
if ep == nil {
return fmt.Errorf("endpoint id %q not found", eid)
}
if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil {
if err := ns.NlHandle().LinkDel(link); err != nil {
logrus.WithError(err).Warnf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id)
}
}
if err := d.storeDelete(ep); err != nil {
logrus.Warnf("Failed to remove ipvlan endpoint %.7s from store: %v", ep.id, err)
}
n.deleteEndpoint(ep.id)
return nil
} | go | func (d *driver) DeleteEndpoint(nid, eid string) error {
defer osl.InitOSContext()()
if err := validateID(nid, eid); err != nil {
return err
}
n := d.network(nid)
if n == nil {
return fmt.Errorf("network id %q not found", nid)
}
ep := n.endpoint(eid)
if ep == nil {
return fmt.Errorf("endpoint id %q not found", eid)
}
if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil {
if err := ns.NlHandle().LinkDel(link); err != nil {
logrus.WithError(err).Warnf("Failed to delete interface (%s)'s link on endpoint (%s) delete", ep.srcName, ep.id)
}
}
if err := d.storeDelete(ep); err != nil {
logrus.Warnf("Failed to remove ipvlan endpoint %.7s from store: %v", ep.id, err)
}
n.deleteEndpoint(ep.id)
return nil
} | [
"func",
"(",
"d",
"*",
"driver",
")",
"DeleteEndpoint",
"(",
"nid",
",",
"eid",
"string",
")",
"error",
"{",
"defer",
"osl",
".",
"InitOSContext",
"(",
")",
"(",
")",
"\n",
"if",
"err",
":=",
"validateID",
"(",
"nid",
",",
"eid",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"n",
":=",
"d",
".",
"network",
"(",
"nid",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nid",
")",
"\n",
"}",
"\n",
"ep",
":=",
"n",
".",
"endpoint",
"(",
"eid",
")",
"\n",
"if",
"ep",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"eid",
")",
"\n",
"}",
"\n",
"if",
"link",
",",
"err",
":=",
"ns",
".",
"NlHandle",
"(",
")",
".",
"LinkByName",
"(",
"ep",
".",
"srcName",
")",
";",
"err",
"==",
"nil",
"{",
"if",
"err",
":=",
"ns",
".",
"NlHandle",
"(",
")",
".",
"LinkDel",
"(",
"link",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"ep",
".",
"srcName",
",",
"ep",
".",
"id",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"d",
".",
"storeDelete",
"(",
"ep",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"ep",
".",
"id",
",",
"err",
")",
"\n",
"}",
"\n",
"n",
".",
"deleteEndpoint",
"(",
"ep",
".",
"id",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // DeleteEndpoint remove the endpoint and associated netlink interface | [
"DeleteEndpoint",
"remove",
"the",
"endpoint",
"and",
"associated",
"netlink",
"interface"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/ipvlan/ipvlan_endpoint.go#L65-L89 | train |
docker/libnetwork | osl/kernel/knobs_linux.go | ApplyOSTweaks | func ApplyOSTweaks(osConfig map[string]*OSValue) {
for k, v := range osConfig {
// read the existing property from disk
oldv, err := readSystemProperty(k)
if err != nil {
logrus.WithError(err).Errorf("error reading the kernel parameter %s", k)
continue
}
if propertyIsValid(oldv, v.Value, v.CheckFn) {
// write new prop value to disk
if err := writeSystemProperty(k, v.Value); err != nil {
logrus.WithError(err).Errorf("error setting the kernel parameter %s = %s, (leaving as %s)", k, v.Value, oldv)
continue
}
logrus.Debugf("updated kernel parameter %s = %s (was %s)", k, v.Value, oldv)
}
}
} | go | func ApplyOSTweaks(osConfig map[string]*OSValue) {
for k, v := range osConfig {
// read the existing property from disk
oldv, err := readSystemProperty(k)
if err != nil {
logrus.WithError(err).Errorf("error reading the kernel parameter %s", k)
continue
}
if propertyIsValid(oldv, v.Value, v.CheckFn) {
// write new prop value to disk
if err := writeSystemProperty(k, v.Value); err != nil {
logrus.WithError(err).Errorf("error setting the kernel parameter %s = %s, (leaving as %s)", k, v.Value, oldv)
continue
}
logrus.Debugf("updated kernel parameter %s = %s (was %s)", k, v.Value, oldv)
}
}
} | [
"func",
"ApplyOSTweaks",
"(",
"osConfig",
"map",
"[",
"string",
"]",
"*",
"OSValue",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"osConfig",
"{",
"// read the existing property from disk",
"oldv",
",",
"err",
":=",
"readSystemProperty",
"(",
"k",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"if",
"propertyIsValid",
"(",
"oldv",
",",
"v",
".",
"Value",
",",
"v",
".",
"CheckFn",
")",
"{",
"// write new prop value to disk",
"if",
"err",
":=",
"writeSystemProperty",
"(",
"k",
",",
"v",
".",
"Value",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
",",
"v",
".",
"Value",
",",
"oldv",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"k",
",",
"v",
".",
"Value",
",",
"oldv",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ApplyOSTweaks applies the configuration values passed as arguments | [
"ApplyOSTweaks",
"applies",
"the",
"configuration",
"values",
"passed",
"as",
"arguments"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/osl/kernel/knobs_linux.go#L29-L47 | train |
docker/libnetwork | idm/idm.go | GetID | func (i *Idm) GetID(serial bool) (uint64, error) {
if i.handle == nil {
return 0, errors.New("ID set is not initialized")
}
ordinal, err := i.handle.SetAny(serial)
return i.start + ordinal, err
} | go | func (i *Idm) GetID(serial bool) (uint64, error) {
if i.handle == nil {
return 0, errors.New("ID set is not initialized")
}
ordinal, err := i.handle.SetAny(serial)
return i.start + ordinal, err
} | [
"func",
"(",
"i",
"*",
"Idm",
")",
"GetID",
"(",
"serial",
"bool",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"if",
"i",
".",
"handle",
"==",
"nil",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ordinal",
",",
"err",
":=",
"i",
".",
"handle",
".",
"SetAny",
"(",
"serial",
")",
"\n",
"return",
"i",
".",
"start",
"+",
"ordinal",
",",
"err",
"\n",
"}"
] | // GetID returns the first available id in the set | [
"GetID",
"returns",
"the",
"first",
"available",
"id",
"in",
"the",
"set"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L37-L43 | train |
docker/libnetwork | idm/idm.go | GetSpecificID | func (i *Idm) GetSpecificID(id uint64) error {
if i.handle == nil {
return errors.New("ID set is not initialized")
}
if id < i.start || id > i.end {
return errors.New("Requested id does not belong to the set")
}
return i.handle.Set(id - i.start)
} | go | func (i *Idm) GetSpecificID(id uint64) error {
if i.handle == nil {
return errors.New("ID set is not initialized")
}
if id < i.start || id > i.end {
return errors.New("Requested id does not belong to the set")
}
return i.handle.Set(id - i.start)
} | [
"func",
"(",
"i",
"*",
"Idm",
")",
"GetSpecificID",
"(",
"id",
"uint64",
")",
"error",
"{",
"if",
"i",
".",
"handle",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"id",
"<",
"i",
".",
"start",
"||",
"id",
">",
"i",
".",
"end",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"i",
".",
"handle",
".",
"Set",
"(",
"id",
"-",
"i",
".",
"start",
")",
"\n",
"}"
] | // GetSpecificID tries to reserve the specified id | [
"GetSpecificID",
"tries",
"to",
"reserve",
"the",
"specified",
"id"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L46-L56 | train |
docker/libnetwork | idm/idm.go | Release | func (i *Idm) Release(id uint64) {
i.handle.Unset(id - i.start)
} | go | func (i *Idm) Release(id uint64) {
i.handle.Unset(id - i.start)
} | [
"func",
"(",
"i",
"*",
"Idm",
")",
"Release",
"(",
"id",
"uint64",
")",
"{",
"i",
".",
"handle",
".",
"Unset",
"(",
"id",
"-",
"i",
".",
"start",
")",
"\n",
"}"
] | // Release releases the specified id | [
"Release",
"releases",
"the",
"specified",
"id"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/idm/idm.go#L74-L76 | train |
docker/libnetwork | types/types.go | Equal | func (t *TransportPort) Equal(o *TransportPort) bool {
if t == o {
return true
}
if o == nil {
return false
}
if t.Proto != o.Proto || t.Port != o.Port {
return false
}
return true
} | go | func (t *TransportPort) Equal(o *TransportPort) bool {
if t == o {
return true
}
if o == nil {
return false
}
if t.Proto != o.Proto || t.Port != o.Port {
return false
}
return true
} | [
"func",
"(",
"t",
"*",
"TransportPort",
")",
"Equal",
"(",
"o",
"*",
"TransportPort",
")",
"bool",
"{",
"if",
"t",
"==",
"o",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"o",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"Proto",
"!=",
"o",
".",
"Proto",
"||",
"t",
".",
"Port",
"!=",
"o",
".",
"Port",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // Equal checks if this instance of Transportport is equal to the passed one | [
"Equal",
"checks",
"if",
"this",
"instance",
"of",
"Transportport",
"is",
"equal",
"to",
"the",
"passed",
"one"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L45-L59 | train |
docker/libnetwork | types/types.go | GetCopy | func (t *TransportPort) GetCopy() TransportPort {
return TransportPort{Proto: t.Proto, Port: t.Port}
} | go | func (t *TransportPort) GetCopy() TransportPort {
return TransportPort{Proto: t.Proto, Port: t.Port}
} | [
"func",
"(",
"t",
"*",
"TransportPort",
")",
"GetCopy",
"(",
")",
"TransportPort",
"{",
"return",
"TransportPort",
"{",
"Proto",
":",
"t",
".",
"Proto",
",",
"Port",
":",
"t",
".",
"Port",
"}",
"\n",
"}"
] | // GetCopy returns a copy of this TransportPort structure instance | [
"GetCopy",
"returns",
"a",
"copy",
"of",
"this",
"TransportPort",
"structure",
"instance"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L62-L64 | train |
docker/libnetwork | types/types.go | String | func (t *TransportPort) String() string {
return fmt.Sprintf("%s/%d", t.Proto.String(), t.Port)
} | go | func (t *TransportPort) String() string {
return fmt.Sprintf("%s/%d", t.Proto.String(), t.Port)
} | [
"func",
"(",
"t",
"*",
"TransportPort",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"Proto",
".",
"String",
"(",
")",
",",
"t",
".",
"Port",
")",
"\n",
"}"
] | // String returns the TransportPort structure in string form | [
"String",
"returns",
"the",
"TransportPort",
"structure",
"in",
"string",
"form"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L67-L69 | train |
docker/libnetwork | types/types.go | FromString | func (t *TransportPort) FromString(s string) error {
ps := strings.Split(s, "/")
if len(ps) == 2 {
t.Proto = ParseProtocol(ps[0])
if p, err := strconv.ParseUint(ps[1], 10, 16); err == nil {
t.Port = uint16(p)
return nil
}
}
return BadRequestErrorf("invalid format for transport port: %s", s)
} | go | func (t *TransportPort) FromString(s string) error {
ps := strings.Split(s, "/")
if len(ps) == 2 {
t.Proto = ParseProtocol(ps[0])
if p, err := strconv.ParseUint(ps[1], 10, 16); err == nil {
t.Port = uint16(p)
return nil
}
}
return BadRequestErrorf("invalid format for transport port: %s", s)
} | [
"func",
"(",
"t",
"*",
"TransportPort",
")",
"FromString",
"(",
"s",
"string",
")",
"error",
"{",
"ps",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"ps",
")",
"==",
"2",
"{",
"t",
".",
"Proto",
"=",
"ParseProtocol",
"(",
"ps",
"[",
"0",
"]",
")",
"\n",
"if",
"p",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"ps",
"[",
"1",
"]",
",",
"10",
",",
"16",
")",
";",
"err",
"==",
"nil",
"{",
"t",
".",
"Port",
"=",
"uint16",
"(",
"p",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}"
] | // FromString reads the TransportPort structure from string | [
"FromString",
"reads",
"the",
"TransportPort",
"structure",
"from",
"string"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L72-L82 | train |
docker/libnetwork | types/types.go | HostAddr | func (p PortBinding) HostAddr() (net.Addr, error) {
switch p.Proto {
case UDP:
return &net.UDPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil
case TCP:
return &net.TCPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil
case SCTP:
return &sctp.SCTPAddr{IP: []net.IP{p.HostIP}, Port: int(p.HostPort)}, nil
default:
return nil, ErrInvalidProtocolBinding(p.Proto.String())
}
} | go | func (p PortBinding) HostAddr() (net.Addr, error) {
switch p.Proto {
case UDP:
return &net.UDPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil
case TCP:
return &net.TCPAddr{IP: p.HostIP, Port: int(p.HostPort)}, nil
case SCTP:
return &sctp.SCTPAddr{IP: []net.IP{p.HostIP}, Port: int(p.HostPort)}, nil
default:
return nil, ErrInvalidProtocolBinding(p.Proto.String())
}
} | [
"func",
"(",
"p",
"PortBinding",
")",
"HostAddr",
"(",
")",
"(",
"net",
".",
"Addr",
",",
"error",
")",
"{",
"switch",
"p",
".",
"Proto",
"{",
"case",
"UDP",
":",
"return",
"&",
"net",
".",
"UDPAddr",
"{",
"IP",
":",
"p",
".",
"HostIP",
",",
"Port",
":",
"int",
"(",
"p",
".",
"HostPort",
")",
"}",
",",
"nil",
"\n",
"case",
"TCP",
":",
"return",
"&",
"net",
".",
"TCPAddr",
"{",
"IP",
":",
"p",
".",
"HostIP",
",",
"Port",
":",
"int",
"(",
"p",
".",
"HostPort",
")",
"}",
",",
"nil",
"\n",
"case",
"SCTP",
":",
"return",
"&",
"sctp",
".",
"SCTPAddr",
"{",
"IP",
":",
"[",
"]",
"net",
".",
"IP",
"{",
"p",
".",
"HostIP",
"}",
",",
"Port",
":",
"int",
"(",
"p",
".",
"HostPort",
")",
"}",
",",
"nil",
"\n",
"default",
":",
"return",
"nil",
",",
"ErrInvalidProtocolBinding",
"(",
"p",
".",
"Proto",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // HostAddr returns the host side transport address | [
"HostAddr",
"returns",
"the",
"host",
"side",
"transport",
"address"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L95-L106 | train |
docker/libnetwork | types/types.go | GetCopy | func (p *PortBinding) GetCopy() PortBinding {
return PortBinding{
Proto: p.Proto,
IP: GetIPCopy(p.IP),
Port: p.Port,
HostIP: GetIPCopy(p.HostIP),
HostPort: p.HostPort,
HostPortEnd: p.HostPortEnd,
}
} | go | func (p *PortBinding) GetCopy() PortBinding {
return PortBinding{
Proto: p.Proto,
IP: GetIPCopy(p.IP),
Port: p.Port,
HostIP: GetIPCopy(p.HostIP),
HostPort: p.HostPort,
HostPortEnd: p.HostPortEnd,
}
} | [
"func",
"(",
"p",
"*",
"PortBinding",
")",
"GetCopy",
"(",
")",
"PortBinding",
"{",
"return",
"PortBinding",
"{",
"Proto",
":",
"p",
".",
"Proto",
",",
"IP",
":",
"GetIPCopy",
"(",
"p",
".",
"IP",
")",
",",
"Port",
":",
"p",
".",
"Port",
",",
"HostIP",
":",
"GetIPCopy",
"(",
"p",
".",
"HostIP",
")",
",",
"HostPort",
":",
"p",
".",
"HostPort",
",",
"HostPortEnd",
":",
"p",
".",
"HostPortEnd",
",",
"}",
"\n",
"}"
] | // GetCopy returns a copy of this PortBinding structure instance | [
"GetCopy",
"returns",
"a",
"copy",
"of",
"this",
"PortBinding",
"structure",
"instance"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L123-L132 | train |
docker/libnetwork | types/types.go | String | func (p *PortBinding) String() string {
ret := fmt.Sprintf("%s/", p.Proto)
if p.IP != nil {
ret += p.IP.String()
}
ret = fmt.Sprintf("%s:%d/", ret, p.Port)
if p.HostIP != nil {
ret += p.HostIP.String()
}
ret = fmt.Sprintf("%s:%d", ret, p.HostPort)
return ret
} | go | func (p *PortBinding) String() string {
ret := fmt.Sprintf("%s/", p.Proto)
if p.IP != nil {
ret += p.IP.String()
}
ret = fmt.Sprintf("%s:%d/", ret, p.Port)
if p.HostIP != nil {
ret += p.HostIP.String()
}
ret = fmt.Sprintf("%s:%d", ret, p.HostPort)
return ret
} | [
"func",
"(",
"p",
"*",
"PortBinding",
")",
"String",
"(",
")",
"string",
"{",
"ret",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"Proto",
")",
"\n",
"if",
"p",
".",
"IP",
"!=",
"nil",
"{",
"ret",
"+=",
"p",
".",
"IP",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"ret",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ret",
",",
"p",
".",
"Port",
")",
"\n",
"if",
"p",
".",
"HostIP",
"!=",
"nil",
"{",
"ret",
"+=",
"p",
".",
"HostIP",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"ret",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ret",
",",
"p",
".",
"HostPort",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // String returns the PortBinding structure in string form | [
"String",
"returns",
"the",
"PortBinding",
"structure",
"in",
"string",
"form"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L135-L146 | train |
docker/libnetwork | types/types.go | Equal | func (p *PortBinding) Equal(o *PortBinding) bool {
if p == o {
return true
}
if o == nil {
return false
}
if p.Proto != o.Proto || p.Port != o.Port ||
p.HostPort != o.HostPort || p.HostPortEnd != o.HostPortEnd {
return false
}
if p.IP != nil {
if !p.IP.Equal(o.IP) {
return false
}
} else {
if o.IP != nil {
return false
}
}
if p.HostIP != nil {
if !p.HostIP.Equal(o.HostIP) {
return false
}
} else {
if o.HostIP != nil {
return false
}
}
return true
} | go | func (p *PortBinding) Equal(o *PortBinding) bool {
if p == o {
return true
}
if o == nil {
return false
}
if p.Proto != o.Proto || p.Port != o.Port ||
p.HostPort != o.HostPort || p.HostPortEnd != o.HostPortEnd {
return false
}
if p.IP != nil {
if !p.IP.Equal(o.IP) {
return false
}
} else {
if o.IP != nil {
return false
}
}
if p.HostIP != nil {
if !p.HostIP.Equal(o.HostIP) {
return false
}
} else {
if o.HostIP != nil {
return false
}
}
return true
} | [
"func",
"(",
"p",
"*",
"PortBinding",
")",
"Equal",
"(",
"o",
"*",
"PortBinding",
")",
"bool",
"{",
"if",
"p",
"==",
"o",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"o",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"Proto",
"!=",
"o",
".",
"Proto",
"||",
"p",
".",
"Port",
"!=",
"o",
".",
"Port",
"||",
"p",
".",
"HostPort",
"!=",
"o",
".",
"HostPort",
"||",
"p",
".",
"HostPortEnd",
"!=",
"o",
".",
"HostPortEnd",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"IP",
"!=",
"nil",
"{",
"if",
"!",
"p",
".",
"IP",
".",
"Equal",
"(",
"o",
".",
"IP",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"o",
".",
"IP",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"HostIP",
"!=",
"nil",
"{",
"if",
"!",
"p",
".",
"HostIP",
".",
"Equal",
"(",
"o",
".",
"HostIP",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"o",
".",
"HostIP",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // Equal checks if this instance of PortBinding is equal to the passed one | [
"Equal",
"checks",
"if",
"this",
"instance",
"of",
"PortBinding",
"is",
"equal",
"to",
"the",
"passed",
"one"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L194-L229 | train |
docker/libnetwork | types/types.go | ParseProtocol | func ParseProtocol(s string) Protocol {
switch strings.ToLower(s) {
case "icmp":
return ICMP
case "udp":
return UDP
case "tcp":
return TCP
case "sctp":
return SCTP
default:
return 0
}
} | go | func ParseProtocol(s string) Protocol {
switch strings.ToLower(s) {
case "icmp":
return ICMP
case "udp":
return UDP
case "tcp":
return TCP
case "sctp":
return SCTP
default:
return 0
}
} | [
"func",
"ParseProtocol",
"(",
"s",
"string",
")",
"Protocol",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"s",
")",
"{",
"case",
"\"",
"\"",
":",
"return",
"ICMP",
"\n",
"case",
"\"",
"\"",
":",
"return",
"UDP",
"\n",
"case",
"\"",
"\"",
":",
"return",
"TCP",
"\n",
"case",
"\"",
"\"",
":",
"return",
"SCTP",
"\n",
"default",
":",
"return",
"0",
"\n",
"}",
"\n",
"}"
] | // ParseProtocol returns the respective Protocol type for the passed string | [
"ParseProtocol",
"returns",
"the",
"respective",
"Protocol",
"type",
"for",
"the",
"passed",
"string"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L268-L281 | train |
docker/libnetwork | types/types.go | GetMacCopy | func GetMacCopy(from net.HardwareAddr) net.HardwareAddr {
if from == nil {
return nil
}
to := make(net.HardwareAddr, len(from))
copy(to, from)
return to
} | go | func GetMacCopy(from net.HardwareAddr) net.HardwareAddr {
if from == nil {
return nil
}
to := make(net.HardwareAddr, len(from))
copy(to, from)
return to
} | [
"func",
"GetMacCopy",
"(",
"from",
"net",
".",
"HardwareAddr",
")",
"net",
".",
"HardwareAddr",
"{",
"if",
"from",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"to",
":=",
"make",
"(",
"net",
".",
"HardwareAddr",
",",
"len",
"(",
"from",
")",
")",
"\n",
"copy",
"(",
"to",
",",
"from",
")",
"\n",
"return",
"to",
"\n",
"}"
] | // GetMacCopy returns a copy of the passed MAC address | [
"GetMacCopy",
"returns",
"a",
"copy",
"of",
"the",
"passed",
"MAC",
"address"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L284-L291 | train |
docker/libnetwork | types/types.go | GetIPCopy | func GetIPCopy(from net.IP) net.IP {
if from == nil {
return nil
}
to := make(net.IP, len(from))
copy(to, from)
return to
} | go | func GetIPCopy(from net.IP) net.IP {
if from == nil {
return nil
}
to := make(net.IP, len(from))
copy(to, from)
return to
} | [
"func",
"GetIPCopy",
"(",
"from",
"net",
".",
"IP",
")",
"net",
".",
"IP",
"{",
"if",
"from",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"to",
":=",
"make",
"(",
"net",
".",
"IP",
",",
"len",
"(",
"from",
")",
")",
"\n",
"copy",
"(",
"to",
",",
"from",
")",
"\n",
"return",
"to",
"\n",
"}"
] | // GetIPCopy returns a copy of the passed IP address | [
"GetIPCopy",
"returns",
"a",
"copy",
"of",
"the",
"passed",
"IP",
"address"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L294-L301 | train |
docker/libnetwork | types/types.go | GetIPNetCopy | func GetIPNetCopy(from *net.IPNet) *net.IPNet {
if from == nil {
return nil
}
bm := make(net.IPMask, len(from.Mask))
copy(bm, from.Mask)
return &net.IPNet{IP: GetIPCopy(from.IP), Mask: bm}
} | go | func GetIPNetCopy(from *net.IPNet) *net.IPNet {
if from == nil {
return nil
}
bm := make(net.IPMask, len(from.Mask))
copy(bm, from.Mask)
return &net.IPNet{IP: GetIPCopy(from.IP), Mask: bm}
} | [
"func",
"GetIPNetCopy",
"(",
"from",
"*",
"net",
".",
"IPNet",
")",
"*",
"net",
".",
"IPNet",
"{",
"if",
"from",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"bm",
":=",
"make",
"(",
"net",
".",
"IPMask",
",",
"len",
"(",
"from",
".",
"Mask",
")",
")",
"\n",
"copy",
"(",
"bm",
",",
"from",
".",
"Mask",
")",
"\n",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"GetIPCopy",
"(",
"from",
".",
"IP",
")",
",",
"Mask",
":",
"bm",
"}",
"\n",
"}"
] | // GetIPNetCopy returns a copy of the passed IP Network | [
"GetIPNetCopy",
"returns",
"a",
"copy",
"of",
"the",
"passed",
"IP",
"Network"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L304-L311 | train |
docker/libnetwork | types/types.go | GetIPNetCanonical | func GetIPNetCanonical(nw *net.IPNet) *net.IPNet {
if nw == nil {
return nil
}
c := GetIPNetCopy(nw)
c.IP = c.IP.Mask(nw.Mask)
return c
} | go | func GetIPNetCanonical(nw *net.IPNet) *net.IPNet {
if nw == nil {
return nil
}
c := GetIPNetCopy(nw)
c.IP = c.IP.Mask(nw.Mask)
return c
} | [
"func",
"GetIPNetCanonical",
"(",
"nw",
"*",
"net",
".",
"IPNet",
")",
"*",
"net",
".",
"IPNet",
"{",
"if",
"nw",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"c",
":=",
"GetIPNetCopy",
"(",
"nw",
")",
"\n",
"c",
".",
"IP",
"=",
"c",
".",
"IP",
".",
"Mask",
"(",
"nw",
".",
"Mask",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // GetIPNetCanonical returns the canonical form for the passed network | [
"GetIPNetCanonical",
"returns",
"the",
"canonical",
"form",
"for",
"the",
"passed",
"network"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L314-L321 | train |
docker/libnetwork | types/types.go | CompareIPNet | func CompareIPNet(a, b *net.IPNet) bool {
if a == b {
return true
}
if a == nil || b == nil {
return false
}
return a.IP.Equal(b.IP) && bytes.Equal(a.Mask, b.Mask)
} | go | func CompareIPNet(a, b *net.IPNet) bool {
if a == b {
return true
}
if a == nil || b == nil {
return false
}
return a.IP.Equal(b.IP) && bytes.Equal(a.Mask, b.Mask)
} | [
"func",
"CompareIPNet",
"(",
"a",
",",
"b",
"*",
"net",
".",
"IPNet",
")",
"bool",
"{",
"if",
"a",
"==",
"b",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"a",
"==",
"nil",
"||",
"b",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"a",
".",
"IP",
".",
"Equal",
"(",
"b",
".",
"IP",
")",
"&&",
"bytes",
".",
"Equal",
"(",
"a",
".",
"Mask",
",",
"b",
".",
"Mask",
")",
"\n",
"}"
] | // CompareIPNet returns equal if the two IP Networks are equal | [
"CompareIPNet",
"returns",
"equal",
"if",
"the",
"two",
"IP",
"Networks",
"are",
"equal"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L324-L332 | train |
docker/libnetwork | types/types.go | GetMinimalIP | func GetMinimalIP(ip net.IP) net.IP {
if ip != nil && ip.To4() != nil {
return ip.To4()
}
return ip
} | go | func GetMinimalIP(ip net.IP) net.IP {
if ip != nil && ip.To4() != nil {
return ip.To4()
}
return ip
} | [
"func",
"GetMinimalIP",
"(",
"ip",
"net",
".",
"IP",
")",
"net",
".",
"IP",
"{",
"if",
"ip",
"!=",
"nil",
"&&",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"ip",
".",
"To4",
"(",
")",
"\n",
"}",
"\n",
"return",
"ip",
"\n",
"}"
] | // GetMinimalIP returns the address in its shortest form
// If ip contains an IPv4-mapped IPv6 address, the 4-octet form of the IPv4 address will be returned.
// Otherwise ip is returned unchanged. | [
"GetMinimalIP",
"returns",
"the",
"address",
"in",
"its",
"shortest",
"form",
"If",
"ip",
"contains",
"an",
"IPv4",
"-",
"mapped",
"IPv6",
"address",
"the",
"4",
"-",
"octet",
"form",
"of",
"the",
"IPv4",
"address",
"will",
"be",
"returned",
".",
"Otherwise",
"ip",
"is",
"returned",
"unchanged",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L337-L342 | train |
docker/libnetwork | types/types.go | GetMinimalIPNet | func GetMinimalIPNet(nw *net.IPNet) *net.IPNet {
if nw == nil {
return nil
}
if len(nw.IP) == 16 && nw.IP.To4() != nil {
m := nw.Mask
if len(m) == 16 {
m = m[12:16]
}
return &net.IPNet{IP: nw.IP.To4(), Mask: m}
}
return nw
} | go | func GetMinimalIPNet(nw *net.IPNet) *net.IPNet {
if nw == nil {
return nil
}
if len(nw.IP) == 16 && nw.IP.To4() != nil {
m := nw.Mask
if len(m) == 16 {
m = m[12:16]
}
return &net.IPNet{IP: nw.IP.To4(), Mask: m}
}
return nw
} | [
"func",
"GetMinimalIPNet",
"(",
"nw",
"*",
"net",
".",
"IPNet",
")",
"*",
"net",
".",
"IPNet",
"{",
"if",
"nw",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"nw",
".",
"IP",
")",
"==",
"16",
"&&",
"nw",
".",
"IP",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"m",
":=",
"nw",
".",
"Mask",
"\n",
"if",
"len",
"(",
"m",
")",
"==",
"16",
"{",
"m",
"=",
"m",
"[",
"12",
":",
"16",
"]",
"\n",
"}",
"\n",
"return",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"nw",
".",
"IP",
".",
"To4",
"(",
")",
",",
"Mask",
":",
"m",
"}",
"\n",
"}",
"\n",
"return",
"nw",
"\n",
"}"
] | // GetMinimalIPNet returns a copy of the passed IP Network with congruent ip and mask notation | [
"GetMinimalIPNet",
"returns",
"a",
"copy",
"of",
"the",
"passed",
"IP",
"Network",
"with",
"congruent",
"ip",
"and",
"mask",
"notation"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L345-L357 | train |
docker/libnetwork | types/types.go | compareIPMask | func compareIPMask(ip net.IP, mask net.IPMask) (is int, ms int, err error) {
// Find the effective starting of address and mask
if len(ip) == net.IPv6len && ip.To4() != nil {
is = 12
}
if len(ip[is:]) == net.IPv4len && len(mask) == net.IPv6len && bytes.Equal(mask[:12], v4inV6MaskPrefix) {
ms = 12
}
// Check if address and mask are semantically compatible
if len(ip[is:]) != len(mask[ms:]) {
err = fmt.Errorf("ip and mask are not compatible: (%#v, %#v)", ip, mask)
}
return
} | go | func compareIPMask(ip net.IP, mask net.IPMask) (is int, ms int, err error) {
// Find the effective starting of address and mask
if len(ip) == net.IPv6len && ip.To4() != nil {
is = 12
}
if len(ip[is:]) == net.IPv4len && len(mask) == net.IPv6len && bytes.Equal(mask[:12], v4inV6MaskPrefix) {
ms = 12
}
// Check if address and mask are semantically compatible
if len(ip[is:]) != len(mask[ms:]) {
err = fmt.Errorf("ip and mask are not compatible: (%#v, %#v)", ip, mask)
}
return
} | [
"func",
"compareIPMask",
"(",
"ip",
"net",
".",
"IP",
",",
"mask",
"net",
".",
"IPMask",
")",
"(",
"is",
"int",
",",
"ms",
"int",
",",
"err",
"error",
")",
"{",
"// Find the effective starting of address and mask",
"if",
"len",
"(",
"ip",
")",
"==",
"net",
".",
"IPv6len",
"&&",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"is",
"=",
"12",
"\n",
"}",
"\n",
"if",
"len",
"(",
"ip",
"[",
"is",
":",
"]",
")",
"==",
"net",
".",
"IPv4len",
"&&",
"len",
"(",
"mask",
")",
"==",
"net",
".",
"IPv6len",
"&&",
"bytes",
".",
"Equal",
"(",
"mask",
"[",
":",
"12",
"]",
",",
"v4inV6MaskPrefix",
")",
"{",
"ms",
"=",
"12",
"\n",
"}",
"\n",
"// Check if address and mask are semantically compatible",
"if",
"len",
"(",
"ip",
"[",
"is",
":",
"]",
")",
"!=",
"len",
"(",
"mask",
"[",
"ms",
":",
"]",
")",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ip",
",",
"mask",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // compareIPMask checks if the passed ip and mask are semantically compatible.
// It returns the byte indexes for the address and mask so that caller can
// do bitwise operations without modifying address representation. | [
"compareIPMask",
"checks",
"if",
"the",
"passed",
"ip",
"and",
"mask",
"are",
"semantically",
"compatible",
".",
"It",
"returns",
"the",
"byte",
"indexes",
"for",
"the",
"address",
"and",
"mask",
"so",
"that",
"caller",
"can",
"do",
"bitwise",
"operations",
"without",
"modifying",
"address",
"representation",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L370-L383 | train |
docker/libnetwork | types/types.go | GetHostPartIP | func GetHostPartIP(ip net.IP, mask net.IPMask) (net.IP, error) {
// Find the effective starting of address and mask
is, ms, err := compareIPMask(ip, mask)
if err != nil {
return nil, fmt.Errorf("cannot compute host portion ip address because %s", err)
}
// Compute host portion
out := GetIPCopy(ip)
for i := 0; i < len(mask[ms:]); i++ {
out[is+i] &= ^mask[ms+i]
}
return out, nil
} | go | func GetHostPartIP(ip net.IP, mask net.IPMask) (net.IP, error) {
// Find the effective starting of address and mask
is, ms, err := compareIPMask(ip, mask)
if err != nil {
return nil, fmt.Errorf("cannot compute host portion ip address because %s", err)
}
// Compute host portion
out := GetIPCopy(ip)
for i := 0; i < len(mask[ms:]); i++ {
out[is+i] &= ^mask[ms+i]
}
return out, nil
} | [
"func",
"GetHostPartIP",
"(",
"ip",
"net",
".",
"IP",
",",
"mask",
"net",
".",
"IPMask",
")",
"(",
"net",
".",
"IP",
",",
"error",
")",
"{",
"// Find the effective starting of address and mask",
"is",
",",
"ms",
",",
"err",
":=",
"compareIPMask",
"(",
"ip",
",",
"mask",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Compute host portion",
"out",
":=",
"GetIPCopy",
"(",
"ip",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"mask",
"[",
"ms",
":",
"]",
")",
";",
"i",
"++",
"{",
"out",
"[",
"is",
"+",
"i",
"]",
"&=",
"^",
"mask",
"[",
"ms",
"+",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // GetHostPartIP returns the host portion of the ip address identified by the mask.
// IP address representation is not modified. If address and mask are not compatible
// an error is returned. | [
"GetHostPartIP",
"returns",
"the",
"host",
"portion",
"of",
"the",
"ip",
"address",
"identified",
"by",
"the",
"mask",
".",
"IP",
"address",
"representation",
"is",
"not",
"modified",
".",
"If",
"address",
"and",
"mask",
"are",
"not",
"compatible",
"an",
"error",
"is",
"returned",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L388-L402 | train |
docker/libnetwork | types/types.go | GetCopy | func (r *StaticRoute) GetCopy() *StaticRoute {
d := GetIPNetCopy(r.Destination)
nh := GetIPCopy(r.NextHop)
return &StaticRoute{Destination: d,
RouteType: r.RouteType,
NextHop: nh,
}
} | go | func (r *StaticRoute) GetCopy() *StaticRoute {
d := GetIPNetCopy(r.Destination)
nh := GetIPCopy(r.NextHop)
return &StaticRoute{Destination: d,
RouteType: r.RouteType,
NextHop: nh,
}
} | [
"func",
"(",
"r",
"*",
"StaticRoute",
")",
"GetCopy",
"(",
")",
"*",
"StaticRoute",
"{",
"d",
":=",
"GetIPNetCopy",
"(",
"r",
".",
"Destination",
")",
"\n",
"nh",
":=",
"GetIPCopy",
"(",
"r",
".",
"NextHop",
")",
"\n",
"return",
"&",
"StaticRoute",
"{",
"Destination",
":",
"d",
",",
"RouteType",
":",
"r",
".",
"RouteType",
",",
"NextHop",
":",
"nh",
",",
"}",
"\n",
"}"
] | // GetCopy returns a copy of this StaticRoute structure | [
"GetCopy",
"returns",
"a",
"copy",
"of",
"this",
"StaticRoute",
"structure"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L451-L458 | train |
docker/libnetwork | types/types.go | NotFoundErrorf | func NotFoundErrorf(format string, params ...interface{}) error {
return notFound(fmt.Sprintf(format, params...))
} | go | func NotFoundErrorf(format string, params ...interface{}) error {
return notFound(fmt.Sprintf(format, params...))
} | [
"func",
"NotFoundErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"notFound",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // NotFoundErrorf creates an instance of NotFoundError | [
"NotFoundErrorf",
"creates",
"an",
"instance",
"of",
"NotFoundError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L545-L547 | train |
docker/libnetwork | types/types.go | ForbiddenErrorf | func ForbiddenErrorf(format string, params ...interface{}) error {
return forbidden(fmt.Sprintf(format, params...))
} | go | func ForbiddenErrorf(format string, params ...interface{}) error {
return forbidden(fmt.Sprintf(format, params...))
} | [
"func",
"ForbiddenErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"forbidden",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // ForbiddenErrorf creates an instance of ForbiddenError | [
"ForbiddenErrorf",
"creates",
"an",
"instance",
"of",
"ForbiddenError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L550-L552 | train |
docker/libnetwork | types/types.go | NoServiceErrorf | func NoServiceErrorf(format string, params ...interface{}) error {
return noService(fmt.Sprintf(format, params...))
} | go | func NoServiceErrorf(format string, params ...interface{}) error {
return noService(fmt.Sprintf(format, params...))
} | [
"func",
"NoServiceErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"noService",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // NoServiceErrorf creates an instance of NoServiceError | [
"NoServiceErrorf",
"creates",
"an",
"instance",
"of",
"NoServiceError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L555-L557 | train |
docker/libnetwork | types/types.go | NotImplementedErrorf | func NotImplementedErrorf(format string, params ...interface{}) error {
return notImpl(fmt.Sprintf(format, params...))
} | go | func NotImplementedErrorf(format string, params ...interface{}) error {
return notImpl(fmt.Sprintf(format, params...))
} | [
"func",
"NotImplementedErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"notImpl",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // NotImplementedErrorf creates an instance of NotImplementedError | [
"NotImplementedErrorf",
"creates",
"an",
"instance",
"of",
"NotImplementedError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L560-L562 | train |
docker/libnetwork | types/types.go | TimeoutErrorf | func TimeoutErrorf(format string, params ...interface{}) error {
return timeout(fmt.Sprintf(format, params...))
} | go | func TimeoutErrorf(format string, params ...interface{}) error {
return timeout(fmt.Sprintf(format, params...))
} | [
"func",
"TimeoutErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"timeout",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // TimeoutErrorf creates an instance of TimeoutError | [
"TimeoutErrorf",
"creates",
"an",
"instance",
"of",
"TimeoutError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L565-L567 | train |
docker/libnetwork | types/types.go | InternalErrorf | func InternalErrorf(format string, params ...interface{}) error {
return internal(fmt.Sprintf(format, params...))
} | go | func InternalErrorf(format string, params ...interface{}) error {
return internal(fmt.Sprintf(format, params...))
} | [
"func",
"InternalErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"internal",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // InternalErrorf creates an instance of InternalError | [
"InternalErrorf",
"creates",
"an",
"instance",
"of",
"InternalError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L570-L572 | train |
docker/libnetwork | types/types.go | InternalMaskableErrorf | func InternalMaskableErrorf(format string, params ...interface{}) error {
return maskInternal(fmt.Sprintf(format, params...))
} | go | func InternalMaskableErrorf(format string, params ...interface{}) error {
return maskInternal(fmt.Sprintf(format, params...))
} | [
"func",
"InternalMaskableErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"maskInternal",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // InternalMaskableErrorf creates an instance of InternalError and MaskableError | [
"InternalMaskableErrorf",
"creates",
"an",
"instance",
"of",
"InternalError",
"and",
"MaskableError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L575-L577 | train |
docker/libnetwork | types/types.go | RetryErrorf | func RetryErrorf(format string, params ...interface{}) error {
return retry(fmt.Sprintf(format, params...))
} | go | func RetryErrorf(format string, params ...interface{}) error {
return retry(fmt.Sprintf(format, params...))
} | [
"func",
"RetryErrorf",
"(",
"format",
"string",
",",
"params",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"retry",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"params",
"...",
")",
")",
"\n",
"}"
] | // RetryErrorf creates an instance of RetryError | [
"RetryErrorf",
"creates",
"an",
"instance",
"of",
"RetryError"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/types/types.go#L580-L582 | train |
docker/libnetwork | drivers/macvlan/macvlan_state.go | getNetworks | func (d *driver) getNetworks() []*network {
d.Lock()
defer d.Unlock()
ls := make([]*network, 0, len(d.networks))
for _, nw := range d.networks {
ls = append(ls, nw)
}
return ls
} | go | func (d *driver) getNetworks() []*network {
d.Lock()
defer d.Unlock()
ls := make([]*network, 0, len(d.networks))
for _, nw := range d.networks {
ls = append(ls, nw)
}
return ls
} | [
"func",
"(",
"d",
"*",
"driver",
")",
"getNetworks",
"(",
")",
"[",
"]",
"*",
"network",
"{",
"d",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"Unlock",
"(",
")",
"\n\n",
"ls",
":=",
"make",
"(",
"[",
"]",
"*",
"network",
",",
"0",
",",
"len",
"(",
"d",
".",
"networks",
")",
")",
"\n",
"for",
"_",
",",
"nw",
":=",
"range",
"d",
".",
"networks",
"{",
"ls",
"=",
"append",
"(",
"ls",
",",
"nw",
")",
"\n",
"}",
"\n\n",
"return",
"ls",
"\n",
"}"
] | // getNetworks Safely returns a slice of existing networks | [
"getNetworks",
"Safely",
"returns",
"a",
"slice",
"of",
"existing",
"networks"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/macvlan/macvlan_state.go#L35-L45 | train |
docker/libnetwork | config/config.go | LoadDefaultScopes | func (c *Config) LoadDefaultScopes(dataDir string) {
for k, v := range datastore.DefaultScopes(dataDir) {
if _, ok := c.Scopes[k]; !ok {
c.Scopes[k] = v
}
}
} | go | func (c *Config) LoadDefaultScopes(dataDir string) {
for k, v := range datastore.DefaultScopes(dataDir) {
if _, ok := c.Scopes[k]; !ok {
c.Scopes[k] = v
}
}
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"LoadDefaultScopes",
"(",
"dataDir",
"string",
")",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"datastore",
".",
"DefaultScopes",
"(",
"dataDir",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Scopes",
"[",
"k",
"]",
";",
"!",
"ok",
"{",
"c",
".",
"Scopes",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // LoadDefaultScopes loads default scope configs for scopes which
// doesn't have explicit user specified configs. | [
"LoadDefaultScopes",
"loads",
"default",
"scope",
"configs",
"for",
"scopes",
"which",
"doesn",
"t",
"have",
"explicit",
"user",
"specified",
"configs",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L58-L64 | train |
docker/libnetwork | config/config.go | ParseConfigOptions | func ParseConfigOptions(cfgOptions ...Option) *Config {
cfg := &Config{
Daemon: DaemonCfg{
DriverCfg: make(map[string]interface{}),
},
Scopes: make(map[string]*datastore.ScopeCfg),
}
cfg.ProcessOptions(cfgOptions...)
cfg.LoadDefaultScopes(cfg.Daemon.DataDir)
return cfg
} | go | func ParseConfigOptions(cfgOptions ...Option) *Config {
cfg := &Config{
Daemon: DaemonCfg{
DriverCfg: make(map[string]interface{}),
},
Scopes: make(map[string]*datastore.ScopeCfg),
}
cfg.ProcessOptions(cfgOptions...)
cfg.LoadDefaultScopes(cfg.Daemon.DataDir)
return cfg
} | [
"func",
"ParseConfigOptions",
"(",
"cfgOptions",
"...",
"Option",
")",
"*",
"Config",
"{",
"cfg",
":=",
"&",
"Config",
"{",
"Daemon",
":",
"DaemonCfg",
"{",
"DriverCfg",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
",",
"}",
",",
"Scopes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"datastore",
".",
"ScopeCfg",
")",
",",
"}",
"\n\n",
"cfg",
".",
"ProcessOptions",
"(",
"cfgOptions",
"...",
")",
"\n",
"cfg",
".",
"LoadDefaultScopes",
"(",
"cfg",
".",
"Daemon",
".",
"DataDir",
")",
"\n\n",
"return",
"cfg",
"\n",
"}"
] | // ParseConfigOptions parses the configuration options and returns
// a reference to the corresponding Config structure | [
"ParseConfigOptions",
"parses",
"the",
"configuration",
"options",
"and",
"returns",
"a",
"reference",
"to",
"the",
"corresponding",
"Config",
"structure"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L82-L94 | train |
docker/libnetwork | config/config.go | OptionDefaultNetwork | func OptionDefaultNetwork(dn string) Option {
return func(c *Config) {
logrus.Debugf("Option DefaultNetwork: %s", dn)
c.Daemon.DefaultNetwork = strings.TrimSpace(dn)
}
} | go | func OptionDefaultNetwork(dn string) Option {
return func(c *Config) {
logrus.Debugf("Option DefaultNetwork: %s", dn)
c.Daemon.DefaultNetwork = strings.TrimSpace(dn)
}
} | [
"func",
"OptionDefaultNetwork",
"(",
"dn",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"dn",
")",
"\n",
"c",
".",
"Daemon",
".",
"DefaultNetwork",
"=",
"strings",
".",
"TrimSpace",
"(",
"dn",
")",
"\n",
"}",
"\n",
"}"
] | // OptionDefaultNetwork function returns an option setter for a default network | [
"OptionDefaultNetwork",
"function",
"returns",
"an",
"option",
"setter",
"for",
"a",
"default",
"network"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L101-L106 | train |
docker/libnetwork | config/config.go | OptionDefaultDriver | func OptionDefaultDriver(dd string) Option {
return func(c *Config) {
logrus.Debugf("Option DefaultDriver: %s", dd)
c.Daemon.DefaultDriver = strings.TrimSpace(dd)
}
} | go | func OptionDefaultDriver(dd string) Option {
return func(c *Config) {
logrus.Debugf("Option DefaultDriver: %s", dd)
c.Daemon.DefaultDriver = strings.TrimSpace(dd)
}
} | [
"func",
"OptionDefaultDriver",
"(",
"dd",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"dd",
")",
"\n",
"c",
".",
"Daemon",
".",
"DefaultDriver",
"=",
"strings",
".",
"TrimSpace",
"(",
"dd",
")",
"\n",
"}",
"\n",
"}"
] | // OptionDefaultDriver function returns an option setter for default driver | [
"OptionDefaultDriver",
"function",
"returns",
"an",
"option",
"setter",
"for",
"default",
"driver"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L109-L114 | train |
docker/libnetwork | config/config.go | OptionDefaultAddressPoolConfig | func OptionDefaultAddressPoolConfig(addressPool []*ipamutils.NetworkToSplit) Option {
return func(c *Config) {
c.Daemon.DefaultAddressPool = addressPool
}
} | go | func OptionDefaultAddressPoolConfig(addressPool []*ipamutils.NetworkToSplit) Option {
return func(c *Config) {
c.Daemon.DefaultAddressPool = addressPool
}
} | [
"func",
"OptionDefaultAddressPoolConfig",
"(",
"addressPool",
"[",
"]",
"*",
"ipamutils",
".",
"NetworkToSplit",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"c",
".",
"Daemon",
".",
"DefaultAddressPool",
"=",
"addressPool",
"\n",
"}",
"\n",
"}"
] | // OptionDefaultAddressPoolConfig function returns an option setter for default address pool | [
"OptionDefaultAddressPoolConfig",
"function",
"returns",
"an",
"option",
"setter",
"for",
"default",
"address",
"pool"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L117-L121 | train |
docker/libnetwork | config/config.go | OptionDriverConfig | func OptionDriverConfig(networkType string, config map[string]interface{}) Option {
return func(c *Config) {
c.Daemon.DriverCfg[networkType] = config
}
} | go | func OptionDriverConfig(networkType string, config map[string]interface{}) Option {
return func(c *Config) {
c.Daemon.DriverCfg[networkType] = config
}
} | [
"func",
"OptionDriverConfig",
"(",
"networkType",
"string",
",",
"config",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"c",
".",
"Daemon",
".",
"DriverCfg",
"[",
"networkType",
"]",
"=",
"config",
"\n",
"}",
"\n",
"}"
] | // OptionDriverConfig returns an option setter for driver configuration. | [
"OptionDriverConfig",
"returns",
"an",
"option",
"setter",
"for",
"driver",
"configuration",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L124-L128 | train |
docker/libnetwork | config/config.go | OptionLabels | func OptionLabels(labels []string) Option {
return func(c *Config) {
for _, label := range labels {
if strings.HasPrefix(label, netlabel.Prefix) {
c.Daemon.Labels = append(c.Daemon.Labels, label)
}
}
}
} | go | func OptionLabels(labels []string) Option {
return func(c *Config) {
for _, label := range labels {
if strings.HasPrefix(label, netlabel.Prefix) {
c.Daemon.Labels = append(c.Daemon.Labels, label)
}
}
}
} | [
"func",
"OptionLabels",
"(",
"labels",
"[",
"]",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"for",
"_",
",",
"label",
":=",
"range",
"labels",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"label",
",",
"netlabel",
".",
"Prefix",
")",
"{",
"c",
".",
"Daemon",
".",
"Labels",
"=",
"append",
"(",
"c",
".",
"Daemon",
".",
"Labels",
",",
"label",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // OptionLabels function returns an option setter for labels | [
"OptionLabels",
"function",
"returns",
"an",
"option",
"setter",
"for",
"labels"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L131-L139 | train |
docker/libnetwork | config/config.go | OptionKVProvider | func OptionKVProvider(provider string) Option {
return func(c *Config) {
logrus.Debugf("Option OptionKVProvider: %s", provider)
if _, ok := c.Scopes[datastore.GlobalScope]; !ok {
c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{}
}
c.Scopes[datastore.GlobalScope].Client.Provider = strings.TrimSpace(provider)
}
} | go | func OptionKVProvider(provider string) Option {
return func(c *Config) {
logrus.Debugf("Option OptionKVProvider: %s", provider)
if _, ok := c.Scopes[datastore.GlobalScope]; !ok {
c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{}
}
c.Scopes[datastore.GlobalScope].Client.Provider = strings.TrimSpace(provider)
}
} | [
"func",
"OptionKVProvider",
"(",
"provider",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"provider",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
";",
"!",
"ok",
"{",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
"=",
"&",
"datastore",
".",
"ScopeCfg",
"{",
"}",
"\n",
"}",
"\n",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
".",
"Client",
".",
"Provider",
"=",
"strings",
".",
"TrimSpace",
"(",
"provider",
")",
"\n",
"}",
"\n",
"}"
] | // OptionKVProvider function returns an option setter for kvstore provider | [
"OptionKVProvider",
"function",
"returns",
"an",
"option",
"setter",
"for",
"kvstore",
"provider"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L142-L150 | train |
docker/libnetwork | config/config.go | OptionKVProviderURL | func OptionKVProviderURL(url string) Option {
return func(c *Config) {
logrus.Debugf("Option OptionKVProviderURL: %s", url)
if _, ok := c.Scopes[datastore.GlobalScope]; !ok {
c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{}
}
c.Scopes[datastore.GlobalScope].Client.Address = strings.TrimSpace(url)
}
} | go | func OptionKVProviderURL(url string) Option {
return func(c *Config) {
logrus.Debugf("Option OptionKVProviderURL: %s", url)
if _, ok := c.Scopes[datastore.GlobalScope]; !ok {
c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{}
}
c.Scopes[datastore.GlobalScope].Client.Address = strings.TrimSpace(url)
}
} | [
"func",
"OptionKVProviderURL",
"(",
"url",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"url",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
";",
"!",
"ok",
"{",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
"=",
"&",
"datastore",
".",
"ScopeCfg",
"{",
"}",
"\n",
"}",
"\n",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
".",
"Client",
".",
"Address",
"=",
"strings",
".",
"TrimSpace",
"(",
"url",
")",
"\n",
"}",
"\n",
"}"
] | // OptionKVProviderURL function returns an option setter for kvstore url | [
"OptionKVProviderURL",
"function",
"returns",
"an",
"option",
"setter",
"for",
"kvstore",
"url"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L153-L161 | train |
docker/libnetwork | config/config.go | OptionKVOpts | func OptionKVOpts(opts map[string]string) Option {
return func(c *Config) {
if opts["kv.cacertfile"] != "" && opts["kv.certfile"] != "" && opts["kv.keyfile"] != "" {
logrus.Info("Option Initializing KV with TLS")
tlsConfig, err := tlsconfig.Client(tlsconfig.Options{
CAFile: opts["kv.cacertfile"],
CertFile: opts["kv.certfile"],
KeyFile: opts["kv.keyfile"],
})
if err != nil {
logrus.Errorf("Unable to set up TLS: %s", err)
return
}
if _, ok := c.Scopes[datastore.GlobalScope]; !ok {
c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{}
}
if c.Scopes[datastore.GlobalScope].Client.Config == nil {
c.Scopes[datastore.GlobalScope].Client.Config = &store.Config{TLS: tlsConfig}
} else {
c.Scopes[datastore.GlobalScope].Client.Config.TLS = tlsConfig
}
// Workaround libkv/etcd bug for https
c.Scopes[datastore.GlobalScope].Client.Config.ClientTLS = &store.ClientTLSConfig{
CACertFile: opts["kv.cacertfile"],
CertFile: opts["kv.certfile"],
KeyFile: opts["kv.keyfile"],
}
} else {
logrus.Info("Option Initializing KV without TLS")
}
}
} | go | func OptionKVOpts(opts map[string]string) Option {
return func(c *Config) {
if opts["kv.cacertfile"] != "" && opts["kv.certfile"] != "" && opts["kv.keyfile"] != "" {
logrus.Info("Option Initializing KV with TLS")
tlsConfig, err := tlsconfig.Client(tlsconfig.Options{
CAFile: opts["kv.cacertfile"],
CertFile: opts["kv.certfile"],
KeyFile: opts["kv.keyfile"],
})
if err != nil {
logrus.Errorf("Unable to set up TLS: %s", err)
return
}
if _, ok := c.Scopes[datastore.GlobalScope]; !ok {
c.Scopes[datastore.GlobalScope] = &datastore.ScopeCfg{}
}
if c.Scopes[datastore.GlobalScope].Client.Config == nil {
c.Scopes[datastore.GlobalScope].Client.Config = &store.Config{TLS: tlsConfig}
} else {
c.Scopes[datastore.GlobalScope].Client.Config.TLS = tlsConfig
}
// Workaround libkv/etcd bug for https
c.Scopes[datastore.GlobalScope].Client.Config.ClientTLS = &store.ClientTLSConfig{
CACertFile: opts["kv.cacertfile"],
CertFile: opts["kv.certfile"],
KeyFile: opts["kv.keyfile"],
}
} else {
logrus.Info("Option Initializing KV without TLS")
}
}
} | [
"func",
"OptionKVOpts",
"(",
"opts",
"map",
"[",
"string",
"]",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"if",
"opts",
"[",
"\"",
"\"",
"]",
"!=",
"\"",
"\"",
"&&",
"opts",
"[",
"\"",
"\"",
"]",
"!=",
"\"",
"\"",
"&&",
"opts",
"[",
"\"",
"\"",
"]",
"!=",
"\"",
"\"",
"{",
"logrus",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"tlsConfig",
",",
"err",
":=",
"tlsconfig",
".",
"Client",
"(",
"tlsconfig",
".",
"Options",
"{",
"CAFile",
":",
"opts",
"[",
"\"",
"\"",
"]",
",",
"CertFile",
":",
"opts",
"[",
"\"",
"\"",
"]",
",",
"KeyFile",
":",
"opts",
"[",
"\"",
"\"",
"]",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
";",
"!",
"ok",
"{",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
"=",
"&",
"datastore",
".",
"ScopeCfg",
"{",
"}",
"\n",
"}",
"\n",
"if",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
".",
"Client",
".",
"Config",
"==",
"nil",
"{",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
".",
"Client",
".",
"Config",
"=",
"&",
"store",
".",
"Config",
"{",
"TLS",
":",
"tlsConfig",
"}",
"\n",
"}",
"else",
"{",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
".",
"Client",
".",
"Config",
".",
"TLS",
"=",
"tlsConfig",
"\n",
"}",
"\n",
"// Workaround libkv/etcd bug for https",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"GlobalScope",
"]",
".",
"Client",
".",
"Config",
".",
"ClientTLS",
"=",
"&",
"store",
".",
"ClientTLSConfig",
"{",
"CACertFile",
":",
"opts",
"[",
"\"",
"\"",
"]",
",",
"CertFile",
":",
"opts",
"[",
"\"",
"\"",
"]",
",",
"KeyFile",
":",
"opts",
"[",
"\"",
"\"",
"]",
",",
"}",
"\n",
"}",
"else",
"{",
"logrus",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // OptionKVOpts function returns an option setter for kvstore options | [
"OptionKVOpts",
"function",
"returns",
"an",
"option",
"setter",
"for",
"kvstore",
"options"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L164-L195 | train |
docker/libnetwork | config/config.go | OptionDiscoveryWatcher | func OptionDiscoveryWatcher(watcher discovery.Watcher) Option {
return func(c *Config) {
c.Cluster.Watcher = watcher
}
} | go | func OptionDiscoveryWatcher(watcher discovery.Watcher) Option {
return func(c *Config) {
c.Cluster.Watcher = watcher
}
} | [
"func",
"OptionDiscoveryWatcher",
"(",
"watcher",
"discovery",
".",
"Watcher",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"c",
".",
"Cluster",
".",
"Watcher",
"=",
"watcher",
"\n",
"}",
"\n",
"}"
] | // OptionDiscoveryWatcher function returns an option setter for discovery watcher | [
"OptionDiscoveryWatcher",
"function",
"returns",
"an",
"option",
"setter",
"for",
"discovery",
"watcher"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L198-L202 | train |
docker/libnetwork | config/config.go | OptionDiscoveryAddress | func OptionDiscoveryAddress(address string) Option {
return func(c *Config) {
c.Cluster.Address = address
}
} | go | func OptionDiscoveryAddress(address string) Option {
return func(c *Config) {
c.Cluster.Address = address
}
} | [
"func",
"OptionDiscoveryAddress",
"(",
"address",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"c",
".",
"Cluster",
".",
"Address",
"=",
"address",
"\n",
"}",
"\n",
"}"
] | // OptionDiscoveryAddress function returns an option setter for self discovery address | [
"OptionDiscoveryAddress",
"function",
"returns",
"an",
"option",
"setter",
"for",
"self",
"discovery",
"address"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L205-L209 | train |
docker/libnetwork | config/config.go | OptionDataDir | func OptionDataDir(dataDir string) Option {
return func(c *Config) {
c.Daemon.DataDir = dataDir
}
} | go | func OptionDataDir(dataDir string) Option {
return func(c *Config) {
c.Daemon.DataDir = dataDir
}
} | [
"func",
"OptionDataDir",
"(",
"dataDir",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"c",
".",
"Daemon",
".",
"DataDir",
"=",
"dataDir",
"\n",
"}",
"\n",
"}"
] | // OptionDataDir function returns an option setter for data folder | [
"OptionDataDir",
"function",
"returns",
"an",
"option",
"setter",
"for",
"data",
"folder"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L212-L216 | train |
docker/libnetwork | config/config.go | OptionExecRoot | func OptionExecRoot(execRoot string) Option {
return func(c *Config) {
c.Daemon.ExecRoot = execRoot
osl.SetBasePath(execRoot)
}
} | go | func OptionExecRoot(execRoot string) Option {
return func(c *Config) {
c.Daemon.ExecRoot = execRoot
osl.SetBasePath(execRoot)
}
} | [
"func",
"OptionExecRoot",
"(",
"execRoot",
"string",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"c",
".",
"Daemon",
".",
"ExecRoot",
"=",
"execRoot",
"\n",
"osl",
".",
"SetBasePath",
"(",
"execRoot",
")",
"\n",
"}",
"\n",
"}"
] | // OptionExecRoot function returns an option setter for exec root folder | [
"OptionExecRoot",
"function",
"returns",
"an",
"option",
"setter",
"for",
"exec",
"root",
"folder"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L219-L224 | train |
docker/libnetwork | config/config.go | OptionPluginGetter | func OptionPluginGetter(pg plugingetter.PluginGetter) Option {
return func(c *Config) {
c.PluginGetter = pg
}
} | go | func OptionPluginGetter(pg plugingetter.PluginGetter) Option {
return func(c *Config) {
c.PluginGetter = pg
}
} | [
"func",
"OptionPluginGetter",
"(",
"pg",
"plugingetter",
".",
"PluginGetter",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"c",
".",
"PluginGetter",
"=",
"pg",
"\n",
"}",
"\n",
"}"
] | // OptionPluginGetter returns a plugingetter for remote drivers. | [
"OptionPluginGetter",
"returns",
"a",
"plugingetter",
"for",
"remote",
"drivers",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L227-L231 | train |
docker/libnetwork | config/config.go | OptionExperimental | func OptionExperimental(exp bool) Option {
return func(c *Config) {
logrus.Debugf("Option Experimental: %v", exp)
c.Daemon.Experimental = exp
}
} | go | func OptionExperimental(exp bool) Option {
return func(c *Config) {
logrus.Debugf("Option Experimental: %v", exp)
c.Daemon.Experimental = exp
}
} | [
"func",
"OptionExperimental",
"(",
"exp",
"bool",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"exp",
")",
"\n",
"c",
".",
"Daemon",
".",
"Experimental",
"=",
"exp",
"\n",
"}",
"\n",
"}"
] | // OptionExperimental function returns an option setter for experimental daemon | [
"OptionExperimental",
"function",
"returns",
"an",
"option",
"setter",
"for",
"experimental",
"daemon"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L234-L239 | train |
docker/libnetwork | config/config.go | OptionNetworkControlPlaneMTU | func OptionNetworkControlPlaneMTU(exp int) Option {
return func(c *Config) {
logrus.Debugf("Network Control Plane MTU: %d", exp)
if exp < warningThNetworkControlPlaneMTU {
logrus.Warnf("Received a MTU of %d, this value is very low, the network control plane can misbehave,"+
" defaulting to minimum value (%d)", exp, minimumNetworkControlPlaneMTU)
if exp < minimumNetworkControlPlaneMTU {
exp = minimumNetworkControlPlaneMTU
}
}
c.Daemon.NetworkControlPlaneMTU = exp
}
} | go | func OptionNetworkControlPlaneMTU(exp int) Option {
return func(c *Config) {
logrus.Debugf("Network Control Plane MTU: %d", exp)
if exp < warningThNetworkControlPlaneMTU {
logrus.Warnf("Received a MTU of %d, this value is very low, the network control plane can misbehave,"+
" defaulting to minimum value (%d)", exp, minimumNetworkControlPlaneMTU)
if exp < minimumNetworkControlPlaneMTU {
exp = minimumNetworkControlPlaneMTU
}
}
c.Daemon.NetworkControlPlaneMTU = exp
}
} | [
"func",
"OptionNetworkControlPlaneMTU",
"(",
"exp",
"int",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"exp",
")",
"\n",
"if",
"exp",
"<",
"warningThNetworkControlPlaneMTU",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
"+",
"\"",
"\"",
",",
"exp",
",",
"minimumNetworkControlPlaneMTU",
")",
"\n",
"if",
"exp",
"<",
"minimumNetworkControlPlaneMTU",
"{",
"exp",
"=",
"minimumNetworkControlPlaneMTU",
"\n",
"}",
"\n",
"}",
"\n",
"c",
".",
"Daemon",
".",
"NetworkControlPlaneMTU",
"=",
"exp",
"\n",
"}",
"\n",
"}"
] | // OptionNetworkControlPlaneMTU function returns an option setter for control plane MTU | [
"OptionNetworkControlPlaneMTU",
"function",
"returns",
"an",
"option",
"setter",
"for",
"control",
"plane",
"MTU"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L242-L254 | train |
docker/libnetwork | config/config.go | ProcessOptions | func (c *Config) ProcessOptions(options ...Option) {
for _, opt := range options {
if opt != nil {
opt(c)
}
}
} | go | func (c *Config) ProcessOptions(options ...Option) {
for _, opt := range options {
if opt != nil {
opt(c)
}
}
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"ProcessOptions",
"(",
"options",
"...",
"Option",
")",
"{",
"for",
"_",
",",
"opt",
":=",
"range",
"options",
"{",
"if",
"opt",
"!=",
"nil",
"{",
"opt",
"(",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ProcessOptions processes options and stores it in config | [
"ProcessOptions",
"processes",
"options",
"and",
"stores",
"it",
"in",
"config"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L257-L263 | train |
docker/libnetwork | config/config.go | OptionLocalKVProviderConfig | func OptionLocalKVProviderConfig(config *store.Config) Option {
return func(c *Config) {
logrus.Debugf("Option OptionLocalKVProviderConfig: %v", config)
if _, ok := c.Scopes[datastore.LocalScope]; !ok {
c.Scopes[datastore.LocalScope] = &datastore.ScopeCfg{}
}
c.Scopes[datastore.LocalScope].Client.Config = config
}
} | go | func OptionLocalKVProviderConfig(config *store.Config) Option {
return func(c *Config) {
logrus.Debugf("Option OptionLocalKVProviderConfig: %v", config)
if _, ok := c.Scopes[datastore.LocalScope]; !ok {
c.Scopes[datastore.LocalScope] = &datastore.ScopeCfg{}
}
c.Scopes[datastore.LocalScope].Client.Config = config
}
} | [
"func",
"OptionLocalKVProviderConfig",
"(",
"config",
"*",
"store",
".",
"Config",
")",
"Option",
"{",
"return",
"func",
"(",
"c",
"*",
"Config",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"config",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"LocalScope",
"]",
";",
"!",
"ok",
"{",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"LocalScope",
"]",
"=",
"&",
"datastore",
".",
"ScopeCfg",
"{",
"}",
"\n",
"}",
"\n",
"c",
".",
"Scopes",
"[",
"datastore",
".",
"LocalScope",
"]",
".",
"Client",
".",
"Config",
"=",
"config",
"\n",
"}",
"\n",
"}"
] | // OptionLocalKVProviderConfig function returns an option setter for kvstore config | [
"OptionLocalKVProviderConfig",
"function",
"returns",
"an",
"option",
"setter",
"for",
"kvstore",
"config"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/config/config.go#L293-L301 | train |
docker/libnetwork | iptables/firewalld.go | FirewalldInit | func FirewalldInit() error {
var err error
if connection, err = newConnection(); err != nil {
return fmt.Errorf("Failed to connect to D-Bus system bus: %v", err)
}
firewalldRunning = checkRunning()
if !firewalldRunning {
connection.sysconn.Close()
connection = nil
}
if connection != nil {
go signalHandler()
}
return nil
} | go | func FirewalldInit() error {
var err error
if connection, err = newConnection(); err != nil {
return fmt.Errorf("Failed to connect to D-Bus system bus: %v", err)
}
firewalldRunning = checkRunning()
if !firewalldRunning {
connection.sysconn.Close()
connection = nil
}
if connection != nil {
go signalHandler()
}
return nil
} | [
"func",
"FirewalldInit",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"connection",
",",
"err",
"=",
"newConnection",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"firewalldRunning",
"=",
"checkRunning",
"(",
")",
"\n",
"if",
"!",
"firewalldRunning",
"{",
"connection",
".",
"sysconn",
".",
"Close",
"(",
")",
"\n",
"connection",
"=",
"nil",
"\n",
"}",
"\n",
"if",
"connection",
"!=",
"nil",
"{",
"go",
"signalHandler",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // FirewalldInit initializes firewalld management code. | [
"FirewalldInit",
"initializes",
"firewalld",
"management",
"code",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L41-L57 | train |
docker/libnetwork | iptables/firewalld.go | initConnection | func (c *Conn) initConnection() error {
var err error
c.sysconn, err = dbus.SystemBus()
if err != nil {
return err
}
// This never fails, even if the service is not running atm.
c.sysobj = c.sysconn.Object(dbusInterface, dbus.ObjectPath(dbusPath))
rule := fmt.Sprintf("type='signal',path='%s',interface='%s',sender='%s',member='Reloaded'",
dbusPath, dbusInterface, dbusInterface)
c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
rule = fmt.Sprintf("type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',sender='org.freedesktop.DBus',arg0='%s'",
dbusInterface)
c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
c.signal = make(chan *dbus.Signal, 10)
c.sysconn.Signal(c.signal)
return nil
} | go | func (c *Conn) initConnection() error {
var err error
c.sysconn, err = dbus.SystemBus()
if err != nil {
return err
}
// This never fails, even if the service is not running atm.
c.sysobj = c.sysconn.Object(dbusInterface, dbus.ObjectPath(dbusPath))
rule := fmt.Sprintf("type='signal',path='%s',interface='%s',sender='%s',member='Reloaded'",
dbusPath, dbusInterface, dbusInterface)
c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
rule = fmt.Sprintf("type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',sender='org.freedesktop.DBus',arg0='%s'",
dbusInterface)
c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
c.signal = make(chan *dbus.Signal, 10)
c.sysconn.Signal(c.signal)
return nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"initConnection",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"c",
".",
"sysconn",
",",
"err",
"=",
"dbus",
".",
"SystemBus",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// This never fails, even if the service is not running atm.",
"c",
".",
"sysobj",
"=",
"c",
".",
"sysconn",
".",
"Object",
"(",
"dbusInterface",
",",
"dbus",
".",
"ObjectPath",
"(",
"dbusPath",
")",
")",
"\n\n",
"rule",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"dbusPath",
",",
"dbusInterface",
",",
"dbusInterface",
")",
"\n",
"c",
".",
"sysconn",
".",
"BusObject",
"(",
")",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"rule",
")",
"\n\n",
"rule",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"dbusInterface",
")",
"\n",
"c",
".",
"sysconn",
".",
"BusObject",
"(",
")",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"rule",
")",
"\n\n",
"c",
".",
"signal",
"=",
"make",
"(",
"chan",
"*",
"dbus",
".",
"Signal",
",",
"10",
")",
"\n",
"c",
".",
"sysconn",
".",
"Signal",
"(",
"c",
".",
"signal",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Initialize D-Bus connection. | [
"Initialize",
"D",
"-",
"Bus",
"connection",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L70-L93 | train |
docker/libnetwork | iptables/firewalld.go | OnReloaded | func OnReloaded(callback func()) {
for _, pf := range onReloaded {
if pf == &callback {
return
}
}
onReloaded = append(onReloaded, &callback)
} | go | func OnReloaded(callback func()) {
for _, pf := range onReloaded {
if pf == &callback {
return
}
}
onReloaded = append(onReloaded, &callback)
} | [
"func",
"OnReloaded",
"(",
"callback",
"func",
"(",
")",
")",
"{",
"for",
"_",
",",
"pf",
":=",
"range",
"onReloaded",
"{",
"if",
"pf",
"==",
"&",
"callback",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"onReloaded",
"=",
"append",
"(",
"onReloaded",
",",
"&",
"callback",
")",
"\n",
"}"
] | // OnReloaded add callback | [
"OnReloaded",
"add",
"callback"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L138-L145 | train |
docker/libnetwork | iptables/firewalld.go | checkRunning | func checkRunning() bool {
var zone string
var err error
if connection != nil {
err = connection.sysobj.Call(dbusInterface+".getDefaultZone", 0).Store(&zone)
return err == nil
}
return false
} | go | func checkRunning() bool {
var zone string
var err error
if connection != nil {
err = connection.sysobj.Call(dbusInterface+".getDefaultZone", 0).Store(&zone)
return err == nil
}
return false
} | [
"func",
"checkRunning",
"(",
")",
"bool",
"{",
"var",
"zone",
"string",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"connection",
"!=",
"nil",
"{",
"err",
"=",
"connection",
".",
"sysobj",
".",
"Call",
"(",
"dbusInterface",
"+",
"\"",
"\"",
",",
"0",
")",
".",
"Store",
"(",
"&",
"zone",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Call some remote method to see whether the service is actually running. | [
"Call",
"some",
"remote",
"method",
"to",
"see",
"whether",
"the",
"service",
"is",
"actually",
"running",
"."
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/iptables/firewalld.go#L148-L157 | train |
docker/libnetwork | drivers/windows/overlay/ov_network_windows.go | contains | func (n *network) contains(ip net.IP) bool {
for _, s := range n.subnets {
if s.subnetIP.Contains(ip) {
return true
}
}
return false
} | go | func (n *network) contains(ip net.IP) bool {
for _, s := range n.subnets {
if s.subnetIP.Contains(ip) {
return true
}
}
return false
} | [
"func",
"(",
"n",
"*",
"network",
")",
"contains",
"(",
"ip",
"net",
".",
"IP",
")",
"bool",
"{",
"for",
"_",
",",
"s",
":=",
"range",
"n",
".",
"subnets",
"{",
"if",
"s",
".",
"subnetIP",
".",
"Contains",
"(",
"ip",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // contains return true if the passed ip belongs to one the network's
// subnets | [
"contains",
"return",
"true",
"if",
"the",
"passed",
"ip",
"belongs",
"to",
"one",
"the",
"network",
"s",
"subnets"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/overlay/ov_network_windows.go#L341-L349 | train |
docker/libnetwork | drivers/windows/overlay/ov_network_windows.go | getMatchingSubnet | func (n *network) getMatchingSubnet(ip *net.IPNet) *subnet {
if ip == nil {
return nil
}
for _, s := range n.subnets {
// first check if the mask lengths are the same
i, _ := s.subnetIP.Mask.Size()
j, _ := ip.Mask.Size()
if i != j {
continue
}
if s.subnetIP.IP.Equal(ip.IP) {
return s
}
}
return nil
} | go | func (n *network) getMatchingSubnet(ip *net.IPNet) *subnet {
if ip == nil {
return nil
}
for _, s := range n.subnets {
// first check if the mask lengths are the same
i, _ := s.subnetIP.Mask.Size()
j, _ := ip.Mask.Size()
if i != j {
continue
}
if s.subnetIP.IP.Equal(ip.IP) {
return s
}
}
return nil
} | [
"func",
"(",
"n",
"*",
"network",
")",
"getMatchingSubnet",
"(",
"ip",
"*",
"net",
".",
"IPNet",
")",
"*",
"subnet",
"{",
"if",
"ip",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"n",
".",
"subnets",
"{",
"// first check if the mask lengths are the same",
"i",
",",
"_",
":=",
"s",
".",
"subnetIP",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"j",
",",
"_",
":=",
"ip",
".",
"Mask",
".",
"Size",
"(",
")",
"\n",
"if",
"i",
"!=",
"j",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"s",
".",
"subnetIP",
".",
"IP",
".",
"Equal",
"(",
"ip",
".",
"IP",
")",
"{",
"return",
"s",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // getMatchingSubnet return the network's subnet that matches the input | [
"getMatchingSubnet",
"return",
"the",
"network",
"s",
"subnet",
"that",
"matches",
"the",
"input"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/drivers/windows/overlay/ov_network_windows.go#L368-L384 | train |
docker/libnetwork | ipam/structures.go | String | func (r *AddressRange) String() string {
return fmt.Sprintf("Sub: %s, range [%d, %d]", r.Sub, r.Start, r.End)
} | go | func (r *AddressRange) String() string {
return fmt.Sprintf("Sub: %s, range [%d, %d]", r.Sub, r.Start, r.End)
} | [
"func",
"(",
"r",
"*",
"AddressRange",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"Sub",
",",
"r",
".",
"Start",
",",
"r",
".",
"End",
")",
"\n",
"}"
] | // String returns the string form of the AddressRange object | [
"String",
"returns",
"the",
"string",
"form",
"of",
"the",
"AddressRange",
"object"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L50-L52 | train |
docker/libnetwork | ipam/structures.go | MarshalJSON | func (r *AddressRange) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"Sub": r.Sub.String(),
"Start": r.Start,
"End": r.End,
}
return json.Marshal(m)
} | go | func (r *AddressRange) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"Sub": r.Sub.String(),
"Start": r.Start,
"End": r.End,
}
return json.Marshal(m)
} | [
"func",
"(",
"r",
"*",
"AddressRange",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"r",
".",
"Sub",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"r",
".",
"Start",
",",
"\"",
"\"",
":",
"r",
".",
"End",
",",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"m",
")",
"\n",
"}"
] | // MarshalJSON returns the JSON encoding of the Range object | [
"MarshalJSON",
"returns",
"the",
"JSON",
"encoding",
"of",
"the",
"Range",
"object"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L55-L62 | train |
docker/libnetwork | ipam/structures.go | UnmarshalJSON | func (r *AddressRange) UnmarshalJSON(data []byte) error {
m := map[string]interface{}{}
err := json.Unmarshal(data, &m)
if err != nil {
return err
}
if r.Sub, err = types.ParseCIDR(m["Sub"].(string)); err != nil {
return err
}
r.Start = uint64(m["Start"].(float64))
r.End = uint64(m["End"].(float64))
return nil
} | go | func (r *AddressRange) UnmarshalJSON(data []byte) error {
m := map[string]interface{}{}
err := json.Unmarshal(data, &m)
if err != nil {
return err
}
if r.Sub, err = types.ParseCIDR(m["Sub"].(string)); err != nil {
return err
}
r.Start = uint64(m["Start"].(float64))
r.End = uint64(m["End"].(float64))
return nil
} | [
"func",
"(",
"r",
"*",
"AddressRange",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"Sub",
",",
"err",
"=",
"types",
".",
"ParseCIDR",
"(",
"m",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"r",
".",
"Start",
"=",
"uint64",
"(",
"m",
"[",
"\"",
"\"",
"]",
".",
"(",
"float64",
")",
")",
"\n",
"r",
".",
"End",
"=",
"uint64",
"(",
"m",
"[",
"\"",
"\"",
"]",
".",
"(",
"float64",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON decodes data into the Range object | [
"UnmarshalJSON",
"decodes",
"data",
"into",
"the",
"Range",
"object"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L65-L77 | train |
docker/libnetwork | ipam/structures.go | String | func (s *SubnetKey) String() string {
k := fmt.Sprintf("%s/%s", s.AddressSpace, s.Subnet)
if s.ChildSubnet != "" {
k = fmt.Sprintf("%s/%s", k, s.ChildSubnet)
}
return k
} | go | func (s *SubnetKey) String() string {
k := fmt.Sprintf("%s/%s", s.AddressSpace, s.Subnet)
if s.ChildSubnet != "" {
k = fmt.Sprintf("%s/%s", k, s.ChildSubnet)
}
return k
} | [
"func",
"(",
"s",
"*",
"SubnetKey",
")",
"String",
"(",
")",
"string",
"{",
"k",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"AddressSpace",
",",
"s",
".",
"Subnet",
")",
"\n",
"if",
"s",
".",
"ChildSubnet",
"!=",
"\"",
"\"",
"{",
"k",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
",",
"s",
".",
"ChildSubnet",
")",
"\n",
"}",
"\n",
"return",
"k",
"\n",
"}"
] | // String returns the string form of the SubnetKey object | [
"String",
"returns",
"the",
"string",
"form",
"of",
"the",
"SubnetKey",
"object"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L80-L86 | train |
docker/libnetwork | ipam/structures.go | FromString | func (s *SubnetKey) FromString(str string) error {
if str == "" || !strings.Contains(str, "/") {
return types.BadRequestErrorf("invalid string form for subnetkey: %s", str)
}
p := strings.Split(str, "/")
if len(p) != 3 && len(p) != 5 {
return types.BadRequestErrorf("invalid string form for subnetkey: %s", str)
}
s.AddressSpace = p[0]
s.Subnet = fmt.Sprintf("%s/%s", p[1], p[2])
if len(p) == 5 {
s.ChildSubnet = fmt.Sprintf("%s/%s", p[3], p[4])
}
return nil
} | go | func (s *SubnetKey) FromString(str string) error {
if str == "" || !strings.Contains(str, "/") {
return types.BadRequestErrorf("invalid string form for subnetkey: %s", str)
}
p := strings.Split(str, "/")
if len(p) != 3 && len(p) != 5 {
return types.BadRequestErrorf("invalid string form for subnetkey: %s", str)
}
s.AddressSpace = p[0]
s.Subnet = fmt.Sprintf("%s/%s", p[1], p[2])
if len(p) == 5 {
s.ChildSubnet = fmt.Sprintf("%s/%s", p[3], p[4])
}
return nil
} | [
"func",
"(",
"s",
"*",
"SubnetKey",
")",
"FromString",
"(",
"str",
"string",
")",
"error",
"{",
"if",
"str",
"==",
"\"",
"\"",
"||",
"!",
"strings",
".",
"Contains",
"(",
"str",
",",
"\"",
"\"",
")",
"{",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"str",
")",
"\n",
"}",
"\n\n",
"p",
":=",
"strings",
".",
"Split",
"(",
"str",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"p",
")",
"!=",
"3",
"&&",
"len",
"(",
"p",
")",
"!=",
"5",
"{",
"return",
"types",
".",
"BadRequestErrorf",
"(",
"\"",
"\"",
",",
"str",
")",
"\n",
"}",
"\n",
"s",
".",
"AddressSpace",
"=",
"p",
"[",
"0",
"]",
"\n",
"s",
".",
"Subnet",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
"[",
"1",
"]",
",",
"p",
"[",
"2",
"]",
")",
"\n",
"if",
"len",
"(",
"p",
")",
"==",
"5",
"{",
"s",
".",
"ChildSubnet",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
"[",
"3",
"]",
",",
"p",
"[",
"4",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // FromString populates the SubnetKey object reading it from string | [
"FromString",
"populates",
"the",
"SubnetKey",
"object",
"reading",
"it",
"from",
"string"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L89-L105 | train |
docker/libnetwork | ipam/structures.go | String | func (p *PoolData) String() string {
return fmt.Sprintf("ParentKey: %s, Pool: %s, Range: %s, RefCount: %d",
p.ParentKey.String(), p.Pool.String(), p.Range, p.RefCount)
} | go | func (p *PoolData) String() string {
return fmt.Sprintf("ParentKey: %s, Pool: %s, Range: %s, RefCount: %d",
p.ParentKey.String(), p.Pool.String(), p.Range, p.RefCount)
} | [
"func",
"(",
"p",
"*",
"PoolData",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"ParentKey",
".",
"String",
"(",
")",
",",
"p",
".",
"Pool",
".",
"String",
"(",
")",
",",
"p",
".",
"Range",
",",
"p",
".",
"RefCount",
")",
"\n",
"}"
] | // String returns the string form of the PoolData object | [
"String",
"returns",
"the",
"string",
"form",
"of",
"the",
"PoolData",
"object"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L108-L111 | train |
docker/libnetwork | ipam/structures.go | MarshalJSON | func (p *PoolData) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"ParentKey": p.ParentKey,
"RefCount": p.RefCount,
}
if p.Pool != nil {
m["Pool"] = p.Pool.String()
}
if p.Range != nil {
m["Range"] = p.Range
}
return json.Marshal(m)
} | go | func (p *PoolData) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"ParentKey": p.ParentKey,
"RefCount": p.RefCount,
}
if p.Pool != nil {
m["Pool"] = p.Pool.String()
}
if p.Range != nil {
m["Range"] = p.Range
}
return json.Marshal(m)
} | [
"func",
"(",
"p",
"*",
"PoolData",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"p",
".",
"ParentKey",
",",
"\"",
"\"",
":",
"p",
".",
"RefCount",
",",
"}",
"\n",
"if",
"p",
".",
"Pool",
"!=",
"nil",
"{",
"m",
"[",
"\"",
"\"",
"]",
"=",
"p",
".",
"Pool",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"if",
"p",
".",
"Range",
"!=",
"nil",
"{",
"m",
"[",
"\"",
"\"",
"]",
"=",
"p",
".",
"Range",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"m",
")",
"\n",
"}"
] | // MarshalJSON returns the JSON encoding of the PoolData object | [
"MarshalJSON",
"returns",
"the",
"JSON",
"encoding",
"of",
"the",
"PoolData",
"object"
] | 9ff9b57c344df5cd47443ad9e65702ec85c5aeb0 | https://github.com/docker/libnetwork/blob/9ff9b57c344df5cd47443ad9e65702ec85c5aeb0/ipam/structures.go#L114-L126 | train |
Subsets and Splits