id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
25,800 | veandco/go-sdl2 | sdl/pixels.go | Uint32 | func (c Color) Uint32() uint32 {
var v uint32
v |= uint32(c.R) << 24
v |= uint32(c.G) << 16
v |= uint32(c.B) << 8
v |= uint32(c.A)
return v
} | go | func (c Color) Uint32() uint32 {
var v uint32
v |= uint32(c.R) << 24
v |= uint32(c.G) << 16
v |= uint32(c.B) << 8
v |= uint32(c.A)
return v
} | [
"func",
"(",
"c",
"Color",
")",
"Uint32",
"(",
")",
"uint32",
"{",
"var",
"v",
"uint32",
"\n",
"v",
"|=",
"uint32",
"(",
"c",
".",
"R",
")",
"<<",
"24",
"\n",
"v",
"|=",
"uint32",
"(",
"c",
".",
"G",
")",
"<<",
"16",
"\n",
"v",
"|=",
"uint3... | // Uint32 return uint32 representation of RGBA color. | [
"Uint32",
"return",
"uint32",
"representation",
"of",
"RGBA",
"color",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/pixels.go#L75-L82 |
25,801 | veandco/go-sdl2 | sdl/pixels.go | BytesPerPixel | func BytesPerPixel(format uint32) int {
return int(C.bytesPerPixel(C.Uint32(format)))
} | go | func BytesPerPixel(format uint32) int {
return int(C.bytesPerPixel(C.Uint32(format)))
} | [
"func",
"BytesPerPixel",
"(",
"format",
"uint32",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"bytesPerPixel",
"(",
"C",
".",
"Uint32",
"(",
"format",
")",
")",
")",
"\n",
"}"
] | // BytesPerPixel returns the number of bytes per pixel for the given format | [
"BytesPerPixel",
"returns",
"the",
"number",
"of",
"bytes",
"per",
"pixel",
"for",
"the",
"given",
"format"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/pixels.go#L334-L336 |
25,802 | veandco/go-sdl2 | sdl/pixels.go | BitsPerPixel | func BitsPerPixel(format uint32) int {
return int(C.bitsPerPixel(C.Uint32(format)))
} | go | func BitsPerPixel(format uint32) int {
return int(C.bitsPerPixel(C.Uint32(format)))
} | [
"func",
"BitsPerPixel",
"(",
"format",
"uint32",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"bitsPerPixel",
"(",
"C",
".",
"Uint32",
"(",
"format",
")",
")",
")",
"\n",
"}"
] | // BitsPerPixel returns the number of bits per pixel for the given format | [
"BitsPerPixel",
"returns",
"the",
"number",
"of",
"bits",
"per",
"pixel",
"for",
"the",
"given",
"format"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/pixels.go#L339-L341 |
25,803 | veandco/go-sdl2 | mix/midi.go | EachSoundFont | func EachSoundFont(function func(string) int) int {
eachSoundFontFunc = function
return int(C.Mix_EachSoundFont((*[0]byte)(C.callEachSoundFont), nil))
} | go | func EachSoundFont(function func(string) int) int {
eachSoundFontFunc = function
return int(C.Mix_EachSoundFont((*[0]byte)(C.callEachSoundFont), nil))
} | [
"func",
"EachSoundFont",
"(",
"function",
"func",
"(",
"string",
")",
"int",
")",
"int",
"{",
"eachSoundFontFunc",
"=",
"function",
"\n",
"return",
"int",
"(",
"C",
".",
"Mix_EachSoundFont",
"(",
"(",
"*",
"[",
"0",
"]",
"byte",
")",
"(",
"C",
".",
"... | // EachSoundFont iterates over SoundFonts paths to use by supported MIDI backends. | [
"EachSoundFont",
"iterates",
"over",
"SoundFonts",
"paths",
"to",
"use",
"by",
"supported",
"MIDI",
"backends",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/midi.go#L19-L22 |
25,804 | veandco/go-sdl2 | mix/midi.go | SetSoundFonts | func SetSoundFonts(paths string) bool {
_paths := C.CString(paths)
defer C.free(unsafe.Pointer(_paths))
return int(C.Mix_SetSoundFonts(_paths)) == 0
} | go | func SetSoundFonts(paths string) bool {
_paths := C.CString(paths)
defer C.free(unsafe.Pointer(_paths))
return int(C.Mix_SetSoundFonts(_paths)) == 0
} | [
"func",
"SetSoundFonts",
"(",
"paths",
"string",
")",
"bool",
"{",
"_paths",
":=",
"C",
".",
"CString",
"(",
"paths",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"_paths",
")",
")",
"\n",
"return",
"int",
"(",
"C",
"."... | // SetSoundFonts sets SoundFonts paths to use by supported MIDI backends. | [
"SetSoundFonts",
"sets",
"SoundFonts",
"paths",
"to",
"use",
"by",
"supported",
"MIDI",
"backends",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/midi.go#L25-L29 |
25,805 | veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceVendor | func JoystickGetDeviceVendor(index int) int {
return int(C.SDL_JoystickGetDeviceVendor(C.int(index)))
} | go | func JoystickGetDeviceVendor(index int) int {
return int(C.SDL_JoystickGetDeviceVendor(C.int(index)))
} | [
"func",
"JoystickGetDeviceVendor",
"(",
"index",
"int",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"SDL_JoystickGetDeviceVendor",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceVendor returns the USB vendor ID of a joystick, if available, 0 otherwise. | [
"JoystickGetDeviceVendor",
"returns",
"the",
"USB",
"vendor",
"ID",
"of",
"a",
"joystick",
"if",
"available",
"0",
"otherwise",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L276-L278 |
25,806 | veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceProduct | func JoystickGetDeviceProduct(index int) int {
return int(C.SDL_JoystickGetDeviceProduct(C.int(index)))
} | go | func JoystickGetDeviceProduct(index int) int {
return int(C.SDL_JoystickGetDeviceProduct(C.int(index)))
} | [
"func",
"JoystickGetDeviceProduct",
"(",
"index",
"int",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"SDL_JoystickGetDeviceProduct",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceProduct returns the USB product ID of a joystick, if available, 0 otherwise. | [
"JoystickGetDeviceProduct",
"returns",
"the",
"USB",
"product",
"ID",
"of",
"a",
"joystick",
"if",
"available",
"0",
"otherwise",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L281-L283 |
25,807 | veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceProductVersion | func JoystickGetDeviceProductVersion(index int) int {
return int(C.SDL_JoystickGetDeviceProductVersion(C.int(index)))
} | go | func JoystickGetDeviceProductVersion(index int) int {
return int(C.SDL_JoystickGetDeviceProductVersion(C.int(index)))
} | [
"func",
"JoystickGetDeviceProductVersion",
"(",
"index",
"int",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"SDL_JoystickGetDeviceProductVersion",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceProductVersion returns the product version of a joystick, if available, 0 otherwise. | [
"JoystickGetDeviceProductVersion",
"returns",
"the",
"product",
"version",
"of",
"a",
"joystick",
"if",
"available",
"0",
"otherwise",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L286-L288 |
25,808 | veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceType | func JoystickGetDeviceType(index int) JoystickType {
return JoystickType(C.SDL_JoystickGetDeviceType(C.int(index)))
} | go | func JoystickGetDeviceType(index int) JoystickType {
return JoystickType(C.SDL_JoystickGetDeviceType(C.int(index)))
} | [
"func",
"JoystickGetDeviceType",
"(",
"index",
"int",
")",
"JoystickType",
"{",
"return",
"JoystickType",
"(",
"C",
".",
"SDL_JoystickGetDeviceType",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceType returns the type of a joystick. | [
"JoystickGetDeviceType",
"returns",
"the",
"type",
"of",
"a",
"joystick",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L291-L293 |
25,809 | veandco/go-sdl2 | sdl/joystick.go | JoystickGetDeviceInstanceID | func JoystickGetDeviceInstanceID(index int) JoystickID {
return JoystickID(C.SDL_JoystickGetDeviceInstanceID(C.int(index)))
} | go | func JoystickGetDeviceInstanceID(index int) JoystickID {
return JoystickID(C.SDL_JoystickGetDeviceInstanceID(C.int(index)))
} | [
"func",
"JoystickGetDeviceInstanceID",
"(",
"index",
"int",
")",
"JoystickID",
"{",
"return",
"JoystickID",
"(",
"C",
".",
"SDL_JoystickGetDeviceInstanceID",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
")",
"\n",
"}"
] | // JoystickGetDeviceInstanceID returns the instance ID of a joystick. | [
"JoystickGetDeviceInstanceID",
"returns",
"the",
"instance",
"ID",
"of",
"a",
"joystick",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L296-L298 |
25,810 | veandco/go-sdl2 | sdl/joystick.go | AxisInitialState | func (joy *Joystick) AxisInitialState(axis int) (state int16, ok bool) {
ok = C.SDL_JoystickGetAxisInitialState(joy.cptr(), C.int(axis), (*C.Sint16)(&state)) == C.SDL_TRUE
return
} | go | func (joy *Joystick) AxisInitialState(axis int) (state int16, ok bool) {
ok = C.SDL_JoystickGetAxisInitialState(joy.cptr(), C.int(axis), (*C.Sint16)(&state)) == C.SDL_TRUE
return
} | [
"func",
"(",
"joy",
"*",
"Joystick",
")",
"AxisInitialState",
"(",
"axis",
"int",
")",
"(",
"state",
"int16",
",",
"ok",
"bool",
")",
"{",
"ok",
"=",
"C",
".",
"SDL_JoystickGetAxisInitialState",
"(",
"joy",
".",
"cptr",
"(",
")",
",",
"C",
".",
"int"... | // AxisInitialState returns the initial state of an axis control on a joystick, ok is true if this axis has any initial value. | [
"AxisInitialState",
"returns",
"the",
"initial",
"state",
"of",
"an",
"axis",
"control",
"on",
"a",
"joystick",
"ok",
"is",
"true",
"if",
"this",
"axis",
"has",
"any",
"initial",
"value",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/joystick.go#L429-L432 |
25,811 | oxequa/realize | realize/settings.go | Set | func (l *Legacy) Set(status bool, interval int) {
l.Force = true
l.Interval = time.Duration(interval) * time.Second
} | go | func (l *Legacy) Set(status bool, interval int) {
l.Force = true
l.Interval = time.Duration(interval) * time.Second
} | [
"func",
"(",
"l",
"*",
"Legacy",
")",
"Set",
"(",
"status",
"bool",
",",
"interval",
"int",
")",
"{",
"l",
".",
"Force",
"=",
"true",
"\n",
"l",
".",
"Interval",
"=",
"time",
".",
"Duration",
"(",
"interval",
")",
"*",
"time",
".",
"Second",
"\n"... | // Set legacy watcher with an interval | [
"Set",
"legacy",
"watcher",
"with",
"an",
"interval"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L65-L68 |
25,812 | oxequa/realize | realize/settings.go | Remove | func (s *Settings) Remove(d string) error {
_, err := os.Stat(d)
if !os.IsNotExist(err) {
return os.RemoveAll(d)
}
return err
} | go | func (s *Settings) Remove(d string) error {
_, err := os.Stat(d)
if !os.IsNotExist(err) {
return os.RemoveAll(d)
}
return err
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Remove",
"(",
"d",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"d",
")",
"\n",
"if",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"os",
".",
"RemoveAll",
... | // Remove realize folder | [
"Remove",
"realize",
"folder"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L71-L77 |
25,813 | oxequa/realize | realize/settings.go | Read | func (s *Settings) Read(out interface{}) error {
// backward compatibility
if _, err := os.Stat(RFile); err != nil {
return err
}
content, err := s.Stream(RFile)
if err == nil {
err = yaml.Unmarshal(content, out)
return err
}
return err
} | go | func (s *Settings) Read(out interface{}) error {
// backward compatibility
if _, err := os.Stat(RFile); err != nil {
return err
}
content, err := s.Stream(RFile)
if err == nil {
err = yaml.Unmarshal(content, out)
return err
}
return err
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Read",
"(",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"// backward compatibility",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"RFile",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n... | // Read config file | [
"Read",
"config",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L80-L91 |
25,814 | oxequa/realize | realize/settings.go | Write | func (s *Settings) Write(out interface{}) error {
y, err := yaml.Marshal(out)
if err != nil {
return err
}
s.Fatal(ioutil.WriteFile(RFile, y, Permission))
return nil
} | go | func (s *Settings) Write(out interface{}) error {
y, err := yaml.Marshal(out)
if err != nil {
return err
}
s.Fatal(ioutil.WriteFile(RFile, y, Permission))
return nil
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Write",
"(",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"y",
",",
"err",
":=",
"yaml",
".",
"Marshal",
"(",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"s",
... | // Write config file | [
"Write",
"config",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L94-L101 |
25,815 | oxequa/realize | realize/settings.go | Stream | func (s Settings) Stream(file string) ([]byte, error) {
_, err := os.Stat(file)
if err != nil {
return nil, err
}
content, err := ioutil.ReadFile(file)
s.Fatal(err)
return content, err
} | go | func (s Settings) Stream(file string) ([]byte, error) {
_, err := os.Stat(file)
if err != nil {
return nil, err
}
content, err := ioutil.ReadFile(file)
s.Fatal(err)
return content, err
} | [
"func",
"(",
"s",
"Settings",
")",
"Stream",
"(",
"file",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"er... | // Stream return a byte stream of a given file | [
"Stream",
"return",
"a",
"byte",
"stream",
"of",
"a",
"given",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L104-L112 |
25,816 | oxequa/realize | realize/settings.go | Fatal | func (s Settings) Fatal(err error, msg ...interface{}) {
if err != nil {
if len(msg) > 0 {
log.Fatalln(Red.Regular(msg...), err.Error())
} else {
log.Fatalln(err.Error())
}
}
} | go | func (s Settings) Fatal(err error, msg ...interface{}) {
if err != nil {
if len(msg) > 0 {
log.Fatalln(Red.Regular(msg...), err.Error())
} else {
log.Fatalln(err.Error())
}
}
} | [
"func",
"(",
"s",
"Settings",
")",
"Fatal",
"(",
"err",
"error",
",",
"msg",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"if",
"len",
"(",
"msg",
")",
">",
"0",
"{",
"log",
".",
"Fatalln",
"(",
"Red",
".",
"Regular",
... | // Fatal prints a fatal error with its additional messages | [
"Fatal",
"prints",
"a",
"fatal",
"error",
"with",
"its",
"additional",
"messages"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L115-L123 |
25,817 | oxequa/realize | realize/settings.go | Create | func (s Settings) Create(path string, name string) *os.File {
file := filepath.Join(path, name)
out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, Permission)
s.Fatal(err)
return out
} | go | func (s Settings) Create(path string, name string) *os.File {
file := filepath.Join(path, name)
out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY|os.O_CREATE|os.O_SYNC, Permission)
s.Fatal(err)
return out
} | [
"func",
"(",
"s",
"Settings",
")",
"Create",
"(",
"path",
"string",
",",
"name",
"string",
")",
"*",
"os",
".",
"File",
"{",
"file",
":=",
"filepath",
".",
"Join",
"(",
"path",
",",
"name",
")",
"\n",
"out",
",",
"err",
":=",
"os",
".",
"OpenFile... | // Create a new file and return its pointer | [
"Create",
"a",
"new",
"file",
"and",
"return",
"its",
"pointer"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L126-L131 |
25,818 | oxequa/realize | realize/server.go | render | func (s *Server) render(c echo.Context, path string, mime int) error {
data, err := Asset(path)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound)
}
rs := c.Response()
// check content type by extensions
switch mime {
case 1:
rs.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
... | go | func (s *Server) render(c echo.Context, path string, mime int) error {
data, err := Asset(path)
if err != nil {
return echo.NewHTTPError(http.StatusNotFound)
}
rs := c.Response()
// check content type by extensions
switch mime {
case 1:
rs.Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8)
... | [
"func",
"(",
"s",
"*",
"Server",
")",
"render",
"(",
"c",
"echo",
".",
"Context",
",",
"path",
"string",
",",
"mime",
"int",
")",
"error",
"{",
"data",
",",
"err",
":=",
"Asset",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // Render return a web pages defined in bindata | [
"Render",
"return",
"a",
"web",
"pages",
"defined",
"in",
"bindata"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/server.go#L72-L99 |
25,819 | oxequa/realize | realize/server.go | Start | func (s *Server) Start() (err error) {
if s.Status {
e := echo.New()
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 2,
}))
e.Use(middleware.Recover())
// web panel
e.GET("/", func(c echo.Context) error {
return s.render(c, "assets/index.html", 1)
})
e.GET("/assets/js/all.min.js", ... | go | func (s *Server) Start() (err error) {
if s.Status {
e := echo.New()
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
Level: 2,
}))
e.Use(middleware.Recover())
// web panel
e.GET("/", func(c echo.Context) error {
return s.render(c, "assets/index.html", 1)
})
e.GET("/assets/js/all.min.js", ... | [
"func",
"(",
"s",
"*",
"Server",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"s",
".",
"Status",
"{",
"e",
":=",
"echo",
".",
"New",
"(",
")",
"\n",
"e",
".",
"Use",
"(",
"middleware",
".",
"GzipWithConfig",
"(",
"middleware",
... | // Start the web server | [
"Start",
"the",
"web",
"server"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/server.go#L109-L165 |
25,820 | oxequa/realize | realize/server.go | OpenURL | func (s *Server) OpenURL() error {
url := "http://" + string(s.Parent.Server.Host) + ":" + strconv.Itoa(s.Parent.Server.Port)
stderr := bytes.Buffer{}
cmd := map[string]string{
"windows": "start",
"darwin": "open",
"linux": "xdg-open",
}
if s.Open {
open, err := cmd[runtime.GOOS]
if !err {
return f... | go | func (s *Server) OpenURL() error {
url := "http://" + string(s.Parent.Server.Host) + ":" + strconv.Itoa(s.Parent.Server.Port)
stderr := bytes.Buffer{}
cmd := map[string]string{
"windows": "start",
"darwin": "open",
"linux": "xdg-open",
}
if s.Open {
open, err := cmd[runtime.GOOS]
if !err {
return f... | [
"func",
"(",
"s",
"*",
"Server",
")",
"OpenURL",
"(",
")",
"error",
"{",
"url",
":=",
"\"",
"\"",
"+",
"string",
"(",
"s",
".",
"Parent",
".",
"Server",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"s",
".",
"Parent",
... | // OpenURL in a new tab of default browser | [
"OpenURL",
"in",
"a",
"new",
"tab",
"of",
"default",
"browser"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/server.go#L168-L188 |
25,821 | oxequa/realize | realize/settings_unix.go | Flimit | func (s *Settings) Flimit() error {
var rLimit syscall.Rlimit
rLimit.Max = uint64(s.FileLimit)
rLimit.Cur = uint64(s.FileLimit)
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
} | go | func (s *Settings) Flimit() error {
var rLimit syscall.Rlimit
rLimit.Max = uint64(s.FileLimit)
rLimit.Cur = uint64(s.FileLimit)
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
} | [
"func",
"(",
"s",
"*",
"Settings",
")",
"Flimit",
"(",
")",
"error",
"{",
"var",
"rLimit",
"syscall",
".",
"Rlimit",
"\n",
"rLimit",
".",
"Max",
"=",
"uint64",
"(",
"s",
".",
"FileLimit",
")",
"\n",
"rLimit",
".",
"Cur",
"=",
"uint64",
"(",
"s",
... | // Flimit defines the max number of watched files | [
"Flimit",
"defines",
"the",
"max",
"number",
"of",
"watched",
"files"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings_unix.go#L8-L14 |
25,822 | oxequa/realize | realize/cli.go | Stop | func (r *Realize) Stop() error {
for k := range r.Schema.Projects {
if r.Schema.Projects[k].exit != nil {
close(r.Schema.Projects[k].exit)
}
}
return nil
} | go | func (r *Realize) Stop() error {
for k := range r.Schema.Projects {
if r.Schema.Projects[k].exit != nil {
close(r.Schema.Projects[k].exit)
}
}
return nil
} | [
"func",
"(",
"r",
"*",
"Realize",
")",
"Stop",
"(",
")",
"error",
"{",
"for",
"k",
":=",
"range",
"r",
".",
"Schema",
".",
"Projects",
"{",
"if",
"r",
".",
"Schema",
".",
"Projects",
"[",
"k",
"]",
".",
"exit",
"!=",
"nil",
"{",
"close",
"(",
... | // Stop realize workflow | [
"Stop",
"realize",
"workflow"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/cli.go#L76-L83 |
25,823 | oxequa/realize | realize/cli.go | Prefix | func (r *Realize) Prefix(input string) string {
if len(input) > 0 {
return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(RPrefix), Yellow.Bold("]"), " : ", input)
}
return input
} | go | func (r *Realize) Prefix(input string) string {
if len(input) > 0 {
return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(RPrefix), Yellow.Bold("]"), " : ", input)
}
return input
} | [
"func",
"(",
"r",
"*",
"Realize",
")",
"Prefix",
"(",
"input",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"input",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Sprint",
"(",
"Yellow",
".",
"Bold",
"(",
"\"",
"\"",
")",
",",
"strings",
".",
"... | // Prefix a given string with tool name | [
"Prefix",
"a",
"given",
"string",
"with",
"tool",
"name"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/cli.go#L104-L109 |
25,824 | oxequa/realize | realize/cli.go | Write | func (w LogWriter) Write(bytes []byte) (int, error) {
if len(bytes) > 0 {
return fmt.Fprint(Output, Yellow.Regular("["), time.Now().Format("15:04:05"), Yellow.Regular("]"), string(bytes))
}
return 0, nil
} | go | func (w LogWriter) Write(bytes []byte) (int, error) {
if len(bytes) > 0 {
return fmt.Fprint(Output, Yellow.Regular("["), time.Now().Format("15:04:05"), Yellow.Regular("]"), string(bytes))
}
return 0, nil
} | [
"func",
"(",
"w",
"LogWriter",
")",
"Write",
"(",
"bytes",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"bytes",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Fprint",
"(",
"Output",
",",
"Yellow",
".",
"Regular",
"... | // Rewrite the layout of the log timestamp | [
"Rewrite",
"the",
"layout",
"of",
"the",
"log",
"timestamp"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/cli.go#L112-L117 |
25,825 | oxequa/realize | realize/projects.go | After | func (p *Project) After() {
if p.parent.After != nil {
p.parent.After(Context{Project: p})
return
}
p.cmd(nil, "after", true)
} | go | func (p *Project) After() {
if p.parent.After != nil {
p.parent.After(Context{Project: p})
return
}
p.cmd(nil, "after", true)
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"After",
"(",
")",
"{",
"if",
"p",
".",
"parent",
".",
"After",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"After",
"(",
"Context",
"{",
"Project",
":",
"p",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n",
"p... | // After stop watcher | [
"After",
"stop",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L103-L109 |
25,826 | oxequa/realize | realize/projects.go | Before | func (p *Project) Before() {
if p.parent.Before != nil {
p.parent.Before(Context{Project: p})
return
}
if hasGoMod(Wdir()) {
p.Tools.vgo = true
}
// setup go tools
p.Tools.Setup()
// global commands before
p.cmd(p.stop, "before", true)
// indexing files and dirs
for _, dir := range p.Watcher.Paths {
... | go | func (p *Project) Before() {
if p.parent.Before != nil {
p.parent.Before(Context{Project: p})
return
}
if hasGoMod(Wdir()) {
p.Tools.vgo = true
}
// setup go tools
p.Tools.Setup()
// global commands before
p.cmd(p.stop, "before", true)
// indexing files and dirs
for _, dir := range p.Watcher.Paths {
... | [
"func",
"(",
"p",
"*",
"Project",
")",
"Before",
"(",
")",
"{",
"if",
"p",
".",
"parent",
".",
"Before",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Before",
"(",
"Context",
"{",
"Project",
":",
"p",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n\n",... | // Before start watcher | [
"Before",
"start",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L112-L140 |
25,827 | oxequa/realize | realize/projects.go | Change | func (p *Project) Change(event fsnotify.Event) {
if p.parent.Change != nil {
p.parent.Change(Context{Project: p, Event: event})
return
}
// file extension
ext := ext(event.Name)
if ext == "" {
ext = "DIR"
}
// change message
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", Magenta.Bold(strings.ToUpper(ext)), "... | go | func (p *Project) Change(event fsnotify.Event) {
if p.parent.Change != nil {
p.parent.Change(Context{Project: p, Event: event})
return
}
// file extension
ext := ext(event.Name)
if ext == "" {
ext = "DIR"
}
// change message
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", Magenta.Bold(strings.ToUpper(ext)), "... | [
"func",
"(",
"p",
"*",
"Project",
")",
"Change",
"(",
"event",
"fsnotify",
".",
"Event",
")",
"{",
"if",
"p",
".",
"parent",
".",
"Change",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Change",
"(",
"Context",
"{",
"Project",
":",
"p",
",",
"Event... | // Change event message | [
"Change",
"event",
"message"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L156-L170 |
25,828 | oxequa/realize | realize/projects.go | Watch | func (p *Project) Watch(wg *sync.WaitGroup) {
var err error
// change channel
p.stop = make(chan bool)
// init a new watcher
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
if err != nil {
log.Fatal(err)
}
defer func() {
close(p.stop)
p.watcher.Close()
}()
// before start checks
p.Before()
/... | go | func (p *Project) Watch(wg *sync.WaitGroup) {
var err error
// change channel
p.stop = make(chan bool)
// init a new watcher
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
if err != nil {
log.Fatal(err)
}
defer func() {
close(p.stop)
p.watcher.Close()
}()
// before start checks
p.Before()
/... | [
"func",
"(",
"p",
"*",
"Project",
")",
"Watch",
"(",
"wg",
"*",
"sync",
".",
"WaitGroup",
")",
"{",
"var",
"err",
"error",
"\n",
"// change channel",
"p",
".",
"stop",
"=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"// init a new watcher",
"p",
".",
"w... | // Watch a project | [
"Watch",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L277-L342 |
25,829 | oxequa/realize | realize/projects.go | Validate | func (p *Project) Validate(path string, fcheck bool) bool {
if len(path) == 0 {
return false
}
// check if skip hidden
if p.Watcher.Hidden && isHidden(path) {
return false
}
// check for a valid ext or path
if e := ext(path); e != "" {
if len(p.Watcher.Exts) == 0 {
return false
}
// check ignored
... | go | func (p *Project) Validate(path string, fcheck bool) bool {
if len(path) == 0 {
return false
}
// check if skip hidden
if p.Watcher.Hidden && isHidden(path) {
return false
}
// check for a valid ext or path
if e := ext(path); e != "" {
if len(p.Watcher.Exts) == 0 {
return false
}
// check ignored
... | [
"func",
"(",
"p",
"*",
"Project",
")",
"Validate",
"(",
"path",
"string",
",",
"fcheck",
"bool",
")",
"bool",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// check if skip hidden",
"if",
"p",
".",
"Watcher"... | // Validate a file path | [
"Validate",
"a",
"file",
"path"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L345-L386 |
25,830 | oxequa/realize | realize/projects.go | pname | func (p *Project) pname(name string, color int) string {
switch color {
case 1:
name = Yellow.Regular("[") + strings.ToUpper(name) + Yellow.Regular("]")
break
case 2:
name = Yellow.Regular("[") + Red.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 3:
name = Yellow.Regular("[") + Blue.Bold(str... | go | func (p *Project) pname(name string, color int) string {
switch color {
case 1:
name = Yellow.Regular("[") + strings.ToUpper(name) + Yellow.Regular("]")
break
case 2:
name = Yellow.Regular("[") + Red.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 3:
name = Yellow.Regular("[") + Blue.Bold(str... | [
"func",
"(",
"p",
"*",
"Project",
")",
"pname",
"(",
"name",
"string",
",",
"color",
"int",
")",
"string",
"{",
"switch",
"color",
"{",
"case",
"1",
":",
"name",
"=",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"+",
"strings",
".",
"ToUpper",
... | // Defines the colors scheme for the project name | [
"Defines",
"the",
"colors",
"scheme",
"for",
"the",
"project",
"name"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L389-L408 |
25,831 | oxequa/realize | realize/projects.go | tools | func (p *Project) tools(stop <-chan bool, path string, fi os.FileInfo) {
done := make(chan bool)
result := make(chan Response)
v := reflect.ValueOf(p.Tools)
go func() {
for i := 0; i < v.NumField()-1; i++ {
tool := v.Field(i).Interface().(Tool)
tool.parent = p
if tool.Status && tool.isTool {
if fi.Is... | go | func (p *Project) tools(stop <-chan bool, path string, fi os.FileInfo) {
done := make(chan bool)
result := make(chan Response)
v := reflect.ValueOf(p.Tools)
go func() {
for i := 0; i < v.NumField()-1; i++ {
tool := v.Field(i).Interface().(Tool)
tool.parent = p
if tool.Status && tool.isTool {
if fi.Is... | [
"func",
"(",
"p",
"*",
"Project",
")",
"tools",
"(",
"stop",
"<-",
"chan",
"bool",
",",
"path",
"string",
",",
"fi",
"os",
".",
"FileInfo",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"result",
":=",
"make",
"(",
"chan",
"Resp... | // Tool logs the result of a go command | [
"Tool",
"logs",
"the",
"result",
"of",
"a",
"go",
"command"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L411-L452 |
25,832 | oxequa/realize | realize/projects.go | walk | func (p *Project) walk(path string, info os.FileInfo, err error) error {
if p.shouldIgnore(path) {
return filepath.SkipDir
}
if p.Validate(path, true) {
result := p.watcher.Walk(path, p.init)
if result != "" {
if p.parent.Settings.Recovery.Index {
log.Println("Indexing", path)
}
p.tools(p.stop, p... | go | func (p *Project) walk(path string, info os.FileInfo, err error) error {
if p.shouldIgnore(path) {
return filepath.SkipDir
}
if p.Validate(path, true) {
result := p.watcher.Walk(path, p.init)
if result != "" {
if p.parent.Settings.Recovery.Index {
log.Println("Indexing", path)
}
p.tools(p.stop, p... | [
"func",
"(",
"p",
"*",
"Project",
")",
"walk",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"p",
".",
"shouldIgnore",
"(",
"path",
")",
"{",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}"... | // Watch the files tree of a project | [
"Watch",
"the",
"files",
"tree",
"of",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L487-L509 |
25,833 | oxequa/realize | realize/projects.go | stamp | func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
ctime := time.Now()
content := []string{ctime.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n", stream}
switch t {
case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.parent.Settings.Files.Outputs.St... | go | func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
ctime := time.Now()
content := []string{ctime.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n", stream}
switch t {
case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.parent.Settings.Files.Outputs.St... | [
"func",
"(",
"p",
"*",
"Project",
")",
"stamp",
"(",
"t",
"string",
",",
"o",
"BufferOut",
",",
"msg",
"string",
",",
"stream",
"string",
")",
"{",
"ctime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"content",
":=",
"[",
"]",
"string",
"{",
"ctim... | // Print on files, cli, ws | [
"Print",
"on",
"files",
"cli",
"ws"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L525-L563 |
25,834 | oxequa/realize | realize/projects.go | print | func (r *Response) print(start time.Time, p *Project) {
if r.Err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), "\n", r.Err.Error())
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out}
p.stamp("error", out, msg, r.Out)
} else {
msg = fmt.Sprintln(p.pname... | go | func (r *Response) print(start time.Time, p *Project) {
if r.Err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), "\n", r.Err.Error())
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: r.Name, Stream: r.Out}
p.stamp("error", out, msg, r.Out)
} else {
msg = fmt.Sprintln(p.pname... | [
"func",
"(",
"r",
"*",
"Response",
")",
"print",
"(",
"start",
"time",
".",
"Time",
",",
"p",
"*",
"Project",
")",
"{",
"if",
"r",
".",
"Err",
"!=",
"nil",
"{",
"msg",
"=",
"fmt",
".",
"Sprintln",
"(",
"p",
".",
"pname",
"(",
"p",
".",
"Name"... | // Print with time after | [
"Print",
"with",
"time",
"after"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L680-L690 |
25,835 | oxequa/realize | realize/projects.go | exec | func (c *Command) exec(base string, stop <-chan bool) (response Response) {
var stdout bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(c.Cmd, "'", "", -1), "\"", "", -1), " ")
ex := exec.Command(args[0], args[1:]...)
ex.Dir = base
// make cmd pa... | go | func (c *Command) exec(base string, stop <-chan bool) (response Response) {
var stdout bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(c.Cmd, "'", "", -1), "\"", "", -1), " ")
ex := exec.Command(args[0], args[1:]...)
ex.Dir = base
// make cmd pa... | [
"func",
"(",
"c",
"*",
"Command",
")",
"exec",
"(",
"base",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"var",
"stdout",
"bytes",
".",
"Buffer",
"\n",
"var",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"done",... | // Exec an additional command from a defined path if specified | [
"Exec",
"an",
"additional",
"command",
"from",
"a",
"defined",
"path",
"if",
"specified"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L693-L727 |
25,836 | oxequa/realize | realize.go | version | func version() {
log.Println(r.Prefix(realize.Green.Bold(realize.RVersion)))
} | go | func version() {
log.Println(r.Prefix(realize.Green.Bold(realize.RVersion)))
} | [
"func",
"version",
"(",
")",
"{",
"log",
".",
"Println",
"(",
"r",
".",
"Prefix",
"(",
"realize",
".",
"Green",
".",
"Bold",
"(",
"realize",
".",
"RVersion",
")",
")",
")",
"\n",
"}"
] | // Version print current version | [
"Version",
"print",
"current",
"version"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L107-L109 |
25,837 | oxequa/realize | realize.go | clean | func clean() (err error) {
if err := r.Settings.Remove(realize.RFile); err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("folder successfully removed")))
return nil
} | go | func clean() (err error) {
if err := r.Settings.Remove(realize.RFile); err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("folder successfully removed")))
return nil
} | [
"func",
"clean",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"r",
".",
"Settings",
".",
"Remove",
"(",
"realize",
".",
"RFile",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Println",
"(",
"r"... | // Clean remove realize file | [
"Clean",
"remove",
"realize",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L112-L118 |
25,838 | oxequa/realize | realize.go | add | func add(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
projects := len(r.Schema.Projects)
// create and add a new project
r.Schema.Add(r.Schema.New(c))
if len(r.Schema.Projects) > projects {
// update config
err = r.Settings.Write(r)
if er... | go | func add(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
projects := len(r.Schema.Projects)
// create and add a new project
r.Schema.Add(r.Schema.New(c))
if len(r.Schema.Projects) > projects {
// update config
err = r.Settings.Write(r)
if er... | [
"func",
"add",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"// read a config if exist",
"err",
"=",
"r",
".",
"Settings",
".",
"Read",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"... | // Add a project to an existing config or create a new one | [
"Add",
"a",
"project",
"to",
"an",
"existing",
"config",
"or",
"create",
"a",
"new",
"one"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L121-L141 |
25,839 | oxequa/realize | realize.go | remove | func remove(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
if c.String("name") != "" {
err := r.Schema.Remove(c.String("name"))
if err != nil {
return err
}
// update config
err = r.Settings.Write(r)
if err != nil {
return err
}
... | go | func remove(c *cli.Context) (err error) {
// read a config if exist
err = r.Settings.Read(&r)
if err != nil {
return err
}
if c.String("name") != "" {
err := r.Schema.Remove(c.String("name"))
if err != nil {
return err
}
// update config
err = r.Settings.Write(r)
if err != nil {
return err
}
... | [
"func",
"remove",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"// read a config if exist",
"err",
"=",
"r",
".",
"Settings",
".",
"Read",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
... | // Remove a project from an existing config | [
"Remove",
"a",
"project",
"from",
"an",
"existing",
"config"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L1168-L1189 |
25,840 | oxequa/realize | realize/tools.go | Exec | func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
if t.dir {
if filepath.Ext(path) != "" {
path = filepath.Dir(path)
}
// check if there is at least one go file
matched := false
files, _ := ioutil.ReadDir(path)
for _, f := range files {
matched, _ = filepath.Match("*.go", f.Nam... | go | func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
if t.dir {
if filepath.Ext(path) != "" {
path = filepath.Dir(path)
}
// check if there is at least one go file
matched := false
files, _ := ioutil.ReadDir(path)
for _, f := range files {
matched, _ = filepath.Match("*.go", f.Nam... | [
"func",
"(",
"t",
"*",
"Tool",
")",
"Exec",
"(",
"path",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"if",
"t",
".",
"dir",
"{",
"if",
"filepath",
".",
"Ext",
"(",
"path",
")",
"!=",
"\"",
"\"",
"{",... | // Exec a go tool | [
"Exec",
"a",
"go",
"tool"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/tools.go#L105-L171 |
25,841 | oxequa/realize | realize/tools.go | Compile | func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
var out bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := append(t.cmd, t.Args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout... | go | func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
var out bytes.Buffer
var stderr bytes.Buffer
done := make(chan error)
args := append(t.cmd, t.Args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout... | [
"func",
"(",
"t",
"*",
"Tool",
")",
"Compile",
"(",
"path",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"var",
"out",
"bytes",
".",
"Buffer",
"\n",
"var",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"done",
... | // Compile is used for build and install | [
"Compile",
"is",
"used",
"for",
"build",
"and",
"install"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/tools.go#L174-L203 |
25,842 | oxequa/realize | realize/utils.go | params | func params(params *cli.Context) []string {
argsN := params.NArg()
if argsN > 0 {
var args []string
for i := 0; i <= argsN-1; i++ {
args = append(args, params.Args().Get(i))
}
return args
}
return nil
} | go | func params(params *cli.Context) []string {
argsN := params.NArg()
if argsN > 0 {
var args []string
for i := 0; i <= argsN-1; i++ {
args = append(args, params.Args().Get(i))
}
return args
}
return nil
} | [
"func",
"params",
"(",
"params",
"*",
"cli",
".",
"Context",
")",
"[",
"]",
"string",
"{",
"argsN",
":=",
"params",
".",
"NArg",
"(",
")",
"\n",
"if",
"argsN",
">",
"0",
"{",
"var",
"args",
"[",
"]",
"string",
"\n",
"for",
"i",
":=",
"0",
";",
... | // Params parse one by one the given argumentes | [
"Params",
"parse",
"one",
"by",
"one",
"the",
"given",
"argumentes"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L14-L24 |
25,843 | oxequa/realize | realize/utils.go | split | func split(args, fields []string) []string {
for _, arg := range fields {
arr := strings.Fields(arg)
args = append(args, arr...)
}
return args
} | go | func split(args, fields []string) []string {
for _, arg := range fields {
arr := strings.Fields(arg)
args = append(args, arr...)
}
return args
} | [
"func",
"split",
"(",
"args",
",",
"fields",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"for",
"_",
",",
"arg",
":=",
"range",
"fields",
"{",
"arr",
":=",
"strings",
".",
"Fields",
"(",
"arg",
")",
"\n",
"args",
"=",
"append",
"(",
"args",... | // Split each arguments in multiple fields | [
"Split",
"each",
"arguments",
"in",
"multiple",
"fields"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L27-L33 |
25,844 | oxequa/realize | realize/utils.go | ext | func ext(path string) string {
var ext string
for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- {
if path[i] == '.' {
ext = path[i:]
if index := strings.LastIndex(ext, "."); index > 0 {
ext = ext[index:]
}
}
}
if ext != "" {
return ext[1:]
}
return ""
} | go | func ext(path string) string {
var ext string
for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- {
if path[i] == '.' {
ext = path[i:]
if index := strings.LastIndex(ext, "."); index > 0 {
ext = ext[index:]
}
}
}
if ext != "" {
return ext[1:]
}
return ""
} | [
"func",
"ext",
"(",
"path",
"string",
")",
"string",
"{",
"var",
"ext",
"string",
"\n",
"for",
"i",
":=",
"len",
"(",
"path",
")",
"-",
"1",
";",
"i",
">=",
"0",
"&&",
"!",
"os",
".",
"IsPathSeparator",
"(",
"path",
"[",
"i",
"]",
")",
";",
"... | // Get file extensions | [
"Get",
"file",
"extensions"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L46-L60 |
25,845 | oxequa/realize | realize/utils.go | replace | func replace(a []string, b string) []string {
if len(b) > 0 {
return strings.Fields(b)
}
return a
} | go | func replace(a []string, b string) []string {
if len(b) > 0 {
return strings.Fields(b)
}
return a
} | [
"func",
"replace",
"(",
"a",
"[",
"]",
"string",
",",
"b",
"string",
")",
"[",
"]",
"string",
"{",
"if",
"len",
"(",
"b",
")",
">",
"0",
"{",
"return",
"strings",
".",
"Fields",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"a",
"\n",
"}"
] | // Replace if isn't empty and create a new array | [
"Replace",
"if",
"isn",
"t",
"empty",
"and",
"create",
"a",
"new",
"array"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L63-L68 |
25,846 | oxequa/realize | realize/utils.go | Wdir | func Wdir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err.Error())
}
return dir
} | go | func Wdir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err.Error())
}
return dir
} | [
"func",
"Wdir",
"(",
")",
"string",
"{",
"dir",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"dir",
"\n",
"}"
] | // Wdir return current working directory | [
"Wdir",
"return",
"current",
"working",
"directory"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L71-L77 |
25,847 | oxequa/realize | realize/notify.go | PollingWatcher | func PollingWatcher(interval time.Duration) FileWatcher {
if interval == 0 {
interval = time.Duration(1) * time.Second
}
return &filePoller{
interval: interval,
events: make(chan fsnotify.Event),
errors: make(chan error),
}
} | go | func PollingWatcher(interval time.Duration) FileWatcher {
if interval == 0 {
interval = time.Duration(1) * time.Second
}
return &filePoller{
interval: interval,
events: make(chan fsnotify.Event),
errors: make(chan error),
}
} | [
"func",
"PollingWatcher",
"(",
"interval",
"time",
".",
"Duration",
")",
"FileWatcher",
"{",
"if",
"interval",
"==",
"0",
"{",
"interval",
"=",
"time",
".",
"Duration",
"(",
"1",
")",
"*",
"time",
".",
"Second",
"\n",
"}",
"\n",
"return",
"&",
"filePol... | // PollingWatcher returns a poll-based file watcher | [
"PollingWatcher",
"returns",
"a",
"poll",
"-",
"based",
"file",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L58-L67 |
25,848 | oxequa/realize | realize/notify.go | NewFileWatcher | func NewFileWatcher(l Legacy) (FileWatcher, error) {
if !l.Force {
if w, err := EventWatcher(); err == nil {
return w, nil
}
}
return PollingWatcher(l.Interval), nil
} | go | func NewFileWatcher(l Legacy) (FileWatcher, error) {
if !l.Force {
if w, err := EventWatcher(); err == nil {
return w, nil
}
}
return PollingWatcher(l.Interval), nil
} | [
"func",
"NewFileWatcher",
"(",
"l",
"Legacy",
")",
"(",
"FileWatcher",
",",
"error",
")",
"{",
"if",
"!",
"l",
".",
"Force",
"{",
"if",
"w",
",",
"err",
":=",
"EventWatcher",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"w",
",",
"nil",
"\n"... | // NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error | [
"NewFileWatcher",
"tries",
"to",
"use",
"an",
"fs",
"-",
"event",
"watcher",
"and",
"falls",
"back",
"to",
"the",
"poller",
"if",
"there",
"is",
"an",
"error"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L70-L77 |
25,849 | oxequa/realize | realize/notify.go | EventWatcher | func EventWatcher() (FileWatcher, error) {
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
return &fsNotifyWatcher{Watcher: w}, nil
} | go | func EventWatcher() (FileWatcher, error) {
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
}
return &fsNotifyWatcher{Watcher: w}, nil
} | [
"func",
"EventWatcher",
"(",
")",
"(",
"FileWatcher",
",",
"error",
")",
"{",
"w",
",",
"err",
":=",
"fsnotify",
".",
"NewWatcher",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"fsNotif... | // EventWatcher returns an fs-event based file watcher | [
"EventWatcher",
"returns",
"an",
"fs",
"-",
"event",
"based",
"file",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L80-L86 |
25,850 | oxequa/realize | realize/notify.go | Close | func (w *filePoller) Close() error {
w.mu.Lock()
if w.closed {
w.mu.Unlock()
return nil
}
w.closed = true
for name := range w.watches {
w.remove(name)
delete(w.watches, name)
}
w.mu.Unlock()
return nil
} | go | func (w *filePoller) Close() error {
w.mu.Lock()
if w.closed {
w.mu.Unlock()
return nil
}
w.closed = true
for name := range w.watches {
w.remove(name)
delete(w.watches, name)
}
w.mu.Unlock()
return nil
} | [
"func",
"(",
"w",
"*",
"filePoller",
")",
"Close",
"(",
")",
"error",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"w",
".",
"closed",
"{",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"w",
"... | // Close closes the poller
// All watches are stopped, removed, and the poller cannot be added to | [
"Close",
"closes",
"the",
"poller",
"All",
"watches",
"are",
"stopped",
"removed",
"and",
"the",
"poller",
"cannot",
"be",
"added",
"to"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L108-L122 |
25,851 | oxequa/realize | realize/notify.go | Add | func (w *filePoller) Add(name string) error {
w.mu.Lock()
defer w.mu.Unlock()
if w.closed {
return errPollerClosed
}
f, err := os.Open(name)
if err != nil {
return err
}
fi, err := os.Stat(name)
if err != nil {
return err
}
if w.watches == nil {
w.watches = make(map[string]chan struct{})
}
if _,... | go | func (w *filePoller) Add(name string) error {
w.mu.Lock()
defer w.mu.Unlock()
if w.closed {
return errPollerClosed
}
f, err := os.Open(name)
if err != nil {
return err
}
fi, err := os.Stat(name)
if err != nil {
return err
}
if w.watches == nil {
w.watches = make(map[string]chan struct{})
}
if _,... | [
"func",
"(",
"w",
"*",
"filePoller",
")",
"Add",
"(",
"name",
"string",
")",
"error",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"w",
".",
"closed",
"{",
"return",
"errPolle... | // Add adds a filename to the list of watches
// once added the file is polled for changes in a separate goroutine | [
"Add",
"adds",
"a",
"filename",
"to",
"the",
"list",
"of",
"watches",
"once",
"added",
"the",
"file",
"is",
"polled",
"for",
"changes",
"in",
"a",
"separate",
"goroutine"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/notify.go#L132-L159 |
25,852 | oxequa/realize | realize/schema.go | Add | func (s *Schema) Add(p Project) {
for _, val := range s.Projects {
if reflect.DeepEqual(val, p) {
return
}
}
s.Projects = append(s.Projects, p)
} | go | func (s *Schema) Add(p Project) {
for _, val := range s.Projects {
if reflect.DeepEqual(val, p) {
return
}
}
s.Projects = append(s.Projects, p)
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Add",
"(",
"p",
"Project",
")",
"{",
"for",
"_",
",",
"val",
":=",
"range",
"s",
".",
"Projects",
"{",
"if",
"reflect",
".",
"DeepEqual",
"(",
"val",
",",
"p",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"... | // Add a project if unique | [
"Add",
"a",
"project",
"if",
"unique"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L17-L24 |
25,853 | oxequa/realize | realize/schema.go | Remove | func (s *Schema) Remove(name string) error {
for key, val := range s.Projects {
if name == val.Name {
s.Projects = append(s.Projects[:key], s.Projects[key+1:]...)
return nil
}
}
return errors.New("project not found")
} | go | func (s *Schema) Remove(name string) error {
for key, val := range s.Projects {
if name == val.Name {
s.Projects = append(s.Projects[:key], s.Projects[key+1:]...)
return nil
}
}
return errors.New("project not found")
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Remove",
"(",
"name",
"string",
")",
"error",
"{",
"for",
"key",
",",
"val",
":=",
"range",
"s",
".",
"Projects",
"{",
"if",
"name",
"==",
"val",
".",
"Name",
"{",
"s",
".",
"Projects",
"=",
"append",
"(",
... | // Remove a project | [
"Remove",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L27-L35 |
25,854 | oxequa/realize | realize/schema.go | New | func (s *Schema) New(c *cli.Context) Project {
var vgo bool
name := filepath.Base(c.String("path"))
if len(name) == 0 || name == "." {
name = filepath.Base(Wdir())
}
if hasGoMod(Wdir()) {
vgo = true
}
project := Project{
Name: name,
Path: c.String("path"),
Tools: Tools{
Vet: Tool{
Status: c.Bo... | go | func (s *Schema) New(c *cli.Context) Project {
var vgo bool
name := filepath.Base(c.String("path"))
if len(name) == 0 || name == "." {
name = filepath.Base(Wdir())
}
if hasGoMod(Wdir()) {
vgo = true
}
project := Project{
Name: name,
Path: c.String("path"),
Tools: Tools{
Vet: Tool{
Status: c.Bo... | [
"func",
"(",
"s",
"*",
"Schema",
")",
"New",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"Project",
"{",
"var",
"vgo",
"bool",
"\n",
"name",
":=",
"filepath",
".",
"Base",
"(",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"len",
... | // New create a project using cli fields | [
"New",
"create",
"a",
"project",
"using",
"cli",
"fields"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L38-L84 |
25,855 | oxequa/realize | realize/schema.go | Filter | func (s *Schema) Filter(field string, value interface{}) []Project {
result := []Project{}
for _, item := range s.Projects {
v := reflect.ValueOf(item)
for i := 0; i < v.NumField(); i++ {
if v.Type().Field(i).Name == field {
if reflect.DeepEqual(v.Field(i).Interface(), value) {
result = append(result,... | go | func (s *Schema) Filter(field string, value interface{}) []Project {
result := []Project{}
for _, item := range s.Projects {
v := reflect.ValueOf(item)
for i := 0; i < v.NumField(); i++ {
if v.Type().Field(i).Name == field {
if reflect.DeepEqual(v.Field(i).Interface(), value) {
result = append(result,... | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Filter",
"(",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"[",
"]",
"Project",
"{",
"result",
":=",
"[",
"]",
"Project",
"{",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"s",
".",
"... | // Filter project list by field | [
"Filter",
"project",
"list",
"by",
"field"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L87-L100 |
25,856 | oxequa/realize | realize/style.go | Regular | func (c colorBase) Regular(a ...interface{}) string {
return color.New(color.Attribute(c)).Sprint(a...)
} | go | func (c colorBase) Regular(a ...interface{}) string {
return color.New(color.Attribute(c)).Sprint(a...)
} | [
"func",
"(",
"c",
"colorBase",
")",
"Regular",
"(",
"a",
"...",
"interface",
"{",
"}",
")",
"string",
"{",
"return",
"color",
".",
"New",
"(",
"color",
".",
"Attribute",
"(",
"c",
")",
")",
".",
"Sprint",
"(",
"a",
"...",
")",
"\n",
"}"
] | // Regular font with a color | [
"Regular",
"font",
"with",
"a",
"color"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/style.go#L26-L28 |
25,857 | gravityblast/fresh | runner/runnerutils/utils.go | HasErrors | func HasErrors() bool {
if _, err := os.Stat(logFilePath); err == nil {
return true
}
return false
} | go | func HasErrors() bool {
if _, err := os.Stat(logFilePath); err == nil {
return true
}
return false
} | [
"func",
"HasErrors",
"(",
")",
"bool",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"logFilePath",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Returns true if a build error file exists in the tmp folder. | [
"Returns",
"true",
"if",
"a",
"build",
"error",
"file",
"exists",
"in",
"the",
"tmp",
"folder",
"."
] | 9c0092493eff2825c3abf64e087b3383dec939c3 | https://github.com/gravityblast/fresh/blob/9c0092493eff2825c3abf64e087b3383dec939c3/runner/runnerutils/utils.go#L22-L28 |
25,858 | gravityblast/fresh | runner/runnerutils/utils.go | RenderError | func RenderError(w http.ResponseWriter) {
data := map[string]interface{}{
"Output": readErrorFile(),
}
w.Header().Set("Content-Type", "text/html")
tpl := template.Must(template.New("ErrorPage").Parse(buildPageTpl))
tpl.Execute(w, data)
} | go | func RenderError(w http.ResponseWriter) {
data := map[string]interface{}{
"Output": readErrorFile(),
}
w.Header().Set("Content-Type", "text/html")
tpl := template.Must(template.New("ErrorPage").Parse(buildPageTpl))
tpl.Execute(w, data)
} | [
"func",
"RenderError",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"{",
"data",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"readErrorFile",
"(",
")",
",",
"}",
"\n\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
... | // It renders an error page with the build error message. | [
"It",
"renders",
"an",
"error",
"page",
"with",
"the",
"build",
"error",
"message",
"."
] | 9c0092493eff2825c3abf64e087b3383dec939c3 | https://github.com/gravityblast/fresh/blob/9c0092493eff2825c3abf64e087b3383dec939c3/runner/runnerutils/utils.go#L31-L39 |
25,859 | goraft/raft | log.go | currentIndex | func (l *Log) currentIndex() uint64 {
l.mutex.RLock()
defer l.mutex.RUnlock()
return l.internalCurrentIndex()
} | go | func (l *Log) currentIndex() uint64 {
l.mutex.RLock()
defer l.mutex.RUnlock()
return l.internalCurrentIndex()
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"currentIndex",
"(",
")",
"uint64",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"l",
".",
"internalCurrentIndex",
"(",
")",
"\n",
"... | // The current index in the log. | [
"The",
"current",
"index",
"in",
"the",
"log",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L70-L74 |
25,860 | goraft/raft | log.go | internalCurrentIndex | func (l *Log) internalCurrentIndex() uint64 {
if len(l.entries) == 0 {
return l.startIndex
}
return l.entries[len(l.entries)-1].Index()
} | go | func (l *Log) internalCurrentIndex() uint64 {
if len(l.entries) == 0 {
return l.startIndex
}
return l.entries[len(l.entries)-1].Index()
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"internalCurrentIndex",
"(",
")",
"uint64",
"{",
"if",
"len",
"(",
"l",
".",
"entries",
")",
"==",
"0",
"{",
"return",
"l",
".",
"startIndex",
"\n",
"}",
"\n",
"return",
"l",
".",
"entries",
"[",
"len",
"(",
"l"... | // The current index in the log without locking | [
"The",
"current",
"index",
"in",
"the",
"log",
"without",
"locking"
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L77-L82 |
25,861 | goraft/raft | log.go | isEmpty | func (l *Log) isEmpty() bool {
l.mutex.RLock()
defer l.mutex.RUnlock()
return (len(l.entries) == 0) && (l.startIndex == 0)
} | go | func (l *Log) isEmpty() bool {
l.mutex.RLock()
defer l.mutex.RUnlock()
return (len(l.entries) == 0) && (l.startIndex == 0)
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"isEmpty",
"(",
")",
"bool",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"(",
"len",
"(",
"l",
".",
"entries",
")",
"==",
"0",
... | // Determines if the log contains zero entries. | [
"Determines",
"if",
"the",
"log",
"contains",
"zero",
"entries",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L90-L94 |
25,862 | goraft/raft | log.go | lastCommandName | func (l *Log) lastCommandName() string {
l.mutex.RLock()
defer l.mutex.RUnlock()
if len(l.entries) > 0 {
if entry := l.entries[len(l.entries)-1]; entry != nil {
return entry.CommandName()
}
}
return ""
} | go | func (l *Log) lastCommandName() string {
l.mutex.RLock()
defer l.mutex.RUnlock()
if len(l.entries) > 0 {
if entry := l.entries[len(l.entries)-1]; entry != nil {
return entry.CommandName()
}
}
return ""
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"lastCommandName",
"(",
")",
"string",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"len",
"(",
"l",
".",
"entries",
")",
">",
"0",
... | // The name of the last command in the log. | [
"The",
"name",
"of",
"the",
"last",
"command",
"in",
"the",
"log",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L97-L106 |
25,863 | goraft/raft | log.go | close | func (l *Log) close() {
l.mutex.Lock()
defer l.mutex.Unlock()
if l.file != nil {
l.file.Close()
l.file = nil
}
l.entries = make([]*LogEntry, 0)
} | go | func (l *Log) close() {
l.mutex.Lock()
defer l.mutex.Unlock()
if l.file != nil {
l.file.Close()
l.file = nil
}
l.entries = make([]*LogEntry, 0)
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"close",
"(",
")",
"{",
"l",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"file",
"!=",
"nil",
"{",
"l",
".",
"file",
".",
"Close"... | // Closes the log file. | [
"Closes",
"the",
"log",
"file",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L198-L207 |
25,864 | goraft/raft | log.go | getEntry | func (l *Log) getEntry(index uint64) *LogEntry {
l.mutex.RLock()
defer l.mutex.RUnlock()
if index <= l.startIndex || index > (l.startIndex+uint64(len(l.entries))) {
return nil
}
return l.entries[index-l.startIndex-1]
} | go | func (l *Log) getEntry(index uint64) *LogEntry {
l.mutex.RLock()
defer l.mutex.RUnlock()
if index <= l.startIndex || index > (l.startIndex+uint64(len(l.entries))) {
return nil
}
return l.entries[index-l.startIndex-1]
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"getEntry",
"(",
"index",
"uint64",
")",
"*",
"LogEntry",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"index",
"<=",
"l",
".",
"sta... | // Retrieves an entry from the log. If the entry has been eliminated because
// of a snapshot then nil is returned. | [
"Retrieves",
"an",
"entry",
"from",
"the",
"log",
".",
"If",
"the",
"entry",
"has",
"been",
"eliminated",
"because",
"of",
"a",
"snapshot",
"then",
"nil",
"is",
"returned",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L225-L233 |
25,865 | goraft/raft | log.go | getEntriesAfter | func (l *Log) getEntriesAfter(index uint64, maxLogEntriesPerRequest uint64) ([]*LogEntry, uint64) {
l.mutex.RLock()
defer l.mutex.RUnlock()
// Return nil if index is before the start of the log.
if index < l.startIndex {
traceln("log.entriesAfter.before: ", index, " ", l.startIndex)
return nil, 0
}
// Retur... | go | func (l *Log) getEntriesAfter(index uint64, maxLogEntriesPerRequest uint64) ([]*LogEntry, uint64) {
l.mutex.RLock()
defer l.mutex.RUnlock()
// Return nil if index is before the start of the log.
if index < l.startIndex {
traceln("log.entriesAfter.before: ", index, " ", l.startIndex)
return nil, 0
}
// Retur... | [
"func",
"(",
"l",
"*",
"Log",
")",
"getEntriesAfter",
"(",
"index",
"uint64",
",",
"maxLogEntriesPerRequest",
"uint64",
")",
"(",
"[",
"]",
"*",
"LogEntry",
",",
"uint64",
")",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
... | // Retrieves a list of entries after a given index as well as the term of the
// index provided. A nil list of entries is returned if the index no longer
// exists because a snapshot was made. | [
"Retrieves",
"a",
"list",
"of",
"entries",
"after",
"a",
"given",
"index",
"as",
"well",
"as",
"the",
"term",
"of",
"the",
"index",
"provided",
".",
"A",
"nil",
"list",
"of",
"entries",
"is",
"returned",
"if",
"the",
"index",
"no",
"longer",
"exists",
... | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L244-L278 |
25,866 | goraft/raft | log.go | lastInfo | func (l *Log) lastInfo() (index uint64, term uint64) {
l.mutex.RLock()
defer l.mutex.RUnlock()
// If we don't have any entries then just return zeros.
if len(l.entries) == 0 {
return l.startIndex, l.startTerm
}
// Return the last index & term
entry := l.entries[len(l.entries)-1]
return entry.Index(), entry.... | go | func (l *Log) lastInfo() (index uint64, term uint64) {
l.mutex.RLock()
defer l.mutex.RUnlock()
// If we don't have any entries then just return zeros.
if len(l.entries) == 0 {
return l.startIndex, l.startTerm
}
// Return the last index & term
entry := l.entries[len(l.entries)-1]
return entry.Index(), entry.... | [
"func",
"(",
"l",
"*",
"Log",
")",
"lastInfo",
"(",
")",
"(",
"index",
"uint64",
",",
"term",
"uint64",
")",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"// If we don't have an... | // Retrieves the last index and term that has been appended to the log. | [
"Retrieves",
"the",
"last",
"index",
"and",
"term",
"that",
"has",
"been",
"appended",
"to",
"the",
"log",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L305-L317 |
25,867 | goraft/raft | log.go | updateCommitIndex | func (l *Log) updateCommitIndex(index uint64) {
l.mutex.Lock()
defer l.mutex.Unlock()
if index > l.commitIndex {
l.commitIndex = index
}
debugln("update.commit.index ", index)
} | go | func (l *Log) updateCommitIndex(index uint64) {
l.mutex.Lock()
defer l.mutex.Unlock()
if index > l.commitIndex {
l.commitIndex = index
}
debugln("update.commit.index ", index)
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"updateCommitIndex",
"(",
"index",
"uint64",
")",
"{",
"l",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"index",
">",
"l",
".",
"commitIndex",
"{",... | // Updates the commit index | [
"Updates",
"the",
"commit",
"index"
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L320-L327 |
25,868 | goraft/raft | log.go | setCommitIndex | func (l *Log) setCommitIndex(index uint64) error {
l.mutex.Lock()
defer l.mutex.Unlock()
// this is not error any more after limited the number of sending entries
// commit up to what we already have
if index > l.startIndex+uint64(len(l.entries)) {
debugln("raft.Log: Commit index", index, "set back to ", len(l.... | go | func (l *Log) setCommitIndex(index uint64) error {
l.mutex.Lock()
defer l.mutex.Unlock()
// this is not error any more after limited the number of sending entries
// commit up to what we already have
if index > l.startIndex+uint64(len(l.entries)) {
debugln("raft.Log: Commit index", index, "set back to ", len(l.... | [
"func",
"(",
"l",
"*",
"Log",
")",
"setCommitIndex",
"(",
"index",
"uint64",
")",
"error",
"{",
"l",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"// this is not error any more after limited the nu... | // Updates the commit index and writes entries after that index to the stable storage. | [
"Updates",
"the",
"commit",
"index",
"and",
"writes",
"entries",
"after",
"that",
"index",
"to",
"the",
"stable",
"storage",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L330-L393 |
25,869 | goraft/raft | log.go | flushCommitIndex | func (l *Log) flushCommitIndex() {
l.file.Seek(0, os.SEEK_SET)
fmt.Fprintf(l.file, "%8x\n", l.commitIndex)
l.file.Seek(0, os.SEEK_END)
} | go | func (l *Log) flushCommitIndex() {
l.file.Seek(0, os.SEEK_SET)
fmt.Fprintf(l.file, "%8x\n", l.commitIndex)
l.file.Seek(0, os.SEEK_END)
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"flushCommitIndex",
"(",
")",
"{",
"l",
".",
"file",
".",
"Seek",
"(",
"0",
",",
"os",
".",
"SEEK_SET",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"l",
".",
"file",
",",
"\"",
"\\n",
"\"",
",",
"l",
".",
"commit... | // Set the commitIndex at the head of the log file to the current
// commit Index. This should be called after obtained a log lock | [
"Set",
"the",
"commitIndex",
"at",
"the",
"head",
"of",
"the",
"log",
"file",
"to",
"the",
"current",
"commit",
"Index",
".",
"This",
"should",
"be",
"called",
"after",
"obtained",
"a",
"log",
"lock"
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L397-L401 |
25,870 | goraft/raft | log.go | appendEntry | func (l *Log) appendEntry(entry *LogEntry) error {
l.mutex.Lock()
defer l.mutex.Unlock()
if l.file == nil {
return errors.New("raft.Log: Log is not open")
}
// Make sure the term and index are greater than the previous.
if len(l.entries) > 0 {
lastEntry := l.entries[len(l.entries)-1]
if entry.Term() < las... | go | func (l *Log) appendEntry(entry *LogEntry) error {
l.mutex.Lock()
defer l.mutex.Unlock()
if l.file == nil {
return errors.New("raft.Log: Log is not open")
}
// Make sure the term and index are greater than the previous.
if len(l.entries) > 0 {
lastEntry := l.entries[len(l.entries)-1]
if entry.Term() < las... | [
"func",
"(",
"l",
"*",
"Log",
")",
"appendEntry",
"(",
"entry",
"*",
"LogEntry",
")",
"error",
"{",
"l",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"file",
"==",
"nil"... | // Writes a single log entry to the end of the log. | [
"Writes",
"a",
"single",
"log",
"entry",
"to",
"the",
"end",
"of",
"the",
"log",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L510-L541 |
25,871 | goraft/raft | log.go | writeEntry | func (l *Log) writeEntry(entry *LogEntry, w io.Writer) (int64, error) {
if l.file == nil {
return -1, errors.New("raft.Log: Log is not open")
}
// Make sure the term and index are greater than the previous.
if len(l.entries) > 0 {
lastEntry := l.entries[len(l.entries)-1]
if entry.Term() < lastEntry.Term() {
... | go | func (l *Log) writeEntry(entry *LogEntry, w io.Writer) (int64, error) {
if l.file == nil {
return -1, errors.New("raft.Log: Log is not open")
}
// Make sure the term and index are greater than the previous.
if len(l.entries) > 0 {
lastEntry := l.entries[len(l.entries)-1]
if entry.Term() < lastEntry.Term() {
... | [
"func",
"(",
"l",
"*",
"Log",
")",
"writeEntry",
"(",
"entry",
"*",
"LogEntry",
",",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"l",
".",
"file",
"==",
"nil",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"New",
... | // appendEntry with Buffered io | [
"appendEntry",
"with",
"Buffered",
"io"
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L544-L569 |
25,872 | goraft/raft | request_vote.go | newRequestVoteRequest | func newRequestVoteRequest(term uint64, candidateName string, lastLogIndex uint64, lastLogTerm uint64) *RequestVoteRequest {
return &RequestVoteRequest{
Term: term,
LastLogIndex: lastLogIndex,
LastLogTerm: lastLogTerm,
CandidateName: candidateName,
}
} | go | func newRequestVoteRequest(term uint64, candidateName string, lastLogIndex uint64, lastLogTerm uint64) *RequestVoteRequest {
return &RequestVoteRequest{
Term: term,
LastLogIndex: lastLogIndex,
LastLogTerm: lastLogTerm,
CandidateName: candidateName,
}
} | [
"func",
"newRequestVoteRequest",
"(",
"term",
"uint64",
",",
"candidateName",
"string",
",",
"lastLogIndex",
"uint64",
",",
"lastLogTerm",
"uint64",
")",
"*",
"RequestVoteRequest",
"{",
"return",
"&",
"RequestVoteRequest",
"{",
"Term",
":",
"term",
",",
"LastLogIn... | // Creates a new RequestVote request. | [
"Creates",
"a",
"new",
"RequestVote",
"request",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/request_vote.go#L28-L35 |
25,873 | goraft/raft | request_vote.go | Encode | func (req *RequestVoteRequest) Encode(w io.Writer) (int, error) {
pb := &protobuf.RequestVoteRequest{
Term: proto.Uint64(req.Term),
LastLogIndex: proto.Uint64(req.LastLogIndex),
LastLogTerm: proto.Uint64(req.LastLogTerm),
CandidateName: proto.String(req.CandidateName),
}
p, err := proto.Marshal(p... | go | func (req *RequestVoteRequest) Encode(w io.Writer) (int, error) {
pb := &protobuf.RequestVoteRequest{
Term: proto.Uint64(req.Term),
LastLogIndex: proto.Uint64(req.LastLogIndex),
LastLogTerm: proto.Uint64(req.LastLogTerm),
CandidateName: proto.String(req.CandidateName),
}
p, err := proto.Marshal(p... | [
"func",
"(",
"req",
"*",
"RequestVoteRequest",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"pb",
":=",
"&",
"protobuf",
".",
"RequestVoteRequest",
"{",
"Term",
":",
"proto",
".",
"Uint64",
"(",
"req",
".",
... | // Encodes the RequestVoteRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred. | [
"Encodes",
"the",
"RequestVoteRequest",
"to",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"may",
"have",
"occurred",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/request_vote.go#L39-L52 |
25,874 | goraft/raft | request_vote.go | Decode | func (req *RequestVoteRequest) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return -1, err
}
totalBytes := len(data)
pb := &protobuf.RequestVoteRequest{}
if err = proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.Term = pb.GetTerm()
req.LastLogIndex = pb.... | go | func (req *RequestVoteRequest) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return -1, err
}
totalBytes := len(data)
pb := &protobuf.RequestVoteRequest{}
if err = proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.Term = pb.GetTerm()
req.LastLogIndex = pb.... | [
"func",
"(",
"req",
"*",
"RequestVoteRequest",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // Decodes the RequestVoteRequest from a buffer. Returns the number of bytes read and
// any error that occurs. | [
"Decodes",
"the",
"RequestVoteRequest",
"from",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"read",
"and",
"any",
"error",
"that",
"occurs",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/request_vote.go#L56-L76 |
25,875 | goraft/raft | request_vote.go | newRequestVoteResponse | func newRequestVoteResponse(term uint64, voteGranted bool) *RequestVoteResponse {
return &RequestVoteResponse{
Term: term,
VoteGranted: voteGranted,
}
} | go | func newRequestVoteResponse(term uint64, voteGranted bool) *RequestVoteResponse {
return &RequestVoteResponse{
Term: term,
VoteGranted: voteGranted,
}
} | [
"func",
"newRequestVoteResponse",
"(",
"term",
"uint64",
",",
"voteGranted",
"bool",
")",
"*",
"RequestVoteResponse",
"{",
"return",
"&",
"RequestVoteResponse",
"{",
"Term",
":",
"term",
",",
"VoteGranted",
":",
"voteGranted",
",",
"}",
"\n",
"}"
] | // Creates a new RequestVote response. | [
"Creates",
"a",
"new",
"RequestVote",
"response",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/request_vote.go#L79-L84 |
25,876 | goraft/raft | request_vote.go | Encode | func (resp *RequestVoteResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.RequestVoteResponse{
Term: proto.Uint64(resp.Term),
VoteGranted: proto.Bool(resp.VoteGranted),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
} | go | func (resp *RequestVoteResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.RequestVoteResponse{
Term: proto.Uint64(resp.Term),
VoteGranted: proto.Bool(resp.VoteGranted),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
} | [
"func",
"(",
"resp",
"*",
"RequestVoteResponse",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"pb",
":=",
"&",
"protobuf",
".",
"RequestVoteResponse",
"{",
"Term",
":",
"proto",
".",
"Uint64",
"(",
"resp",
".... | // Encodes the RequestVoteResponse to a buffer. Returns the number of bytes
// written and any error that may have occurred. | [
"Encodes",
"the",
"RequestVoteResponse",
"to",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"may",
"have",
"occurred",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/request_vote.go#L88-L100 |
25,877 | goraft/raft | request_vote.go | Decode | func (resp *RequestVoteResponse) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.RequestVoteResponse{}
if err = proto.Unmarshal(data, pb); err != nil {
return -1, err
}
resp.Term = pb.GetTerm()
resp.VoteGranted = ... | go | func (resp *RequestVoteResponse) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.RequestVoteResponse{}
if err = proto.Unmarshal(data, pb); err != nil {
return -1, err
}
resp.Term = pb.GetTerm()
resp.VoteGranted = ... | [
"func",
"(",
"resp",
"*",
"RequestVoteResponse",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"ret... | // Decodes the RequestVoteResponse from a buffer. Returns the number of bytes read and
// any error that occurs. | [
"Decodes",
"the",
"RequestVoteResponse",
"from",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"read",
"and",
"any",
"error",
"that",
"occurs",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/request_vote.go#L104-L122 |
25,878 | goraft/raft | event_dispatcher.go | newEventDispatcher | func newEventDispatcher(source interface{}) *eventDispatcher {
return &eventDispatcher{
source: source,
listeners: make(map[string]eventListeners),
}
} | go | func newEventDispatcher(source interface{}) *eventDispatcher {
return &eventDispatcher{
source: source,
listeners: make(map[string]eventListeners),
}
} | [
"func",
"newEventDispatcher",
"(",
"source",
"interface",
"{",
"}",
")",
"*",
"eventDispatcher",
"{",
"return",
"&",
"eventDispatcher",
"{",
"source",
":",
"source",
",",
"listeners",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"eventListeners",
")",
",",
... | // newEventDispatcher creates a new eventDispatcher instance. | [
"newEventDispatcher",
"creates",
"a",
"new",
"eventDispatcher",
"instance",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/event_dispatcher.go#L23-L28 |
25,879 | goraft/raft | event_dispatcher.go | AddEventListener | func (d *eventDispatcher) AddEventListener(typ string, listener EventListener) {
d.Lock()
defer d.Unlock()
d.listeners[typ] = append(d.listeners[typ], listener)
} | go | func (d *eventDispatcher) AddEventListener(typ string, listener EventListener) {
d.Lock()
defer d.Unlock()
d.listeners[typ] = append(d.listeners[typ], listener)
} | [
"func",
"(",
"d",
"*",
"eventDispatcher",
")",
"AddEventListener",
"(",
"typ",
"string",
",",
"listener",
"EventListener",
")",
"{",
"d",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"Unlock",
"(",
")",
"\n",
"d",
".",
"listeners",
"[",
"typ",
"]"... | // AddEventListener adds a listener function for a given event type. | [
"AddEventListener",
"adds",
"a",
"listener",
"function",
"for",
"a",
"given",
"event",
"type",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/event_dispatcher.go#L31-L35 |
25,880 | goraft/raft | event_dispatcher.go | RemoveEventListener | func (d *eventDispatcher) RemoveEventListener(typ string, listener EventListener) {
d.Lock()
defer d.Unlock()
// Grab a reference to the function pointer once.
ptr := reflect.ValueOf(listener).Pointer()
// Find listener by pointer and remove it.
listeners := d.listeners[typ]
for i, l := range listeners {
if ... | go | func (d *eventDispatcher) RemoveEventListener(typ string, listener EventListener) {
d.Lock()
defer d.Unlock()
// Grab a reference to the function pointer once.
ptr := reflect.ValueOf(listener).Pointer()
// Find listener by pointer and remove it.
listeners := d.listeners[typ]
for i, l := range listeners {
if ... | [
"func",
"(",
"d",
"*",
"eventDispatcher",
")",
"RemoveEventListener",
"(",
"typ",
"string",
",",
"listener",
"EventListener",
")",
"{",
"d",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"Unlock",
"(",
")",
"\n\n",
"// Grab a reference to the function pointe... | // RemoveEventListener removes a listener function for a given event type. | [
"RemoveEventListener",
"removes",
"a",
"listener",
"function",
"for",
"a",
"given",
"event",
"type",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/event_dispatcher.go#L38-L52 |
25,881 | goraft/raft | event_dispatcher.go | DispatchEvent | func (d *eventDispatcher) DispatchEvent(e Event) {
d.RLock()
defer d.RUnlock()
// Automatically set the event source.
if e, ok := e.(*event); ok {
e.source = d.source
}
// Dispatch the event to all listeners.
for _, l := range d.listeners[e.Type()] {
l(e)
}
} | go | func (d *eventDispatcher) DispatchEvent(e Event) {
d.RLock()
defer d.RUnlock()
// Automatically set the event source.
if e, ok := e.(*event); ok {
e.source = d.source
}
// Dispatch the event to all listeners.
for _, l := range d.listeners[e.Type()] {
l(e)
}
} | [
"func",
"(",
"d",
"*",
"eventDispatcher",
")",
"DispatchEvent",
"(",
"e",
"Event",
")",
"{",
"d",
".",
"RLock",
"(",
")",
"\n",
"defer",
"d",
".",
"RUnlock",
"(",
")",
"\n\n",
"// Automatically set the event source.",
"if",
"e",
",",
"ok",
":=",
"e",
"... | // DispatchEvent dispatches an event. | [
"DispatchEvent",
"dispatches",
"an",
"event",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/event_dispatcher.go#L55-L68 |
25,882 | goraft/raft | snapshot.go | save | func (ss *Snapshot) save() error {
// Open the file for writing.
file, err := os.OpenFile(ss.Path, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return err
}
defer file.Close()
// Serialize to JSON.
b, err := json.Marshal(ss)
if err != nil {
return err
}
// Generate checksum and write it to disk.
chec... | go | func (ss *Snapshot) save() error {
// Open the file for writing.
file, err := os.OpenFile(ss.Path, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return err
}
defer file.Close()
// Serialize to JSON.
b, err := json.Marshal(ss)
if err != nil {
return err
}
// Generate checksum and write it to disk.
chec... | [
"func",
"(",
"ss",
"*",
"Snapshot",
")",
"save",
"(",
")",
"error",
"{",
"// Open the file for writing.",
"file",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"ss",
".",
"Path",
",",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_WRONLY",
",",
"0600",
")... | // save writes the snapshot to file. | [
"save",
"writes",
"the",
"snapshot",
"to",
"file",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L55-L86 |
25,883 | goraft/raft | snapshot.go | remove | func (ss *Snapshot) remove() error {
if err := os.Remove(ss.Path); err != nil {
return err
}
return nil
} | go | func (ss *Snapshot) remove() error {
if err := os.Remove(ss.Path); err != nil {
return err
}
return nil
} | [
"func",
"(",
"ss",
"*",
"Snapshot",
")",
"remove",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"os",
".",
"Remove",
"(",
"ss",
".",
"Path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // remove deletes the snapshot file. | [
"remove",
"deletes",
"the",
"snapshot",
"file",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L89-L94 |
25,884 | goraft/raft | snapshot.go | Encode | func (req *SnapshotRecoveryRequest) Encode(w io.Writer) (int, error) {
protoPeers := make([]*protobuf.SnapshotRecoveryRequest_Peer, len(req.Peers))
for i, peer := range req.Peers {
protoPeers[i] = &protobuf.SnapshotRecoveryRequest_Peer{
Name: proto.String(peer.Name),
ConnectionString: proto.Stri... | go | func (req *SnapshotRecoveryRequest) Encode(w io.Writer) (int, error) {
protoPeers := make([]*protobuf.SnapshotRecoveryRequest_Peer, len(req.Peers))
for i, peer := range req.Peers {
protoPeers[i] = &protobuf.SnapshotRecoveryRequest_Peer{
Name: proto.String(peer.Name),
ConnectionString: proto.Stri... | [
"func",
"(",
"req",
"*",
"SnapshotRecoveryRequest",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"protoPeers",
":=",
"make",
"(",
"[",
"]",
"*",
"protobuf",
".",
"SnapshotRecoveryRequest_Peer",
",",
"len",
"(",
... | // Encodes the SnapshotRecoveryRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred. | [
"Encodes",
"the",
"SnapshotRecoveryRequest",
"to",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"may",
"have",
"occurred",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L109-L133 |
25,885 | goraft/raft | snapshot.go | Decode | func (req *SnapshotRecoveryRequest) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotRecoveryRequest{}
if err = proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.LeaderName = pb.GetLeaderName()
r... | go | func (req *SnapshotRecoveryRequest) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotRecoveryRequest{}
if err = proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.LeaderName = pb.GetLeaderName()
r... | [
"func",
"(",
"req",
"*",
"SnapshotRecoveryRequest",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // Decodes the SnapshotRecoveryRequest from a buffer. Returns the number of bytes read and
// any error that occurs. | [
"Decodes",
"the",
"SnapshotRecoveryRequest",
"from",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"read",
"and",
"any",
"error",
"that",
"occurs",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L137-L166 |
25,886 | goraft/raft | snapshot.go | newSnapshotRecoveryResponse | func newSnapshotRecoveryResponse(term uint64, success bool, commitIndex uint64) *SnapshotRecoveryResponse {
return &SnapshotRecoveryResponse{
Term: term,
Success: success,
CommitIndex: commitIndex,
}
} | go | func newSnapshotRecoveryResponse(term uint64, success bool, commitIndex uint64) *SnapshotRecoveryResponse {
return &SnapshotRecoveryResponse{
Term: term,
Success: success,
CommitIndex: commitIndex,
}
} | [
"func",
"newSnapshotRecoveryResponse",
"(",
"term",
"uint64",
",",
"success",
"bool",
",",
"commitIndex",
"uint64",
")",
"*",
"SnapshotRecoveryResponse",
"{",
"return",
"&",
"SnapshotRecoveryResponse",
"{",
"Term",
":",
"term",
",",
"Success",
":",
"success",
",",... | // Creates a new Snapshot response. | [
"Creates",
"a",
"new",
"Snapshot",
"response",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L169-L175 |
25,887 | goraft/raft | snapshot.go | Encode | func (req *SnapshotRecoveryResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.SnapshotRecoveryResponse{
Term: proto.Uint64(req.Term),
Success: proto.Bool(req.Success),
CommitIndex: proto.Uint64(req.CommitIndex),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.... | go | func (req *SnapshotRecoveryResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.SnapshotRecoveryResponse{
Term: proto.Uint64(req.Term),
Success: proto.Bool(req.Success),
CommitIndex: proto.Uint64(req.CommitIndex),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.... | [
"func",
"(",
"req",
"*",
"SnapshotRecoveryResponse",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"pb",
":=",
"&",
"protobuf",
".",
"SnapshotRecoveryResponse",
"{",
"Term",
":",
"proto",
".",
"Uint64",
"(",
"re... | // Encode writes the response to a writer.
// Returns the number of bytes written and any error that occurs. | [
"Encode",
"writes",
"the",
"response",
"to",
"a",
"writer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"occurs",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L179-L191 |
25,888 | goraft/raft | snapshot.go | Decode | func (req *SnapshotRecoveryResponse) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotRecoveryResponse{}
if err := proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.Term = pb.GetTerm()
req.Succes... | go | func (req *SnapshotRecoveryResponse) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotRecoveryResponse{}
if err := proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.Term = pb.GetTerm()
req.Succes... | [
"func",
"(",
"req",
"*",
"SnapshotRecoveryResponse",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
... | // Decodes the SnapshotRecoveryResponse from a buffer. | [
"Decodes",
"the",
"SnapshotRecoveryResponse",
"from",
"a",
"buffer",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L194-L213 |
25,889 | goraft/raft | snapshot.go | Encode | func (req *SnapshotRequest) Encode(w io.Writer) (int, error) {
pb := &protobuf.SnapshotRequest{
LeaderName: proto.String(req.LeaderName),
LastIndex: proto.Uint64(req.LastIndex),
LastTerm: proto.Uint64(req.LastTerm),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
} | go | func (req *SnapshotRequest) Encode(w io.Writer) (int, error) {
pb := &protobuf.SnapshotRequest{
LeaderName: proto.String(req.LeaderName),
LastIndex: proto.Uint64(req.LastIndex),
LastTerm: proto.Uint64(req.LastTerm),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
} | [
"func",
"(",
"req",
"*",
"SnapshotRequest",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"pb",
":=",
"&",
"protobuf",
".",
"SnapshotRequest",
"{",
"LeaderName",
":",
"proto",
".",
"String",
"(",
"req",
".",
... | // Encodes the SnapshotRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred. | [
"Encodes",
"the",
"SnapshotRequest",
"to",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"may",
"have",
"occurred",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L226-L238 |
25,890 | goraft/raft | snapshot.go | Decode | func (req *SnapshotRequest) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotRequest{}
if err := proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.LeaderName = pb.GetLeaderName()
req.LastIndex =... | go | func (req *SnapshotRequest) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotRequest{}
if err := proto.Unmarshal(data, pb); err != nil {
return -1, err
}
req.LeaderName = pb.GetLeaderName()
req.LastIndex =... | [
"func",
"(",
"req",
"*",
"SnapshotRequest",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",... | // Decodes the SnapshotRequest from a buffer. Returns the number of bytes read and
// any error that occurs. | [
"Decodes",
"the",
"SnapshotRequest",
"from",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"read",
"and",
"any",
"error",
"that",
"occurs",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L242-L262 |
25,891 | goraft/raft | snapshot.go | Encode | func (resp *SnapshotResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.SnapshotResponse{
Success: proto.Bool(resp.Success),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
} | go | func (resp *SnapshotResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.SnapshotResponse{
Success: proto.Bool(resp.Success),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
} | [
"func",
"(",
"resp",
"*",
"SnapshotResponse",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"pb",
":=",
"&",
"protobuf",
".",
"SnapshotResponse",
"{",
"Success",
":",
"proto",
".",
"Bool",
"(",
"resp",
".",
... | // Encodes the SnapshotResponse to a buffer. Returns the number of bytes
// written and any error that may have occurred. | [
"Encodes",
"the",
"SnapshotResponse",
"to",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"may",
"have",
"occurred",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L273-L283 |
25,892 | goraft/raft | snapshot.go | Decode | func (resp *SnapshotResponse) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotResponse{}
if err := proto.Unmarshal(data, pb); err != nil {
return -1, err
}
resp.Success = pb.GetSuccess()
return totalBytes... | go | func (resp *SnapshotResponse) Decode(r io.Reader) (int, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return 0, err
}
totalBytes := len(data)
pb := &protobuf.SnapshotResponse{}
if err := proto.Unmarshal(data, pb); err != nil {
return -1, err
}
resp.Success = pb.GetSuccess()
return totalBytes... | [
"func",
"(",
"resp",
"*",
"SnapshotResponse",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // Decodes the SnapshotResponse from a buffer. Returns the number of bytes read and
// any error that occurs. | [
"Decodes",
"the",
"SnapshotResponse",
"from",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"read",
"and",
"any",
"error",
"that",
"occurs",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L287-L304 |
25,893 | goraft/raft | log_entry.go | newLogEntry | func newLogEntry(log *Log, event *ev, index uint64, term uint64, command Command) (*LogEntry, error) {
var buf bytes.Buffer
var commandName string
if command != nil {
commandName = command.CommandName()
if encoder, ok := command.(CommandEncoder); ok {
if err := encoder.Encode(&buf); err != nil {
return ni... | go | func newLogEntry(log *Log, event *ev, index uint64, term uint64, command Command) (*LogEntry, error) {
var buf bytes.Buffer
var commandName string
if command != nil {
commandName = command.CommandName()
if encoder, ok := command.(CommandEncoder); ok {
if err := encoder.Encode(&buf); err != nil {
return ni... | [
"func",
"newLogEntry",
"(",
"log",
"*",
"Log",
",",
"event",
"*",
"ev",
",",
"index",
"uint64",
",",
"term",
"uint64",
",",
"command",
"Command",
")",
"(",
"*",
"LogEntry",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"var",
... | // Creates a new log entry associated with a log. | [
"Creates",
"a",
"new",
"log",
"entry",
"associated",
"with",
"a",
"log",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log_entry.go#L22-L52 |
25,894 | goraft/raft | log_entry.go | Encode | func (e *LogEntry) Encode(w io.Writer) (int, error) {
b, err := proto.Marshal(e.pb)
if err != nil {
return -1, err
}
if _, err = fmt.Fprintf(w, "%8x\n", len(b)); err != nil {
return -1, err
}
return w.Write(b)
} | go | func (e *LogEntry) Encode(w io.Writer) (int, error) {
b, err := proto.Marshal(e.pb)
if err != nil {
return -1, err
}
if _, err = fmt.Fprintf(w, "%8x\n", len(b)); err != nil {
return -1, err
}
return w.Write(b)
} | [
"func",
"(",
"e",
"*",
"LogEntry",
")",
"Encode",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"e",
".",
"pb",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",... | // Encodes the log entry to a buffer. Returns the number of bytes
// written and any error that may have occurred. | [
"Encodes",
"the",
"log",
"entry",
"to",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"and",
"any",
"error",
"that",
"may",
"have",
"occurred",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log_entry.go#L72-L83 |
25,895 | goraft/raft | log_entry.go | Decode | func (e *LogEntry) Decode(r io.Reader) (int, error) {
var length int
_, err := fmt.Fscanf(r, "%8x\n", &length)
if err != nil {
return -1, err
}
data := make([]byte, length)
_, err = io.ReadFull(r, data)
if err != nil {
return -1, err
}
if err = proto.Unmarshal(data, e.pb); err != nil {
return -1, err... | go | func (e *LogEntry) Decode(r io.Reader) (int, error) {
var length int
_, err := fmt.Fscanf(r, "%8x\n", &length)
if err != nil {
return -1, err
}
data := make([]byte, length)
_, err = io.ReadFull(r, data)
if err != nil {
return -1, err
}
if err = proto.Unmarshal(data, e.pb); err != nil {
return -1, err... | [
"func",
"(",
"e",
"*",
"LogEntry",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"length",
"int",
"\n",
"_",
",",
"err",
":=",
"fmt",
".",
"Fscanf",
"(",
"r",
",",
"\"",
"\\n",
"\"",
",",
"&",
... | // Decodes the log entry from a buffer. Returns the number of bytes read and
// any error that occurs. | [
"Decodes",
"the",
"log",
"entry",
"from",
"a",
"buffer",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"read",
"and",
"any",
"error",
"that",
"occurs",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log_entry.go#L87-L107 |
25,896 | goraft/raft | util.go | afterBetween | func afterBetween(min time.Duration, max time.Duration) <-chan time.Time {
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
d, delta := min, (max - min)
if delta > 0 {
d += time.Duration(rand.Int63n(int64(delta)))
}
return time.After(d)
} | go | func afterBetween(min time.Duration, max time.Duration) <-chan time.Time {
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
d, delta := min, (max - min)
if delta > 0 {
d += time.Duration(rand.Int63n(int64(delta)))
}
return time.After(d)
} | [
"func",
"afterBetween",
"(",
"min",
"time",
".",
"Duration",
",",
"max",
"time",
".",
"Duration",
")",
"<-",
"chan",
"time",
".",
"Time",
"{",
"rand",
":=",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"time",
".",
"Now",
"(",
")",
".",
... | // Waits for a random time between two durations and sends the current time on
// the returned channel. | [
"Waits",
"for",
"a",
"random",
"time",
"between",
"two",
"durations",
"and",
"sends",
"the",
"current",
"time",
"on",
"the",
"returned",
"channel",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/util.go#L46-L53 |
25,897 | goraft/raft | command.go | newCommand | func newCommand(name string, data []byte) (Command, error) {
// Find the registered command.
command := commandTypes[name]
if command == nil {
return nil, fmt.Errorf("raft.Command: Unregistered command type: %s", name)
}
// Make a copy of the command.
v := reflect.New(reflect.Indirect(reflect.ValueOf(command))... | go | func newCommand(name string, data []byte) (Command, error) {
// Find the registered command.
command := commandTypes[name]
if command == nil {
return nil, fmt.Errorf("raft.Command: Unregistered command type: %s", name)
}
// Make a copy of the command.
v := reflect.New(reflect.Indirect(reflect.ValueOf(command))... | [
"func",
"newCommand",
"(",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"Command",
",",
"error",
")",
"{",
"// Find the registered command.",
"command",
":=",
"commandTypes",
"[",
"name",
"]",
"\n",
"if",
"command",
"==",
"nil",
"{",
"return"... | // Creates a new instance of a command by name. | [
"Creates",
"a",
"new",
"instance",
"of",
"a",
"command",
"by",
"name",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/command.go#L38-L66 |
25,898 | goraft/raft | command.go | RegisterCommand | func RegisterCommand(command Command) {
if command == nil {
panic(fmt.Sprintf("raft: Cannot register nil"))
} else if commandTypes[command.CommandName()] != nil {
panic(fmt.Sprintf("raft: Duplicate registration: %s", command.CommandName()))
}
commandTypes[command.CommandName()] = command
} | go | func RegisterCommand(command Command) {
if command == nil {
panic(fmt.Sprintf("raft: Cannot register nil"))
} else if commandTypes[command.CommandName()] != nil {
panic(fmt.Sprintf("raft: Duplicate registration: %s", command.CommandName()))
}
commandTypes[command.CommandName()] = command
} | [
"func",
"RegisterCommand",
"(",
"command",
"Command",
")",
"{",
"if",
"command",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"else",
"if",
"commandTypes",
"[",
"command",
".",
"CommandName",
"(",
")",
... | // Registers a command by storing a reference to an instance of it. | [
"Registers",
"a",
"command",
"by",
"storing",
"a",
"reference",
"to",
"an",
"instance",
"of",
"it",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/command.go#L69-L76 |
25,899 | goraft/raft | http_transporter.go | SendVoteRequest | func (t *HTTPTransporter) SendVoteRequest(server Server, peer *Peer, req *RequestVoteRequest) *RequestVoteResponse {
var b bytes.Buffer
if _, err := req.Encode(&b); err != nil {
traceln("transporter.rv.encoding.error:", err)
return nil
}
url := fmt.Sprintf("%s%s", peer.ConnectionString, t.RequestVotePath())
t... | go | func (t *HTTPTransporter) SendVoteRequest(server Server, peer *Peer, req *RequestVoteRequest) *RequestVoteResponse {
var b bytes.Buffer
if _, err := req.Encode(&b); err != nil {
traceln("transporter.rv.encoding.error:", err)
return nil
}
url := fmt.Sprintf("%s%s", peer.ConnectionString, t.RequestVotePath())
t... | [
"func",
"(",
"t",
"*",
"HTTPTransporter",
")",
"SendVoteRequest",
"(",
"server",
"Server",
",",
"peer",
"*",
"Peer",
",",
"req",
"*",
"RequestVoteRequest",
")",
"*",
"RequestVoteResponse",
"{",
"var",
"b",
"bytes",
".",
"Buffer",
"\n",
"if",
"_",
",",
"e... | // Sends a RequestVote RPC to a peer. | [
"Sends",
"a",
"RequestVote",
"RPC",
"to",
"a",
"peer",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/http_transporter.go#L142-L166 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.