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
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
2,600
BurntSushi/xgbutil
xprop/xprop.go
ChangeProp
func ChangeProp(xu *xgbutil.XUtil, win xproto.Window, format byte, prop string, typ string, data []byte) error { propAtom, err := Atm(xu, prop) if err != nil { return err } typAtom, err := Atm(xu, typ) if err != nil { return err } return xproto.ChangePropertyChecked(xu.Conn(), xproto.PropModeReplace, win, propAtom, typAtom, format, uint32(len(data)/(int(format)/8)), data).Check() }
go
func ChangeProp(xu *xgbutil.XUtil, win xproto.Window, format byte, prop string, typ string, data []byte) error { propAtom, err := Atm(xu, prop) if err != nil { return err } typAtom, err := Atm(xu, typ) if err != nil { return err } return xproto.ChangePropertyChecked(xu.Conn(), xproto.PropModeReplace, win, propAtom, typAtom, format, uint32(len(data)/(int(format)/8)), data).Check() }
[ "func", "ChangeProp", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "win", "xproto", ".", "Window", ",", "format", "byte", ",", "prop", "string", ",", "typ", "string", ",", "data", "[", "]", "byte", ")", "error", "{", "propAtom", ",", "err", ":=", "Atm", "(", "xu", ",", "prop", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "typAtom", ",", "err", ":=", "Atm", "(", "xu", ",", "typ", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "xproto", ".", "ChangePropertyChecked", "(", "xu", ".", "Conn", "(", ")", ",", "xproto", ".", "PropModeReplace", ",", "win", ",", "propAtom", ",", "typAtom", ",", "format", ",", "uint32", "(", "len", "(", "data", ")", "/", "(", "int", "(", "format", ")", "/", "8", ")", ")", ",", "data", ")", ".", "Check", "(", ")", "\n", "}" ]
// ChangeProperty abstracts the semi-nastiness of xgb.ChangeProperty.
[ "ChangeProperty", "abstracts", "the", "semi", "-", "nastiness", "of", "xgb", ".", "ChangeProperty", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L38-L54
2,601
BurntSushi/xgbutil
xprop/xprop.go
ChangeProp32
func ChangeProp32(xu *xgbutil.XUtil, win xproto.Window, prop string, typ string, data ...uint) error { buf := make([]byte, len(data)*4) for i, datum := range data { xgb.Put32(buf[(i*4):], uint32(datum)) } return ChangeProp(xu, win, 32, prop, typ, buf) }
go
func ChangeProp32(xu *xgbutil.XUtil, win xproto.Window, prop string, typ string, data ...uint) error { buf := make([]byte, len(data)*4) for i, datum := range data { xgb.Put32(buf[(i*4):], uint32(datum)) } return ChangeProp(xu, win, 32, prop, typ, buf) }
[ "func", "ChangeProp32", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "win", "xproto", ".", "Window", ",", "prop", "string", ",", "typ", "string", ",", "data", "...", "uint", ")", "error", "{", "buf", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "data", ")", "*", "4", ")", "\n", "for", "i", ",", "datum", ":=", "range", "data", "{", "xgb", ".", "Put32", "(", "buf", "[", "(", "i", "*", "4", ")", ":", "]", ",", "uint32", "(", "datum", ")", ")", "\n", "}", "\n\n", "return", "ChangeProp", "(", "xu", ",", "win", ",", "32", ",", "prop", ",", "typ", ",", "buf", ")", "\n", "}" ]
// ChangeProperty32 makes changing 32 bit formatted properties easier // by constructing the raw X data for you.
[ "ChangeProperty32", "makes", "changing", "32", "bit", "formatted", "properties", "easier", "by", "constructing", "the", "raw", "X", "data", "for", "you", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L58-L67
2,602
BurntSushi/xgbutil
xprop/xprop.go
PropValAtom
func PropValAtom(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply, err error) (string, error) { if err != nil { return "", err } if reply.Format != 32 { return "", fmt.Errorf("PropValAtom: Expected format 32 but got %d", reply.Format) } return AtomName(xu, xproto.Atom(xgb.Get32(reply.Value))) }
go
func PropValAtom(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply, err error) (string, error) { if err != nil { return "", err } if reply.Format != 32 { return "", fmt.Errorf("PropValAtom: Expected format 32 but got %d", reply.Format) } return AtomName(xu, xproto.Atom(xgb.Get32(reply.Value))) }
[ "func", "PropValAtom", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "string", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "32", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n\n", "return", "AtomName", "(", "xu", ",", "xproto", ".", "Atom", "(", "xgb", ".", "Get32", "(", "reply", ".", "Value", ")", ")", ")", "\n", "}" ]
// PropValAtom transforms a GetPropertyReply struct into an ATOM name. // The property reply must be in 32 bit format.
[ "PropValAtom", "transforms", "a", "GetPropertyReply", "struct", "into", "an", "ATOM", "name", ".", "The", "property", "reply", "must", "be", "in", "32", "bit", "format", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L107-L119
2,603
BurntSushi/xgbutil
xprop/xprop.go
PropValAtoms
func PropValAtoms(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply, err error) ([]string, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValAtoms: Expected format 32 but got %d", reply.Format) } ids := make([]string, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { ids[i], err = AtomName(xu, xproto.Atom(xgb.Get32(vals))) if err != nil { return nil, err } vals = vals[4:] } return ids, nil }
go
func PropValAtoms(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply, err error) ([]string, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValAtoms: Expected format 32 but got %d", reply.Format) } ids := make([]string, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { ids[i], err = AtomName(xu, xproto.Atom(xgb.Get32(vals))) if err != nil { return nil, err } vals = vals[4:] } return ids, nil }
[ "func", "PropValAtoms", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "32", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n\n", "ids", ":=", "make", "(", "[", "]", "string", ",", "reply", ".", "ValueLen", ")", "\n", "vals", ":=", "reply", ".", "Value", "\n", "for", "i", ":=", "0", ";", "len", "(", "vals", ")", ">=", "4", ";", "i", "++", "{", "ids", "[", "i", "]", ",", "err", "=", "AtomName", "(", "xu", ",", "xproto", ".", "Atom", "(", "xgb", ".", "Get32", "(", "vals", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "vals", "=", "vals", "[", "4", ":", "]", "\n", "}", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// PropValAtoms is the same as PropValAtom, except that it returns a slice // of atom names. Also must be 32 bit format. // This is a method of an XUtil struct, unlike the other 'PropVal...' functions.
[ "PropValAtoms", "is", "the", "same", "as", "PropValAtom", "except", "that", "it", "returns", "a", "slice", "of", "atom", "names", ".", "Also", "must", "be", "32", "bit", "format", ".", "This", "is", "a", "method", "of", "an", "XUtil", "struct", "unlike", "the", "other", "PropVal", "...", "functions", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L124-L146
2,604
BurntSushi/xgbutil
xprop/xprop.go
PropValWindow
func PropValWindow(reply *xproto.GetPropertyReply, err error) (xproto.Window, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValId: Expected format 32 but got %d", reply.Format) } return xproto.Window(xgb.Get32(reply.Value)), nil }
go
func PropValWindow(reply *xproto.GetPropertyReply, err error) (xproto.Window, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValId: Expected format 32 but got %d", reply.Format) } return xproto.Window(xgb.Get32(reply.Value)), nil }
[ "func", "PropValWindow", "(", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "xproto", ".", "Window", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "32", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n", "return", "xproto", ".", "Window", "(", "xgb", ".", "Get32", "(", "reply", ".", "Value", ")", ")", ",", "nil", "\n", "}" ]
// PropValWindow transforms a GetPropertyReply struct into an X resource // window identifier. // The property reply must be in 32 bit format.
[ "PropValWindow", "transforms", "a", "GetPropertyReply", "struct", "into", "an", "X", "resource", "window", "identifier", ".", "The", "property", "reply", "must", "be", "in", "32", "bit", "format", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L151-L162
2,605
BurntSushi/xgbutil
xprop/xprop.go
PropValWindows
func PropValWindows(reply *xproto.GetPropertyReply, err error) ([]xproto.Window, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d", reply.Format) } ids := make([]xproto.Window, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { ids[i] = xproto.Window(xgb.Get32(vals)) vals = vals[4:] } return ids, nil }
go
func PropValWindows(reply *xproto.GetPropertyReply, err error) ([]xproto.Window, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d", reply.Format) } ids := make([]xproto.Window, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { ids[i] = xproto.Window(xgb.Get32(vals)) vals = vals[4:] } return ids, nil }
[ "func", "PropValWindows", "(", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "[", "]", "xproto", ".", "Window", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "32", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n\n", "ids", ":=", "make", "(", "[", "]", "xproto", ".", "Window", ",", "reply", ".", "ValueLen", ")", "\n", "vals", ":=", "reply", ".", "Value", "\n", "for", "i", ":=", "0", ";", "len", "(", "vals", ")", ">=", "4", ";", "i", "++", "{", "ids", "[", "i", "]", "=", "xproto", ".", "Window", "(", "xgb", ".", "Get32", "(", "vals", ")", ")", "\n", "vals", "=", "vals", "[", "4", ":", "]", "\n", "}", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// PropValWindows is the same as PropValWindow, except that it returns a slice // of identifiers. Also must be 32 bit format.
[ "PropValWindows", "is", "the", "same", "as", "PropValWindow", "except", "that", "it", "returns", "a", "slice", "of", "identifiers", ".", "Also", "must", "be", "32", "bit", "format", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L166-L184
2,606
BurntSushi/xgbutil
xprop/xprop.go
PropValNum
func PropValNum(reply *xproto.GetPropertyReply, err error) (uint, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValNum: Expected format 32 but got %d", reply.Format) } return uint(xgb.Get32(reply.Value)), nil }
go
func PropValNum(reply *xproto.GetPropertyReply, err error) (uint, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValNum: Expected format 32 but got %d", reply.Format) } return uint(xgb.Get32(reply.Value)), nil }
[ "func", "PropValNum", "(", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "uint", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "32", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n", "return", "uint", "(", "xgb", ".", "Get32", "(", "reply", ".", "Value", ")", ")", ",", "nil", "\n", "}" ]
// PropValNum transforms a GetPropertyReply struct into an unsigned // integer. Useful when the property value is a single integer.
[ "PropValNum", "transforms", "a", "GetPropertyReply", "struct", "into", "an", "unsigned", "integer", ".", "Useful", "when", "the", "property", "value", "is", "a", "single", "integer", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L188-L197
2,607
BurntSushi/xgbutil
xprop/xprop.go
PropValNums
func PropValNums(reply *xproto.GetPropertyReply, err error) ([]uint, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d", reply.Format) } nums := make([]uint, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { nums[i] = uint(xgb.Get32(vals)) vals = vals[4:] } return nums, nil }
go
func PropValNums(reply *xproto.GetPropertyReply, err error) ([]uint, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d", reply.Format) } nums := make([]uint, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { nums[i] = uint(xgb.Get32(vals)) vals = vals[4:] } return nums, nil }
[ "func", "PropValNums", "(", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "[", "]", "uint", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "32", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n\n", "nums", ":=", "make", "(", "[", "]", "uint", ",", "reply", ".", "ValueLen", ")", "\n", "vals", ":=", "reply", ".", "Value", "\n", "for", "i", ":=", "0", ";", "len", "(", "vals", ")", ">=", "4", ";", "i", "++", "{", "nums", "[", "i", "]", "=", "uint", "(", "xgb", ".", "Get32", "(", "vals", ")", ")", "\n", "vals", "=", "vals", "[", "4", ":", "]", "\n", "}", "\n", "return", "nums", ",", "nil", "\n", "}" ]
// PropValNums is the same as PropValNum, except that it returns a slice // of integers. Also must be 32 bit format.
[ "PropValNums", "is", "the", "same", "as", "PropValNum", "except", "that", "it", "returns", "a", "slice", "of", "integers", ".", "Also", "must", "be", "32", "bit", "format", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L201-L217
2,608
BurntSushi/xgbutil
xprop/xprop.go
PropValNum64
func PropValNum64(reply *xproto.GetPropertyReply, err error) (int64, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValNum: Expected format 32 but got %d", reply.Format) } return int64(xgb.Get32(reply.Value)), nil }
go
func PropValNum64(reply *xproto.GetPropertyReply, err error) (int64, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValNum: Expected format 32 but got %d", reply.Format) } return int64(xgb.Get32(reply.Value)), nil }
[ "func", "PropValNum64", "(", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "int64", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "32", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n", "return", "int64", "(", "xgb", ".", "Get32", "(", "reply", ".", "Value", ")", ")", ",", "nil", "\n", "}" ]
// PropValNum64 transforms a GetPropertyReply struct into a 64 bit // integer. Useful when the property value is a single integer.
[ "PropValNum64", "transforms", "a", "GetPropertyReply", "struct", "into", "a", "64", "bit", "integer", ".", "Useful", "when", "the", "property", "value", "is", "a", "single", "integer", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L221-L230
2,609
BurntSushi/xgbutil
xprop/xprop.go
PropValStr
func PropValStr(reply *xproto.GetPropertyReply, err error) (string, error) { if err != nil { return "", err } if reply.Format != 8 { return "", fmt.Errorf("PropValStr: Expected format 8 but got %d", reply.Format) } return string(reply.Value), nil }
go
func PropValStr(reply *xproto.GetPropertyReply, err error) (string, error) { if err != nil { return "", err } if reply.Format != 8 { return "", fmt.Errorf("PropValStr: Expected format 8 but got %d", reply.Format) } return string(reply.Value), nil }
[ "func", "PropValStr", "(", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "string", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "8", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n", "return", "string", "(", "reply", ".", "Value", ")", ",", "nil", "\n", "}" ]
// PropValStr transforms a GetPropertyReply struct into a string. // Useful when the property value is a null terminated string represented // by integers. Also must be 8 bit format.
[ "PropValStr", "transforms", "a", "GetPropertyReply", "struct", "into", "a", "string", ".", "Useful", "when", "the", "property", "value", "is", "a", "null", "terminated", "string", "represented", "by", "integers", ".", "Also", "must", "be", "8", "bit", "format", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L235-L244
2,610
BurntSushi/xgbutil
xprop/xprop.go
PropValStrs
func PropValStrs(reply *xproto.GetPropertyReply, err error) ([]string, error) { if err != nil { return nil, err } if reply.Format != 8 { return nil, fmt.Errorf("PropValStrs: Expected format 8 but got %d", reply.Format) } var strs []string sstart := 0 for i, c := range reply.Value { if c == 0 { strs = append(strs, string(reply.Value[sstart:i])) sstart = i + 1 } } if sstart < int(reply.ValueLen) { strs = append(strs, string(reply.Value[sstart:])) } return strs, nil }
go
func PropValStrs(reply *xproto.GetPropertyReply, err error) ([]string, error) { if err != nil { return nil, err } if reply.Format != 8 { return nil, fmt.Errorf("PropValStrs: Expected format 8 but got %d", reply.Format) } var strs []string sstart := 0 for i, c := range reply.Value { if c == 0 { strs = append(strs, string(reply.Value[sstart:i])) sstart = i + 1 } } if sstart < int(reply.ValueLen) { strs = append(strs, string(reply.Value[sstart:])) } return strs, nil }
[ "func", "PropValStrs", "(", "reply", "*", "xproto", ".", "GetPropertyReply", ",", "err", "error", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "reply", ".", "Format", "!=", "8", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reply", ".", "Format", ")", "\n", "}", "\n\n", "var", "strs", "[", "]", "string", "\n", "sstart", ":=", "0", "\n", "for", "i", ",", "c", ":=", "range", "reply", ".", "Value", "{", "if", "c", "==", "0", "{", "strs", "=", "append", "(", "strs", ",", "string", "(", "reply", ".", "Value", "[", "sstart", ":", "i", "]", ")", ")", "\n", "sstart", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "if", "sstart", "<", "int", "(", "reply", ".", "ValueLen", ")", "{", "strs", "=", "append", "(", "strs", ",", "string", "(", "reply", ".", "Value", "[", "sstart", ":", "]", ")", ")", "\n", "}", "\n", "return", "strs", ",", "nil", "\n", "}" ]
// PropValStrs is the same as PropValStr, except that it returns a slice // of strings. The raw byte string is a sequence of null terminated strings, // which is translated into a slice of strings.
[ "PropValStrs", "is", "the", "same", "as", "PropValStr", "except", "that", "it", "returns", "a", "slice", "of", "strings", ".", "The", "raw", "byte", "string", "is", "a", "sequence", "of", "null", "terminated", "strings", "which", "is", "translated", "into", "a", "slice", "of", "strings", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xprop/xprop.go#L249-L270
2,611
BurntSushi/xgbutil
xrect/xrect.go
RectPieces
func RectPieces(xr Rect) (int, int, int, int) { return xr.X(), xr.Y(), xr.Width(), xr.Height() }
go
func RectPieces(xr Rect) (int, int, int, int) { return xr.X(), xr.Y(), xr.Width(), xr.Height() }
[ "func", "RectPieces", "(", "xr", "Rect", ")", "(", "int", ",", "int", ",", "int", ",", "int", ")", "{", "return", "xr", ".", "X", "(", ")", ",", "xr", ".", "Y", "(", ")", ",", "xr", ".", "Width", "(", ")", ",", "xr", ".", "Height", "(", ")", "\n", "}" ]
// RectPieces just returns a four-tuple of x, y, width and height
[ "RectPieces", "just", "returns", "a", "four", "-", "tuple", "of", "x", "y", "width", "and", "height" ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xrect/xrect.go#L19-L21
2,612
BurntSushi/xgbutil
xrect/xrect.go
New
func New(x, y, w, h int) *XRect { return &XRect{x, y, w, h} }
go
func New(x, y, w, h int) *XRect { return &XRect{x, y, w, h} }
[ "func", "New", "(", "x", ",", "y", ",", "w", ",", "h", "int", ")", "*", "XRect", "{", "return", "&", "XRect", "{", "x", ",", "y", ",", "w", ",", "h", "}", "\n", "}" ]
// Provide the ability to construct an XRect.
[ "Provide", "the", "ability", "to", "construct", "an", "XRect", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xrect/xrect.go#L34-L36
2,613
BurntSushi/xgbutil
xrect/xrect.go
Pieces
func (r *XRect) Pieces() (int, int, int, int) { return r.X(), r.Y(), r.Width(), r.Height() }
go
func (r *XRect) Pieces() (int, int, int, int) { return r.X(), r.Y(), r.Width(), r.Height() }
[ "func", "(", "r", "*", "XRect", ")", "Pieces", "(", ")", "(", "int", ",", "int", ",", "int", ",", "int", ")", "{", "return", "r", ".", "X", "(", ")", ",", "r", ".", "Y", "(", ")", ",", "r", ".", "Width", "(", ")", ",", "r", ".", "Height", "(", ")", "\n", "}" ]
// Pieces just returns a four-tuple of x, y, width and height
[ "Pieces", "just", "returns", "a", "four", "-", "tuple", "of", "x", "y", "width", "and", "height" ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xrect/xrect.go#L76-L78
2,614
BurntSushi/xgbutil
xrect/xrect.go
Subtract
func Subtract(r1 Rect, r2 Rect) []Rect { r1x1, r1y1, r1w, r1h := r1.Pieces() r2x1, r2y1, r2w, r2h := r2.Pieces() r1x2, r1y2 := r1x1+r1w, r1y1+r1h r2x2, r2y2 := r2x1+r2w, r2y1+r2h // No intersection; return r1. if r2x1 >= r1x2 || r1x1 >= r2x2 || r2y1 >= r1y2 || r1y1 >= r2y2 { return []Rect{New(r1x1, r1y1, r1w, r1h)} } // r2 covers r1; so subtraction yields no rectangles. if r1x1 >= r2x1 && r1y1 >= r2y1 && r1x2 <= r2x2 && r1y2 <= r2y2 { return []Rect{} } // Now generate each of the four possible rectangles and add them only // if they are valid (i.e., width/height >= 1) result := make([]Rect, 0, 4) rect1 := New(r1x1, r1y1, r1w, r2y1-r1y1) rect2 := New(r1x1, r1y1, r2x1-r1x1, r1h) rect3 := New(r1x1, r2y2, r1w, r1h-((r2y1-r1y1)+r2h)) rect4 := New(r2x2, r1y1, r1w-((r2x1-r1x1)+r2w), r1h) if Valid(rect1) { result = append(result, rect1) } if Valid(rect2) { result = append(result, rect2) } if Valid(rect3) { result = append(result, rect3) } if Valid(rect4) { result = append(result, rect4) } return result }
go
func Subtract(r1 Rect, r2 Rect) []Rect { r1x1, r1y1, r1w, r1h := r1.Pieces() r2x1, r2y1, r2w, r2h := r2.Pieces() r1x2, r1y2 := r1x1+r1w, r1y1+r1h r2x2, r2y2 := r2x1+r2w, r2y1+r2h // No intersection; return r1. if r2x1 >= r1x2 || r1x1 >= r2x2 || r2y1 >= r1y2 || r1y1 >= r2y2 { return []Rect{New(r1x1, r1y1, r1w, r1h)} } // r2 covers r1; so subtraction yields no rectangles. if r1x1 >= r2x1 && r1y1 >= r2y1 && r1x2 <= r2x2 && r1y2 <= r2y2 { return []Rect{} } // Now generate each of the four possible rectangles and add them only // if they are valid (i.e., width/height >= 1) result := make([]Rect, 0, 4) rect1 := New(r1x1, r1y1, r1w, r2y1-r1y1) rect2 := New(r1x1, r1y1, r2x1-r1x1, r1h) rect3 := New(r1x1, r2y2, r1w, r1h-((r2y1-r1y1)+r2h)) rect4 := New(r2x2, r1y1, r1w-((r2x1-r1x1)+r2w), r1h) if Valid(rect1) { result = append(result, rect1) } if Valid(rect2) { result = append(result, rect2) } if Valid(rect3) { result = append(result, rect3) } if Valid(rect4) { result = append(result, rect4) } return result }
[ "func", "Subtract", "(", "r1", "Rect", ",", "r2", "Rect", ")", "[", "]", "Rect", "{", "r1x1", ",", "r1y1", ",", "r1w", ",", "r1h", ":=", "r1", ".", "Pieces", "(", ")", "\n", "r2x1", ",", "r2y1", ",", "r2w", ",", "r2h", ":=", "r2", ".", "Pieces", "(", ")", "\n\n", "r1x2", ",", "r1y2", ":=", "r1x1", "+", "r1w", ",", "r1y1", "+", "r1h", "\n", "r2x2", ",", "r2y2", ":=", "r2x1", "+", "r2w", ",", "r2y1", "+", "r2h", "\n\n", "// No intersection; return r1.", "if", "r2x1", ">=", "r1x2", "||", "r1x1", ">=", "r2x2", "||", "r2y1", ">=", "r1y2", "||", "r1y1", ">=", "r2y2", "{", "return", "[", "]", "Rect", "{", "New", "(", "r1x1", ",", "r1y1", ",", "r1w", ",", "r1h", ")", "}", "\n", "}", "\n\n", "// r2 covers r1; so subtraction yields no rectangles.", "if", "r1x1", ">=", "r2x1", "&&", "r1y1", ">=", "r2y1", "&&", "r1x2", "<=", "r2x2", "&&", "r1y2", "<=", "r2y2", "{", "return", "[", "]", "Rect", "{", "}", "\n", "}", "\n\n", "// Now generate each of the four possible rectangles and add them only", "// if they are valid (i.e., width/height >= 1)", "result", ":=", "make", "(", "[", "]", "Rect", ",", "0", ",", "4", ")", "\n\n", "rect1", ":=", "New", "(", "r1x1", ",", "r1y1", ",", "r1w", ",", "r2y1", "-", "r1y1", ")", "\n", "rect2", ":=", "New", "(", "r1x1", ",", "r1y1", ",", "r2x1", "-", "r1x1", ",", "r1h", ")", "\n", "rect3", ":=", "New", "(", "r1x1", ",", "r2y2", ",", "r1w", ",", "r1h", "-", "(", "(", "r2y1", "-", "r1y1", ")", "+", "r2h", ")", ")", "\n", "rect4", ":=", "New", "(", "r2x2", ",", "r1y1", ",", "r1w", "-", "(", "(", "r2x1", "-", "r1x1", ")", "+", "r2w", ")", ",", "r1h", ")", "\n\n", "if", "Valid", "(", "rect1", ")", "{", "result", "=", "append", "(", "result", ",", "rect1", ")", "\n", "}", "\n", "if", "Valid", "(", "rect2", ")", "{", "result", "=", "append", "(", "result", ",", "rect2", ")", "\n", "}", "\n", "if", "Valid", "(", "rect3", ")", "{", "result", "=", "append", "(", "result", ",", "rect3", ")", "\n", "}", "\n", "if", "Valid", "(", "rect4", ")", "{", "result", "=", "append", "(", "result", ",", "rect4", ")", "\n", "}", "\n\n", "return", "result", "\n", "}" ]
// Subtract subtracts r2 from r1 and returns the result as a // new slice of Rects. // Basically, rectangle subtraction works by cutting r2 out of r1, and returning // the resulting rectangles. // If r1 does not overlap r2, then only one rectangle is returned and is // equivalent to r1. // If r2 covers r1, then no rectangles are returned. // If r1 covers r2, then four rectangles are returned. // If r2 partially overlaps r1, then one, two or three rectangles are returned.
[ "Subtract", "subtracts", "r2", "from", "r1", "and", "returns", "the", "result", "as", "a", "new", "slice", "of", "Rects", ".", "Basically", "rectangle", "subtraction", "works", "by", "cutting", "r2", "out", "of", "r1", "and", "returning", "the", "resulting", "rectangles", ".", "If", "r1", "does", "not", "overlap", "r2", "then", "only", "one", "rectangle", "is", "returned", "and", "is", "equivalent", "to", "r1", ".", "If", "r2", "covers", "r1", "then", "no", "rectangles", "are", "returned", ".", "If", "r1", "covers", "r2", "then", "four", "rectangles", "are", "returned", ".", "If", "r2", "partially", "overlaps", "r1", "then", "one", "two", "or", "three", "rectangles", "are", "returned", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xrect/xrect.go#L95-L135
2,615
BurntSushi/xgbutil
xrect/xrect.go
IntersectArea
func IntersectArea(r1 Rect, r2 Rect) int { x1, y1, w1, h1 := RectPieces(r1) x2, y2, w2, h2 := RectPieces(r2) if x2 < x1+w1 && x2+w2 > x1 && y2 < y1+h1 && y2+h2 > y1 { iw := min(x1+w1-1, x2+w2-1) - max(x1, x2) + 1 ih := min(y1+h1-1, y2+h2-1) - max(y1, y2) + 1 return iw * ih } return 0 }
go
func IntersectArea(r1 Rect, r2 Rect) int { x1, y1, w1, h1 := RectPieces(r1) x2, y2, w2, h2 := RectPieces(r2) if x2 < x1+w1 && x2+w2 > x1 && y2 < y1+h1 && y2+h2 > y1 { iw := min(x1+w1-1, x2+w2-1) - max(x1, x2) + 1 ih := min(y1+h1-1, y2+h2-1) - max(y1, y2) + 1 return iw * ih } return 0 }
[ "func", "IntersectArea", "(", "r1", "Rect", ",", "r2", "Rect", ")", "int", "{", "x1", ",", "y1", ",", "w1", ",", "h1", ":=", "RectPieces", "(", "r1", ")", "\n", "x2", ",", "y2", ",", "w2", ",", "h2", ":=", "RectPieces", "(", "r2", ")", "\n", "if", "x2", "<", "x1", "+", "w1", "&&", "x2", "+", "w2", ">", "x1", "&&", "y2", "<", "y1", "+", "h1", "&&", "y2", "+", "h2", ">", "y1", "{", "iw", ":=", "min", "(", "x1", "+", "w1", "-", "1", ",", "x2", "+", "w2", "-", "1", ")", "-", "max", "(", "x1", ",", "x2", ")", "+", "1", "\n", "ih", ":=", "min", "(", "y1", "+", "h1", "-", "1", ",", "y2", "+", "h2", "-", "1", ")", "-", "max", "(", "y1", ",", "y2", ")", "+", "1", "\n", "return", "iw", "*", "ih", "\n", "}", "\n\n", "return", "0", "\n", "}" ]
// IntersectArea takes two rectangles satisfying the Rect interface and // returns the area of their intersection. If there is no intersection, return // 0 area.
[ "IntersectArea", "takes", "two", "rectangles", "satisfying", "the", "Rect", "interface", "and", "returns", "the", "area", "of", "their", "intersection", ".", "If", "there", "is", "no", "intersection", "return", "0", "area", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xrect/xrect.go#L140-L150
2,616
BurntSushi/xgbutil
xrect/xrect.go
xInRect
func xInRect(xtest uint, rect Rect) bool { x, _, w, _ := RectPieces(rect) return int(xtest) >= x && int(xtest) < (x+w) }
go
func xInRect(xtest uint, rect Rect) bool { x, _, w, _ := RectPieces(rect) return int(xtest) >= x && int(xtest) < (x+w) }
[ "func", "xInRect", "(", "xtest", "uint", ",", "rect", "Rect", ")", "bool", "{", "x", ",", "_", ",", "w", ",", "_", ":=", "RectPieces", "(", "rect", ")", "\n", "return", "int", "(", "xtest", ")", ">=", "x", "&&", "int", "(", "xtest", ")", "<", "(", "x", "+", "w", ")", "\n", "}" ]
// xInRect is whether a particular x-coordinate is vertically constrained by // a rectangle.
[ "xInRect", "is", "whether", "a", "particular", "x", "-", "coordinate", "is", "vertically", "constrained", "by", "a", "rectangle", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xrect/xrect.go#L258-L261
2,617
BurntSushi/xgbutil
xrect/xrect.go
yInRect
func yInRect(ytest uint, rect Rect) bool { _, y, _, h := RectPieces(rect) return int(ytest) >= y && int(ytest) < (y+h) }
go
func yInRect(ytest uint, rect Rect) bool { _, y, _, h := RectPieces(rect) return int(ytest) >= y && int(ytest) < (y+h) }
[ "func", "yInRect", "(", "ytest", "uint", ",", "rect", "Rect", ")", "bool", "{", "_", ",", "y", ",", "_", ",", "h", ":=", "RectPieces", "(", "rect", ")", "\n", "return", "int", "(", "ytest", ")", ">=", "y", "&&", "int", "(", "ytest", ")", "<", "(", "y", "+", "h", ")", "\n", "}" ]
// yInRect is whether a particular y-coordinate is horizontally constrained by // a rectangle.
[ "yInRect", "is", "whether", "a", "particular", "y", "-", "coordinate", "is", "horizontally", "constrained", "by", "a", "rectangle", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xrect/xrect.go#L265-L268
2,618
BurntSushi/xgbutil
_examples/multiple-source-event-loop/main.go
otherSource
func otherSource() chan int { c := make(chan int, 0) go func() { defer close(c) i := 1 for { c <- i i++ time.Sleep(time.Second) } }() return c }
go
func otherSource() chan int { c := make(chan int, 0) go func() { defer close(c) i := 1 for { c <- i i++ time.Sleep(time.Second) } }() return c }
[ "func", "otherSource", "(", ")", "chan", "int", "{", "c", ":=", "make", "(", "chan", "int", ",", "0", ")", "\n", "go", "func", "(", ")", "{", "defer", "close", "(", "c", ")", "\n\n", "i", ":=", "1", "\n", "for", "{", "c", "<-", "i", "\n", "i", "++", "\n", "time", ".", "Sleep", "(", "time", ".", "Second", ")", "\n", "}", "\n", "}", "(", ")", "\n", "return", "c", "\n", "}" ]
// otherSource serves as a placeholder from some other source of user input.
[ "otherSource", "serves", "as", "a", "placeholder", "from", "some", "other", "source", "of", "user", "input", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/_examples/multiple-source-event-loop/main.go#L21-L34
2,619
BurntSushi/xgbutil
_examples/pointer-painting/main.go
drawGopher
func drawGopher(canvas *xgraphics.Image, gopher image.Image, win *xwindow.Window, x, y int) { // Find the rectangle of the canvas where we're going to draw the gopher. gopherRect := midRect(x, y, gopherWidth, gopherHeight, width, height) // If the rectangle contains no pixels, don't draw anything. if gopherRect.Empty() { return } // Output a little message. log.Printf("Drawing gopher at (%d, %d)", x, y) // Get a subimage of the gopher that's in sync with gopherRect. gopherPt := image.Pt(gopher.Bounds().Min.X, gopher.Bounds().Min.Y) if gopherRect.Min.X == 0 { gopherPt.X = gopherWidth - gopherRect.Dx() } if gopherRect.Min.Y == 0 { gopherPt.Y = gopherHeight - gopherRect.Dy() } // Create the canvas subimage. subCanvas := canvas.SubImage(gopherRect).(*xgraphics.Image) // Blend the gopher image into the sub-canvas. // This does alpha blending. xgraphics.Blend(subCanvas, gopher, gopherPt) // Now draw the changes to the pixmap. subCanvas.XDraw() // And paint them to the window. subCanvas.XPaint(win.Id) }
go
func drawGopher(canvas *xgraphics.Image, gopher image.Image, win *xwindow.Window, x, y int) { // Find the rectangle of the canvas where we're going to draw the gopher. gopherRect := midRect(x, y, gopherWidth, gopherHeight, width, height) // If the rectangle contains no pixels, don't draw anything. if gopherRect.Empty() { return } // Output a little message. log.Printf("Drawing gopher at (%d, %d)", x, y) // Get a subimage of the gopher that's in sync with gopherRect. gopherPt := image.Pt(gopher.Bounds().Min.X, gopher.Bounds().Min.Y) if gopherRect.Min.X == 0 { gopherPt.X = gopherWidth - gopherRect.Dx() } if gopherRect.Min.Y == 0 { gopherPt.Y = gopherHeight - gopherRect.Dy() } // Create the canvas subimage. subCanvas := canvas.SubImage(gopherRect).(*xgraphics.Image) // Blend the gopher image into the sub-canvas. // This does alpha blending. xgraphics.Blend(subCanvas, gopher, gopherPt) // Now draw the changes to the pixmap. subCanvas.XDraw() // And paint them to the window. subCanvas.XPaint(win.Id) }
[ "func", "drawGopher", "(", "canvas", "*", "xgraphics", ".", "Image", ",", "gopher", "image", ".", "Image", ",", "win", "*", "xwindow", ".", "Window", ",", "x", ",", "y", "int", ")", "{", "// Find the rectangle of the canvas where we're going to draw the gopher.", "gopherRect", ":=", "midRect", "(", "x", ",", "y", ",", "gopherWidth", ",", "gopherHeight", ",", "width", ",", "height", ")", "\n\n", "// If the rectangle contains no pixels, don't draw anything.", "if", "gopherRect", ".", "Empty", "(", ")", "{", "return", "\n", "}", "\n\n", "// Output a little message.", "log", ".", "Printf", "(", "\"", "\"", ",", "x", ",", "y", ")", "\n\n", "// Get a subimage of the gopher that's in sync with gopherRect.", "gopherPt", ":=", "image", ".", "Pt", "(", "gopher", ".", "Bounds", "(", ")", ".", "Min", ".", "X", ",", "gopher", ".", "Bounds", "(", ")", ".", "Min", ".", "Y", ")", "\n", "if", "gopherRect", ".", "Min", ".", "X", "==", "0", "{", "gopherPt", ".", "X", "=", "gopherWidth", "-", "gopherRect", ".", "Dx", "(", ")", "\n", "}", "\n", "if", "gopherRect", ".", "Min", ".", "Y", "==", "0", "{", "gopherPt", ".", "Y", "=", "gopherHeight", "-", "gopherRect", ".", "Dy", "(", ")", "\n", "}", "\n\n", "// Create the canvas subimage.", "subCanvas", ":=", "canvas", ".", "SubImage", "(", "gopherRect", ")", ".", "(", "*", "xgraphics", ".", "Image", ")", "\n\n", "// Blend the gopher image into the sub-canvas.", "// This does alpha blending.", "xgraphics", ".", "Blend", "(", "subCanvas", ",", "gopher", ",", "gopherPt", ")", "\n\n", "// Now draw the changes to the pixmap.", "subCanvas", ".", "XDraw", "(", ")", "\n\n", "// And paint them to the window.", "subCanvas", ".", "XPaint", "(", "win", ".", "Id", ")", "\n", "}" ]
// drawGopher draws the gopher image to the canvas.
[ "drawGopher", "draws", "the", "gopher", "image", "to", "the", "canvas", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/_examples/pointer-painting/main.go#L93-L128
2,620
BurntSushi/xgbutil
_examples/pointer-painting/main.go
clearCanvas
func clearCanvas(canvas *xgraphics.Image, win *xwindow.Window) { log.Println("Clearing canvas...") canvas.For(func(x, y int) xgraphics.BGRA { return bg }) canvas.XDraw() canvas.XPaint(win.Id) }
go
func clearCanvas(canvas *xgraphics.Image, win *xwindow.Window) { log.Println("Clearing canvas...") canvas.For(func(x, y int) xgraphics.BGRA { return bg }) canvas.XDraw() canvas.XPaint(win.Id) }
[ "func", "clearCanvas", "(", "canvas", "*", "xgraphics", ".", "Image", ",", "win", "*", "xwindow", ".", "Window", ")", "{", "log", ".", "Println", "(", "\"", "\"", ")", "\n", "canvas", ".", "For", "(", "func", "(", "x", ",", "y", "int", ")", "xgraphics", ".", "BGRA", "{", "return", "bg", "\n", "}", ")", "\n\n", "canvas", ".", "XDraw", "(", ")", "\n", "canvas", ".", "XPaint", "(", "win", ".", "Id", ")", "\n", "}" ]
// clearCanvas erases all your pencil marks.
[ "clearCanvas", "erases", "all", "your", "pencil", "marks", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/_examples/pointer-painting/main.go#L131-L139
2,621
BurntSushi/xgbutil
keybind/encoding.go
ModifierString
func ModifierString(mods uint16) string { modStrs := make([]string, 0, 3) for i, mod := range Modifiers { if mod&mods > 0 && len(NiceModifiers[i]) > 0 { modStrs = append(modStrs, NiceModifiers[i]) } } return strings.Join(modStrs, "-") }
go
func ModifierString(mods uint16) string { modStrs := make([]string, 0, 3) for i, mod := range Modifiers { if mod&mods > 0 && len(NiceModifiers[i]) > 0 { modStrs = append(modStrs, NiceModifiers[i]) } } return strings.Join(modStrs, "-") }
[ "func", "ModifierString", "(", "mods", "uint16", ")", "string", "{", "modStrs", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "3", ")", "\n", "for", "i", ",", "mod", ":=", "range", "Modifiers", "{", "if", "mod", "&", "mods", ">", "0", "&&", "len", "(", "NiceModifiers", "[", "i", "]", ")", ">", "0", "{", "modStrs", "=", "append", "(", "modStrs", ",", "NiceModifiers", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "modStrs", ",", "\"", "\"", ")", "\n", "}" ]
// ModifierString takes in a keyboard state and returns a string of all // modifiers in the state.
[ "ModifierString", "takes", "in", "a", "keyboard", "state", "and", "returns", "a", "string", "of", "all", "modifiers", "in", "the", "state", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/encoding.go#L62-L70
2,622
BurntSushi/xgbutil
_examples/xgraphics-compat/main.go
checkCompatibility
func checkCompatibility(X *xgbutil.XUtil) { s := X.Setup() scrn := X.Screen() failed := false if s.ImageByteOrder != xproto.ImageOrderLSBFirst { log.Printf("Your X server uses MSB image byte order. Unfortunately, " + "xgraphics currently requires LSB image byte order. You may see " + "weird things. Please report this.") failed = true } if s.BitmapFormatBitOrder != xproto.ImageOrderLSBFirst { log.Printf("Your X server uses MSB bitmap bit order. Unfortunately, " + "xgraphics currently requires LSB bitmap bit order. If you " + "aren't using X bitmaps, you should be able to proceed normally. " + "Please report this.") failed = true } if s.BitmapFormatScanlineUnit != 32 { log.Printf("xgraphics expects that the scanline unit is set to 32, "+ "but your X server has it set to '%d'. "+ "Namely, xgraphics hasn't been tested on other values. Things "+ "may still work. Particularly, if you aren't using X bitmaps, "+ "you should be completely unaffected. Please report this.", s.BitmapFormatScanlineUnit) failed = true } if scrn.RootDepth != 24 { log.Printf("xgraphics expects that the root window has a depth of 24, "+ "but yours has depth '%d'. Its possible things will still work "+ "if your value is 32, but will be unlikely to work with values "+ "less than 24. Please report this.", scrn.RootDepth) failed = true } // Look for the default format for pixmaps and make sure bits per pixel // is 32. format := xgraphics.GetFormat(X, scrn.RootDepth) if format.BitsPerPixel != 32 { log.Printf("xgraphics expects that the bits per pixel for the root "+ "window depth is 32. On your system, the root depth is %d and "+ "the bits per pixel is %d. Things will most certainly not work. "+ "Please report this.", scrn.RootDepth, format.BitsPerPixel) failed = true } // Give instructions on reporting the issue. if failed { log.Printf("Please report the aforementioned error message(s) at " + "https://github.com/BurntSushi/xgbutil. Please also include the " + "entire output of the `xdpyinfo` command in your report. Thanks!") } else { log.Printf("No compatibility issues detected.") } }
go
func checkCompatibility(X *xgbutil.XUtil) { s := X.Setup() scrn := X.Screen() failed := false if s.ImageByteOrder != xproto.ImageOrderLSBFirst { log.Printf("Your X server uses MSB image byte order. Unfortunately, " + "xgraphics currently requires LSB image byte order. You may see " + "weird things. Please report this.") failed = true } if s.BitmapFormatBitOrder != xproto.ImageOrderLSBFirst { log.Printf("Your X server uses MSB bitmap bit order. Unfortunately, " + "xgraphics currently requires LSB bitmap bit order. If you " + "aren't using X bitmaps, you should be able to proceed normally. " + "Please report this.") failed = true } if s.BitmapFormatScanlineUnit != 32 { log.Printf("xgraphics expects that the scanline unit is set to 32, "+ "but your X server has it set to '%d'. "+ "Namely, xgraphics hasn't been tested on other values. Things "+ "may still work. Particularly, if you aren't using X bitmaps, "+ "you should be completely unaffected. Please report this.", s.BitmapFormatScanlineUnit) failed = true } if scrn.RootDepth != 24 { log.Printf("xgraphics expects that the root window has a depth of 24, "+ "but yours has depth '%d'. Its possible things will still work "+ "if your value is 32, but will be unlikely to work with values "+ "less than 24. Please report this.", scrn.RootDepth) failed = true } // Look for the default format for pixmaps and make sure bits per pixel // is 32. format := xgraphics.GetFormat(X, scrn.RootDepth) if format.BitsPerPixel != 32 { log.Printf("xgraphics expects that the bits per pixel for the root "+ "window depth is 32. On your system, the root depth is %d and "+ "the bits per pixel is %d. Things will most certainly not work. "+ "Please report this.", scrn.RootDepth, format.BitsPerPixel) failed = true } // Give instructions on reporting the issue. if failed { log.Printf("Please report the aforementioned error message(s) at " + "https://github.com/BurntSushi/xgbutil. Please also include the " + "entire output of the `xdpyinfo` command in your report. Thanks!") } else { log.Printf("No compatibility issues detected.") } }
[ "func", "checkCompatibility", "(", "X", "*", "xgbutil", ".", "XUtil", ")", "{", "s", ":=", "X", ".", "Setup", "(", ")", "\n", "scrn", ":=", "X", ".", "Screen", "(", ")", "\n", "failed", ":=", "false", "\n\n", "if", "s", ".", "ImageByteOrder", "!=", "xproto", ".", "ImageOrderLSBFirst", "{", "log", ".", "Printf", "(", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", ")", "\n", "failed", "=", "true", "\n", "}", "\n", "if", "s", ".", "BitmapFormatBitOrder", "!=", "xproto", ".", "ImageOrderLSBFirst", "{", "log", ".", "Printf", "(", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", ")", "\n", "failed", "=", "true", "\n", "}", "\n", "if", "s", ".", "BitmapFormatScanlineUnit", "!=", "32", "{", "log", ".", "Printf", "(", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", ",", "s", ".", "BitmapFormatScanlineUnit", ")", "\n", "failed", "=", "true", "\n", "}", "\n", "if", "scrn", ".", "RootDepth", "!=", "24", "{", "log", ".", "Printf", "(", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", ",", "scrn", ".", "RootDepth", ")", "\n", "failed", "=", "true", "\n", "}", "\n\n", "// Look for the default format for pixmaps and make sure bits per pixel", "// is 32.", "format", ":=", "xgraphics", ".", "GetFormat", "(", "X", ",", "scrn", ".", "RootDepth", ")", "\n", "if", "format", ".", "BitsPerPixel", "!=", "32", "{", "log", ".", "Printf", "(", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", ",", "scrn", ".", "RootDepth", ",", "format", ".", "BitsPerPixel", ")", "\n", "failed", "=", "true", "\n", "}", "\n\n", "// Give instructions on reporting the issue.", "if", "failed", "{", "log", ".", "Printf", "(", "\"", "\"", "+", "\"", "\"", "+", "\"", "\"", ")", "\n", "}", "else", "{", "log", ".", "Printf", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// checkCompatibility reads info in the X setup info struct and emits // messages to stderr if they don't correspond to values that xgraphics // supports. // The idea is that in the future, we'll support more values. // The real reason for checkCompatibility is to make debugging easier. Without // it, if the values weren't what we'd expect, we'd see garbled images in the // best case, and probably BadLength errors in the worst case.
[ "checkCompatibility", "reads", "info", "in", "the", "X", "setup", "info", "struct", "and", "emits", "messages", "to", "stderr", "if", "they", "don", "t", "correspond", "to", "values", "that", "xgraphics", "supports", ".", "The", "idea", "is", "that", "in", "the", "future", "we", "ll", "support", "more", "values", ".", "The", "real", "reason", "for", "checkCompatibility", "is", "to", "make", "debugging", "easier", ".", "Without", "it", "if", "the", "values", "weren", "t", "what", "we", "d", "expect", "we", "d", "see", "garbled", "images", "in", "the", "best", "case", "and", "probably", "BadLength", "errors", "in", "the", "worst", "case", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/_examples/xgraphics-compat/main.go#L29-L84
2,623
BurntSushi/xgbutil
mousebind/xutil.go
mouseKeys
func mouseKeys(xu *xgbutil.XUtil) []xgbutil.MouseKey { xu.MousebindsLck.RLock() defer xu.MousebindsLck.RUnlock() keys := make([]xgbutil.MouseKey, len(xu.Mousebinds)) i := 0 for key, _ := range xu.Mousebinds { keys[i] = key i++ } return keys }
go
func mouseKeys(xu *xgbutil.XUtil) []xgbutil.MouseKey { xu.MousebindsLck.RLock() defer xu.MousebindsLck.RUnlock() keys := make([]xgbutil.MouseKey, len(xu.Mousebinds)) i := 0 for key, _ := range xu.Mousebinds { keys[i] = key i++ } return keys }
[ "func", "mouseKeys", "(", "xu", "*", "xgbutil", ".", "XUtil", ")", "[", "]", "xgbutil", ".", "MouseKey", "{", "xu", ".", "MousebindsLck", ".", "RLock", "(", ")", "\n", "defer", "xu", ".", "MousebindsLck", ".", "RUnlock", "(", ")", "\n\n", "keys", ":=", "make", "(", "[", "]", "xgbutil", ".", "MouseKey", ",", "len", "(", "xu", ".", "Mousebinds", ")", ")", "\n", "i", ":=", "0", "\n", "for", "key", ",", "_", ":=", "range", "xu", ".", "Mousebinds", "{", "keys", "[", "i", "]", "=", "key", "\n", "i", "++", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// mouseKeys returns a copy of all the keys in the 'Mousebinds' map.
[ "mouseKeys", "returns", "a", "copy", "of", "all", "the", "keys", "in", "the", "Mousebinds", "map", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/xutil.go#L39-L50
2,624
BurntSushi/xgbutil
mousebind/xutil.go
mouseCallbacks
func mouseCallbacks(xu *xgbutil.XUtil, key xgbutil.MouseKey) []xgbutil.CallbackMouse { xu.MousebindsLck.RLock() defer xu.MousebindsLck.RUnlock() cbs := make([]xgbutil.CallbackMouse, len(xu.Mousebinds[key])) copy(cbs, xu.Mousebinds[key]) return cbs }
go
func mouseCallbacks(xu *xgbutil.XUtil, key xgbutil.MouseKey) []xgbutil.CallbackMouse { xu.MousebindsLck.RLock() defer xu.MousebindsLck.RUnlock() cbs := make([]xgbutil.CallbackMouse, len(xu.Mousebinds[key])) copy(cbs, xu.Mousebinds[key]) return cbs }
[ "func", "mouseCallbacks", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "key", "xgbutil", ".", "MouseKey", ")", "[", "]", "xgbutil", ".", "CallbackMouse", "{", "xu", ".", "MousebindsLck", ".", "RLock", "(", ")", "\n", "defer", "xu", ".", "MousebindsLck", ".", "RUnlock", "(", ")", "\n\n", "cbs", ":=", "make", "(", "[", "]", "xgbutil", ".", "CallbackMouse", ",", "len", "(", "xu", ".", "Mousebinds", "[", "key", "]", ")", ")", "\n", "copy", "(", "cbs", ",", "xu", ".", "Mousebinds", "[", "key", "]", ")", "\n", "return", "cbs", "\n", "}" ]
// mouseBindCallbacks returns a slice of callbacks for a particular key.
[ "mouseBindCallbacks", "returns", "a", "slice", "of", "callbacks", "for", "a", "particular", "key", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/xutil.go#L53-L62
2,625
BurntSushi/xgbutil
mousebind/xutil.go
mouseDragStepSet
func mouseDragStepSet(xu *xgbutil.XUtil, f xgbutil.MouseDragFun) { xu.MouseDragStepFun = f }
go
func mouseDragStepSet(xu *xgbutil.XUtil, f xgbutil.MouseDragFun) { xu.MouseDragStepFun = f }
[ "func", "mouseDragStepSet", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "f", "xgbutil", ".", "MouseDragFun", ")", "{", "xu", ".", "MouseDragStepFun", "=", "f", "\n", "}" ]
// mouseDragStepSet sets the function associated with the step of a drag.
[ "mouseDragStepSet", "sets", "the", "function", "associated", "with", "the", "step", "of", "a", "drag", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/xutil.go#L140-L142
2,626
BurntSushi/xgbutil
mousebind/xutil.go
mouseDragEndSet
func mouseDragEndSet(xu *xgbutil.XUtil, f xgbutil.MouseDragFun) { xu.MouseDragEndFun = f }
go
func mouseDragEndSet(xu *xgbutil.XUtil, f xgbutil.MouseDragFun) { xu.MouseDragEndFun = f }
[ "func", "mouseDragEndSet", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "f", "xgbutil", ".", "MouseDragFun", ")", "{", "xu", ".", "MouseDragEndFun", "=", "f", "\n", "}" ]
// mouseDragEndSet sets the function associated with the end of a drag.
[ "mouseDragEndSet", "sets", "the", "function", "associated", "with", "the", "end", "of", "a", "drag", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/xutil.go#L151-L153
2,627
BurntSushi/xgbutil
_examples/compress-events/main.go
newWindow
func newWindow(X *xgbutil.XUtil, color uint32) *xwindow.Window { win, err := xwindow.Generate(X) if err != nil { log.Fatal(err) } err = win.CreateChecked(X.RootWin(), 0, 0, 400, 400, xproto.CwBackPixel|xproto.CwEventMask, color, xproto.EventMaskPointerMotion) if err != nil { log.Fatal(err) } win.Map() return win }
go
func newWindow(X *xgbutil.XUtil, color uint32) *xwindow.Window { win, err := xwindow.Generate(X) if err != nil { log.Fatal(err) } err = win.CreateChecked(X.RootWin(), 0, 0, 400, 400, xproto.CwBackPixel|xproto.CwEventMask, color, xproto.EventMaskPointerMotion) if err != nil { log.Fatal(err) } win.Map() return win }
[ "func", "newWindow", "(", "X", "*", "xgbutil", ".", "XUtil", ",", "color", "uint32", ")", "*", "xwindow", ".", "Window", "{", "win", ",", "err", ":=", "xwindow", ".", "Generate", "(", "X", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n\n", "err", "=", "win", ".", "CreateChecked", "(", "X", ".", "RootWin", "(", ")", ",", "0", ",", "0", ",", "400", ",", "400", ",", "xproto", ".", "CwBackPixel", "|", "xproto", ".", "CwEventMask", ",", "color", ",", "xproto", ".", "EventMaskPointerMotion", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n\n", "win", ".", "Map", "(", ")", "\n", "return", "win", "\n", "}" ]
// newWindow creates a new window that listens to MotionNotify events with // the given backgroundcolor.
[ "newWindow", "creates", "a", "new", "window", "that", "listens", "to", "MotionNotify", "events", "with", "the", "given", "backgroundcolor", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/_examples/compress-events/main.go#L65-L80
2,628
BurntSushi/xgbutil
mousebind/mousebind.go
Initialize
func Initialize(xu *xgbutil.XUtil) { xevent.MotionNotifyFun(dragStep).Connect(xu, xu.Dummy()) xevent.ButtonReleaseFun(DragEnd).Connect(xu, xu.Dummy()) }
go
func Initialize(xu *xgbutil.XUtil) { xevent.MotionNotifyFun(dragStep).Connect(xu, xu.Dummy()) xevent.ButtonReleaseFun(DragEnd).Connect(xu, xu.Dummy()) }
[ "func", "Initialize", "(", "xu", "*", "xgbutil", ".", "XUtil", ")", "{", "xevent", ".", "MotionNotifyFun", "(", "dragStep", ")", ".", "Connect", "(", "xu", ",", "xu", ".", "Dummy", "(", ")", ")", "\n", "xevent", ".", "ButtonReleaseFun", "(", "DragEnd", ")", ".", "Connect", "(", "xu", ",", "xu", ".", "Dummy", "(", ")", ")", "\n", "}" ]
// Initialize attaches the appropriate callbacks to make mouse bindings easier. // i.e., prep the dummy window to handle mouse dragging events
[ "Initialize", "attaches", "the", "appropriate", "callbacks", "to", "make", "mouse", "bindings", "easier", ".", "i", ".", "e", ".", "prep", "the", "dummy", "window", "to", "handle", "mouse", "dragging", "events" ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/mousebind.go#L29-L32
2,629
BurntSushi/xgbutil
mousebind/mousebind.go
Ungrab
func Ungrab(xu *xgbutil.XUtil, win xproto.Window, mods uint16, button xproto.Button) { for _, m := range xevent.IgnoreMods { xproto.UngrabButtonChecked(xu.Conn(), byte(button), win, mods|m).Check() } }
go
func Ungrab(xu *xgbutil.XUtil, win xproto.Window, mods uint16, button xproto.Button) { for _, m := range xevent.IgnoreMods { xproto.UngrabButtonChecked(xu.Conn(), byte(button), win, mods|m).Check() } }
[ "func", "Ungrab", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "win", "xproto", ".", "Window", ",", "mods", "uint16", ",", "button", "xproto", ".", "Button", ")", "{", "for", "_", ",", "m", ":=", "range", "xevent", ".", "IgnoreMods", "{", "xproto", ".", "UngrabButtonChecked", "(", "xu", ".", "Conn", "(", ")", ",", "byte", "(", "button", ")", ",", "win", ",", "mods", "|", "m", ")", ".", "Check", "(", ")", "\n", "}", "\n", "}" ]
// Ungrab undoes Grab. It will handle all combinations of modifiers found // in xevent.IgnoreMods.
[ "Ungrab", "undoes", "Grab", ".", "It", "will", "handle", "all", "combinations", "of", "modifiers", "found", "in", "xevent", ".", "IgnoreMods", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/mousebind/mousebind.go#L141-L147
2,630
BurntSushi/xgbutil
xgraphics/image.go
Destroy
func (im *Image) Destroy() { if im.Pixmap != 0 { xproto.FreePixmap(im.X.Conn(), im.Pixmap) im.Pixmap = 0 } }
go
func (im *Image) Destroy() { if im.Pixmap != 0 { xproto.FreePixmap(im.X.Conn(), im.Pixmap) im.Pixmap = 0 } }
[ "func", "(", "im", "*", "Image", ")", "Destroy", "(", ")", "{", "if", "im", ".", "Pixmap", "!=", "0", "{", "xproto", ".", "FreePixmap", "(", "im", ".", "X", ".", "Conn", "(", ")", ",", "im", ".", "Pixmap", ")", "\n", "im", ".", "Pixmap", "=", "0", "\n", "}", "\n", "}" ]
// Destroy frees the pixmap resource being used by this image. // It should be called whenever the image will no longer be drawn or painted.
[ "Destroy", "frees", "the", "pixmap", "resource", "being", "used", "by", "this", "image", ".", "It", "should", "be", "called", "whenever", "the", "image", "will", "no", "longer", "be", "drawn", "or", "painted", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L100-L105
2,631
BurntSushi/xgbutil
xgraphics/image.go
WritePng
func (im *Image) WritePng(w io.Writer) error { return png.Encode(w, im) }
go
func (im *Image) WritePng(w io.Writer) error { return png.Encode(w, im) }
[ "func", "(", "im", "*", "Image", ")", "WritePng", "(", "w", "io", ".", "Writer", ")", "error", "{", "return", "png", ".", "Encode", "(", "w", ",", "im", ")", "\n", "}" ]
// WritePng encodes the image to w as a png.
[ "WritePng", "encodes", "the", "image", "to", "w", "as", "a", "png", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L121-L123
2,632
BurntSushi/xgbutil
xgraphics/image.go
SavePng
func (im *Image) SavePng(name string) error { file, err := os.Create(name) if err != nil { return err } return im.WritePng(file) }
go
func (im *Image) SavePng(name string) error { file, err := os.Create(name) if err != nil { return err } return im.WritePng(file) }
[ "func", "(", "im", "*", "Image", ")", "SavePng", "(", "name", "string", ")", "error", "{", "file", ",", "err", ":=", "os", ".", "Create", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "im", ".", "WritePng", "(", "file", ")", "\n", "}" ]
// SavePng writes the Image to a file with name as a png.
[ "SavePng", "writes", "the", "Image", "to", "a", "file", "with", "name", "as", "a", "png", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L126-L132
2,633
BurntSushi/xgbutil
xgraphics/image.go
At
func (im *Image) At(x, y int) color.Color { if !(image.Point{x, y}.In(im.Rect)) { return BGRA{} } i := im.PixOffset(x, y) return BGRA{ B: im.Pix[i], G: im.Pix[i+1], R: im.Pix[i+2], A: im.Pix[i+3], } }
go
func (im *Image) At(x, y int) color.Color { if !(image.Point{x, y}.In(im.Rect)) { return BGRA{} } i := im.PixOffset(x, y) return BGRA{ B: im.Pix[i], G: im.Pix[i+1], R: im.Pix[i+2], A: im.Pix[i+3], } }
[ "func", "(", "im", "*", "Image", ")", "At", "(", "x", ",", "y", "int", ")", "color", ".", "Color", "{", "if", "!", "(", "image", ".", "Point", "{", "x", ",", "y", "}", ".", "In", "(", "im", ".", "Rect", ")", ")", "{", "return", "BGRA", "{", "}", "\n", "}", "\n", "i", ":=", "im", ".", "PixOffset", "(", "x", ",", "y", ")", "\n", "return", "BGRA", "{", "B", ":", "im", ".", "Pix", "[", "i", "]", ",", "G", ":", "im", ".", "Pix", "[", "i", "+", "1", "]", ",", "R", ":", "im", ".", "Pix", "[", "i", "+", "2", "]", ",", "A", ":", "im", ".", "Pix", "[", "i", "+", "3", "]", ",", "}", "\n", "}" ]
// At returns the color at the specified pixel.
[ "At", "returns", "the", "color", "at", "the", "specified", "pixel", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L145-L156
2,634
BurntSushi/xgbutil
xgraphics/image.go
SetBGRA
func (im *Image) SetBGRA(x, y int, c BGRA) { if !(image.Point{x, y}.In(im.Rect)) { return } i := im.PixOffset(x, y) im.Pix[i] = c.B im.Pix[i+1] = c.G im.Pix[i+2] = c.R im.Pix[i+3] = c.A }
go
func (im *Image) SetBGRA(x, y int, c BGRA) { if !(image.Point{x, y}.In(im.Rect)) { return } i := im.PixOffset(x, y) im.Pix[i] = c.B im.Pix[i+1] = c.G im.Pix[i+2] = c.R im.Pix[i+3] = c.A }
[ "func", "(", "im", "*", "Image", ")", "SetBGRA", "(", "x", ",", "y", "int", ",", "c", "BGRA", ")", "{", "if", "!", "(", "image", ".", "Point", "{", "x", ",", "y", "}", ".", "In", "(", "im", ".", "Rect", ")", ")", "{", "return", "\n", "}", "\n\n", "i", ":=", "im", ".", "PixOffset", "(", "x", ",", "y", ")", "\n", "im", ".", "Pix", "[", "i", "]", "=", "c", ".", "B", "\n", "im", ".", "Pix", "[", "i", "+", "1", "]", "=", "c", ".", "G", "\n", "im", ".", "Pix", "[", "i", "+", "2", "]", "=", "c", ".", "R", "\n", "im", ".", "Pix", "[", "i", "+", "3", "]", "=", "c", ".", "A", "\n", "}" ]
// SetBGRA is like set, but without the type assertion.
[ "SetBGRA", "is", "like", "set", "but", "without", "the", "type", "assertion", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L174-L184
2,635
BurntSushi/xgbutil
xgraphics/image.go
SubImage
func (im *Image) SubImage(r image.Rectangle) image.Image { r = r.Intersect(im.Rect) if r.Empty() { return nil } i := im.PixOffset(r.Min.X, r.Min.Y) return &Image{ X: im.X, Pixmap: im.Pixmap, Pix: im.Pix[i:], Stride: im.Stride, Rect: r, Subimg: true, } }
go
func (im *Image) SubImage(r image.Rectangle) image.Image { r = r.Intersect(im.Rect) if r.Empty() { return nil } i := im.PixOffset(r.Min.X, r.Min.Y) return &Image{ X: im.X, Pixmap: im.Pixmap, Pix: im.Pix[i:], Stride: im.Stride, Rect: r, Subimg: true, } }
[ "func", "(", "im", "*", "Image", ")", "SubImage", "(", "r", "image", ".", "Rectangle", ")", "image", ".", "Image", "{", "r", "=", "r", ".", "Intersect", "(", "im", ".", "Rect", ")", "\n", "if", "r", ".", "Empty", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "i", ":=", "im", ".", "PixOffset", "(", "r", ".", "Min", ".", "X", ",", "r", ".", "Min", ".", "Y", ")", "\n", "return", "&", "Image", "{", "X", ":", "im", ".", "X", ",", "Pixmap", ":", "im", ".", "Pixmap", ",", "Pix", ":", "im", ".", "Pix", "[", "i", ":", "]", ",", "Stride", ":", "im", ".", "Stride", ",", "Rect", ":", "r", ",", "Subimg", ":", "true", ",", "}", "\n", "}" ]
// SubImage provides a sub image of Image without copying image data. // N.B. The standard library defines a similar function, but returns an // image.Image. Here, we return xgraphics.Image so that we can use the extra // methods defined by xgraphics on it. // // This method is cheap to call. It should be used to update only specific // regions of an X pixmap to avoid sending an entire image to the X server when // only a piece of it is updated. // // Note that if the intersection of `r` and `im` is empty, `nil` is returned.
[ "SubImage", "provides", "a", "sub", "image", "of", "Image", "without", "copying", "image", "data", ".", "N", ".", "B", ".", "The", "standard", "library", "defines", "a", "similar", "function", "but", "returns", "an", "image", ".", "Image", ".", "Here", "we", "return", "xgraphics", ".", "Image", "so", "that", "we", "can", "use", "the", "extra", "methods", "defined", "by", "xgraphics", "on", "it", ".", "This", "method", "is", "cheap", "to", "call", ".", "It", "should", "be", "used", "to", "update", "only", "specific", "regions", "of", "an", "X", "pixmap", "to", "avoid", "sending", "an", "entire", "image", "to", "the", "X", "server", "when", "only", "a", "piece", "of", "it", "is", "updated", ".", "Note", "that", "if", "the", "intersection", "of", "r", "and", "im", "is", "empty", "nil", "is", "returned", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L224-L239
2,636
BurntSushi/xgbutil
xgraphics/image.go
Window
func (im *Image) Window(parent xproto.Window) *xwindow.Window { win := xwindow.Must(xwindow.Create(im.X, parent)) win.Resize(im.Bounds().Dx(), im.Bounds().Dy()) im.XSurfaceSet(win.Id) im.XDraw() im.XPaint(win.Id) im.Destroy() return win }
go
func (im *Image) Window(parent xproto.Window) *xwindow.Window { win := xwindow.Must(xwindow.Create(im.X, parent)) win.Resize(im.Bounds().Dx(), im.Bounds().Dy()) im.XSurfaceSet(win.Id) im.XDraw() im.XPaint(win.Id) im.Destroy() return win }
[ "func", "(", "im", "*", "Image", ")", "Window", "(", "parent", "xproto", ".", "Window", ")", "*", "xwindow", ".", "Window", "{", "win", ":=", "xwindow", ".", "Must", "(", "xwindow", ".", "Create", "(", "im", ".", "X", ",", "parent", ")", ")", "\n", "win", ".", "Resize", "(", "im", ".", "Bounds", "(", ")", ".", "Dx", "(", ")", ",", "im", ".", "Bounds", "(", ")", ".", "Dy", "(", ")", ")", "\n\n", "im", ".", "XSurfaceSet", "(", "win", ".", "Id", ")", "\n", "im", ".", "XDraw", "(", ")", "\n", "im", ".", "XPaint", "(", "win", ".", "Id", ")", "\n", "im", ".", "Destroy", "(", ")", "\n\n", "return", "win", "\n", "}" ]
// Window is a convenience function for painting the provided // Image value to a new window, destroying the pixmap created by that image, // and returning the window value. // The window is sized to the dimensions of the image.
[ "Window", "is", "a", "convenience", "function", "for", "painting", "the", "provided", "Image", "value", "to", "a", "new", "window", "destroying", "the", "pixmap", "created", "by", "that", "image", "and", "returning", "the", "window", "value", ".", "The", "window", "is", "sized", "to", "the", "dimensions", "of", "the", "image", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L251-L261
2,637
BurntSushi/xgbutil
xgraphics/image.go
RGBA
func (c BGRA) RGBA() (r, g, b, a uint32) { r = uint32(c.R) r |= r << 8 g = uint32(c.G) g |= g << 8 b = uint32(c.B) b |= b << 8 a = uint32(c.A) a |= a << 8 return }
go
func (c BGRA) RGBA() (r, g, b, a uint32) { r = uint32(c.R) r |= r << 8 g = uint32(c.G) g |= g << 8 b = uint32(c.B) b |= b << 8 a = uint32(c.A) a |= a << 8 return }
[ "func", "(", "c", "BGRA", ")", "RGBA", "(", ")", "(", "r", ",", "g", ",", "b", ",", "a", "uint32", ")", "{", "r", "=", "uint32", "(", "c", ".", "R", ")", "\n", "r", "|=", "r", "<<", "8", "\n\n", "g", "=", "uint32", "(", "c", ".", "G", ")", "\n", "g", "|=", "g", "<<", "8", "\n\n", "b", "=", "uint32", "(", "c", ".", "B", ")", "\n", "b", "|=", "b", "<<", "8", "\n\n", "a", "=", "uint32", "(", "c", ".", "A", ")", "\n", "a", "|=", "a", "<<", "8", "\n\n", "return", "\n", "}" ]
// RGBA satisfies the color.Color interface.
[ "RGBA", "satisfies", "the", "color", ".", "Color", "interface", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L270-L284
2,638
BurntSushi/xgbutil
xgraphics/image.go
bgraModel
func bgraModel(c color.Color) color.Color { if _, ok := c.(BGRA); ok { return c } r, g, b, a := c.RGBA() return BGRA{ B: uint8(b >> 8), G: uint8(g >> 8), R: uint8(r >> 8), A: uint8(a >> 8), } }
go
func bgraModel(c color.Color) color.Color { if _, ok := c.(BGRA); ok { return c } r, g, b, a := c.RGBA() return BGRA{ B: uint8(b >> 8), G: uint8(g >> 8), R: uint8(r >> 8), A: uint8(a >> 8), } }
[ "func", "bgraModel", "(", "c", "color", ".", "Color", ")", "color", ".", "Color", "{", "if", "_", ",", "ok", ":=", "c", ".", "(", "BGRA", ")", ";", "ok", "{", "return", "c", "\n", "}", "\n\n", "r", ",", "g", ",", "b", ",", "a", ":=", "c", ".", "RGBA", "(", ")", "\n", "return", "BGRA", "{", "B", ":", "uint8", "(", "b", ">>", "8", ")", ",", "G", ":", "uint8", "(", "g", ">>", "8", ")", ",", "R", ":", "uint8", "(", "r", ">>", "8", ")", ",", "A", ":", "uint8", "(", "a", ">>", "8", ")", ",", "}", "\n", "}" ]
// bgraModel converts from any color to a BGRA color type.
[ "bgraModel", "converts", "from", "any", "color", "to", "a", "BGRA", "color", "type", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xgraphics/image.go#L287-L299
2,639
BurntSushi/xgbutil
keybind/xutil.go
addKeyString
func addKeyString(xu *xgbutil.XUtil, callback xgbutil.CallbackKey, evtype int, win xproto.Window, keyStr string, grab bool) { xu.KeybindsLck.Lock() defer xu.KeybindsLck.Unlock() k := xgbutil.KeyString{ Str: keyStr, Callback: callback, Evtype: evtype, Win: win, Grab: grab, } xu.Keystrings = append(xu.Keystrings, k) }
go
func addKeyString(xu *xgbutil.XUtil, callback xgbutil.CallbackKey, evtype int, win xproto.Window, keyStr string, grab bool) { xu.KeybindsLck.Lock() defer xu.KeybindsLck.Unlock() k := xgbutil.KeyString{ Str: keyStr, Callback: callback, Evtype: evtype, Win: win, Grab: grab, } xu.Keystrings = append(xu.Keystrings, k) }
[ "func", "addKeyString", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "callback", "xgbutil", ".", "CallbackKey", ",", "evtype", "int", ",", "win", "xproto", ".", "Window", ",", "keyStr", "string", ",", "grab", "bool", ")", "{", "xu", ".", "KeybindsLck", ".", "Lock", "(", ")", "\n", "defer", "xu", ".", "KeybindsLck", ".", "Unlock", "(", ")", "\n\n", "k", ":=", "xgbutil", ".", "KeyString", "{", "Str", ":", "keyStr", ",", "Callback", ":", "callback", ",", "Evtype", ":", "evtype", ",", "Win", ":", "win", ",", "Grab", ":", "grab", ",", "}", "\n", "xu", ".", "Keystrings", "=", "append", "(", "xu", ".", "Keystrings", ",", "k", ")", "\n", "}" ]
// addKeyString adds a new key binding string to XUtil.Keystrings. // The invariant is that each key string appears once and only once.
[ "addKeyString", "adds", "a", "new", "key", "binding", "string", "to", "XUtil", ".", "Keystrings", ".", "The", "invariant", "is", "that", "each", "key", "string", "appears", "once", "and", "only", "once", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/xutil.go#L41-L55
2,640
BurntSushi/xgbutil
keybind/xutil.go
keyKeys
func keyKeys(xu *xgbutil.XUtil) []xgbutil.KeyKey { xu.KeybindsLck.RLock() defer xu.KeybindsLck.RUnlock() keys := make([]xgbutil.KeyKey, len(xu.Keybinds)) i := 0 for key, _ := range xu.Keybinds { keys[i] = key i++ } return keys }
go
func keyKeys(xu *xgbutil.XUtil) []xgbutil.KeyKey { xu.KeybindsLck.RLock() defer xu.KeybindsLck.RUnlock() keys := make([]xgbutil.KeyKey, len(xu.Keybinds)) i := 0 for key, _ := range xu.Keybinds { keys[i] = key i++ } return keys }
[ "func", "keyKeys", "(", "xu", "*", "xgbutil", ".", "XUtil", ")", "[", "]", "xgbutil", ".", "KeyKey", "{", "xu", ".", "KeybindsLck", ".", "RLock", "(", ")", "\n", "defer", "xu", ".", "KeybindsLck", ".", "RUnlock", "(", ")", "\n\n", "keys", ":=", "make", "(", "[", "]", "xgbutil", ".", "KeyKey", ",", "len", "(", "xu", ".", "Keybinds", ")", ")", "\n", "i", ":=", "0", "\n", "for", "key", ",", "_", ":=", "range", "xu", ".", "Keybinds", "{", "keys", "[", "i", "]", "=", "key", "\n", "i", "++", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// keyBindKeys returns a copy of all the keys in the 'keybinds' map.
[ "keyBindKeys", "returns", "a", "copy", "of", "all", "the", "keys", "in", "the", "keybinds", "map", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/xutil.go#L58-L69
2,641
BurntSushi/xgbutil
keybind/xutil.go
keyCallbacks
func keyCallbacks(xu *xgbutil.XUtil, key xgbutil.KeyKey) []xgbutil.CallbackKey { xu.KeybindsLck.RLock() defer xu.KeybindsLck.RUnlock() cbs := make([]xgbutil.CallbackKey, len(xu.Keybinds[key])) copy(cbs, xu.Keybinds[key]) return cbs }
go
func keyCallbacks(xu *xgbutil.XUtil, key xgbutil.KeyKey) []xgbutil.CallbackKey { xu.KeybindsLck.RLock() defer xu.KeybindsLck.RUnlock() cbs := make([]xgbutil.CallbackKey, len(xu.Keybinds[key])) copy(cbs, xu.Keybinds[key]) return cbs }
[ "func", "keyCallbacks", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "key", "xgbutil", ".", "KeyKey", ")", "[", "]", "xgbutil", ".", "CallbackKey", "{", "xu", ".", "KeybindsLck", ".", "RLock", "(", ")", "\n", "defer", "xu", ".", "KeybindsLck", ".", "RUnlock", "(", ")", "\n\n", "cbs", ":=", "make", "(", "[", "]", "xgbutil", ".", "CallbackKey", ",", "len", "(", "xu", ".", "Keybinds", "[", "key", "]", ")", ")", "\n", "copy", "(", "cbs", ",", "xu", ".", "Keybinds", "[", "key", "]", ")", "\n", "return", "cbs", "\n", "}" ]
// keyBindCallbacks returns a slice of callbacks for a particular key.
[ "keyBindCallbacks", "returns", "a", "slice", "of", "callbacks", "for", "a", "particular", "key", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/xutil.go#L84-L93
2,642
BurntSushi/xgbutil
keybind/xutil.go
connectedKeyBind
func connectedKeyBind(xu *xgbutil.XUtil, evtype int, win xproto.Window) bool { xu.KeybindsLck.RLock() defer xu.KeybindsLck.RUnlock() // Since we can't create a full key, loop through all key binds // and check if evtype and window match. for key, _ := range xu.Keybinds { if key.Evtype == evtype && key.Win == win { return true } } return false }
go
func connectedKeyBind(xu *xgbutil.XUtil, evtype int, win xproto.Window) bool { xu.KeybindsLck.RLock() defer xu.KeybindsLck.RUnlock() // Since we can't create a full key, loop through all key binds // and check if evtype and window match. for key, _ := range xu.Keybinds { if key.Evtype == evtype && key.Win == win { return true } } return false }
[ "func", "connectedKeyBind", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "evtype", "int", ",", "win", "xproto", ".", "Window", ")", "bool", "{", "xu", ".", "KeybindsLck", ".", "RLock", "(", ")", "\n", "defer", "xu", ".", "KeybindsLck", ".", "RUnlock", "(", ")", "\n\n", "// Since we can't create a full key, loop through all key binds", "// and check if evtype and window match.", "for", "key", ",", "_", ":=", "range", "xu", ".", "Keybinds", "{", "if", "key", ".", "Evtype", "==", "evtype", "&&", "key", ".", "Win", "==", "win", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ConnectedKeyBind checks to see if there are any key binds for a particular // event type already in play.
[ "ConnectedKeyBind", "checks", "to", "see", "if", "there", "are", "any", "key", "binds", "for", "a", "particular", "event", "type", "already", "in", "play", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/xutil.go#L97-L109
2,643
BurntSushi/xgbutil
keybind/keybind.go
Initialize
func Initialize(xu *xgbutil.XUtil) { // Listen to mapping notify events xevent.MappingNotifyFun(updateMaps).Connect(xu, xevent.NoWindow) // Give us an initial mapping state... keyMap, modMap := MapsGet(xu) KeyMapSet(xu, keyMap) ModMapSet(xu, modMap) }
go
func Initialize(xu *xgbutil.XUtil) { // Listen to mapping notify events xevent.MappingNotifyFun(updateMaps).Connect(xu, xevent.NoWindow) // Give us an initial mapping state... keyMap, modMap := MapsGet(xu) KeyMapSet(xu, keyMap) ModMapSet(xu, modMap) }
[ "func", "Initialize", "(", "xu", "*", "xgbutil", ".", "XUtil", ")", "{", "// Listen to mapping notify events", "xevent", ".", "MappingNotifyFun", "(", "updateMaps", ")", ".", "Connect", "(", "xu", ",", "xevent", ".", "NoWindow", ")", "\n\n", "// Give us an initial mapping state...", "keyMap", ",", "modMap", ":=", "MapsGet", "(", "xu", ")", "\n", "KeyMapSet", "(", "xu", ",", "keyMap", ")", "\n", "ModMapSet", "(", "xu", ",", "modMap", ")", "\n", "}" ]
// Initialize attaches the appropriate callbacks to make key bindings easier. // i.e., update state of the world on a MappingNotify.
[ "Initialize", "attaches", "the", "appropriate", "callbacks", "to", "make", "key", "bindings", "easier", ".", "i", ".", "e", ".", "update", "state", "of", "the", "world", "on", "a", "MappingNotify", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L28-L36
2,644
BurntSushi/xgbutil
keybind/keybind.go
minMaxKeycodeGet
func minMaxKeycodeGet(xu *xgbutil.XUtil) (xproto.Keycode, xproto.Keycode) { return xu.Setup().MinKeycode, xu.Setup().MaxKeycode }
go
func minMaxKeycodeGet(xu *xgbutil.XUtil) (xproto.Keycode, xproto.Keycode) { return xu.Setup().MinKeycode, xu.Setup().MaxKeycode }
[ "func", "minMaxKeycodeGet", "(", "xu", "*", "xgbutil", ".", "XUtil", ")", "(", "xproto", ".", "Keycode", ",", "xproto", ".", "Keycode", ")", "{", "return", "xu", ".", "Setup", "(", ")", ".", "MinKeycode", ",", "xu", ".", "Setup", "(", ")", ".", "MaxKeycode", "\n", "}" ]
// minMaxKeycodeGet a simple accessor to the X setup info to return the // minimum and maximum keycodes. They are typically 8 and 255, respectively.
[ "minMaxKeycodeGet", "a", "simple", "accessor", "to", "the", "X", "setup", "info", "to", "return", "the", "minimum", "and", "maximum", "keycodes", ".", "They", "are", "typically", "8", "and", "255", "respectively", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L94-L96
2,645
BurntSushi/xgbutil
keybind/keybind.go
keycodesGet
func keycodesGet(xu *xgbutil.XUtil, keysym xproto.Keysym) []xproto.Keycode { min, max := minMaxKeycodeGet(xu) keyMap := KeyMapGet(xu) if keyMap == nil { panic("keybind.Initialize must be called before using the keybind " + "package.") } var c byte var keycode xproto.Keycode keycodes := make([]xproto.Keycode, 0) set := make(map[xproto.Keycode]bool, 0) for kc := int(min); kc <= int(max); kc++ { keycode = xproto.Keycode(kc) for c = 0; c < keyMap.KeysymsPerKeycode; c++ { if keysym == KeysymGet(xu, keycode, c) && !set[keycode] { keycodes = append(keycodes, keycode) set[keycode] = true } } } return keycodes }
go
func keycodesGet(xu *xgbutil.XUtil, keysym xproto.Keysym) []xproto.Keycode { min, max := minMaxKeycodeGet(xu) keyMap := KeyMapGet(xu) if keyMap == nil { panic("keybind.Initialize must be called before using the keybind " + "package.") } var c byte var keycode xproto.Keycode keycodes := make([]xproto.Keycode, 0) set := make(map[xproto.Keycode]bool, 0) for kc := int(min); kc <= int(max); kc++ { keycode = xproto.Keycode(kc) for c = 0; c < keyMap.KeysymsPerKeycode; c++ { if keysym == KeysymGet(xu, keycode, c) && !set[keycode] { keycodes = append(keycodes, keycode) set[keycode] = true } } } return keycodes }
[ "func", "keycodesGet", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "keysym", "xproto", ".", "Keysym", ")", "[", "]", "xproto", ".", "Keycode", "{", "min", ",", "max", ":=", "minMaxKeycodeGet", "(", "xu", ")", "\n", "keyMap", ":=", "KeyMapGet", "(", "xu", ")", "\n", "if", "keyMap", "==", "nil", "{", "panic", "(", "\"", "\"", "+", "\"", "\"", ")", "\n", "}", "\n\n", "var", "c", "byte", "\n", "var", "keycode", "xproto", ".", "Keycode", "\n", "keycodes", ":=", "make", "(", "[", "]", "xproto", ".", "Keycode", ",", "0", ")", "\n", "set", ":=", "make", "(", "map", "[", "xproto", ".", "Keycode", "]", "bool", ",", "0", ")", "\n\n", "for", "kc", ":=", "int", "(", "min", ")", ";", "kc", "<=", "int", "(", "max", ")", ";", "kc", "++", "{", "keycode", "=", "xproto", ".", "Keycode", "(", "kc", ")", "\n", "for", "c", "=", "0", ";", "c", "<", "keyMap", ".", "KeysymsPerKeycode", ";", "c", "++", "{", "if", "keysym", "==", "KeysymGet", "(", "xu", ",", "keycode", ",", "c", ")", "&&", "!", "set", "[", "keycode", "]", "{", "keycodes", "=", "append", "(", "keycodes", ",", "keycode", ")", "\n", "set", "[", "keycode", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "keycodes", "\n", "}" ]
// Given a keysym, find all keycodes mapped to it in the current X environment. // keybind.Initialize MUST have been called before using this function.
[ "Given", "a", "keysym", "find", "all", "keycodes", "mapped", "to", "it", "in", "the", "current", "X", "environment", ".", "keybind", ".", "Initialize", "MUST", "have", "been", "called", "before", "using", "this", "function", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L201-L224
2,646
BurntSushi/xgbutil
keybind/keybind.go
KeysymGet
func KeysymGet(xu *xgbutil.XUtil, keycode xproto.Keycode, column byte) xproto.Keysym { return KeysymGetWithMap(xu, KeyMapGet(xu), keycode, column) }
go
func KeysymGet(xu *xgbutil.XUtil, keycode xproto.Keycode, column byte) xproto.Keysym { return KeysymGetWithMap(xu, KeyMapGet(xu), keycode, column) }
[ "func", "KeysymGet", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "keycode", "xproto", ".", "Keycode", ",", "column", "byte", ")", "xproto", ".", "Keysym", "{", "return", "KeysymGetWithMap", "(", "xu", ",", "KeyMapGet", "(", "xu", ")", ",", "keycode", ",", "column", ")", "\n", "}" ]
// KeysymGet is a shortcut alias for 'KeysymGetWithMap' using the current // keymap stored in XUtil. // keybind.Initialize MUST have been called before using this function.
[ "KeysymGet", "is", "a", "shortcut", "alias", "for", "KeysymGetWithMap", "using", "the", "current", "keymap", "stored", "in", "XUtil", ".", "keybind", ".", "Initialize", "MUST", "have", "been", "called", "before", "using", "this", "function", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L248-L252
2,647
BurntSushi/xgbutil
keybind/keybind.go
KeysymGetWithMap
func KeysymGetWithMap(xu *xgbutil.XUtil, keyMap *xgbutil.KeyboardMapping, keycode xproto.Keycode, column byte) xproto.Keysym { min, _ := minMaxKeycodeGet(xu) i := (int(keycode)-int(min))*int(keyMap.KeysymsPerKeycode) + int(column) return keyMap.Keysyms[i] }
go
func KeysymGetWithMap(xu *xgbutil.XUtil, keyMap *xgbutil.KeyboardMapping, keycode xproto.Keycode, column byte) xproto.Keysym { min, _ := minMaxKeycodeGet(xu) i := (int(keycode)-int(min))*int(keyMap.KeysymsPerKeycode) + int(column) return keyMap.Keysyms[i] }
[ "func", "KeysymGetWithMap", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "keyMap", "*", "xgbutil", ".", "KeyboardMapping", ",", "keycode", "xproto", ".", "Keycode", ",", "column", "byte", ")", "xproto", ".", "Keysym", "{", "min", ",", "_", ":=", "minMaxKeycodeGet", "(", "xu", ")", "\n", "i", ":=", "(", "int", "(", "keycode", ")", "-", "int", "(", "min", ")", ")", "*", "int", "(", "keyMap", ".", "KeysymsPerKeycode", ")", "+", "int", "(", "column", ")", "\n\n", "return", "keyMap", ".", "Keysyms", "[", "i", "]", "\n", "}" ]
// KeysymGetWithMap uses the given key map and finds a keysym associated // with the given keycode in the current X environment.
[ "KeysymGetWithMap", "uses", "the", "given", "key", "map", "and", "finds", "a", "keysym", "associated", "with", "the", "given", "keycode", "in", "the", "current", "X", "environment", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L256-L263
2,648
BurntSushi/xgbutil
keybind/keybind.go
ModGet
func ModGet(xu *xgbutil.XUtil, keycode xproto.Keycode) uint16 { modMap := ModMapGet(xu) var i byte for i = 0; int(i) < len(modMap.Keycodes); i++ { if modMap.Keycodes[i] == keycode { return Modifiers[i/modMap.KeycodesPerModifier] } } return 0 }
go
func ModGet(xu *xgbutil.XUtil, keycode xproto.Keycode) uint16 { modMap := ModMapGet(xu) var i byte for i = 0; int(i) < len(modMap.Keycodes); i++ { if modMap.Keycodes[i] == keycode { return Modifiers[i/modMap.KeycodesPerModifier] } } return 0 }
[ "func", "ModGet", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "keycode", "xproto", ".", "Keycode", ")", "uint16", "{", "modMap", ":=", "ModMapGet", "(", "xu", ")", "\n\n", "var", "i", "byte", "\n", "for", "i", "=", "0", ";", "int", "(", "i", ")", "<", "len", "(", "modMap", ".", "Keycodes", ")", ";", "i", "++", "{", "if", "modMap", ".", "Keycodes", "[", "i", "]", "==", "keycode", "{", "return", "Modifiers", "[", "i", "/", "modMap", ".", "KeycodesPerModifier", "]", "\n", "}", "\n", "}", "\n", "return", "0", "\n", "}" ]
// ModGet finds the modifier currently associated with a given keycode. // If a modifier doesn't exist for this keycode, then 0 is returned.
[ "ModGet", "finds", "the", "modifier", "currently", "associated", "with", "a", "given", "keycode", ".", "If", "a", "modifier", "doesn", "t", "exist", "for", "this", "keycode", "then", "0", "is", "returned", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L267-L277
2,649
BurntSushi/xgbutil
keybind/keybind.go
Grab
func Grab(xu *xgbutil.XUtil, win xproto.Window, mods uint16, key xproto.Keycode) { for _, m := range xevent.IgnoreMods { xproto.GrabKey(xu.Conn(), true, win, mods|m, key, xproto.GrabModeAsync, xproto.GrabModeAsync) } }
go
func Grab(xu *xgbutil.XUtil, win xproto.Window, mods uint16, key xproto.Keycode) { for _, m := range xevent.IgnoreMods { xproto.GrabKey(xu.Conn(), true, win, mods|m, key, xproto.GrabModeAsync, xproto.GrabModeAsync) } }
[ "func", "Grab", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "win", "xproto", ".", "Window", ",", "mods", "uint16", ",", "key", "xproto", ".", "Keycode", ")", "{", "for", "_", ",", "m", ":=", "range", "xevent", ".", "IgnoreMods", "{", "xproto", ".", "GrabKey", "(", "xu", ".", "Conn", "(", ")", ",", "true", ",", "win", ",", "mods", "|", "m", ",", "key", ",", "xproto", ".", "GrabModeAsync", ",", "xproto", ".", "GrabModeAsync", ")", "\n", "}", "\n", "}" ]
// Grab grabs a key with mods on a particular window. // This will also grab all combinations of modifiers found in xevent.IgnoreMods.
[ "Grab", "grabs", "a", "key", "with", "mods", "on", "a", "particular", "window", ".", "This", "will", "also", "grab", "all", "combinations", "of", "modifiers", "found", "in", "xevent", ".", "IgnoreMods", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L281-L288
2,650
BurntSushi/xgbutil
keybind/keybind.go
Ungrab
func Ungrab(xu *xgbutil.XUtil, win xproto.Window, mods uint16, key xproto.Keycode) { for _, m := range xevent.IgnoreMods { xproto.UngrabKeyChecked(xu.Conn(), key, win, mods|m).Check() } }
go
func Ungrab(xu *xgbutil.XUtil, win xproto.Window, mods uint16, key xproto.Keycode) { for _, m := range xevent.IgnoreMods { xproto.UngrabKeyChecked(xu.Conn(), key, win, mods|m).Check() } }
[ "func", "Ungrab", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "win", "xproto", ".", "Window", ",", "mods", "uint16", ",", "key", "xproto", ".", "Keycode", ")", "{", "for", "_", ",", "m", ":=", "range", "xevent", ".", "IgnoreMods", "{", "xproto", ".", "UngrabKeyChecked", "(", "xu", ".", "Conn", "(", ")", ",", "key", ",", "win", ",", "mods", "|", "m", ")", ".", "Check", "(", ")", "\n", "}", "\n", "}" ]
// Ungrab undoes Grab. It will handle all combinations od modifiers found // in xevent.IgnoreMods.
[ "Ungrab", "undoes", "Grab", ".", "It", "will", "handle", "all", "combinations", "od", "modifiers", "found", "in", "xevent", ".", "IgnoreMods", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L311-L317
2,651
BurntSushi/xgbutil
keybind/keybind.go
SmartGrab
func SmartGrab(xu *xgbutil.XUtil, win xproto.Window) error { err := GrabKeyboard(xu, win) if err != nil { return fmt.Errorf("SmartGrab: %s", err) } // Now redirect all key events to the dummy window to prevent races xevent.RedirectKeyEvents(xu, win) return nil }
go
func SmartGrab(xu *xgbutil.XUtil, win xproto.Window) error { err := GrabKeyboard(xu, win) if err != nil { return fmt.Errorf("SmartGrab: %s", err) } // Now redirect all key events to the dummy window to prevent races xevent.RedirectKeyEvents(xu, win) return nil }
[ "func", "SmartGrab", "(", "xu", "*", "xgbutil", ".", "XUtil", ",", "win", "xproto", ".", "Window", ")", "error", "{", "err", ":=", "GrabKeyboard", "(", "xu", ",", "win", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Now redirect all key events to the dummy window to prevent races", "xevent", ".", "RedirectKeyEvents", "(", "xu", ",", "win", ")", "\n\n", "return", "nil", "\n", "}" ]
// SmartGrab grabs the keyboard for the given window, and redirects all // key events in the xevent main event loop to avoid races.
[ "SmartGrab", "grabs", "the", "keyboard", "for", "the", "given", "window", "and", "redirects", "all", "key", "events", "in", "the", "xevent", "main", "event", "loop", "to", "avoid", "races", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/keybind/keybind.go#L358-L368
2,652
BurntSushi/xgbutil
xinerama/xinerama.go
Less
func (hds Heads) Less(i int, j int) bool { return hds[i].X() < hds[j].X() || (hds[i].X() == hds[j].X() && hds[i].Y() < hds[j].Y()) }
go
func (hds Heads) Less(i int, j int) bool { return hds[i].X() < hds[j].X() || (hds[i].X() == hds[j].X() && hds[i].Y() < hds[j].Y()) }
[ "func", "(", "hds", "Heads", ")", "Less", "(", "i", "int", ",", "j", "int", ")", "bool", "{", "return", "hds", "[", "i", "]", ".", "X", "(", ")", "<", "hds", "[", "j", "]", ".", "X", "(", ")", "||", "(", "hds", "[", "i", "]", ".", "X", "(", ")", "==", "hds", "[", "j", "]", ".", "X", "(", ")", "&&", "hds", "[", "i", "]", ".", "Y", "(", ")", "<", "hds", "[", "j", "]", ".", "Y", "(", ")", ")", "\n", "}" ]
// Less satisfies 'Less' in sort.Interface.
[ "Less", "satisfies", "Less", "in", "sort", ".", "Interface", "." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xinerama/xinerama.go#L21-L24
2,653
BurntSushi/xgbutil
xinerama/xinerama.go
Swap
func (hds Heads) Swap(i int, j int) { hds[i], hds[j] = hds[j], hds[i] }
go
func (hds Heads) Swap(i int, j int) { hds[i], hds[j] = hds[j], hds[i] }
[ "func", "(", "hds", "Heads", ")", "Swap", "(", "i", "int", ",", "j", "int", ")", "{", "hds", "[", "i", "]", ",", "hds", "[", "j", "]", "=", "hds", "[", "j", "]", ",", "hds", "[", "i", "]", "\n", "}" ]
// Swap does just that. Nothing to see here...
[ "Swap", "does", "just", "that", ".", "Nothing", "to", "see", "here", "..." ]
f7c97cef3b4e6c88280a5a7091c3314e815ca243
https://github.com/BurntSushi/xgbutil/blob/f7c97cef3b4e6c88280a5a7091c3314e815ca243/xinerama/xinerama.go#L27-L29
2,654
goph/emperror
context.go
With
func With(err error, keyvals ...interface{}) error { if err == nil { return nil } if len(keyvals) == 0 { return err } var kvs []interface{} // extract context from previous error if c, ok := err.(*withContext); ok { err = c.err kvs = append(kvs, c.keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } } kvs = append(kvs, keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } // Limiting the capacity of the stored keyvals ensures that a new // backing array is created if the slice must grow in With. // Using the extra capacity without copying risks a data race. return &withContext{ err: err, keyvals: kvs[:len(kvs):len(kvs)], } }
go
func With(err error, keyvals ...interface{}) error { if err == nil { return nil } if len(keyvals) == 0 { return err } var kvs []interface{} // extract context from previous error if c, ok := err.(*withContext); ok { err = c.err kvs = append(kvs, c.keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } } kvs = append(kvs, keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } // Limiting the capacity of the stored keyvals ensures that a new // backing array is created if the slice must grow in With. // Using the extra capacity without copying risks a data race. return &withContext{ err: err, keyvals: kvs[:len(kvs):len(kvs)], } }
[ "func", "With", "(", "err", "error", ",", "keyvals", "...", "interface", "{", "}", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "len", "(", "keyvals", ")", "==", "0", "{", "return", "err", "\n", "}", "\n\n", "var", "kvs", "[", "]", "interface", "{", "}", "\n\n", "// extract context from previous error", "if", "c", ",", "ok", ":=", "err", ".", "(", "*", "withContext", ")", ";", "ok", "{", "err", "=", "c", ".", "err", "\n\n", "kvs", "=", "append", "(", "kvs", ",", "c", ".", "keyvals", "...", ")", "\n\n", "if", "len", "(", "kvs", ")", "%", "2", "!=", "0", "{", "kvs", "=", "append", "(", "kvs", ",", "nil", ")", "\n", "}", "\n", "}", "\n\n", "kvs", "=", "append", "(", "kvs", ",", "keyvals", "...", ")", "\n\n", "if", "len", "(", "kvs", ")", "%", "2", "!=", "0", "{", "kvs", "=", "append", "(", "kvs", ",", "nil", ")", "\n", "}", "\n\n", "// Limiting the capacity of the stored keyvals ensures that a new", "// backing array is created if the slice must grow in With.", "// Using the extra capacity without copying risks a data race.", "return", "&", "withContext", "{", "err", ":", "err", ",", "keyvals", ":", "kvs", "[", ":", "len", "(", "kvs", ")", ":", "len", "(", "kvs", ")", "]", ",", "}", "\n", "}" ]
// The implementation bellow is heavily influenced by go-kit's log context. // With returns a new error with keyvals context appended to it. // If the wrapped error is already a contextual error created by With // keyvals is appended to the existing context, but a new error is returned.
[ "The", "implementation", "bellow", "is", "heavily", "influenced", "by", "go", "-", "kit", "s", "log", "context", ".", "With", "returns", "a", "new", "error", "with", "keyvals", "context", "appended", "to", "it", ".", "If", "the", "wrapped", "error", "is", "already", "a", "contextual", "error", "created", "by", "With", "keyvals", "is", "appended", "to", "the", "existing", "context", "but", "a", "new", "error", "is", "returned", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/context.go#L13-L48
2,655
goph/emperror
handler_composite.go
Handle
func (h *compositeHandler) Handle(err error) { for _, handler := range h.handlers { handler.Handle(err) } }
go
func (h *compositeHandler) Handle(err error) { for _, handler := range h.handlers { handler.Handle(err) } }
[ "func", "(", "h", "*", "compositeHandler", ")", "Handle", "(", "err", "error", ")", "{", "for", "_", ",", "handler", ":=", "range", "h", ".", "handlers", "{", "handler", ".", "Handle", "(", "err", ")", "\n", "}", "\n", "}" ]
// Handle goes through the handlers and call each of them for the error.
[ "Handle", "goes", "through", "the", "handlers", "and", "call", "each", "of", "them", "for", "the", "error", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler_composite.go#L14-L18
2,656
goph/emperror
utils.go
Handle
func Handle(handler Handler, err error) { if err != nil { handler.Handle(err) } }
go
func Handle(handler Handler, err error) { if err != nil { handler.Handle(err) } }
[ "func", "Handle", "(", "handler", "Handler", ",", "err", "error", ")", "{", "if", "err", "!=", "nil", "{", "handler", ".", "Handle", "(", "err", ")", "\n", "}", "\n", "}" ]
// Handle handles an error whenever it occurs.
[ "Handle", "handles", "an", "error", "whenever", "it", "occurs", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/utils.go#L14-L18
2,657
goph/emperror
multierr.go
Add
func (b *MultiErrorBuilder) Add(err error) { // Do not add nil values. if err == nil { return } b.errors = append(b.errors, err) }
go
func (b *MultiErrorBuilder) Add(err error) { // Do not add nil values. if err == nil { return } b.errors = append(b.errors, err) }
[ "func", "(", "b", "*", "MultiErrorBuilder", ")", "Add", "(", "err", "error", ")", "{", "// Do not add nil values.", "if", "err", "==", "nil", "{", "return", "\n", "}", "\n\n", "b", ".", "errors", "=", "append", "(", "b", ".", "errors", ",", "err", ")", "\n", "}" ]
// Add adds an error to the list. // // Calling this method concurrently is not safe.
[ "Add", "adds", "an", "error", "to", "the", "list", ".", "Calling", "this", "method", "concurrently", "is", "not", "safe", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/multierr.go#L53-L60
2,658
goph/emperror
multierr.go
ErrOrNil
func (b *MultiErrorBuilder) ErrOrNil() error { // No errors added, return nil. if len(b.errors) == 0 { return nil } // Return a single error when there is only one and the builder is told to do so. if len(b.errors) == 1 && b.SingleWrapMode == ReturnSingle { return b.errors[0] } return &multiError{b.errors, b.Message} }
go
func (b *MultiErrorBuilder) ErrOrNil() error { // No errors added, return nil. if len(b.errors) == 0 { return nil } // Return a single error when there is only one and the builder is told to do so. if len(b.errors) == 1 && b.SingleWrapMode == ReturnSingle { return b.errors[0] } return &multiError{b.errors, b.Message} }
[ "func", "(", "b", "*", "MultiErrorBuilder", ")", "ErrOrNil", "(", ")", "error", "{", "// No errors added, return nil.", "if", "len", "(", "b", ".", "errors", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "// Return a single error when there is only one and the builder is told to do so.", "if", "len", "(", "b", ".", "errors", ")", "==", "1", "&&", "b", ".", "SingleWrapMode", "==", "ReturnSingle", "{", "return", "b", ".", "errors", "[", "0", "]", "\n", "}", "\n\n", "return", "&", "multiError", "{", "b", ".", "errors", ",", "b", ".", "Message", "}", "\n", "}" ]
// ErrOrNil returns a MultiError the builder aggregates a list of errors, // or returns nil if the list of errors is empty. // // It is useful to avoid checking if there are any errors added to the list.
[ "ErrOrNil", "returns", "a", "MultiError", "the", "builder", "aggregates", "a", "list", "of", "errors", "or", "returns", "nil", "if", "the", "list", "of", "errors", "is", "empty", ".", "It", "is", "useful", "to", "avoid", "checking", "if", "there", "are", "any", "errors", "added", "to", "the", "list", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/multierr.go#L66-L78
2,659
goph/emperror
stack.go
Format
func (w *withStack) Format(s fmt.State, verb rune) { switch verb { case 'v': if s.Flag('+') { _, _ = fmt.Fprintf(s, "%+v", w.Cause()) return } fallthrough case 's': _, _ = io.WriteString(s, w.Error()) case 'q': _, _ = fmt.Fprintf(s, "%q", w.Error()) } }
go
func (w *withStack) Format(s fmt.State, verb rune) { switch verb { case 'v': if s.Flag('+') { _, _ = fmt.Fprintf(s, "%+v", w.Cause()) return } fallthrough case 's': _, _ = io.WriteString(s, w.Error()) case 'q': _, _ = fmt.Fprintf(s, "%q", w.Error()) } }
[ "func", "(", "w", "*", "withStack", ")", "Format", "(", "s", "fmt", ".", "State", ",", "verb", "rune", ")", "{", "switch", "verb", "{", "case", "'v'", ":", "if", "s", ".", "Flag", "(", "'+'", ")", "{", "_", ",", "_", "=", "fmt", ".", "Fprintf", "(", "s", ",", "\"", "\"", ",", "w", ".", "Cause", "(", ")", ")", "\n", "return", "\n", "}", "\n", "fallthrough", "\n\n", "case", "'s'", ":", "_", ",", "_", "=", "io", ".", "WriteString", "(", "s", ",", "w", ".", "Error", "(", ")", ")", "\n\n", "case", "'q'", ":", "_", ",", "_", "=", "fmt", ".", "Fprintf", "(", "s", ",", "\"", "\"", ",", "w", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}" ]
// Format implements the fmt.Formatter interface.
[ "Format", "implements", "the", "fmt", ".", "Formatter", "interface", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/stack.go#L59-L74
2,660
goph/emperror
handler/logrushandler/handler.go
Handle
func (h *Handler) Handle(err error) { logger := h.logger // Extract context from the error and attach it to the log if kvs := emperror.Context(err); len(kvs) > 0 { logger = h.logger.WithFields(logrus.Fields(keyvals.ToMap(kvs))) } type errorCollection interface { Errors() []error } if errs, ok := err.(errorCollection); ok { for _, e := range errs.Errors() { logger.WithField("parent", err.Error()).Error(e.Error()) } } else { logger.Error(err.Error()) } }
go
func (h *Handler) Handle(err error) { logger := h.logger // Extract context from the error and attach it to the log if kvs := emperror.Context(err); len(kvs) > 0 { logger = h.logger.WithFields(logrus.Fields(keyvals.ToMap(kvs))) } type errorCollection interface { Errors() []error } if errs, ok := err.(errorCollection); ok { for _, e := range errs.Errors() { logger.WithField("parent", err.Error()).Error(e.Error()) } } else { logger.Error(err.Error()) } }
[ "func", "(", "h", "*", "Handler", ")", "Handle", "(", "err", "error", ")", "{", "logger", ":=", "h", ".", "logger", "\n\n", "// Extract context from the error and attach it to the log", "if", "kvs", ":=", "emperror", ".", "Context", "(", "err", ")", ";", "len", "(", "kvs", ")", ">", "0", "{", "logger", "=", "h", ".", "logger", ".", "WithFields", "(", "logrus", ".", "Fields", "(", "keyvals", ".", "ToMap", "(", "kvs", ")", ")", ")", "\n", "}", "\n\n", "type", "errorCollection", "interface", "{", "Errors", "(", ")", "[", "]", "error", "\n", "}", "\n\n", "if", "errs", ",", "ok", ":=", "err", ".", "(", "errorCollection", ")", ";", "ok", "{", "for", "_", ",", "e", ":=", "range", "errs", ".", "Errors", "(", ")", "{", "logger", ".", "WithField", "(", "\"", "\"", ",", "err", ".", "Error", "(", ")", ")", ".", "Error", "(", "e", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "else", "{", "logger", ".", "Error", "(", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}" ]
// Handle logs an error.
[ "Handle", "logs", "an", "error", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler/logrushandler/handler.go#L24-L43
2,661
goph/emperror
handler/airbrakehandler/handler.go
NewFromNotifier
func NewFromNotifier(notifier *gobrake.Notifier) *Handler { handler := &Handler{ notifier: notifier, } return handler }
go
func NewFromNotifier(notifier *gobrake.Notifier) *Handler { handler := &Handler{ notifier: notifier, } return handler }
[ "func", "NewFromNotifier", "(", "notifier", "*", "gobrake", ".", "Notifier", ")", "*", "Handler", "{", "handler", ":=", "&", "Handler", "{", "notifier", ":", "notifier", ",", "}", "\n\n", "return", "handler", "\n", "}" ]
// NewFromNotifier creates a new handler from a notifier instance.
[ "NewFromNotifier", "creates", "a", "new", "handler", "from", "a", "notifier", "instance", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler/airbrakehandler/handler.go#L34-L40
2,662
goph/emperror
handler/airbrakehandler/handler.go
NewSyncFromNotifier
func NewSyncFromNotifier(notifier *gobrake.Notifier) *Handler { handler := NewFromNotifier(notifier) handler.sendSynchronously = true return handler }
go
func NewSyncFromNotifier(notifier *gobrake.Notifier) *Handler { handler := NewFromNotifier(notifier) handler.sendSynchronously = true return handler }
[ "func", "NewSyncFromNotifier", "(", "notifier", "*", "gobrake", ".", "Notifier", ")", "*", "Handler", "{", "handler", ":=", "NewFromNotifier", "(", "notifier", ")", "\n\n", "handler", ".", "sendSynchronously", "=", "true", "\n\n", "return", "handler", "\n", "}" ]
// NewSyncFromNotifier creates a new handler from a notifier instance that sends errors synchronously.
[ "NewSyncFromNotifier", "creates", "a", "new", "handler", "from", "a", "notifier", "instance", "that", "sends", "errors", "synchronously", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler/airbrakehandler/handler.go#L43-L49
2,663
goph/emperror
handler/sentryhandler/handler.go
NewSyncFromClient
func NewSyncFromClient(client *raven.Client) *Handler { handler := NewFromClient(client) handler.sendSynchronously = true return handler }
go
func NewSyncFromClient(client *raven.Client) *Handler { handler := NewFromClient(client) handler.sendSynchronously = true return handler }
[ "func", "NewSyncFromClient", "(", "client", "*", "raven", ".", "Client", ")", "*", "Handler", "{", "handler", ":=", "NewFromClient", "(", "client", ")", "\n\n", "handler", ".", "sendSynchronously", "=", "true", "\n\n", "return", "handler", "\n", "}" ]
// NewSyncFromClient creates a new handler from a client instance that sends errors synchronously.
[ "NewSyncFromClient", "creates", "a", "new", "handler", "from", "a", "client", "instance", "that", "sends", "errors", "synchronously", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler/sentryhandler/handler.go#L49-L55
2,664
goph/emperror
handler/sentryhandler/handler.go
Close
func (h *Handler) Close() error { h.client.Close() h.client.Wait() return nil }
go
func (h *Handler) Close() error { h.client.Close() h.client.Wait() return nil }
[ "func", "(", "h", "*", "Handler", ")", "Close", "(", ")", "error", "{", "h", ".", "client", ".", "Close", "(", ")", "\n", "h", ".", "client", ".", "Wait", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// Close closes the underlying notifier and waits for asynchronous reports to finish.
[ "Close", "closes", "the", "underlying", "notifier", "and", "waits", "for", "asynchronous", "reports", "to", "finish", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler/sentryhandler/handler.go#L86-L91
2,665
goph/emperror
handler/bugsnaghandler/handler.go
Handle
func (h *Handler) Handle(err error) { // Expose the stackTracer interface on the outer error (if there is stack trace in the error) // Convert error with stack trace to an internal error type if e, ok := emperror.ExposeStackTrace(err).(stackTracer); ok { err = newErrorWithStackFrames(e) } var rawData []interface{} if cause := errors.Cause(err); cause != nil { if name := reflect.TypeOf(cause).String(); len(name) > 0 { errorClass := bugsnag.ErrorClass{Name: name} rawData = append(rawData, errorClass) } } if ctx := emperror.Context(err); len(ctx) > 0 { rawData = append(rawData, bugsnag.MetaData{ "Params": keyvals.ToMap(ctx), }) } _ = h.notifier.Notify(err, rawData...) }
go
func (h *Handler) Handle(err error) { // Expose the stackTracer interface on the outer error (if there is stack trace in the error) // Convert error with stack trace to an internal error type if e, ok := emperror.ExposeStackTrace(err).(stackTracer); ok { err = newErrorWithStackFrames(e) } var rawData []interface{} if cause := errors.Cause(err); cause != nil { if name := reflect.TypeOf(cause).String(); len(name) > 0 { errorClass := bugsnag.ErrorClass{Name: name} rawData = append(rawData, errorClass) } } if ctx := emperror.Context(err); len(ctx) > 0 { rawData = append(rawData, bugsnag.MetaData{ "Params": keyvals.ToMap(ctx), }) } _ = h.notifier.Notify(err, rawData...) }
[ "func", "(", "h", "*", "Handler", ")", "Handle", "(", "err", "error", ")", "{", "// Expose the stackTracer interface on the outer error (if there is stack trace in the error)", "// Convert error with stack trace to an internal error type", "if", "e", ",", "ok", ":=", "emperror", ".", "ExposeStackTrace", "(", "err", ")", ".", "(", "stackTracer", ")", ";", "ok", "{", "err", "=", "newErrorWithStackFrames", "(", "e", ")", "\n", "}", "\n\n", "var", "rawData", "[", "]", "interface", "{", "}", "\n\n", "if", "cause", ":=", "errors", ".", "Cause", "(", "err", ")", ";", "cause", "!=", "nil", "{", "if", "name", ":=", "reflect", ".", "TypeOf", "(", "cause", ")", ".", "String", "(", ")", ";", "len", "(", "name", ")", ">", "0", "{", "errorClass", ":=", "bugsnag", ".", "ErrorClass", "{", "Name", ":", "name", "}", "\n\n", "rawData", "=", "append", "(", "rawData", ",", "errorClass", ")", "\n", "}", "\n", "}", "\n\n", "if", "ctx", ":=", "emperror", ".", "Context", "(", "err", ")", ";", "len", "(", "ctx", ")", ">", "0", "{", "rawData", "=", "append", "(", "rawData", ",", "bugsnag", ".", "MetaData", "{", "\"", "\"", ":", "keyvals", ".", "ToMap", "(", "ctx", ")", ",", "}", ")", "\n", "}", "\n\n", "_", "=", "h", ".", "notifier", ".", "Notify", "(", "err", ",", "rawData", "...", ")", "\n", "}" ]
// Handle sends the error to Bugsnag.
[ "Handle", "sends", "the", "error", "to", "Bugsnag", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler/bugsnaghandler/handler.go#L34-L58
2,666
goph/emperror
internal/keyvals/to_map.go
ToMap
func ToMap(kvs []interface{}) map[string]interface{} { m := map[string]interface{}{} if len(kvs) == 0 { return m } if len(kvs)%2 == 1 { kvs = append(kvs, nil) } for i := 0; i < len(kvs); i += 2 { merge(m, kvs[i], kvs[i+1]) } return m }
go
func ToMap(kvs []interface{}) map[string]interface{} { m := map[string]interface{}{} if len(kvs) == 0 { return m } if len(kvs)%2 == 1 { kvs = append(kvs, nil) } for i := 0; i < len(kvs); i += 2 { merge(m, kvs[i], kvs[i+1]) } return m }
[ "func", "ToMap", "(", "kvs", "[", "]", "interface", "{", "}", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "m", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n\n", "if", "len", "(", "kvs", ")", "==", "0", "{", "return", "m", "\n", "}", "\n\n", "if", "len", "(", "kvs", ")", "%", "2", "==", "1", "{", "kvs", "=", "append", "(", "kvs", ",", "nil", ")", "\n", "}", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "kvs", ")", ";", "i", "+=", "2", "{", "merge", "(", "m", ",", "kvs", "[", "i", "]", ",", "kvs", "[", "i", "+", "1", "]", ")", "\n", "}", "\n\n", "return", "m", "\n", "}" ]
// ToMap creates a map of key-value pairs from a variadic key-value pair slice. // // The implementation bellow is from go-kit's JSON logger.
[ "ToMap", "creates", "a", "map", "of", "key", "-", "value", "pairs", "from", "a", "variadic", "key", "-", "value", "pair", "slice", ".", "The", "implementation", "bellow", "is", "from", "go", "-", "kit", "s", "JSON", "logger", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/internal/keyvals/to_map.go#L11-L27
2,667
goph/emperror
httperr/http.go
WithHTTPRequest
func WithHTTPRequest(err error, r *http.Request) error { return &withHTTPRequest{ req: r, err: err, } }
go
func WithHTTPRequest(err error, r *http.Request) error { return &withHTTPRequest{ req: r, err: err, } }
[ "func", "WithHTTPRequest", "(", "err", "error", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "return", "&", "withHTTPRequest", "{", "req", ":", "r", ",", "err", ":", "err", ",", "}", "\n", "}" ]
// WithHTTPRequest attaches an HTTP request to the error.
[ "WithHTTPRequest", "attaches", "an", "HTTP", "request", "to", "the", "error", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/httperr/http.go#L12-L17
2,668
goph/emperror
handler_context.go
HandlerWith
func HandlerWith(handler Handler, keyvals ...interface{}) Handler { if len(keyvals) == 0 { return handler } kvs, handler := extractHandlerContext(handler) kvs = append(kvs, keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } // Limiting the capacity of the stored keyvals ensures that a new // backing array is created if the slice must grow in HandlerWith. // Using the extra capacity without copying risks a data race. return newContextualHandler(handler, kvs[:len(kvs):len(kvs)]) }
go
func HandlerWith(handler Handler, keyvals ...interface{}) Handler { if len(keyvals) == 0 { return handler } kvs, handler := extractHandlerContext(handler) kvs = append(kvs, keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } // Limiting the capacity of the stored keyvals ensures that a new // backing array is created if the slice must grow in HandlerWith. // Using the extra capacity without copying risks a data race. return newContextualHandler(handler, kvs[:len(kvs):len(kvs)]) }
[ "func", "HandlerWith", "(", "handler", "Handler", ",", "keyvals", "...", "interface", "{", "}", ")", "Handler", "{", "if", "len", "(", "keyvals", ")", "==", "0", "{", "return", "handler", "\n", "}", "\n\n", "kvs", ",", "handler", ":=", "extractHandlerContext", "(", "handler", ")", "\n\n", "kvs", "=", "append", "(", "kvs", ",", "keyvals", "...", ")", "\n\n", "if", "len", "(", "kvs", ")", "%", "2", "!=", "0", "{", "kvs", "=", "append", "(", "kvs", ",", "nil", ")", "\n", "}", "\n\n", "// Limiting the capacity of the stored keyvals ensures that a new", "// backing array is created if the slice must grow in HandlerWith.", "// Using the extra capacity without copying risks a data race.", "return", "newContextualHandler", "(", "handler", ",", "kvs", "[", ":", "len", "(", "kvs", ")", ":", "len", "(", "kvs", ")", "]", ")", "\n", "}" ]
// The implementation bellow is heavily influenced by go-kit's log context. // HandlerWith returns a new error handler with keyvals context appended to it. // If the wrapped error handler is already a contextual error handler created by HandlerWith or HandlerWithPrefix // keyvals is appended to the existing context, but a new error handler is returned. // // The created handler will prepend it's own context to the handled errors.
[ "The", "implementation", "bellow", "is", "heavily", "influenced", "by", "go", "-", "kit", "s", "log", "context", ".", "HandlerWith", "returns", "a", "new", "error", "handler", "with", "keyvals", "context", "appended", "to", "it", ".", "If", "the", "wrapped", "error", "handler", "is", "already", "a", "contextual", "error", "handler", "created", "by", "HandlerWith", "or", "HandlerWithPrefix", "keyvals", "is", "appended", "to", "the", "existing", "context", "but", "a", "new", "error", "handler", "is", "returned", ".", "The", "created", "handler", "will", "prepend", "it", "s", "own", "context", "to", "the", "handled", "errors", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler_context.go#L10-L27
2,669
goph/emperror
handler_context.go
HandlerWithPrefix
func HandlerWithPrefix(handler Handler, keyvals ...interface{}) Handler { if len(keyvals) == 0 { return handler } prevkvs, handler := extractHandlerContext(handler) n := len(prevkvs) + len(keyvals) if len(keyvals)%2 != 0 { n++ } kvs := make([]interface{}, 0, n) kvs = append(kvs, keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } kvs = append(kvs, prevkvs...) return newContextualHandler(handler, kvs) }
go
func HandlerWithPrefix(handler Handler, keyvals ...interface{}) Handler { if len(keyvals) == 0 { return handler } prevkvs, handler := extractHandlerContext(handler) n := len(prevkvs) + len(keyvals) if len(keyvals)%2 != 0 { n++ } kvs := make([]interface{}, 0, n) kvs = append(kvs, keyvals...) if len(kvs)%2 != 0 { kvs = append(kvs, nil) } kvs = append(kvs, prevkvs...) return newContextualHandler(handler, kvs) }
[ "func", "HandlerWithPrefix", "(", "handler", "Handler", ",", "keyvals", "...", "interface", "{", "}", ")", "Handler", "{", "if", "len", "(", "keyvals", ")", "==", "0", "{", "return", "handler", "\n", "}", "\n\n", "prevkvs", ",", "handler", ":=", "extractHandlerContext", "(", "handler", ")", "\n\n", "n", ":=", "len", "(", "prevkvs", ")", "+", "len", "(", "keyvals", ")", "\n", "if", "len", "(", "keyvals", ")", "%", "2", "!=", "0", "{", "n", "++", "\n", "}", "\n\n", "kvs", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "0", ",", "n", ")", "\n", "kvs", "=", "append", "(", "kvs", ",", "keyvals", "...", ")", "\n\n", "if", "len", "(", "kvs", ")", "%", "2", "!=", "0", "{", "kvs", "=", "append", "(", "kvs", ",", "nil", ")", "\n", "}", "\n\n", "kvs", "=", "append", "(", "kvs", ",", "prevkvs", "...", ")", "\n\n", "return", "newContextualHandler", "(", "handler", ",", "kvs", ")", "\n", "}" ]
// HandlerWithPrefix returns a new error handler with keyvals context prepended to it. // If the wrapped error handler is already a contextual error handler created by HandlerWith or HandlerWithPrefix // keyvals is prepended to the existing context, but a new error handler is returned. // // The created handler will prepend it's own context to the handled errors.
[ "HandlerWithPrefix", "returns", "a", "new", "error", "handler", "with", "keyvals", "context", "prepended", "to", "it", ".", "If", "the", "wrapped", "error", "handler", "is", "already", "a", "contextual", "error", "handler", "created", "by", "HandlerWith", "or", "HandlerWithPrefix", "keyvals", "is", "prepended", "to", "the", "existing", "context", "but", "a", "new", "error", "handler", "is", "returned", ".", "The", "created", "handler", "will", "prepend", "it", "s", "own", "context", "to", "the", "handled", "errors", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler_context.go#L34-L56
2,670
goph/emperror
handler_context.go
extractHandlerContext
func extractHandlerContext(handler Handler) ([]interface{}, Handler) { var kvs []interface{} if c, ok := handler.(*contextualHandler); ok { handler = c.handler kvs = c.keyvals } return kvs, handler }
go
func extractHandlerContext(handler Handler) ([]interface{}, Handler) { var kvs []interface{} if c, ok := handler.(*contextualHandler); ok { handler = c.handler kvs = c.keyvals } return kvs, handler }
[ "func", "extractHandlerContext", "(", "handler", "Handler", ")", "(", "[", "]", "interface", "{", "}", ",", "Handler", ")", "{", "var", "kvs", "[", "]", "interface", "{", "}", "\n\n", "if", "c", ",", "ok", ":=", "handler", ".", "(", "*", "contextualHandler", ")", ";", "ok", "{", "handler", "=", "c", ".", "handler", "\n", "kvs", "=", "c", ".", "keyvals", "\n", "}", "\n\n", "return", "kvs", ",", "handler", "\n", "}" ]
// extractHandlerContext extracts the context and optionally the wrapped handler when it's the same container.
[ "extractHandlerContext", "extracts", "the", "context", "and", "optionally", "the", "wrapped", "handler", "when", "it", "s", "the", "same", "container", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/handler_context.go#L59-L68
2,671
goph/emperror
cause.go
ForEachCause
func ForEachCause(err error, fn func(err error) bool) { // causer is the interface defined in github.com/pkg/errors for specifying a parent error. type causer interface { Cause() error } for err != nil { continueLoop := fn(err) if !continueLoop { break } cause, ok := err.(causer) if !ok { break } err = cause.Cause() } }
go
func ForEachCause(err error, fn func(err error) bool) { // causer is the interface defined in github.com/pkg/errors for specifying a parent error. type causer interface { Cause() error } for err != nil { continueLoop := fn(err) if !continueLoop { break } cause, ok := err.(causer) if !ok { break } err = cause.Cause() } }
[ "func", "ForEachCause", "(", "err", "error", ",", "fn", "func", "(", "err", "error", ")", "bool", ")", "{", "// causer is the interface defined in github.com/pkg/errors for specifying a parent error.", "type", "causer", "interface", "{", "Cause", "(", ")", "error", "\n", "}", "\n\n", "for", "err", "!=", "nil", "{", "continueLoop", ":=", "fn", "(", "err", ")", "\n", "if", "!", "continueLoop", "{", "break", "\n", "}", "\n\n", "cause", ",", "ok", ":=", "err", ".", "(", "causer", ")", "\n", "if", "!", "ok", "{", "break", "\n", "}", "\n\n", "err", "=", "cause", ".", "Cause", "(", ")", "\n", "}", "\n", "}" ]
// ForEachCause loops through an error chain and calls a function for each of them, // starting with the topmost one. // // The function can return false to break the loop before it ends.
[ "ForEachCause", "loops", "through", "an", "error", "chain", "and", "calls", "a", "function", "for", "each", "of", "them", "starting", "with", "the", "topmost", "one", ".", "The", "function", "can", "return", "false", "to", "break", "the", "loop", "before", "it", "ends", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/cause.go#L7-L26
2,672
goph/emperror
panic.go
Panic
func Panic(err error) { if err != nil { if _, ok := StackTrace(err); !ok { err = &wrappedError{ err: err, stack: callers(), } } panic(err) } }
go
func Panic(err error) { if err != nil { if _, ok := StackTrace(err); !ok { err = &wrappedError{ err: err, stack: callers(), } } panic(err) } }
[ "func", "Panic", "(", "err", "error", ")", "{", "if", "err", "!=", "nil", "{", "if", "_", ",", "ok", ":=", "StackTrace", "(", "err", ")", ";", "!", "ok", "{", "err", "=", "&", "wrappedError", "{", "err", ":", "err", ",", "stack", ":", "callers", "(", ")", ",", "}", "\n", "}", "\n\n", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// Panic panics if the passed error is not nil. // If the error does not contain any stack trace, the function attaches one, starting from the frame of the // "Panic" function call. // // This function is useful with HandleRecover when panic is used as a flow control tool to stop the application.
[ "Panic", "panics", "if", "the", "passed", "error", "is", "not", "nil", ".", "If", "the", "error", "does", "not", "contain", "any", "stack", "trace", "the", "function", "attaches", "one", "starting", "from", "the", "frame", "of", "the", "Panic", "function", "call", ".", "This", "function", "is", "useful", "with", "HandleRecover", "when", "panic", "is", "used", "as", "a", "flow", "control", "tool", "to", "stop", "the", "application", "." ]
ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17
https://github.com/goph/emperror/blob/ae59d9fdc3f0c4814bc5fac2d4a68441dcff5a17/panic.go#L8-L19
2,673
cloudfoundry/route-emitter
routingtable/routingtable.go
mergeUnfreshRoutes
func mergeUnfreshRoutes(before, after RoutableEndpoints, domains models.DomainSet) RoutableEndpoints { merged := after.copy() merged.Domain = before.Domain if !domains.Contains(before.Domain) { // non-fresh domain, append routes from older endpoint for _, oldRoute := range before.Routes { routeExistInNewLRP := func() bool { for _, newRoute := range after.Routes { if newRoute == oldRoute { return true } } return false } if !routeExistInNewLRP() { merged.Routes = append(merged.Routes, oldRoute) } } } return merged }
go
func mergeUnfreshRoutes(before, after RoutableEndpoints, domains models.DomainSet) RoutableEndpoints { merged := after.copy() merged.Domain = before.Domain if !domains.Contains(before.Domain) { // non-fresh domain, append routes from older endpoint for _, oldRoute := range before.Routes { routeExistInNewLRP := func() bool { for _, newRoute := range after.Routes { if newRoute == oldRoute { return true } } return false } if !routeExistInNewLRP() { merged.Routes = append(merged.Routes, oldRoute) } } } return merged }
[ "func", "mergeUnfreshRoutes", "(", "before", ",", "after", "RoutableEndpoints", ",", "domains", "models", ".", "DomainSet", ")", "RoutableEndpoints", "{", "merged", ":=", "after", ".", "copy", "(", ")", "\n", "merged", ".", "Domain", "=", "before", ".", "Domain", "\n\n", "if", "!", "domains", ".", "Contains", "(", "before", ".", "Domain", ")", "{", "// non-fresh domain, append routes from older endpoint", "for", "_", ",", "oldRoute", ":=", "range", "before", ".", "Routes", "{", "routeExistInNewLRP", ":=", "func", "(", ")", "bool", "{", "for", "_", ",", "newRoute", ":=", "range", "after", ".", "Routes", "{", "if", "newRoute", "==", "oldRoute", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "if", "!", "routeExistInNewLRP", "(", ")", "{", "merged", ".", "Routes", "=", "append", "(", "merged", ".", "Routes", ",", "oldRoute", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "merged", "\n", "}" ]
// merge the routes from both endpoints, ensuring that non-fresh routes aren't removed
[ "merge", "the", "routes", "from", "both", "endpoints", "ensuring", "that", "non", "-", "fresh", "routes", "aren", "t", "removed" ]
1a971a54af97eea7a94c6f0978bda9dafe008e40
https://github.com/cloudfoundry/route-emitter/blob/1a971a54af97eea7a94c6f0978bda9dafe008e40/routingtable/routingtable.go#L386-L408
2,674
cloudfoundry/route-emitter
routingtable/registry_message.go
InternalEndpointRegistryMessageFor
func InternalEndpointRegistryMessageFor(endpoint Endpoint, route InternalRoute, emitEndpointUpdatedAt bool) RegistryMessage { var index string if endpoint.InstanceGUID != "" { index = fmt.Sprintf("%d", endpoint.Index) } since := endpoint.Since if !emitEndpointUpdatedAt { since = 0 } return RegistryMessage{ URIs: []string{route.Hostname, fmt.Sprintf("%s.%s", index, route.Hostname)}, Host: endpoint.ContainerIP, App: route.LogGUID, Tags: map[string]string{"component": "route-emitter"}, EndpointUpdatedAtNs: since, PrivateInstanceIndex: index, } }
go
func InternalEndpointRegistryMessageFor(endpoint Endpoint, route InternalRoute, emitEndpointUpdatedAt bool) RegistryMessage { var index string if endpoint.InstanceGUID != "" { index = fmt.Sprintf("%d", endpoint.Index) } since := endpoint.Since if !emitEndpointUpdatedAt { since = 0 } return RegistryMessage{ URIs: []string{route.Hostname, fmt.Sprintf("%s.%s", index, route.Hostname)}, Host: endpoint.ContainerIP, App: route.LogGUID, Tags: map[string]string{"component": "route-emitter"}, EndpointUpdatedAtNs: since, PrivateInstanceIndex: index, } }
[ "func", "InternalEndpointRegistryMessageFor", "(", "endpoint", "Endpoint", ",", "route", "InternalRoute", ",", "emitEndpointUpdatedAt", "bool", ")", "RegistryMessage", "{", "var", "index", "string", "\n", "if", "endpoint", ".", "InstanceGUID", "!=", "\"", "\"", "{", "index", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "endpoint", ".", "Index", ")", "\n", "}", "\n", "since", ":=", "endpoint", ".", "Since", "\n", "if", "!", "emitEndpointUpdatedAt", "{", "since", "=", "0", "\n", "}", "\n", "return", "RegistryMessage", "{", "URIs", ":", "[", "]", "string", "{", "route", ".", "Hostname", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "index", ",", "route", ".", "Hostname", ")", "}", ",", "Host", ":", "endpoint", ".", "ContainerIP", ",", "App", ":", "route", ".", "LogGUID", ",", "Tags", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", "}", ",", "EndpointUpdatedAtNs", ":", "since", ",", "PrivateInstanceIndex", ":", "index", ",", "}", "\n", "}" ]
// This is used to generate registry messages for Internal routes
[ "This", "is", "used", "to", "generate", "registry", "messages", "for", "Internal", "routes" ]
1a971a54af97eea7a94c6f0978bda9dafe008e40
https://github.com/cloudfoundry/route-emitter/blob/1a971a54af97eea7a94c6f0978bda9dafe008e40/routingtable/registry_message.go#L76-L94
2,675
codahale/metrics
metrics.go
AddN
func (c Counter) AddN(delta uint64) { cm.Lock() counters[string(c)] += delta cm.Unlock() }
go
func (c Counter) AddN(delta uint64) { cm.Lock() counters[string(c)] += delta cm.Unlock() }
[ "func", "(", "c", "Counter", ")", "AddN", "(", "delta", "uint64", ")", "{", "cm", ".", "Lock", "(", ")", "\n", "counters", "[", "string", "(", "c", ")", "]", "+=", "delta", "\n", "cm", ".", "Unlock", "(", ")", "\n", "}" ]
// AddN increments the counter by N.
[ "AddN", "increments", "the", "counter", "by", "N", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L52-L56
2,676
codahale/metrics
metrics.go
SetFunc
func (c Counter) SetFunc(f func() uint64) { cm.Lock() defer cm.Unlock() counterFuncs[string(c)] = f }
go
func (c Counter) SetFunc(f func() uint64) { cm.Lock() defer cm.Unlock() counterFuncs[string(c)] = f }
[ "func", "(", "c", "Counter", ")", "SetFunc", "(", "f", "func", "(", ")", "uint64", ")", "{", "cm", ".", "Lock", "(", ")", "\n", "defer", "cm", ".", "Unlock", "(", ")", "\n\n", "counterFuncs", "[", "string", "(", "c", ")", "]", "=", "f", "\n", "}" ]
// SetFunc sets the counter's value to the lazily-called return value of the // given function.
[ "SetFunc", "sets", "the", "counter", "s", "value", "to", "the", "lazily", "-", "called", "return", "value", "of", "the", "given", "function", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L60-L65
2,677
codahale/metrics
metrics.go
SetBatchFunc
func (c Counter) SetBatchFunc(key interface{}, init func(), f func() uint64) { gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() counterFuncs[string(c)] = f if _, ok := inits[key]; !ok { inits[key] = init } }
go
func (c Counter) SetBatchFunc(key interface{}, init func(), f func() uint64) { gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() counterFuncs[string(c)] = f if _, ok := inits[key]; !ok { inits[key] = init } }
[ "func", "(", "c", "Counter", ")", "SetBatchFunc", "(", "key", "interface", "{", "}", ",", "init", "func", "(", ")", ",", "f", "func", "(", ")", "uint64", ")", "{", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "cm", ".", "Lock", "(", ")", "\n", "defer", "cm", ".", "Unlock", "(", ")", "\n\n", "counterFuncs", "[", "string", "(", "c", ")", "]", "=", "f", "\n", "if", "_", ",", "ok", ":=", "inits", "[", "key", "]", ";", "!", "ok", "{", "inits", "[", "key", "]", "=", "init", "\n", "}", "\n", "}" ]
// SetBatchFunc sets the counter's value to the lazily-called return value of // the given function, with an additional initializer function for a related // batch of counters, all of which are keyed by an arbitrary value.
[ "SetBatchFunc", "sets", "the", "counter", "s", "value", "to", "the", "lazily", "-", "called", "return", "value", "of", "the", "given", "function", "with", "an", "additional", "initializer", "function", "for", "a", "related", "batch", "of", "counters", "all", "of", "which", "are", "keyed", "by", "an", "arbitrary", "value", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L70-L81
2,678
codahale/metrics
metrics.go
Remove
func (c Counter) Remove() { gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() delete(counters, string(c)) delete(counterFuncs, string(c)) delete(inits, string(c)) }
go
func (c Counter) Remove() { gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() delete(counters, string(c)) delete(counterFuncs, string(c)) delete(inits, string(c)) }
[ "func", "(", "c", "Counter", ")", "Remove", "(", ")", "{", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "cm", ".", "Lock", "(", ")", "\n", "defer", "cm", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "counters", ",", "string", "(", "c", ")", ")", "\n", "delete", "(", "counterFuncs", ",", "string", "(", "c", ")", ")", "\n", "delete", "(", "inits", ",", "string", "(", "c", ")", ")", "\n", "}" ]
// Remove removes the given counter.
[ "Remove", "removes", "the", "given", "counter", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L84-L94
2,679
codahale/metrics
metrics.go
Set
func (g Gauge) Set(value int64) { gm.Lock() defer gm.Unlock() gauges[string(g)] = func() int64 { return value } }
go
func (g Gauge) Set(value int64) { gm.Lock() defer gm.Unlock() gauges[string(g)] = func() int64 { return value } }
[ "func", "(", "g", "Gauge", ")", "Set", "(", "value", "int64", ")", "{", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "gauges", "[", "string", "(", "g", ")", "]", "=", "func", "(", ")", "int64", "{", "return", "value", "\n", "}", "\n", "}" ]
// Set the gauge's value to the given value.
[ "Set", "the", "gauge", "s", "value", "to", "the", "given", "value", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L103-L110
2,680
codahale/metrics
metrics.go
SetFunc
func (g Gauge) SetFunc(f func() int64) { gm.Lock() defer gm.Unlock() gauges[string(g)] = f }
go
func (g Gauge) SetFunc(f func() int64) { gm.Lock() defer gm.Unlock() gauges[string(g)] = f }
[ "func", "(", "g", "Gauge", ")", "SetFunc", "(", "f", "func", "(", ")", "int64", ")", "{", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "gauges", "[", "string", "(", "g", ")", "]", "=", "f", "\n", "}" ]
// SetFunc sets the gauge's value to the lazily-called return value of the given // function.
[ "SetFunc", "sets", "the", "gauge", "s", "value", "to", "the", "lazily", "-", "called", "return", "value", "of", "the", "given", "function", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L114-L119
2,681
codahale/metrics
metrics.go
SetBatchFunc
func (g Gauge) SetBatchFunc(key interface{}, init func(), f func() int64) { gm.Lock() defer gm.Unlock() gauges[string(g)] = f if _, ok := inits[key]; !ok { inits[key] = init } }
go
func (g Gauge) SetBatchFunc(key interface{}, init func(), f func() int64) { gm.Lock() defer gm.Unlock() gauges[string(g)] = f if _, ok := inits[key]; !ok { inits[key] = init } }
[ "func", "(", "g", "Gauge", ")", "SetBatchFunc", "(", "key", "interface", "{", "}", ",", "init", "func", "(", ")", ",", "f", "func", "(", ")", "int64", ")", "{", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "gauges", "[", "string", "(", "g", ")", "]", "=", "f", "\n", "if", "_", ",", "ok", ":=", "inits", "[", "key", "]", ";", "!", "ok", "{", "inits", "[", "key", "]", "=", "init", "\n", "}", "\n", "}" ]
// SetBatchFunc sets the gauge's value to the lazily-called return value of the // given function, with an additional initializer function for a related batch // of gauges, all of which are keyed by an arbitrary value.
[ "SetBatchFunc", "sets", "the", "gauge", "s", "value", "to", "the", "lazily", "-", "called", "return", "value", "of", "the", "given", "function", "with", "an", "additional", "initializer", "function", "for", "a", "related", "batch", "of", "gauges", "all", "of", "which", "are", "keyed", "by", "an", "arbitrary", "value", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L124-L132
2,682
codahale/metrics
metrics.go
Remove
func (g Gauge) Remove() { gm.Lock() defer gm.Unlock() delete(gauges, string(g)) delete(inits, string(g)) }
go
func (g Gauge) Remove() { gm.Lock() defer gm.Unlock() delete(gauges, string(g)) delete(inits, string(g)) }
[ "func", "(", "g", "Gauge", ")", "Remove", "(", ")", "{", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "delete", "(", "gauges", ",", "string", "(", "g", ")", ")", "\n", "delete", "(", "inits", ",", "string", "(", "g", ")", ")", "\n", "}" ]
// Remove removes the given gauge.
[ "Remove", "removes", "the", "given", "gauge", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L135-L141
2,683
codahale/metrics
metrics.go
Reset
func Reset() { hm.Lock() defer hm.Unlock() gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() counters = make(map[string]uint64) counterFuncs = make(map[string]func() uint64) gauges = make(map[string]func() int64) histograms = make(map[string]*Histogram) inits = make(map[interface{}]func()) }
go
func Reset() { hm.Lock() defer hm.Unlock() gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() counters = make(map[string]uint64) counterFuncs = make(map[string]func() uint64) gauges = make(map[string]func() int64) histograms = make(map[string]*Histogram) inits = make(map[interface{}]func()) }
[ "func", "Reset", "(", ")", "{", "hm", ".", "Lock", "(", ")", "\n", "defer", "hm", ".", "Unlock", "(", ")", "\n\n", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "cm", ".", "Lock", "(", ")", "\n", "defer", "cm", ".", "Unlock", "(", ")", "\n\n", "counters", "=", "make", "(", "map", "[", "string", "]", "uint64", ")", "\n", "counterFuncs", "=", "make", "(", "map", "[", "string", "]", "func", "(", ")", "uint64", ")", "\n", "gauges", "=", "make", "(", "map", "[", "string", "]", "func", "(", ")", "int64", ")", "\n", "histograms", "=", "make", "(", "map", "[", "string", "]", "*", "Histogram", ")", "\n", "inits", "=", "make", "(", "map", "[", "interface", "{", "}", "]", "func", "(", ")", ")", "\n", "}" ]
// Reset removes all existing counters and gauges.
[ "Reset", "removes", "all", "existing", "counters", "and", "gauges", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L144-L159
2,684
codahale/metrics
metrics.go
Snapshot
func Snapshot() (c map[string]uint64, g map[string]int64) { hm.Lock() defer hm.Unlock() gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() for _, init := range inits { init() } c = make(map[string]uint64, len(counters)+len(counterFuncs)) for n, v := range counters { c[n] = v } for n, f := range counterFuncs { c[n] = f() } g = make(map[string]int64, len(gauges)) for n, f := range gauges { g[n] = f() } return }
go
func Snapshot() (c map[string]uint64, g map[string]int64) { hm.Lock() defer hm.Unlock() gm.Lock() defer gm.Unlock() cm.Lock() defer cm.Unlock() for _, init := range inits { init() } c = make(map[string]uint64, len(counters)+len(counterFuncs)) for n, v := range counters { c[n] = v } for n, f := range counterFuncs { c[n] = f() } g = make(map[string]int64, len(gauges)) for n, f := range gauges { g[n] = f() } return }
[ "func", "Snapshot", "(", ")", "(", "c", "map", "[", "string", "]", "uint64", ",", "g", "map", "[", "string", "]", "int64", ")", "{", "hm", ".", "Lock", "(", ")", "\n", "defer", "hm", ".", "Unlock", "(", ")", "\n\n", "gm", ".", "Lock", "(", ")", "\n", "defer", "gm", ".", "Unlock", "(", ")", "\n\n", "cm", ".", "Lock", "(", ")", "\n", "defer", "cm", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "init", ":=", "range", "inits", "{", "init", "(", ")", "\n", "}", "\n\n", "c", "=", "make", "(", "map", "[", "string", "]", "uint64", ",", "len", "(", "counters", ")", "+", "len", "(", "counterFuncs", ")", ")", "\n", "for", "n", ",", "v", ":=", "range", "counters", "{", "c", "[", "n", "]", "=", "v", "\n", "}", "\n\n", "for", "n", ",", "f", ":=", "range", "counterFuncs", "{", "c", "[", "n", "]", "=", "f", "(", ")", "\n", "}", "\n\n", "g", "=", "make", "(", "map", "[", "string", "]", "int64", ",", "len", "(", "gauges", ")", ")", "\n", "for", "n", ",", "f", ":=", "range", "gauges", "{", "g", "[", "n", "]", "=", "f", "(", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// Snapshot returns a copy of the values of all registered counters and gauges.
[ "Snapshot", "returns", "a", "copy", "of", "the", "values", "of", "all", "registered", "counters", "and", "gauges", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L162-L191
2,685
codahale/metrics
metrics.go
Remove
func (h *Histogram) Remove() { hm.Lock() defer hm.Unlock() Gauge(h.name + ".P50").Remove() Gauge(h.name + ".P75").Remove() Gauge(h.name + ".P90").Remove() Gauge(h.name + ".P95").Remove() Gauge(h.name + ".P99").Remove() Gauge(h.name + ".P999").Remove() delete(histograms, h.name) }
go
func (h *Histogram) Remove() { hm.Lock() defer hm.Unlock() Gauge(h.name + ".P50").Remove() Gauge(h.name + ".P75").Remove() Gauge(h.name + ".P90").Remove() Gauge(h.name + ".P95").Remove() Gauge(h.name + ".P99").Remove() Gauge(h.name + ".P999").Remove() delete(histograms, h.name) }
[ "func", "(", "h", "*", "Histogram", ")", "Remove", "(", ")", "{", "hm", ".", "Lock", "(", ")", "\n", "defer", "hm", ".", "Unlock", "(", ")", "\n\n", "Gauge", "(", "h", ".", "name", "+", "\"", "\"", ")", ".", "Remove", "(", ")", "\n", "Gauge", "(", "h", ".", "name", "+", "\"", "\"", ")", ".", "Remove", "(", ")", "\n", "Gauge", "(", "h", ".", "name", "+", "\"", "\"", ")", ".", "Remove", "(", ")", "\n", "Gauge", "(", "h", ".", "name", "+", "\"", "\"", ")", ".", "Remove", "(", ")", "\n", "Gauge", "(", "h", ".", "name", "+", "\"", "\"", ")", ".", "Remove", "(", ")", "\n", "Gauge", "(", "h", ".", "name", "+", "\"", "\"", ")", ".", "Remove", "(", ")", "\n\n", "delete", "(", "histograms", ",", "h", ".", "name", ")", "\n", "}" ]
// Remove removes the given histogram.
[ "Remove", "removes", "the", "given", "histogram", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L223-L236
2,686
codahale/metrics
metrics.go
RecordValue
func (h *Histogram) RecordValue(v int64) error { h.rw.Lock() defer h.rw.Unlock() err := h.hist.Current.RecordValue(v) if err != nil { return Error{h.name, err} } return nil }
go
func (h *Histogram) RecordValue(v int64) error { h.rw.Lock() defer h.rw.Unlock() err := h.hist.Current.RecordValue(v) if err != nil { return Error{h.name, err} } return nil }
[ "func", "(", "h", "*", "Histogram", ")", "RecordValue", "(", "v", "int64", ")", "error", "{", "h", ".", "rw", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "rw", ".", "Unlock", "(", ")", "\n\n", "err", ":=", "h", ".", "hist", ".", "Current", ".", "RecordValue", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Error", "{", "h", ".", "name", ",", "err", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RecordValue records the given value, or returns an error if the value is out // of range. // Returned error values are of type Error.
[ "RecordValue", "records", "the", "given", "value", "or", "returns", "an", "error", "if", "the", "value", "is", "out", "of", "range", ".", "Returned", "error", "values", "are", "of", "type", "Error", "." ]
bc2005d86c7922adc3dd228f42f16015d8132ac8
https://github.com/codahale/metrics/blob/bc2005d86c7922adc3dd228f42f16015d8132ac8/metrics.go#L256-L265
2,687
ipfs/go-ipld-cbor
encoding/cloner.go
NewPooledCloner
func NewPooledCloner(atl atlas.Atlas) PooledCloner { return PooledCloner{ pool: sync.Pool{ New: func() interface{} { return refmt.NewCloner(atl) }, }, } }
go
func NewPooledCloner(atl atlas.Atlas) PooledCloner { return PooledCloner{ pool: sync.Pool{ New: func() interface{} { return refmt.NewCloner(atl) }, }, } }
[ "func", "NewPooledCloner", "(", "atl", "atlas", ".", "Atlas", ")", "PooledCloner", "{", "return", "PooledCloner", "{", "pool", ":", "sync", ".", "Pool", "{", "New", ":", "func", "(", ")", "interface", "{", "}", "{", "return", "refmt", ".", "NewCloner", "(", "atl", ")", "\n", "}", ",", "}", ",", "}", "\n", "}" ]
// NewPooledCloner returns a PooledCloner with the given atlas. Do not copy // after use.
[ "NewPooledCloner", "returns", "a", "PooledCloner", "with", "the", "given", "atlas", ".", "Do", "not", "copy", "after", "use", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/encoding/cloner.go#L17-L25
2,688
ipfs/go-ipld-cbor
encoding/cloner.go
Clone
func (p *PooledCloner) Clone(a, b interface{}) error { c := p.pool.Get().(refmt.Cloner) err := c.Clone(a, b) p.pool.Put(c) return err }
go
func (p *PooledCloner) Clone(a, b interface{}) error { c := p.pool.Get().(refmt.Cloner) err := c.Clone(a, b) p.pool.Put(c) return err }
[ "func", "(", "p", "*", "PooledCloner", ")", "Clone", "(", "a", ",", "b", "interface", "{", "}", ")", "error", "{", "c", ":=", "p", ".", "pool", ".", "Get", "(", ")", ".", "(", "refmt", ".", "Cloner", ")", "\n", "err", ":=", "c", ".", "Clone", "(", "a", ",", "b", ")", "\n", "p", ".", "pool", ".", "Put", "(", "c", ")", "\n", "return", "err", "\n", "}" ]
// Clone clones a into b using a cloner from the pool.
[ "Clone", "clones", "a", "into", "b", "using", "a", "cloner", "from", "the", "pool", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/encoding/cloner.go#L28-L33
2,689
ipfs/go-ipld-cbor
refmt.go
RegisterCborType
func RegisterCborType(i interface{}) { var entry *atlas.AtlasEntry if ae, ok := i.(*atlas.AtlasEntry); ok { entry = ae } else { entry = atlas.BuildEntry(i).StructMap().AutogenerateWithSortingScheme(atlas.KeySortMode_RFC7049).Complete() } atlasEntries = append(atlasEntries, entry) rebuildAtlas() }
go
func RegisterCborType(i interface{}) { var entry *atlas.AtlasEntry if ae, ok := i.(*atlas.AtlasEntry); ok { entry = ae } else { entry = atlas.BuildEntry(i).StructMap().AutogenerateWithSortingScheme(atlas.KeySortMode_RFC7049).Complete() } atlasEntries = append(atlasEntries, entry) rebuildAtlas() }
[ "func", "RegisterCborType", "(", "i", "interface", "{", "}", ")", "{", "var", "entry", "*", "atlas", ".", "AtlasEntry", "\n", "if", "ae", ",", "ok", ":=", "i", ".", "(", "*", "atlas", ".", "AtlasEntry", ")", ";", "ok", "{", "entry", "=", "ae", "\n", "}", "else", "{", "entry", "=", "atlas", ".", "BuildEntry", "(", "i", ")", ".", "StructMap", "(", ")", ".", "AutogenerateWithSortingScheme", "(", "atlas", ".", "KeySortMode_RFC7049", ")", ".", "Complete", "(", ")", "\n", "}", "\n", "atlasEntries", "=", "append", "(", "atlasEntries", ",", "entry", ")", "\n", "rebuildAtlas", "(", ")", "\n", "}" ]
// RegisterCborType allows to register a custom cbor type
[ "RegisterCborType", "allows", "to", "register", "a", "custom", "cbor", "type" ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/refmt.go#L63-L72
2,690
ipfs/go-ipld-cbor
readable.go
HumanReadable
func HumanReadable(blob []byte) (string, error) { reader := bytes.NewReader(blob) var buf bytes.Buffer writer := bufio.NewWriter(&buf) err := shared.TokenPump{ TokenSource: cbor.NewDecoder(cbor.DecodeOptions{}, reader), TokenSink: pretty.NewEncoder(writer), }.Run() if err != nil { return "", err } if err = writer.Flush(); err != nil { return "", err } return buf.String(), nil }
go
func HumanReadable(blob []byte) (string, error) { reader := bytes.NewReader(blob) var buf bytes.Buffer writer := bufio.NewWriter(&buf) err := shared.TokenPump{ TokenSource: cbor.NewDecoder(cbor.DecodeOptions{}, reader), TokenSink: pretty.NewEncoder(writer), }.Run() if err != nil { return "", err } if err = writer.Flush(); err != nil { return "", err } return buf.String(), nil }
[ "func", "HumanReadable", "(", "blob", "[", "]", "byte", ")", "(", "string", ",", "error", ")", "{", "reader", ":=", "bytes", ".", "NewReader", "(", "blob", ")", "\n\n", "var", "buf", "bytes", ".", "Buffer", "\n", "writer", ":=", "bufio", ".", "NewWriter", "(", "&", "buf", ")", "\n\n", "err", ":=", "shared", ".", "TokenPump", "{", "TokenSource", ":", "cbor", ".", "NewDecoder", "(", "cbor", ".", "DecodeOptions", "{", "}", ",", "reader", ")", ",", "TokenSink", ":", "pretty", ".", "NewEncoder", "(", "writer", ")", ",", "}", ".", "Run", "(", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "err", "=", "writer", ".", "Flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "buf", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
//HumanReadable returns a string representation of a CBOR blob
[ "HumanReadable", "returns", "a", "string", "representation", "of", "a", "CBOR", "blob" ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/readable.go#L13-L33
2,691
ipfs/go-ipld-cbor
node.go
WrapObject
func WrapObject(m interface{}, mhType uint64, mhLen int) (*Node, error) { data, err := marshaller.Marshal(m) if err != nil { return nil, err } var obj interface{} err = cloner.Clone(m, &obj) if err != nil { return nil, err } if mhType == math.MaxUint64 { mhType = mh.SHA2_256 } hash, err := mh.Sum(data, mhType, mhLen) if err != nil { return nil, err } c := cid.NewCidV1(cid.DagCBOR, hash) block, err := blocks.NewBlockWithCid(data, c) if err != nil { // TODO: Shouldn't this just panic? return nil, err } // No need to deserialize. We can just deep copy. return newObject(block, obj) }
go
func WrapObject(m interface{}, mhType uint64, mhLen int) (*Node, error) { data, err := marshaller.Marshal(m) if err != nil { return nil, err } var obj interface{} err = cloner.Clone(m, &obj) if err != nil { return nil, err } if mhType == math.MaxUint64 { mhType = mh.SHA2_256 } hash, err := mh.Sum(data, mhType, mhLen) if err != nil { return nil, err } c := cid.NewCidV1(cid.DagCBOR, hash) block, err := blocks.NewBlockWithCid(data, c) if err != nil { // TODO: Shouldn't this just panic? return nil, err } // No need to deserialize. We can just deep copy. return newObject(block, obj) }
[ "func", "WrapObject", "(", "m", "interface", "{", "}", ",", "mhType", "uint64", ",", "mhLen", "int", ")", "(", "*", "Node", ",", "error", ")", "{", "data", ",", "err", ":=", "marshaller", ".", "Marshal", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "obj", "interface", "{", "}", "\n", "err", "=", "cloner", ".", "Clone", "(", "m", ",", "&", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "mhType", "==", "math", ".", "MaxUint64", "{", "mhType", "=", "mh", ".", "SHA2_256", "\n", "}", "\n\n", "hash", ",", "err", ":=", "mh", ".", "Sum", "(", "data", ",", "mhType", ",", "mhLen", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ":=", "cid", ".", "NewCidV1", "(", "cid", ".", "DagCBOR", ",", "hash", ")", "\n\n", "block", ",", "err", ":=", "blocks", ".", "NewBlockWithCid", "(", "data", ",", "c", ")", "\n", "if", "err", "!=", "nil", "{", "// TODO: Shouldn't this just panic?", "return", "nil", ",", "err", "\n", "}", "\n", "// No need to deserialize. We can just deep copy.", "return", "newObject", "(", "block", ",", "obj", ")", "\n", "}" ]
// WrapObject converts an arbitrary object into a Node.
[ "WrapObject", "converts", "an", "arbitrary", "object", "into", "a", "Node", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L112-L141
2,692
ipfs/go-ipld-cbor
node.go
Resolve
func (n *Node) Resolve(path []string) (interface{}, []string, error) { var cur interface{} = n.obj for i, val := range path { switch curv := cur.(type) { case map[string]interface{}: next, ok := curv[val] if !ok { return nil, nil, ErrNoSuchLink } cur = next case map[interface{}]interface{}: next, ok := curv[val] if !ok { return nil, nil, ErrNoSuchLink } cur = next case []interface{}: n, err := strconv.Atoi(val) if err != nil { return nil, nil, err } if n < 0 || n >= len(curv) { return nil, nil, ErrArrayOutOfRange } cur = curv[n] case cid.Cid: return &node.Link{Cid: curv}, path[i:], nil default: return nil, nil, ErrNoLinks } } lnk, ok := cur.(cid.Cid) if ok { return &node.Link{Cid: lnk}, nil, nil } jsonish, err := convertToJSONIsh(cur) if err != nil { return nil, nil, err } return jsonish, nil, nil }
go
func (n *Node) Resolve(path []string) (interface{}, []string, error) { var cur interface{} = n.obj for i, val := range path { switch curv := cur.(type) { case map[string]interface{}: next, ok := curv[val] if !ok { return nil, nil, ErrNoSuchLink } cur = next case map[interface{}]interface{}: next, ok := curv[val] if !ok { return nil, nil, ErrNoSuchLink } cur = next case []interface{}: n, err := strconv.Atoi(val) if err != nil { return nil, nil, err } if n < 0 || n >= len(curv) { return nil, nil, ErrArrayOutOfRange } cur = curv[n] case cid.Cid: return &node.Link{Cid: curv}, path[i:], nil default: return nil, nil, ErrNoLinks } } lnk, ok := cur.(cid.Cid) if ok { return &node.Link{Cid: lnk}, nil, nil } jsonish, err := convertToJSONIsh(cur) if err != nil { return nil, nil, err } return jsonish, nil, nil }
[ "func", "(", "n", "*", "Node", ")", "Resolve", "(", "path", "[", "]", "string", ")", "(", "interface", "{", "}", ",", "[", "]", "string", ",", "error", ")", "{", "var", "cur", "interface", "{", "}", "=", "n", ".", "obj", "\n", "for", "i", ",", "val", ":=", "range", "path", "{", "switch", "curv", ":=", "cur", ".", "(", "type", ")", "{", "case", "map", "[", "string", "]", "interface", "{", "}", ":", "next", ",", "ok", ":=", "curv", "[", "val", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "nil", ",", "ErrNoSuchLink", "\n", "}", "\n\n", "cur", "=", "next", "\n", "case", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", ":", "next", ",", "ok", ":=", "curv", "[", "val", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "nil", ",", "ErrNoSuchLink", "\n", "}", "\n\n", "cur", "=", "next", "\n", "case", "[", "]", "interface", "{", "}", ":", "n", ",", "err", ":=", "strconv", ".", "Atoi", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "if", "n", "<", "0", "||", "n", ">=", "len", "(", "curv", ")", "{", "return", "nil", ",", "nil", ",", "ErrArrayOutOfRange", "\n", "}", "\n\n", "cur", "=", "curv", "[", "n", "]", "\n", "case", "cid", ".", "Cid", ":", "return", "&", "node", ".", "Link", "{", "Cid", ":", "curv", "}", ",", "path", "[", "i", ":", "]", ",", "nil", "\n", "default", ":", "return", "nil", ",", "nil", ",", "ErrNoLinks", "\n", "}", "\n", "}", "\n\n", "lnk", ",", "ok", ":=", "cur", ".", "(", "cid", ".", "Cid", ")", "\n", "if", "ok", "{", "return", "&", "node", ".", "Link", "{", "Cid", ":", "lnk", "}", ",", "nil", ",", "nil", "\n", "}", "\n\n", "jsonish", ",", "err", ":=", "convertToJSONIsh", "(", "cur", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "return", "jsonish", ",", "nil", ",", "nil", "\n", "}" ]
// Resolve resolves a given path, and returns the object found at the end, as well // as the possible tail of the path that was not resolved.
[ "Resolve", "resolves", "a", "given", "path", "and", "returns", "the", "object", "found", "at", "the", "end", "as", "well", "as", "the", "possible", "tail", "of", "the", "path", "that", "was", "not", "resolved", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L145-L192
2,693
ipfs/go-ipld-cbor
node.go
Copy
func (n *Node) Copy() node.Node { links := make([]*node.Link, len(n.links)) copy(links, n.links) raw := make([]byte, len(n.raw)) copy(raw, n.raw) tree := make([]string, len(n.tree)) copy(tree, n.tree) return &Node{ obj: copyObj(n.obj), links: links, raw: raw, tree: tree, cid: n.cid, } }
go
func (n *Node) Copy() node.Node { links := make([]*node.Link, len(n.links)) copy(links, n.links) raw := make([]byte, len(n.raw)) copy(raw, n.raw) tree := make([]string, len(n.tree)) copy(tree, n.tree) return &Node{ obj: copyObj(n.obj), links: links, raw: raw, tree: tree, cid: n.cid, } }
[ "func", "(", "n", "*", "Node", ")", "Copy", "(", ")", "node", ".", "Node", "{", "links", ":=", "make", "(", "[", "]", "*", "node", ".", "Link", ",", "len", "(", "n", ".", "links", ")", ")", "\n", "copy", "(", "links", ",", "n", ".", "links", ")", "\n\n", "raw", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "n", ".", "raw", ")", ")", "\n", "copy", "(", "raw", ",", "n", ".", "raw", ")", "\n\n", "tree", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "n", ".", "tree", ")", ")", "\n", "copy", "(", "tree", ",", "n", ".", "tree", ")", "\n\n", "return", "&", "Node", "{", "obj", ":", "copyObj", "(", "n", ".", "obj", ")", ",", "links", ":", "links", ",", "raw", ":", "raw", ",", "tree", ":", "tree", ",", "cid", ":", "n", ".", "cid", ",", "}", "\n", "}" ]
// Copy creates a copy of the Node.
[ "Copy", "creates", "a", "copy", "of", "the", "Node", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L195-L212
2,694
ipfs/go-ipld-cbor
node.go
ResolveLink
func (n *Node) ResolveLink(path []string) (*node.Link, []string, error) { obj, rest, err := n.Resolve(path) if err != nil { return nil, nil, err } lnk, ok := obj.(*node.Link) if !ok { return nil, rest, ErrNonLink } return lnk, rest, nil }
go
func (n *Node) ResolveLink(path []string) (*node.Link, []string, error) { obj, rest, err := n.Resolve(path) if err != nil { return nil, nil, err } lnk, ok := obj.(*node.Link) if !ok { return nil, rest, ErrNonLink } return lnk, rest, nil }
[ "func", "(", "n", "*", "Node", ")", "ResolveLink", "(", "path", "[", "]", "string", ")", "(", "*", "node", ".", "Link", ",", "[", "]", "string", ",", "error", ")", "{", "obj", ",", "rest", ",", "err", ":=", "n", ".", "Resolve", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "lnk", ",", "ok", ":=", "obj", ".", "(", "*", "node", ".", "Link", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "rest", ",", "ErrNonLink", "\n", "}", "\n\n", "return", "lnk", ",", "rest", ",", "nil", "\n", "}" ]
// ResolveLink resolves a path and returns the raw Link at the end, as well as // the possible tail of the path that was not resolved.
[ "ResolveLink", "resolves", "a", "path", "and", "returns", "the", "raw", "Link", "at", "the", "end", "as", "well", "as", "the", "possible", "tail", "of", "the", "path", "that", "was", "not", "resolved", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L244-L256
2,695
ipfs/go-ipld-cbor
node.go
Tree
func (n *Node) Tree(path string, depth int) []string { if path == "" && depth == -1 { return n.tree } var out []string for _, t := range n.tree { if !strings.HasPrefix(t, path) { continue } sub := strings.TrimLeft(t[len(path):], "/") if sub == "" { continue } if depth < 0 { out = append(out, sub) continue } parts := strings.Split(sub, "/") if len(parts) <= depth { out = append(out, sub) } } return out }
go
func (n *Node) Tree(path string, depth int) []string { if path == "" && depth == -1 { return n.tree } var out []string for _, t := range n.tree { if !strings.HasPrefix(t, path) { continue } sub := strings.TrimLeft(t[len(path):], "/") if sub == "" { continue } if depth < 0 { out = append(out, sub) continue } parts := strings.Split(sub, "/") if len(parts) <= depth { out = append(out, sub) } } return out }
[ "func", "(", "n", "*", "Node", ")", "Tree", "(", "path", "string", ",", "depth", "int", ")", "[", "]", "string", "{", "if", "path", "==", "\"", "\"", "&&", "depth", "==", "-", "1", "{", "return", "n", ".", "tree", "\n", "}", "\n\n", "var", "out", "[", "]", "string", "\n", "for", "_", ",", "t", ":=", "range", "n", ".", "tree", "{", "if", "!", "strings", ".", "HasPrefix", "(", "t", ",", "path", ")", "{", "continue", "\n", "}", "\n\n", "sub", ":=", "strings", ".", "TrimLeft", "(", "t", "[", "len", "(", "path", ")", ":", "]", ",", "\"", "\"", ")", "\n", "if", "sub", "==", "\"", "\"", "{", "continue", "\n", "}", "\n\n", "if", "depth", "<", "0", "{", "out", "=", "append", "(", "out", ",", "sub", ")", "\n", "continue", "\n", "}", "\n\n", "parts", ":=", "strings", ".", "Split", "(", "sub", ",", "\"", "\"", ")", "\n", "if", "len", "(", "parts", ")", "<=", "depth", "{", "out", "=", "append", "(", "out", ",", "sub", ")", "\n", "}", "\n", "}", "\n", "return", "out", "\n", "}" ]
// Tree returns a flattend array of paths at the given path for the given depth.
[ "Tree", "returns", "a", "flattend", "array", "of", "paths", "at", "the", "given", "path", "for", "the", "given", "depth", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L259-L286
2,696
ipfs/go-ipld-cbor
node.go
Size
func (n *Node) Size() (uint64, error) { return uint64(len(n.RawData())), nil }
go
func (n *Node) Size() (uint64, error) { return uint64(len(n.RawData())), nil }
[ "func", "(", "n", "*", "Node", ")", "Size", "(", ")", "(", "uint64", ",", "error", ")", "{", "return", "uint64", "(", "len", "(", "n", ".", "RawData", "(", ")", ")", ")", ",", "nil", "\n", "}" ]
// Size returns the size of the binary representation of the Node.
[ "Size", "returns", "the", "size", "of", "the", "binary", "representation", "of", "the", "Node", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L368-L370
2,697
ipfs/go-ipld-cbor
node.go
MarshalJSON
func (n *Node) MarshalJSON() ([]byte, error) { out, err := convertToJSONIsh(n.obj) if err != nil { return nil, err } return json.Marshal(out) }
go
func (n *Node) MarshalJSON() ([]byte, error) { out, err := convertToJSONIsh(n.obj) if err != nil { return nil, err } return json.Marshal(out) }
[ "func", "(", "n", "*", "Node", ")", "MarshalJSON", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "out", ",", "err", ":=", "convertToJSONIsh", "(", "n", ".", "obj", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "json", ".", "Marshal", "(", "out", ")", "\n", "}" ]
// MarshalJSON converts the Node into its JSON representation.
[ "MarshalJSON", "converts", "the", "Node", "into", "its", "JSON", "representation", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L384-L391
2,698
ipfs/go-ipld-cbor
node.go
FromJSON
func FromJSON(r io.Reader, mhType uint64, mhLen int) (*Node, error) { var m interface{} err := json.NewDecoder(r).Decode(&m) if err != nil { return nil, err } obj, err := convertToCborIshObj(m) if err != nil { return nil, err } return WrapObject(obj, mhType, mhLen) }
go
func FromJSON(r io.Reader, mhType uint64, mhLen int) (*Node, error) { var m interface{} err := json.NewDecoder(r).Decode(&m) if err != nil { return nil, err } obj, err := convertToCborIshObj(m) if err != nil { return nil, err } return WrapObject(obj, mhType, mhLen) }
[ "func", "FromJSON", "(", "r", "io", ".", "Reader", ",", "mhType", "uint64", ",", "mhLen", "int", ")", "(", "*", "Node", ",", "error", ")", "{", "var", "m", "interface", "{", "}", "\n", "err", ":=", "json", ".", "NewDecoder", "(", "r", ")", ".", "Decode", "(", "&", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "obj", ",", "err", ":=", "convertToCborIshObj", "(", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "WrapObject", "(", "obj", ",", "mhType", ",", "mhLen", ")", "\n", "}" ]
// FromJSON converts incoming JSON into a Node.
[ "FromJSON", "converts", "incoming", "JSON", "into", "a", "Node", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/node.go#L455-L468
2,699
ipfs/go-ipld-cbor
encoding/marshaller.go
NewMarshallerAtlased
func NewMarshallerAtlased(atl atlas.Atlas) *Marshaller { m := new(Marshaller) m.marshal = cbor.NewMarshallerAtlased(&m.writer, atl) return m }
go
func NewMarshallerAtlased(atl atlas.Atlas) *Marshaller { m := new(Marshaller) m.marshal = cbor.NewMarshallerAtlased(&m.writer, atl) return m }
[ "func", "NewMarshallerAtlased", "(", "atl", "atlas", ".", "Atlas", ")", "*", "Marshaller", "{", "m", ":=", "new", "(", "Marshaller", ")", "\n", "m", ".", "marshal", "=", "cbor", ".", "NewMarshallerAtlased", "(", "&", "m", ".", "writer", ",", "atl", ")", "\n", "return", "m", "\n", "}" ]
// NewMarshallerAtlased constructs a new cbor Marshaller using the given atlas.
[ "NewMarshallerAtlased", "constructs", "a", "new", "cbor", "Marshaller", "using", "the", "given", "atlas", "." ]
59d81622555073ee8fdb6eed13c728a1fedeb724
https://github.com/ipfs/go-ipld-cbor/blob/59d81622555073ee8fdb6eed13c728a1fedeb724/encoding/marshaller.go#L27-L31