id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
157,000 | go-vgo/robotgo | robotgo.go | GetScaleSize | func GetScaleSize() (int, int) {
x, y := GetScreenSize()
s := Scale()
return x * s / 100, y * s / 100
} | go | func GetScaleSize() (int, int) {
x, y := GetScreenSize()
s := Scale()
return x * s / 100, y * s / 100
} | [
"func",
"GetScaleSize",
"(",
")",
"(",
"int",
",",
"int",
")",
"{",
"x",
",",
"y",
":=",
"GetScreenSize",
"(",
")",
"\n",
"s",
":=",
"Scale",
"(",
")",
"\n",
"return",
"x",
"*",
"s",
"/",
"100",
",",
"y",
"*",
"s",
"/",
"100",
"\n",
"}"
] | // GetScaleSize get the screen scale size | [
"GetScaleSize",
"get",
"the",
"screen",
"scale",
"size"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L257-L261 |
157,001 | go-vgo/robotgo | robotgo.go | SetXDisplayName | func SetXDisplayName(name string) string {
cname := C.CString(name)
str := C.set_XDisplay_name(cname)
gstr := C.GoString(str)
C.free(unsafe.Pointer(cname))
return gstr
} | go | func SetXDisplayName(name string) string {
cname := C.CString(name)
str := C.set_XDisplay_name(cname)
gstr := C.GoString(str)
C.free(unsafe.Pointer(cname))
return gstr
} | [
"func",
"SetXDisplayName",
"(",
"name",
"string",
")",
"string",
"{",
"cname",
":=",
"C",
".",
"CString",
"(",
"name",
")",
"\n",
"str",
":=",
"C",
".",
"set_XDisplay_name",
"(",
"cname",
")",
"\n",
"gstr",
":=",
"C",
".",
"GoString",
"(",
"str",
")"... | // SetXDisplayName set XDisplay name | [
"SetXDisplayName",
"set",
"XDisplay",
"name"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L264-L271 |
157,002 | go-vgo/robotgo | robotgo.go | GetXDisplayName | func GetXDisplayName() string {
name := C.get_XDisplay_name()
gname := C.GoString(name)
C.free(unsafe.Pointer(name))
return gname
} | go | func GetXDisplayName() string {
name := C.get_XDisplay_name()
gname := C.GoString(name)
C.free(unsafe.Pointer(name))
return gname
} | [
"func",
"GetXDisplayName",
"(",
")",
"string",
"{",
"name",
":=",
"C",
".",
"get_XDisplay_name",
"(",
")",
"\n",
"gname",
":=",
"C",
".",
"GoString",
"(",
"name",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"name",
")",
")",
"\... | // GetXDisplayName get XDisplay name | [
"GetXDisplayName",
"get",
"XDisplay",
"name"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L274-L280 |
157,003 | go-vgo/robotgo | robotgo.go | SaveCapture | func SaveCapture(spath string, args ...int) {
bit := CaptureScreen(args...)
SaveBitmap(bit, spath)
FreeBitmap(bit)
} | go | func SaveCapture(spath string, args ...int) {
bit := CaptureScreen(args...)
SaveBitmap(bit, spath)
FreeBitmap(bit)
} | [
"func",
"SaveCapture",
"(",
"spath",
"string",
",",
"args",
"...",
"int",
")",
"{",
"bit",
":=",
"CaptureScreen",
"(",
"args",
"...",
")",
"\n\n",
"SaveBitmap",
"(",
"bit",
",",
"spath",
")",
"\n",
"FreeBitmap",
"(",
"bit",
")",
"\n",
"}"
] | // SaveCapture capture screen and save | [
"SaveCapture",
"capture",
"screen",
"and",
"save"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L317-L322 |
157,004 | go-vgo/robotgo | robotgo.go | Move | func Move(x, y int) {
cx := C.size_t(x)
cy := C.size_t(y)
C.move_mouse(cx, cy)
} | go | func Move(x, y int) {
cx := C.size_t(x)
cy := C.size_t(y)
C.move_mouse(cx, cy)
} | [
"func",
"Move",
"(",
"x",
",",
"y",
"int",
")",
"{",
"cx",
":=",
"C",
".",
"size_t",
"(",
"x",
")",
"\n",
"cy",
":=",
"C",
".",
"size_t",
"(",
"y",
")",
"\n",
"C",
".",
"move_mouse",
"(",
"cx",
",",
"cy",
")",
"\n",
"}"
] | // Move move the mouse | [
"Move",
"move",
"the",
"mouse"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L359-L363 |
157,005 | go-vgo/robotgo | robotgo.go | DragMouse | func DragMouse(x, y int, args ...string) {
Drag(x, y, args...)
} | go | func DragMouse(x, y int, args ...string) {
Drag(x, y, args...)
} | [
"func",
"DragMouse",
"(",
"x",
",",
"y",
"int",
",",
"args",
"...",
"string",
")",
"{",
"Drag",
"(",
"x",
",",
"y",
",",
"args",
"...",
")",
"\n",
"}"
] | // DragMouse drag the mouse | [
"DragMouse",
"drag",
"the",
"mouse"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L366-L368 |
157,006 | go-vgo/robotgo | robotgo.go | Drag | func Drag(x, y int, args ...string) {
var button C.MMMouseButton = C.LEFT_BUTTON
cx := C.size_t(x)
cy := C.size_t(y)
if len(args) > 0 {
button = CheckMouse(args[0])
}
C.drag_mouse(cx, cy, button)
} | go | func Drag(x, y int, args ...string) {
var button C.MMMouseButton = C.LEFT_BUTTON
cx := C.size_t(x)
cy := C.size_t(y)
if len(args) > 0 {
button = CheckMouse(args[0])
}
C.drag_mouse(cx, cy, button)
} | [
"func",
"Drag",
"(",
"x",
",",
"y",
"int",
",",
"args",
"...",
"string",
")",
"{",
"var",
"button",
"C",
".",
"MMMouseButton",
"=",
"C",
".",
"LEFT_BUTTON",
"\n\n",
"cx",
":=",
"C",
".",
"size_t",
"(",
"x",
")",
"\n",
"cy",
":=",
"C",
".",
"siz... | // Drag drag the mouse | [
"Drag",
"drag",
"the",
"mouse"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L371-L382 |
157,007 | go-vgo/robotgo | robotgo.go | MoveMouseSmooth | func MoveMouseSmooth(x, y int, args ...interface{}) bool {
return MoveSmooth(x, y, args...)
} | go | func MoveMouseSmooth(x, y int, args ...interface{}) bool {
return MoveSmooth(x, y, args...)
} | [
"func",
"MoveMouseSmooth",
"(",
"x",
",",
"y",
"int",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"return",
"MoveSmooth",
"(",
"x",
",",
"y",
",",
"args",
"...",
")",
"\n",
"}"
] | // MoveMouseSmooth move the mouse smooth,
// moves mouse to x, y human like, with the mouse button up. | [
"MoveMouseSmooth",
"move",
"the",
"mouse",
"smooth",
"moves",
"mouse",
"to",
"x",
"y",
"human",
"like",
"with",
"the",
"mouse",
"button",
"up",
"."
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L386-L388 |
157,008 | go-vgo/robotgo | robotgo.go | GetMousePos | func GetMousePos() (int, int) {
pos := C.get_mouse_pos()
x := int(pos.x)
y := int(pos.y)
return x, y
} | go | func GetMousePos() (int, int) {
pos := C.get_mouse_pos()
x := int(pos.x)
y := int(pos.y)
return x, y
} | [
"func",
"GetMousePos",
"(",
")",
"(",
"int",
",",
"int",
")",
"{",
"pos",
":=",
"C",
".",
"get_mouse_pos",
"(",
")",
"\n\n",
"x",
":=",
"int",
"(",
"pos",
".",
"x",
")",
"\n",
"y",
":=",
"int",
"(",
"pos",
".",
"y",
")",
"\n\n",
"return",
"x"... | // GetMousePos get mouse's portion | [
"GetMousePos",
"get",
"mouse",
"s",
"portion"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L422-L429 |
157,009 | go-vgo/robotgo | robotgo.go | MovesClick | func MovesClick(x, y int, args ...interface{}) {
MoveSmooth(x, y)
MouseClick(args...)
} | go | func MovesClick(x, y int, args ...interface{}) {
MoveSmooth(x, y)
MouseClick(args...)
} | [
"func",
"MovesClick",
"(",
"x",
",",
"y",
"int",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"MoveSmooth",
"(",
"x",
",",
"y",
")",
"\n",
"MouseClick",
"(",
"args",
"...",
")",
"\n",
"}"
] | // MovesClick move smooth and click the mouse | [
"MovesClick",
"move",
"smooth",
"and",
"click",
"the",
"mouse"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L467-L470 |
157,010 | go-vgo/robotgo | robotgo.go | MouseToggle | func MouseToggle(togKey string, args ...interface{}) {
var button C.MMMouseButton = C.LEFT_BUTTON
if len(args) > 0 {
button = CheckMouse(args[0].(string))
}
down := C.CString(togKey)
C.mouse_toggle(down, button)
C.free(unsafe.Pointer(down))
} | go | func MouseToggle(togKey string, args ...interface{}) {
var button C.MMMouseButton = C.LEFT_BUTTON
if len(args) > 0 {
button = CheckMouse(args[0].(string))
}
down := C.CString(togKey)
C.mouse_toggle(down, button)
C.free(unsafe.Pointer(down))
} | [
"func",
"MouseToggle",
"(",
"togKey",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"var",
"button",
"C",
".",
"MMMouseButton",
"=",
"C",
".",
"LEFT_BUTTON",
"\n\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"button",
"=",
"Check... | // MouseToggle toggle the mouse | [
"MouseToggle",
"toggle",
"the",
"mouse"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L473-L484 |
157,011 | go-vgo/robotgo | robotgo.go | SetMouseDelay | func SetMouseDelay(delay int) {
cdelay := C.size_t(delay)
C.set_mouse_delay(cdelay)
} | go | func SetMouseDelay(delay int) {
cdelay := C.size_t(delay)
C.set_mouse_delay(cdelay)
} | [
"func",
"SetMouseDelay",
"(",
"delay",
"int",
")",
"{",
"cdelay",
":=",
"C",
".",
"size_t",
"(",
"delay",
")",
"\n",
"C",
".",
"set_mouse_delay",
"(",
"cdelay",
")",
"\n",
"}"
] | // SetMouseDelay set mouse delay | [
"SetMouseDelay",
"set",
"mouse",
"delay"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L487-L490 |
157,012 | go-vgo/robotgo | robotgo.go | ScrollMouse | func ScrollMouse(x int, direction string) {
cx := C.size_t(x)
cy := C.CString(direction)
C.scroll_mouse(cx, cy)
C.free(unsafe.Pointer(cy))
} | go | func ScrollMouse(x int, direction string) {
cx := C.size_t(x)
cy := C.CString(direction)
C.scroll_mouse(cx, cy)
C.free(unsafe.Pointer(cy))
} | [
"func",
"ScrollMouse",
"(",
"x",
"int",
",",
"direction",
"string",
")",
"{",
"cx",
":=",
"C",
".",
"size_t",
"(",
"x",
")",
"\n",
"cy",
":=",
"C",
".",
"CString",
"(",
"direction",
")",
"\n",
"C",
".",
"scroll_mouse",
"(",
"cx",
",",
"cy",
")",
... | // ScrollMouse scroll the mouse | [
"ScrollMouse",
"scroll",
"the",
"mouse"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L493-L499 |
157,013 | go-vgo/robotgo | robotgo.go | CharCodeAt | func CharCodeAt(s string, n int) rune {
i := 0
for _, r := range s {
if i == n {
return r
}
i++
}
return 0
} | go | func CharCodeAt(s string, n int) rune {
i := 0
for _, r := range s {
if i == n {
return r
}
i++
}
return 0
} | [
"func",
"CharCodeAt",
"(",
"s",
"string",
",",
"n",
"int",
")",
"rune",
"{",
"i",
":=",
"0",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"s",
"{",
"if",
"i",
"==",
"n",
"{",
"return",
"r",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"retu... | // CharCodeAt char code at utf-8 | [
"CharCodeAt",
"char",
"code",
"at",
"utf",
"-",
"8"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L670-L680 |
157,014 | go-vgo/robotgo | robotgo.go | UnicodeType | func UnicodeType(str uint32) {
cstr := C.uint(str)
C.unicodeType(cstr)
} | go | func UnicodeType(str uint32) {
cstr := C.uint(str)
C.unicodeType(cstr)
} | [
"func",
"UnicodeType",
"(",
"str",
"uint32",
")",
"{",
"cstr",
":=",
"C",
".",
"uint",
"(",
"str",
")",
"\n",
"C",
".",
"unicodeType",
"(",
"cstr",
")",
"\n",
"}"
] | // UnicodeType tap uint32 unicode | [
"UnicodeType",
"tap",
"uint32",
"unicode"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L733-L736 |
157,015 | go-vgo/robotgo | robotgo.go | PasteStr | func PasteStr(str string) {
clipboard.WriteAll(str)
if runtime.GOOS == "darwin" {
KeyTap("v", "command")
} else {
KeyTap("v", "control")
}
} | go | func PasteStr(str string) {
clipboard.WriteAll(str)
if runtime.GOOS == "darwin" {
KeyTap("v", "command")
} else {
KeyTap("v", "control")
}
} | [
"func",
"PasteStr",
"(",
"str",
"string",
")",
"{",
"clipboard",
".",
"WriteAll",
"(",
"str",
")",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"KeyTap",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"KeyTap",
"(",
... | // PasteStr paste a string, support UTF-8 | [
"PasteStr",
"paste",
"a",
"string",
"support",
"UTF",
"-",
"8"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L748-L755 |
157,016 | go-vgo/robotgo | robotgo.go | TypeStrDelay | func TypeStrDelay(str string, delay int) {
cstr := C.CString(str)
cdelay := C.size_t(delay)
C.type_string_delayed(cstr, cdelay)
C.free(unsafe.Pointer(cstr))
} | go | func TypeStrDelay(str string, delay int) {
cstr := C.CString(str)
cdelay := C.size_t(delay)
C.type_string_delayed(cstr, cdelay)
C.free(unsafe.Pointer(cstr))
} | [
"func",
"TypeStrDelay",
"(",
"str",
"string",
",",
"delay",
"int",
")",
"{",
"cstr",
":=",
"C",
".",
"CString",
"(",
"str",
")",
"\n",
"cdelay",
":=",
"C",
".",
"size_t",
"(",
"delay",
")",
"\n",
"C",
".",
"type_string_delayed",
"(",
"cstr",
",",
"... | // TypeStrDelay type string delayed | [
"TypeStrDelay",
"type",
"string",
"delayed"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L758-L764 |
157,017 | go-vgo/robotgo | robotgo.go | ToBitmap | func ToBitmap(bit C.MMBitmapRef) Bitmap {
bitmap := Bitmap{
ImgBuf: (*uint8)(bit.imageBuffer),
Width: int(bit.width),
Height: int(bit.height),
Bytewidth: int(bit.bytewidth),
BitsPixel: uint8(bit.bitsPerPixel),
BytesPerPixel: uint8(bit.bytesPerPixel),
}
return bitmap
} | go | func ToBitmap(bit C.MMBitmapRef) Bitmap {
bitmap := Bitmap{
ImgBuf: (*uint8)(bit.imageBuffer),
Width: int(bit.width),
Height: int(bit.height),
Bytewidth: int(bit.bytewidth),
BitsPixel: uint8(bit.bitsPerPixel),
BytesPerPixel: uint8(bit.bytesPerPixel),
}
return bitmap
} | [
"func",
"ToBitmap",
"(",
"bit",
"C",
".",
"MMBitmapRef",
")",
"Bitmap",
"{",
"bitmap",
":=",
"Bitmap",
"{",
"ImgBuf",
":",
"(",
"*",
"uint8",
")",
"(",
"bit",
".",
"imageBuffer",
")",
",",
"Width",
":",
"int",
"(",
"bit",
".",
"width",
")",
",",
... | // ToBitmap trans C.MMBitmapRef to Bitmap | [
"ToBitmap",
"trans",
"C",
".",
"MMBitmapRef",
"to",
"Bitmap"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L812-L823 |
157,018 | go-vgo/robotgo | robotgo.go | ToCBitmap | func ToCBitmap(bit Bitmap) C.MMBitmapRef {
cbitmap := C.createMMBitmap(
(*C.uint8_t)(bit.ImgBuf),
C.size_t(bit.Width),
C.size_t(bit.Height),
C.size_t(bit.Bytewidth),
C.uint8_t(bit.BitsPixel),
C.uint8_t(bit.BytesPerPixel),
)
return cbitmap
} | go | func ToCBitmap(bit Bitmap) C.MMBitmapRef {
cbitmap := C.createMMBitmap(
(*C.uint8_t)(bit.ImgBuf),
C.size_t(bit.Width),
C.size_t(bit.Height),
C.size_t(bit.Bytewidth),
C.uint8_t(bit.BitsPixel),
C.uint8_t(bit.BytesPerPixel),
)
return cbitmap
} | [
"func",
"ToCBitmap",
"(",
"bit",
"Bitmap",
")",
"C",
".",
"MMBitmapRef",
"{",
"cbitmap",
":=",
"C",
".",
"createMMBitmap",
"(",
"(",
"*",
"C",
".",
"uint8_t",
")",
"(",
"bit",
".",
"ImgBuf",
")",
",",
"C",
".",
"size_t",
"(",
"bit",
".",
"Width",
... | // ToCBitmap trans Bitmap to C.MMBitmapRef | [
"ToCBitmap",
"trans",
"Bitmap",
"to",
"C",
".",
"MMBitmapRef"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L826-L837 |
157,019 | go-vgo/robotgo | robotgo.go | ToBitmapBytes | func ToBitmapBytes(bit C.MMBitmapRef) []byte {
var len C.size_t
ptr := C.saveMMBitmapAsBytes(bit, &len)
if int(len) < 0 {
return nil
}
bs := C.GoBytes(unsafe.Pointer(ptr), C.int(len))
C.free(unsafe.Pointer(ptr))
return bs
} | go | func ToBitmapBytes(bit C.MMBitmapRef) []byte {
var len C.size_t
ptr := C.saveMMBitmapAsBytes(bit, &len)
if int(len) < 0 {
return nil
}
bs := C.GoBytes(unsafe.Pointer(ptr), C.int(len))
C.free(unsafe.Pointer(ptr))
return bs
} | [
"func",
"ToBitmapBytes",
"(",
"bit",
"C",
".",
"MMBitmapRef",
")",
"[",
"]",
"byte",
"{",
"var",
"len",
"C",
".",
"size_t",
"\n",
"ptr",
":=",
"C",
".",
"saveMMBitmapAsBytes",
"(",
"bit",
",",
"&",
"len",
")",
"\n",
"if",
"int",
"(",
"len",
")",
... | // ToBitmapBytes saves Bitmap to bitmap format in bytes | [
"ToBitmapBytes",
"saves",
"Bitmap",
"to",
"bitmap",
"format",
"in",
"bytes"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L840-L850 |
157,020 | go-vgo/robotgo | robotgo.go | TostringBitmap | func TostringBitmap(bit C.MMBitmapRef) string {
strBit := C.tostring_bitmap(bit)
return C.GoString(strBit)
} | go | func TostringBitmap(bit C.MMBitmapRef) string {
strBit := C.tostring_bitmap(bit)
return C.GoString(strBit)
} | [
"func",
"TostringBitmap",
"(",
"bit",
"C",
".",
"MMBitmapRef",
")",
"string",
"{",
"strBit",
":=",
"C",
".",
"tostring_bitmap",
"(",
"bit",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"strBit",
")",
"\n",
"}"
] | // TostringBitmap tostring bitmap to string | [
"TostringBitmap",
"tostring",
"bitmap",
"to",
"string"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L858-L861 |
157,021 | go-vgo/robotgo | robotgo.go | TocharBitmap | func TocharBitmap(bit C.MMBitmapRef) *C.char {
strBit := C.tostring_bitmap(bit)
return strBit
} | go | func TocharBitmap(bit C.MMBitmapRef) *C.char {
strBit := C.tostring_bitmap(bit)
return strBit
} | [
"func",
"TocharBitmap",
"(",
"bit",
"C",
".",
"MMBitmapRef",
")",
"*",
"C",
".",
"char",
"{",
"strBit",
":=",
"C",
".",
"tostring_bitmap",
"(",
"bit",
")",
"\n",
"return",
"strBit",
"\n",
"}"
] | // TocharBitmap tostring bitmap to C.char | [
"TocharBitmap",
"tostring",
"bitmap",
"to",
"C",
".",
"char"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L864-L867 |
157,022 | go-vgo/robotgo | robotgo.go | FindCBitmap | func FindCBitmap(bmp CBitmap, args ...interface{}) (int, int) {
return FindBitmap(ToMMBitmapRef(bmp), args...)
} | go | func FindCBitmap(bmp CBitmap, args ...interface{}) (int, int) {
return FindBitmap(ToMMBitmapRef(bmp), args...)
} | [
"func",
"FindCBitmap",
"(",
"bmp",
"CBitmap",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"int",
")",
"{",
"return",
"FindBitmap",
"(",
"ToMMBitmapRef",
"(",
"bmp",
")",
",",
"args",
"...",
")",
"\n",
"}"
] | // FindCBitmap find bitmap's pos by CBitmap | [
"FindCBitmap",
"find",
"bitmap",
"s",
"pos",
"by",
"CBitmap"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L876-L878 |
157,023 | go-vgo/robotgo | robotgo.go | FindEveryBitmap | func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) {
var (
sbit C.MMBitmapRef
tolerance C.float = 0.01
lpos C.MMPoint
)
if len(args) > 0 {
sbit = args[0].(C.MMBitmapRef)
} else {
sbit = CaptureScreen()
}
if len(args) > 1 {
tolerance = C.float(args[1].(float64))
}
if len(args) > 2 {
lpos.x = C.size_t(args[2].(int))
lpos.y = 0
} else {
lpos.x = 0
lpos.y = 0
}
if len(args) > 3 {
lpos.x = C.size_t(args[2].(int))
lpos.y = C.size_t(args[3].(int))
}
pos := C.find_every_bitmap(bit, sbit, tolerance, &lpos)
// FreeBitmap(bit)
if len(args) <= 0 {
FreeBitmap(sbit)
}
// fmt.Println("pos----", pos)
return int(pos.x), int(pos.y)
} | go | func FindEveryBitmap(bit C.MMBitmapRef, args ...interface{}) (int, int) {
var (
sbit C.MMBitmapRef
tolerance C.float = 0.01
lpos C.MMPoint
)
if len(args) > 0 {
sbit = args[0].(C.MMBitmapRef)
} else {
sbit = CaptureScreen()
}
if len(args) > 1 {
tolerance = C.float(args[1].(float64))
}
if len(args) > 2 {
lpos.x = C.size_t(args[2].(int))
lpos.y = 0
} else {
lpos.x = 0
lpos.y = 0
}
if len(args) > 3 {
lpos.x = C.size_t(args[2].(int))
lpos.y = C.size_t(args[3].(int))
}
pos := C.find_every_bitmap(bit, sbit, tolerance, &lpos)
// FreeBitmap(bit)
if len(args) <= 0 {
FreeBitmap(sbit)
}
// fmt.Println("pos----", pos)
return int(pos.x), int(pos.y)
} | [
"func",
"FindEveryBitmap",
"(",
"bit",
"C",
".",
"MMBitmapRef",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"int",
")",
"{",
"var",
"(",
"sbit",
"C",
".",
"MMBitmapRef",
"\n",
"tolerance",
"C",
".",
"float",
"=",
"0.01",
"\n",
... | // FindEveryBitmap find the every bitmap | [
"FindEveryBitmap",
"find",
"the",
"every",
"bitmap"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L948-L986 |
157,024 | go-vgo/robotgo | robotgo.go | CountBitmap | func CountBitmap(bitmap, sbit C.MMBitmapRef, args ...float32) int {
var tolerance C.float = 0.01
if len(args) > 0 {
tolerance = C.float(args[0])
}
count := C.count_of_bitmap(bitmap, sbit, tolerance)
return int(count)
} | go | func CountBitmap(bitmap, sbit C.MMBitmapRef, args ...float32) int {
var tolerance C.float = 0.01
if len(args) > 0 {
tolerance = C.float(args[0])
}
count := C.count_of_bitmap(bitmap, sbit, tolerance)
return int(count)
} | [
"func",
"CountBitmap",
"(",
"bitmap",
",",
"sbit",
"C",
".",
"MMBitmapRef",
",",
"args",
"...",
"float32",
")",
"int",
"{",
"var",
"tolerance",
"C",
".",
"float",
"=",
"0.01",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"tolerance",
"=",
"C... | // CountBitmap count of the bitmap | [
"CountBitmap",
"count",
"of",
"the",
"bitmap"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L989-L997 |
157,025 | go-vgo/robotgo | robotgo.go | BitmapClick | func BitmapClick(bitmap C.MMBitmapRef, args ...interface{}) {
x, y := FindBitmap(bitmap)
MovesClick(x, y, args...)
} | go | func BitmapClick(bitmap C.MMBitmapRef, args ...interface{}) {
x, y := FindBitmap(bitmap)
MovesClick(x, y, args...)
} | [
"func",
"BitmapClick",
"(",
"bitmap",
"C",
".",
"MMBitmapRef",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"x",
",",
"y",
":=",
"FindBitmap",
"(",
"bitmap",
")",
"\n",
"MovesClick",
"(",
"x",
",",
"y",
",",
"args",
"...",
")",
"\n",
"}"
] | // BitmapClick find the bitmap and click | [
"BitmapClick",
"find",
"the",
"bitmap",
"and",
"click"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1000-L1003 |
157,026 | go-vgo/robotgo | robotgo.go | PointInBounds | func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool {
var point C.MMPoint
point.x = C.size_t(x)
point.y = C.size_t(y)
cbool := C.point_in_bounds(bitmap, point)
return bool(cbool)
} | go | func PointInBounds(bitmap C.MMBitmapRef, x, y int) bool {
var point C.MMPoint
point.x = C.size_t(x)
point.y = C.size_t(y)
cbool := C.point_in_bounds(bitmap, point)
return bool(cbool)
} | [
"func",
"PointInBounds",
"(",
"bitmap",
"C",
".",
"MMBitmapRef",
",",
"x",
",",
"y",
"int",
")",
"bool",
"{",
"var",
"point",
"C",
".",
"MMPoint",
"\n",
"point",
".",
"x",
"=",
"C",
".",
"size_t",
"(",
"x",
")",
"\n",
"point",
".",
"y",
"=",
"C... | // PointInBounds bitmap point in bounds | [
"PointInBounds",
"bitmap",
"point",
"in",
"bounds"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1006-L1013 |
157,027 | go-vgo/robotgo | robotgo.go | DecodeImg | func DecodeImg(path string) (image.Image, string, error) {
return imgo.DecodeFile(path)
} | go | func DecodeImg(path string) (image.Image, string, error) {
return imgo.DecodeFile(path)
} | [
"func",
"DecodeImg",
"(",
"path",
"string",
")",
"(",
"image",
".",
"Image",
",",
"string",
",",
"error",
")",
"{",
"return",
"imgo",
".",
"DecodeFile",
"(",
"path",
")",
"\n",
"}"
] | // DecodeImg decode the image to image.Image and return | [
"DecodeImg",
"decode",
"the",
"image",
"to",
"image",
".",
"Image",
"and",
"return"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1033-L1035 |
157,028 | go-vgo/robotgo | robotgo.go | BitmapFromStr | func BitmapFromStr(str string) C.MMBitmapRef {
cs := C.CString(str)
bit := C.bitmap_from_string(cs)
C.free(unsafe.Pointer(cs))
return bit
} | go | func BitmapFromStr(str string) C.MMBitmapRef {
cs := C.CString(str)
bit := C.bitmap_from_string(cs)
C.free(unsafe.Pointer(cs))
return bit
} | [
"func",
"BitmapFromStr",
"(",
"str",
"string",
")",
"C",
".",
"MMBitmapRef",
"{",
"cs",
":=",
"C",
".",
"CString",
"(",
"str",
")",
"\n",
"bit",
":=",
"C",
".",
"bitmap_from_string",
"(",
"cs",
")",
"\n",
"C",
".",
"free",
"(",
"unsafe",
".",
"Poin... | // BitmapFromStr bitmap from string | [
"BitmapFromStr",
"bitmap",
"from",
"string"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1048-L1054 |
157,029 | go-vgo/robotgo | robotgo.go | GetPortion | func GetPortion(bit C.MMBitmapRef, x, y, w, h int) C.MMBitmapRef {
var rect C.MMRect
rect.origin.x = C.size_t(x)
rect.origin.y = C.size_t(y)
rect.size.width = C.size_t(w)
rect.size.height = C.size_t(h)
pos := C.get_portion(bit, rect)
return pos
} | go | func GetPortion(bit C.MMBitmapRef, x, y, w, h int) C.MMBitmapRef {
var rect C.MMRect
rect.origin.x = C.size_t(x)
rect.origin.y = C.size_t(y)
rect.size.width = C.size_t(w)
rect.size.height = C.size_t(h)
pos := C.get_portion(bit, rect)
return pos
} | [
"func",
"GetPortion",
"(",
"bit",
"C",
".",
"MMBitmapRef",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
"int",
")",
"C",
".",
"MMBitmapRef",
"{",
"var",
"rect",
"C",
".",
"MMRect",
"\n",
"rect",
".",
"origin",
".",
"x",
"=",
"C",
".",
"size_t",
"(",... | // GetPortion get bitmap portion | [
"GetPortion",
"get",
"bitmap",
"portion"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1073-L1082 |
157,030 | go-vgo/robotgo | robotgo.go | ReadBitmap | func ReadBitmap(bitmap C.MMBitmapRef) bool {
abool := C.bitmap_ready(bitmap)
gbool := bool(abool)
return gbool
} | go | func ReadBitmap(bitmap C.MMBitmapRef) bool {
abool := C.bitmap_ready(bitmap)
gbool := bool(abool)
return gbool
} | [
"func",
"ReadBitmap",
"(",
"bitmap",
"C",
".",
"MMBitmapRef",
")",
"bool",
"{",
"abool",
":=",
"C",
".",
"bitmap_ready",
"(",
"bitmap",
")",
"\n",
"gbool",
":=",
"bool",
"(",
"abool",
")",
"\n",
"return",
"gbool",
"\n",
"}"
] | // ReadBitmap returns false and sets error if |bitmap| is NULL | [
"ReadBitmap",
"returns",
"false",
"and",
"sets",
"error",
"if",
"|bitmap|",
"is",
"NULL"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1106-L1110 |
157,031 | go-vgo/robotgo | robotgo.go | CopyBitPB | func CopyBitPB(bitmap C.MMBitmapRef) bool {
abool := C.bitmap_copy_to_pboard(bitmap)
gbool := bool(abool)
return gbool
} | go | func CopyBitPB(bitmap C.MMBitmapRef) bool {
abool := C.bitmap_copy_to_pboard(bitmap)
gbool := bool(abool)
return gbool
} | [
"func",
"CopyBitPB",
"(",
"bitmap",
"C",
".",
"MMBitmapRef",
")",
"bool",
"{",
"abool",
":=",
"C",
".",
"bitmap_copy_to_pboard",
"(",
"bitmap",
")",
"\n",
"gbool",
":=",
"bool",
"(",
"abool",
")",
"\n\n",
"return",
"gbool",
"\n",
"}"
] | // CopyBitPB copy bitmap to pasteboard | [
"CopyBitPB",
"copy",
"bitmap",
"to",
"pasteboard"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1113-L1118 |
157,032 | go-vgo/robotgo | robotgo.go | DeepCopyBit | func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef {
bit := C.bitmap_deepcopy(bitmap)
return bit
} | go | func DeepCopyBit(bitmap C.MMBitmapRef) C.MMBitmapRef {
bit := C.bitmap_deepcopy(bitmap)
return bit
} | [
"func",
"DeepCopyBit",
"(",
"bitmap",
"C",
".",
"MMBitmapRef",
")",
"C",
".",
"MMBitmapRef",
"{",
"bit",
":=",
"C",
".",
"bitmap_deepcopy",
"(",
"bitmap",
")",
"\n",
"return",
"bit",
"\n",
"}"
] | // DeepCopyBit deep copy bitmap | [
"DeepCopyBit",
"deep",
"copy",
"bitmap"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1126-L1129 |
157,033 | go-vgo/robotgo | robotgo.go | GetColor | func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex {
color := C.bitmap_get_color(bitmap, C.size_t(x), C.size_t(y))
return color
} | go | func GetColor(bitmap C.MMBitmapRef, x, y int) C.MMRGBHex {
color := C.bitmap_get_color(bitmap, C.size_t(x), C.size_t(y))
return color
} | [
"func",
"GetColor",
"(",
"bitmap",
"C",
".",
"MMBitmapRef",
",",
"x",
",",
"y",
"int",
")",
"C",
".",
"MMRGBHex",
"{",
"color",
":=",
"C",
".",
"bitmap_get_color",
"(",
"bitmap",
",",
"C",
".",
"size_t",
"(",
"x",
")",
",",
"C",
".",
"size_t",
"(... | // GetColor get bitmap color | [
"GetColor",
"get",
"bitmap",
"color"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1132-L1136 |
157,034 | go-vgo/robotgo | robotgo.go | GetColors | func GetColors(bitmap C.MMBitmapRef, x, y int) string {
clo := GetColor(bitmap, x, y)
return PadHex(clo)
} | go | func GetColors(bitmap C.MMBitmapRef, x, y int) string {
clo := GetColor(bitmap, x, y)
return PadHex(clo)
} | [
"func",
"GetColors",
"(",
"bitmap",
"C",
".",
"MMBitmapRef",
",",
"x",
",",
"y",
"int",
")",
"string",
"{",
"clo",
":=",
"GetColor",
"(",
"bitmap",
",",
"x",
",",
"y",
")",
"\n\n",
"return",
"PadHex",
"(",
"clo",
")",
"\n",
"}"
] | // GetColors get bitmap color retrun string | [
"GetColors",
"get",
"bitmap",
"color",
"retrun",
"string"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1139-L1143 |
157,035 | go-vgo/robotgo | robotgo.go | FindColorCS | func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) {
var tolerance = 0.01
if len(args) > 0 {
tolerance = args[0]
}
bitmap := CaptureScreen(x, y, w, h)
rx, ry := FindColor(color, bitmap, tolerance)
FreeBitmap(bitmap)
return rx, ry
} | go | func FindColorCS(color CHex, x, y, w, h int, args ...float64) (int, int) {
var tolerance = 0.01
if len(args) > 0 {
tolerance = args[0]
}
bitmap := CaptureScreen(x, y, w, h)
rx, ry := FindColor(color, bitmap, tolerance)
FreeBitmap(bitmap)
return rx, ry
} | [
"func",
"FindColorCS",
"(",
"color",
"CHex",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
"int",
",",
"args",
"...",
"float64",
")",
"(",
"int",
",",
"int",
")",
"{",
"var",
"tolerance",
"=",
"0.01",
"\n\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
... | // FindColorCS findcolor by CaptureScreen | [
"FindColorCS",
"findcolor",
"by",
"CaptureScreen"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1176-L1188 |
157,036 | go-vgo/robotgo | robotgo.go | CountColor | func CountColor(color CHex, args ...interface{}) int {
var (
tolerance C.float = 0.01
bitmap C.MMBitmapRef
)
if len(args) > 0 {
bitmap = args[0].(C.MMBitmapRef)
} else {
bitmap = CaptureScreen()
}
if len(args) > 1 {
tolerance = C.float(args[1].(float64))
}
count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance)
if len(args) <= 0 {
FreeBitmap(bitmap)
}
return int(count)
} | go | func CountColor(color CHex, args ...interface{}) int {
var (
tolerance C.float = 0.01
bitmap C.MMBitmapRef
)
if len(args) > 0 {
bitmap = args[0].(C.MMBitmapRef)
} else {
bitmap = CaptureScreen()
}
if len(args) > 1 {
tolerance = C.float(args[1].(float64))
}
count := C.bitmap_count_of_color(bitmap, C.MMRGBHex(color), tolerance)
if len(args) <= 0 {
FreeBitmap(bitmap)
}
return int(count)
} | [
"func",
"CountColor",
"(",
"color",
"CHex",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"int",
"{",
"var",
"(",
"tolerance",
"C",
".",
"float",
"=",
"0.01",
"\n",
"bitmap",
"C",
".",
"MMBitmapRef",
"\n",
")",
"\n\n",
"if",
"len",
"(",
"args",
"... | // CountColor count bitmap color | [
"CountColor",
"count",
"bitmap",
"color"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1191-L1213 |
157,037 | go-vgo/robotgo | robotgo.go | CountColorCS | func CountColorCS(color CHex, x, y, w, h int, args ...float64) int {
var tolerance = 0.01
if len(args) > 0 {
tolerance = args[0]
}
bitmap := CaptureScreen(x, y, w, h)
rx := CountColor(color, bitmap, tolerance)
FreeBitmap(bitmap)
return rx
} | go | func CountColorCS(color CHex, x, y, w, h int, args ...float64) int {
var tolerance = 0.01
if len(args) > 0 {
tolerance = args[0]
}
bitmap := CaptureScreen(x, y, w, h)
rx := CountColor(color, bitmap, tolerance)
FreeBitmap(bitmap)
return rx
} | [
"func",
"CountColorCS",
"(",
"color",
"CHex",
",",
"x",
",",
"y",
",",
"w",
",",
"h",
"int",
",",
"args",
"...",
"float64",
")",
"int",
"{",
"var",
"tolerance",
"=",
"0.01",
"\n\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"tolerance",
"=",
... | // CountColorCS count bitmap color by CaptureScreen | [
"CountColorCS",
"count",
"bitmap",
"color",
"by",
"CaptureScreen"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1216-L1228 |
157,038 | go-vgo/robotgo | robotgo.go | GetImgSize | func GetImgSize(imgPath string) (int, int) {
bitmap := OpenBitmap(imgPath)
gbit := ToBitmap(bitmap)
w := gbit.Width / 2
h := gbit.Height / 2
FreeBitmap(bitmap)
return w, h
} | go | func GetImgSize(imgPath string) (int, int) {
bitmap := OpenBitmap(imgPath)
gbit := ToBitmap(bitmap)
w := gbit.Width / 2
h := gbit.Height / 2
FreeBitmap(bitmap)
return w, h
} | [
"func",
"GetImgSize",
"(",
"imgPath",
"string",
")",
"(",
"int",
",",
"int",
")",
"{",
"bitmap",
":=",
"OpenBitmap",
"(",
"imgPath",
")",
"\n",
"gbit",
":=",
"ToBitmap",
"(",
"bitmap",
")",
"\n\n",
"w",
":=",
"gbit",
".",
"Width",
"/",
"2",
"\n",
"... | // GetImgSize get the image size | [
"GetImgSize",
"get",
"the",
"image",
"size"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1231-L1240 |
157,039 | go-vgo/robotgo | robotgo.go | AddMousePos | func AddMousePos(x, y int16) bool {
s := hook.Start()
for {
e := <-s
if e.Kind == hook.MouseMove && e.X == x && e.Y == y {
hook.End()
break
}
}
return true
} | go | func AddMousePos(x, y int16) bool {
s := hook.Start()
for {
e := <-s
if e.Kind == hook.MouseMove && e.X == x && e.Y == y {
hook.End()
break
}
}
return true
} | [
"func",
"AddMousePos",
"(",
"x",
",",
"y",
"int16",
")",
"bool",
"{",
"s",
":=",
"hook",
".",
"Start",
"(",
")",
"\n\n",
"for",
"{",
"e",
":=",
"<-",
"s",
"\n",
"if",
"e",
".",
"Kind",
"==",
"hook",
".",
"MouseMove",
"&&",
"e",
".",
"X",
"=="... | // AddMousePos add listen mouse event pos hook | [
"AddMousePos",
"add",
"listen",
"mouse",
"event",
"pos",
"hook"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1384-L1396 |
157,040 | go-vgo/robotgo | robotgo.go | MinWindow | func MinWindow(pid int32, args ...interface{}) {
var (
state = true
hwnd int
)
if len(args) > 0 {
state = args[0].(bool)
}
if len(args) > 1 {
hwnd = args[1].(int)
}
C.min_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd))
} | go | func MinWindow(pid int32, args ...interface{}) {
var (
state = true
hwnd int
)
if len(args) > 0 {
state = args[0].(bool)
}
if len(args) > 1 {
hwnd = args[1].(int)
}
C.min_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd))
} | [
"func",
"MinWindow",
"(",
"pid",
"int32",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"var",
"(",
"state",
"=",
"true",
"\n",
"hwnd",
"int",
"\n",
")",
"\n\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"state",
"=",
"args",
"[",
"0... | // MinWindow set the window min | [
"MinWindow",
"set",
"the",
"window",
"min"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1464-L1478 |
157,041 | go-vgo/robotgo | robotgo.go | MaxWindow | func MaxWindow(pid int32, args ...interface{}) {
var (
state = true
hwnd int
)
if len(args) > 0 {
state = args[0].(bool)
}
if len(args) > 1 {
hwnd = args[1].(int)
}
C.max_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd))
} | go | func MaxWindow(pid int32, args ...interface{}) {
var (
state = true
hwnd int
)
if len(args) > 0 {
state = args[0].(bool)
}
if len(args) > 1 {
hwnd = args[1].(int)
}
C.max_window(C.uintptr(pid), C.bool(state), C.uintptr(hwnd))
} | [
"func",
"MaxWindow",
"(",
"pid",
"int32",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"var",
"(",
"state",
"=",
"true",
"\n",
"hwnd",
"int",
"\n",
")",
"\n\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"state",
"=",
"args",
"[",
"0... | // MaxWindow set the window max | [
"MaxWindow",
"set",
"the",
"window",
"max"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1481-L1495 |
157,042 | go-vgo/robotgo | robotgo.go | CloseWindow | func CloseWindow(args ...int32) {
if len(args) <= 0 {
C.close_main_window()
return
}
var hwnd, isHwnd int32
if len(args) > 0 {
hwnd = args[0]
}
if len(args) > 1 {
isHwnd = args[1]
}
C.close_window(C.uintptr(hwnd), C.uintptr(isHwnd))
} | go | func CloseWindow(args ...int32) {
if len(args) <= 0 {
C.close_main_window()
return
}
var hwnd, isHwnd int32
if len(args) > 0 {
hwnd = args[0]
}
if len(args) > 1 {
isHwnd = args[1]
}
C.close_window(C.uintptr(hwnd), C.uintptr(isHwnd))
} | [
"func",
"CloseWindow",
"(",
"args",
"...",
"int32",
")",
"{",
"if",
"len",
"(",
"args",
")",
"<=",
"0",
"{",
"C",
".",
"close_main_window",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"var",
"hwnd",
",",
"isHwnd",
"int32",
"\n",
"if",
"len",
"(",
... | // CloseWindow close the window | [
"CloseWindow",
"close",
"the",
"window"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1498-L1513 |
157,043 | go-vgo/robotgo | robotgo.go | SetHandle | func SetHandle(hwnd int) {
chwnd := C.uintptr(hwnd)
C.set_handle(chwnd)
} | go | func SetHandle(hwnd int) {
chwnd := C.uintptr(hwnd)
C.set_handle(chwnd)
} | [
"func",
"SetHandle",
"(",
"hwnd",
"int",
")",
"{",
"chwnd",
":=",
"C",
".",
"uintptr",
"(",
"hwnd",
")",
"\n",
"C",
".",
"set_handle",
"(",
"chwnd",
")",
"\n",
"}"
] | // SetHandle set the window handle | [
"SetHandle",
"set",
"the",
"window",
"handle"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1516-L1519 |
157,044 | go-vgo/robotgo | robotgo.go | SetHandlePid | func SetHandlePid(pid int32, args ...int32) {
var isHwnd int32
if len(args) > 0 {
isHwnd = args[0]
}
C.set_handle_pid_mData(C.uintptr(pid), C.uintptr(isHwnd))
} | go | func SetHandlePid(pid int32, args ...int32) {
var isHwnd int32
if len(args) > 0 {
isHwnd = args[0]
}
C.set_handle_pid_mData(C.uintptr(pid), C.uintptr(isHwnd))
} | [
"func",
"SetHandlePid",
"(",
"pid",
"int32",
",",
"args",
"...",
"int32",
")",
"{",
"var",
"isHwnd",
"int32",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"isHwnd",
"=",
"args",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"C",
".",
"set_handle_pid_mDa... | // SetHandlePid set the window handle by pid | [
"SetHandlePid",
"set",
"the",
"window",
"handle",
"by",
"pid"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1522-L1529 |
157,045 | go-vgo/robotgo | robotgo.go | GetHandPid | func GetHandPid(pid int32, args ...int32) C.MData {
var isHwnd int32
if len(args) > 0 {
isHwnd = args[0]
}
return C.set_handle_pid(C.uintptr(pid), C.uintptr(isHwnd))
} | go | func GetHandPid(pid int32, args ...int32) C.MData {
var isHwnd int32
if len(args) > 0 {
isHwnd = args[0]
}
return C.set_handle_pid(C.uintptr(pid), C.uintptr(isHwnd))
} | [
"func",
"GetHandPid",
"(",
"pid",
"int32",
",",
"args",
"...",
"int32",
")",
"C",
".",
"MData",
"{",
"var",
"isHwnd",
"int32",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"isHwnd",
"=",
"args",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
... | // GetHandPid get handle mdata by pid | [
"GetHandPid",
"get",
"handle",
"mdata",
"by",
"pid"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1532-L1539 |
157,046 | go-vgo/robotgo | robotgo.go | GetTitle | func GetTitle(args ...int32) string {
if len(args) <= 0 {
title := C.get_main_title()
gtitle := C.GoString(title)
return gtitle
}
if len(args) > 1 {
return internalGetTitle(args[0], args[1])
}
return internalGetTitle(args[0])
} | go | func GetTitle(args ...int32) string {
if len(args) <= 0 {
title := C.get_main_title()
gtitle := C.GoString(title)
return gtitle
}
if len(args) > 1 {
return internalGetTitle(args[0], args[1])
}
return internalGetTitle(args[0])
} | [
"func",
"GetTitle",
"(",
"args",
"...",
"int32",
")",
"string",
"{",
"if",
"len",
"(",
"args",
")",
"<=",
"0",
"{",
"title",
":=",
"C",
".",
"get_main_title",
"(",
")",
"\n",
"gtitle",
":=",
"C",
".",
"GoString",
"(",
"title",
")",
"\n",
"return",
... | // GetTitle get the window title | [
"GetTitle",
"get",
"the",
"window",
"title"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1565-L1577 |
157,047 | go-vgo/robotgo | robotgo.go | internalGetBounds | func internalGetBounds(pid int32, hwnd int) (int, int, int, int) {
bounds := C.get_bounds(C.uintptr(pid), C.uintptr(hwnd))
return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H)
} | go | func internalGetBounds(pid int32, hwnd int) (int, int, int, int) {
bounds := C.get_bounds(C.uintptr(pid), C.uintptr(hwnd))
return int(bounds.X), int(bounds.Y), int(bounds.W), int(bounds.H)
} | [
"func",
"internalGetBounds",
"(",
"pid",
"int32",
",",
"hwnd",
"int",
")",
"(",
"int",
",",
"int",
",",
"int",
",",
"int",
")",
"{",
"bounds",
":=",
"C",
".",
"get_bounds",
"(",
"C",
".",
"uintptr",
"(",
"pid",
")",
",",
"C",
".",
"uintptr",
"(",... | // internalGetBounds get the window bounds | [
"internalGetBounds",
"get",
"the",
"window",
"bounds"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1586-L1589 |
157,048 | go-vgo/robotgo | robotgo.go | Pids | func Pids() ([]int32, error) {
var ret []int32
pid, err := process.Pids()
if err != nil {
return ret, err
}
return pid, err
} | go | func Pids() ([]int32, error) {
var ret []int32
pid, err := process.Pids()
if err != nil {
return ret, err
}
return pid, err
} | [
"func",
"Pids",
"(",
")",
"(",
"[",
"]",
"int32",
",",
"error",
")",
"{",
"var",
"ret",
"[",
"]",
"int32",
"\n",
"pid",
",",
"err",
":=",
"process",
".",
"Pids",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ret",
",",
"err",
"\n"... | // Pids get the all process id | [
"Pids",
"get",
"the",
"all",
"process",
"id"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1592-L1600 |
157,049 | go-vgo/robotgo | robotgo.go | PidExists | func PidExists(pid int32) (bool, error) {
abool, err := process.PidExists(pid)
return abool, err
} | go | func PidExists(pid int32) (bool, error) {
abool, err := process.PidExists(pid)
return abool, err
} | [
"func",
"PidExists",
"(",
"pid",
"int32",
")",
"(",
"bool",
",",
"error",
")",
"{",
"abool",
",",
"err",
":=",
"process",
".",
"PidExists",
"(",
"pid",
")",
"\n\n",
"return",
"abool",
",",
"err",
"\n",
"}"
] | // PidExists determine whether the process exists | [
"PidExists",
"determine",
"whether",
"the",
"process",
"exists"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1603-L1607 |
157,050 | go-vgo/robotgo | robotgo.go | Process | func Process() ([]Nps, error) {
var npsArr []Nps
pid, err := process.Pids()
if err != nil {
return npsArr, err
}
for i := 0; i < len(pid); i++ {
nps, err := process.NewProcess(pid[i])
if err != nil {
return npsArr, err
}
names, err := nps.Name()
if err != nil {
return npsArr, err
}
np := Nps{
pid[i],
names,
}
npsArr = append(npsArr, np)
}
return npsArr, err
} | go | func Process() ([]Nps, error) {
var npsArr []Nps
pid, err := process.Pids()
if err != nil {
return npsArr, err
}
for i := 0; i < len(pid); i++ {
nps, err := process.NewProcess(pid[i])
if err != nil {
return npsArr, err
}
names, err := nps.Name()
if err != nil {
return npsArr, err
}
np := Nps{
pid[i],
names,
}
npsArr = append(npsArr, np)
}
return npsArr, err
} | [
"func",
"Process",
"(",
")",
"(",
"[",
"]",
"Nps",
",",
"error",
")",
"{",
"var",
"npsArr",
"[",
"]",
"Nps",
"\n\n",
"pid",
",",
"err",
":=",
"process",
".",
"Pids",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"npsArr",
",",
"err... | // Process get the all process struct | [
"Process",
"get",
"the",
"all",
"process",
"struct"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1616-L1644 |
157,051 | go-vgo/robotgo | robotgo.go | FindName | func FindName(pid int32) (string, error) {
nps, err := process.NewProcess(pid)
if err != nil {
return "", err
}
names, err := nps.Name()
if err != nil {
return "", err
}
return names, err
} | go | func FindName(pid int32) (string, error) {
nps, err := process.NewProcess(pid)
if err != nil {
return "", err
}
names, err := nps.Name()
if err != nil {
return "", err
}
return names, err
} | [
"func",
"FindName",
"(",
"pid",
"int32",
")",
"(",
"string",
",",
"error",
")",
"{",
"nps",
",",
"err",
":=",
"process",
".",
"NewProcess",
"(",
"pid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",... | // FindName find the process name by the process id | [
"FindName",
"find",
"the",
"process",
"name",
"by",
"the",
"process",
"id"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1647-L1659 |
157,052 | go-vgo/robotgo | robotgo.go | FindNames | func FindNames() ([]string, error) {
var strArr []string
pid, err := process.Pids()
if err != nil {
return strArr, err
}
for i := 0; i < len(pid); i++ {
nps, err := process.NewProcess(pid[i])
if err != nil {
return strArr, err
}
names, err := nps.Name()
if err != nil {
return strArr, err
}
strArr = append(strArr, names)
return strArr, err
}
return strArr, err
} | go | func FindNames() ([]string, error) {
var strArr []string
pid, err := process.Pids()
if err != nil {
return strArr, err
}
for i := 0; i < len(pid); i++ {
nps, err := process.NewProcess(pid[i])
if err != nil {
return strArr, err
}
names, err := nps.Name()
if err != nil {
return strArr, err
}
strArr = append(strArr, names)
return strArr, err
}
return strArr, err
} | [
"func",
"FindNames",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"strArr",
"[",
"]",
"string",
"\n",
"pid",
",",
"err",
":=",
"process",
".",
"Pids",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"strArr",
",",
... | // FindNames find the all process name | [
"FindNames",
"find",
"the",
"all",
"process",
"name"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1662-L1686 |
157,053 | go-vgo/robotgo | robotgo.go | Kill | func Kill(pid int32) error {
ps := os.Process{Pid: int(pid)}
return ps.Kill()
} | go | func Kill(pid int32) error {
ps := os.Process{Pid: int(pid)}
return ps.Kill()
} | [
"func",
"Kill",
"(",
"pid",
"int32",
")",
"error",
"{",
"ps",
":=",
"os",
".",
"Process",
"{",
"Pid",
":",
"int",
"(",
"pid",
")",
"}",
"\n",
"return",
"ps",
".",
"Kill",
"(",
")",
"\n",
"}"
] | // Kill kill the process by PID | [
"Kill",
"kill",
"the",
"process",
"by",
"PID"
] | d643b9ffe5a44c524740136edc428be68ddbecae | https://github.com/go-vgo/robotgo/blob/d643b9ffe5a44c524740136edc428be68ddbecae/robotgo.go#L1736-L1739 |
157,054 | gorilla/mux | regexp.go | url | func (r *routeRegexp) url(values map[string]string) (string, error) {
urlValues := make([]interface{}, len(r.varsN))
for k, v := range r.varsN {
value, ok := values[v]
if !ok {
return "", fmt.Errorf("mux: missing route variable %q", v)
}
if r.regexpType == regexpTypeQuery {
value = url.QueryEscape(value)
}
urlValues[k] = value
}
rv := fmt.Sprintf(r.reverse, urlValues...)
if !r.regexp.MatchString(rv) {
// The URL is checked against the full regexp, instead of checking
// individual variables. This is faster but to provide a good error
// message, we check individual regexps if the URL doesn't match.
for k, v := range r.varsN {
if !r.varsR[k].MatchString(values[v]) {
return "", fmt.Errorf(
"mux: variable %q doesn't match, expected %q", values[v],
r.varsR[k].String())
}
}
}
return rv, nil
} | go | func (r *routeRegexp) url(values map[string]string) (string, error) {
urlValues := make([]interface{}, len(r.varsN))
for k, v := range r.varsN {
value, ok := values[v]
if !ok {
return "", fmt.Errorf("mux: missing route variable %q", v)
}
if r.regexpType == regexpTypeQuery {
value = url.QueryEscape(value)
}
urlValues[k] = value
}
rv := fmt.Sprintf(r.reverse, urlValues...)
if !r.regexp.MatchString(rv) {
// The URL is checked against the full regexp, instead of checking
// individual variables. This is faster but to provide a good error
// message, we check individual regexps if the URL doesn't match.
for k, v := range r.varsN {
if !r.varsR[k].MatchString(values[v]) {
return "", fmt.Errorf(
"mux: variable %q doesn't match, expected %q", values[v],
r.varsR[k].String())
}
}
}
return rv, nil
} | [
"func",
"(",
"r",
"*",
"routeRegexp",
")",
"url",
"(",
"values",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"urlValues",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"r",
".",
"varsN",... | // url builds a URL part using the given values. | [
"url",
"builds",
"a",
"URL",
"part",
"using",
"the",
"given",
"values",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/regexp.go#L180-L206 |
157,055 | gorilla/mux | regexp.go | getURLQuery | func (r *routeRegexp) getURLQuery(req *http.Request) string {
if r.regexpType != regexpTypeQuery {
return ""
}
templateKey := strings.SplitN(r.template, "=", 2)[0]
for key, vals := range req.URL.Query() {
if key == templateKey && len(vals) > 0 {
return key + "=" + vals[0]
}
}
return ""
} | go | func (r *routeRegexp) getURLQuery(req *http.Request) string {
if r.regexpType != regexpTypeQuery {
return ""
}
templateKey := strings.SplitN(r.template, "=", 2)[0]
for key, vals := range req.URL.Query() {
if key == templateKey && len(vals) > 0 {
return key + "=" + vals[0]
}
}
return ""
} | [
"func",
"(",
"r",
"*",
"routeRegexp",
")",
"getURLQuery",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"if",
"r",
".",
"regexpType",
"!=",
"regexpTypeQuery",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"templateKey",
":=",
"strings",
".... | // getURLQuery returns a single query parameter from a request URL.
// For a URL with foo=bar&baz=ding, we return only the relevant key
// value pair for the routeRegexp. | [
"getURLQuery",
"returns",
"a",
"single",
"query",
"parameter",
"from",
"a",
"request",
"URL",
".",
"For",
"a",
"URL",
"with",
"foo",
"=",
"bar&baz",
"=",
"ding",
"we",
"return",
"only",
"the",
"relevant",
"key",
"value",
"pair",
"for",
"the",
"routeRegexp"... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/regexp.go#L211-L222 |
157,056 | gorilla/mux | route.go | Match | func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
if r.buildOnly || r.err != nil {
return false
}
var matchErr error
// Match everything.
for _, m := range r.matchers {
if matched := m.Match(req, match); !matched {
if _, ok := m.(methodMatcher); ok {
matchErr = ErrMethodMismatch
continue
}
// Ignore ErrNotFound errors. These errors arise from match call
// to Subrouters.
//
// This prevents subsequent matching subrouters from failing to
// run middleware. If not ignored, the middleware would see a
// non-nil MatchErr and be skipped, even when there was a
// matching route.
if match.MatchErr == ErrNotFound {
match.MatchErr = nil
}
matchErr = nil
return false
}
}
if matchErr != nil {
match.MatchErr = matchErr
return false
}
if match.MatchErr == ErrMethodMismatch {
// We found a route which matches request method, clear MatchErr
match.MatchErr = nil
// Then override the mis-matched handler
match.Handler = r.handler
}
// Yay, we have a match. Let's collect some info about it.
if match.Route == nil {
match.Route = r
}
if match.Handler == nil {
match.Handler = r.handler
}
if match.Vars == nil {
match.Vars = make(map[string]string)
}
// Set variables.
r.regexp.setMatch(req, match, r)
return true
} | go | func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
if r.buildOnly || r.err != nil {
return false
}
var matchErr error
// Match everything.
for _, m := range r.matchers {
if matched := m.Match(req, match); !matched {
if _, ok := m.(methodMatcher); ok {
matchErr = ErrMethodMismatch
continue
}
// Ignore ErrNotFound errors. These errors arise from match call
// to Subrouters.
//
// This prevents subsequent matching subrouters from failing to
// run middleware. If not ignored, the middleware would see a
// non-nil MatchErr and be skipped, even when there was a
// matching route.
if match.MatchErr == ErrNotFound {
match.MatchErr = nil
}
matchErr = nil
return false
}
}
if matchErr != nil {
match.MatchErr = matchErr
return false
}
if match.MatchErr == ErrMethodMismatch {
// We found a route which matches request method, clear MatchErr
match.MatchErr = nil
// Then override the mis-matched handler
match.Handler = r.handler
}
// Yay, we have a match. Let's collect some info about it.
if match.Route == nil {
match.Route = r
}
if match.Handler == nil {
match.Handler = r.handler
}
if match.Vars == nil {
match.Vars = make(map[string]string)
}
// Set variables.
r.regexp.setMatch(req, match, r)
return true
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"Match",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"match",
"*",
"RouteMatch",
")",
"bool",
"{",
"if",
"r",
".",
"buildOnly",
"||",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
... | // Match matches the route against the request. | [
"Match",
"matches",
"the",
"route",
"against",
"the",
"request",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L41-L98 |
157,057 | gorilla/mux | route.go | HandlerFunc | func (r *Route) HandlerFunc(f func(http.ResponseWriter, *http.Request)) *Route {
return r.Handler(http.HandlerFunc(f))
} | go | func (r *Route) HandlerFunc(f func(http.ResponseWriter, *http.Request)) *Route {
return r.Handler(http.HandlerFunc(f))
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"HandlerFunc",
"(",
"f",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"Handler",
"(",
"http",
".",
"HandlerFunc",
"(",
"f",
")",
... | // HandlerFunc sets a handler function for the route. | [
"HandlerFunc",
"sets",
"a",
"handler",
"function",
"for",
"the",
"route",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L126-L128 |
157,058 | gorilla/mux | route.go | Match | func (m MatcherFunc) Match(r *http.Request, match *RouteMatch) bool {
return m(r, match)
} | go | func (m MatcherFunc) Match(r *http.Request, match *RouteMatch) bool {
return m(r, match)
} | [
"func",
"(",
"m",
"MatcherFunc",
")",
"Match",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"match",
"*",
"RouteMatch",
")",
"bool",
"{",
"return",
"m",
"(",
"r",
",",
"match",
")",
"\n",
"}"
] | // Match returns the match for a given request. | [
"Match",
"returns",
"the",
"match",
"for",
"a",
"given",
"request",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L304-L306 |
157,059 | gorilla/mux | route.go | BuildVarsFunc | func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
if r.buildVarsFunc != nil {
// compose the old and new functions
old := r.buildVarsFunc
r.buildVarsFunc = func(m map[string]string) map[string]string {
return f(old(m))
}
} else {
r.buildVarsFunc = f
}
return r
} | go | func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
if r.buildVarsFunc != nil {
// compose the old and new functions
old := r.buildVarsFunc
r.buildVarsFunc = func(m map[string]string) map[string]string {
return f(old(m))
}
} else {
r.buildVarsFunc = f
}
return r
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"BuildVarsFunc",
"(",
"f",
"BuildVarsFunc",
")",
"*",
"Route",
"{",
"if",
"r",
".",
"buildVarsFunc",
"!=",
"nil",
"{",
"// compose the old and new functions",
"old",
":=",
"r",
".",
"buildVarsFunc",
"\n",
"r",
".",
"bui... | // BuildVarsFunc adds a custom function to be used to modify build variables
// before a route's URL is built. | [
"BuildVarsFunc",
"adds",
"a",
"custom",
"function",
"to",
"be",
"used",
"to",
"modify",
"build",
"variables",
"before",
"a",
"route",
"s",
"URL",
"is",
"built",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L438-L449 |
157,060 | gorilla/mux | route.go | GetPathTemplate | func (r *Route) GetPathTemplate() (string, error) {
if r.err != nil {
return "", r.err
}
if r.regexp.path == nil {
return "", errors.New("mux: route doesn't have a path")
}
return r.regexp.path.template, nil
} | go | func (r *Route) GetPathTemplate() (string, error) {
if r.err != nil {
return "", r.err
}
if r.regexp.path == nil {
return "", errors.New("mux: route doesn't have a path")
}
return r.regexp.path.template, nil
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"GetPathTemplate",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"regexp",
".",
"pat... | // GetPathTemplate returns the template used to build the
// route match.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not define a path. | [
"GetPathTemplate",
"returns",
"the",
"template",
"used",
"to",
"build",
"the",
"route",
"match",
".",
"This",
"is",
"useful",
"for",
"building",
"simple",
"REST",
"API",
"documentation",
"and",
"for",
"instrumentation",
"against",
"third",
"-",
"party",
"service... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L602-L610 |
157,061 | gorilla/mux | route.go | GetPathRegexp | func (r *Route) GetPathRegexp() (string, error) {
if r.err != nil {
return "", r.err
}
if r.regexp.path == nil {
return "", errors.New("mux: route does not have a path")
}
return r.regexp.path.regexp.String(), nil
} | go | func (r *Route) GetPathRegexp() (string, error) {
if r.err != nil {
return "", r.err
}
if r.regexp.path == nil {
return "", errors.New("mux: route does not have a path")
}
return r.regexp.path.regexp.String(), nil
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"GetPathRegexp",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"regexp",
".",
"path"... | // GetPathRegexp returns the expanded regular expression used to match route path.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not define a path. | [
"GetPathRegexp",
"returns",
"the",
"expanded",
"regular",
"expression",
"used",
"to",
"match",
"route",
"path",
".",
"This",
"is",
"useful",
"for",
"building",
"simple",
"REST",
"API",
"documentation",
"and",
"for",
"instrumentation",
"against",
"third",
"-",
"p... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L616-L624 |
157,062 | gorilla/mux | route.go | GetQueriesRegexp | func (r *Route) GetQueriesRegexp() ([]string, error) {
if r.err != nil {
return nil, r.err
}
if r.regexp.queries == nil {
return nil, errors.New("mux: route doesn't have queries")
}
var queries []string
for _, query := range r.regexp.queries {
queries = append(queries, query.regexp.String())
}
return queries, nil
} | go | func (r *Route) GetQueriesRegexp() ([]string, error) {
if r.err != nil {
return nil, r.err
}
if r.regexp.queries == nil {
return nil, errors.New("mux: route doesn't have queries")
}
var queries []string
for _, query := range r.regexp.queries {
queries = append(queries, query.regexp.String())
}
return queries, nil
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"GetQueriesRegexp",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"regexp",
"."... | // GetQueriesRegexp returns the expanded regular expressions used to match the
// route queries.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not have queries. | [
"GetQueriesRegexp",
"returns",
"the",
"expanded",
"regular",
"expressions",
"used",
"to",
"match",
"the",
"route",
"queries",
".",
"This",
"is",
"useful",
"for",
"building",
"simple",
"REST",
"API",
"documentation",
"and",
"for",
"instrumentation",
"against",
"thi... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L631-L643 |
157,063 | gorilla/mux | route.go | GetQueriesTemplates | func (r *Route) GetQueriesTemplates() ([]string, error) {
if r.err != nil {
return nil, r.err
}
if r.regexp.queries == nil {
return nil, errors.New("mux: route doesn't have queries")
}
var queries []string
for _, query := range r.regexp.queries {
queries = append(queries, query.template)
}
return queries, nil
} | go | func (r *Route) GetQueriesTemplates() ([]string, error) {
if r.err != nil {
return nil, r.err
}
if r.regexp.queries == nil {
return nil, errors.New("mux: route doesn't have queries")
}
var queries []string
for _, query := range r.regexp.queries {
queries = append(queries, query.template)
}
return queries, nil
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"GetQueriesTemplates",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"regexp",
... | // GetQueriesTemplates returns the templates used to build the
// query matching.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not define queries. | [
"GetQueriesTemplates",
"returns",
"the",
"templates",
"used",
"to",
"build",
"the",
"query",
"matching",
".",
"This",
"is",
"useful",
"for",
"building",
"simple",
"REST",
"API",
"documentation",
"and",
"for",
"instrumentation",
"against",
"third",
"-",
"party",
... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L650-L662 |
157,064 | gorilla/mux | route.go | GetMethods | func (r *Route) GetMethods() ([]string, error) {
if r.err != nil {
return nil, r.err
}
for _, m := range r.matchers {
if methods, ok := m.(methodMatcher); ok {
return []string(methods), nil
}
}
return nil, errors.New("mux: route doesn't have methods")
} | go | func (r *Route) GetMethods() ([]string, error) {
if r.err != nil {
return nil, r.err
}
for _, m := range r.matchers {
if methods, ok := m.(methodMatcher); ok {
return []string(methods), nil
}
}
return nil, errors.New("mux: route doesn't have methods")
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"GetMethods",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"rang... | // GetMethods returns the methods the route matches against
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if route does not have methods. | [
"GetMethods",
"returns",
"the",
"methods",
"the",
"route",
"matches",
"against",
"This",
"is",
"useful",
"for",
"building",
"simple",
"REST",
"API",
"documentation",
"and",
"for",
"instrumentation",
"against",
"third",
"-",
"party",
"services",
".",
"An",
"error... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L668-L678 |
157,065 | gorilla/mux | route.go | GetHostTemplate | func (r *Route) GetHostTemplate() (string, error) {
if r.err != nil {
return "", r.err
}
if r.regexp.host == nil {
return "", errors.New("mux: route doesn't have a host")
}
return r.regexp.host.template, nil
} | go | func (r *Route) GetHostTemplate() (string, error) {
if r.err != nil {
return "", r.err
}
if r.regexp.host == nil {
return "", errors.New("mux: route doesn't have a host")
}
return r.regexp.host.template, nil
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"GetHostTemplate",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"r",
".",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"regexp",
".",
"hos... | // GetHostTemplate returns the template used to build the
// route match.
// This is useful for building simple REST API documentation and for instrumentation
// against third-party services.
// An error will be returned if the route does not define a host. | [
"GetHostTemplate",
"returns",
"the",
"template",
"used",
"to",
"build",
"the",
"route",
"match",
".",
"This",
"is",
"useful",
"for",
"building",
"simple",
"REST",
"API",
"documentation",
"and",
"for",
"instrumentation",
"against",
"third",
"-",
"party",
"service... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L685-L693 |
157,066 | gorilla/mux | route.go | prepareVars | func (r *Route) prepareVars(pairs ...string) (map[string]string, error) {
m, err := mapFromPairsToString(pairs...)
if err != nil {
return nil, err
}
return r.buildVars(m), nil
} | go | func (r *Route) prepareVars(pairs ...string) (map[string]string, error) {
m, err := mapFromPairsToString(pairs...)
if err != nil {
return nil, err
}
return r.buildVars(m), nil
} | [
"func",
"(",
"r",
"*",
"Route",
")",
"prepareVars",
"(",
"pairs",
"...",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"mapFromPairsToString",
"(",
"pairs",
"...",
")",
"\n",
"if",
"err",
"!... | // prepareVars converts the route variable pairs into a map. If the route has a
// BuildVarsFunc, it is invoked. | [
"prepareVars",
"converts",
"the",
"route",
"variable",
"pairs",
"into",
"a",
"map",
".",
"If",
"the",
"route",
"has",
"a",
"BuildVarsFunc",
"it",
"is",
"invoked",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/route.go#L697-L703 |
157,067 | gorilla/mux | mux.go | copyRouteConf | func copyRouteConf(r routeConf) routeConf {
c := r
if r.regexp.path != nil {
c.regexp.path = copyRouteRegexp(r.regexp.path)
}
if r.regexp.host != nil {
c.regexp.host = copyRouteRegexp(r.regexp.host)
}
c.regexp.queries = make([]*routeRegexp, 0, len(r.regexp.queries))
for _, q := range r.regexp.queries {
c.regexp.queries = append(c.regexp.queries, copyRouteRegexp(q))
}
c.matchers = make([]matcher, 0, len(r.matchers))
for _, m := range r.matchers {
c.matchers = append(c.matchers, m)
}
return c
} | go | func copyRouteConf(r routeConf) routeConf {
c := r
if r.regexp.path != nil {
c.regexp.path = copyRouteRegexp(r.regexp.path)
}
if r.regexp.host != nil {
c.regexp.host = copyRouteRegexp(r.regexp.host)
}
c.regexp.queries = make([]*routeRegexp, 0, len(r.regexp.queries))
for _, q := range r.regexp.queries {
c.regexp.queries = append(c.regexp.queries, copyRouteRegexp(q))
}
c.matchers = make([]matcher, 0, len(r.matchers))
for _, m := range r.matchers {
c.matchers = append(c.matchers, m)
}
return c
} | [
"func",
"copyRouteConf",
"(",
"r",
"routeConf",
")",
"routeConf",
"{",
"c",
":=",
"r",
"\n\n",
"if",
"r",
".",
"regexp",
".",
"path",
"!=",
"nil",
"{",
"c",
".",
"regexp",
".",
"path",
"=",
"copyRouteRegexp",
"(",
"r",
".",
"regexp",
".",
"path",
"... | // returns an effective deep copy of `routeConf` | [
"returns",
"an",
"effective",
"deep",
"copy",
"of",
"routeConf"
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L98-L120 |
157,068 | gorilla/mux | mux.go | BuildVarsFunc | func (r *Router) BuildVarsFunc(f BuildVarsFunc) *Route {
return r.NewRoute().BuildVarsFunc(f)
} | go | func (r *Router) BuildVarsFunc(f BuildVarsFunc) *Route {
return r.NewRoute().BuildVarsFunc(f)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"BuildVarsFunc",
"(",
"f",
"BuildVarsFunc",
")",
"*",
"Route",
"{",
"return",
"r",
".",
"NewRoute",
"(",
")",
".",
"BuildVarsFunc",
"(",
"f",
")",
"\n",
"}"
] | // BuildVarsFunc registers a new route with a custom function for modifying
// route variables before building a URL. | [
"BuildVarsFunc",
"registers",
"a",
"new",
"route",
"with",
"a",
"custom",
"function",
"for",
"modifying",
"route",
"variables",
"before",
"building",
"a",
"URL",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L355-L357 |
157,069 | gorilla/mux | mux.go | Walk | func (r *Router) Walk(walkFn WalkFunc) error {
return r.walk(walkFn, []*Route{})
} | go | func (r *Router) Walk(walkFn WalkFunc) error {
return r.walk(walkFn, []*Route{})
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Walk",
"(",
"walkFn",
"WalkFunc",
")",
"error",
"{",
"return",
"r",
".",
"walk",
"(",
"walkFn",
",",
"[",
"]",
"*",
"Route",
"{",
"}",
")",
"\n",
"}"
] | // Walk walks the router and all its sub-routers, calling walkFn for each route
// in the tree. The routes are walked in the order they were added. Sub-routers
// are explored depth-first. | [
"Walk",
"walks",
"the",
"router",
"and",
"all",
"its",
"sub",
"-",
"routers",
"calling",
"walkFn",
"for",
"each",
"route",
"in",
"the",
"tree",
".",
"The",
"routes",
"are",
"walked",
"in",
"the",
"order",
"they",
"were",
"added",
".",
"Sub",
"-",
"rout... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L362-L364 |
157,070 | gorilla/mux | mux.go | CurrentRoute | func CurrentRoute(r *http.Request) *Route {
if rv := contextGet(r, routeKey); rv != nil {
return rv.(*Route)
}
return nil
} | go | func CurrentRoute(r *http.Request) *Route {
if rv := contextGet(r, routeKey); rv != nil {
return rv.(*Route)
}
return nil
} | [
"func",
"CurrentRoute",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"*",
"Route",
"{",
"if",
"rv",
":=",
"contextGet",
"(",
"r",
",",
"routeKey",
")",
";",
"rv",
"!=",
"nil",
"{",
"return",
"rv",
".",
"(",
"*",
"Route",
")",
"\n",
"}",
"\n",
"r... | // CurrentRoute returns the matched route for the current request, if any.
// This only works when called inside the handler of the matched route
// because the matched route is stored in the request context which is cleared
// after the handler returns, unless the KeepContext option is set on the
// Router. | [
"CurrentRoute",
"returns",
"the",
"matched",
"route",
"for",
"the",
"current",
"request",
"if",
"any",
".",
"This",
"only",
"works",
"when",
"called",
"inside",
"the",
"handler",
"of",
"the",
"matched",
"route",
"because",
"the",
"matched",
"route",
"is",
"s... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L442-L447 |
157,071 | gorilla/mux | mux.go | uniqueVars | func uniqueVars(s1, s2 []string) error {
for _, v1 := range s1 {
for _, v2 := range s2 {
if v1 == v2 {
return fmt.Errorf("mux: duplicated route variable %q", v2)
}
}
}
return nil
} | go | func uniqueVars(s1, s2 []string) error {
for _, v1 := range s1 {
for _, v2 := range s2 {
if v1 == v2 {
return fmt.Errorf("mux: duplicated route variable %q", v2)
}
}
}
return nil
} | [
"func",
"uniqueVars",
"(",
"s1",
",",
"s2",
"[",
"]",
"string",
")",
"error",
"{",
"for",
"_",
",",
"v1",
":=",
"range",
"s1",
"{",
"for",
"_",
",",
"v2",
":=",
"range",
"s2",
"{",
"if",
"v1",
"==",
"v2",
"{",
"return",
"fmt",
".",
"Errorf",
... | // uniqueVars returns an error if two slices contain duplicated strings. | [
"uniqueVars",
"returns",
"an",
"error",
"if",
"two",
"slices",
"contain",
"duplicated",
"strings",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L481-L490 |
157,072 | gorilla/mux | mux.go | checkPairs | func checkPairs(pairs ...string) (int, error) {
length := len(pairs)
if length%2 != 0 {
return length, fmt.Errorf(
"mux: number of parameters must be multiple of 2, got %v", pairs)
}
return length, nil
} | go | func checkPairs(pairs ...string) (int, error) {
length := len(pairs)
if length%2 != 0 {
return length, fmt.Errorf(
"mux: number of parameters must be multiple of 2, got %v", pairs)
}
return length, nil
} | [
"func",
"checkPairs",
"(",
"pairs",
"...",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"length",
":=",
"len",
"(",
"pairs",
")",
"\n",
"if",
"length",
"%",
"2",
"!=",
"0",
"{",
"return",
"length",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\""... | // checkPairs returns the count of strings passed in, and an error if
// the count is not an even number. | [
"checkPairs",
"returns",
"the",
"count",
"of",
"strings",
"passed",
"in",
"and",
"an",
"error",
"if",
"the",
"count",
"is",
"not",
"an",
"even",
"number",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L494-L501 |
157,073 | gorilla/mux | mux.go | mapFromPairsToString | func mapFromPairsToString(pairs ...string) (map[string]string, error) {
length, err := checkPairs(pairs...)
if err != nil {
return nil, err
}
m := make(map[string]string, length/2)
for i := 0; i < length; i += 2 {
m[pairs[i]] = pairs[i+1]
}
return m, nil
} | go | func mapFromPairsToString(pairs ...string) (map[string]string, error) {
length, err := checkPairs(pairs...)
if err != nil {
return nil, err
}
m := make(map[string]string, length/2)
for i := 0; i < length; i += 2 {
m[pairs[i]] = pairs[i+1]
}
return m, nil
} | [
"func",
"mapFromPairsToString",
"(",
"pairs",
"...",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"length",
",",
"err",
":=",
"checkPairs",
"(",
"pairs",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // mapFromPairsToString converts variadic string parameters to a
// string to string map. | [
"mapFromPairsToString",
"converts",
"variadic",
"string",
"parameters",
"to",
"a",
"string",
"to",
"string",
"map",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L505-L515 |
157,074 | gorilla/mux | mux.go | mapFromPairsToRegex | func mapFromPairsToRegex(pairs ...string) (map[string]*regexp.Regexp, error) {
length, err := checkPairs(pairs...)
if err != nil {
return nil, err
}
m := make(map[string]*regexp.Regexp, length/2)
for i := 0; i < length; i += 2 {
regex, err := regexp.Compile(pairs[i+1])
if err != nil {
return nil, err
}
m[pairs[i]] = regex
}
return m, nil
} | go | func mapFromPairsToRegex(pairs ...string) (map[string]*regexp.Regexp, error) {
length, err := checkPairs(pairs...)
if err != nil {
return nil, err
}
m := make(map[string]*regexp.Regexp, length/2)
for i := 0; i < length; i += 2 {
regex, err := regexp.Compile(pairs[i+1])
if err != nil {
return nil, err
}
m[pairs[i]] = regex
}
return m, nil
} | [
"func",
"mapFromPairsToRegex",
"(",
"pairs",
"...",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"regexp",
".",
"Regexp",
",",
"error",
")",
"{",
"length",
",",
"err",
":=",
"checkPairs",
"(",
"pairs",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil... | // mapFromPairsToRegex converts variadic string parameters to a
// string to regex map. | [
"mapFromPairsToRegex",
"converts",
"variadic",
"string",
"parameters",
"to",
"a",
"string",
"to",
"regex",
"map",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L519-L533 |
157,075 | gorilla/mux | mux.go | matchInArray | func matchInArray(arr []string, value string) bool {
for _, v := range arr {
if v == value {
return true
}
}
return false
} | go | func matchInArray(arr []string, value string) bool {
for _, v := range arr {
if v == value {
return true
}
}
return false
} | [
"func",
"matchInArray",
"(",
"arr",
"[",
"]",
"string",
",",
"value",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"arr",
"{",
"if",
"v",
"==",
"value",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n... | // matchInArray returns true if the given string value is in the array. | [
"matchInArray",
"returns",
"true",
"if",
"the",
"given",
"string",
"value",
"is",
"in",
"the",
"array",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L536-L543 |
157,076 | gorilla/mux | mux.go | methodNotAllowed | func methodNotAllowed(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusMethodNotAllowed)
} | go | func methodNotAllowed(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusMethodNotAllowed)
} | [
"func",
"methodNotAllowed",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusMethodNotAllowed",
")",
"\n",
"}"
] | // methodNotAllowed replies to the request with an HTTP status code 405. | [
"methodNotAllowed",
"replies",
"to",
"the",
"request",
"with",
"an",
"HTTP",
"status",
"code",
"405",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/mux.go#L601-L603 |
157,077 | gorilla/mux | middleware.go | Middleware | func (mw MiddlewareFunc) Middleware(handler http.Handler) http.Handler {
return mw(handler)
} | go | func (mw MiddlewareFunc) Middleware(handler http.Handler) http.Handler {
return mw(handler)
} | [
"func",
"(",
"mw",
"MiddlewareFunc",
")",
"Middleware",
"(",
"handler",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"mw",
"(",
"handler",
")",
"\n",
"}"
] | // Middleware allows MiddlewareFunc to implement the middleware interface. | [
"Middleware",
"allows",
"MiddlewareFunc",
"to",
"implement",
"the",
"middleware",
"interface",
"."
] | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/middleware.go#L19-L21 |
157,078 | gorilla/mux | middleware.go | CORSMethodMiddleware | func CORSMethodMiddleware(r *Router) MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
var allMethods []string
err := r.Walk(func(route *Route, _ *Router, _ []*Route) error {
for _, m := range route.matchers {
if _, ok := m.(*routeRegexp); ok {
if m.Match(req, &RouteMatch{}) {
methods, err := route.GetMethods()
if err != nil {
return err
}
allMethods = append(allMethods, methods...)
}
break
}
}
return nil
})
if err == nil {
w.Header().Set("Access-Control-Allow-Methods", strings.Join(append(allMethods, "OPTIONS"), ","))
if req.Method == "OPTIONS" {
return
}
}
next.ServeHTTP(w, req)
})
}
} | go | func CORSMethodMiddleware(r *Router) MiddlewareFunc {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
var allMethods []string
err := r.Walk(func(route *Route, _ *Router, _ []*Route) error {
for _, m := range route.matchers {
if _, ok := m.(*routeRegexp); ok {
if m.Match(req, &RouteMatch{}) {
methods, err := route.GetMethods()
if err != nil {
return err
}
allMethods = append(allMethods, methods...)
}
break
}
}
return nil
})
if err == nil {
w.Header().Set("Access-Control-Allow-Methods", strings.Join(append(allMethods, "OPTIONS"), ","))
if req.Method == "OPTIONS" {
return
}
}
next.ServeHTTP(w, req)
})
}
} | [
"func",
"CORSMethodMiddleware",
"(",
"r",
"*",
"Router",
")",
"MiddlewareFunc",
"{",
"return",
"func",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"Respo... | // CORSMethodMiddleware sets the Access-Control-Allow-Methods response header
// on a request, by matching routes based only on paths. It also handles
// OPTIONS requests, by settings Access-Control-Allow-Methods, and then
// returning without calling the next http handler. | [
"CORSMethodMiddleware",
"sets",
"the",
"Access",
"-",
"Control",
"-",
"Allow",
"-",
"Methods",
"response",
"header",
"on",
"a",
"request",
"by",
"matching",
"routes",
"based",
"only",
"on",
"paths",
".",
"It",
"also",
"handles",
"OPTIONS",
"requests",
"by",
... | c5c6c98bc25355028a63748a498942a6398ccd22 | https://github.com/gorilla/mux/blob/c5c6c98bc25355028a63748a498942a6398ccd22/middleware.go#L39-L72 |
157,079 | kelseyhightower/confd | resource/template/resource.go | NewTemplateResource | func NewTemplateResource(path string, config Config) (*TemplateResource, error) {
if config.StoreClient == nil {
return nil, errors.New("A valid StoreClient is required.")
}
// Set the default uid and gid so we can determine if it was
// unset from configuration.
tc := &TemplateResourceConfig{TemplateResource{Uid: -1, Gid: -1}}
log.Debug("Loading template resource from " + path)
_, err := toml.DecodeFile(path, &tc)
if err != nil {
return nil, fmt.Errorf("Cannot process template resource %s - %s", path, err.Error())
}
tr := tc.TemplateResource
tr.keepStageFile = config.KeepStageFile
tr.noop = config.Noop
tr.storeClient = config.StoreClient
tr.funcMap = newFuncMap()
tr.store = memkv.New()
tr.syncOnly = config.SyncOnly
addFuncs(tr.funcMap, tr.store.FuncMap)
if config.Prefix != "" {
tr.Prefix = config.Prefix
}
if !strings.HasPrefix(tr.Prefix, "/") {
tr.Prefix = "/" + tr.Prefix
}
if len(config.PGPPrivateKey) > 0 {
tr.PGPPrivateKey = config.PGPPrivateKey
addCryptFuncs(&tr)
}
if tr.Src == "" {
return nil, ErrEmptySrc
}
if tr.Uid == -1 {
tr.Uid = os.Geteuid()
}
if tr.Gid == -1 {
tr.Gid = os.Getegid()
}
tr.Src = filepath.Join(config.TemplateDir, tr.Src)
return &tr, nil
} | go | func NewTemplateResource(path string, config Config) (*TemplateResource, error) {
if config.StoreClient == nil {
return nil, errors.New("A valid StoreClient is required.")
}
// Set the default uid and gid so we can determine if it was
// unset from configuration.
tc := &TemplateResourceConfig{TemplateResource{Uid: -1, Gid: -1}}
log.Debug("Loading template resource from " + path)
_, err := toml.DecodeFile(path, &tc)
if err != nil {
return nil, fmt.Errorf("Cannot process template resource %s - %s", path, err.Error())
}
tr := tc.TemplateResource
tr.keepStageFile = config.KeepStageFile
tr.noop = config.Noop
tr.storeClient = config.StoreClient
tr.funcMap = newFuncMap()
tr.store = memkv.New()
tr.syncOnly = config.SyncOnly
addFuncs(tr.funcMap, tr.store.FuncMap)
if config.Prefix != "" {
tr.Prefix = config.Prefix
}
if !strings.HasPrefix(tr.Prefix, "/") {
tr.Prefix = "/" + tr.Prefix
}
if len(config.PGPPrivateKey) > 0 {
tr.PGPPrivateKey = config.PGPPrivateKey
addCryptFuncs(&tr)
}
if tr.Src == "" {
return nil, ErrEmptySrc
}
if tr.Uid == -1 {
tr.Uid = os.Geteuid()
}
if tr.Gid == -1 {
tr.Gid = os.Getegid()
}
tr.Src = filepath.Join(config.TemplateDir, tr.Src)
return &tr, nil
} | [
"func",
"NewTemplateResource",
"(",
"path",
"string",
",",
"config",
"Config",
")",
"(",
"*",
"TemplateResource",
",",
"error",
")",
"{",
"if",
"config",
".",
"StoreClient",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
... | // NewTemplateResource creates a TemplateResource. | [
"NewTemplateResource",
"creates",
"a",
"TemplateResource",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L68-L119 |
157,080 | kelseyhightower/confd | resource/template/resource.go | setVars | func (t *TemplateResource) setVars() error {
var err error
log.Debug("Retrieving keys from store")
log.Debug("Key prefix set to " + t.Prefix)
result, err := t.storeClient.GetValues(util.AppendPrefix(t.Prefix, t.Keys))
if err != nil {
return err
}
log.Debug("Got the following map from store: %v", result)
t.store.Purge()
for k, v := range result {
t.store.Set(path.Join("/", strings.TrimPrefix(k, t.Prefix)), v)
}
return nil
} | go | func (t *TemplateResource) setVars() error {
var err error
log.Debug("Retrieving keys from store")
log.Debug("Key prefix set to " + t.Prefix)
result, err := t.storeClient.GetValues(util.AppendPrefix(t.Prefix, t.Keys))
if err != nil {
return err
}
log.Debug("Got the following map from store: %v", result)
t.store.Purge()
for k, v := range result {
t.store.Set(path.Join("/", strings.TrimPrefix(k, t.Prefix)), v)
}
return nil
} | [
"func",
"(",
"t",
"*",
"TemplateResource",
")",
"setVars",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
"+",
"t",
".",
"Prefix",
")",
"\n\n",
"result",... | // setVars sets the Vars for template resource. | [
"setVars",
"sets",
"the",
"Vars",
"for",
"template",
"resource",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L175-L192 |
157,081 | kelseyhightower/confd | resource/template/resource.go | createStageFile | func (t *TemplateResource) createStageFile() error {
log.Debug("Using source template " + t.Src)
if !util.IsFileExist(t.Src) {
return errors.New("Missing template: " + t.Src)
}
log.Debug("Compiling source template " + t.Src)
tmpl, err := template.New(filepath.Base(t.Src)).Funcs(t.funcMap).ParseFiles(t.Src)
if err != nil {
return fmt.Errorf("Unable to process template %s, %s", t.Src, err)
}
// create TempFile in Dest directory to avoid cross-filesystem issues
temp, err := ioutil.TempFile(filepath.Dir(t.Dest), "."+filepath.Base(t.Dest))
if err != nil {
return err
}
if err = tmpl.Execute(temp, nil); err != nil {
temp.Close()
os.Remove(temp.Name())
return err
}
defer temp.Close()
// Set the owner, group, and mode on the stage file now to make it easier to
// compare against the destination configuration file later.
os.Chmod(temp.Name(), t.FileMode)
os.Chown(temp.Name(), t.Uid, t.Gid)
t.StageFile = temp
return nil
} | go | func (t *TemplateResource) createStageFile() error {
log.Debug("Using source template " + t.Src)
if !util.IsFileExist(t.Src) {
return errors.New("Missing template: " + t.Src)
}
log.Debug("Compiling source template " + t.Src)
tmpl, err := template.New(filepath.Base(t.Src)).Funcs(t.funcMap).ParseFiles(t.Src)
if err != nil {
return fmt.Errorf("Unable to process template %s, %s", t.Src, err)
}
// create TempFile in Dest directory to avoid cross-filesystem issues
temp, err := ioutil.TempFile(filepath.Dir(t.Dest), "."+filepath.Base(t.Dest))
if err != nil {
return err
}
if err = tmpl.Execute(temp, nil); err != nil {
temp.Close()
os.Remove(temp.Name())
return err
}
defer temp.Close()
// Set the owner, group, and mode on the stage file now to make it easier to
// compare against the destination configuration file later.
os.Chmod(temp.Name(), t.FileMode)
os.Chown(temp.Name(), t.Uid, t.Gid)
t.StageFile = temp
return nil
} | [
"func",
"(",
"t",
"*",
"TemplateResource",
")",
"createStageFile",
"(",
")",
"error",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
"+",
"t",
".",
"Src",
")",
"\n\n",
"if",
"!",
"util",
".",
"IsFileExist",
"(",
"t",
".",
"Src",
")",
"{",
"return",
"... | // createStageFile stages the src configuration file by processing the src
// template and setting the desired owner, group, and mode. It also sets the
// StageFile for the template resource.
// It returns an error if any. | [
"createStageFile",
"stages",
"the",
"src",
"configuration",
"file",
"by",
"processing",
"the",
"src",
"template",
"and",
"setting",
"the",
"desired",
"owner",
"group",
"and",
"mode",
".",
"It",
"also",
"sets",
"the",
"StageFile",
"for",
"the",
"template",
"res... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L198-L231 |
157,082 | kelseyhightower/confd | resource/template/resource.go | sync | func (t *TemplateResource) sync() error {
staged := t.StageFile.Name()
if t.keepStageFile {
log.Info("Keeping staged file: " + staged)
} else {
defer os.Remove(staged)
}
log.Debug("Comparing candidate config to " + t.Dest)
ok, err := util.IsConfigChanged(staged, t.Dest)
if err != nil {
log.Error(err.Error())
}
if t.noop {
log.Warning("Noop mode enabled. " + t.Dest + " will not be modified")
return nil
}
if ok {
log.Info("Target config " + t.Dest + " out of sync")
if !t.syncOnly && t.CheckCmd != "" {
if err := t.check(); err != nil {
return errors.New("Config check failed: " + err.Error())
}
}
log.Debug("Overwriting target config " + t.Dest)
err := os.Rename(staged, t.Dest)
if err != nil {
if strings.Contains(err.Error(), "device or resource busy") {
log.Debug("Rename failed - target is likely a mount. Trying to write instead")
// try to open the file and write to it
var contents []byte
var rerr error
contents, rerr = ioutil.ReadFile(staged)
if rerr != nil {
return rerr
}
err := ioutil.WriteFile(t.Dest, contents, t.FileMode)
// make sure owner and group match the temp file, in case the file was created with WriteFile
os.Chown(t.Dest, t.Uid, t.Gid)
if err != nil {
return err
}
} else {
return err
}
}
if !t.syncOnly && t.ReloadCmd != "" {
if err := t.reload(); err != nil {
return err
}
}
log.Info("Target config " + t.Dest + " has been updated")
} else {
log.Debug("Target config " + t.Dest + " in sync")
}
return nil
} | go | func (t *TemplateResource) sync() error {
staged := t.StageFile.Name()
if t.keepStageFile {
log.Info("Keeping staged file: " + staged)
} else {
defer os.Remove(staged)
}
log.Debug("Comparing candidate config to " + t.Dest)
ok, err := util.IsConfigChanged(staged, t.Dest)
if err != nil {
log.Error(err.Error())
}
if t.noop {
log.Warning("Noop mode enabled. " + t.Dest + " will not be modified")
return nil
}
if ok {
log.Info("Target config " + t.Dest + " out of sync")
if !t.syncOnly && t.CheckCmd != "" {
if err := t.check(); err != nil {
return errors.New("Config check failed: " + err.Error())
}
}
log.Debug("Overwriting target config " + t.Dest)
err := os.Rename(staged, t.Dest)
if err != nil {
if strings.Contains(err.Error(), "device or resource busy") {
log.Debug("Rename failed - target is likely a mount. Trying to write instead")
// try to open the file and write to it
var contents []byte
var rerr error
contents, rerr = ioutil.ReadFile(staged)
if rerr != nil {
return rerr
}
err := ioutil.WriteFile(t.Dest, contents, t.FileMode)
// make sure owner and group match the temp file, in case the file was created with WriteFile
os.Chown(t.Dest, t.Uid, t.Gid)
if err != nil {
return err
}
} else {
return err
}
}
if !t.syncOnly && t.ReloadCmd != "" {
if err := t.reload(); err != nil {
return err
}
}
log.Info("Target config " + t.Dest + " has been updated")
} else {
log.Debug("Target config " + t.Dest + " in sync")
}
return nil
} | [
"func",
"(",
"t",
"*",
"TemplateResource",
")",
"sync",
"(",
")",
"error",
"{",
"staged",
":=",
"t",
".",
"StageFile",
".",
"Name",
"(",
")",
"\n",
"if",
"t",
".",
"keepStageFile",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
"+",
"staged",
")",
"\n... | // sync compares the staged and dest config files and attempts to sync them
// if they differ. sync will run a config check command if set before
// overwriting the target config file. Finally, sync will run a reload command
// if set to have the application or service pick up the changes.
// It returns an error if any. | [
"sync",
"compares",
"the",
"staged",
"and",
"dest",
"config",
"files",
"and",
"attempts",
"to",
"sync",
"them",
"if",
"they",
"differ",
".",
"sync",
"will",
"run",
"a",
"config",
"check",
"command",
"if",
"set",
"before",
"overwriting",
"the",
"target",
"c... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L238-L294 |
157,083 | kelseyhightower/confd | resource/template/resource.go | check | func (t *TemplateResource) check() error {
var cmdBuffer bytes.Buffer
data := make(map[string]string)
data["src"] = t.StageFile.Name()
tmpl, err := template.New("checkcmd").Parse(t.CheckCmd)
if err != nil {
return err
}
if err := tmpl.Execute(&cmdBuffer, data); err != nil {
return err
}
return runCommand(cmdBuffer.String())
} | go | func (t *TemplateResource) check() error {
var cmdBuffer bytes.Buffer
data := make(map[string]string)
data["src"] = t.StageFile.Name()
tmpl, err := template.New("checkcmd").Parse(t.CheckCmd)
if err != nil {
return err
}
if err := tmpl.Execute(&cmdBuffer, data); err != nil {
return err
}
return runCommand(cmdBuffer.String())
} | [
"func",
"(",
"t",
"*",
"TemplateResource",
")",
"check",
"(",
")",
"error",
"{",
"var",
"cmdBuffer",
"bytes",
".",
"Buffer",
"\n",
"data",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"data",
"[",
"\"",
"\"",
"]",
"=",
"t",
... | // check executes the check command to validate the staged config file. The
// command is modified so that any references to src template are substituted
// with a string representing the full path of the staged file. This allows the
// check to be run on the staged file before overwriting the destination config
// file.
// It returns nil if the check command returns 0 and there are no other errors. | [
"check",
"executes",
"the",
"check",
"command",
"to",
"validate",
"the",
"staged",
"config",
"file",
".",
"The",
"command",
"is",
"modified",
"so",
"that",
"any",
"references",
"to",
"src",
"template",
"are",
"substituted",
"with",
"a",
"string",
"representing... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L302-L314 |
157,084 | kelseyhightower/confd | resource/template/resource.go | runCommand | func runCommand(cmd string) error {
log.Debug("Running " + cmd)
var c *exec.Cmd
if runtime.GOOS == "windows" {
c = exec.Command("cmd", "/C", cmd)
} else {
c = exec.Command("/bin/sh", "-c", cmd)
}
output, err := c.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%q", string(output)))
return err
}
log.Debug(fmt.Sprintf("%q", string(output)))
return nil
} | go | func runCommand(cmd string) error {
log.Debug("Running " + cmd)
var c *exec.Cmd
if runtime.GOOS == "windows" {
c = exec.Command("cmd", "/C", cmd)
} else {
c = exec.Command("/bin/sh", "-c", cmd)
}
output, err := c.CombinedOutput()
if err != nil {
log.Error(fmt.Sprintf("%q", string(output)))
return err
}
log.Debug(fmt.Sprintf("%q", string(output)))
return nil
} | [
"func",
"runCommand",
"(",
"cmd",
"string",
")",
"error",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
"+",
"cmd",
")",
"\n",
"var",
"c",
"*",
"exec",
".",
"Cmd",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"c",
"=",
"exec",
".",
... | // runCommand is a shared function used by check and reload
// to run the given command and log its output.
// It returns nil if the given cmd returns 0.
// The command can be run on unix and windows. | [
"runCommand",
"is",
"a",
"shared",
"function",
"used",
"by",
"check",
"and",
"reload",
"to",
"run",
"the",
"given",
"command",
"and",
"log",
"its",
"output",
".",
"It",
"returns",
"nil",
"if",
"the",
"given",
"cmd",
"returns",
"0",
".",
"The",
"command",... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L326-L342 |
157,085 | kelseyhightower/confd | resource/template/resource.go | process | func (t *TemplateResource) process() error {
if err := t.setFileMode(); err != nil {
return err
}
if err := t.setVars(); err != nil {
return err
}
if err := t.createStageFile(); err != nil {
return err
}
if err := t.sync(); err != nil {
return err
}
return nil
} | go | func (t *TemplateResource) process() error {
if err := t.setFileMode(); err != nil {
return err
}
if err := t.setVars(); err != nil {
return err
}
if err := t.createStageFile(); err != nil {
return err
}
if err := t.sync(); err != nil {
return err
}
return nil
} | [
"func",
"(",
"t",
"*",
"TemplateResource",
")",
"process",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"t",
".",
"setFileMode",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"t",
".",
"setVars",
"(",
... | // process is a convenience function that wraps calls to the three main tasks
// required to keep local configuration files in sync. First we gather vars
// from the store, then we stage a candidate configuration file, and finally sync
// things up.
// It returns an error if any. | [
"process",
"is",
"a",
"convenience",
"function",
"that",
"wraps",
"calls",
"to",
"the",
"three",
"main",
"tasks",
"required",
"to",
"keep",
"local",
"configuration",
"files",
"in",
"sync",
".",
"First",
"we",
"gather",
"vars",
"from",
"the",
"store",
"then",... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L349-L363 |
157,086 | kelseyhightower/confd | resource/template/resource.go | setFileMode | func (t *TemplateResource) setFileMode() error {
if t.Mode == "" {
if !util.IsFileExist(t.Dest) {
t.FileMode = 0644
} else {
fi, err := os.Stat(t.Dest)
if err != nil {
return err
}
t.FileMode = fi.Mode()
}
} else {
mode, err := strconv.ParseUint(t.Mode, 0, 32)
if err != nil {
return err
}
t.FileMode = os.FileMode(mode)
}
return nil
} | go | func (t *TemplateResource) setFileMode() error {
if t.Mode == "" {
if !util.IsFileExist(t.Dest) {
t.FileMode = 0644
} else {
fi, err := os.Stat(t.Dest)
if err != nil {
return err
}
t.FileMode = fi.Mode()
}
} else {
mode, err := strconv.ParseUint(t.Mode, 0, 32)
if err != nil {
return err
}
t.FileMode = os.FileMode(mode)
}
return nil
} | [
"func",
"(",
"t",
"*",
"TemplateResource",
")",
"setFileMode",
"(",
")",
"error",
"{",
"if",
"t",
".",
"Mode",
"==",
"\"",
"\"",
"{",
"if",
"!",
"util",
".",
"IsFileExist",
"(",
"t",
".",
"Dest",
")",
"{",
"t",
".",
"FileMode",
"=",
"0644",
"\n",... | // setFileMode sets the FileMode. | [
"setFileMode",
"sets",
"the",
"FileMode",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/resource.go#L366-L385 |
157,087 | kelseyhightower/confd | backends/client.go | New | func New(config Config) (StoreClient, error) {
if config.Backend == "" {
config.Backend = "etcd"
}
backendNodes := config.BackendNodes
if config.Backend == "file" {
log.Info("Backend source(s) set to " + strings.Join(config.YAMLFile, ", "))
} else {
log.Info("Backend source(s) set to " + strings.Join(backendNodes, ", "))
}
switch config.Backend {
case "consul":
return consul.New(config.BackendNodes, config.Scheme,
config.ClientCert, config.ClientKey,
config.ClientCaKeys,
config.BasicAuth,
config.Username,
config.Password,
)
case "etcd":
// Create the etcd client upfront and use it for the life of the process.
// The etcdClient is an http.Client and designed to be reused.
return etcd.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.ClientInsecure, config.BasicAuth, config.Username, config.Password)
case "etcdv3":
return etcdv3.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.BasicAuth, config.Username, config.Password)
case "zookeeper":
return zookeeper.NewZookeeperClient(backendNodes)
case "rancher":
return rancher.NewRancherClient(backendNodes)
case "redis":
return redis.NewRedisClient(backendNodes, config.ClientKey, config.Separator)
case "env":
return env.NewEnvClient()
case "file":
return file.NewFileClient(config.YAMLFile, config.Filter)
case "vault":
vaultConfig := map[string]string{
"app-id": config.AppID,
"user-id": config.UserID,
"role-id": config.RoleID,
"secret-id": config.SecretID,
"username": config.Username,
"password": config.Password,
"token": config.AuthToken,
"cert": config.ClientCert,
"key": config.ClientKey,
"caCert": config.ClientCaKeys,
"path": config.Path,
}
return vault.New(backendNodes[0], config.AuthType, vaultConfig)
case "dynamodb":
table := config.Table
log.Info("DynamoDB table set to " + table)
return dynamodb.NewDynamoDBClient(table)
case "ssm":
return ssm.New()
}
return nil, errors.New("Invalid backend")
} | go | func New(config Config) (StoreClient, error) {
if config.Backend == "" {
config.Backend = "etcd"
}
backendNodes := config.BackendNodes
if config.Backend == "file" {
log.Info("Backend source(s) set to " + strings.Join(config.YAMLFile, ", "))
} else {
log.Info("Backend source(s) set to " + strings.Join(backendNodes, ", "))
}
switch config.Backend {
case "consul":
return consul.New(config.BackendNodes, config.Scheme,
config.ClientCert, config.ClientKey,
config.ClientCaKeys,
config.BasicAuth,
config.Username,
config.Password,
)
case "etcd":
// Create the etcd client upfront and use it for the life of the process.
// The etcdClient is an http.Client and designed to be reused.
return etcd.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.ClientInsecure, config.BasicAuth, config.Username, config.Password)
case "etcdv3":
return etcdv3.NewEtcdClient(backendNodes, config.ClientCert, config.ClientKey, config.ClientCaKeys, config.BasicAuth, config.Username, config.Password)
case "zookeeper":
return zookeeper.NewZookeeperClient(backendNodes)
case "rancher":
return rancher.NewRancherClient(backendNodes)
case "redis":
return redis.NewRedisClient(backendNodes, config.ClientKey, config.Separator)
case "env":
return env.NewEnvClient()
case "file":
return file.NewFileClient(config.YAMLFile, config.Filter)
case "vault":
vaultConfig := map[string]string{
"app-id": config.AppID,
"user-id": config.UserID,
"role-id": config.RoleID,
"secret-id": config.SecretID,
"username": config.Username,
"password": config.Password,
"token": config.AuthToken,
"cert": config.ClientCert,
"key": config.ClientKey,
"caCert": config.ClientCaKeys,
"path": config.Path,
}
return vault.New(backendNodes[0], config.AuthType, vaultConfig)
case "dynamodb":
table := config.Table
log.Info("DynamoDB table set to " + table)
return dynamodb.NewDynamoDBClient(table)
case "ssm":
return ssm.New()
}
return nil, errors.New("Invalid backend")
} | [
"func",
"New",
"(",
"config",
"Config",
")",
"(",
"StoreClient",
",",
"error",
")",
"{",
"if",
"config",
".",
"Backend",
"==",
"\"",
"\"",
"{",
"config",
".",
"Backend",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"backendNodes",
":=",
"config",
".",
"BackendN... | // New is used to create a storage client based on our configuration. | [
"New",
"is",
"used",
"to",
"create",
"a",
"storage",
"client",
"based",
"on",
"our",
"configuration",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/backends/client.go#L29-L90 |
157,088 | kelseyhightower/confd | resource/template/template_funcs.go | Getenv | func Getenv(key string, v ...string) string {
defaultValue := ""
if len(v) > 0 {
defaultValue = v[0]
}
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
} | go | func Getenv(key string, v ...string) string {
defaultValue := ""
if len(v) > 0 {
defaultValue = v[0]
}
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
} | [
"func",
"Getenv",
"(",
"key",
"string",
",",
"v",
"...",
"string",
")",
"string",
"{",
"defaultValue",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"v",
")",
">",
"0",
"{",
"defaultValue",
"=",
"v",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"value",
":=",
... | // Getenv retrieves the value of the environment variable named by the key.
// It returns the value, which will the default value if the variable is not present.
// If no default value was given - returns "". | [
"Getenv",
"retrieves",
"the",
"value",
"of",
"the",
"environment",
"variable",
"named",
"by",
"the",
"key",
".",
"It",
"returns",
"the",
"value",
"which",
"will",
"the",
"default",
"value",
"if",
"the",
"variable",
"is",
"not",
"present",
".",
"If",
"no",
... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/resource/template/template_funcs.go#L130-L141 |
157,089 | kelseyhightower/confd | backends/ssm/client.go | GetValues | func (c *Client) GetValues(keys []string) (map[string]string, error) {
vars := make(map[string]string)
var err error
for _, key := range keys {
log.Debug("Processing key=%s", key)
var resp map[string]string
resp, err = c.getParametersWithPrefix(key)
if err != nil {
return vars, err
}
if len(resp) == 0 {
resp, err = c.getParameter(key)
if err != nil && err.(awserr.Error).Code() != ssm.ErrCodeParameterNotFound {
return vars, err
}
}
for k, v := range resp {
vars[k] = v
}
}
return vars, nil
} | go | func (c *Client) GetValues(keys []string) (map[string]string, error) {
vars := make(map[string]string)
var err error
for _, key := range keys {
log.Debug("Processing key=%s", key)
var resp map[string]string
resp, err = c.getParametersWithPrefix(key)
if err != nil {
return vars, err
}
if len(resp) == 0 {
resp, err = c.getParameter(key)
if err != nil && err.(awserr.Error).Code() != ssm.ErrCodeParameterNotFound {
return vars, err
}
}
for k, v := range resp {
vars[k] = v
}
}
return vars, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetValues",
"(",
"keys",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"vars",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"var",
"err",
... | // GetValues retrieves the values for the given keys from AWS SSM Parameter Store | [
"GetValues",
"retrieves",
"the",
"values",
"for",
"the",
"given",
"keys",
"from",
"AWS",
"SSM",
"Parameter",
"Store"
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/backends/ssm/client.go#L44-L65 |
157,090 | kelseyhightower/confd | backends/ssm/client.go | WatchPrefix | func (c *Client) WatchPrefix(prefix string, keys []string, waitIndex uint64, stopChan chan bool) (uint64, error) {
<-stopChan
return 0, nil
} | go | func (c *Client) WatchPrefix(prefix string, keys []string, waitIndex uint64, stopChan chan bool) (uint64, error) {
<-stopChan
return 0, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"WatchPrefix",
"(",
"prefix",
"string",
",",
"keys",
"[",
"]",
"string",
",",
"waitIndex",
"uint64",
",",
"stopChan",
"chan",
"bool",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"<-",
"stopChan",
"\n",
"return",
... | // WatchPrefix is not implemented | [
"WatchPrefix",
"is",
"not",
"implemented"
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/backends/ssm/client.go#L100-L103 |
157,091 | kelseyhightower/confd | backends/etcdv3/client.go | WaitNext | func (w *Watch) WaitNext(ctx context.Context, lastRevision int64, notify chan<-int64) {
for {
w.rwl.RLock()
if w.revision > lastRevision {
w.rwl.RUnlock()
break
}
cond := w.cond
w.rwl.RUnlock()
select{
case <-cond:
case <-ctx.Done():
return
}
}
// We accept larger revision, so do not need to use RLock
select{
case notify<-w.revision:
case <-ctx.Done():
}
} | go | func (w *Watch) WaitNext(ctx context.Context, lastRevision int64, notify chan<-int64) {
for {
w.rwl.RLock()
if w.revision > lastRevision {
w.rwl.RUnlock()
break
}
cond := w.cond
w.rwl.RUnlock()
select{
case <-cond:
case <-ctx.Done():
return
}
}
// We accept larger revision, so do not need to use RLock
select{
case notify<-w.revision:
case <-ctx.Done():
}
} | [
"func",
"(",
"w",
"*",
"Watch",
")",
"WaitNext",
"(",
"ctx",
"context",
".",
"Context",
",",
"lastRevision",
"int64",
",",
"notify",
"chan",
"<-",
"int64",
")",
"{",
"for",
"{",
"w",
".",
"rwl",
".",
"RLock",
"(",
")",
"\n",
"if",
"w",
".",
"revi... | // Wait until revision is greater than lastRevision | [
"Wait",
"until",
"revision",
"is",
"greater",
"than",
"lastRevision"
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/backends/etcdv3/client.go#L28-L48 |
157,092 | kelseyhightower/confd | util/util.go | Set | func (n *Nodes) Set(node string) error {
*n = append(*n, node)
return nil
} | go | func (n *Nodes) Set(node string) error {
*n = append(*n, node)
return nil
} | [
"func",
"(",
"n",
"*",
"Nodes",
")",
"Set",
"(",
"node",
"string",
")",
"error",
"{",
"*",
"n",
"=",
"append",
"(",
"*",
"n",
",",
"node",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set appends the node to the etcd node list. | [
"Set",
"appends",
"the",
"node",
"to",
"the",
"etcd",
"node",
"list",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/util/util.go#L20-L23 |
157,093 | kelseyhightower/confd | util/util.go | IsFileExist | func IsFileExist(fpath string) bool {
if _, err := os.Stat(fpath); os.IsNotExist(err) {
return false
}
return true
} | go | func IsFileExist(fpath string) bool {
if _, err := os.Stat(fpath); os.IsNotExist(err) {
return false
}
return true
} | [
"func",
"IsFileExist",
"(",
"fpath",
"string",
")",
"bool",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"fpath",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}... | // isFileExist reports whether path exits. | [
"isFileExist",
"reports",
"whether",
"path",
"exits",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/util/util.go#L42-L47 |
157,094 | kelseyhightower/confd | util/util.go | IsConfigChanged | func IsConfigChanged(src, dest string) (bool, error) {
if !IsFileExist(dest) {
return true, nil
}
d, err := FileStat(dest)
if err != nil {
return true, err
}
s, err := FileStat(src)
if err != nil {
return true, err
}
if d.Uid != s.Uid {
log.Info(fmt.Sprintf("%s has UID %d should be %d", dest, d.Uid, s.Uid))
}
if d.Gid != s.Gid {
log.Info(fmt.Sprintf("%s has GID %d should be %d", dest, d.Gid, s.Gid))
}
if d.Mode != s.Mode {
log.Info(fmt.Sprintf("%s has mode %s should be %s", dest, os.FileMode(d.Mode), os.FileMode(s.Mode)))
}
if d.Md5 != s.Md5 {
log.Info(fmt.Sprintf("%s has md5sum %s should be %s", dest, d.Md5, s.Md5))
}
if d.Uid != s.Uid || d.Gid != s.Gid || d.Mode != s.Mode || d.Md5 != s.Md5 {
return true, nil
}
return false, nil
} | go | func IsConfigChanged(src, dest string) (bool, error) {
if !IsFileExist(dest) {
return true, nil
}
d, err := FileStat(dest)
if err != nil {
return true, err
}
s, err := FileStat(src)
if err != nil {
return true, err
}
if d.Uid != s.Uid {
log.Info(fmt.Sprintf("%s has UID %d should be %d", dest, d.Uid, s.Uid))
}
if d.Gid != s.Gid {
log.Info(fmt.Sprintf("%s has GID %d should be %d", dest, d.Gid, s.Gid))
}
if d.Mode != s.Mode {
log.Info(fmt.Sprintf("%s has mode %s should be %s", dest, os.FileMode(d.Mode), os.FileMode(s.Mode)))
}
if d.Md5 != s.Md5 {
log.Info(fmt.Sprintf("%s has md5sum %s should be %s", dest, d.Md5, s.Md5))
}
if d.Uid != s.Uid || d.Gid != s.Gid || d.Mode != s.Mode || d.Md5 != s.Md5 {
return true, nil
}
return false, nil
} | [
"func",
"IsConfigChanged",
"(",
"src",
",",
"dest",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"!",
"IsFileExist",
"(",
"dest",
")",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"d",
",",
"err",
":=",
"FileStat",
"(",
"dest",
... | // IsConfigChanged reports whether src and dest config files are equal.
// Two config files are equal when they have the same file contents and
// Unix permissions. The owner, group, and mode must match.
// It return false in other cases. | [
"IsConfigChanged",
"reports",
"whether",
"src",
"and",
"dest",
"config",
"files",
"are",
"equal",
".",
"Two",
"config",
"files",
"are",
"equal",
"when",
"they",
"have",
"the",
"same",
"file",
"contents",
"and",
"Unix",
"permissions",
".",
"The",
"owner",
"gr... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/util/util.go#L53-L81 |
157,095 | kelseyhightower/confd | backends/dynamodb/client.go | GetValues | func (c *Client) GetValues(keys []string) (map[string]string, error) {
vars := make(map[string]string)
for _, key := range keys {
// Check if we can find the single item
m := make(map[string]*dynamodb.AttributeValue)
m["key"] = &dynamodb.AttributeValue{S: aws.String(key)}
g, err := c.client.GetItem(&dynamodb.GetItemInput{Key: m, TableName: &c.table})
if err != nil {
return vars, err
}
if g.Item != nil {
if val, ok := g.Item["value"]; ok {
if val.S != nil {
vars[key] = *val.S
} else {
log.Warning("Skipping key '%s'. 'value' is not of type 'string'.", key)
}
continue
}
}
// Check for nested keys
q, err := c.client.Scan(
&dynamodb.ScanInput{
ScanFilter: map[string]*dynamodb.Condition{
"key": &dynamodb.Condition{
AttributeValueList: []*dynamodb.AttributeValue{
&dynamodb.AttributeValue{S: aws.String(key)}},
ComparisonOperator: aws.String("BEGINS_WITH")}},
AttributesToGet: []*string{aws.String("key"), aws.String("value")},
TableName: aws.String(c.table),
Select: aws.String("SPECIFIC_ATTRIBUTES"),
})
if err != nil {
return vars, err
}
for _, i := range q.Items {
item := i
if val, ok := item["value"]; ok {
if val.S != nil {
vars[*item["key"].S] = *val.S
} else {
log.Warning("Skipping key '%s'. 'value' is not of type 'string'.", *item["key"].S)
}
continue
}
}
}
return vars, nil
} | go | func (c *Client) GetValues(keys []string) (map[string]string, error) {
vars := make(map[string]string)
for _, key := range keys {
// Check if we can find the single item
m := make(map[string]*dynamodb.AttributeValue)
m["key"] = &dynamodb.AttributeValue{S: aws.String(key)}
g, err := c.client.GetItem(&dynamodb.GetItemInput{Key: m, TableName: &c.table})
if err != nil {
return vars, err
}
if g.Item != nil {
if val, ok := g.Item["value"]; ok {
if val.S != nil {
vars[key] = *val.S
} else {
log.Warning("Skipping key '%s'. 'value' is not of type 'string'.", key)
}
continue
}
}
// Check for nested keys
q, err := c.client.Scan(
&dynamodb.ScanInput{
ScanFilter: map[string]*dynamodb.Condition{
"key": &dynamodb.Condition{
AttributeValueList: []*dynamodb.AttributeValue{
&dynamodb.AttributeValue{S: aws.String(key)}},
ComparisonOperator: aws.String("BEGINS_WITH")}},
AttributesToGet: []*string{aws.String("key"), aws.String("value")},
TableName: aws.String(c.table),
Select: aws.String("SPECIFIC_ATTRIBUTES"),
})
if err != nil {
return vars, err
}
for _, i := range q.Items {
item := i
if val, ok := item["value"]; ok {
if val.S != nil {
vars[*item["key"].S] = *val.S
} else {
log.Warning("Skipping key '%s'. 'value' is not of type 'string'.", *item["key"].S)
}
continue
}
}
}
return vars, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetValues",
"(",
"keys",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"vars",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",... | // GetValues retrieves the values for the given keys from DynamoDB | [
"GetValues",
"retrieves",
"the",
"values",
"for",
"the",
"given",
"keys",
"from",
"DynamoDB"
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/backends/dynamodb/client.go#L53-L105 |
157,096 | kelseyhightower/confd | backends/redis/client.go | tryConnect | func tryConnect(machines []string, password string, timeout bool) (redis.Conn, int, error) {
var err error
for _, address := range machines {
var conn redis.Conn
var db int
idx := strings.Index(address, "/")
if idx != -1 {
// a database is provided
db, err = strconv.Atoi(address[idx+1:])
if err == nil {
address = address[:idx]
}
}
network := "tcp"
if _, err = os.Stat(address); err == nil {
network = "unix"
}
log.Debug(fmt.Sprintf("Trying to connect to redis node %s", address))
var dialops []redis.DialOption
if timeout {
dialops = []redis.DialOption{
redis.DialConnectTimeout(time.Second),
redis.DialReadTimeout(time.Second),
redis.DialWriteTimeout(time.Second),
redis.DialDatabase(db),
}
} else {
dialops = []redis.DialOption{
redis.DialConnectTimeout(time.Second),
redis.DialWriteTimeout(time.Second),
redis.DialDatabase(db),
}
}
if password != "" {
dialops = append(dialops, redis.DialPassword(password))
}
conn, err = redis.Dial(network, address, dialops...)
if err != nil {
continue
}
return conn, db, nil
}
return nil, 0, err
} | go | func tryConnect(machines []string, password string, timeout bool) (redis.Conn, int, error) {
var err error
for _, address := range machines {
var conn redis.Conn
var db int
idx := strings.Index(address, "/")
if idx != -1 {
// a database is provided
db, err = strconv.Atoi(address[idx+1:])
if err == nil {
address = address[:idx]
}
}
network := "tcp"
if _, err = os.Stat(address); err == nil {
network = "unix"
}
log.Debug(fmt.Sprintf("Trying to connect to redis node %s", address))
var dialops []redis.DialOption
if timeout {
dialops = []redis.DialOption{
redis.DialConnectTimeout(time.Second),
redis.DialReadTimeout(time.Second),
redis.DialWriteTimeout(time.Second),
redis.DialDatabase(db),
}
} else {
dialops = []redis.DialOption{
redis.DialConnectTimeout(time.Second),
redis.DialWriteTimeout(time.Second),
redis.DialDatabase(db),
}
}
if password != "" {
dialops = append(dialops, redis.DialPassword(password))
}
conn, err = redis.Dial(network, address, dialops...)
if err != nil {
continue
}
return conn, db, nil
}
return nil, 0, err
} | [
"func",
"tryConnect",
"(",
"machines",
"[",
"]",
"string",
",",
"password",
"string",
",",
"timeout",
"bool",
")",
"(",
"redis",
".",
"Conn",
",",
"int",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"for",
"_",
",",
"address",
":=",
"range",
... | // Iterate through `machines`, trying to connect to each in turn.
// Returns the first successful connection or the last error encountered.
// Assumes that `machines` is non-empty. | [
"Iterate",
"through",
"machines",
"trying",
"to",
"connect",
"to",
"each",
"in",
"turn",
".",
"Returns",
"the",
"first",
"successful",
"connection",
"or",
"the",
"last",
"error",
"encountered",
".",
"Assumes",
"that",
"machines",
"is",
"non",
"-",
"empty",
"... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/backends/redis/client.go#L33-L82 |
157,097 | kelseyhightower/confd | backends/redis/client.go | connectedClient | func (c *Client) connectedClient() (redis.Conn, error) {
if c.client != nil {
log.Debug("Testing existing redis connection.")
resp, err := c.client.Do("PING")
if (err != nil && err == redis.ErrNil) || resp != "PONG" {
log.Error(fmt.Sprintf("Existing redis connection no longer usable. "+
"Will try to re-establish. Error: %s", err.Error()))
c.client = nil
}
}
// Existing client could have been deleted by previous block
if c.client == nil {
var err error
c.client, _, err = tryConnect(c.machines, c.password, true)
if err != nil {
return nil, err
}
}
return c.client, nil
} | go | func (c *Client) connectedClient() (redis.Conn, error) {
if c.client != nil {
log.Debug("Testing existing redis connection.")
resp, err := c.client.Do("PING")
if (err != nil && err == redis.ErrNil) || resp != "PONG" {
log.Error(fmt.Sprintf("Existing redis connection no longer usable. "+
"Will try to re-establish. Error: %s", err.Error()))
c.client = nil
}
}
// Existing client could have been deleted by previous block
if c.client == nil {
var err error
c.client, _, err = tryConnect(c.machines, c.password, true)
if err != nil {
return nil, err
}
}
return c.client, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"connectedClient",
"(",
")",
"(",
"redis",
".",
"Conn",
",",
"error",
")",
"{",
"if",
"c",
".",
"client",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"resp",
",",
"err",
":=",
"c",
... | // Retrieves a connected redis client from the client wrapper.
// Existing connections will be tested with a PING command before being returned. Tries to reconnect once if necessary.
// Returns the established redis connection or the error encountered. | [
"Retrieves",
"a",
"connected",
"redis",
"client",
"from",
"the",
"client",
"wrapper",
".",
"Existing",
"connections",
"will",
"be",
"tested",
"with",
"a",
"PING",
"command",
"before",
"being",
"returned",
".",
"Tries",
"to",
"reconnect",
"once",
"if",
"necessa... | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/backends/redis/client.go#L87-L109 |
157,098 | kelseyhightower/confd | log/log.go | SetLevel | func SetLevel(level string) {
lvl, err := log.ParseLevel(level)
if err != nil {
Fatal(fmt.Sprintf(`not a valid level: "%s"`, level))
}
log.SetLevel(lvl)
} | go | func SetLevel(level string) {
lvl, err := log.ParseLevel(level)
if err != nil {
Fatal(fmt.Sprintf(`not a valid level: "%s"`, level))
}
log.SetLevel(lvl)
} | [
"func",
"SetLevel",
"(",
"level",
"string",
")",
"{",
"lvl",
",",
"err",
":=",
"log",
".",
"ParseLevel",
"(",
"level",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"Fatal",
"(",
"fmt",
".",
"Sprintf",
"(",
"`not a valid level: \"%s\"`",
",",
"level",
")",... | // SetLevel sets the log level. Valid levels are panic, fatal, error, warn, info and debug. | [
"SetLevel",
"sets",
"the",
"log",
"level",
".",
"Valid",
"levels",
"are",
"panic",
"fatal",
"error",
"warn",
"info",
"and",
"debug",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/log/log.go#L43-L49 |
157,099 | kelseyhightower/confd | log/log.go | Debug | func Debug(format string, v ...interface{}) {
log.Debug(fmt.Sprintf(format, v...))
} | go | func Debug(format string, v ...interface{}) {
log.Debug(fmt.Sprintf(format, v...))
} | [
"func",
"Debug",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"log",
".",
"Debug",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"v",
"...",
")",
")",
"\n",
"}"
] | // Debug logs a message with severity DEBUG. | [
"Debug",
"logs",
"a",
"message",
"with",
"severity",
"DEBUG",
"."
] | cccd334562329858feac719ad94b75aa87968a99 | https://github.com/kelseyhightower/confd/blob/cccd334562329858feac719ad94b75aa87968a99/log/log.go#L52-L54 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.