id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
142,300
voxelbrain/goptions
flagset.go
PrintHelp
func (fs *FlagSet) PrintHelp(w io.Writer) { fs.HelpFunc(w, fs) }
go
func (fs *FlagSet) PrintHelp(w io.Writer) { fs.HelpFunc(w, fs) }
[ "func", "(", "fs", "*", "FlagSet", ")", "PrintHelp", "(", "w", "io", ".", "Writer", ")", "{", "fs", ".", "HelpFunc", "(", "w", ",", "fs", ")", "\n", "}" ]
// Prints the FlagSet's help to the given writer.
[ "Prints", "the", "FlagSet", "s", "help", "to", "the", "given", "writer", "." ]
58cddc247ea2f1b0d682decc39f2aec8c6ff0d00
https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/flagset.go#L218-L220
142,301
voxelbrain/goptions
mutexgroup.go
IsObligatory
func (mg MutexGroup) IsObligatory() bool { for _, flag := range mg { if flag.Obligatory { return true } } return false }
go
func (mg MutexGroup) IsObligatory() bool { for _, flag := range mg { if flag.Obligatory { return true } } return false }
[ "func", "(", "mg", "MutexGroup", ")", "IsObligatory", "(", ")", "bool", "{", "for", "_", ",", "flag", ":=", "range", "mg", "{", "if", "flag", ".", "Obligatory", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// IsObligatory returns true if exactly one of the flags in the MutexGroup has // to be specified
[ "IsObligatory", "returns", "true", "if", "exactly", "one", "of", "the", "flags", "in", "the", "MutexGroup", "has", "to", "be", "specified" ]
58cddc247ea2f1b0d682decc39f2aec8c6ff0d00
https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/mutexgroup.go#L9-L16
142,302
voxelbrain/goptions
mutexgroup.go
Names
func (mg MutexGroup) Names() []string { r := make([]string, len(mg)) for i, flag := range mg { r[i] = flag.Name() } return r }
go
func (mg MutexGroup) Names() []string { r := make([]string, len(mg)) for i, flag := range mg { r[i] = flag.Name() } return r }
[ "func", "(", "mg", "MutexGroup", ")", "Names", "(", ")", "[", "]", "string", "{", "r", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "mg", ")", ")", "\n", "for", "i", ",", "flag", ":=", "range", "mg", "{", "r", "[", "i", "]", "=",...
// Names is a convenience function to return the array of names of the flags // in the MutexGroup.
[ "Names", "is", "a", "convenience", "function", "to", "return", "the", "array", "of", "names", "of", "the", "flags", "in", "the", "MutexGroup", "." ]
58cddc247ea2f1b0d682decc39f2aec8c6ff0d00
https://github.com/voxelbrain/goptions/blob/58cddc247ea2f1b0d682decc39f2aec8c6ff0d00/mutexgroup.go#L42-L48
142,303
willfaught/gockle
batch.go
Add
func (m BatchMock) Add(statement string, arguments ...interface{}) { m.Called(statement, arguments) }
go
func (m BatchMock) Add(statement string, arguments ...interface{}) { m.Called(statement, arguments) }
[ "func", "(", "m", "BatchMock", ")", "Add", "(", "statement", "string", ",", "arguments", "...", "interface", "{", "}", ")", "{", "m", ".", "Called", "(", "statement", ",", "arguments", ")", "\n", "}" ]
// Add implements Batch.
[ "Add", "implements", "Batch", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/batch.go#L56-L58
142,304
willfaught/gockle
batch.go
ExecTx
func (m BatchMock) ExecTx() ([]map[string]interface{}, error) { var r = m.Called() return r.Get(0).([]map[string]interface{}), r.Error(1) }
go
func (m BatchMock) ExecTx() ([]map[string]interface{}, error) { var r = m.Called() return r.Get(0).([]map[string]interface{}), r.Error(1) }
[ "func", "(", "m", "BatchMock", ")", "ExecTx", "(", ")", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "var", "r", "=", "m", ".", "Called", "(", ")", "\n\n", "return", "r", ".", "Get", "(", "0", ")", ...
// ExecTx implements Batch.
[ "ExecTx", "implements", "Batch", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/batch.go#L66-L70
142,305
willfaught/gockle
iterator.go
ScanMap
func (m IteratorMock) ScanMap(results map[string]interface{}) bool { return m.Called(results).Bool(0) }
go
func (m IteratorMock) ScanMap(results map[string]interface{}) bool { return m.Called(results).Bool(0) }
[ "func", "(", "m", "IteratorMock", ")", "ScanMap", "(", "results", "map", "[", "string", "]", "interface", "{", "}", ")", "bool", "{", "return", "m", ".", "Called", "(", "results", ")", ".", "Bool", "(", "0", ")", "\n", "}" ]
// ScanMap implements Iterator.
[ "ScanMap", "implements", "Iterator", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/iterator.go#L43-L45
142,306
willfaught/gockle
session.go
NewSimpleSession
func NewSimpleSession(hosts ...string) (Session, error) { var c = gocql.NewCluster(hosts...) c.ProtoVersion = 4 var s, err = c.CreateSession() if err != nil { return nil, err } return session{s: s}, nil }
go
func NewSimpleSession(hosts ...string) (Session, error) { var c = gocql.NewCluster(hosts...) c.ProtoVersion = 4 var s, err = c.CreateSession() if err != nil { return nil, err } return session{s: s}, nil }
[ "func", "NewSimpleSession", "(", "hosts", "...", "string", ")", "(", "Session", ",", "error", ")", "{", "var", "c", "=", "gocql", ".", "NewCluster", "(", "hosts", "...", ")", "\n\n", "c", ".", "ProtoVersion", "=", "4", "\n\n", "var", "s", ",", "err",...
// NewSimpleSession returns a new Session for hosts. It uses native protocol // version 4.
[ "NewSimpleSession", "returns", "a", "new", "Session", "for", "hosts", ".", "It", "uses", "native", "protocol", "version", "4", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L79-L91
142,307
willfaught/gockle
session.go
Batch
func (m SessionMock) Batch(kind BatchKind) Batch { return m.Called(kind).Get(0).(Batch) }
go
func (m SessionMock) Batch(kind BatchKind) Batch { return m.Called(kind).Get(0).(Batch) }
[ "func", "(", "m", "SessionMock", ")", "Batch", "(", "kind", "BatchKind", ")", "Batch", "{", "return", "m", ".", "Called", "(", "kind", ")", ".", "Get", "(", "0", ")", ".", "(", "Batch", ")", "\n", "}" ]
// Batch implements Session.
[ "Batch", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L99-L101
142,308
willfaught/gockle
session.go
Columns
func (m SessionMock) Columns(keyspace, table string) (map[string]gocql.TypeInfo, error) { var r = m.Called(keyspace, table) return r.Get(0).(map[string]gocql.TypeInfo), r.Error(1) }
go
func (m SessionMock) Columns(keyspace, table string) (map[string]gocql.TypeInfo, error) { var r = m.Called(keyspace, table) return r.Get(0).(map[string]gocql.TypeInfo), r.Error(1) }
[ "func", "(", "m", "SessionMock", ")", "Columns", "(", "keyspace", ",", "table", "string", ")", "(", "map", "[", "string", "]", "gocql", ".", "TypeInfo", ",", "error", ")", "{", "var", "r", "=", "m", ".", "Called", "(", "keyspace", ",", "table", ")"...
// Columns implements Session.
[ "Columns", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L109-L113
142,309
willfaught/gockle
session.go
Exec
func (m SessionMock) Exec(statement string, arguments ...interface{}) error { return m.Called(statement, arguments).Error(0) }
go
func (m SessionMock) Exec(statement string, arguments ...interface{}) error { return m.Called(statement, arguments).Error(0) }
[ "func", "(", "m", "SessionMock", ")", "Exec", "(", "statement", "string", ",", "arguments", "...", "interface", "{", "}", ")", "error", "{", "return", "m", ".", "Called", "(", "statement", ",", "arguments", ")", ".", "Error", "(", "0", ")", "\n", "}"...
// Exec implements Session.
[ "Exec", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L116-L118
142,310
willfaught/gockle
session.go
Scan
func (m SessionMock) Scan(statement string, results []interface{}, arguments ...interface{}) error { return m.Called(statement, results, arguments).Error(0) }
go
func (m SessionMock) Scan(statement string, results []interface{}, arguments ...interface{}) error { return m.Called(statement, results, arguments).Error(0) }
[ "func", "(", "m", "SessionMock", ")", "Scan", "(", "statement", "string", ",", "results", "[", "]", "interface", "{", "}", ",", "arguments", "...", "interface", "{", "}", ")", "error", "{", "return", "m", ".", "Called", "(", "statement", ",", "results"...
// Scan implements Session.
[ "Scan", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L121-L123
142,311
willfaught/gockle
session.go
ScanIterator
func (m SessionMock) ScanIterator(statement string, arguments ...interface{}) Iterator { return m.Called(statement, arguments).Get(0).(Iterator) }
go
func (m SessionMock) ScanIterator(statement string, arguments ...interface{}) Iterator { return m.Called(statement, arguments).Get(0).(Iterator) }
[ "func", "(", "m", "SessionMock", ")", "ScanIterator", "(", "statement", "string", ",", "arguments", "...", "interface", "{", "}", ")", "Iterator", "{", "return", "m", ".", "Called", "(", "statement", ",", "arguments", ")", ".", "Get", "(", "0", ")", "....
// ScanIterator implements Session.
[ "ScanIterator", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L126-L128
142,312
willfaught/gockle
session.go
ScanMapSlice
func (m SessionMock) ScanMapSlice(statement string, arguments ...interface{}) ([]map[string]interface{}, error) { var r = m.Called(statement, arguments) return r.Get(0).([]map[string]interface{}), r.Error(1) }
go
func (m SessionMock) ScanMapSlice(statement string, arguments ...interface{}) ([]map[string]interface{}, error) { var r = m.Called(statement, arguments) return r.Get(0).([]map[string]interface{}), r.Error(1) }
[ "func", "(", "m", "SessionMock", ")", "ScanMapSlice", "(", "statement", "string", ",", "arguments", "...", "interface", "{", "}", ")", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ",", "error", ")", "{", "var", "r", "=", "m", "....
// ScanMapSlice implements Session.
[ "ScanMapSlice", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L136-L140
142,313
willfaught/gockle
session.go
ScanMapTx
func (m SessionMock) ScanMapTx(statement string, results map[string]interface{}, arguments ...interface{}) (bool, error) { var r = m.Called(statement, results, arguments) return r.Bool(0), r.Error(1) }
go
func (m SessionMock) ScanMapTx(statement string, results map[string]interface{}, arguments ...interface{}) (bool, error) { var r = m.Called(statement, results, arguments) return r.Bool(0), r.Error(1) }
[ "func", "(", "m", "SessionMock", ")", "ScanMapTx", "(", "statement", "string", ",", "results", "map", "[", "string", "]", "interface", "{", "}", ",", "arguments", "...", "interface", "{", "}", ")", "(", "bool", ",", "error", ")", "{", "var", "r", "="...
// ScanMapTx implements Session.
[ "ScanMapTx", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L143-L147
142,314
willfaught/gockle
session.go
Tables
func (m SessionMock) Tables(keyspace string) ([]string, error) { var r = m.Called(keyspace) return r.Get(0).([]string), r.Error(1) }
go
func (m SessionMock) Tables(keyspace string) ([]string, error) { var r = m.Called(keyspace) return r.Get(0).([]string), r.Error(1) }
[ "func", "(", "m", "SessionMock", ")", "Tables", "(", "keyspace", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "r", "=", "m", ".", "Called", "(", "keyspace", ")", "\n\n", "return", "r", ".", "Get", "(", "0", ")", ".", "...
// Tables implements Session.
[ "Tables", "implements", "Session", "." ]
4f254e1e0f0a12485963192ff605f61f1933e71f
https://github.com/willfaught/gockle/blob/4f254e1e0f0a12485963192ff605f61f1933e71f/session.go#L150-L154
142,315
go-restit/lzjson
node.go
Decode
func Decode(reader io.Reader) Node { b, err := ioutil.ReadAll(reader) return &rootNode{ buf: b, err: err, } }
go
func Decode(reader io.Reader) Node { b, err := ioutil.ReadAll(reader) return &rootNode{ buf: b, err: err, } }
[ "func", "Decode", "(", "reader", "io", ".", "Reader", ")", "Node", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "reader", ")", "\n", "return", "&", "rootNode", "{", "buf", ":", "b", ",", "err", ":", "err", ",", "}", "\n", "}" ]
// Decode read and decodes a JSON from io.Reader then // returns a Node of it
[ "Decode", "read", "and", "decodes", "a", "JSON", "from", "io", ".", "Reader", "then", "returns", "a", "Node", "of", "it" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L81-L87
142,316
go-restit/lzjson
node.go
Unmarshal
func (n *rootNode) Unmarshal(v interface{}) error { return json.Unmarshal(n.buf, v) }
go
func (n *rootNode) Unmarshal(v interface{}) error { return json.Unmarshal(n.buf, v) }
[ "func", "(", "n", "*", "rootNode", ")", "Unmarshal", "(", "v", "interface", "{", "}", ")", "error", "{", "return", "json", ".", "Unmarshal", "(", "n", ".", "buf", ",", "v", ")", "\n", "}" ]
// Unmarshal implements Node
[ "Unmarshal", "implements", "Node" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L98-L100
142,317
go-restit/lzjson
node.go
UnmarshalJSON
func (n *rootNode) UnmarshalJSON(b []byte) error { n.buf = b n.mapBuf = nil return nil }
go
func (n *rootNode) UnmarshalJSON(b []byte) error { n.buf = b n.mapBuf = nil return nil }
[ "func", "(", "n", "*", "rootNode", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "n", ".", "buf", "=", "b", "\n", "n", ".", "mapBuf", "=", "nil", "\n", "return", "nil", "\n", "}" ]
// UnmarshalJSON implements Node
[ "UnmarshalJSON", "implements", "Node" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L103-L107
142,318
go-restit/lzjson
node.go
Type
func (n rootNode) Type() Type { switch { case n.err != nil: // for error, return TypeError return TypeError case n.buf == nil || len(n.buf) == 0: // for nil raw, return TypeUndefined return TypeUndefined case n.buf[0] == '"': // simply examine the first character // to determine the value type return...
go
func (n rootNode) Type() Type { switch { case n.err != nil: // for error, return TypeError return TypeError case n.buf == nil || len(n.buf) == 0: // for nil raw, return TypeUndefined return TypeUndefined case n.buf[0] == '"': // simply examine the first character // to determine the value type return...
[ "func", "(", "n", "rootNode", ")", "Type", "(", ")", "Type", "{", "switch", "{", "case", "n", ".", "err", "!=", "nil", ":", "// for error, return TypeError", "return", "TypeError", "\n", "case", "n", ".", "buf", "==", "nil", "||", "len", "(", "n", "....
// Type implements Node
[ "Type", "implements", "Node" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L115-L148
142,319
go-restit/lzjson
node.go
GetKeys
func (n *rootNode) GetKeys() (keys []string) { if err := n.genMapBuf(); err != nil { return } keys = make([]string, 0, len(n.mapBuf)) for key := range n.mapBuf { keys = append(keys, key) } return }
go
func (n *rootNode) GetKeys() (keys []string) { if err := n.genMapBuf(); err != nil { return } keys = make([]string, 0, len(n.mapBuf)) for key := range n.mapBuf { keys = append(keys, key) } return }
[ "func", "(", "n", "*", "rootNode", ")", "GetKeys", "(", ")", "(", "keys", "[", "]", "string", ")", "{", "if", "err", ":=", "n", ".", "genMapBuf", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "keys", "=", "make", "(", "["...
// GetKeys get object keys of the node. // If the node is not an object, returns nil
[ "GetKeys", "get", "object", "keys", "of", "the", "node", ".", "If", "the", "node", "is", "not", "an", "object", "returns", "nil" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L165-L174
142,320
go-restit/lzjson
node.go
Get
func (n *rootNode) Get(key string) (inner Node) { // the child key path path := n.keyPath(key) // if there is previous error, inherit if err := n.ParseError(); err != nil { return &rootNode{ path: path, err: err, } } if err := n.genMapBuf(); err != nil { if err == ErrorNotObject { path = n.path...
go
func (n *rootNode) Get(key string) (inner Node) { // the child key path path := n.keyPath(key) // if there is previous error, inherit if err := n.ParseError(); err != nil { return &rootNode{ path: path, err: err, } } if err := n.genMapBuf(); err != nil { if err == ErrorNotObject { path = n.path...
[ "func", "(", "n", "*", "rootNode", ")", "Get", "(", "key", "string", ")", "(", "inner", "Node", ")", "{", "// the child key path", "path", ":=", "n", ".", "keyPath", "(", "key", ")", "\n\n", "// if there is previous error, inherit", "if", "err", ":=", "n",...
// Get implements Node
[ "Get", "implements", "Node" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L185-L222
142,321
go-restit/lzjson
node.go
Len
func (n *rootNode) Len() int { switch n.Type() { case TypeString: return len(string(n.buf)) - 2 // subtact the 2 " marks case TypeArray: vslice := []*rootNode{} n.Unmarshal(&vslice) return len(vslice) } // default return -1 (for type mismatch) return -1 }
go
func (n *rootNode) Len() int { switch n.Type() { case TypeString: return len(string(n.buf)) - 2 // subtact the 2 " marks case TypeArray: vslice := []*rootNode{} n.Unmarshal(&vslice) return len(vslice) } // default return -1 (for type mismatch) return -1 }
[ "func", "(", "n", "*", "rootNode", ")", "Len", "(", ")", "int", "{", "switch", "n", ".", "Type", "(", ")", "{", "case", "TypeString", ":", "return", "len", "(", "string", "(", "n", ".", "buf", ")", ")", "-", "2", "// subtact the 2 \" marks", "\n", ...
// Len gets the length of the value // Only works with Array and String value type
[ "Len", "gets", "the", "length", "of", "the", "value", "Only", "works", "with", "Array", "and", "String", "value", "type" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L226-L237
142,322
go-restit/lzjson
node.go
GetN
func (n *rootNode) GetN(nth int) Node { // the path to nth node path := n.nthPath(nth) // if there is previous error, inherit if err := n.ParseError(); err != nil { return &rootNode{ path: path, err: err, } } if n.Type() != TypeArray { return &rootNode{ path: n.path, err: Error{ Path: "j...
go
func (n *rootNode) GetN(nth int) Node { // the path to nth node path := n.nthPath(nth) // if there is previous error, inherit if err := n.ParseError(); err != nil { return &rootNode{ path: path, err: err, } } if n.Type() != TypeArray { return &rootNode{ path: n.path, err: Error{ Path: "j...
[ "func", "(", "n", "*", "rootNode", ")", "GetN", "(", "nth", "int", ")", "Node", "{", "// the path to nth node", "path", ":=", "n", ".", "nthPath", "(", "nth", ")", "\n\n", "// if there is previous error, inherit", "if", "err", ":=", "n", ".", "ParseError", ...
// GetN implements Node
[ "GetN", "implements", "Node" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/node.go#L244-L280
142,323
go-restit/lzjson
sel.go
lexSel
func lexSel(input string) *selLexer { return &selLexer{ input: input, items: make(chan selItem), } }
go
func lexSel(input string) *selLexer { return &selLexer{ input: input, items: make(chan selItem), } }
[ "func", "lexSel", "(", "input", "string", ")", "*", "selLexer", "{", "return", "&", "selLexer", "{", "input", ":", "input", ",", "items", ":", "make", "(", "chan", "selItem", ")", ",", "}", "\n", "}" ]
// lexSel returns a lexer for the selector string
[ "lexSel", "returns", "a", "lexer", "for", "the", "selector", "string" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/sel.go#L39-L44
142,324
go-restit/lzjson
sel.go
errorf
func (l *selLexer) errorf(format string, args ...interface{}) selStateFn { l.items <- selItem{selItemError, fmt.Sprintf(format, args...)} return nil }
go
func (l *selLexer) errorf(format string, args ...interface{}) selStateFn { l.items <- selItem{selItemError, fmt.Sprintf(format, args...)} return nil }
[ "func", "(", "l", "*", "selLexer", ")", "errorf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "selStateFn", "{", "l", ".", "items", "<-", "selItem", "{", "selItemError", ",", "fmt", ".", "Sprintf", "(", "format", ",", "ar...
// errorf returns an error token and terminates the scan by passing // back a nil pointer that will be the next state, terminating l.nextItem.
[ "errorf", "returns", "an", "error", "token", "and", "terminates", "the", "scan", "by", "passing", "back", "a", "nil", "pointer", "that", "will", "be", "the", "next", "state", "terminating", "l", ".", "nextItem", "." ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/sel.go#L93-L96
142,325
go-restit/lzjson
sel.go
selLexText
func selLexText(l *selLexer) selStateFn { next := l.next() switch next { case '.': l.emit(selItemDot) return selLexProc case '[': l.emit(selItemLeftBrac) return selLexInsideBrac case ']': l.emit(selItemRightBrac) return selLexText case eof: break default: return selLexProc } if l.pos > l.start ...
go
func selLexText(l *selLexer) selStateFn { next := l.next() switch next { case '.': l.emit(selItemDot) return selLexProc case '[': l.emit(selItemLeftBrac) return selLexInsideBrac case ']': l.emit(selItemRightBrac) return selLexText case eof: break default: return selLexProc } if l.pos > l.start ...
[ "func", "selLexText", "(", "l", "*", "selLexer", ")", "selStateFn", "{", "next", ":=", "l", ".", "next", "(", ")", "\n", "switch", "next", "{", "case", "'.'", ":", "l", ".", "emit", "(", "selItemDot", ")", "\n", "return", "selLexProc", "\n", "case", ...
// selLexText process selector and determine what selStateFn // to process the upcoming string
[ "selLexText", "process", "selector", "and", "determine", "what", "selStateFn", "to", "process", "the", "upcoming", "string" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/sel.go#L134-L156
142,326
go-restit/lzjson
sel.go
selLexProc
func selLexProc(l *selLexer) selStateFn { l.acceptRun(charCap + charSmallCap + charNumeric) l.emit(selItemProp) return selLexText }
go
func selLexProc(l *selLexer) selStateFn { l.acceptRun(charCap + charSmallCap + charNumeric) l.emit(selItemProp) return selLexText }
[ "func", "selLexProc", "(", "l", "*", "selLexer", ")", "selStateFn", "{", "l", ".", "acceptRun", "(", "charCap", "+", "charSmallCap", "+", "charNumeric", ")", "\n", "l", ".", "emit", "(", "selItemProp", ")", "\n", "return", "selLexText", "\n", "}" ]
// selLexProc process selector string like object property // name until reaching non-alphanumerical character
[ "selLexProc", "process", "selector", "string", "like", "object", "property", "name", "until", "reaching", "non", "-", "alphanumerical", "character" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/sel.go#L160-L164
142,327
go-restit/lzjson
error.go
Error
func (err Error) Error() string { if err.Path != "" { return err.Path + ": " + err.Err.Error() } return err.Err.Error() }
go
func (err Error) Error() string { if err.Path != "" { return err.Path + ": " + err.Err.Error() } return err.Err.Error() }
[ "func", "(", "err", "Error", ")", "Error", "(", ")", "string", "{", "if", "err", ".", "Path", "!=", "\"", "\"", "{", "return", "err", ".", "Path", "+", "\"", "\"", "+", "err", ".", "Err", ".", "Error", "(", ")", "\n", "}", "\n", "return", "er...
// Error implements error type
[ "Error", "implements", "error", "type" ]
efe3c53acc682f0a1f43cecd3e3e0d535af3e73e
https://github.com/go-restit/lzjson/blob/efe3c53acc682f0a1f43cecd3e3e0d535af3e73e/error.go#L39-L44
142,328
tj/go-progress
progress.go
New
func New(total float64) *Bar { b := &Bar{ StartDelimiter: "|", EndDelimiter: "|", Filled: "█", Empty: "░", Total: total, Width: 60, } b.Template(`{{.Percent | printf "%3.0f"}}% {{.Bar}} {{.Text}}`) return b }
go
func New(total float64) *Bar { b := &Bar{ StartDelimiter: "|", EndDelimiter: "|", Filled: "█", Empty: "░", Total: total, Width: 60, } b.Template(`{{.Percent | printf "%3.0f"}}% {{.Bar}} {{.Text}}`) return b }
[ "func", "New", "(", "total", "float64", ")", "*", "Bar", "{", "b", ":=", "&", "Bar", "{", "StartDelimiter", ":", "\"", "\"", ",", "EndDelimiter", ":", "\"", "\"", ",", "Filled", ":", "\"", "", "", "Empty", ":", "\"", "", "", "Total", ":", "tota...
// New returns a new bar with the given total.
[ "New", "returns", "a", "new", "bar", "with", "the", "given", "total", "." ]
fadc638a53ddb120e0f59c81a2dd8390e97b67d9
https://github.com/tj/go-progress/blob/fadc638a53ddb120e0f59c81a2dd8390e97b67d9/progress.go#L28-L41
142,329
tj/go-progress
progress.go
Value
func (b *Bar) Value(n float64) { if n > b.Total { panic("Bar update value cannot be greater than the total") } b.value = n }
go
func (b *Bar) Value(n float64) { if n > b.Total { panic("Bar update value cannot be greater than the total") } b.value = n }
[ "func", "(", "b", "*", "Bar", ")", "Value", "(", "n", "float64", ")", "{", "if", "n", ">", "b", ".", "Total", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "b", ".", "value", "=", "n", "\n", "}" ]
// Value sets the value.
[ "Value", "sets", "the", "value", "." ]
fadc638a53ddb120e0f59c81a2dd8390e97b67d9
https://github.com/tj/go-progress/blob/fadc638a53ddb120e0f59c81a2dd8390e97b67d9/progress.go#L54-L59
142,330
tj/go-progress
progress.go
bar
func (b *Bar) bar() string { p := b.value / b.Total filled := math.Ceil(float64(b.Width) * p) empty := math.Floor(float64(b.Width) - filled) s := b.StartDelimiter s += strings.Repeat(b.Filled, int(filled)) s += strings.Repeat(b.Empty, int(empty)) s += b.EndDelimiter return s }
go
func (b *Bar) bar() string { p := b.value / b.Total filled := math.Ceil(float64(b.Width) * p) empty := math.Floor(float64(b.Width) - filled) s := b.StartDelimiter s += strings.Repeat(b.Filled, int(filled)) s += strings.Repeat(b.Empty, int(empty)) s += b.EndDelimiter return s }
[ "func", "(", "b", "*", "Bar", ")", "bar", "(", ")", "string", "{", "p", ":=", "b", ".", "value", "/", "b", ".", "Total", "\n", "filled", ":=", "math", ".", "Ceil", "(", "float64", "(", "b", ".", "Width", ")", "*", "p", ")", "\n", "empty", "...
// Bar returns the progress bar string.
[ "Bar", "returns", "the", "progress", "bar", "string", "." ]
fadc638a53ddb120e0f59c81a2dd8390e97b67d9
https://github.com/tj/go-progress/blob/fadc638a53ddb120e0f59c81a2dd8390e97b67d9/progress.go#L72-L81
142,331
tj/go-progress
progress.go
String
func (b *Bar) String() string { var buf bytes.Buffer data := struct { Value float64 Total float64 Percent float64 StartDelimiter string EndDelimiter string Bar string Text string }{ Value: b.value, Text: b.text, StartDelimiter: b...
go
func (b *Bar) String() string { var buf bytes.Buffer data := struct { Value float64 Total float64 Percent float64 StartDelimiter string EndDelimiter string Bar string Text string }{ Value: b.value, Text: b.text, StartDelimiter: b...
[ "func", "(", "b", "*", "Bar", ")", "String", "(", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n\n", "data", ":=", "struct", "{", "Value", "float64", "\n", "Total", "float64", "\n", "Percent", "float64", "\n", "StartDelimiter", "string", ...
// String returns the progress bar.
[ "String", "returns", "the", "progress", "bar", "." ]
fadc638a53ddb120e0f59c81a2dd8390e97b67d9
https://github.com/tj/go-progress/blob/fadc638a53ddb120e0f59c81a2dd8390e97b67d9/progress.go#L84-L109
142,332
tj/go-progress
progress.go
WriteTo
func (b *Bar) WriteTo(w io.Writer) (int64, error) { s := fmt.Sprintf("\r %s ", b.String()) _, err := io.WriteString(w, s) return int64(len(s)), err }
go
func (b *Bar) WriteTo(w io.Writer) (int64, error) { s := fmt.Sprintf("\r %s ", b.String()) _, err := io.WriteString(w, s) return int64(len(s)), err }
[ "func", "(", "b", "*", "Bar", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "s", ":=", "fmt", ".", "Sprintf", "(", "\"", "\\r", "\"", ",", "b", ".", "String", "(", ")", ")", "\n", "_", ",", "err",...
// WriteTo writes the progress bar to w.
[ "WriteTo", "writes", "the", "progress", "bar", "to", "w", "." ]
fadc638a53ddb120e0f59c81a2dd8390e97b67d9
https://github.com/tj/go-progress/blob/fadc638a53ddb120e0f59c81a2dd8390e97b67d9/progress.go#L112-L116
142,333
tj/go-progress
progress.go
Template
func (b *Bar) Template(s string) { t, err := template.New("").Parse(s) if err != nil { panic(err) } b.tmpl = t }
go
func (b *Bar) Template(s string) { t, err := template.New("").Parse(s) if err != nil { panic(err) } b.tmpl = t }
[ "func", "(", "b", "*", "Bar", ")", "Template", "(", "s", "string", ")", "{", "t", ",", "err", ":=", "template", ".", "New", "(", "\"", "\"", ")", ".", "Parse", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\...
// Template for rendering. This method will panic if the template fails to parse.
[ "Template", "for", "rendering", ".", "This", "method", "will", "panic", "if", "the", "template", "fails", "to", "parse", "." ]
fadc638a53ddb120e0f59c81a2dd8390e97b67d9
https://github.com/tj/go-progress/blob/fadc638a53ddb120e0f59c81a2dd8390e97b67d9/progress.go#L119-L126
142,334
alecthomas/binary
binary.go
NewStrictEncoder
func NewStrictEncoder(w io.Writer) *Encoder { e := NewEncoder(w) e.strict = true return e }
go
func NewStrictEncoder(w io.Writer) *Encoder { e := NewEncoder(w) e.strict = true return e }
[ "func", "NewStrictEncoder", "(", "w", "io", ".", "Writer", ")", "*", "Encoder", "{", "e", ":=", "NewEncoder", "(", "w", ")", "\n", "e", ".", "strict", "=", "true", "\n", "return", "e", "\n", "}" ]
// NewStrictEncoder creates an encoder similar to NewEncoder, however // if this encoder attempts to encode a struct and the struct has no encodable // fields an error is returned whereas the encoder returned from NewEncoder // will simply not write anything to `w`.
[ "NewStrictEncoder", "creates", "an", "encoder", "similar", "to", "NewEncoder", "however", "if", "this", "encoder", "attempts", "to", "encode", "a", "struct", "and", "the", "struct", "has", "no", "encodable", "fields", "an", "error", "is", "returned", "whereas", ...
6e8df1b1fb9d591dfc8249e230e0a762524873f3
https://github.com/alecthomas/binary/blob/6e8df1b1fb9d591dfc8249e230e0a762524873f3/binary.go#L50-L54
142,335
araddon/gou
jsonhelper.go
NewJsonHelperFromResp
func NewJsonHelperFromResp(resp *http.Response) (JsonHelper, error) { jh := make(JsonHelper) if resp == nil || resp.Body == nil { return jh, fmt.Errorf("No response or response body to read") } defer resp.Body.Close() respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } if len(respB...
go
func NewJsonHelperFromResp(resp *http.Response) (JsonHelper, error) { jh := make(JsonHelper) if resp == nil || resp.Body == nil { return jh, fmt.Errorf("No response or response body to read") } defer resp.Body.Close() respBytes, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } if len(respB...
[ "func", "NewJsonHelperFromResp", "(", "resp", "*", "http", ".", "Response", ")", "(", "JsonHelper", ",", "error", ")", "{", "jh", ":=", "make", "(", "JsonHelper", ")", "\n", "if", "resp", "==", "nil", "||", "resp", ".", "Body", "==", "nil", "{", "ret...
// Make a JsonHelper from http response. This will automatically // close the response body
[ "Make", "a", "JsonHelper", "from", "http", "response", ".", "This", "will", "automatically", "close", "the", "response", "body" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/jsonhelper.go#L161-L178
142,336
araddon/gou
jsonhelper.go
Helper
func (j JsonHelper) Helper(n string) JsonHelper { v := j.Get(n) if v == nil { return nil } switch vt := v.(type) { case map[string]interface{}: cn := JsonHelper{} for n, val := range vt { cn[n] = val } return cn case map[string]string: cn := JsonHelper{} for n, val := range vt { cn[n] = val ...
go
func (j JsonHelper) Helper(n string) JsonHelper { v := j.Get(n) if v == nil { return nil } switch vt := v.(type) { case map[string]interface{}: cn := JsonHelper{} for n, val := range vt { cn[n] = val } return cn case map[string]string: cn := JsonHelper{} for n, val := range vt { cn[n] = val ...
[ "func", "(", "j", "JsonHelper", ")", "Helper", "(", "n", "string", ")", "JsonHelper", "{", "v", ":=", "j", ".", "Get", "(", "n", ")", "\n", "if", "v", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "switch", "vt", ":=", "v", ".", "(", "t...
// Get a Helper from a string path
[ "Get", "a", "Helper", "from", "a", "string", "path" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/jsonhelper.go#L273-L297
142,337
araddon/gou
jsonhelper.go
Helpers
func (j JsonHelper) Helpers(n string) []JsonHelper { v := j.Get(n) if v == nil { return nil } switch val := v.(type) { case []map[string]interface{}: hl := make([]JsonHelper, 0) for _, mapVal := range val { hl = append(hl, mapVal) } return hl case []interface{}: jhl := make([]JsonHelper, 0) for _...
go
func (j JsonHelper) Helpers(n string) []JsonHelper { v := j.Get(n) if v == nil { return nil } switch val := v.(type) { case []map[string]interface{}: hl := make([]JsonHelper, 0) for _, mapVal := range val { hl = append(hl, mapVal) } return hl case []interface{}: jhl := make([]JsonHelper, 0) for _...
[ "func", "(", "j", "JsonHelper", ")", "Helpers", "(", "n", "string", ")", "[", "]", "JsonHelper", "{", "v", ":=", "j", ".", "Get", "(", "n", ")", "\n", "if", "v", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "switch", "val", ":=", "v", ...
// Get list of Helpers at given name. Trys to coerce into // proper Helper type
[ "Get", "list", "of", "Helpers", "at", "given", "name", ".", "Trys", "to", "coerce", "into", "proper", "Helper", "type" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/jsonhelper.go#L301-L324
142,338
araddon/gou
uid.go
initHostPidId
func initHostPidId() { var sum [4]byte hostB := sum[:] host, err := os.Hostname() if err != nil { // if we cannot get hostname, just use a random set of bytes _, err2 := io.ReadFull(rand.Reader, hostB) if err2 != nil { panic(fmt.Errorf("cannot get hostname: %v; %v", err, err2)) } } else { hw := md5.Ne...
go
func initHostPidId() { var sum [4]byte hostB := sum[:] host, err := os.Hostname() if err != nil { // if we cannot get hostname, just use a random set of bytes _, err2 := io.ReadFull(rand.Reader, hostB) if err2 != nil { panic(fmt.Errorf("cannot get hostname: %v; %v", err, err2)) } } else { hw := md5.Ne...
[ "func", "initHostPidId", "(", ")", "{", "var", "sum", "[", "4", "]", "byte", "\n", "hostB", ":=", "sum", "[", ":", "]", "\n", "host", ",", "err", ":=", "os", ".", "Hostname", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// if we cannot get hostn...
// initHostPidId generates a machine-process specific id by using hostname // and processid
[ "initHostPidId", "generates", "a", "machine", "-", "process", "specific", "id", "by", "using", "hostname", "and", "processid" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/uid.go#L44-L66
142,339
araddon/gou
uid.go
NewUid
func NewUid() uint64 { b := make([]byte, 8) ts := uint32(time.Now().Unix()) - ourEpoch // Timestamp, 4 bytes, big endian binary.BigEndian.PutUint32(b, ts) //Debugf("ts=%v b=%v", ts, b) // first 3 bytes of host/pid b[4] = hostPidId[2] b[5] = hostPidId[3] b[6] = hostPidId[3] // Increment, 2 bytes, big endian...
go
func NewUid() uint64 { b := make([]byte, 8) ts := uint32(time.Now().Unix()) - ourEpoch // Timestamp, 4 bytes, big endian binary.BigEndian.PutUint32(b, ts) //Debugf("ts=%v b=%v", ts, b) // first 3 bytes of host/pid b[4] = hostPidId[2] b[5] = hostPidId[3] b[6] = hostPidId[3] // Increment, 2 bytes, big endian...
[ "func", "NewUid", "(", ")", "uint64", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "ts", ":=", "uint32", "(", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ")", "-", "ourEpoch", "\n\n", "// Timestamp, 4 bytes, big endi...
// Create a new uint64 unique id
[ "Create", "a", "new", "uint64", "unique", "id" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/uid.go#L72-L90
142,340
araddon/gou
log_unix.go
IsTerminal
func IsTerminal() bool { ws := &winsize{} isTerm := true defer func() { if r := recover(); r != nil { isTerm = false } }() // This blows up on windows retCode, _, _ := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), uintptr(_TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) if int(retCode) == -1...
go
func IsTerminal() bool { ws := &winsize{} isTerm := true defer func() { if r := recover(); r != nil { isTerm = false } }() // This blows up on windows retCode, _, _ := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), uintptr(_TIOCGWINSZ), uintptr(unsafe.Pointer(ws))) if int(retCode) == -1...
[ "func", "IsTerminal", "(", ")", "bool", "{", "ws", ":=", "&", "winsize", "{", "}", "\n", "isTerm", ":=", "true", "\n", "defer", "func", "(", ")", "{", "if", "r", ":=", "recover", "(", ")", ";", "r", "!=", "nil", "{", "isTerm", "=", "false", "\n...
// Determine is this process is running in a Terminal or not?
[ "Determine", "is", "this", "process", "is", "running", "in", "a", "Terminal", "or", "not?" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log_unix.go#L11-L29
142,341
araddon/gou
coerce.go
CoerceStrings
func CoerceStrings(v interface{}) []string { switch val := v.(type) { case string: if val == "" { return nil } return strings.Split(val, ",") case []string: return val case []interface{}: sva := make([]string, 0) for _, av := range val { switch aval := av.(type) { case string: sva = append(...
go
func CoerceStrings(v interface{}) []string { switch val := v.(type) { case string: if val == "" { return nil } return strings.Split(val, ",") case []string: return val case []interface{}: sva := make([]string, 0) for _, av := range val { switch aval := av.(type) { case string: sva = append(...
[ "func", "CoerceStrings", "(", "v", "interface", "{", "}", ")", "[", "]", "string", "{", "switch", "val", ":=", "v", ".", "(", "type", ")", "{", "case", "string", ":", "if", "val", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "return",...
// CoerceStrings Coerce type to strings, will split on comma by default.
[ "CoerceStrings", "Coerce", "type", "to", "strings", "will", "split", "on", "comma", "by", "default", "." ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/coerce.go#L59-L84
142,342
araddon/gou
http.go
Fetch
func Fetch(url string) (ret []byte, err error) { resp, err := http.Get(url) defer func() { if resp != nil && resp.Body != nil { resp.Body.Close() } }() if err != nil { Log(WARN, err.Error()) return } ret, err = ioutil.ReadAll(resp.Body) if err != nil { return } return }
go
func Fetch(url string) (ret []byte, err error) { resp, err := http.Get(url) defer func() { if resp != nil && resp.Body != nil { resp.Body.Close() } }() if err != nil { Log(WARN, err.Error()) return } ret, err = ioutil.ReadAll(resp.Body) if err != nil { return } return }
[ "func", "Fetch", "(", "url", "string", ")", "(", "ret", "[", "]", "byte", ",", "err", "error", ")", "{", "resp", ",", "err", ":=", "http", ".", "Get", "(", "url", ")", "\n", "defer", "func", "(", ")", "{", "if", "resp", "!=", "nil", "&&", "re...
// Simple Fetch Wrapper, given a url it returns bytes
[ "Simple", "Fetch", "Wrapper", "given", "a", "url", "it", "returns", "bytes" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/http.go#L13-L29
142,343
araddon/gou
http.go
PostForm
func PostForm(url, body string) (ret string, err error, resp *http.Response) { //Post(url string, bodyType string, body io.Reader) buf := bytes.NewBufferString(body) resp, err = http.Post(url, "application/x-www-form-urlencoded", buf) defer func() { if resp != nil && resp.Body != nil { resp.Body.Close() } }...
go
func PostForm(url, body string) (ret string, err error, resp *http.Response) { //Post(url string, bodyType string, body io.Reader) buf := bytes.NewBufferString(body) resp, err = http.Post(url, "application/x-www-form-urlencoded", buf) defer func() { if resp != nil && resp.Body != nil { resp.Body.Close() } }...
[ "func", "PostForm", "(", "url", ",", "body", "string", ")", "(", "ret", "string", ",", "err", "error", ",", "resp", "*", "http", ".", "Response", ")", "{", "//Post(url string, bodyType string, body io.Reader)", "buf", ":=", "bytes", ".", "NewBufferString", "("...
// posts a www-form encoded form to url with body
[ "posts", "a", "www", "-", "form", "encoded", "form", "to", "url", "with", "body" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/http.go#L159-L178
142,344
araddon/gou
log.go
SetupLoggingFile
func SetupLoggingFile(f *os.File, lvl string) { SetLogger(log.New(f, "", log.LstdFlags|log.Lshortfile|log.Lmicroseconds), strings.ToLower(lvl)) }
go
func SetupLoggingFile(f *os.File, lvl string) { SetLogger(log.New(f, "", log.LstdFlags|log.Lshortfile|log.Lmicroseconds), strings.ToLower(lvl)) }
[ "func", "SetupLoggingFile", "(", "f", "*", "os", ".", "File", ",", "lvl", "string", ")", "{", "SetLogger", "(", "log", ".", "New", "(", "f", ",", "\"", "\"", ",", "log", ".", "LstdFlags", "|", "log", ".", "Lshortfile", "|", "log", ".", "Lmicrosecon...
// SetupLoggingFile writes logs to the file object parameter.
[ "SetupLoggingFile", "writes", "logs", "to", "the", "file", "object", "parameter", "." ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L90-L92
142,345
araddon/gou
log.go
LogLevelSet
func LogLevelSet(levelWord string) { if lvl, ok := LogLevelWords[levelWord]; ok { LogLevel = lvl } }
go
func LogLevelSet(levelWord string) { if lvl, ok := LogLevelWords[levelWord]; ok { LogLevel = lvl } }
[ "func", "LogLevelSet", "(", "levelWord", "string", ")", "{", "if", "lvl", ",", "ok", ":=", "LogLevelWords", "[", "levelWord", "]", ";", "ok", "{", "LogLevel", "=", "lvl", "\n", "}", "\n", "}" ]
// sets the log level from a string
[ "sets", "the", "log", "level", "from", "a", "string" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L163-L167
142,346
araddon/gou
log.go
NewContext
func NewContext(ctx context.Context, msg string) context.Context { return context.WithValue(ctx, logContextKey, msg) }
go
func NewContext(ctx context.Context, msg string) context.Context { return context.WithValue(ctx, logContextKey, msg) }
[ "func", "NewContext", "(", "ctx", "context", ".", "Context", ",", "msg", "string", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "logContextKey", ",", "msg", ")", "\n", "}" ]
// NewContext returns a new Context carrying contextual log message // that gets prefixed to log statements.
[ "NewContext", "returns", "a", "new", "Context", "carrying", "contextual", "log", "message", "that", "gets", "prefixed", "to", "log", "statements", "." ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L171-L173
142,347
araddon/gou
log.go
NewContextWrap
func NewContextWrap(ctx context.Context, msg string) context.Context { logContext, ok := ctx.Value(logContextKey).(string) if ok { return context.WithValue(ctx, logContextKey, fmt.Sprintf("%s %s", logContext, msg)) } return context.WithValue(ctx, logContextKey, msg) }
go
func NewContextWrap(ctx context.Context, msg string) context.Context { logContext, ok := ctx.Value(logContextKey).(string) if ok { return context.WithValue(ctx, logContextKey, fmt.Sprintf("%s %s", logContext, msg)) } return context.WithValue(ctx, logContextKey, msg) }
[ "func", "NewContextWrap", "(", "ctx", "context", ".", "Context", ",", "msg", "string", ")", "context", ".", "Context", "{", "logContext", ",", "ok", ":=", "ctx", ".", "Value", "(", "logContextKey", ")", ".", "(", "string", ")", "\n", "if", "ok", "{", ...
// NewContextWrap returns a new Context carrying contextual log message // that gets prefixed to log statements.
[ "NewContextWrap", "returns", "a", "new", "Context", "carrying", "contextual", "log", "message", "that", "gets", "prefixed", "to", "log", "statements", "." ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L177-L183
142,348
araddon/gou
log.go
FromContext
func FromContext(ctx context.Context) string { logContext, _ := ctx.Value(logContextKey).(string) return logContext }
go
func FromContext(ctx context.Context) string { logContext, _ := ctx.Value(logContextKey).(string) return logContext }
[ "func", "FromContext", "(", "ctx", "context", ".", "Context", ")", "string", "{", "logContext", ",", "_", ":=", "ctx", ".", "Value", "(", "logContextKey", ")", ".", "(", "string", ")", "\n", "return", "logContext", "\n", "}" ]
// FromContext extracts the Log Context prefix from context
[ "FromContext", "extracts", "the", "Log", "Context", "prefix", "from", "context" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L186-L189
142,349
araddon/gou
log.go
Debugf
func Debugf(format string, v ...interface{}) { if LogLevel >= 4 { DoLog(3, DEBUG, fmt.Sprintf(format, v...)) } }
go
func Debugf(format string, v ...interface{}) { if LogLevel >= 4 { DoLog(3, DEBUG, fmt.Sprintf(format, v...)) } }
[ "func", "Debugf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "4", "{", "DoLog", "(", "3", ",", "DEBUG", ",", "fmt", ".", "Sprintf", "(", "format", ",", "v", "...", ")", ")", "\n", "}", "\n...
// Debug log formatted
[ "Debug", "log", "formatted" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L199-L203
142,350
araddon/gou
log.go
DebugCtx
func DebugCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 4 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, DEBUG, fmt.Sprintf(format, v...)) } }
go
func DebugCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 4 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, DEBUG, fmt.Sprintf(format, v...)) } }
[ "func", "DebugCtx", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "4", "{", "lc", ":=", "FromContext", "(", "ctx", ")", "\n", "if", "len", "(", "lc", ")", ...
// Debug log formatted context writer
[ "Debug", "log", "formatted", "context", "writer" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L206-L214
142,351
araddon/gou
log.go
Infof
func Infof(format string, v ...interface{}) { if LogLevel >= 3 { DoLog(3, INFO, fmt.Sprintf(format, v...)) } }
go
func Infof(format string, v ...interface{}) { if LogLevel >= 3 { DoLog(3, INFO, fmt.Sprintf(format, v...)) } }
[ "func", "Infof", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "3", "{", "DoLog", "(", "3", ",", "INFO", ",", "fmt", ".", "Sprintf", "(", "format", ",", "v", "...", ")", ")", "\n", "}", "\n",...
// info log formatted
[ "info", "log", "formatted" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L230-L234
142,352
araddon/gou
log.go
InfoCtx
func InfoCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 3 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, INFO, fmt.Sprintf(format, v...)) } }
go
func InfoCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 3 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, INFO, fmt.Sprintf(format, v...)) } }
[ "func", "InfoCtx", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "3", "{", "lc", ":=", "FromContext", "(", "ctx", ")", "\n", "if", "len", "(", "lc", ")", ...
// Info log formatted context writer
[ "Info", "log", "formatted", "context", "writer" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L237-L245
142,353
araddon/gou
log.go
Warnf
func Warnf(format string, v ...interface{}) { if LogLevel >= 2 { DoLog(3, WARN, fmt.Sprintf(format, v...)) } }
go
func Warnf(format string, v ...interface{}) { if LogLevel >= 2 { DoLog(3, WARN, fmt.Sprintf(format, v...)) } }
[ "func", "Warnf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "2", "{", "DoLog", "(", "3", ",", "WARN", ",", "fmt", ".", "Sprintf", "(", "format", ",", "v", "...", ")", ")", "\n", "}", "\n",...
// Warn log formatted
[ "Warn", "log", "formatted" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L262-L266
142,354
araddon/gou
log.go
WarnCtx
func WarnCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 2 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, WARN, fmt.Sprintf(format, v...)) } }
go
func WarnCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 2 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, WARN, fmt.Sprintf(format, v...)) } }
[ "func", "WarnCtx", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "2", "{", "lc", ":=", "FromContext", "(", "ctx", ")", "\n", "if", "len", "(", "lc", ")", ...
// Warn log formatted context writer
[ "Warn", "log", "formatted", "context", "writer" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L269-L277
142,355
araddon/gou
log.go
Errorf
func Errorf(format string, v ...interface{}) { if LogLevel >= 1 { DoLog(3, ERROR, fmt.Sprintf(format, v...)) } }
go
func Errorf(format string, v ...interface{}) { if LogLevel >= 1 { DoLog(3, ERROR, fmt.Sprintf(format, v...)) } }
[ "func", "Errorf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "1", "{", "DoLog", "(", "3", ",", "ERROR", ",", "fmt", ".", "Sprintf", "(", "format", ",", "v", "...", ")", ")", "\n", "}", "\n...
// Error log formatted
[ "Error", "log", "formatted" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L294-L298
142,356
araddon/gou
log.go
ErrorCtx
func ErrorCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 1 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, ERROR, fmt.Sprintf(format, v...)) } }
go
func ErrorCtx(ctx context.Context, format string, v ...interface{}) { if LogLevel >= 1 { lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } DoLog(3, ERROR, fmt.Sprintf(format, v...)) } }
[ "func", "ErrorCtx", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "1", "{", "lc", ":=", "FromContext", "(", "ctx", ")", "\n", "if", "len", "(", "lc", ")", ...
// Error log formatted context writer
[ "Error", "log", "formatted", "context", "writer" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L301-L309
142,357
araddon/gou
log.go
LogErrorf
func LogErrorf(format string, v ...interface{}) error { err := fmt.Errorf(format, v...) if LogLevel >= 1 { DoLog(3, ERROR, err.Error()) } return err }
go
func LogErrorf(format string, v ...interface{}) error { err := fmt.Errorf(format, v...) if LogLevel >= 1 { DoLog(3, ERROR, err.Error()) } return err }
[ "func", "LogErrorf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "error", "{", "err", ":=", "fmt", ".", "Errorf", "(", "format", ",", "v", "...", ")", "\n", "if", "LogLevel", ">=", "1", "{", "DoLog", "(", "3", ",", "ERRO...
// Log this error, and return error object
[ "Log", "this", "error", "and", "return", "error", "object" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L312-L318
142,358
araddon/gou
log.go
PrettyStack
func PrettyStack(lineCt int) string { stackBuf := make([]byte, 10000) stackBufLen := runtime.Stack(stackBuf, false) stackTraceStr := string(stackBuf[0:stackBufLen]) parts := strings.Split(stackTraceStr, "\n") if len(parts) > 3 { parts = parts[2:] parts2 := make([]string, 0, len(parts)/2) for i := 3; i < len(...
go
func PrettyStack(lineCt int) string { stackBuf := make([]byte, 10000) stackBufLen := runtime.Stack(stackBuf, false) stackTraceStr := string(stackBuf[0:stackBufLen]) parts := strings.Split(stackTraceStr, "\n") if len(parts) > 3 { parts = parts[2:] parts2 := make([]string, 0, len(parts)/2) for i := 3; i < len(...
[ "func", "PrettyStack", "(", "lineCt", "int", ")", "string", "{", "stackBuf", ":=", "make", "(", "[", "]", "byte", ",", "10000", ")", "\n", "stackBufLen", ":=", "runtime", ".", "Stack", "(", "stackBuf", ",", "false", ")", "\n", "stackTraceStr", ":=", "s...
// PrettyStack is a helper to pull stack-trace, prettify it.
[ "PrettyStack", "is", "a", "helper", "to", "pull", "stack", "-", "trace", "prettify", "it", "." ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L376-L395
142,359
araddon/gou
log.go
LogThrottleKey
func LogThrottleKey(logLvl, limit int, key, format string, v ...interface{}) { if LogLevel < logLvl { return } doLogThrottle(4, logLvl, limit, key, fmt.Sprintf(format, v...)) }
go
func LogThrottleKey(logLvl, limit int, key, format string, v ...interface{}) { if LogLevel < logLvl { return } doLogThrottle(4, logLvl, limit, key, fmt.Sprintf(format, v...)) }
[ "func", "LogThrottleKey", "(", "logLvl", ",", "limit", "int", ",", "key", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", "<", "logLvl", "{", "return", "\n", "}", "\n\n", "doLogThrottle", "(", "4", ",", "l...
// Throttle logging based on key, such that key would never occur more than // @limit times per hour // // LogThrottleKey(u.ERROR, 1,"error_that_happens_a_lot" "message %s", varx) //
[ "Throttle", "logging", "based", "on", "key", "such", "that", "key", "would", "never", "occur", "more", "than" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L402-L408
142,360
araddon/gou
log.go
LogThrottle
func LogThrottle(logLvl, limit int, format string, v ...interface{}) { if LogLevel < logLvl { return } doLogThrottle(4, logLvl, limit, format, fmt.Sprintf(format, v...)) }
go
func LogThrottle(logLvl, limit int, format string, v ...interface{}) { if LogLevel < logLvl { return } doLogThrottle(4, logLvl, limit, format, fmt.Sprintf(format, v...)) }
[ "func", "LogThrottle", "(", "logLvl", ",", "limit", "int", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", "<", "logLvl", "{", "return", "\n", "}", "\n", "doLogThrottle", "(", "4", ",", "logLvl", ",", "lim...
// LogThrottleD logging based on @format as a key, such that key would never occur more than // @limit times per hour // // LogThrottle(u.ERROR, 1, "message %s", varx) //
[ "LogThrottleD", "logging", "based", "on" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L428-L433
142,361
araddon/gou
log.go
LogThrottleCtx
func LogThrottleCtx(ctx context.Context, logLvl, limit int, format string, v ...interface{}) { if LogLevel < logLvl { return } lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } doLogThrottle(4, logLvl, limit, format, fmt.Sprintf(format, v...)) }
go
func LogThrottleCtx(ctx context.Context, logLvl, limit int, format string, v ...interface{}) { if LogLevel < logLvl { return } lc := FromContext(ctx) if len(lc) > 0 { format = fmt.Sprintf("%s %s", lc, format) } doLogThrottle(4, logLvl, limit, format, fmt.Sprintf(format, v...)) }
[ "func", "LogThrottleCtx", "(", "ctx", "context", ".", "Context", ",", "logLvl", ",", "limit", "int", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", "<", "logLvl", "{", "return", "\n", "}", "\n\n", "lc", "...
// LogThrottleCtx log formatted context writer, limits to @limit/hour.
[ "LogThrottleCtx", "log", "formatted", "context", "writer", "limits", "to" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L436-L446
142,362
araddon/gou
log.go
LogThrottleD
func LogThrottleD(depth, logLvl, limit int, format string, v ...interface{}) { if LogLevel < logLvl { return } doLogThrottle(depth, logLvl, limit, format, fmt.Sprintf(format, v...)) }
go
func LogThrottleD(depth, logLvl, limit int, format string, v ...interface{}) { if LogLevel < logLvl { return } doLogThrottle(depth, logLvl, limit, format, fmt.Sprintf(format, v...)) }
[ "func", "LogThrottleD", "(", "depth", ",", "logLvl", ",", "limit", "int", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", "<", "logLvl", "{", "return", "\n", "}", "\n", "doLogThrottle", "(", "depth", ",", ...
// LogThrottleD Throttle logging based on @format as a key, such that key would never // occur more than @limit times per hour // // LogThrottleD(5, u.ERROR, 1, "message %s", varx) //
[ "LogThrottleD", "Throttle", "logging", "based", "on" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L453-L458
142,363
araddon/gou
log.go
DoLog
func DoLog(depth, logLvl int, msg string) { DoLogFields(depth+1, logLvl, msg, nil) }
go
func DoLog(depth, logLvl int, msg string) { DoLogFields(depth+1, logLvl, msg, nil) }
[ "func", "DoLog", "(", "depth", ",", "logLvl", "int", ",", "msg", "string", ")", "{", "DoLogFields", "(", "depth", "+", "1", ",", "logLvl", ",", "msg", ",", "nil", ")", "\n", "}" ]
// Low level log with depth , level, message and logger
[ "Low", "level", "log", "with", "depth", "level", "message", "and", "logger" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L532-L534
142,364
araddon/gou
log.go
LogCtx
func LogCtx(ctx context.Context, depth, logLvl int, format string, v ...interface{}) { if LogLevel >= logLvl { msg := fmt.Sprintf(format, v...) lc := FromContext(ctx) if len(lc) > 0 { msg = fmt.Sprintf("%s %s", lc, msg) } DoLog(depth+1, logLvl, msg) } }
go
func LogCtx(ctx context.Context, depth, logLvl int, format string, v ...interface{}) { if LogLevel >= logLvl { msg := fmt.Sprintf(format, v...) lc := FromContext(ctx) if len(lc) > 0 { msg = fmt.Sprintf("%s %s", lc, msg) } DoLog(depth+1, logLvl, msg) } }
[ "func", "LogCtx", "(", "ctx", "context", ".", "Context", ",", "depth", ",", "logLvl", "int", ",", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "if", "LogLevel", ">=", "logLvl", "{", "msg", ":=", "fmt", ".", "Sprintf", "(", ...
// LogCtx Low level log with depth , level, message and logger
[ "LogCtx", "Low", "level", "log", "with", "depth", "level", "message", "and", "logger" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L537-L546
142,365
araddon/gou
log.go
DoLogFields
func DoLogFields(depth, logLvl int, msg string, fields map[string]interface{}) { if escapeNewlines { msg = EscapeNewlines(msg) } if customLogger == nil { // Use standard logger if ErrLogLevel >= logLvl && loggerErr != nil { loggerErr.Output(depth, LogPrefix[logLvl]+msg+postFix) } else if LogLevel >= log...
go
func DoLogFields(depth, logLvl int, msg string, fields map[string]interface{}) { if escapeNewlines { msg = EscapeNewlines(msg) } if customLogger == nil { // Use standard logger if ErrLogLevel >= logLvl && loggerErr != nil { loggerErr.Output(depth, LogPrefix[logLvl]+msg+postFix) } else if LogLevel >= log...
[ "func", "DoLogFields", "(", "depth", ",", "logLvl", "int", ",", "msg", "string", ",", "fields", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "if", "escapeNewlines", "{", "msg", "=", "EscapeNewlines", "(", "msg", ")", "\n", "}", "\n\n", ...
// DoLogFields allows the inclusion of additional context for logrus logs // file and line number are included in the fields by default
[ "DoLogFields", "allows", "the", "inclusion", "of", "additional", "context", "for", "logrus", "logs", "file", "and", "line", "number", "are", "included", "in", "the", "fields", "by", "default" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/log.go#L550-L566
142,366
araddon/gou
throttle.go
NewThrottler
func NewThrottler(max int, per time.Duration) *Throttler { return &Throttler{ maxPer: float64(max), allowance: float64(max), count: int32(0), last: time.Now(), per: per.Seconds(), } }
go
func NewThrottler(max int, per time.Duration) *Throttler { return &Throttler{ maxPer: float64(max), allowance: float64(max), count: int32(0), last: time.Now(), per: per.Seconds(), } }
[ "func", "NewThrottler", "(", "max", "int", ",", "per", "time", ".", "Duration", ")", "*", "Throttler", "{", "return", "&", "Throttler", "{", "maxPer", ":", "float64", "(", "max", ")", ",", "allowance", ":", "float64", "(", "max", ")", ",", "count", "...
// new Throttler that will tell you to limit or not based // on given @max events @per duration
[ "new", "Throttler", "that", "will", "tell", "you", "to", "limit", "or", "not", "based", "on", "given" ]
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/throttle.go#L24-L32
142,367
araddon/gou
throttle.go
ThrottleAdd
func (r *Throttler) ThrottleAdd(ct int32) (bool, int32) { if r.maxPer == 0 { return false, 0 } // http://stackoverflow.com/questions/667508/whats-a-good-rate-limiting-algorithm now := time.Now() elapsed := float64(now.Sub(r.last).Nanoseconds()) / 1e9 // seconds r.last = now r.allowance += elapsed * (r.maxPer...
go
func (r *Throttler) ThrottleAdd(ct int32) (bool, int32) { if r.maxPer == 0 { return false, 0 } // http://stackoverflow.com/questions/667508/whats-a-good-rate-limiting-algorithm now := time.Now() elapsed := float64(now.Sub(r.last).Nanoseconds()) / 1e9 // seconds r.last = now r.allowance += elapsed * (r.maxPer...
[ "func", "(", "r", "*", "Throttler", ")", "ThrottleAdd", "(", "ct", "int32", ")", "(", "bool", ",", "int32", ")", "{", "if", "r", ".", "maxPer", "==", "0", "{", "return", "false", ",", "0", "\n", "}", "\n\n", "// http://stackoverflow.com/questions/667508/...
// Should we limit this because we are above rate? // Returns a bool of whether to throttle the message, and a count // of previous log messages throttled since last log message.
[ "Should", "we", "limit", "this", "because", "we", "are", "above", "rate?", "Returns", "a", "bool", "of", "whether", "to", "throttle", "the", "message", "and", "a", "count", "of", "previous", "log", "messages", "throttled", "since", "last", "log", "message", ...
c797efecbb6162ea2d4200cdf779c8b73da7233c
https://github.com/araddon/gou/blob/c797efecbb6162ea2d4200cdf779c8b73da7233c/throttle.go#L37-L64
142,368
mitchellh/go-linereader
linereader.go
New
func New(r io.Reader) *Reader { result := &Reader{ Reader: r, Timeout: 100 * time.Millisecond, Ch: make(chan string), } go result.Run() return result }
go
func New(r io.Reader) *Reader { result := &Reader{ Reader: r, Timeout: 100 * time.Millisecond, Ch: make(chan string), } go result.Run() return result }
[ "func", "New", "(", "r", "io", ".", "Reader", ")", "*", "Reader", "{", "result", ":=", "&", "Reader", "{", "Reader", ":", "r", ",", "Timeout", ":", "100", "*", "time", ".", "Millisecond", ",", "Ch", ":", "make", "(", "chan", "string", ")", ",", ...
// New creates a new Reader that reads lines from the io.Reader. // // The Reader is already started when returned, so it is unsafe to modify // any struct fields.
[ "New", "creates", "a", "new", "Reader", "that", "reads", "lines", "from", "the", "io", ".", "Reader", ".", "The", "Reader", "is", "already", "started", "when", "returned", "so", "it", "is", "unsafe", "to", "modify", "any", "struct", "fields", "." ]
1b945b3263eb070718f0a0742000234b5c8cab86
https://github.com/mitchellh/go-linereader/blob/1b945b3263eb070718f0a0742000234b5c8cab86/linereader.go#L26-L35
142,369
mitchellh/go-linereader
linereader.go
Run
func (r *Reader) Run() { if !atomic.CompareAndSwapUint32(&r.started, 0, 1) { return } // When we're done, close the channel defer close(r.Ch) // Listen for bytes in a goroutine. We do this so that if we're blocking // we can flush the bytes we have after some configured time. There is // probably a way to ma...
go
func (r *Reader) Run() { if !atomic.CompareAndSwapUint32(&r.started, 0, 1) { return } // When we're done, close the channel defer close(r.Ch) // Listen for bytes in a goroutine. We do this so that if we're blocking // we can flush the bytes we have after some configured time. There is // probably a way to ma...
[ "func", "(", "r", "*", "Reader", ")", "Run", "(", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapUint32", "(", "&", "r", ".", "started", ",", "0", ",", "1", ")", "{", "return", "\n", "}", "\n\n", "// When we're done, close the channel", "defer", "c...
// Run reads from the Reader and dispatches lines on the Ch channel. // // This blocks and is usually called with `go` prefixed to dispatch onto // a goroutine. It is safe to call this function multiple times; subsequent // calls to Run will exit without running.
[ "Run", "reads", "from", "the", "Reader", "and", "dispatches", "lines", "on", "the", "Ch", "channel", ".", "This", "blocks", "and", "is", "usually", "called", "with", "go", "prefixed", "to", "dispatch", "onto", "a", "goroutine", ".", "It", "is", "safe", "...
1b945b3263eb070718f0a0742000234b5c8cab86
https://github.com/mitchellh/go-linereader/blob/1b945b3263eb070718f0a0742000234b5c8cab86/linereader.go#L42-L118
142,370
twmb/algoimpl
go/various/inversions.go
inversionsCount
func inversionsCount(array, buffer []int) int { if len(array) <= 1 { return 0 } cleft := inversionsCount(buffer[:len(array)/2], array[:len(array)/2]) cright := inversionsCount(buffer[len(array)/2:], array[len(array)/2:]) ccross := inversionsCombine(array[:len(array)/2], array[len(array)/2:], buffer) return clef...
go
func inversionsCount(array, buffer []int) int { if len(array) <= 1 { return 0 } cleft := inversionsCount(buffer[:len(array)/2], array[:len(array)/2]) cright := inversionsCount(buffer[len(array)/2:], array[len(array)/2:]) ccross := inversionsCombine(array[:len(array)/2], array[len(array)/2:], buffer) return clef...
[ "func", "inversionsCount", "(", "array", ",", "buffer", "[", "]", "int", ")", "int", "{", "if", "len", "(", "array", ")", "<=", "1", "{", "return", "0", "\n", "}", "\n", "cleft", ":=", "inversionsCount", "(", "buffer", "[", ":", "len", "(", "array"...
// performs a mergesort while counting inversions
[ "performs", "a", "mergesort", "while", "counting", "inversions" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/various/inversions.go#L26-L34
142,371
twmb/algoimpl
go/sort/sort.go
InsertionSort
func InsertionSort(stuff Sortable) { for j := 1; j < stuff.Len(); j++ { // from the second spot to the last for i := j; i > 0 && stuff.Less(i, i-1); i-- { // while left is larger stuff.Swap(i, i-1) // slide right one position } } }
go
func InsertionSort(stuff Sortable) { for j := 1; j < stuff.Len(); j++ { // from the second spot to the last for i := j; i > 0 && stuff.Less(i, i-1); i-- { // while left is larger stuff.Swap(i, i-1) // slide right one position } } }
[ "func", "InsertionSort", "(", "stuff", "Sortable", ")", "{", "for", "j", ":=", "1", ";", "j", "<", "stuff", ".", "Len", "(", ")", ";", "j", "++", "{", "// from the second spot to the last", "for", "i", ":=", "j", ";", "i", ">", "0", "&&", "stuff", ...
// Insertion sort on Sortable type // Does not have start and end indices yet, like the Go authors of sort
[ "Insertion", "sort", "on", "Sortable", "type", "Does", "not", "have", "start", "and", "end", "indices", "yet", "like", "the", "Go", "authors", "of", "sort" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/sort/sort.go#L28-L34
142,372
twmb/algoimpl
go/graph/graph.go
New
func New(kind GraphType) *Graph { g := &Graph{} if kind == Directed { g.Kind = Directed } return g }
go
func New(kind GraphType) *Graph { g := &Graph{} if kind == Directed { g.Kind = Directed } return g }
[ "func", "New", "(", "kind", "GraphType", ")", "*", "Graph", "{", "g", ":=", "&", "Graph", "{", "}", "\n", "if", "kind", "==", "Directed", "{", "g", ".", "Kind", "=", "Directed", "\n", "}", "\n", "return", "g", "\n", "}" ]
// New creates and returns an empty graph. // If kind is Directed, returns a directed graph. // This function returns an undirected graph by default.
[ "New", "creates", "and", "returns", "an", "empty", "graph", ".", "If", "kind", "is", "Directed", "returns", "a", "directed", "graph", ".", "This", "function", "returns", "an", "undirected", "graph", "by", "default", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L67-L73
142,373
twmb/algoimpl
go/graph/graph.go
MakeNode
func (g *Graph) MakeNode() Node { newNode := &node{index: len(g.nodes)} newNode.container = Node{node: newNode, Value: new(interface{})} g.nodes = append(g.nodes, newNode) return newNode.container }
go
func (g *Graph) MakeNode() Node { newNode := &node{index: len(g.nodes)} newNode.container = Node{node: newNode, Value: new(interface{})} g.nodes = append(g.nodes, newNode) return newNode.container }
[ "func", "(", "g", "*", "Graph", ")", "MakeNode", "(", ")", "Node", "{", "newNode", ":=", "&", "node", "{", "index", ":", "len", "(", "g", ".", "nodes", ")", "}", "\n", "newNode", ".", "container", "=", "Node", "{", "node", ":", "newNode", ",", ...
// MakeNode creates a node, adds it to the graph and returns the new node.
[ "MakeNode", "creates", "a", "node", "adds", "it", "to", "the", "graph", "and", "returns", "the", "new", "node", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L76-L81
142,374
twmb/algoimpl
go/graph/graph.go
RemoveNode
func (g *Graph) RemoveNode(remove *Node) { if remove.node == nil { return } // O(V) nodeExists := false // remove all edges that connect from a different node to this one for _, node := range g.nodes { if node == remove.node { nodeExists = true continue } // O(E) swapIndex := -1 // index that the...
go
func (g *Graph) RemoveNode(remove *Node) { if remove.node == nil { return } // O(V) nodeExists := false // remove all edges that connect from a different node to this one for _, node := range g.nodes { if node == remove.node { nodeExists = true continue } // O(E) swapIndex := -1 // index that the...
[ "func", "(", "g", "*", "Graph", ")", "RemoveNode", "(", "remove", "*", "Node", ")", "{", "if", "remove", ".", "node", "==", "nil", "{", "return", "\n", "}", "\n", "// O(V)", "nodeExists", ":=", "false", "\n", "// remove all edges that connect from a differen...
// RemoveNode removes a node from the graph and all edges connected to it. // This function nils points in the Node structure. If 'remove' is used in // a map, you must delete the map index first.
[ "RemoveNode", "removes", "a", "node", "from", "the", "graph", "and", "all", "edges", "connected", "to", "it", ".", "This", "function", "nils", "points", "in", "the", "Node", "structure", ".", "If", "remove", "is", "used", "in", "a", "map", "you", "must",...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L86-L130
142,375
twmb/algoimpl
go/graph/graph.go
MakeEdge
func (g *Graph) MakeEdge(from, to Node) error { return g.MakeEdgeWeight(from, to, 0) }
go
func (g *Graph) MakeEdge(from, to Node) error { return g.MakeEdgeWeight(from, to, 0) }
[ "func", "(", "g", "*", "Graph", ")", "MakeEdge", "(", "from", ",", "to", "Node", ")", "error", "{", "return", "g", ".", "MakeEdgeWeight", "(", "from", ",", "to", ",", "0", ")", "\n", "}" ]
// MakeEdge calls MakeEdgeWeight with a weight of 0 and returns an error if either of the nodes do not // belong in the graph. Calling MakeEdge multiple times on the same nodes will not create multiple edges.
[ "MakeEdge", "calls", "MakeEdgeWeight", "with", "a", "weight", "of", "0", "and", "returns", "an", "error", "if", "either", "of", "the", "nodes", "do", "not", "belong", "in", "the", "graph", ".", "Calling", "MakeEdge", "multiple", "times", "on", "the", "same...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L134-L136
142,376
twmb/algoimpl
go/graph/graph.go
MakeEdgeWeight
func (g *Graph) MakeEdgeWeight(from, to Node, weight int) error { if from.node == nil || from.node.index >= len(g.nodes) || g.nodes[from.node.index] != from.node { return errors.New("First node in MakeEdge call does not belong to this graph") } if to.node == nil || to.node.index >= len(g.nodes) || g.nodes[to.node....
go
func (g *Graph) MakeEdgeWeight(from, to Node, weight int) error { if from.node == nil || from.node.index >= len(g.nodes) || g.nodes[from.node.index] != from.node { return errors.New("First node in MakeEdge call does not belong to this graph") } if to.node == nil || to.node.index >= len(g.nodes) || g.nodes[to.node....
[ "func", "(", "g", "*", "Graph", ")", "MakeEdgeWeight", "(", "from", ",", "to", "Node", ",", "weight", "int", ")", "error", "{", "if", "from", ".", "node", "==", "nil", "||", "from", ".", "node", ".", "index", ">=", "len", "(", "g", ".", "nodes", ...
// MakeEdgeWeight creates an edge in the graph with a corresponding weight. // It returns an error if either of the nodes do not belong in the graph. // // Calling MakeEdgeWeight multiple times on the same nodes will not create multiple edges; // this function will update the weight on the node to the new value.
[ "MakeEdgeWeight", "creates", "an", "edge", "in", "the", "graph", "with", "a", "corresponding", "weight", ".", "It", "returns", "an", "error", "if", "either", "of", "the", "nodes", "do", "not", "belong", "in", "the", "graph", ".", "Calling", "MakeEdgeWeight",...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L143-L176
142,377
twmb/algoimpl
go/graph/graph.go
RemoveEdge
func (g *Graph) RemoveEdge(from, to Node) { fromEdges := from.node.edges toEdges := to.node.edges toReversedEdges := to.node.reversedEdges for e := range fromEdges { // fix from->to if fromEdges[e].end == to.node { swapNRemoveEdge(e, &fromEdges) from.node.edges = fromEdges break } } for e := range to...
go
func (g *Graph) RemoveEdge(from, to Node) { fromEdges := from.node.edges toEdges := to.node.edges toReversedEdges := to.node.reversedEdges for e := range fromEdges { // fix from->to if fromEdges[e].end == to.node { swapNRemoveEdge(e, &fromEdges) from.node.edges = fromEdges break } } for e := range to...
[ "func", "(", "g", "*", "Graph", ")", "RemoveEdge", "(", "from", ",", "to", "Node", ")", "{", "fromEdges", ":=", "from", ".", "node", ".", "edges", "\n", "toEdges", ":=", "to", ".", "node", ".", "edges", "\n", "toReversedEdges", ":=", "to", ".", "no...
// RemoveEdge removes edges starting at the from node and ending at the to node. // If the graph is undirected, RemoveEdge will remove all edges between the nodes.
[ "RemoveEdge", "removes", "edges", "starting", "at", "the", "from", "node", "and", "ending", "at", "the", "to", "node", ".", "If", "the", "graph", "is", "undirected", "RemoveEdge", "will", "remove", "all", "edges", "between", "the", "nodes", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L180-L207
142,378
twmb/algoimpl
go/graph/graph.go
Neighbors
func (g *Graph) Neighbors(n Node) []Node { neighbors := make([]Node, 0, len(n.node.edges)) if g.nodes[n.node.index] == n.node { for _, edge := range n.node.edges { neighbors = append(neighbors, edge.end.container) } } return neighbors }
go
func (g *Graph) Neighbors(n Node) []Node { neighbors := make([]Node, 0, len(n.node.edges)) if g.nodes[n.node.index] == n.node { for _, edge := range n.node.edges { neighbors = append(neighbors, edge.end.container) } } return neighbors }
[ "func", "(", "g", "*", "Graph", ")", "Neighbors", "(", "n", "Node", ")", "[", "]", "Node", "{", "neighbors", ":=", "make", "(", "[", "]", "Node", ",", "0", ",", "len", "(", "n", ".", "node", ".", "edges", ")", ")", "\n", "if", "g", ".", "no...
// Neighbors returns a slice of nodes that are reachable from the given node in a graph.
[ "Neighbors", "returns", "a", "slice", "of", "nodes", "that", "are", "reachable", "from", "the", "given", "node", "in", "a", "graph", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L210-L218
142,379
twmb/algoimpl
go/graph/graph.go
swapNRemoveEdge
func swapNRemoveEdge(remove int, edges *[]edge) { (*edges)[remove], (*edges)[len(*edges)-1] = (*edges)[len(*edges)-1], (*edges)[remove] *edges = (*edges)[:len(*edges)-1] }
go
func swapNRemoveEdge(remove int, edges *[]edge) { (*edges)[remove], (*edges)[len(*edges)-1] = (*edges)[len(*edges)-1], (*edges)[remove] *edges = (*edges)[:len(*edges)-1] }
[ "func", "swapNRemoveEdge", "(", "remove", "int", ",", "edges", "*", "[", "]", "edge", ")", "{", "(", "*", "edges", ")", "[", "remove", "]", ",", "(", "*", "edges", ")", "[", "len", "(", "*", "edges", ")", "-", "1", "]", "=", "(", "*", "edges"...
// Swaps an edge to the end of the edges slice and 'removes' it by reslicing.
[ "Swaps", "an", "edge", "to", "the", "end", "of", "the", "edges", "slice", "and", "removes", "it", "by", "reslicing", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/graph.go#L221-L224
142,380
twmb/algoimpl
go/matrix/multiply.go
pad
func pad(M [][]int, power int) [][]int { newM := make([][]int, power) for i := 0; i < len(M); i++ { newM[i] = make([]int, power) copy(newM[i], M[i]) } for i := len(M); i < power; i++ { newM[i] = make([]int, power) } return newM }
go
func pad(M [][]int, power int) [][]int { newM := make([][]int, power) for i := 0; i < len(M); i++ { newM[i] = make([]int, power) copy(newM[i], M[i]) } for i := len(M); i < power; i++ { newM[i] = make([]int, power) } return newM }
[ "func", "pad", "(", "M", "[", "]", "[", "]", "int", ",", "power", "int", ")", "[", "]", "[", "]", "int", "{", "newM", ":=", "make", "(", "[", "]", "[", "]", "int", ",", "power", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(...
// pad to power of two and deep copy the elements
[ "pad", "to", "power", "of", "two", "and", "deep", "copy", "the", "elements" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/matrix/multiply.go#L45-L55
142,381
twmb/algoimpl
go/sort/integers/mergesort.go
MergeSort
func MergeSort(me []int, from, to int, tch chan<- int) { if from < to-1 { lch, rch := make(chan int), make(chan int) go MergeSort(me, from, (from+to)/2, lch) go MergeSort(me, (from+to)/2, to, rch) mergeCombine(lch, rch, tch) } else { for i := from; i < to; i++ { tch <- me[i] } close(tch) } }
go
func MergeSort(me []int, from, to int, tch chan<- int) { if from < to-1 { lch, rch := make(chan int), make(chan int) go MergeSort(me, from, (from+to)/2, lch) go MergeSort(me, (from+to)/2, to, rch) mergeCombine(lch, rch, tch) } else { for i := from; i < to; i++ { tch <- me[i] } close(tch) } }
[ "func", "MergeSort", "(", "me", "[", "]", "int", ",", "from", ",", "to", "int", ",", "tch", "chan", "<-", "int", ")", "{", "if", "from", "<", "to", "-", "1", "{", "lch", ",", "rch", ":=", "make", "(", "chan", "int", ")", ",", "make", "(", "...
// This function takes a slice to be sorted, a range to sort // and a channel to send in-order ints to.
[ "This", "function", "takes", "a", "slice", "to", "be", "sorted", "a", "range", "to", "sort", "and", "a", "channel", "to", "send", "in", "-", "order", "ints", "to", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/sort/integers/mergesort.go#L31-L43
142,382
twmb/algoimpl
go/tree/binary/binaryTree.go
Walk
func (b *BinaryTree) Walk() []Comparable { walked := make([]Comparable, 0, b.size) return walkInOrder(b.root, walked) }
go
func (b *BinaryTree) Walk() []Comparable { walked := make([]Comparable, 0, b.size) return walkInOrder(b.root, walked) }
[ "func", "(", "b", "*", "BinaryTree", ")", "Walk", "(", ")", "[", "]", "Comparable", "{", "walked", ":=", "make", "(", "[", "]", "Comparable", ",", "0", ",", "b", ".", "size", ")", "\n", "return", "walkInOrder", "(", "b", ".", "root", ",", "walked...
// Returns an in order Comparable slice of the binary tree.
[ "Returns", "an", "in", "order", "Comparable", "slice", "of", "the", "binary", "tree", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L38-L41
142,383
twmb/algoimpl
go/tree/binary/binaryTree.go
WalkPreOrder
func (b *BinaryTree) WalkPreOrder() []Comparable { walked := make([]Comparable, 0, b.size) return walkPreOrder(b.root, walked) }
go
func (b *BinaryTree) WalkPreOrder() []Comparable { walked := make([]Comparable, 0, b.size) return walkPreOrder(b.root, walked) }
[ "func", "(", "b", "*", "BinaryTree", ")", "WalkPreOrder", "(", ")", "[", "]", "Comparable", "{", "walked", ":=", "make", "(", "[", "]", "Comparable", ",", "0", ",", "b", ".", "size", ")", "\n", "return", "walkPreOrder", "(", "b", ".", "root", ",", ...
// Returns a pre order Comparable slice of the binary tree.
[ "Returns", "a", "pre", "order", "Comparable", "slice", "of", "the", "binary", "tree", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L54-L57
142,384
twmb/algoimpl
go/tree/binary/binaryTree.go
WalkPostOrder
func (b *BinaryTree) WalkPostOrder() []Comparable { walked := make([]Comparable, 0, b.size) return walkPostOrder(b.root, walked) }
go
func (b *BinaryTree) WalkPostOrder() []Comparable { walked := make([]Comparable, 0, b.size) return walkPostOrder(b.root, walked) }
[ "func", "(", "b", "*", "BinaryTree", ")", "WalkPostOrder", "(", ")", "[", "]", "Comparable", "{", "walked", ":=", "make", "(", "[", "]", "Comparable", ",", "0", ",", "b", ".", "size", ")", "\n", "return", "walkPostOrder", "(", "b", ".", "root", ","...
// Returns a post order Comparable slice of the binary tree.
[ "Returns", "a", "post", "order", "Comparable", "slice", "of", "the", "binary", "tree", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L70-L73
142,385
twmb/algoimpl
go/tree/binary/binaryTree.go
search
func (b *BinaryTree) search(target Comparable) *node { current := b.root for current != nil { switch current.value.CompareTo(target) { case -1: current = current.left case 0: return current case 1: current = current.right } } return nil }
go
func (b *BinaryTree) search(target Comparable) *node { current := b.root for current != nil { switch current.value.CompareTo(target) { case -1: current = current.left case 0: return current case 1: current = current.right } } return nil }
[ "func", "(", "b", "*", "BinaryTree", ")", "search", "(", "target", "Comparable", ")", "*", "node", "{", "current", ":=", "b", ".", "root", "\n", "for", "current", "!=", "nil", "{", "switch", "current", ".", "value", ".", "CompareTo", "(", "target", "...
// Search for a Comparable in the tree and returns the node that contains it. // If no node does, returns nil.
[ "Search", "for", "a", "Comparable", "in", "the", "tree", "and", "returns", "the", "node", "that", "contains", "it", ".", "If", "no", "node", "does", "returns", "nil", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L77-L90
142,386
twmb/algoimpl
go/tree/binary/binaryTree.go
Contains
func (b *BinaryTree) Contains(target Comparable) bool { return b.search(target) != nil }
go
func (b *BinaryTree) Contains(target Comparable) bool { return b.search(target) != nil }
[ "func", "(", "b", "*", "BinaryTree", ")", "Contains", "(", "target", "Comparable", ")", "bool", "{", "return", "b", ".", "search", "(", "target", ")", "!=", "nil", "\n", "}" ]
// Returns true if the binary tree contains the target Comparable
[ "Returns", "true", "if", "the", "binary", "tree", "contains", "the", "target", "Comparable" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L93-L95
142,387
twmb/algoimpl
go/tree/binary/binaryTree.go
minimum
func minimum(startNode *node) *node { current := startNode for current.left != nil { current = current.left } return current }
go
func minimum(startNode *node) *node { current := startNode for current.left != nil { current = current.left } return current }
[ "func", "minimum", "(", "startNode", "*", "node", ")", "*", "node", "{", "current", ":=", "startNode", "\n", "for", "current", ".", "left", "!=", "nil", "{", "current", "=", "current", ".", "left", "\n", "}", "\n", "return", "current", "\n", "}" ]
// returns a pointer to the node that contains the minimum // starting from the start node
[ "returns", "a", "pointer", "to", "the", "node", "that", "contains", "the", "minimum", "starting", "from", "the", "start", "node" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L99-L105
142,388
twmb/algoimpl
go/tree/binary/binaryTree.go
Maximum
func (b *BinaryTree) Maximum() *Comparable { current := b.root for current.right != nil { current = current.right } // copy rval := current.value return &rval }
go
func (b *BinaryTree) Maximum() *Comparable { current := b.root for current.right != nil { current = current.right } // copy rval := current.value return &rval }
[ "func", "(", "b", "*", "BinaryTree", ")", "Maximum", "(", ")", "*", "Comparable", "{", "current", ":=", "b", ".", "root", "\n", "for", "current", ".", "right", "!=", "nil", "{", "current", "=", "current", ".", "right", "\n", "}", "\n", "// copy", "...
// Returns a pointer to a copy of the maximum value // in the binary tree. If the tree is empty, this will // return nil.
[ "Returns", "a", "pointer", "to", "a", "copy", "of", "the", "maximum", "value", "in", "the", "binary", "tree", ".", "If", "the", "tree", "is", "empty", "this", "will", "return", "nil", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L117-L125
142,389
twmb/algoimpl
go/tree/binary/binaryTree.go
transplant
func (b *BinaryTree) transplant(old, replacement *node) { if old.parent == nil { b.root = replacement } else if old == old.parent.left { old.parent.left = replacement } else { old.parent.right = replacement } if replacement != nil { replacement.parent = old.parent } // garbage collect old.parent = nil ...
go
func (b *BinaryTree) transplant(old, replacement *node) { if old.parent == nil { b.root = replacement } else if old == old.parent.left { old.parent.left = replacement } else { old.parent.right = replacement } if replacement != nil { replacement.parent = old.parent } // garbage collect old.parent = nil ...
[ "func", "(", "b", "*", "BinaryTree", ")", "transplant", "(", "old", ",", "replacement", "*", "node", ")", "{", "if", "old", ".", "parent", "==", "nil", "{", "b", ".", "root", "=", "replacement", "\n", "}", "else", "if", "old", "==", "old", ".", "...
// Sets the replacement node's parent information to that // of the old node and updates the parent of the old node // to point to the replacement. This also updates pointer // values on the old node to nil. For garbage collection.
[ "Sets", "the", "replacement", "node", "s", "parent", "information", "to", "that", "of", "the", "old", "node", "and", "updates", "the", "parent", "of", "the", "old", "node", "to", "point", "to", "the", "replacement", ".", "This", "also", "updates", "pointer...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/tree/binary/binaryTree.go#L180-L195
142,390
twmb/algoimpl
go/various/random_select.go
partition
func partition(slice []int) int { pi := rand.Intn(len(slice)) n := len(slice) - 1 // convenience slice[n], slice[pi] = slice[pi], slice[n] // swap pivot to end b := 0 // boundry between larger and smaller elements. demarcates first element index larger than p...
go
func partition(slice []int) int { pi := rand.Intn(len(slice)) n := len(slice) - 1 // convenience slice[n], slice[pi] = slice[pi], slice[n] // swap pivot to end b := 0 // boundry between larger and smaller elements. demarcates first element index larger than p...
[ "func", "partition", "(", "slice", "[", "]", "int", ")", "int", "{", "pi", ":=", "rand", ".", "Intn", "(", "len", "(", "slice", ")", ")", "\n", "n", ":=", "len", "(", "slice", ")", "-", "1", "// convenience", "\n", "slice", "[", "n", "]", ",", ...
// returns the final pivot index
[ "returns", "the", "final", "pivot", "index" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/various/random_select.go#L9-L23
142,391
twmb/algoimpl
go/graph/functions.go
TopologicalSort
func (g *Graph) TopologicalSort() []Node { if g.Kind == Undirected { return nil } // init states for i := range g.nodes { g.nodes[i].state = unseen } sorted := make([]Node, 0, len(g.nodes)) // sort preorder (first jacket, then shirt) for _, node := range g.nodes { if node.state == unseen { g.dfs(node, ...
go
func (g *Graph) TopologicalSort() []Node { if g.Kind == Undirected { return nil } // init states for i := range g.nodes { g.nodes[i].state = unseen } sorted := make([]Node, 0, len(g.nodes)) // sort preorder (first jacket, then shirt) for _, node := range g.nodes { if node.state == unseen { g.dfs(node, ...
[ "func", "(", "g", "*", "Graph", ")", "TopologicalSort", "(", ")", "[", "]", "Node", "{", "if", "g", ".", "Kind", "==", "Undirected", "{", "return", "nil", "\n", "}", "\n", "// init states", "for", "i", ":=", "range", "g", ".", "nodes", "{", "g", ...
// TopologicalSort topoligically sorts a directed acyclic graph. // If the graph is cyclic, the sort order will change // based on which node the sort starts on. // // The StronglyConnectedComponents function can be used to determine if a graph has cycles.
[ "TopologicalSort", "topoligically", "sorts", "a", "directed", "acyclic", "graph", ".", "If", "the", "graph", "is", "cyclic", "the", "sort", "order", "will", "change", "based", "on", "which", "node", "the", "sort", "starts", "on", ".", "The", "StronglyConnected...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L67-L88
142,392
twmb/algoimpl
go/graph/functions.go
Reverse
func (g *Graph) Reverse() *Graph { reversed := New(Directed) if g.Kind == Undirected { reversed = New(Undirected) } // O(V) for _ = range g.nodes { reversed.MakeNode() } // O(V + E) for _, node := range g.nodes { for _, edge := range node.edges { reversed.MakeEdge(reversed.nodes[edge.end.index].contain...
go
func (g *Graph) Reverse() *Graph { reversed := New(Directed) if g.Kind == Undirected { reversed = New(Undirected) } // O(V) for _ = range g.nodes { reversed.MakeNode() } // O(V + E) for _, node := range g.nodes { for _, edge := range node.edges { reversed.MakeEdge(reversed.nodes[edge.end.index].contain...
[ "func", "(", "g", "*", "Graph", ")", "Reverse", "(", ")", "*", "Graph", "{", "reversed", ":=", "New", "(", "Directed", ")", "\n", "if", "g", ".", "Kind", "==", "Undirected", "{", "reversed", "=", "New", "(", "Undirected", ")", "\n", "}", "\n", "/...
// Reverse returns reversed copy of the directed graph g. // This function can be used to copy an undirected graph.
[ "Reverse", "returns", "reversed", "copy", "of", "the", "directed", "graph", "g", ".", "This", "function", "can", "be", "used", "to", "copy", "an", "undirected", "graph", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L92-L109
142,393
twmb/algoimpl
go/graph/functions.go
StronglyConnectedComponents
func (g *Graph) StronglyConnectedComponents() [][]Node { if g.Kind == Undirected { return g.sccUndirected() } return g.sccDirected() }
go
func (g *Graph) StronglyConnectedComponents() [][]Node { if g.Kind == Undirected { return g.sccUndirected() } return g.sccDirected() }
[ "func", "(", "g", "*", "Graph", ")", "StronglyConnectedComponents", "(", ")", "[", "]", "[", "]", "Node", "{", "if", "g", ".", "Kind", "==", "Undirected", "{", "return", "g", ".", "sccUndirected", "(", ")", "\n", "}", "\n", "return", "g", ".", "scc...
// StronglyConnectedComponents returns a slice of strongly connected nodes in a directed graph. // If used on an undirected graph, this function returns distinct connected components.
[ "StronglyConnectedComponents", "returns", "a", "slice", "of", "strongly", "connected", "nodes", "in", "a", "directed", "graph", ".", "If", "used", "on", "an", "undirected", "graph", "this", "function", "returns", "distinct", "connected", "components", "." ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L113-L118
142,394
twmb/algoimpl
go/graph/functions.go
sccUndirected
func (g *Graph) sccUndirected() [][]Node { components := make([][]Node, 0) for _, node := range g.nodes { if node.state == unseen { component := make([]Node, 0) g.bfs(node, &component) components = append(components, component) } } return components }
go
func (g *Graph) sccUndirected() [][]Node { components := make([][]Node, 0) for _, node := range g.nodes { if node.state == unseen { component := make([]Node, 0) g.bfs(node, &component) components = append(components, component) } } return components }
[ "func", "(", "g", "*", "Graph", ")", "sccUndirected", "(", ")", "[", "]", "[", "]", "Node", "{", "components", ":=", "make", "(", "[", "]", "[", "]", "Node", ",", "0", ")", "\n", "for", "_", ",", "node", ":=", "range", "g", ".", "nodes", "{",...
// the connected components algorithm for an undirected graph
[ "the", "connected", "components", "algorithm", "for", "an", "undirected", "graph" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L121-L131
142,395
twmb/algoimpl
go/graph/functions.go
sccDirected
func (g *Graph) sccDirected() [][]Node { components := make([][]Node, 0) finishOrder := g.TopologicalSort() for i := range finishOrder { finishOrder[i].node.state = unseen } for _, sink := range finishOrder { if g.nodes[sink.node.index].state == unseen { component := make([]Node, 0) g.dfsReversedEdges(g....
go
func (g *Graph) sccDirected() [][]Node { components := make([][]Node, 0) finishOrder := g.TopologicalSort() for i := range finishOrder { finishOrder[i].node.state = unseen } for _, sink := range finishOrder { if g.nodes[sink.node.index].state == unseen { component := make([]Node, 0) g.dfsReversedEdges(g....
[ "func", "(", "g", "*", "Graph", ")", "sccDirected", "(", ")", "[", "]", "[", "]", "Node", "{", "components", ":=", "make", "(", "[", "]", "[", "]", "Node", ",", "0", ")", "\n", "finishOrder", ":=", "g", ".", "TopologicalSort", "(", ")", "\n", "...
// the Strongly Connected Components algorithm for a directed graph
[ "the", "Strongly", "Connected", "Components", "algorithm", "for", "a", "directed", "graph" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L134-L148
142,396
twmb/algoimpl
go/graph/functions.go
shuffle
func shuffle(edges []lite.Edge) { for i := len(edges) - 1; i > 0; i-- { j := rand.Intn(i + 1) edges[j], edges[i] = edges[i], edges[j] } }
go
func shuffle(edges []lite.Edge) { for i := len(edges) - 1; i > 0; i-- { j := rand.Intn(i + 1) edges[j], edges[i] = edges[i], edges[j] } }
[ "func", "shuffle", "(", "edges", "[", "]", "lite", ".", "Edge", ")", "{", "for", "i", ":=", "len", "(", "edges", ")", "-", "1", ";", "i", ">", "0", ";", "i", "--", "{", "j", ":=", "rand", ".", "Intn", "(", "i", "+", "1", ")", "\n", "edges...
// Fischer-Yates shuffle
[ "Fischer", "-", "Yates", "shuffle" ]
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L243-L248
142,397
twmb/algoimpl
go/graph/functions.go
MinimumSpanningTree
func (g *Graph) MinimumSpanningTree() []Edge { if g.Kind == Directed { return nil } // create priority queue for vertices // node.data is the index into the heap // node.state is the weight of an edge to its parent nodesBase := nodeSlice(make([]*node, len(g.nodes))) copy(nodesBase, g.nodes) for i := range nod...
go
func (g *Graph) MinimumSpanningTree() []Edge { if g.Kind == Directed { return nil } // create priority queue for vertices // node.data is the index into the heap // node.state is the weight of an edge to its parent nodesBase := nodeSlice(make([]*node, len(g.nodes))) copy(nodesBase, g.nodes) for i := range nod...
[ "func", "(", "g", "*", "Graph", ")", "MinimumSpanningTree", "(", ")", "[", "]", "Edge", "{", "if", "g", ".", "Kind", "==", "Directed", "{", "return", "nil", "\n", "}", "\n", "// create priority queue for vertices", "// node.data is the index into the heap", "// ...
// MinimumSpanningTree will return the edges corresponding to the // minimum spanning tree in the graph based off of edge weight values. // This will return nil for a directed graph.
[ "MinimumSpanningTree", "will", "return", "the", "edges", "corresponding", "to", "the", "minimum", "spanning", "tree", "in", "the", "graph", "based", "off", "of", "edge", "weight", "values", ".", "This", "will", "return", "nil", "for", "a", "directed", "graph",...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L253-L293
142,398
twmb/algoimpl
go/graph/functions.go
MaxSpacingClustering
func (g *Graph) MaxSpacingClustering(n int) ([][]Node, int, error) { if n < 1 || n > len(g.nodes) { return nil, 0, errors.New("MaxSpacingClustering: invalid number of clusters requested") } mst := g.MinimumSpanningTree() sort.Sort(sort.Reverse(edgeSlice(mst))) distance := 0 // node.data is a cluster it belongs...
go
func (g *Graph) MaxSpacingClustering(n int) ([][]Node, int, error) { if n < 1 || n > len(g.nodes) { return nil, 0, errors.New("MaxSpacingClustering: invalid number of clusters requested") } mst := g.MinimumSpanningTree() sort.Sort(sort.Reverse(edgeSlice(mst))) distance := 0 // node.data is a cluster it belongs...
[ "func", "(", "g", "*", "Graph", ")", "MaxSpacingClustering", "(", "n", "int", ")", "(", "[", "]", "[", "]", "Node", ",", "int", ",", "error", ")", "{", "if", "n", "<", "1", "||", "n", ">", "len", "(", "g", ".", "nodes", ")", "{", "return", ...
// MaxSpacingClustering returns a slice of clusters // with the distance between the clusters maximized as // well as the maximized distance between these clusters. // It takes as input the number of clusters to compute.
[ "MaxSpacingClustering", "returns", "a", "slice", "of", "clusters", "with", "the", "distance", "between", "the", "clusters", "maximized", "as", "well", "as", "the", "maximized", "distance", "between", "these", "clusters", ".", "It", "takes", "as", "input", "the",...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/functions.go#L299-L324
142,399
twmb/algoimpl
go/graph/search.go
DijkstraSearch
func (g *Graph) DijkstraSearch(start Node) []Path { if start.node == nil || g.nodes[start.node.index] != start.node { return nil } paths := make([]Path, len(g.nodes)) nodesBase := nodeSlice(make([]*node, len(g.nodes))) copy(nodesBase, g.nodes) for i := range nodesBase { nodesBase[i].state = 1<<31 - 1 nodes...
go
func (g *Graph) DijkstraSearch(start Node) []Path { if start.node == nil || g.nodes[start.node.index] != start.node { return nil } paths := make([]Path, len(g.nodes)) nodesBase := nodeSlice(make([]*node, len(g.nodes))) copy(nodesBase, g.nodes) for i := range nodesBase { nodesBase[i].state = 1<<31 - 1 nodes...
[ "func", "(", "g", "*", "Graph", ")", "DijkstraSearch", "(", "start", "Node", ")", "[", "]", "Path", "{", "if", "start", ".", "node", "==", "nil", "||", "g", ".", "nodes", "[", "start", ".", "node", ".", "index", "]", "!=", "start", ".", "node", ...
// DijkstraSearch returns the shortest path from the start node to every other // node in the graph. All edges must have a positive weight, otherwise this // function will return nil.
[ "DijkstraSearch", "returns", "the", "shortest", "path", "from", "the", "start", "node", "to", "every", "other", "node", "in", "the", "graph", ".", "All", "edges", "must", "have", "a", "positive", "weight", "otherwise", "this", "function", "will", "return", "...
076353e90b94cccf4fe7cc41790d46f421da2d97
https://github.com/twmb/algoimpl/blob/076353e90b94cccf4fe7cc41790d46f421da2d97/go/graph/search.go#L11-L55