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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
147,800 | veandco/go-sdl2 | mix/sdl_mixer.go | LengthInMs | func (chunk *Chunk) LengthInMs() int {
_chunk := (*C.Mix_Chunk)(unsafe.Pointer(chunk))
return int(C.getChunkTimeMilliseconds(_chunk))
} | go | func (chunk *Chunk) LengthInMs() int {
_chunk := (*C.Mix_Chunk)(unsafe.Pointer(chunk))
return int(C.getChunkTimeMilliseconds(_chunk))
} | [
"func",
"(",
"chunk",
"*",
"Chunk",
")",
"LengthInMs",
"(",
")",
"int",
"{",
"_chunk",
":=",
"(",
"*",
"C",
".",
"Mix_Chunk",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"chunk",
")",
")",
"\n",
"return",
"int",
"(",
"C",
".",
"getChunkTimeMilliseconds",
"(",
"_chunk",
")",
")",
"\n",
"}"
] | // LengthInMs returns the playing time of the chunk in milliseconds. | [
"LengthInMs",
"returns",
"the",
"playing",
"time",
"of",
"the",
"chunk",
"in",
"milliseconds",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/sdl_mixer.go#L378-L381 |
147,801 | veandco/go-sdl2 | mix/sdl_mixer.go | SetSynchroValue | func SetSynchroValue(value int) bool {
_value := (C.int)(value)
return int(C.Mix_SetSynchroValue(_value)) == 0
} | go | func SetSynchroValue(value int) bool {
_value := (C.int)(value)
return int(C.Mix_SetSynchroValue(_value)) == 0
} | [
"func",
"SetSynchroValue",
"(",
"value",
"int",
")",
"bool",
"{",
"_value",
":=",
"(",
"C",
".",
"int",
")",
"(",
"value",
")",
"\n",
"return",
"int",
"(",
"C",
".",
"Mix_SetSynchroValue",
"(",
"_value",
")",
")",
"==",
"0",
"\n",
"}"
] | // SetSynchroValue sets the synchro value. | [
"SetSynchroValue",
"sets",
"the",
"synchro",
"value",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/mix/sdl_mixer.go#L620-L623 |
147,802 | veandco/go-sdl2 | sdl/audio.go | AllocBuf | func (cvt *AudioCVT) AllocBuf(size uintptr) {
cvt.Buf = C.malloc(C.size_t(size))
} | go | func (cvt *AudioCVT) AllocBuf(size uintptr) {
cvt.Buf = C.malloc(C.size_t(size))
} | [
"func",
"(",
"cvt",
"*",
"AudioCVT",
")",
"AllocBuf",
"(",
"size",
"uintptr",
")",
"{",
"cvt",
".",
"Buf",
"=",
"C",
".",
"malloc",
"(",
"C",
".",
"size_t",
"(",
"size",
")",
")",
"\n",
"}"
] | // AllocBuf allocates the requested memory for AudioCVT buffer. | [
"AllocBuf",
"allocates",
"the",
"requested",
"memory",
"for",
"AudioCVT",
"buffer",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/audio.go#L295-L297 |
147,803 | veandco/go-sdl2 | sdl/render.go | SetDrawColorArray | func (renderer *Renderer) SetDrawColorArray(bs ...uint8) error {
_bs := []C.Uint8{0, 0, 0, 255}
for i := 0; i < len(_bs) && i < len(bs); i++ {
_bs[i] = C.Uint8(bs[i])
}
return errorFromInt(int(
C.SDL_SetRenderDrawColor(
renderer.cptr(),
_bs[0],
_bs[1],
_bs[2],
_bs[3])))
} | go | func (renderer *Renderer) SetDrawColorArray(bs ...uint8) error {
_bs := []C.Uint8{0, 0, 0, 255}
for i := 0; i < len(_bs) && i < len(bs); i++ {
_bs[i] = C.Uint8(bs[i])
}
return errorFromInt(int(
C.SDL_SetRenderDrawColor(
renderer.cptr(),
_bs[0],
_bs[1],
_bs[2],
_bs[3])))
} | [
"func",
"(",
"renderer",
"*",
"Renderer",
")",
"SetDrawColorArray",
"(",
"bs",
"...",
"uint8",
")",
"error",
"{",
"_bs",
":=",
"[",
"]",
"C",
".",
"Uint8",
"{",
"0",
",",
"0",
",",
"0",
",",
"255",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"_bs",
")",
"&&",
"i",
"<",
"len",
"(",
"bs",
")",
";",
"i",
"++",
"{",
"_bs",
"[",
"i",
"]",
"=",
"C",
".",
"Uint8",
"(",
"bs",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"errorFromInt",
"(",
"int",
"(",
"C",
".",
"SDL_SetRenderDrawColor",
"(",
"renderer",
".",
"cptr",
"(",
")",
",",
"_bs",
"[",
"0",
"]",
",",
"_bs",
"[",
"1",
"]",
",",
"_bs",
"[",
"2",
"]",
",",
"_bs",
"[",
"3",
"]",
")",
")",
")",
"\n",
"}"
] | // SetDrawColorArray is a custom variant of SetDrawColor. | [
"SetDrawColorArray",
"is",
"a",
"custom",
"variant",
"of",
"SetDrawColor",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/render.go#L539-L551 |
147,804 | veandco/go-sdl2 | sdl/gamecontroller.go | GameControllerMappingForIndex | func GameControllerMappingForIndex(index int) string {
mappingString := C.SDL_GameControllerMappingForIndex(C.int(index))
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
} | go | func GameControllerMappingForIndex(index int) string {
mappingString := C.SDL_GameControllerMappingForIndex(C.int(index))
defer C.free(unsafe.Pointer(mappingString))
return C.GoString(mappingString)
} | [
"func",
"GameControllerMappingForIndex",
"(",
"index",
"int",
")",
"string",
"{",
"mappingString",
":=",
"C",
".",
"SDL_GameControllerMappingForIndex",
"(",
"C",
".",
"int",
"(",
"index",
")",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"mappingString",
")",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"mappingString",
")",
"\n",
"}"
] | // GameControllerMappingForIndex returns the game controller mapping string at a particular index. | [
"GameControllerMappingForIndex",
"returns",
"the",
"game",
"controller",
"mapping",
"string",
"at",
"a",
"particular",
"index",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/gamecontroller.go#L160-L164 |
147,805 | veandco/go-sdl2 | sdl/gamecontroller.go | Axis | func (bind *GameControllerButtonBind) Axis() int {
val, _ := binary.Varint(bind.value[:4])
return int(val)
} | go | func (bind *GameControllerButtonBind) Axis() int {
val, _ := binary.Varint(bind.value[:4])
return int(val)
} | [
"func",
"(",
"bind",
"*",
"GameControllerButtonBind",
")",
"Axis",
"(",
")",
"int",
"{",
"val",
",",
"_",
":=",
"binary",
".",
"Varint",
"(",
"bind",
".",
"value",
"[",
":",
"4",
"]",
")",
"\n",
"return",
"int",
"(",
"val",
")",
"\n",
"}"
] | // Axis returns axis mapped for this SDL joystick layer binding. | [
"Axis",
"returns",
"axis",
"mapped",
"for",
"this",
"SDL",
"joystick",
"layer",
"binding",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/gamecontroller.go#L321-L324 |
147,806 | veandco/go-sdl2 | img/sdl_image.go | LoadTexture | func LoadTexture(renderer *sdl.Renderer, file string) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_surface := C.IMG_LoadTexture(_renderer, _file)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | go | func LoadTexture(renderer *sdl.Renderer, file string) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_surface := C.IMG_LoadTexture(_renderer, _file)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | [
"func",
"LoadTexture",
"(",
"renderer",
"*",
"sdl",
".",
"Renderer",
",",
"file",
"string",
")",
"(",
"*",
"sdl",
".",
"Texture",
",",
"error",
")",
"{",
"_renderer",
":=",
"(",
"*",
"C",
".",
"SDL_Renderer",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"renderer",
")",
")",
"\n",
"_file",
":=",
"C",
".",
"CString",
"(",
"file",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"_file",
")",
")",
"\n",
"_surface",
":=",
"C",
".",
"IMG_LoadTexture",
"(",
"_renderer",
",",
"_file",
")",
"\n",
"if",
"_surface",
"==",
"nil",
"{",
"return",
"nil",
",",
"GetError",
"(",
")",
"\n",
"}",
"\n",
"return",
"(",
"*",
"sdl",
".",
"Texture",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"_surface",
")",
")",
",",
"nil",
"\n",
"}"
] | // LoadTexture loads an image directly into a render texture. | [
"LoadTexture",
"loads",
"an",
"image",
"directly",
"into",
"a",
"render",
"texture",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L87-L96 |
147,807 | veandco/go-sdl2 | img/sdl_image.go | LoadTextureRW | func LoadTextureRW(renderer *sdl.Renderer, src *sdl.RWops, freesrc bool) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_freesrc := (C.int)(sdl.Btoi(freesrc))
_surface := C.IMG_LoadTexture_RW(_renderer, _src, _freesrc)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | go | func LoadTextureRW(renderer *sdl.Renderer, src *sdl.RWops, freesrc bool) (*sdl.Texture, error) {
_renderer := (*C.SDL_Renderer)(unsafe.Pointer(renderer))
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_freesrc := (C.int)(sdl.Btoi(freesrc))
_surface := C.IMG_LoadTexture_RW(_renderer, _src, _freesrc)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Texture)(unsafe.Pointer(_surface)), nil
} | [
"func",
"LoadTextureRW",
"(",
"renderer",
"*",
"sdl",
".",
"Renderer",
",",
"src",
"*",
"sdl",
".",
"RWops",
",",
"freesrc",
"bool",
")",
"(",
"*",
"sdl",
".",
"Texture",
",",
"error",
")",
"{",
"_renderer",
":=",
"(",
"*",
"C",
".",
"SDL_Renderer",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"renderer",
")",
")",
"\n",
"_src",
":=",
"(",
"*",
"C",
".",
"SDL_RWops",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"src",
")",
")",
"\n",
"_freesrc",
":=",
"(",
"C",
".",
"int",
")",
"(",
"sdl",
".",
"Btoi",
"(",
"freesrc",
")",
")",
"\n",
"_surface",
":=",
"C",
".",
"IMG_LoadTexture_RW",
"(",
"_renderer",
",",
"_src",
",",
"_freesrc",
")",
"\n",
"if",
"_surface",
"==",
"nil",
"{",
"return",
"nil",
",",
"GetError",
"(",
")",
"\n",
"}",
"\n",
"return",
"(",
"*",
"sdl",
".",
"Texture",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"_surface",
")",
")",
",",
"nil",
"\n",
"}"
] | // LoadTextureRW loads an image from an SDL data source directly into a render texture. | [
"LoadTextureRW",
"loads",
"an",
"image",
"from",
"an",
"SDL",
"data",
"source",
"directly",
"into",
"a",
"render",
"texture",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L99-L108 |
147,808 | veandco/go-sdl2 | img/sdl_image.go | IsWEBP | func IsWEBP(src *sdl.RWops) bool {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
return int(C.IMG_isWEBP(_src)) > 0
} | go | func IsWEBP(src *sdl.RWops) bool {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
return int(C.IMG_isWEBP(_src)) > 0
} | [
"func",
"IsWEBP",
"(",
"src",
"*",
"sdl",
".",
"RWops",
")",
"bool",
"{",
"_src",
":=",
"(",
"*",
"C",
".",
"SDL_RWops",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"src",
")",
")",
"\n",
"return",
"int",
"(",
"C",
".",
"IMG_isWEBP",
"(",
"_src",
")",
")",
">",
"0",
"\n",
"}"
] | // IsWEBP reports whether WEBP format is supported and image data is readable as a WEBP. | [
"IsWEBP",
"reports",
"whether",
"WEBP",
"format",
"is",
"supported",
"and",
"image",
"data",
"is",
"readable",
"as",
"a",
"WEBP",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L202-L205 |
147,809 | veandco/go-sdl2 | img/sdl_image.go | LoadWEBPRW | func LoadWEBPRW(src *sdl.RWops) (*sdl.Surface, error) {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_surface := C.IMG_LoadWEBP_RW(_src)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
} | go | func LoadWEBPRW(src *sdl.RWops) (*sdl.Surface, error) {
_src := (*C.SDL_RWops)(unsafe.Pointer(src))
_surface := C.IMG_LoadWEBP_RW(_src)
if _surface == nil {
return nil, GetError()
}
return (*sdl.Surface)(unsafe.Pointer(_surface)), nil
} | [
"func",
"LoadWEBPRW",
"(",
"src",
"*",
"sdl",
".",
"RWops",
")",
"(",
"*",
"sdl",
".",
"Surface",
",",
"error",
")",
"{",
"_src",
":=",
"(",
"*",
"C",
".",
"SDL_RWops",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"src",
")",
")",
"\n",
"_surface",
":=",
"C",
".",
"IMG_LoadWEBP_RW",
"(",
"_src",
")",
"\n",
"if",
"_surface",
"==",
"nil",
"{",
"return",
"nil",
",",
"GetError",
"(",
")",
"\n",
"}",
"\n",
"return",
"(",
"*",
"sdl",
".",
"Surface",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"_surface",
")",
")",
",",
"nil",
"\n",
"}"
] | // LoadWEBPRW loads a WEBP image from an SDL data source for use as a surface. | [
"LoadWEBPRW",
"loads",
"a",
"WEBP",
"image",
"from",
"an",
"SDL",
"data",
"source",
"for",
"use",
"as",
"a",
"surface",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L362-L369 |
147,810 | veandco/go-sdl2 | img/sdl_image.go | SavePNG | func SavePNG(surface *sdl.Surface, file string) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_ret := C.IMG_SavePNG(_surface, _file)
if _ret < 0 {
return GetError()
}
return nil
} | go | func SavePNG(surface *sdl.Surface, file string) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_file := C.CString(file)
defer C.free(unsafe.Pointer(_file))
_ret := C.IMG_SavePNG(_surface, _file)
if _ret < 0 {
return GetError()
}
return nil
} | [
"func",
"SavePNG",
"(",
"surface",
"*",
"sdl",
".",
"Surface",
",",
"file",
"string",
")",
"error",
"{",
"_surface",
":=",
"(",
"*",
"C",
".",
"SDL_Surface",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"surface",
")",
")",
"\n",
"_file",
":=",
"C",
".",
"CString",
"(",
"file",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"_file",
")",
")",
"\n",
"_ret",
":=",
"C",
".",
"IMG_SavePNG",
"(",
"_surface",
",",
"_file",
")",
"\n",
"if",
"_ret",
"<",
"0",
"{",
"return",
"GetError",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SavePNG saves a surface as PNG file. | [
"SavePNG",
"saves",
"a",
"surface",
"as",
"PNG",
"file",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L384-L393 |
147,811 | veandco/go-sdl2 | img/sdl_image.go | SavePNGRW | func SavePNGRW(surface *sdl.Surface, dst *sdl.RWops, freedst int) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_dst := (*C.SDL_RWops)(unsafe.Pointer(dst))
_freedst := (C.int)(freedst)
_ret := C.IMG_SavePNG_RW(_surface, _dst, _freedst)
if _ret < 0 {
return GetError()
}
return nil
} | go | func SavePNGRW(surface *sdl.Surface, dst *sdl.RWops, freedst int) error {
_surface := (*C.SDL_Surface)(unsafe.Pointer(surface))
_dst := (*C.SDL_RWops)(unsafe.Pointer(dst))
_freedst := (C.int)(freedst)
_ret := C.IMG_SavePNG_RW(_surface, _dst, _freedst)
if _ret < 0 {
return GetError()
}
return nil
} | [
"func",
"SavePNGRW",
"(",
"surface",
"*",
"sdl",
".",
"Surface",
",",
"dst",
"*",
"sdl",
".",
"RWops",
",",
"freedst",
"int",
")",
"error",
"{",
"_surface",
":=",
"(",
"*",
"C",
".",
"SDL_Surface",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"surface",
")",
")",
"\n",
"_dst",
":=",
"(",
"*",
"C",
".",
"SDL_RWops",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"dst",
")",
")",
"\n",
"_freedst",
":=",
"(",
"C",
".",
"int",
")",
"(",
"freedst",
")",
"\n",
"_ret",
":=",
"C",
".",
"IMG_SavePNG_RW",
"(",
"_surface",
",",
"_dst",
",",
"_freedst",
")",
"\n",
"if",
"_ret",
"<",
"0",
"{",
"return",
"GetError",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SavePNGRW saves a surface to an SDL data source. | [
"SavePNGRW",
"saves",
"a",
"surface",
"to",
"an",
"SDL",
"data",
"source",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/img/sdl_image.go#L396-L405 |
147,812 | veandco/go-sdl2 | sdl/events.go | GetText | func (e *TextEditingEvent) GetText() string {
length := func(buf []byte) int {
for i := range buf {
if buf[i] == 0 {
return i
}
}
return 0
}(e.Text[:])
text := e.Text[:length]
return string(text)
} | go | func (e *TextEditingEvent) GetText() string {
length := func(buf []byte) int {
for i := range buf {
if buf[i] == 0 {
return i
}
}
return 0
}(e.Text[:])
text := e.Text[:length]
return string(text)
} | [
"func",
"(",
"e",
"*",
"TextEditingEvent",
")",
"GetText",
"(",
")",
"string",
"{",
"length",
":=",
"func",
"(",
"buf",
"[",
"]",
"byte",
")",
"int",
"{",
"for",
"i",
":=",
"range",
"buf",
"{",
"if",
"buf",
"[",
"i",
"]",
"==",
"0",
"{",
"return",
"i",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"0",
"\n",
"}",
"(",
"e",
".",
"Text",
"[",
":",
"]",
")",
"\n\n",
"text",
":=",
"e",
".",
"Text",
"[",
":",
"length",
"]",
"\n",
"return",
"string",
"(",
"text",
")",
"\n",
"}"
] | // GetText returns the text as string | [
"GetText",
"returns",
"the",
"text",
"as",
"string"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/events.go#L303-L316 |
147,813 | veandco/go-sdl2 | sdl/surface.go | Pixels | func (surface *Surface) Pixels() []byte {
var b []byte
length := int(surface.W*surface.H) * int(surface.Format.BytesPerPixel)
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sliceHeader.Cap = int(length)
sliceHeader.Len = int(length)
sliceHeader.Data = uintptr(surface.pixels)
return b
} | go | func (surface *Surface) Pixels() []byte {
var b []byte
length := int(surface.W*surface.H) * int(surface.Format.BytesPerPixel)
sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sliceHeader.Cap = int(length)
sliceHeader.Len = int(length)
sliceHeader.Data = uintptr(surface.pixels)
return b
} | [
"func",
"(",
"surface",
"*",
"Surface",
")",
"Pixels",
"(",
")",
"[",
"]",
"byte",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n",
"length",
":=",
"int",
"(",
"surface",
".",
"W",
"*",
"surface",
".",
"H",
")",
"*",
"int",
"(",
"surface",
".",
"Format",
".",
"BytesPerPixel",
")",
"\n",
"sliceHeader",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"b",
")",
")",
"\n",
"sliceHeader",
".",
"Cap",
"=",
"int",
"(",
"length",
")",
"\n",
"sliceHeader",
".",
"Len",
"=",
"int",
"(",
"length",
")",
"\n",
"sliceHeader",
".",
"Data",
"=",
"uintptr",
"(",
"surface",
".",
"pixels",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Pixels returns the actual pixel data of the surface. | [
"Pixels",
"returns",
"the",
"actual",
"pixel",
"data",
"of",
"the",
"surface",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/surface.go#L500-L508 |
147,814 | veandco/go-sdl2 | sdl/surface.go | Duplicate | func (surface *Surface) Duplicate() (newSurface *Surface, err error) {
_newSurface := C.SDL_DuplicateSurface(surface.cptr())
if _newSurface == nil {
err = GetError()
return
}
newSurface = (*Surface)(unsafe.Pointer(_newSurface))
return
} | go | func (surface *Surface) Duplicate() (newSurface *Surface, err error) {
_newSurface := C.SDL_DuplicateSurface(surface.cptr())
if _newSurface == nil {
err = GetError()
return
}
newSurface = (*Surface)(unsafe.Pointer(_newSurface))
return
} | [
"func",
"(",
"surface",
"*",
"Surface",
")",
"Duplicate",
"(",
")",
"(",
"newSurface",
"*",
"Surface",
",",
"err",
"error",
")",
"{",
"_newSurface",
":=",
"C",
".",
"SDL_DuplicateSurface",
"(",
"surface",
".",
"cptr",
"(",
")",
")",
"\n",
"if",
"_newSurface",
"==",
"nil",
"{",
"err",
"=",
"GetError",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"newSurface",
"=",
"(",
"*",
"Surface",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"_newSurface",
")",
")",
"\n",
"return",
"\n",
"}"
] | // Duplicate creates a new surface identical to the existing surface | [
"Duplicate",
"creates",
"a",
"new",
"surface",
"identical",
"to",
"the",
"existing",
"surface"
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/surface.go#L516-L525 |
147,815 | veandco/go-sdl2 | sdl/surface.go | ColorModel | func (surface *Surface) ColorModel() color.Model {
switch surface.Format.Format {
case PIXELFORMAT_ARGB8888, PIXELFORMAT_ABGR8888:
return color.RGBAModel
case PIXELFORMAT_RGB888:
return color.RGBAModel
default:
panic("Not implemented yet")
}
} | go | func (surface *Surface) ColorModel() color.Model {
switch surface.Format.Format {
case PIXELFORMAT_ARGB8888, PIXELFORMAT_ABGR8888:
return color.RGBAModel
case PIXELFORMAT_RGB888:
return color.RGBAModel
default:
panic("Not implemented yet")
}
} | [
"func",
"(",
"surface",
"*",
"Surface",
")",
"ColorModel",
"(",
")",
"color",
".",
"Model",
"{",
"switch",
"surface",
".",
"Format",
".",
"Format",
"{",
"case",
"PIXELFORMAT_ARGB8888",
",",
"PIXELFORMAT_ABGR8888",
":",
"return",
"color",
".",
"RGBAModel",
"\n",
"case",
"PIXELFORMAT_RGB888",
":",
"return",
"color",
".",
"RGBAModel",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // ColorModel returns the color model used by this Surface. | [
"ColorModel",
"returns",
"the",
"color",
"model",
"used",
"by",
"this",
"Surface",
"."
] | 649ea85188106bf99d15daf5cdcd93b0da65ada9 | https://github.com/veandco/go-sdl2/blob/649ea85188106bf99d15daf5cdcd93b0da65ada9/sdl/surface.go#L528-L537 |
147,816 | 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",
"|=",
"uint32",
"(",
"c",
".",
"B",
")",
"<<",
"8",
"\n",
"v",
"|=",
"uint32",
"(",
"c",
".",
"A",
")",
"\n",
"return",
"v",
"\n",
"}"
] | // 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 |
147,817 | 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 |
147,818 | 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 |
147,819 | 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",
".",
"callEachSoundFont",
")",
",",
"nil",
")",
")",
"\n",
"}"
] | // 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 |
147,820 | 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",
".",
"Mix_SetSoundFonts",
"(",
"_paths",
")",
")",
"==",
"0",
"\n",
"}"
] | // 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 |
147,821 | 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 |
147,822 | 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 |
147,823 | 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 |
147,824 | 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 |
147,825 | 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 |
147,826 | 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",
"(",
"axis",
")",
",",
"(",
"*",
"C",
".",
"Sint16",
")",
"(",
"&",
"state",
")",
")",
"==",
"C",
".",
"SDL_TRUE",
"\n",
"return",
"\n",
"}"
] | // 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 |
147,827 | 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 |
147,828 | 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",
"(",
"d",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Remove realize folder | [
"Remove",
"realize",
"folder"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L71-L77 |
147,829 | 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",
"}",
"\n",
"content",
",",
"err",
":=",
"s",
".",
"Stream",
"(",
"RFile",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"yaml",
".",
"Unmarshal",
"(",
"content",
",",
"out",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Read config file | [
"Read",
"config",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L80-L91 |
147,830 | 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",
".",
"Fatal",
"(",
"ioutil",
".",
"WriteFile",
"(",
"RFile",
",",
"y",
",",
"Permission",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Write config file | [
"Write",
"config",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/settings.go#L94-L101 |
147,831 | 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",
",",
"err",
"\n",
"}",
"\n",
"content",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"file",
")",
"\n",
"s",
".",
"Fatal",
"(",
"err",
")",
"\n",
"return",
"content",
",",
"err",
"\n",
"}"
] | // 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 |
147,832 | 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",
"(",
"msg",
"...",
")",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Fatalln",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // 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 |
147,833 | 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",
"(",
"file",
",",
"os",
".",
"O_APPEND",
"|",
"os",
".",
"O_WRONLY",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_SYNC",
",",
"Permission",
")",
"\n",
"s",
".",
"Fatal",
"(",
"err",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // 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 |
147,834 | 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)
break
case 2:
rs.Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScriptCharsetUTF8)
break
case 3:
rs.Header().Set(echo.HeaderContentType, "text/css")
break
case 4:
rs.Header().Set(echo.HeaderContentType, "image/svg+xml")
break
case 5:
rs.Header().Set(echo.HeaderContentType, "image/png")
break
}
rs.WriteHeader(http.StatusOK)
rs.Write(data)
return nil
} | 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)
break
case 2:
rs.Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScriptCharsetUTF8)
break
case 3:
rs.Header().Set(echo.HeaderContentType, "text/css")
break
case 4:
rs.Header().Set(echo.HeaderContentType, "image/svg+xml")
break
case 5:
rs.Header().Set(echo.HeaderContentType, "image/png")
break
}
rs.WriteHeader(http.StatusOK)
rs.Write(data)
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"render",
"(",
"c",
"echo",
".",
"Context",
",",
"path",
"string",
",",
"mime",
"int",
")",
"error",
"{",
"data",
",",
"err",
":=",
"Asset",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"echo",
".",
"NewHTTPError",
"(",
"http",
".",
"StatusNotFound",
")",
"\n",
"}",
"\n",
"rs",
":=",
"c",
".",
"Response",
"(",
")",
"\n",
"// check content type by extensions",
"switch",
"mime",
"{",
"case",
"1",
":",
"rs",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"echo",
".",
"HeaderContentType",
",",
"echo",
".",
"MIMETextHTMLCharsetUTF8",
")",
"\n",
"break",
"\n",
"case",
"2",
":",
"rs",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"echo",
".",
"HeaderContentType",
",",
"echo",
".",
"MIMEApplicationJavaScriptCharsetUTF8",
")",
"\n",
"break",
"\n",
"case",
"3",
":",
"rs",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"echo",
".",
"HeaderContentType",
",",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"case",
"4",
":",
"rs",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"echo",
".",
"HeaderContentType",
",",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"case",
"5",
":",
"rs",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"echo",
".",
"HeaderContentType",
",",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"}",
"\n",
"rs",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"rs",
".",
"Write",
"(",
"data",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
147,835 | 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", func(c echo.Context) error {
return s.render(c, "assets/assets/js/all.min.js", 2)
})
e.GET("/assets/css/app.css", func(c echo.Context) error {
return s.render(c, "assets/assets/css/app.css", 3)
})
e.GET("/app/components/settings/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/settings/index.html", 1)
})
e.GET("/app/components/project/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/project/index.html", 1)
})
e.GET("/app/components/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/index.html", 1)
})
e.GET("/assets/img/logo.png", func(c echo.Context) error {
return s.render(c, "assets/assets/img/logo.png", 5)
})
e.GET("/assets/img/svg/github-logo.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/github-logo.svg", 4)
})
e.GET("/assets/img/svg/ic_arrow_back_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_arrow_back_black_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_clear_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_clear_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_menu_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_menu_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_settings_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_settings_black_48px.svg", 4)
})
//websocket
e.GET("/ws", s.projects)
e.HideBanner = true
e.Debug = false
go func() {
log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port)))
e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port))
}()
}
return nil
} | 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(c echo.Context) error {
return s.render(c, "assets/assets/js/all.min.js", 2)
})
e.GET("/assets/css/app.css", func(c echo.Context) error {
return s.render(c, "assets/assets/css/app.css", 3)
})
e.GET("/app/components/settings/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/settings/index.html", 1)
})
e.GET("/app/components/project/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/project/index.html", 1)
})
e.GET("/app/components/index.html", func(c echo.Context) error {
return s.render(c, "assets/app/components/index.html", 1)
})
e.GET("/assets/img/logo.png", func(c echo.Context) error {
return s.render(c, "assets/assets/img/logo.png", 5)
})
e.GET("/assets/img/svg/github-logo.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/github-logo.svg", 4)
})
e.GET("/assets/img/svg/ic_arrow_back_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_arrow_back_black_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_clear_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_clear_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_menu_white_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_menu_white_48px.svg", 4)
})
e.GET("/assets/img/svg/ic_settings_black_48px.svg", func(c echo.Context) error {
return s.render(c, "assets/assets/img/svg/ic_settings_black_48px.svg", 4)
})
//websocket
e.GET("/ws", s.projects)
e.HideBanner = true
e.Debug = false
go func() {
log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port)))
e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port))
}()
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"s",
".",
"Status",
"{",
"e",
":=",
"echo",
".",
"New",
"(",
")",
"\n",
"e",
".",
"Use",
"(",
"middleware",
".",
"GzipWithConfig",
"(",
"middleware",
".",
"GzipConfig",
"{",
"Level",
":",
"2",
",",
"}",
")",
")",
"\n",
"e",
".",
"Use",
"(",
"middleware",
".",
"Recover",
"(",
")",
")",
"\n\n",
"// web panel",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"3",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"1",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"5",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"4",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"4",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"4",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"4",
")",
"\n",
"}",
")",
"\n",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"func",
"(",
"c",
"echo",
".",
"Context",
")",
"error",
"{",
"return",
"s",
".",
"render",
"(",
"c",
",",
"\"",
"\"",
",",
"4",
")",
"\n",
"}",
")",
"\n\n",
"//websocket",
"e",
".",
"GET",
"(",
"\"",
"\"",
",",
"s",
".",
"projects",
")",
"\n",
"e",
".",
"HideBanner",
"=",
"true",
"\n",
"e",
".",
"Debug",
"=",
"false",
"\n",
"go",
"func",
"(",
")",
"{",
"log",
".",
"Println",
"(",
"s",
".",
"Parent",
".",
"Prefix",
"(",
"\"",
"\"",
"+",
"string",
"(",
"s",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"s",
".",
"Port",
")",
")",
")",
"\n",
"e",
".",
"Start",
"(",
"string",
"(",
"s",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"s",
".",
"Port",
")",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Start the web server | [
"Start",
"the",
"web",
"server"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/server.go#L109-L165 |
147,836 | 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 fmt.Errorf("operating system %q is not supported", runtime.GOOS)
}
cmd := exec.Command(open, url)
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return errors.New(stderr.String())
}
}
return nil
} | 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 fmt.Errorf("operating system %q is not supported", runtime.GOOS)
}
cmd := exec.Command(open, url)
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return errors.New(stderr.String())
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"OpenURL",
"(",
")",
"error",
"{",
"url",
":=",
"\"",
"\"",
"+",
"string",
"(",
"s",
".",
"Parent",
".",
"Server",
".",
"Host",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"s",
".",
"Parent",
".",
"Server",
".",
"Port",
")",
"\n",
"stderr",
":=",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"cmd",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
"\n",
"if",
"s",
".",
"Open",
"{",
"open",
",",
"err",
":=",
"cmd",
"[",
"runtime",
".",
"GOOS",
"]",
"\n",
"if",
"!",
"err",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"runtime",
".",
"GOOS",
")",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"open",
",",
"url",
")",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"stderr",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
147,837 | 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",
".",
"FileLimit",
")",
"\n\n",
"return",
"syscall",
".",
"Setrlimit",
"(",
"syscall",
".",
"RLIMIT_NOFILE",
",",
"&",
"rLimit",
")",
"\n",
"}"
] | // 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 |
147,838 | 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",
"(",
"r",
".",
"Schema",
".",
"Projects",
"[",
"k",
"]",
".",
"exit",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Stop realize workflow | [
"Stop",
"realize",
"workflow"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/cli.go#L76-L83 |
147,839 | 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",
".",
"ToUpper",
"(",
"RPrefix",
")",
",",
"Yellow",
".",
"Bold",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"input",
")",
"\n",
"}",
"\n",
"return",
"input",
"\n",
"}"
] | // 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 |
147,840 | 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",
"(",
"\"",
"\"",
")",
",",
"time",
".",
"Now",
"(",
")",
".",
"Format",
"(",
"\"",
"\"",
")",
",",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
",",
"string",
"(",
"bytes",
")",
")",
"\n",
"}",
"\n",
"return",
"0",
",",
"nil",
"\n",
"}"
] | // 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 |
147,841 | 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",
".",
"cmd",
"(",
"nil",
",",
"\"",
"\"",
",",
"true",
")",
"\n",
"}"
] | // After stop watcher | [
"After",
"stop",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L103-L109 |
147,842 | 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 {
base, _ := filepath.Abs(p.Path)
base = filepath.Join(base, dir)
if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, p.walk); err != nil {
p.Err(err)
}
}
}
// start message
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Blue.Bold("Watching"), Magenta.Bold(p.files), "file/s", Magenta.Bold(p.folders), "folder/s")
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(p.files, 10) + " files/s " + strconv.FormatInt(p.folders, 10) + " folder/s"}
p.stamp("log", out, msg, "")
} | 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 {
base, _ := filepath.Abs(p.Path)
base = filepath.Join(base, dir)
if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, p.walk); err != nil {
p.Err(err)
}
}
}
// start message
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Blue.Bold("Watching"), Magenta.Bold(p.files), "file/s", Magenta.Bold(p.folders), "folder/s")
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(p.files, 10) + " files/s " + strconv.FormatInt(p.folders, 10) + " folder/s"}
p.stamp("log", out, msg, "")
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Before",
"(",
")",
"{",
"if",
"p",
".",
"parent",
".",
"Before",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Before",
"(",
"Context",
"{",
"Project",
":",
"p",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"hasGoMod",
"(",
"Wdir",
"(",
")",
")",
"{",
"p",
".",
"Tools",
".",
"vgo",
"=",
"true",
"\n",
"}",
"\n\n",
"// setup go tools",
"p",
".",
"Tools",
".",
"Setup",
"(",
")",
"\n",
"// global commands before",
"p",
".",
"cmd",
"(",
"p",
".",
"stop",
",",
"\"",
"\"",
",",
"true",
")",
"\n",
"// indexing files and dirs",
"for",
"_",
",",
"dir",
":=",
"range",
"p",
".",
"Watcher",
".",
"Paths",
"{",
"base",
",",
"_",
":=",
"filepath",
".",
"Abs",
"(",
"p",
".",
"Path",
")",
"\n",
"base",
"=",
"filepath",
".",
"Join",
"(",
"base",
",",
"dir",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"base",
")",
";",
"err",
"==",
"nil",
"{",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"base",
",",
"p",
".",
"walk",
")",
";",
"err",
"!=",
"nil",
"{",
"p",
".",
"Err",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"// start message",
"msg",
"=",
"fmt",
".",
"Sprintln",
"(",
"p",
".",
"pname",
"(",
"p",
".",
"Name",
",",
"1",
")",
",",
"\"",
"\"",
",",
"Blue",
".",
"Bold",
"(",
"\"",
"\"",
")",
",",
"Magenta",
".",
"Bold",
"(",
"p",
".",
"files",
")",
",",
"\"",
"\"",
",",
"Magenta",
".",
"Bold",
"(",
"p",
".",
"folders",
")",
",",
"\"",
"\"",
")",
"\n",
"out",
"=",
"BufferOut",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Text",
":",
"\"",
"\"",
"+",
"strconv",
".",
"FormatInt",
"(",
"p",
".",
"files",
",",
"10",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"FormatInt",
"(",
"p",
".",
"folders",
",",
"10",
")",
"+",
"\"",
"\"",
"}",
"\n",
"p",
".",
"stamp",
"(",
"\"",
"\"",
",",
"out",
",",
"msg",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Before start watcher | [
"Before",
"start",
"watcher"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L112-L140 |
147,843 | 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)), "changed", Magenta.Bold(event.Name))
out = BufferOut{Time: time.Now(), Text: ext + " changed " + event.Name}
p.stamp("log", out, msg, "")
} | 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)), "changed", Magenta.Bold(event.Name))
out = BufferOut{Time: time.Now(), Text: ext + " changed " + event.Name}
p.stamp("log", out, msg, "")
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Change",
"(",
"event",
"fsnotify",
".",
"Event",
")",
"{",
"if",
"p",
".",
"parent",
".",
"Change",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Change",
"(",
"Context",
"{",
"Project",
":",
"p",
",",
"Event",
":",
"event",
"}",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// file extension",
"ext",
":=",
"ext",
"(",
"event",
".",
"Name",
")",
"\n",
"if",
"ext",
"==",
"\"",
"\"",
"{",
"ext",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"// change message",
"msg",
"=",
"fmt",
".",
"Sprintln",
"(",
"p",
".",
"pname",
"(",
"p",
".",
"Name",
",",
"4",
")",
",",
"\"",
"\"",
",",
"Magenta",
".",
"Bold",
"(",
"strings",
".",
"ToUpper",
"(",
"ext",
")",
")",
",",
"\"",
"\"",
",",
"Magenta",
".",
"Bold",
"(",
"event",
".",
"Name",
")",
")",
"\n",
"out",
"=",
"BufferOut",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Text",
":",
"ext",
"+",
"\"",
"\"",
"+",
"event",
".",
"Name",
"}",
"\n",
"p",
".",
"stamp",
"(",
"\"",
"\"",
",",
"out",
",",
"msg",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Change event message | [
"Change",
"event",
"message"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L156-L170 |
147,844 | 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()
// start watcher
go p.Reload("", p.stop)
L:
for {
select {
case event := <-p.watcher.Events():
if p.parent.Settings.Recovery.Events {
log.Println("File:", event.Name, "LastFile:", p.last.file, "Time:", time.Now(), "LastTime:", p.last.time)
}
if time.Now().Truncate(time.Second).After(p.last.time) {
// switch event type
switch event.Op {
case fsnotify.Chmod:
case fsnotify.Remove:
p.watcher.Remove(event.Name)
if p.Validate(event.Name, false) && ext(event.Name) != "" {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload("", p.stop)
}
default:
if p.Validate(event.Name, true) {
fi, err := os.Stat(event.Name)
if err != nil {
continue
}
if fi.IsDir() {
filepath.Walk(event.Name, p.walk)
} else {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload(event.Name, p.stop)
p.last.time = time.Now().Truncate(time.Second)
p.last.file = event.Name
}
}
}
}
case err := <-p.watcher.Errors():
p.Err(err)
case <-p.exit:
p.After()
break L
}
}
wg.Done()
} | 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()
// start watcher
go p.Reload("", p.stop)
L:
for {
select {
case event := <-p.watcher.Events():
if p.parent.Settings.Recovery.Events {
log.Println("File:", event.Name, "LastFile:", p.last.file, "Time:", time.Now(), "LastTime:", p.last.time)
}
if time.Now().Truncate(time.Second).After(p.last.time) {
// switch event type
switch event.Op {
case fsnotify.Chmod:
case fsnotify.Remove:
p.watcher.Remove(event.Name)
if p.Validate(event.Name, false) && ext(event.Name) != "" {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload("", p.stop)
}
default:
if p.Validate(event.Name, true) {
fi, err := os.Stat(event.Name)
if err != nil {
continue
}
if fi.IsDir() {
filepath.Walk(event.Name, p.walk)
} else {
// stop and restart
close(p.stop)
p.stop = make(chan bool)
p.Change(event)
go p.Reload(event.Name, p.stop)
p.last.time = time.Now().Truncate(time.Second)
p.last.file = event.Name
}
}
}
}
case err := <-p.watcher.Errors():
p.Err(err)
case <-p.exit:
p.After()
break L
}
}
wg.Done()
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Watch",
"(",
"wg",
"*",
"sync",
".",
"WaitGroup",
")",
"{",
"var",
"err",
"error",
"\n",
"// change channel",
"p",
".",
"stop",
"=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"// init a new watcher",
"p",
".",
"watcher",
",",
"err",
"=",
"NewFileWatcher",
"(",
"p",
".",
"parent",
".",
"Settings",
".",
"Legacy",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"close",
"(",
"p",
".",
"stop",
")",
"\n",
"p",
".",
"watcher",
".",
"Close",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"// before start checks",
"p",
".",
"Before",
"(",
")",
"\n",
"// start watcher",
"go",
"p",
".",
"Reload",
"(",
"\"",
"\"",
",",
"p",
".",
"stop",
")",
"\n",
"L",
":",
"for",
"{",
"select",
"{",
"case",
"event",
":=",
"<-",
"p",
".",
"watcher",
".",
"Events",
"(",
")",
":",
"if",
"p",
".",
"parent",
".",
"Settings",
".",
"Recovery",
".",
"Events",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"event",
".",
"Name",
",",
"\"",
"\"",
",",
"p",
".",
"last",
".",
"file",
",",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
",",
"\"",
"\"",
",",
"p",
".",
"last",
".",
"time",
")",
"\n",
"}",
"\n",
"if",
"time",
".",
"Now",
"(",
")",
".",
"Truncate",
"(",
"time",
".",
"Second",
")",
".",
"After",
"(",
"p",
".",
"last",
".",
"time",
")",
"{",
"// switch event type",
"switch",
"event",
".",
"Op",
"{",
"case",
"fsnotify",
".",
"Chmod",
":",
"case",
"fsnotify",
".",
"Remove",
":",
"p",
".",
"watcher",
".",
"Remove",
"(",
"event",
".",
"Name",
")",
"\n",
"if",
"p",
".",
"Validate",
"(",
"event",
".",
"Name",
",",
"false",
")",
"&&",
"ext",
"(",
"event",
".",
"Name",
")",
"!=",
"\"",
"\"",
"{",
"// stop and restart",
"close",
"(",
"p",
".",
"stop",
")",
"\n",
"p",
".",
"stop",
"=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"p",
".",
"Change",
"(",
"event",
")",
"\n",
"go",
"p",
".",
"Reload",
"(",
"\"",
"\"",
",",
"p",
".",
"stop",
")",
"\n",
"}",
"\n",
"default",
":",
"if",
"p",
".",
"Validate",
"(",
"event",
".",
"Name",
",",
"true",
")",
"{",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"event",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"filepath",
".",
"Walk",
"(",
"event",
".",
"Name",
",",
"p",
".",
"walk",
")",
"\n",
"}",
"else",
"{",
"// stop and restart",
"close",
"(",
"p",
".",
"stop",
")",
"\n",
"p",
".",
"stop",
"=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"p",
".",
"Change",
"(",
"event",
")",
"\n",
"go",
"p",
".",
"Reload",
"(",
"event",
".",
"Name",
",",
"p",
".",
"stop",
")",
"\n",
"p",
".",
"last",
".",
"time",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Truncate",
"(",
"time",
".",
"Second",
")",
"\n",
"p",
".",
"last",
".",
"file",
"=",
"event",
".",
"Name",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"err",
":=",
"<-",
"p",
".",
"watcher",
".",
"Errors",
"(",
")",
":",
"p",
".",
"Err",
"(",
"err",
")",
"\n",
"case",
"<-",
"p",
".",
"exit",
":",
"p",
".",
"After",
"(",
")",
"\n",
"break",
"L",
"\n",
"}",
"\n",
"}",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}"
] | // Watch a project | [
"Watch",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L277-L342 |
147,845 | 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
for _, v := range p.Watcher.Ignore {
if v == e {
return false
}
}
// supported extensions
for index, v := range p.Watcher.Exts {
if e == v {
break
}
if index == len(p.Watcher.Exts)-1 {
return false
}
}
}
if p.shouldIgnore(path) {
return false
}
// file check
if fcheck {
fi, err := os.Stat(path)
if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0 {
return false
}
}
return true
} | 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
for _, v := range p.Watcher.Ignore {
if v == e {
return false
}
}
// supported extensions
for index, v := range p.Watcher.Exts {
if e == v {
break
}
if index == len(p.Watcher.Exts)-1 {
return false
}
}
}
if p.shouldIgnore(path) {
return false
}
// file check
if fcheck {
fi, err := os.Stat(path)
if err != nil || fi.Mode()&os.ModeSymlink != 0 || !fi.IsDir() && ext(path) == "" || fi.Size() <= 0 {
return false
}
}
return true
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"Validate",
"(",
"path",
"string",
",",
"fcheck",
"bool",
")",
"bool",
"{",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// check if skip hidden",
"if",
"p",
".",
"Watcher",
".",
"Hidden",
"&&",
"isHidden",
"(",
"path",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// check for a valid ext or path",
"if",
"e",
":=",
"ext",
"(",
"path",
")",
";",
"e",
"!=",
"\"",
"\"",
"{",
"if",
"len",
"(",
"p",
".",
"Watcher",
".",
"Exts",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// check ignored",
"for",
"_",
",",
"v",
":=",
"range",
"p",
".",
"Watcher",
".",
"Ignore",
"{",
"if",
"v",
"==",
"e",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"// supported extensions",
"for",
"index",
",",
"v",
":=",
"range",
"p",
".",
"Watcher",
".",
"Exts",
"{",
"if",
"e",
"==",
"v",
"{",
"break",
"\n",
"}",
"\n",
"if",
"index",
"==",
"len",
"(",
"p",
".",
"Watcher",
".",
"Exts",
")",
"-",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"p",
".",
"shouldIgnore",
"(",
"path",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// file check",
"if",
"fcheck",
"{",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"fi",
".",
"Mode",
"(",
")",
"&",
"os",
".",
"ModeSymlink",
"!=",
"0",
"||",
"!",
"fi",
".",
"IsDir",
"(",
")",
"&&",
"ext",
"(",
"path",
")",
"==",
"\"",
"\"",
"||",
"fi",
".",
"Size",
"(",
")",
"<=",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n\n",
"}"
] | // Validate a file path | [
"Validate",
"a",
"file",
"path"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L345-L386 |
147,846 | 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(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 4:
name = Yellow.Regular("[") + Magenta.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 5:
name = Yellow.Regular("[") + Green.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
}
return name
} | 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(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 4:
name = Yellow.Regular("[") + Magenta.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
case 5:
name = Yellow.Regular("[") + Green.Bold(strings.ToUpper(name)) + Yellow.Regular("]")
break
}
return name
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"pname",
"(",
"name",
"string",
",",
"color",
"int",
")",
"string",
"{",
"switch",
"color",
"{",
"case",
"1",
":",
"name",
"=",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"+",
"strings",
".",
"ToUpper",
"(",
"name",
")",
"+",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"case",
"2",
":",
"name",
"=",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"+",
"Red",
".",
"Bold",
"(",
"strings",
".",
"ToUpper",
"(",
"name",
")",
")",
"+",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"case",
"3",
":",
"name",
"=",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"+",
"Blue",
".",
"Bold",
"(",
"strings",
".",
"ToUpper",
"(",
"name",
")",
")",
"+",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"case",
"4",
":",
"name",
"=",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"+",
"Magenta",
".",
"Bold",
"(",
"strings",
".",
"ToUpper",
"(",
"name",
")",
")",
"+",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"case",
"5",
":",
"name",
"=",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"+",
"Green",
".",
"Bold",
"(",
"strings",
".",
"ToUpper",
"(",
"name",
")",
")",
"+",
"Yellow",
".",
"Regular",
"(",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"}",
"\n",
"return",
"name",
"\n",
"}"
] | // 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 |
147,847 | 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.IsDir() {
if tool.dir {
result <- tool.Exec(path, stop)
}
} else if !tool.dir {
result <- tool.Exec(path, stop)
}
}
}
close(done)
}()
for {
select {
case <-done:
return
case <-stop:
return
case r := <-result:
if r.Err != nil {
if fi.IsDir() {
path, _ = filepath.Abs(fi.Name())
}
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), Red.Regular("there are some errors in"), ":", Magenta.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: r.Name, Stream: r.Err.Error()}
p.stamp("error", buff, msg, r.Err.Error())
} else if r.Out != "" {
msg = fmt.Sprintln(p.pname(p.Name, 3), ":", Red.Bold(r.Name), Red.Regular("outputs"), ":", Blue.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "outputs", Path: path, Type: r.Name, Stream: r.Out}
p.stamp("out", buff, msg, r.Out)
}
}
}
} | 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.IsDir() {
if tool.dir {
result <- tool.Exec(path, stop)
}
} else if !tool.dir {
result <- tool.Exec(path, stop)
}
}
}
close(done)
}()
for {
select {
case <-done:
return
case <-stop:
return
case r := <-result:
if r.Err != nil {
if fi.IsDir() {
path, _ = filepath.Abs(fi.Name())
}
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), Red.Regular("there are some errors in"), ":", Magenta.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: r.Name, Stream: r.Err.Error()}
p.stamp("error", buff, msg, r.Err.Error())
} else if r.Out != "" {
msg = fmt.Sprintln(p.pname(p.Name, 3), ":", Red.Bold(r.Name), Red.Regular("outputs"), ":", Blue.Bold(path))
buff := BufferOut{Time: time.Now(), Text: "outputs", Path: path, Type: r.Name, Stream: r.Out}
p.stamp("out", buff, msg, r.Out)
}
}
}
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"tools",
"(",
"stop",
"<-",
"chan",
"bool",
",",
"path",
"string",
",",
"fi",
"os",
".",
"FileInfo",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"result",
":=",
"make",
"(",
"chan",
"Response",
")",
"\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"p",
".",
"Tools",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"v",
".",
"NumField",
"(",
")",
"-",
"1",
";",
"i",
"++",
"{",
"tool",
":=",
"v",
".",
"Field",
"(",
"i",
")",
".",
"Interface",
"(",
")",
".",
"(",
"Tool",
")",
"\n",
"tool",
".",
"parent",
"=",
"p",
"\n",
"if",
"tool",
".",
"Status",
"&&",
"tool",
".",
"isTool",
"{",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"if",
"tool",
".",
"dir",
"{",
"result",
"<-",
"tool",
".",
"Exec",
"(",
"path",
",",
"stop",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"!",
"tool",
".",
"dir",
"{",
"result",
"<-",
"tool",
".",
"Exec",
"(",
"path",
",",
"stop",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"close",
"(",
"done",
")",
"\n",
"}",
"(",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"done",
":",
"return",
"\n",
"case",
"<-",
"stop",
":",
"return",
"\n",
"case",
"r",
":=",
"<-",
"result",
":",
"if",
"r",
".",
"Err",
"!=",
"nil",
"{",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"path",
",",
"_",
"=",
"filepath",
".",
"Abs",
"(",
"fi",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"msg",
"=",
"fmt",
".",
"Sprintln",
"(",
"p",
".",
"pname",
"(",
"p",
".",
"Name",
",",
"2",
")",
",",
"\"",
"\"",
",",
"Red",
".",
"Bold",
"(",
"r",
".",
"Name",
")",
",",
"Red",
".",
"Regular",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"Magenta",
".",
"Bold",
"(",
"path",
")",
")",
"\n",
"buff",
":=",
"BufferOut",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Text",
":",
"\"",
"\"",
",",
"Path",
":",
"path",
",",
"Type",
":",
"r",
".",
"Name",
",",
"Stream",
":",
"r",
".",
"Err",
".",
"Error",
"(",
")",
"}",
"\n",
"p",
".",
"stamp",
"(",
"\"",
"\"",
",",
"buff",
",",
"msg",
",",
"r",
".",
"Err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"r",
".",
"Out",
"!=",
"\"",
"\"",
"{",
"msg",
"=",
"fmt",
".",
"Sprintln",
"(",
"p",
".",
"pname",
"(",
"p",
".",
"Name",
",",
"3",
")",
",",
"\"",
"\"",
",",
"Red",
".",
"Bold",
"(",
"r",
".",
"Name",
")",
",",
"Red",
".",
"Regular",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"Blue",
".",
"Bold",
"(",
"path",
")",
")",
"\n",
"buff",
":=",
"BufferOut",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Text",
":",
"\"",
"\"",
",",
"Path",
":",
"path",
",",
"Type",
":",
"r",
".",
"Name",
",",
"Stream",
":",
"r",
".",
"Out",
"}",
"\n",
"p",
".",
"stamp",
"(",
"\"",
"\"",
",",
"buff",
",",
"msg",
",",
"r",
".",
"Out",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // 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 |
147,848 | 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, path, info)
if info.IsDir() {
// tools dir
p.folders++
} else {
// tools files
p.files++
}
}
}
return nil
} | 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, path, info)
if info.IsDir() {
// tools dir
p.folders++
} else {
// tools files
p.files++
}
}
}
return nil
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"walk",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"p",
".",
"shouldIgnore",
"(",
"path",
")",
"{",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"Validate",
"(",
"path",
",",
"true",
")",
"{",
"result",
":=",
"p",
".",
"watcher",
".",
"Walk",
"(",
"path",
",",
"p",
".",
"init",
")",
"\n",
"if",
"result",
"!=",
"\"",
"\"",
"{",
"if",
"p",
".",
"parent",
".",
"Settings",
".",
"Recovery",
".",
"Index",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n",
"p",
".",
"tools",
"(",
"p",
".",
"stop",
",",
"path",
",",
"info",
")",
"\n",
"if",
"info",
".",
"IsDir",
"(",
")",
"{",
"// tools dir",
"p",
".",
"folders",
"++",
"\n",
"}",
"else",
"{",
"// tools files",
"p",
".",
"files",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\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 |
147,849 | 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.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Outputs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.parent.Settings.Files.Logs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Logs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.parent.Settings.Files.Errors.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Errors.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
}
if msg != "" {
log.Print(msg)
}
if stream != "" {
fmt.Fprintln(Output, stream)
}
go func() {
p.parent.Sync <- "sync"
}()
} | 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.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Outputs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.parent.Settings.Files.Logs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Logs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.parent.Settings.Files.Errors.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Errors.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "")
}
}
}
if msg != "" {
log.Print(msg)
}
if stream != "" {
fmt.Fprintln(Output, stream)
}
go func() {
p.parent.Sync <- "sync"
}()
} | [
"func",
"(",
"p",
"*",
"Project",
")",
"stamp",
"(",
"t",
"string",
",",
"o",
"BufferOut",
",",
"msg",
"string",
",",
"stream",
"string",
")",
"{",
"ctime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"content",
":=",
"[",
"]",
"string",
"{",
"ctime",
".",
"Format",
"(",
"\"",
"\"",
")",
",",
"strings",
".",
"ToUpper",
"(",
"p",
".",
"Name",
")",
",",
"\"",
"\"",
",",
"o",
".",
"Text",
",",
"\"",
"\\r",
"\\n",
"\"",
",",
"stream",
"}",
"\n",
"switch",
"t",
"{",
"case",
"\"",
"\"",
":",
"p",
".",
"Buffer",
".",
"StdOut",
"=",
"append",
"(",
"p",
".",
"Buffer",
".",
"StdOut",
",",
"o",
")",
"\n",
"if",
"p",
".",
"parent",
".",
"Settings",
".",
"Files",
".",
"Outputs",
".",
"Status",
"{",
"f",
":=",
"p",
".",
"parent",
".",
"Settings",
".",
"Create",
"(",
"p",
".",
"Path",
",",
"p",
".",
"parent",
".",
"Settings",
".",
"Files",
".",
"Outputs",
".",
"Name",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"f",
".",
"WriteString",
"(",
"strings",
".",
"Join",
"(",
"content",
",",
"\"",
"\"",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Settings",
".",
"Fatal",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"p",
".",
"Buffer",
".",
"StdLog",
"=",
"append",
"(",
"p",
".",
"Buffer",
".",
"StdLog",
",",
"o",
")",
"\n",
"if",
"p",
".",
"parent",
".",
"Settings",
".",
"Files",
".",
"Logs",
".",
"Status",
"{",
"f",
":=",
"p",
".",
"parent",
".",
"Settings",
".",
"Create",
"(",
"p",
".",
"Path",
",",
"p",
".",
"parent",
".",
"Settings",
".",
"Files",
".",
"Logs",
".",
"Name",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"f",
".",
"WriteString",
"(",
"strings",
".",
"Join",
"(",
"content",
",",
"\"",
"\"",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Settings",
".",
"Fatal",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"\"",
"\"",
":",
"p",
".",
"Buffer",
".",
"StdErr",
"=",
"append",
"(",
"p",
".",
"Buffer",
".",
"StdErr",
",",
"o",
")",
"\n",
"if",
"p",
".",
"parent",
".",
"Settings",
".",
"Files",
".",
"Errors",
".",
"Status",
"{",
"f",
":=",
"p",
".",
"parent",
".",
"Settings",
".",
"Create",
"(",
"p",
".",
"Path",
",",
"p",
".",
"parent",
".",
"Settings",
".",
"Files",
".",
"Errors",
".",
"Name",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"f",
".",
"WriteString",
"(",
"strings",
".",
"Join",
"(",
"content",
",",
"\"",
"\"",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"p",
".",
"parent",
".",
"Settings",
".",
"Fatal",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"msg",
"!=",
"\"",
"\"",
"{",
"log",
".",
"Print",
"(",
"msg",
")",
"\n",
"}",
"\n",
"if",
"stream",
"!=",
"\"",
"\"",
"{",
"fmt",
".",
"Fprintln",
"(",
"Output",
",",
"stream",
")",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"p",
".",
"parent",
".",
"Sync",
"<-",
"\"",
"\"",
"\n",
"}",
"(",
")",
"\n",
"}"
] | // Print on files, cli, ws | [
"Print",
"on",
"files",
"cli",
"ws"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L525-L563 |
147,850 | 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(p.Name, 5), ":", Green.Bold(r.Name), "completed in", Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: r.Name + " in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.stamp("log", out, msg, r.Out)
}
} | 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(p.Name, 5), ":", Green.Bold(r.Name), "completed in", Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: r.Name + " in " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.stamp("log", out, msg, r.Out)
}
} | [
"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",
"(",
")",
")",
"\n",
"out",
"=",
"BufferOut",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Text",
":",
"r",
".",
"Err",
".",
"Error",
"(",
")",
",",
"Type",
":",
"r",
".",
"Name",
",",
"Stream",
":",
"r",
".",
"Out",
"}",
"\n",
"p",
".",
"stamp",
"(",
"\"",
"\"",
",",
"out",
",",
"msg",
",",
"r",
".",
"Out",
")",
"\n",
"}",
"else",
"{",
"msg",
"=",
"fmt",
".",
"Sprintln",
"(",
"p",
".",
"pname",
"(",
"p",
".",
"Name",
",",
"5",
")",
",",
"\"",
"\"",
",",
"Green",
".",
"Bold",
"(",
"r",
".",
"Name",
")",
",",
"\"",
"\"",
",",
"Magenta",
".",
"Regular",
"(",
"big",
".",
"NewFloat",
"(",
"float64",
"(",
"time",
".",
"Since",
"(",
"start",
")",
".",
"Seconds",
"(",
")",
")",
")",
".",
"Text",
"(",
"'f'",
",",
"3",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"out",
"=",
"BufferOut",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
",",
"Text",
":",
"r",
".",
"Name",
"+",
"\"",
"\"",
"+",
"big",
".",
"NewFloat",
"(",
"float64",
"(",
"time",
".",
"Since",
"(",
"start",
")",
".",
"Seconds",
"(",
")",
")",
")",
".",
"Text",
"(",
"'f'",
",",
"3",
")",
"+",
"\"",
"\"",
"}",
"\n",
"p",
".",
"stamp",
"(",
"\"",
"\"",
",",
"out",
",",
"msg",
",",
"r",
".",
"Out",
")",
"\n",
"}",
"\n",
"}"
] | // Print with time after | [
"Print",
"with",
"time",
"after"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/projects.go#L680-L690 |
147,851 | 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 path
if c.Path != "" {
if strings.Contains(c.Path, base) {
ex.Dir = c.Path
} else {
ex.Dir = filepath.Join(base, c.Path)
}
}
ex.Stdout = &stdout
ex.Stderr = &stderr
// Start command
ex.Start()
go func() { done <- ex.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
ex.Process.Kill()
case err := <-done:
// Command completed
response.Name = c.Cmd
response.Out = stdout.String()
if err != nil {
response.Err = errors.New(stderr.String() + stdout.String())
}
}
return
} | 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 path
if c.Path != "" {
if strings.Contains(c.Path, base) {
ex.Dir = c.Path
} else {
ex.Dir = filepath.Join(base, c.Path)
}
}
ex.Stdout = &stdout
ex.Stderr = &stderr
// Start command
ex.Start()
go func() { done <- ex.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
ex.Process.Kill()
case err := <-done:
// Command completed
response.Name = c.Cmd
response.Out = stdout.String()
if err != nil {
response.Err = errors.New(stderr.String() + stdout.String())
}
}
return
} | [
"func",
"(",
"c",
"*",
"Command",
")",
"exec",
"(",
"base",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"var",
"stdout",
"bytes",
".",
"Buffer",
"\n",
"var",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"done",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"args",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"Replace",
"(",
"strings",
".",
"Replace",
"(",
"c",
".",
"Cmd",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
",",
"\"",
"\\\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
",",
"\"",
"\"",
")",
"\n",
"ex",
":=",
"exec",
".",
"Command",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"ex",
".",
"Dir",
"=",
"base",
"\n",
"// make cmd path",
"if",
"c",
".",
"Path",
"!=",
"\"",
"\"",
"{",
"if",
"strings",
".",
"Contains",
"(",
"c",
".",
"Path",
",",
"base",
")",
"{",
"ex",
".",
"Dir",
"=",
"c",
".",
"Path",
"\n",
"}",
"else",
"{",
"ex",
".",
"Dir",
"=",
"filepath",
".",
"Join",
"(",
"base",
",",
"c",
".",
"Path",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ex",
".",
"Stdout",
"=",
"&",
"stdout",
"\n",
"ex",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"// Start command",
"ex",
".",
"Start",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"done",
"<-",
"ex",
".",
"Wait",
"(",
")",
"}",
"(",
")",
"\n",
"// Wait a result",
"select",
"{",
"case",
"<-",
"stop",
":",
"// Stop running command",
"ex",
".",
"Process",
".",
"Kill",
"(",
")",
"\n",
"case",
"err",
":=",
"<-",
"done",
":",
"// Command completed",
"response",
".",
"Name",
"=",
"c",
".",
"Cmd",
"\n",
"response",
".",
"Out",
"=",
"stdout",
".",
"String",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"response",
".",
"Err",
"=",
"errors",
".",
"New",
"(",
"stderr",
".",
"String",
"(",
")",
"+",
"stdout",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // 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 |
147,852 | 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 |
147,853 | 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",
".",
"Prefix",
"(",
"realize",
".",
"Green",
".",
"Bold",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Clean remove realize file | [
"Clean",
"remove",
"realize",
"file"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize.go#L112-L118 |
147,854 | 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 err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("project successfully added")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project can't be added")))
}
return nil
} | 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 err != nil {
return err
}
log.Println(r.Prefix(realize.Green.Bold("project successfully added")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project can't be added")))
}
return nil
} | [
"func",
"add",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"// read a config if exist",
"err",
"=",
"r",
".",
"Settings",
".",
"Read",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"projects",
":=",
"len",
"(",
"r",
".",
"Schema",
".",
"Projects",
")",
"\n",
"// create and add a new project",
"r",
".",
"Schema",
".",
"Add",
"(",
"r",
".",
"Schema",
".",
"New",
"(",
"c",
")",
")",
"\n",
"if",
"len",
"(",
"r",
".",
"Schema",
".",
"Projects",
")",
">",
"projects",
"{",
"// update config",
"err",
"=",
"r",
".",
"Settings",
".",
"Write",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Println",
"(",
"r",
".",
"Prefix",
"(",
"realize",
".",
"Green",
".",
"Bold",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Println",
"(",
"r",
".",
"Prefix",
"(",
"realize",
".",
"Green",
".",
"Bold",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\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 |
147,855 | 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
}
log.Println(r.Prefix(realize.Green.Bold("project successfully removed")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project name not found")))
}
return nil
} | 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
}
log.Println(r.Prefix(realize.Green.Bold("project successfully removed")))
} else {
log.Println(r.Prefix(realize.Green.Bold("project name not found")))
}
return nil
} | [
"func",
"remove",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"err",
"error",
")",
"{",
"// read a config if exist",
"err",
"=",
"r",
".",
"Settings",
".",
"Read",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
"!=",
"\"",
"\"",
"{",
"err",
":=",
"r",
".",
"Schema",
".",
"Remove",
"(",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// update config",
"err",
"=",
"r",
".",
"Settings",
".",
"Write",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Println",
"(",
"r",
".",
"Prefix",
"(",
"realize",
".",
"Green",
".",
"Bold",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Println",
"(",
"r",
".",
"Prefix",
"(",
"realize",
".",
"Green",
".",
"Bold",
"(",
"\"",
"\"",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\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 |
147,856 | 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.Name())
if matched {
break
}
}
if !matched {
return
}
} else if !strings.HasSuffix(path, ".go") {
return
}
args := t.Args
if strings.HasSuffix(path, ".go") {
args = append(args, path)
path = filepath.Dir(path)
}
if s := ext(path); s == "" || s == "go" {
if t.parent.parent.Settings.Recovery.Tools {
log.Println("Tool:", t.name, path, args)
}
var out, stderr bytes.Buffer
done := make(chan error)
args = append(t.cmd, args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout = &out
cmd.Stderr = &stderr
// Start command
err := cmd.Start()
if err != nil {
response.Name = t.name
response.Err = err
return
}
go func() { done <- cmd.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
response.Name = t.name
if err != nil {
response.Err = errors.New(stderr.String() + out.String() + err.Error())
} else {
if t.Output {
response.Out = out.String()
}
}
}
}
return
} | 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.Name())
if matched {
break
}
}
if !matched {
return
}
} else if !strings.HasSuffix(path, ".go") {
return
}
args := t.Args
if strings.HasSuffix(path, ".go") {
args = append(args, path)
path = filepath.Dir(path)
}
if s := ext(path); s == "" || s == "go" {
if t.parent.parent.Settings.Recovery.Tools {
log.Println("Tool:", t.name, path, args)
}
var out, stderr bytes.Buffer
done := make(chan error)
args = append(t.cmd, args...)
cmd := exec.Command(args[0], args[1:]...)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {
cmd.Dir = path
}
cmd.Stdout = &out
cmd.Stderr = &stderr
// Start command
err := cmd.Start()
if err != nil {
response.Name = t.name
response.Err = err
return
}
go func() { done <- cmd.Wait() }()
// Wait a result
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
response.Name = t.name
if err != nil {
response.Err = errors.New(stderr.String() + out.String() + err.Error())
} else {
if t.Output {
response.Out = out.String()
}
}
}
}
return
} | [
"func",
"(",
"t",
"*",
"Tool",
")",
"Exec",
"(",
"path",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"if",
"t",
".",
"dir",
"{",
"if",
"filepath",
".",
"Ext",
"(",
"path",
")",
"!=",
"\"",
"\"",
"{",
"path",
"=",
"filepath",
".",
"Dir",
"(",
"path",
")",
"\n",
"}",
"\n",
"// check if there is at least one go file",
"matched",
":=",
"false",
"\n",
"files",
",",
"_",
":=",
"ioutil",
".",
"ReadDir",
"(",
"path",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"files",
"{",
"matched",
",",
"_",
"=",
"filepath",
".",
"Match",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"matched",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"matched",
"{",
"return",
"\n",
"}",
"\n",
"}",
"else",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"path",
",",
"\"",
"\"",
")",
"{",
"return",
"\n",
"}",
"\n",
"args",
":=",
"t",
".",
"Args",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"path",
",",
"\"",
"\"",
")",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"path",
")",
"\n",
"path",
"=",
"filepath",
".",
"Dir",
"(",
"path",
")",
"\n",
"}",
"\n",
"if",
"s",
":=",
"ext",
"(",
"path",
")",
";",
"s",
"==",
"\"",
"\"",
"||",
"s",
"==",
"\"",
"\"",
"{",
"if",
"t",
".",
"parent",
".",
"parent",
".",
"Settings",
".",
"Recovery",
".",
"Tools",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"t",
".",
"name",
",",
"path",
",",
"args",
")",
"\n",
"}",
"\n",
"var",
"out",
",",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"done",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"args",
"=",
"append",
"(",
"t",
".",
"cmd",
",",
"args",
"...",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"if",
"t",
".",
"Dir",
"!=",
"\"",
"\"",
"{",
"cmd",
".",
"Dir",
",",
"_",
"=",
"filepath",
".",
"Abs",
"(",
"t",
".",
"Dir",
")",
"\n",
"}",
"else",
"{",
"cmd",
".",
"Dir",
"=",
"path",
"\n",
"}",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"out",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"// Start command",
"err",
":=",
"cmd",
".",
"Start",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"response",
".",
"Name",
"=",
"t",
".",
"name",
"\n",
"response",
".",
"Err",
"=",
"err",
"\n",
"return",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"done",
"<-",
"cmd",
".",
"Wait",
"(",
")",
"}",
"(",
")",
"\n",
"// Wait a result",
"select",
"{",
"case",
"<-",
"stop",
":",
"// Stop running command",
"cmd",
".",
"Process",
".",
"Kill",
"(",
")",
"\n",
"case",
"err",
":=",
"<-",
"done",
":",
"// Command completed",
"response",
".",
"Name",
"=",
"t",
".",
"name",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"response",
".",
"Err",
"=",
"errors",
".",
"New",
"(",
"stderr",
".",
"String",
"(",
")",
"+",
"out",
".",
"String",
"(",
")",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"if",
"t",
".",
"Output",
"{",
"response",
".",
"Out",
"=",
"out",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Exec a go tool | [
"Exec",
"a",
"go",
"tool"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/tools.go#L105-L171 |
147,857 | 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 = &out
cmd.Stderr = &stderr
// Start command
cmd.Start()
go func() { done <- cmd.Wait() }()
// Wait a result
response.Name = t.name
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
if err != nil {
response.Err = errors.New(stderr.String() + err.Error())
}
}
return
} | 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 = &out
cmd.Stderr = &stderr
// Start command
cmd.Start()
go func() { done <- cmd.Wait() }()
// Wait a result
response.Name = t.name
select {
case <-stop:
// Stop running command
cmd.Process.Kill()
case err := <-done:
// Command completed
if err != nil {
response.Err = errors.New(stderr.String() + err.Error())
}
}
return
} | [
"func",
"(",
"t",
"*",
"Tool",
")",
"Compile",
"(",
"path",
"string",
",",
"stop",
"<-",
"chan",
"bool",
")",
"(",
"response",
"Response",
")",
"{",
"var",
"out",
"bytes",
".",
"Buffer",
"\n",
"var",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"done",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"args",
":=",
"append",
"(",
"t",
".",
"cmd",
",",
"t",
".",
"Args",
"...",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"if",
"t",
".",
"Dir",
"!=",
"\"",
"\"",
"{",
"cmd",
".",
"Dir",
",",
"_",
"=",
"filepath",
".",
"Abs",
"(",
"t",
".",
"Dir",
")",
"\n",
"}",
"else",
"{",
"cmd",
".",
"Dir",
"=",
"path",
"\n",
"}",
"\n",
"cmd",
".",
"Stdout",
"=",
"&",
"out",
"\n",
"cmd",
".",
"Stderr",
"=",
"&",
"stderr",
"\n",
"// Start command",
"cmd",
".",
"Start",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"done",
"<-",
"cmd",
".",
"Wait",
"(",
")",
"}",
"(",
")",
"\n",
"// Wait a result",
"response",
".",
"Name",
"=",
"t",
".",
"name",
"\n",
"select",
"{",
"case",
"<-",
"stop",
":",
"// Stop running command",
"cmd",
".",
"Process",
".",
"Kill",
"(",
")",
"\n",
"case",
"err",
":=",
"<-",
"done",
":",
"// Command completed",
"if",
"err",
"!=",
"nil",
"{",
"response",
".",
"Err",
"=",
"errors",
".",
"New",
"(",
"stderr",
".",
"String",
"(",
")",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // 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 |
147,858 | 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",
";",
"i",
"<=",
"argsN",
"-",
"1",
";",
"i",
"++",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"params",
".",
"Args",
"(",
")",
".",
"Get",
"(",
"i",
")",
")",
"\n",
"}",
"\n",
"return",
"args",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
147,859 | 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",
",",
"arr",
"...",
")",
"\n",
"}",
"\n",
"return",
"args",
"\n",
"}"
] | // 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 |
147,860 | 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",
"]",
")",
";",
"i",
"--",
"{",
"if",
"path",
"[",
"i",
"]",
"==",
"'.'",
"{",
"ext",
"=",
"path",
"[",
"i",
":",
"]",
"\n",
"if",
"index",
":=",
"strings",
".",
"LastIndex",
"(",
"ext",
",",
"\"",
"\"",
")",
";",
"index",
">",
"0",
"{",
"ext",
"=",
"ext",
"[",
"index",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"ext",
"!=",
"\"",
"\"",
"{",
"return",
"ext",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // Get file extensions | [
"Get",
"file",
"extensions"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/utils.go#L46-L60 |
147,861 | 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 |
147,862 | 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 |
147,863 | 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",
"&",
"filePoller",
"{",
"interval",
":",
"interval",
",",
"events",
":",
"make",
"(",
"chan",
"fsnotify",
".",
"Event",
")",
",",
"errors",
":",
"make",
"(",
"chan",
"error",
")",
",",
"}",
"\n",
"}"
] | // 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 |
147,864 | 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",
"}",
"\n",
"}",
"\n",
"return",
"PollingWatcher",
"(",
"l",
".",
"Interval",
")",
",",
"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 |
147,865 | 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",
"&",
"fsNotifyWatcher",
"{",
"Watcher",
":",
"w",
"}",
",",
"nil",
"\n",
"}"
] | // 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 |
147,866 | 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",
".",
"closed",
"=",
"true",
"\n",
"for",
"name",
":=",
"range",
"w",
".",
"watches",
"{",
"w",
".",
"remove",
"(",
"name",
")",
"\n",
"delete",
"(",
"w",
".",
"watches",
",",
"name",
")",
"\n",
"}",
"\n",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
147,867 | 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 _, exists := w.watches[name]; exists {
return fmt.Errorf("watch exists")
}
chClose := make(chan struct{})
w.watches[name] = chClose
go w.watch(f, fi, chClose)
return nil
} | 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 _, exists := w.watches[name]; exists {
return fmt.Errorf("watch exists")
}
chClose := make(chan struct{})
w.watches[name] = chClose
go w.watch(f, fi, chClose)
return nil
} | [
"func",
"(",
"w",
"*",
"filePoller",
")",
"Add",
"(",
"name",
"string",
")",
"error",
"{",
"w",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"w",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"w",
".",
"closed",
"{",
"return",
"errPollerClosed",
"\n",
"}",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"w",
".",
"watches",
"==",
"nil",
"{",
"w",
".",
"watches",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"chan",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"exists",
":=",
"w",
".",
"watches",
"[",
"name",
"]",
";",
"exists",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"chClose",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"w",
".",
"watches",
"[",
"name",
"]",
"=",
"chClose",
"\n",
"go",
"w",
".",
"watch",
"(",
"f",
",",
"fi",
",",
"chClose",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
147,868 | 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",
"}",
"\n",
"s",
".",
"Projects",
"=",
"append",
"(",
"s",
".",
"Projects",
",",
"p",
")",
"\n",
"}"
] | // Add a project if unique | [
"Add",
"a",
"project",
"if",
"unique"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L17-L24 |
147,869 | 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",
"(",
"s",
".",
"Projects",
"[",
":",
"key",
"]",
",",
"s",
".",
"Projects",
"[",
"key",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Remove a project | [
"Remove",
"a",
"project"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L27-L35 |
147,870 | 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.Bool("vet"),
},
Fmt: Tool{
Status: c.Bool("fmt"),
},
Test: Tool{
Status: c.Bool("test"),
},
Generate: Tool{
Status: c.Bool("generate"),
},
Build: Tool{
Status: c.Bool("build"),
},
Install: Tool{
Status: c.Bool("install"),
},
Run: Tool{
Status: c.Bool("run"),
},
vgo: vgo,
},
Args: params(c),
Watcher: Watch{
Paths: []string{"/"},
Ignore: []string{".git", ".realize", "vendor"},
Exts: []string{"go"},
},
}
return project
} | 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.Bool("vet"),
},
Fmt: Tool{
Status: c.Bool("fmt"),
},
Test: Tool{
Status: c.Bool("test"),
},
Generate: Tool{
Status: c.Bool("generate"),
},
Build: Tool{
Status: c.Bool("build"),
},
Install: Tool{
Status: c.Bool("install"),
},
Run: Tool{
Status: c.Bool("run"),
},
vgo: vgo,
},
Args: params(c),
Watcher: Watch{
Paths: []string{"/"},
Ignore: []string{".git", ".realize", "vendor"},
Exts: []string{"go"},
},
}
return project
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"New",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"Project",
"{",
"var",
"vgo",
"bool",
"\n",
"name",
":=",
"filepath",
".",
"Base",
"(",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"len",
"(",
"name",
")",
"==",
"0",
"||",
"name",
"==",
"\"",
"\"",
"{",
"name",
"=",
"filepath",
".",
"Base",
"(",
"Wdir",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"hasGoMod",
"(",
"Wdir",
"(",
")",
")",
"{",
"vgo",
"=",
"true",
"\n",
"}",
"\n\n",
"project",
":=",
"Project",
"{",
"Name",
":",
"name",
",",
"Path",
":",
"c",
".",
"String",
"(",
"\"",
"\"",
")",
",",
"Tools",
":",
"Tools",
"{",
"Vet",
":",
"Tool",
"{",
"Status",
":",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"Fmt",
":",
"Tool",
"{",
"Status",
":",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"Test",
":",
"Tool",
"{",
"Status",
":",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"Generate",
":",
"Tool",
"{",
"Status",
":",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"Build",
":",
"Tool",
"{",
"Status",
":",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"Install",
":",
"Tool",
"{",
"Status",
":",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"Run",
":",
"Tool",
"{",
"Status",
":",
"c",
".",
"Bool",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"vgo",
":",
"vgo",
",",
"}",
",",
"Args",
":",
"params",
"(",
"c",
")",
",",
"Watcher",
":",
"Watch",
"{",
"Paths",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Ignore",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"Exts",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
",",
"}",
"\n",
"return",
"project",
"\n",
"}"
] | // 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 |
147,871 | 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, item)
}
}
}
}
return 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, item)
}
}
}
}
return result
} | [
"func",
"(",
"s",
"*",
"Schema",
")",
"Filter",
"(",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"[",
"]",
"Project",
"{",
"result",
":=",
"[",
"]",
"Project",
"{",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"s",
".",
"Projects",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"item",
")",
"\n",
"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",
",",
"item",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // Filter project list by field | [
"Filter",
"project",
"list",
"by",
"field"
] | 9bd3fd838bbb30c3e107a8af77783eeb4b78fef8 | https://github.com/oxequa/realize/blob/9bd3fd838bbb30c3e107a8af77783eeb4b78fef8/realize/schema.go#L87-L100 |
147,872 | 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 |
147,873 | 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 |
147,874 | 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",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"tpl",
":=",
"template",
".",
"Must",
"(",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Parse",
"(",
"buildPageTpl",
")",
")",
"\n",
"tpl",
".",
"Execute",
"(",
"w",
",",
"data",
")",
"\n",
"}"
] | // 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 |
147,875 | 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 |
147,876 | 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",
".",
"entries",
")",
"-",
"1",
"]",
".",
"Index",
"(",
")",
"\n",
"}"
] | // 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 |
147,877 | 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",
")",
"&&",
"(",
"l",
".",
"startIndex",
"==",
"0",
")",
"\n",
"}"
] | // 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 |
147,878 | 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",
"{",
"if",
"entry",
":=",
"l",
".",
"entries",
"[",
"len",
"(",
"l",
".",
"entries",
")",
"-",
"1",
"]",
";",
"entry",
"!=",
"nil",
"{",
"return",
"entry",
".",
"CommandName",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // 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 |
147,879 | 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",
"(",
")",
"\n",
"l",
".",
"file",
"=",
"nil",
"\n",
"}",
"\n",
"l",
".",
"entries",
"=",
"make",
"(",
"[",
"]",
"*",
"LogEntry",
",",
"0",
")",
"\n",
"}"
] | // Closes the log file. | [
"Closes",
"the",
"log",
"file",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L198-L207 |
147,880 | 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",
".",
"startIndex",
"||",
"index",
">",
"(",
"l",
".",
"startIndex",
"+",
"uint64",
"(",
"len",
"(",
"l",
".",
"entries",
")",
")",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"l",
".",
"entries",
"[",
"index",
"-",
"l",
".",
"startIndex",
"-",
"1",
"]",
"\n",
"}"
] | // 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 |
147,881 | 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
}
// Return an error if the index doesn't exist.
if index > (uint64(len(l.entries)) + l.startIndex) {
panic(fmt.Sprintf("raft: Index is beyond end of log: %v %v", len(l.entries), index))
}
// If we're going from the beginning of the log then return the whole log.
if index == l.startIndex {
traceln("log.entriesAfter.beginning: ", index, " ", l.startIndex)
return l.entries, l.startTerm
}
traceln("log.entriesAfter.partial: ", index, " ", l.entries[len(l.entries)-1].Index)
entries := l.entries[index-l.startIndex:]
length := len(entries)
traceln("log.entriesAfter: startIndex:", l.startIndex, " length", len(l.entries))
if uint64(length) < maxLogEntriesPerRequest {
// Determine the term at the given entry and return a subslice.
return entries, l.entries[index-1-l.startIndex].Term()
} else {
return entries[:maxLogEntriesPerRequest], l.entries[index-1-l.startIndex].Term()
}
} | 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
}
// Return an error if the index doesn't exist.
if index > (uint64(len(l.entries)) + l.startIndex) {
panic(fmt.Sprintf("raft: Index is beyond end of log: %v %v", len(l.entries), index))
}
// If we're going from the beginning of the log then return the whole log.
if index == l.startIndex {
traceln("log.entriesAfter.beginning: ", index, " ", l.startIndex)
return l.entries, l.startTerm
}
traceln("log.entriesAfter.partial: ", index, " ", l.entries[len(l.entries)-1].Index)
entries := l.entries[index-l.startIndex:]
length := len(entries)
traceln("log.entriesAfter: startIndex:", l.startIndex, " length", len(l.entries))
if uint64(length) < maxLogEntriesPerRequest {
// Determine the term at the given entry and return a subslice.
return entries, l.entries[index-1-l.startIndex].Term()
} else {
return entries[:maxLogEntriesPerRequest], l.entries[index-1-l.startIndex].Term()
}
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"getEntriesAfter",
"(",
"index",
"uint64",
",",
"maxLogEntriesPerRequest",
"uint64",
")",
"(",
"[",
"]",
"*",
"LogEntry",
",",
"uint64",
")",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"// Return nil if index is before the start of the log.",
"if",
"index",
"<",
"l",
".",
"startIndex",
"{",
"traceln",
"(",
"\"",
"\"",
",",
"index",
",",
"\"",
"\"",
",",
"l",
".",
"startIndex",
")",
"\n",
"return",
"nil",
",",
"0",
"\n",
"}",
"\n\n",
"// Return an error if the index doesn't exist.",
"if",
"index",
">",
"(",
"uint64",
"(",
"len",
"(",
"l",
".",
"entries",
")",
")",
"+",
"l",
".",
"startIndex",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"len",
"(",
"l",
".",
"entries",
")",
",",
"index",
")",
")",
"\n",
"}",
"\n\n",
"// If we're going from the beginning of the log then return the whole log.",
"if",
"index",
"==",
"l",
".",
"startIndex",
"{",
"traceln",
"(",
"\"",
"\"",
",",
"index",
",",
"\"",
"\"",
",",
"l",
".",
"startIndex",
")",
"\n",
"return",
"l",
".",
"entries",
",",
"l",
".",
"startTerm",
"\n",
"}",
"\n\n",
"traceln",
"(",
"\"",
"\"",
",",
"index",
",",
"\"",
"\"",
",",
"l",
".",
"entries",
"[",
"len",
"(",
"l",
".",
"entries",
")",
"-",
"1",
"]",
".",
"Index",
")",
"\n\n",
"entries",
":=",
"l",
".",
"entries",
"[",
"index",
"-",
"l",
".",
"startIndex",
":",
"]",
"\n",
"length",
":=",
"len",
"(",
"entries",
")",
"\n\n",
"traceln",
"(",
"\"",
"\"",
",",
"l",
".",
"startIndex",
",",
"\"",
"\"",
",",
"len",
"(",
"l",
".",
"entries",
")",
")",
"\n\n",
"if",
"uint64",
"(",
"length",
")",
"<",
"maxLogEntriesPerRequest",
"{",
"// Determine the term at the given entry and return a subslice.",
"return",
"entries",
",",
"l",
".",
"entries",
"[",
"index",
"-",
"1",
"-",
"l",
".",
"startIndex",
"]",
".",
"Term",
"(",
")",
"\n",
"}",
"else",
"{",
"return",
"entries",
"[",
":",
"maxLogEntriesPerRequest",
"]",
",",
"l",
".",
"entries",
"[",
"index",
"-",
"1",
"-",
"l",
".",
"startIndex",
"]",
".",
"Term",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // 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",
"because",
"a",
"snapshot",
"was",
"made",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L244-L278 |
147,882 | 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.Term()
} | 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.Term()
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"lastInfo",
"(",
")",
"(",
"index",
"uint64",
",",
"term",
"uint64",
")",
"{",
"l",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"// If we don't have any entries then just return zeros.",
"if",
"len",
"(",
"l",
".",
"entries",
")",
"==",
"0",
"{",
"return",
"l",
".",
"startIndex",
",",
"l",
".",
"startTerm",
"\n",
"}",
"\n\n",
"// Return the last index & term",
"entry",
":=",
"l",
".",
"entries",
"[",
"len",
"(",
"l",
".",
"entries",
")",
"-",
"1",
"]",
"\n",
"return",
"entry",
".",
"Index",
"(",
")",
",",
"entry",
".",
"Term",
"(",
")",
"\n",
"}"
] | // 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 |
147,883 | 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",
"{",
"l",
".",
"commitIndex",
"=",
"index",
"\n",
"}",
"\n",
"debugln",
"(",
"\"",
"\"",
",",
"index",
")",
"\n",
"}"
] | // Updates the commit index | [
"Updates",
"the",
"commit",
"index"
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L320-L327 |
147,884 | 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.entries))
index = l.startIndex + uint64(len(l.entries))
}
// Do not allow previous indices to be committed again.
// This could happens, since the guarantee is that the new leader has up-to-dated
// log entries rather than has most up-to-dated committed index
// For example, Leader 1 send log 80 to follower 2 and follower 3
// follower 2 and follow 3 all got the new entries and reply
// leader 1 committed entry 80 and send reply to follower 2 and follower3
// follower 2 receive the new committed index and update committed index to 80
// leader 1 fail to send the committed index to follower 3
// follower 3 promote to leader (server 1 and server 2 will vote, since leader 3
// has up-to-dated the entries)
// when new leader 3 send heartbeat with committed index = 0 to follower 2,
// follower 2 should reply success and let leader 3 update the committed index to 80
if index < l.commitIndex {
return nil
}
// Find all entries whose index is between the previous index and the current index.
for i := l.commitIndex + 1; i <= index; i++ {
entryIndex := i - 1 - l.startIndex
entry := l.entries[entryIndex]
// Update commit index.
l.commitIndex = entry.Index()
// Decode the command.
command, err := newCommand(entry.CommandName(), entry.Command())
if err != nil {
return err
}
// Apply the changes to the state machine and store the error code.
returnValue, err := l.ApplyFunc(entry, command)
debugf("setCommitIndex.set.result index: %v, entries index: %v", i, entryIndex)
if entry.event != nil {
entry.event.returnValue = returnValue
entry.event.c <- err
}
_, isJoinCommand := command.(JoinCommand)
// we can only commit up to the most recent join command
// if there is a join in this batch of commands.
// after this commit, we need to recalculate the majority.
if isJoinCommand {
return nil
}
}
return nil
} | 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.entries))
index = l.startIndex + uint64(len(l.entries))
}
// Do not allow previous indices to be committed again.
// This could happens, since the guarantee is that the new leader has up-to-dated
// log entries rather than has most up-to-dated committed index
// For example, Leader 1 send log 80 to follower 2 and follower 3
// follower 2 and follow 3 all got the new entries and reply
// leader 1 committed entry 80 and send reply to follower 2 and follower3
// follower 2 receive the new committed index and update committed index to 80
// leader 1 fail to send the committed index to follower 3
// follower 3 promote to leader (server 1 and server 2 will vote, since leader 3
// has up-to-dated the entries)
// when new leader 3 send heartbeat with committed index = 0 to follower 2,
// follower 2 should reply success and let leader 3 update the committed index to 80
if index < l.commitIndex {
return nil
}
// Find all entries whose index is between the previous index and the current index.
for i := l.commitIndex + 1; i <= index; i++ {
entryIndex := i - 1 - l.startIndex
entry := l.entries[entryIndex]
// Update commit index.
l.commitIndex = entry.Index()
// Decode the command.
command, err := newCommand(entry.CommandName(), entry.Command())
if err != nil {
return err
}
// Apply the changes to the state machine and store the error code.
returnValue, err := l.ApplyFunc(entry, command)
debugf("setCommitIndex.set.result index: %v, entries index: %v", i, entryIndex)
if entry.event != nil {
entry.event.returnValue = returnValue
entry.event.c <- err
}
_, isJoinCommand := command.(JoinCommand)
// we can only commit up to the most recent join command
// if there is a join in this batch of commands.
// after this commit, we need to recalculate the majority.
if isJoinCommand {
return nil
}
}
return nil
} | [
"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 number of sending entries",
"// commit up to what we already have",
"if",
"index",
">",
"l",
".",
"startIndex",
"+",
"uint64",
"(",
"len",
"(",
"l",
".",
"entries",
")",
")",
"{",
"debugln",
"(",
"\"",
"\"",
",",
"index",
",",
"\"",
"\"",
",",
"len",
"(",
"l",
".",
"entries",
")",
")",
"\n",
"index",
"=",
"l",
".",
"startIndex",
"+",
"uint64",
"(",
"len",
"(",
"l",
".",
"entries",
")",
")",
"\n",
"}",
"\n\n",
"// Do not allow previous indices to be committed again.",
"// This could happens, since the guarantee is that the new leader has up-to-dated",
"// log entries rather than has most up-to-dated committed index",
"// For example, Leader 1 send log 80 to follower 2 and follower 3",
"// follower 2 and follow 3 all got the new entries and reply",
"// leader 1 committed entry 80 and send reply to follower 2 and follower3",
"// follower 2 receive the new committed index and update committed index to 80",
"// leader 1 fail to send the committed index to follower 3",
"// follower 3 promote to leader (server 1 and server 2 will vote, since leader 3",
"// has up-to-dated the entries)",
"// when new leader 3 send heartbeat with committed index = 0 to follower 2,",
"// follower 2 should reply success and let leader 3 update the committed index to 80",
"if",
"index",
"<",
"l",
".",
"commitIndex",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Find all entries whose index is between the previous index and the current index.",
"for",
"i",
":=",
"l",
".",
"commitIndex",
"+",
"1",
";",
"i",
"<=",
"index",
";",
"i",
"++",
"{",
"entryIndex",
":=",
"i",
"-",
"1",
"-",
"l",
".",
"startIndex",
"\n",
"entry",
":=",
"l",
".",
"entries",
"[",
"entryIndex",
"]",
"\n\n",
"// Update commit index.",
"l",
".",
"commitIndex",
"=",
"entry",
".",
"Index",
"(",
")",
"\n\n",
"// Decode the command.",
"command",
",",
"err",
":=",
"newCommand",
"(",
"entry",
".",
"CommandName",
"(",
")",
",",
"entry",
".",
"Command",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Apply the changes to the state machine and store the error code.",
"returnValue",
",",
"err",
":=",
"l",
".",
"ApplyFunc",
"(",
"entry",
",",
"command",
")",
"\n\n",
"debugf",
"(",
"\"",
"\"",
",",
"i",
",",
"entryIndex",
")",
"\n",
"if",
"entry",
".",
"event",
"!=",
"nil",
"{",
"entry",
".",
"event",
".",
"returnValue",
"=",
"returnValue",
"\n",
"entry",
".",
"event",
".",
"c",
"<-",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"isJoinCommand",
":=",
"command",
".",
"(",
"JoinCommand",
")",
"\n\n",
"// we can only commit up to the most recent join command",
"// if there is a join in this batch of commands.",
"// after this commit, we need to recalculate the majority.",
"if",
"isJoinCommand",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
147,885 | 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",
".",
"commitIndex",
")",
"\n",
"l",
".",
"file",
".",
"Seek",
"(",
"0",
",",
"os",
".",
"SEEK_END",
")",
"\n",
"}"
] | // 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 |
147,886 | 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() < lastEntry.Term() {
return fmt.Errorf("raft.Log: Cannot append entry with earlier term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
} else if entry.Term() == lastEntry.Term() && entry.Index() <= lastEntry.Index() {
return fmt.Errorf("raft.Log: Cannot append entry with earlier index in the same term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
}
}
position, _ := l.file.Seek(0, os.SEEK_CUR)
entry.Position = position
// Write to storage.
if _, err := entry.Encode(l.file); err != nil {
return err
}
// Append to entries list if stored on disk.
l.entries = append(l.entries, entry)
return nil
} | 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() < lastEntry.Term() {
return fmt.Errorf("raft.Log: Cannot append entry with earlier term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
} else if entry.Term() == lastEntry.Term() && entry.Index() <= lastEntry.Index() {
return fmt.Errorf("raft.Log: Cannot append entry with earlier index in the same term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
}
}
position, _ := l.file.Seek(0, os.SEEK_CUR)
entry.Position = position
// Write to storage.
if _, err := entry.Encode(l.file); err != nil {
return err
}
// Append to entries list if stored on disk.
l.entries = append(l.entries, entry)
return nil
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"appendEntry",
"(",
"entry",
"*",
"LogEntry",
")",
"error",
"{",
"l",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"file",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Make sure the term and index are greater than the previous.",
"if",
"len",
"(",
"l",
".",
"entries",
")",
">",
"0",
"{",
"lastEntry",
":=",
"l",
".",
"entries",
"[",
"len",
"(",
"l",
".",
"entries",
")",
"-",
"1",
"]",
"\n",
"if",
"entry",
".",
"Term",
"(",
")",
"<",
"lastEntry",
".",
"Term",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"entry",
".",
"Term",
"(",
")",
",",
"entry",
".",
"Index",
"(",
")",
",",
"lastEntry",
".",
"Term",
"(",
")",
",",
"lastEntry",
".",
"Index",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"entry",
".",
"Term",
"(",
")",
"==",
"lastEntry",
".",
"Term",
"(",
")",
"&&",
"entry",
".",
"Index",
"(",
")",
"<=",
"lastEntry",
".",
"Index",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"entry",
".",
"Term",
"(",
")",
",",
"entry",
".",
"Index",
"(",
")",
",",
"lastEntry",
".",
"Term",
"(",
")",
",",
"lastEntry",
".",
"Index",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"position",
",",
"_",
":=",
"l",
".",
"file",
".",
"Seek",
"(",
"0",
",",
"os",
".",
"SEEK_CUR",
")",
"\n\n",
"entry",
".",
"Position",
"=",
"position",
"\n\n",
"// Write to storage.",
"if",
"_",
",",
"err",
":=",
"entry",
".",
"Encode",
"(",
"l",
".",
"file",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Append to entries list if stored on disk.",
"l",
".",
"entries",
"=",
"append",
"(",
"l",
".",
"entries",
",",
"entry",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
147,887 | 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() {
return -1, fmt.Errorf("raft.Log: Cannot append entry with earlier term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
} else if entry.Term() == lastEntry.Term() && entry.Index() <= lastEntry.Index() {
return -1, fmt.Errorf("raft.Log: Cannot append entry with earlier index in the same term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
}
}
// Write to storage.
size, err := entry.Encode(w)
if err != nil {
return -1, err
}
// Append to entries list if stored on disk.
l.entries = append(l.entries, entry)
return int64(size), nil
} | 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() {
return -1, fmt.Errorf("raft.Log: Cannot append entry with earlier term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
} else if entry.Term() == lastEntry.Term() && entry.Index() <= lastEntry.Index() {
return -1, fmt.Errorf("raft.Log: Cannot append entry with earlier index in the same term (%x:%x <= %x:%x)", entry.Term(), entry.Index(), lastEntry.Term(), lastEntry.Index())
}
}
// Write to storage.
size, err := entry.Encode(w)
if err != nil {
return -1, err
}
// Append to entries list if stored on disk.
l.entries = append(l.entries, entry)
return int64(size), nil
} | [
"func",
"(",
"l",
"*",
"Log",
")",
"writeEntry",
"(",
"entry",
"*",
"LogEntry",
",",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"l",
".",
"file",
"==",
"nil",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Make sure the term and index are greater than the previous.",
"if",
"len",
"(",
"l",
".",
"entries",
")",
">",
"0",
"{",
"lastEntry",
":=",
"l",
".",
"entries",
"[",
"len",
"(",
"l",
".",
"entries",
")",
"-",
"1",
"]",
"\n",
"if",
"entry",
".",
"Term",
"(",
")",
"<",
"lastEntry",
".",
"Term",
"(",
")",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"entry",
".",
"Term",
"(",
")",
",",
"entry",
".",
"Index",
"(",
")",
",",
"lastEntry",
".",
"Term",
"(",
")",
",",
"lastEntry",
".",
"Index",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"entry",
".",
"Term",
"(",
")",
"==",
"lastEntry",
".",
"Term",
"(",
")",
"&&",
"entry",
".",
"Index",
"(",
")",
"<=",
"lastEntry",
".",
"Index",
"(",
")",
"{",
"return",
"-",
"1",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"entry",
".",
"Term",
"(",
")",
",",
"entry",
".",
"Index",
"(",
")",
",",
"lastEntry",
".",
"Term",
"(",
")",
",",
"lastEntry",
".",
"Index",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Write to storage.",
"size",
",",
"err",
":=",
"entry",
".",
"Encode",
"(",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"// Append to entries list if stored on disk.",
"l",
".",
"entries",
"=",
"append",
"(",
"l",
".",
"entries",
",",
"entry",
")",
"\n\n",
"return",
"int64",
"(",
"size",
")",
",",
"nil",
"\n",
"}"
] | // appendEntry with Buffered io | [
"appendEntry",
"with",
"Buffered",
"io"
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/log.go#L544-L569 |
147,888 | 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",
",",
"LastLogIndex",
":",
"lastLogIndex",
",",
"LastLogTerm",
":",
"lastLogTerm",
",",
"CandidateName",
":",
"candidateName",
",",
"}",
"\n",
"}"
] | // Creates a new RequestVote request. | [
"Creates",
"a",
"new",
"RequestVote",
"request",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/request_vote.go#L28-L35 |
147,889 | 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(pb)
if err != nil {
return -1, err
}
return w.Write(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(pb)
if err != nil {
return -1, err
}
return w.Write(p)
} | [
"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",
")",
",",
"}",
"\n",
"p",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"pb",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"w",
".",
"Write",
"(",
"p",
")",
"\n",
"}"
] | // 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 |
147,890 | 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.GetLastLogIndex()
req.LastLogTerm = pb.GetLastLogTerm()
req.CandidateName = pb.GetCandidateName()
return totalBytes, nil
} | 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.GetLastLogIndex()
req.LastLogTerm = pb.GetLastLogTerm()
req.CandidateName = pb.GetCandidateName()
return totalBytes, nil
} | [
"func",
"(",
"req",
"*",
"RequestVoteRequest",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"totalBytes",
":=",
"len",
"(",
"data",
")",
"\n\n",
"pb",
":=",
"&",
"protobuf",
".",
"RequestVoteRequest",
"{",
"}",
"\n",
"if",
"err",
"=",
"proto",
".",
"Unmarshal",
"(",
"data",
",",
"pb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"req",
".",
"Term",
"=",
"pb",
".",
"GetTerm",
"(",
")",
"\n",
"req",
".",
"LastLogIndex",
"=",
"pb",
".",
"GetLastLogIndex",
"(",
")",
"\n",
"req",
".",
"LastLogTerm",
"=",
"pb",
".",
"GetLastLogTerm",
"(",
")",
"\n",
"req",
".",
"CandidateName",
"=",
"pb",
".",
"GetCandidateName",
"(",
")",
"\n\n",
"return",
"totalBytes",
",",
"nil",
"\n",
"}"
] | // 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 |
147,891 | 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 |
147,892 | 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",
".",
"Term",
")",
",",
"VoteGranted",
":",
"proto",
".",
"Bool",
"(",
"resp",
".",
"VoteGranted",
")",
",",
"}",
"\n\n",
"p",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"pb",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"w",
".",
"Write",
"(",
"p",
")",
"\n",
"}"
] | // 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 |
147,893 | 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 = pb.GetVoteGranted()
return totalBytes, nil
} | 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 = pb.GetVoteGranted()
return totalBytes, nil
} | [
"func",
"(",
"resp",
"*",
"RequestVoteResponse",
")",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"totalBytes",
":=",
"len",
"(",
"data",
")",
"\n\n",
"pb",
":=",
"&",
"protobuf",
".",
"RequestVoteResponse",
"{",
"}",
"\n",
"if",
"err",
"=",
"proto",
".",
"Unmarshal",
"(",
"data",
",",
"pb",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"resp",
".",
"Term",
"=",
"pb",
".",
"GetTerm",
"(",
")",
"\n",
"resp",
".",
"VoteGranted",
"=",
"pb",
".",
"GetVoteGranted",
"(",
")",
"\n\n",
"return",
"totalBytes",
",",
"nil",
"\n",
"}"
] | // 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 |
147,894 | 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",
")",
",",
"}",
"\n",
"}"
] | // 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 |
147,895 | 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",
"]",
"=",
"append",
"(",
"d",
".",
"listeners",
"[",
"typ",
"]",
",",
"listener",
")",
"\n",
"}"
] | // 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 |
147,896 | 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 reflect.ValueOf(l).Pointer() == ptr {
d.listeners[typ] = append(listeners[:i], listeners[i+1:]...)
}
}
} | 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 reflect.ValueOf(l).Pointer() == ptr {
d.listeners[typ] = append(listeners[:i], listeners[i+1:]...)
}
}
} | [
"func",
"(",
"d",
"*",
"eventDispatcher",
")",
"RemoveEventListener",
"(",
"typ",
"string",
",",
"listener",
"EventListener",
")",
"{",
"d",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"Unlock",
"(",
")",
"\n\n",
"// Grab a reference to the function pointer once.",
"ptr",
":=",
"reflect",
".",
"ValueOf",
"(",
"listener",
")",
".",
"Pointer",
"(",
")",
"\n\n",
"// Find listener by pointer and remove it.",
"listeners",
":=",
"d",
".",
"listeners",
"[",
"typ",
"]",
"\n",
"for",
"i",
",",
"l",
":=",
"range",
"listeners",
"{",
"if",
"reflect",
".",
"ValueOf",
"(",
"l",
")",
".",
"Pointer",
"(",
")",
"==",
"ptr",
"{",
"d",
".",
"listeners",
"[",
"typ",
"]",
"=",
"append",
"(",
"listeners",
"[",
":",
"i",
"]",
",",
"listeners",
"[",
"i",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // 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 |
147,897 | 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",
".",
"(",
"*",
"event",
")",
";",
"ok",
"{",
"e",
".",
"source",
"=",
"d",
".",
"source",
"\n",
"}",
"\n\n",
"// Dispatch the event to all listeners.",
"for",
"_",
",",
"l",
":=",
"range",
"d",
".",
"listeners",
"[",
"e",
".",
"Type",
"(",
")",
"]",
"{",
"l",
"(",
"e",
")",
"\n",
"}",
"\n",
"}"
] | // DispatchEvent dispatches an event. | [
"DispatchEvent",
"dispatches",
"an",
"event",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/event_dispatcher.go#L55-L68 |
147,898 | 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.
checksum := crc32.ChecksumIEEE(b)
if _, err = fmt.Fprintf(file, "%08x\n", checksum); err != nil {
return err
}
// Write the snapshot to disk.
if _, err = file.Write(b); err != nil {
return err
}
// Ensure that the snapshot has been flushed to disk before continuing.
if err := file.Sync(); err != nil {
return err
}
return nil
} | 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.
checksum := crc32.ChecksumIEEE(b)
if _, err = fmt.Fprintf(file, "%08x\n", checksum); err != nil {
return err
}
// Write the snapshot to disk.
if _, err = file.Write(b); err != nil {
return err
}
// Ensure that the snapshot has been flushed to disk before continuing.
if err := file.Sync(); err != nil {
return err
}
return nil
} | [
"func",
"(",
"ss",
"*",
"Snapshot",
")",
"save",
"(",
")",
"error",
"{",
"// Open the file for writing.",
"file",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"ss",
".",
"Path",
",",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_WRONLY",
",",
"0600",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"// Serialize to JSON.",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"ss",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Generate checksum and write it to disk.",
"checksum",
":=",
"crc32",
".",
"ChecksumIEEE",
"(",
"b",
")",
"\n",
"if",
"_",
",",
"err",
"=",
"fmt",
".",
"Fprintf",
"(",
"file",
",",
"\"",
"\\n",
"\"",
",",
"checksum",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Write the snapshot to disk.",
"if",
"_",
",",
"err",
"=",
"file",
".",
"Write",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Ensure that the snapshot has been flushed to disk before continuing.",
"if",
"err",
":=",
"file",
".",
"Sync",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // save writes the snapshot to file. | [
"save",
"writes",
"the",
"snapshot",
"to",
"file",
"."
] | 0061b6c82526bd96292f41fa72358ec13ee3853c | https://github.com/goraft/raft/blob/0061b6c82526bd96292f41fa72358ec13ee3853c/snapshot.go#L55-L86 |
147,899 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.