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
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
148,800
gocarina/gocsv
unmarshaller.go
validate
func validate(um *Unmarshaller, s interface{}, headers []string) error { concreteType := reflect.TypeOf(s) if concreteType.Kind() == reflect.Ptr { concreteType = concreteType.Elem() } if err := ensureOutInnerType(concreteType); err != nil { return err } structInfo := getStructInfo(concreteType) // Get struct ...
go
func validate(um *Unmarshaller, s interface{}, headers []string) error { concreteType := reflect.TypeOf(s) if concreteType.Kind() == reflect.Ptr { concreteType = concreteType.Elem() } if err := ensureOutInnerType(concreteType); err != nil { return err } structInfo := getStructInfo(concreteType) // Get struct ...
[ "func", "validate", "(", "um", "*", "Unmarshaller", ",", "s", "interface", "{", "}", ",", "headers", "[", "]", "string", ")", "error", "{", "concreteType", ":=", "reflect", ".", "TypeOf", "(", "s", ")", "\n", "if", "concreteType", ".", "Kind", "(", "...
// validate ensures that a struct was used to create the Unmarshaller, and validates // CSV headers against the CSV tags in the struct.
[ "validate", "ensures", "that", "a", "struct", "was", "used", "to", "create", "the", "Unmarshaller", "and", "validates", "CSV", "headers", "against", "the", "CSV", "tags", "in", "the", "struct", "." ]
2fc85fcf0c07e8bb9123b2104e84cfc2a5b53724
https://github.com/gocarina/gocsv/blob/2fc85fcf0c07e8bb9123b2104e84cfc2a5b53724/unmarshaller.go#L58-L93
148,801
gocarina/gocsv
unmarshaller.go
unmarshalRow
func (um *Unmarshaller) unmarshalRow(row []string, unmatched map[string]string) (interface{}, error) { isPointer := false concreteOutType := um.outType if um.outType.Kind() == reflect.Ptr { isPointer = true concreteOutType = concreteOutType.Elem() } outValue := createNewOutInner(isPointer, concreteOutType) fo...
go
func (um *Unmarshaller) unmarshalRow(row []string, unmatched map[string]string) (interface{}, error) { isPointer := false concreteOutType := um.outType if um.outType.Kind() == reflect.Ptr { isPointer = true concreteOutType = concreteOutType.Elem() } outValue := createNewOutInner(isPointer, concreteOutType) fo...
[ "func", "(", "um", "*", "Unmarshaller", ")", "unmarshalRow", "(", "row", "[", "]", "string", ",", "unmatched", "map", "[", "string", "]", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "isPointer", ":=", "false", "\n", "concreteOutT...
// unmarshalRow converts a CSV row to a struct, based on CSV struct tags. // If unmatched is non nil, it is populated with any columns that don't map to a struct field
[ "unmarshalRow", "converts", "a", "CSV", "row", "to", "a", "struct", "based", "on", "CSV", "struct", "tags", ".", "If", "unmatched", "is", "non", "nil", "it", "is", "populated", "with", "any", "columns", "that", "don", "t", "map", "to", "a", "struct", "...
2fc85fcf0c07e8bb9123b2104e84cfc2a5b53724
https://github.com/gocarina/gocsv/blob/2fc85fcf0c07e8bb9123b2104e84cfc2a5b53724/unmarshaller.go#L97-L115
148,802
golang/leveldb
db/db.go
close
func (m *mergingIter) close(i int) error { t := m.iters[i] if t == nil { return nil } err := t.Close() if m.err == nil { m.err = err } m.iters[i] = nil m.keys[i] = nil return err }
go
func (m *mergingIter) close(i int) error { t := m.iters[i] if t == nil { return nil } err := t.Close() if m.err == nil { m.err = err } m.iters[i] = nil m.keys[i] = nil return err }
[ "func", "(", "m", "*", "mergingIter", ")", "close", "(", "i", "int", ")", "error", "{", "t", ":=", "m", ".", "iters", "[", "i", "]", "\n", "if", "t", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "err", ":=", "t", ".", "Close", "(", "...
// close records that the i'th input iterator is done.
[ "close", "records", "that", "the", "i", "th", "input", "iterator", "is", "done", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/db/db.go#L223-L235
148,803
golang/leveldb
compaction.go
pickCompaction
func pickCompaction(vs *versionSet) (c *compaction) { cur := vs.currentVersion() // Pick a compaction based on size. If none exist, pick one based on seeks. if cur.compactionScore >= 1 { c = &compaction{ version: cur, level: cur.compactionLevel, } // TODO: Pick the first file that comes after the comp...
go
func pickCompaction(vs *versionSet) (c *compaction) { cur := vs.currentVersion() // Pick a compaction based on size. If none exist, pick one based on seeks. if cur.compactionScore >= 1 { c = &compaction{ version: cur, level: cur.compactionLevel, } // TODO: Pick the first file that comes after the comp...
[ "func", "pickCompaction", "(", "vs", "*", "versionSet", ")", "(", "c", "*", "compaction", ")", "{", "cur", ":=", "vs", ".", "currentVersion", "(", ")", "\n\n", "// Pick a compaction based on size. If none exist, pick one based on seeks.", "if", "cur", ".", "compacti...
// pickCompaction picks the best compaction, if any, for vs' current version.
[ "pickCompaction", "picks", "the", "best", "compaction", "if", "any", "for", "vs", "current", "version", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L43-L73
148,804
golang/leveldb
compaction.go
grow
func (c *compaction) grow(vs *versionSet, sm, la internalKey) bool { if len(c.inputs[1]) == 0 { return false } grow0 := c.version.overlaps(c.level, vs.ucmp, sm.ukey(), la.ukey()) if len(grow0) <= len(c.inputs[0]) { return false } if totalSize(grow0)+totalSize(c.inputs[1]) >= expandedCompactionByteSizeLimit { ...
go
func (c *compaction) grow(vs *versionSet, sm, la internalKey) bool { if len(c.inputs[1]) == 0 { return false } grow0 := c.version.overlaps(c.level, vs.ucmp, sm.ukey(), la.ukey()) if len(grow0) <= len(c.inputs[0]) { return false } if totalSize(grow0)+totalSize(c.inputs[1]) >= expandedCompactionByteSizeLimit { ...
[ "func", "(", "c", "*", "compaction", ")", "grow", "(", "vs", "*", "versionSet", ",", "sm", ",", "la", "internalKey", ")", "bool", "{", "if", "len", "(", "c", ".", "inputs", "[", "1", "]", ")", "==", "0", "{", "return", "false", "\n", "}", "\n",...
// grow grows the number of inputs at c.level without changing the number of // c.level+1 files in the compaction, and returns whether the inputs grew. sm // and la are the smallest and largest internalKeys in all of the inputs.
[ "grow", "grows", "the", "number", "of", "inputs", "at", "c", ".", "level", "without", "changing", "the", "number", "of", "c", ".", "level", "+", "1", "files", "in", "the", "compaction", "and", "returns", "whether", "the", "inputs", "grew", ".", "sm", "...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L100-L119
148,805
golang/leveldb
compaction.go
maybeScheduleCompaction
func (d *DB) maybeScheduleCompaction() { if d.compacting || d.closed { return } // TODO: check for manual compactions. if d.imm == nil { v := d.versions.currentVersion() // TODO: check v.fileToCompact. if v.compactionScore < 1 { // There is no work to be done. return } } d.compacting = true go d....
go
func (d *DB) maybeScheduleCompaction() { if d.compacting || d.closed { return } // TODO: check for manual compactions. if d.imm == nil { v := d.versions.currentVersion() // TODO: check v.fileToCompact. if v.compactionScore < 1 { // There is no work to be done. return } } d.compacting = true go d....
[ "func", "(", "d", "*", "DB", ")", "maybeScheduleCompaction", "(", ")", "{", "if", "d", ".", "compacting", "||", "d", ".", "closed", "{", "return", "\n", "}", "\n", "// TODO: check for manual compactions.", "if", "d", ".", "imm", "==", "nil", "{", "v", ...
// maybeScheduleCompaction schedules a compaction if necessary. // // d.mu must be held when calling this.
[ "maybeScheduleCompaction", "schedules", "a", "compaction", "if", "necessary", ".", "d", ".", "mu", "must", "be", "held", "when", "calling", "this", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L144-L159
148,806
golang/leveldb
compaction.go
compact
func (d *DB) compact() { d.mu.Lock() defer d.mu.Unlock() if err := d.compact1(); err != nil { // TODO: count consecutive compaction errors and backoff. } d.compacting = false // The previous compaction may have produced too many files in a // level, so reschedule another compaction if needed. d.maybeScheduleC...
go
func (d *DB) compact() { d.mu.Lock() defer d.mu.Unlock() if err := d.compact1(); err != nil { // TODO: count consecutive compaction errors and backoff. } d.compacting = false // The previous compaction may have produced too many files in a // level, so reschedule another compaction if needed. d.maybeScheduleC...
[ "func", "(", "d", "*", "DB", ")", "compact", "(", ")", "{", "d", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "err", ":=", "d", ".", "compact1", "(", ")", ";", "err", "!=", "nil", "...
// compact runs one compaction and maybe schedules another call to compact.
[ "compact", "runs", "one", "compaction", "and", "maybe", "schedules", "another", "call", "to", "compact", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L162-L173
148,807
golang/leveldb
compaction.go
compact1
func (d *DB) compact1() error { if d.imm != nil { return d.compactMemTable() } // TODO: support manual compactions. c := pickCompaction(&d.versions) if c == nil { return nil } // Check for a trivial move of one table from one level to the next. // We avoid such a move if there is lots of overlapping gran...
go
func (d *DB) compact1() error { if d.imm != nil { return d.compactMemTable() } // TODO: support manual compactions. c := pickCompaction(&d.versions) if c == nil { return nil } // Check for a trivial move of one table from one level to the next. // We avoid such a move if there is lots of overlapping gran...
[ "func", "(", "d", "*", "DB", ")", "compact1", "(", ")", "error", "{", "if", "d", ".", "imm", "!=", "nil", "{", "return", "d", ".", "compactMemTable", "(", ")", "\n", "}", "\n\n", "// TODO: support manual compactions.", "c", ":=", "pickCompaction", "(", ...
// compact1 runs one compaction. // // d.mu must be held when calling this, but the mutex may be dropped and // re-acquired during the course of this method.
[ "compact1", "runs", "one", "compaction", ".", "d", ".", "mu", "must", "be", "held", "when", "calling", "this", "but", "the", "mutex", "may", "be", "dropped", "and", "re", "-", "acquired", "during", "the", "course", "of", "this", "method", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L179-L222
148,808
golang/leveldb
compaction.go
compactMemTable
func (d *DB) compactMemTable() error { meta, err := d.writeLevel0Table(d.opts.GetFileSystem(), d.imm) if err != nil { return err } err = d.versions.logAndApply(d.dirname, &versionEdit{ logNumber: d.logNumber, newFiles: []newFileEntry{ {level: 0, meta: meta}, }, }) delete(d.pendingOutputs, meta.fileNum)...
go
func (d *DB) compactMemTable() error { meta, err := d.writeLevel0Table(d.opts.GetFileSystem(), d.imm) if err != nil { return err } err = d.versions.logAndApply(d.dirname, &versionEdit{ logNumber: d.logNumber, newFiles: []newFileEntry{ {level: 0, meta: meta}, }, }) delete(d.pendingOutputs, meta.fileNum)...
[ "func", "(", "d", "*", "DB", ")", "compactMemTable", "(", ")", "error", "{", "meta", ",", "err", ":=", "d", ".", "writeLevel0Table", "(", "d", ".", "opts", ".", "GetFileSystem", "(", ")", ",", "d", ".", "imm", ")", "\n", "if", "err", "!=", "nil",...
// compactMemTable runs a compaction that copies d.imm from memory to disk. // // d.mu must be held when calling this, but the mutex may be dropped and // re-acquired during the course of this method.
[ "compactMemTable", "runs", "a", "compaction", "that", "copies", "d", ".", "imm", "from", "memory", "to", "disk", ".", "d", ".", "mu", "must", "be", "held", "when", "calling", "this", "but", "the", "mutex", "may", "be", "dropped", "and", "re", "-", "acq...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L228-L246
148,809
golang/leveldb
compaction.go
compactionIterator
func compactionIterator(tc *tableCache, icmp db.Comparer, c *compaction) (cIter db.Iterator, retErr error) { iters := make([]db.Iterator, 0, len(c.inputs[0])+1) defer func() { if retErr != nil { for _, iter := range iters { if iter != nil { iter.Close() } } } }() if c.level != 0 { iter, er...
go
func compactionIterator(tc *tableCache, icmp db.Comparer, c *compaction) (cIter db.Iterator, retErr error) { iters := make([]db.Iterator, 0, len(c.inputs[0])+1) defer func() { if retErr != nil { for _, iter := range iters { if iter != nil { iter.Close() } } } }() if c.level != 0 { iter, er...
[ "func", "compactionIterator", "(", "tc", "*", "tableCache", ",", "icmp", "db", ".", "Comparer", ",", "c", "*", "compaction", ")", "(", "cIter", "db", ".", "Iterator", ",", "retErr", "error", ")", "{", "iters", ":=", "make", "(", "[", "]", "db", ".", ...
// compactionIterator returns an iterator over all the tables in a compaction.
[ "compactionIterator", "returns", "an", "iterator", "over", "all", "the", "tables", "in", "a", "compaction", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L393-L427
148,810
golang/leveldb
compaction.go
newConcatenatingIterator
func newConcatenatingIterator(tc *tableCache, inputs []fileMetadata) (cIter db.Iterator, retErr error) { iters := make([]db.Iterator, len(inputs)) defer func() { if retErr != nil { for _, iter := range iters { if iter != nil { iter.Close() } } } }() for i, f := range inputs { iter, err := ...
go
func newConcatenatingIterator(tc *tableCache, inputs []fileMetadata) (cIter db.Iterator, retErr error) { iters := make([]db.Iterator, len(inputs)) defer func() { if retErr != nil { for _, iter := range iters { if iter != nil { iter.Close() } } } }() for i, f := range inputs { iter, err := ...
[ "func", "newConcatenatingIterator", "(", "tc", "*", "tableCache", ",", "inputs", "[", "]", "fileMetadata", ")", "(", "cIter", "db", ".", "Iterator", ",", "retErr", "error", ")", "{", "iters", ":=", "make", "(", "[", "]", "db", ".", "Iterator", ",", "le...
// newConcatenatingIterator returns a concatenating iterator over all of the // input tables.
[ "newConcatenatingIterator", "returns", "a", "concatenating", "iterator", "over", "all", "of", "the", "input", "tables", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/compaction.go#L431-L451
148,811
golang/leveldb
table/reader.go
Set
func (r *Reader) Set(key, value []byte, o *db.WriteOptions) error { return errors.New("leveldb/table: cannot Set into a read-only table") }
go
func (r *Reader) Set(key, value []byte, o *db.WriteOptions) error { return errors.New("leveldb/table: cannot Set into a read-only table") }
[ "func", "(", "r", "*", "Reader", ")", "Set", "(", "key", ",", "value", "[", "]", "byte", ",", "o", "*", "db", ".", "WriteOptions", ")", "error", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// Set is provided to implement the DB interface, but returns an error, as a // Reader cannot write to a table.
[ "Set", "is", "provided", "to", "implement", "the", "DB", "interface", "but", "returns", "an", "error", "as", "a", "Reader", "cannot", "write", "to", "a", "table", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/reader.go#L350-L352
148,812
golang/leveldb
table/reader.go
Delete
func (r *Reader) Delete(key []byte, o *db.WriteOptions) error { return errors.New("leveldb/table: cannot Delete from a read-only table") }
go
func (r *Reader) Delete(key []byte, o *db.WriteOptions) error { return errors.New("leveldb/table: cannot Delete from a read-only table") }
[ "func", "(", "r", "*", "Reader", ")", "Delete", "(", "key", "[", "]", "byte", ",", "o", "*", "db", ".", "WriteOptions", ")", "error", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// Delete is provided to implement the DB interface, but returns an error, as a // Reader cannot write to a table.
[ "Delete", "is", "provided", "to", "implement", "the", "DB", "interface", "but", "returns", "an", "error", "as", "a", "Reader", "cannot", "write", "to", "a", "table", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/reader.go#L356-L358
148,813
golang/leveldb
table/reader.go
readBlock
func (r *Reader) readBlock(bh blockHandle) (block, error) { b := make([]byte, bh.length+blockTrailerLen) if _, err := r.file.ReadAt(b, int64(bh.offset)); err != nil { return nil, err } if r.verifyChecksums { checksum0 := binary.LittleEndian.Uint32(b[bh.length+1:]) checksum1 := crc.New(b[:bh.length+1]).Value()...
go
func (r *Reader) readBlock(bh blockHandle) (block, error) { b := make([]byte, bh.length+blockTrailerLen) if _, err := r.file.ReadAt(b, int64(bh.offset)); err != nil { return nil, err } if r.verifyChecksums { checksum0 := binary.LittleEndian.Uint32(b[bh.length+1:]) checksum1 := crc.New(b[:bh.length+1]).Value()...
[ "func", "(", "r", "*", "Reader", ")", "readBlock", "(", "bh", "blockHandle", ")", "(", "block", ",", "error", ")", "{", "b", ":=", "make", "(", "[", "]", "byte", ",", "bh", ".", "length", "+", "blockTrailerLen", ")", "\n", "if", "_", ",", "err", ...
// readBlock reads and decompresses a block from disk into memory.
[ "readBlock", "reads", "and", "decompresses", "a", "block", "from", "disk", "into", "memory", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/reader.go#L382-L405
148,814
golang/leveldb
table/reader.go
NewReader
func NewReader(f db.File, o *db.Options) *Reader { r := &Reader{ file: f, comparer: o.GetComparer(), verifyChecksums: o.GetVerifyChecksums(), } if f == nil { r.err = errors.New("leveldb/table: nil file") return r } stat, err := f.Stat() if err != nil { r.err = fmt.Errorf("leveldb/tab...
go
func NewReader(f db.File, o *db.Options) *Reader { r := &Reader{ file: f, comparer: o.GetComparer(), verifyChecksums: o.GetVerifyChecksums(), } if f == nil { r.err = errors.New("leveldb/table: nil file") return r } stat, err := f.Stat() if err != nil { r.err = fmt.Errorf("leveldb/tab...
[ "func", "NewReader", "(", "f", "db", ".", "File", ",", "o", "*", "db", ".", "Options", ")", "*", "Reader", "{", "r", ":=", "&", "Reader", "{", "file", ":", "f", ",", "comparer", ":", "o", ".", "GetComparer", "(", ")", ",", "verifyChecksums", ":",...
// NewReader returns a new table reader for the file. Closing the reader will // close the file.
[ "NewReader", "returns", "a", "new", "table", "reader", "for", "the", "file", ".", "Closing", "the", "reader", "will", "close", "the", "file", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/reader.go#L457-L506
148,815
golang/leveldb
bloom/bloom.go
MayContain
func (f Filter) MayContain(key []byte) bool { if len(f) < 2 { return false } k := f[len(f)-1] if k > 30 { // This is reserved for potentially new encodings for short Bloom filters. // Consider it a match. return true } nBits := uint32(8 * (len(f) - 1)) h := hash(key) delta := h>>17 | h<<15 for j := uin...
go
func (f Filter) MayContain(key []byte) bool { if len(f) < 2 { return false } k := f[len(f)-1] if k > 30 { // This is reserved for potentially new encodings for short Bloom filters. // Consider it a match. return true } nBits := uint32(8 * (len(f) - 1)) h := hash(key) delta := h>>17 | h<<15 for j := uin...
[ "func", "(", "f", "Filter", ")", "MayContain", "(", "key", "[", "]", "byte", ")", "bool", "{", "if", "len", "(", "f", ")", "<", "2", "{", "return", "false", "\n", "}", "\n", "k", ":=", "f", "[", "len", "(", "f", ")", "-", "1", "]", "\n", ...
// MayContain returns whether the filter may contain given key. False positives // are possible, where it returns true for keys not in the original set.
[ "MayContain", "returns", "whether", "the", "filter", "may", "contain", "given", "key", ".", "False", "positives", "are", "possible", "where", "it", "returns", "true", "for", "keys", "not", "in", "the", "original", "set", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/bloom/bloom.go#L13-L34
148,816
golang/leveldb
bloom/bloom.go
hash
func hash(b []byte) uint32 { const ( seed = 0xbc9f1d34 m = 0xc6a4a793 ) h := uint32(seed) ^ uint32(len(b)*m) for ; len(b) >= 4; b = b[4:] { h += uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 h *= m h ^= h >> 16 } switch len(b) { case 3: h += uint32(b[2]) << 16 fallthrough ...
go
func hash(b []byte) uint32 { const ( seed = 0xbc9f1d34 m = 0xc6a4a793 ) h := uint32(seed) ^ uint32(len(b)*m) for ; len(b) >= 4; b = b[4:] { h += uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 h *= m h ^= h >> 16 } switch len(b) { case 3: h += uint32(b[2]) << 16 fallthrough ...
[ "func", "hash", "(", "b", "[", "]", "byte", ")", "uint32", "{", "const", "(", "seed", "=", "0xbc9f1d34", "\n", "m", "=", "0xc6a4a793", "\n", ")", "\n", "h", ":=", "uint32", "(", "seed", ")", "^", "uint32", "(", "len", "(", "b", ")", "*", "m", ...
// hash implements a hashing algorithm similar to the Murmur hash.
[ "hash", "implements", "a", "hashing", "algorithm", "similar", "to", "the", "Murmur", "hash", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/bloom/bloom.go#L106-L130
148,817
golang/leveldb
bloom/bloom.go
AppendFilter
func (p FilterPolicy) AppendFilter(dst []byte, keys [][]byte) []byte { return appendFilter(dst, keys, int(p)) }
go
func (p FilterPolicy) AppendFilter(dst []byte, keys [][]byte) []byte { return appendFilter(dst, keys, int(p)) }
[ "func", "(", "p", "FilterPolicy", ")", "AppendFilter", "(", "dst", "[", "]", "byte", ",", "keys", "[", "]", "[", "]", "byte", ")", "[", "]", "byte", "{", "return", "appendFilter", "(", "dst", ",", "keys", ",", "int", "(", "p", ")", ")", "\n", "...
// AppendFilter implements the db.FilterPolicy interface.
[ "AppendFilter", "implements", "the", "db", ".", "FilterPolicy", "interface", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/bloom/bloom.go#L151-L153
148,818
golang/leveldb
bloom/bloom.go
MayContain
func (p FilterPolicy) MayContain(filter, key []byte) bool { return Filter(filter).MayContain(key) }
go
func (p FilterPolicy) MayContain(filter, key []byte) bool { return Filter(filter).MayContain(key) }
[ "func", "(", "p", "FilterPolicy", ")", "MayContain", "(", "filter", ",", "key", "[", "]", "byte", ")", "bool", "{", "return", "Filter", "(", "filter", ")", ".", "MayContain", "(", "key", ")", "\n", "}" ]
// MayContain implements the db.FilterPolicy interface.
[ "MayContain", "implements", "the", "db", ".", "FilterPolicy", "interface", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/bloom/bloom.go#L156-L158
148,819
golang/leveldb
table_cache.go
releaseNode
func (c *tableCache) releaseNode(n *tableCacheNode) { delete(c.nodes, n.fileNum) n.next.prev = n.prev n.prev.next = n.next n.refCount-- if n.refCount == 0 { go n.release() } }
go
func (c *tableCache) releaseNode(n *tableCacheNode) { delete(c.nodes, n.fileNum) n.next.prev = n.prev n.prev.next = n.next n.refCount-- if n.refCount == 0 { go n.release() } }
[ "func", "(", "c", "*", "tableCache", ")", "releaseNode", "(", "n", "*", "tableCacheNode", ")", "{", "delete", "(", "c", ".", "nodes", ",", "n", ".", "fileNum", ")", "\n", "n", ".", "next", ".", "prev", "=", "n", ".", "prev", "\n", "n", ".", "pr...
// releaseNode releases a node from the tableCache. // // c.mu must be held when calling this.
[ "releaseNode", "releases", "a", "node", "from", "the", "tableCache", ".", "c", ".", "mu", "must", "be", "held", "when", "calling", "this", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table_cache.go#L66-L74
148,820
golang/leveldb
table_cache.go
findNode
func (c *tableCache) findNode(fileNum uint64) *tableCacheNode { c.mu.Lock() defer c.mu.Unlock() n := c.nodes[fileNum] if n == nil { n = &tableCacheNode{ fileNum: fileNum, refCount: 1, result: make(chan tableReaderOrError, 1), } c.nodes[fileNum] = n if len(c.nodes) > c.size { // Release the t...
go
func (c *tableCache) findNode(fileNum uint64) *tableCacheNode { c.mu.Lock() defer c.mu.Unlock() n := c.nodes[fileNum] if n == nil { n = &tableCacheNode{ fileNum: fileNum, refCount: 1, result: make(chan tableReaderOrError, 1), } c.nodes[fileNum] = n if len(c.nodes) > c.size { // Release the t...
[ "func", "(", "c", "*", "tableCache", ")", "findNode", "(", "fileNum", "uint64", ")", "*", "tableCacheNode", "{", "c", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "n", ":=", "c", ".", "nodes", ...
// findNode returns the node for the table with the given file number, creating // that node if it didn't already exist. The caller is responsible for // decrementing the returned node's refCount.
[ "findNode", "returns", "the", "node", "for", "the", "table", "with", "the", "given", "file", "number", "creating", "that", "node", "if", "it", "didn", "t", "already", "exist", ".", "The", "caller", "is", "responsible", "for", "decrementing", "the", "returned...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table_cache.go#L79-L109
148,821
golang/leveldb
version.go
totalSize
func totalSize(f []fileMetadata) (size uint64) { for _, x := range f { size += x.size } return size }
go
func totalSize(f []fileMetadata) (size uint64) { for _, x := range f { size += x.size } return size }
[ "func", "totalSize", "(", "f", "[", "]", "fileMetadata", ")", "(", "size", "uint64", ")", "{", "for", "_", ",", "x", ":=", "range", "f", "{", "size", "+=", "x", ".", "size", "\n", "}", "\n", "return", "size", "\n", "}" ]
// totalSize returns the total size of all the files in f.
[ "totalSize", "returns", "the", "total", "size", "of", "all", "the", "files", "in", "f", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/version.go#L26-L31
148,822
golang/leveldb
version.go
ikeyRange
func ikeyRange(icmp db.Comparer, f0, f1 []fileMetadata) (smallest, largest internalKey) { first := true for _, f := range [2][]fileMetadata{f0, f1} { for _, meta := range f { if first { first = false smallest, largest = meta.smallest, meta.largest continue } if icmp.Compare(meta.smallest, small...
go
func ikeyRange(icmp db.Comparer, f0, f1 []fileMetadata) (smallest, largest internalKey) { first := true for _, f := range [2][]fileMetadata{f0, f1} { for _, meta := range f { if first { first = false smallest, largest = meta.smallest, meta.largest continue } if icmp.Compare(meta.smallest, small...
[ "func", "ikeyRange", "(", "icmp", "db", ".", "Comparer", ",", "f0", ",", "f1", "[", "]", "fileMetadata", ")", "(", "smallest", ",", "largest", "internalKey", ")", "{", "first", ":=", "true", "\n", "for", "_", ",", "f", ":=", "range", "[", "2", "]",...
// ikeyRange returns the minimum smallest and maximum largest internalKey for // all the fileMetadata in f0 and f1.
[ "ikeyRange", "returns", "the", "minimum", "smallest", "and", "maximum", "largest", "internalKey", "for", "all", "the", "fileMetadata", "in", "f0", "and", "f1", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/version.go#L35-L53
148,823
golang/leveldb
version.go
updateCompactionScore
func (v *version) updateCompactionScore() { // We treat level-0 specially by bounding the number of files instead of // number of bytes for two reasons: // // (1) With larger write-buffer sizes, it is nice not to do too many // level-0 compactions. // // (2) The files in level-0 are merged on every read and ther...
go
func (v *version) updateCompactionScore() { // We treat level-0 specially by bounding the number of files instead of // number of bytes for two reasons: // // (1) With larger write-buffer sizes, it is nice not to do too many // level-0 compactions. // // (2) The files in level-0 are merged on every read and ther...
[ "func", "(", "v", "*", "version", ")", "updateCompactionScore", "(", ")", "{", "// We treat level-0 specially by bounding the number of files instead of", "// number of bytes for two reasons:", "//", "// (1) With larger write-buffer sizes, it is nice not to do too many", "// level-0 comp...
// updateCompactionScore updates v's compaction score and level.
[ "updateCompactionScore", "updates", "v", "s", "compaction", "score", "and", "level", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/version.go#L108-L131
148,824
golang/leveldb
version.go
get
func (v *version) get(ikey internalKey, tiFinder tableIkeyFinder, ucmp db.Comparer, ro *db.ReadOptions) ([]byte, error) { ukey := ikey.ukey() // Iterate through v's tables, calling internalGet if the table's bounds // might contain ikey. Due to the order in which we search the tables, and // the internalKeyComparer...
go
func (v *version) get(ikey internalKey, tiFinder tableIkeyFinder, ucmp db.Comparer, ro *db.ReadOptions) ([]byte, error) { ukey := ikey.ukey() // Iterate through v's tables, calling internalGet if the table's bounds // might contain ikey. Due to the order in which we search the tables, and // the internalKeyComparer...
[ "func", "(", "v", "*", "version", ")", "get", "(", "ikey", "internalKey", ",", "tiFinder", "tableIkeyFinder", ",", "ucmp", "db", ".", "Comparer", ",", "ro", "*", "db", ".", "ReadOptions", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "ukey", ...
// get looks up the internal key ikey0 in v's tables such that ikey and ikey0 // have the same user key, and ikey0's sequence number is the highest such // sequence number that is less than or equal to ikey's sequence number. // // If ikey0's kind is set, the value for that previous set action is returned. // If ikey0'...
[ "get", "looks", "up", "the", "internal", "key", "ikey0", "in", "v", "s", "tables", "such", "that", "ikey", "and", "ikey0", "have", "the", "same", "user", "key", "and", "ikey0", "s", "sequence", "number", "is", "the", "highest", "such", "sequence", "numbe...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/version.go#L219-L280
148,825
golang/leveldb
ikey.go
valid
func (k internalKey) valid() bool { i := len(k) - 8 return i >= 0 && internalKeyKind(k[i]) <= internalKeyKindMax }
go
func (k internalKey) valid() bool { i := len(k) - 8 return i >= 0 && internalKeyKind(k[i]) <= internalKeyKindMax }
[ "func", "(", "k", "internalKey", ")", "valid", "(", ")", "bool", "{", "i", ":=", "len", "(", "k", ")", "-", "8", "\n", "return", "i", ">=", "0", "&&", "internalKeyKind", "(", "k", "[", "i", "]", ")", "<=", "internalKeyKindMax", "\n", "}" ]
// valid returns whether k is a valid internal key.
[ "valid", "returns", "whether", "k", "is", "a", "valid", "internal", "key", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/ikey.go#L69-L72
148,826
golang/leveldb
ikey.go
seqNum
func (k internalKey) seqNum() uint64 { i := len(k) - 7 n := uint64(k[i+0]) n |= uint64(k[i+1]) << 8 n |= uint64(k[i+2]) << 16 n |= uint64(k[i+3]) << 24 n |= uint64(k[i+4]) << 32 n |= uint64(k[i+5]) << 40 n |= uint64(k[i+6]) << 48 return n }
go
func (k internalKey) seqNum() uint64 { i := len(k) - 7 n := uint64(k[i+0]) n |= uint64(k[i+1]) << 8 n |= uint64(k[i+2]) << 16 n |= uint64(k[i+3]) << 24 n |= uint64(k[i+4]) << 32 n |= uint64(k[i+5]) << 40 n |= uint64(k[i+6]) << 48 return n }
[ "func", "(", "k", "internalKey", ")", "seqNum", "(", ")", "uint64", "{", "i", ":=", "len", "(", "k", ")", "-", "7", "\n", "n", ":=", "uint64", "(", "k", "[", "i", "+", "0", "]", ")", "\n", "n", "|=", "uint64", "(", "k", "[", "i", "+", "1"...
// seqNum returns the sequence number of an internal key. // seqNum may panic if k is not valid.
[ "seqNum", "returns", "the", "sequence", "number", "of", "an", "internal", "key", ".", "seqNum", "may", "panic", "if", "k", "is", "not", "valid", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/ikey.go#L88-L98
148,827
golang/leveldb
ikey.go
clone
func (k internalKey) clone() internalKey { x := make(internalKey, len(k)) copy(x, k) return x }
go
func (k internalKey) clone() internalKey { x := make(internalKey, len(k)) copy(x, k) return x }
[ "func", "(", "k", "internalKey", ")", "clone", "(", ")", "internalKey", "{", "x", ":=", "make", "(", "internalKey", ",", "len", "(", "k", ")", ")", "\n", "copy", "(", "x", ",", "k", ")", "\n", "return", "x", "\n", "}" ]
// clone returns an internalKey that has the same contents but is backed by a // different array.
[ "clone", "returns", "an", "internalKey", "that", "has", "the", "same", "contents", "but", "is", "backed", "by", "a", "different", "array", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/ikey.go#L102-L106
148,828
golang/leveldb
record/record.go
Next
func (r *Reader) Next() (io.Reader, error) { r.seq++ if r.err != nil { return nil, r.err } r.i = r.j r.err = r.nextChunk(true) if r.err != nil { return nil, r.err } r.started = true return singleReader{r, r.seq}, nil }
go
func (r *Reader) Next() (io.Reader, error) { r.seq++ if r.err != nil { return nil, r.err } r.i = r.j r.err = r.nextChunk(true) if r.err != nil { return nil, r.err } r.started = true return singleReader{r, r.seq}, nil }
[ "func", "(", "r", "*", "Reader", ")", "Next", "(", ")", "(", "io", ".", "Reader", ",", "error", ")", "{", "r", ".", "seq", "++", "\n", "if", "r", ".", "err", "!=", "nil", "{", "return", "nil", ",", "r", ".", "err", "\n", "}", "\n", "r", "...
// Next returns a reader for the next record. It returns io.EOF if there are no // more records. The reader returned becomes stale after the next Next call, // and should no longer be used.
[ "Next", "returns", "a", "reader", "for", "the", "next", "record", ".", "It", "returns", "io", ".", "EOF", "if", "there", "are", "no", "more", "records", ".", "The", "reader", "returned", "becomes", "stale", "after", "the", "next", "Next", "call", "and", ...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/record/record.go#L213-L225
148,829
golang/leveldb
record/record.go
Recover
func (r *Reader) Recover() { if r.err == nil { return } r.recovering = true r.err = nil // Discard the rest of the current block. r.i, r.j, r.last = r.n, r.n, false // Invalidate any outstanding singleReader. r.seq++ return }
go
func (r *Reader) Recover() { if r.err == nil { return } r.recovering = true r.err = nil // Discard the rest of the current block. r.i, r.j, r.last = r.n, r.n, false // Invalidate any outstanding singleReader. r.seq++ return }
[ "func", "(", "r", "*", "Reader", ")", "Recover", "(", ")", "{", "if", "r", ".", "err", "==", "nil", "{", "return", "\n", "}", "\n", "r", ".", "recovering", "=", "true", "\n", "r", ".", "err", "=", "nil", "\n", "// Discard the rest of the current bloc...
// Recover clears any errors read so far, so that calling Next will start // reading from the next good 32KiB block. If there are no such blocks, Next // will return io.EOF. Recover also marks the current reader, the one most // recently returned by Next, as stale. If Recover is called without any // prior error, then ...
[ "Recover", "clears", "any", "errors", "read", "so", "far", "so", "that", "calling", "Next", "will", "start", "reading", "from", "the", "next", "good", "32KiB", "block", ".", "If", "there", "are", "no", "such", "blocks", "Next", "will", "return", "io", "....
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/record/record.go#L232-L243
148,830
golang/leveldb
record/record.go
SeekRecord
func (r *Reader) SeekRecord(offset int64) error { r.seq++ if r.err != nil { return r.err } s, ok := r.r.(io.Seeker) if !ok { return ErrNotAnIOSeeker } // Only seek to an exact block offset. c := int(offset & blockSizeMask) if _, r.err = s.Seek(offset&^blockSizeMask, io.SeekStart); r.err != nil { return...
go
func (r *Reader) SeekRecord(offset int64) error { r.seq++ if r.err != nil { return r.err } s, ok := r.r.(io.Seeker) if !ok { return ErrNotAnIOSeeker } // Only seek to an exact block offset. c := int(offset & blockSizeMask) if _, r.err = s.Seek(offset&^blockSizeMask, io.SeekStart); r.err != nil { return...
[ "func", "(", "r", "*", "Reader", ")", "SeekRecord", "(", "offset", "int64", ")", "error", "{", "r", ".", "seq", "++", "\n", "if", "r", ".", "err", "!=", "nil", "{", "return", "r", ".", "err", "\n", "}", "\n\n", "s", ",", "ok", ":=", "r", ".",...
// SeekRecord seeks in the underlying io.Reader such that calling r.Next // returns the record whose first chunk header starts at the provided offset. // Its behavior is undefined if the argument given is not such an offset, as // the bytes at that offset may coincidentally appear to be a valid header. // // It returns...
[ "SeekRecord", "seeks", "in", "the", "underlying", "io", ".", "Reader", "such", "that", "calling", "r", ".", "Next", "returns", "the", "record", "whose", "first", "chunk", "header", "starts", "at", "the", "provided", "offset", ".", "Its", "behavior", "is", ...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/record/record.go#L263-L292
148,831
golang/leveldb
record/record.go
Next
func (w *Writer) Next() (io.Writer, error) { w.seq++ if w.err != nil { return nil, w.err } if w.pending { w.fillHeader(true) } w.i = w.j w.j = w.j + headerSize // Check if there is room in the block for the header. if w.j > blockSize { // Fill in the rest of the block with zeroes. for k := w.i; k < blo...
go
func (w *Writer) Next() (io.Writer, error) { w.seq++ if w.err != nil { return nil, w.err } if w.pending { w.fillHeader(true) } w.i = w.j w.j = w.j + headerSize // Check if there is room in the block for the header. if w.j > blockSize { // Fill in the rest of the block with zeroes. for k := w.i; k < blo...
[ "func", "(", "w", "*", "Writer", ")", "Next", "(", ")", "(", "io", ".", "Writer", ",", "error", ")", "{", "w", ".", "seq", "++", "\n", "if", "w", ".", "err", "!=", "nil", "{", "return", "nil", ",", "w", ".", "err", "\n", "}", "\n", "if", ...
// Next returns a writer for the next record. The writer returned becomes stale // after the next Close, Flush or Next call, and should no longer be used.
[ "Next", "returns", "a", "writer", "for", "the", "next", "record", ".", "The", "writer", "returned", "becomes", "stale", "after", "the", "next", "Close", "Flush", "or", "Next", "call", "and", "should", "no", "longer", "be", "used", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/record/record.go#L447-L472
148,832
golang/leveldb
record/record.go
LastRecordOffset
func (w *Writer) LastRecordOffset() (int64, error) { if w.err != nil { return 0, w.err } if w.lastRecordOffset < 0 { return 0, ErrNoLastRecord } return w.lastRecordOffset, nil }
go
func (w *Writer) LastRecordOffset() (int64, error) { if w.err != nil { return 0, w.err } if w.lastRecordOffset < 0 { return 0, ErrNoLastRecord } return w.lastRecordOffset, nil }
[ "func", "(", "w", "*", "Writer", ")", "LastRecordOffset", "(", ")", "(", "int64", ",", "error", ")", "{", "if", "w", ".", "err", "!=", "nil", "{", "return", "0", ",", "w", ".", "err", "\n", "}", "\n", "if", "w", ".", "lastRecordOffset", "<", "0...
// LastRecordOffset returns the offset in the underlying io.Writer of the last // record so far - the one created by the most recent Next call. It is the // offset of the first chunk header, suitable to pass to Reader.SeekRecord. // // If that io.Writer also implements io.Seeker, the return value is an absolute // offs...
[ "LastRecordOffset", "returns", "the", "offset", "in", "the", "underlying", "io", ".", "Writer", "of", "the", "last", "record", "so", "far", "-", "the", "one", "created", "by", "the", "most", "recent", "Next", "call", ".", "It", "is", "the", "offset", "of...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/record/record.go#L486-L494
148,833
golang/leveldb
table/writer.go
Get
func (w *Writer) Get(key []byte, o *db.ReadOptions) ([]byte, error) { return nil, errors.New("leveldb/table: cannot Get from a write-only table") }
go
func (w *Writer) Get(key []byte, o *db.ReadOptions) ([]byte, error) { return nil, errors.New("leveldb/table: cannot Get from a write-only table") }
[ "func", "(", "w", "*", "Writer", ")", "Get", "(", "key", "[", "]", "byte", ",", "o", "*", "db", ".", "ReadOptions", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", ...
// Get is provided to implement the DB interface, but returns an error, as a // Writer cannot read from a table.
[ "Get", "is", "provided", "to", "implement", "the", "DB", "interface", "but", "returns", "an", "error", "as", "a", "Writer", "cannot", "read", "from", "a", "table", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/writer.go#L170-L172
148,834
golang/leveldb
table/writer.go
Find
func (w *Writer) Find(key []byte, o *db.ReadOptions) db.Iterator { return &tableIter{ err: errors.New("leveldb/table: cannot Find from a write-only table"), } }
go
func (w *Writer) Find(key []byte, o *db.ReadOptions) db.Iterator { return &tableIter{ err: errors.New("leveldb/table: cannot Find from a write-only table"), } }
[ "func", "(", "w", "*", "Writer", ")", "Find", "(", "key", "[", "]", "byte", ",", "o", "*", "db", ".", "ReadOptions", ")", "db", ".", "Iterator", "{", "return", "&", "tableIter", "{", "err", ":", "errors", ".", "New", "(", "\"", "\"", ")", ",", ...
// Find is provided to implement the DB interface, but returns an error, as a // Writer cannot read from a table.
[ "Find", "is", "provided", "to", "implement", "the", "DB", "interface", "but", "returns", "an", "error", "as", "a", "Writer", "cannot", "read", "from", "a", "table", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/writer.go#L182-L186
148,835
golang/leveldb
table/writer.go
flushPendingBH
func (w *Writer) flushPendingBH(key []byte) { if w.pendingBH.length == 0 { // A valid blockHandle must be non-zero. // In particular, it must have a non-zero length. return } n0 := len(w.indexKeys) w.indexKeys = w.cmp.AppendSeparator(w.indexKeys, w.prevKey, key) n1 := len(w.indexKeys) w.indexEntries = appen...
go
func (w *Writer) flushPendingBH(key []byte) { if w.pendingBH.length == 0 { // A valid blockHandle must be non-zero. // In particular, it must have a non-zero length. return } n0 := len(w.indexKeys) w.indexKeys = w.cmp.AppendSeparator(w.indexKeys, w.prevKey, key) n1 := len(w.indexKeys) w.indexEntries = appen...
[ "func", "(", "w", "*", "Writer", ")", "flushPendingBH", "(", "key", "[", "]", "byte", ")", "{", "if", "w", ".", "pendingBH", ".", "length", "==", "0", "{", "// A valid blockHandle must be non-zero.", "// In particular, it must have a non-zero length.", "return", "...
// flushPendingBH adds any pending block handle to the index entries.
[ "flushPendingBH", "adds", "any", "pending", "block", "handle", "to", "the", "index", "entries", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/writer.go#L216-L227
148,836
golang/leveldb
table/writer.go
finishBlock
func (w *Writer) finishBlock() (blockHandle, error) { // Write the restart points to the buffer. if w.nEntries == 0 { // Every block must have at least one restart point. w.restarts = w.restarts[:1] w.restarts[0] = 0 } tmp4 := w.tmp[:4] for _, x := range w.restarts { binary.LittleEndian.PutUint32(tmp4, x) ...
go
func (w *Writer) finishBlock() (blockHandle, error) { // Write the restart points to the buffer. if w.nEntries == 0 { // Every block must have at least one restart point. w.restarts = w.restarts[:1] w.restarts[0] = 0 } tmp4 := w.tmp[:4] for _, x := range w.restarts { binary.LittleEndian.PutUint32(tmp4, x) ...
[ "func", "(", "w", "*", "Writer", ")", "finishBlock", "(", ")", "(", "blockHandle", ",", "error", ")", "{", "// Write the restart points to the buffer.", "if", "w", ".", "nEntries", "==", "0", "{", "// Every block must have at least one restart point.", "w", ".", "...
// finishBlock finishes the current block and returns its block handle, which is // its offset and length in the table.
[ "finishBlock", "finishes", "the", "current", "block", "and", "returns", "its", "block", "handle", "which", "is", "its", "offset", "and", "length", "in", "the", "table", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/writer.go#L249-L289
148,837
golang/leveldb
table/writer.go
NewWriter
func NewWriter(f db.File, o *db.Options) *Writer { w := &Writer{ closer: f, blockRestartInterval: o.GetBlockRestartInterval(), blockSize: o.GetBlockSize(), cmp: o.GetComparer(), compression: o.GetCompression(), filter: filterWriter{ policy: o.GetFilterP...
go
func NewWriter(f db.File, o *db.Options) *Writer { w := &Writer{ closer: f, blockRestartInterval: o.GetBlockRestartInterval(), blockSize: o.GetBlockSize(), cmp: o.GetComparer(), compression: o.GetCompression(), filter: filterWriter{ policy: o.GetFilterP...
[ "func", "NewWriter", "(", "f", "db", ".", "File", ",", "o", "*", "db", ".", "Options", ")", "*", "Writer", "{", "w", ":=", "&", "Writer", "{", "closer", ":", "f", ",", "blockRestartInterval", ":", "o", ".", "GetBlockRestartInterval", "(", ")", ",", ...
// NewWriter returns a new table writer for the file. Closing the writer will // close the file.
[ "NewWriter", "returns", "a", "new", "table", "writer", "for", "the", "file", ".", "Closing", "the", "writer", "will", "close", "the", "file", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/table/writer.go#L409-L437
148,838
golang/leveldb
memdb/memdb.go
ApproximateMemoryUsage
func (m *MemDB) ApproximateMemoryUsage() int { m.mutex.RLock() defer m.mutex.RUnlock() return len(m.kvData) }
go
func (m *MemDB) ApproximateMemoryUsage() int { m.mutex.RLock() defer m.mutex.RUnlock() return len(m.kvData) }
[ "func", "(", "m", "*", "MemDB", ")", "ApproximateMemoryUsage", "(", ")", "int", "{", "m", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "m", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "len", "(", "m", ".", "kvData", ")", "\n",...
// ApproximateMemoryUsage returns the approximate memory usage of the MemDB.
[ "ApproximateMemoryUsage", "returns", "the", "approximate", "memory", "usage", "of", "the", "MemDB", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/memdb/memdb.go#L223-L227
148,839
golang/leveldb
memdb/memdb.go
New
func New(o *db.Options) *MemDB { return &MemDB{ height: 1, cmp: o.GetComparer(), kvData: make([]byte, 0, 4096), // The first maxHeight values of nodeData are the next nodes after the // head node at each possible height. Their initial value is zeroNode. nodeData: make([]int, maxHeight, 256), } }
go
func New(o *db.Options) *MemDB { return &MemDB{ height: 1, cmp: o.GetComparer(), kvData: make([]byte, 0, 4096), // The first maxHeight values of nodeData are the next nodes after the // head node at each possible height. Their initial value is zeroNode. nodeData: make([]int, maxHeight, 256), } }
[ "func", "New", "(", "o", "*", "db", ".", "Options", ")", "*", "MemDB", "{", "return", "&", "MemDB", "{", "height", ":", "1", ",", "cmp", ":", "o", ".", "GetComparer", "(", ")", ",", "kvData", ":", "make", "(", "[", "]", "byte", ",", "0", ",",...
// New returns a new MemDB.
[ "New", "returns", "a", "new", "MemDB", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/memdb/memdb.go#L237-L246
148,840
golang/leveldb
version_set.go
createManifest
func (vs *versionSet) createManifest(dirname string) (err error) { var ( filename = dbFilename(dirname, fileTypeManifest, vs.manifestFileNumber) manifestFile db.File manifest *record.Writer ) defer func() { if manifest != nil { manifest.Close() } if manifestFile != nil { manifestFile.Close(...
go
func (vs *versionSet) createManifest(dirname string) (err error) { var ( filename = dbFilename(dirname, fileTypeManifest, vs.manifestFileNumber) manifestFile db.File manifest *record.Writer ) defer func() { if manifest != nil { manifest.Close() } if manifestFile != nil { manifestFile.Close(...
[ "func", "(", "vs", "*", "versionSet", ")", "createManifest", "(", "dirname", "string", ")", "(", "err", "error", ")", "{", "var", "(", "filename", "=", "dbFilename", "(", "dirname", ",", "fileTypeManifest", ",", "vs", ".", "manifestFileNumber", ")", "\n", ...
// createManifest creates a manifest file that contains a snapshot of vs.
[ "createManifest", "creates", "a", "manifest", "file", "that", "contains", "a", "snapshot", "of", "vs", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/version_set.go#L193-L241
148,841
golang/leveldb
leveldb.go
replayLogFile
func (d *DB) replayLogFile(ve *versionEdit, fs db.FileSystem, filename string) (maxSeqNum uint64, err error) { file, err := fs.Open(filename) if err != nil { return 0, err } defer file.Close() var ( mem *memdb.MemDB batchBuf = new(bytes.Buffer) ikey = make(internalKey, 512) rr = record.Ne...
go
func (d *DB) replayLogFile(ve *versionEdit, fs db.FileSystem, filename string) (maxSeqNum uint64, err error) { file, err := fs.Open(filename) if err != nil { return 0, err } defer file.Close() var ( mem *memdb.MemDB batchBuf = new(bytes.Buffer) ikey = make(internalKey, 512) rr = record.Ne...
[ "func", "(", "d", "*", "DB", ")", "replayLogFile", "(", "ve", "*", "versionEdit", ",", "fs", "db", ".", "FileSystem", ",", "filename", "string", ")", "(", "maxSeqNum", "uint64", ",", "err", "error", ")", "{", "file", ",", "err", ":=", "fs", ".", "O...
// replayLogFile replays the edits in the named log file. // // d.mu must be held when calling this, but the mutex may be dropped and // re-acquired during the course of this method.
[ "replayLogFile", "replays", "the", "edits", "in", "the", "named", "log", "file", ".", "d", ".", "mu", "must", "be", "held", "when", "calling", "this", "but", "the", "mutex", "may", "be", "dropped", "and", "re", "-", "acquired", "during", "the", "course",...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/leveldb.go#L358-L445
148,842
golang/leveldb
leveldb.go
makeRoomForWrite
func (d *DB) makeRoomForWrite(force bool) error { allowDelay := !force for { // TODO: check any previous sticky error, if the paranoid option is set. if allowDelay && len(d.versions.currentVersion().files[0]) > l0SlowdownWritesTrigger { // We are getting close to hitting a hard limit on the number of // L0...
go
func (d *DB) makeRoomForWrite(force bool) error { allowDelay := !force for { // TODO: check any previous sticky error, if the paranoid option is set. if allowDelay && len(d.versions.currentVersion().files[0]) > l0SlowdownWritesTrigger { // We are getting close to hitting a hard limit on the number of // L0...
[ "func", "(", "d", "*", "DB", ")", "makeRoomForWrite", "(", "force", "bool", ")", "error", "{", "allowDelay", ":=", "!", "force", "\n", "for", "{", "// TODO: check any previous sticky error, if the paranoid option is set.", "if", "allowDelay", "&&", "len", "(", "d"...
// makeRoomForWrite ensures that there is room in d.mem for the next write. // // d.mu must be held when calling this, but the mutex may be dropped and // re-acquired during the course of this method.
[ "makeRoomForWrite", "ensures", "that", "there", "is", "room", "in", "d", ".", "mem", "for", "the", "next", "write", ".", "d", ".", "mu", "must", "be", "held", "when", "calling", "this", "but", "the", "mutex", "may", "be", "dropped", "and", "re", "-", ...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/leveldb.go#L564-L623
148,843
golang/leveldb
leveldb.go
deleteObsoleteFiles
func (d *DB) deleteObsoleteFiles() { liveFileNums := map[uint64]struct{}{} for fileNum := range d.pendingOutputs { liveFileNums[fileNum] = struct{}{} } d.versions.addLiveFileNums(liveFileNums) logNumber := d.versions.logNumber manifestFileNumber := d.versions.manifestFileNumber // Release the d.mu lock while ...
go
func (d *DB) deleteObsoleteFiles() { liveFileNums := map[uint64]struct{}{} for fileNum := range d.pendingOutputs { liveFileNums[fileNum] = struct{}{} } d.versions.addLiveFileNums(liveFileNums) logNumber := d.versions.logNumber manifestFileNumber := d.versions.manifestFileNumber // Release the d.mu lock while ...
[ "func", "(", "d", "*", "DB", ")", "deleteObsoleteFiles", "(", ")", "{", "liveFileNums", ":=", "map", "[", "uint64", "]", "struct", "{", "}", "{", "}", "\n", "for", "fileNum", ":=", "range", "d", ".", "pendingOutputs", "{", "liveFileNums", "[", "fileNum...
// deleteObsoleteFiles deletes those files that are no longer needed. // // d.mu must be held when calling this, but the mutex may be dropped and // re-acquired during the course of this method.
[ "deleteObsoleteFiles", "deletes", "those", "files", "that", "are", "no", "longer", "needed", ".", "d", ".", "mu", "must", "be", "held", "when", "calling", "this", "but", "the", "mutex", "may", "be", "dropped", "and", "re", "-", "acquired", "during", "the",...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/leveldb.go#L629-L673
148,844
golang/leveldb
memfs/memfs.go
New
func New() db.FileSystem { return &fileSystem{ root: &node{ children: make(map[string]*node), isDir: true, }, } }
go
func New() db.FileSystem { return &fileSystem{ root: &node{ children: make(map[string]*node), isDir: true, }, } }
[ "func", "New", "(", ")", "db", ".", "FileSystem", "{", "return", "&", "fileSystem", "{", "root", ":", "&", "node", "{", "children", ":", "make", "(", "map", "[", "string", "]", "*", "node", ")", ",", "isDir", ":", "true", ",", "}", ",", "}", "\...
// New returns a new memory-backed db.FileSystem implementation.
[ "New", "returns", "a", "new", "memory", "-", "backed", "db", ".", "FileSystem", "implementation", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/memfs/memfs.go#L34-L41
148,845
golang/leveldb
version_edit.go
apply
func (b *bulkVersionEdit) apply(base *version, icmp db.Comparer) (*version, error) { v := new(version) for level := range v.files { combined := [2][]fileMetadata{ nil, b.added[level], } if base != nil { combined[0] = base.files[level] } n := len(combined[0]) + len(combined[1]) if n == 0 { cont...
go
func (b *bulkVersionEdit) apply(base *version, icmp db.Comparer) (*version, error) { v := new(version) for level := range v.files { combined := [2][]fileMetadata{ nil, b.added[level], } if base != nil { combined[0] = base.files[level] } n := len(combined[0]) + len(combined[1]) if n == 0 { cont...
[ "func", "(", "b", "*", "bulkVersionEdit", ")", "apply", "(", "base", "*", "version", ",", "icmp", "db", ".", "Comparer", ")", "(", "*", "version", ",", "error", ")", "{", "v", ":=", "new", "(", "version", ")", "\n", "for", "level", ":=", "range", ...
// apply applies the delta b to a base version to produce a new version. The // new version is consistent with respect to the internal key comparer icmp. // // base may be nil, which is equivalent to a pointer to a zero version.
[ "apply", "applies", "the", "delta", "b", "to", "a", "base", "version", "to", "produce", "a", "new", "version", ".", "The", "new", "version", "is", "consistent", "with", "respect", "to", "the", "internal", "key", "comparer", "icmp", ".", "base", "may", "b...
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/version_edit.go#L324-L364
148,846
golang/leveldb
batch.go
Set
func (b *Batch) Set(key, value []byte) { if len(b.data) == 0 { b.init(len(key) + len(value) + 2*binary.MaxVarintLen64 + batchHeaderLen) } if b.increment() { b.data = append(b.data, byte(internalKeyKindSet)) b.appendStr(key) b.appendStr(value) } }
go
func (b *Batch) Set(key, value []byte) { if len(b.data) == 0 { b.init(len(key) + len(value) + 2*binary.MaxVarintLen64 + batchHeaderLen) } if b.increment() { b.data = append(b.data, byte(internalKeyKindSet)) b.appendStr(key) b.appendStr(value) } }
[ "func", "(", "b", "*", "Batch", ")", "Set", "(", "key", ",", "value", "[", "]", "byte", ")", "{", "if", "len", "(", "b", ".", "data", ")", "==", "0", "{", "b", ".", "init", "(", "len", "(", "key", ")", "+", "len", "(", "value", ")", "+", ...
// Set adds an action to the batch that sets the key to map to the value.
[ "Set", "adds", "an", "action", "to", "the", "batch", "that", "sets", "the", "key", "to", "map", "to", "the", "value", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/batch.go#L31-L40
148,847
golang/leveldb
batch.go
Delete
func (b *Batch) Delete(key []byte) { if len(b.data) == 0 { b.init(len(key) + binary.MaxVarintLen64 + batchHeaderLen) } if b.increment() { b.data = append(b.data, byte(internalKeyKindDelete)) b.appendStr(key) } }
go
func (b *Batch) Delete(key []byte) { if len(b.data) == 0 { b.init(len(key) + binary.MaxVarintLen64 + batchHeaderLen) } if b.increment() { b.data = append(b.data, byte(internalKeyKindDelete)) b.appendStr(key) } }
[ "func", "(", "b", "*", "Batch", ")", "Delete", "(", "key", "[", "]", "byte", ")", "{", "if", "len", "(", "b", ".", "data", ")", "==", "0", "{", "b", ".", "init", "(", "len", "(", "key", ")", "+", "binary", ".", "MaxVarintLen64", "+", "batchHe...
// Delete adds an action to the batch that deletes the entry for key.
[ "Delete", "adds", "an", "action", "to", "the", "batch", "that", "deletes", "the", "entry", "for", "key", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/batch.go#L43-L51
148,848
golang/leveldb
batch.go
next
func (t *batchIter) next() (kind internalKeyKind, ukey []byte, value []byte, ok bool) { p := *t if len(p) == 0 { return 0, nil, nil, false } kind, *t = internalKeyKind(p[0]), p[1:] if kind > internalKeyKindMax { return 0, nil, nil, false } ukey, ok = t.nextStr() if !ok { return 0, nil, nil, false } if k...
go
func (t *batchIter) next() (kind internalKeyKind, ukey []byte, value []byte, ok bool) { p := *t if len(p) == 0 { return 0, nil, nil, false } kind, *t = internalKeyKind(p[0]), p[1:] if kind > internalKeyKindMax { return 0, nil, nil, false } ukey, ok = t.nextStr() if !ok { return 0, nil, nil, false } if k...
[ "func", "(", "t", "*", "batchIter", ")", "next", "(", ")", "(", "kind", "internalKeyKind", ",", "ukey", "[", "]", "byte", ",", "value", "[", "]", "byte", ",", "ok", "bool", ")", "{", "p", ":=", "*", "t", "\n", "if", "len", "(", "p", ")", "=="...
// next returns the next operation in this batch. // The final return value is false if the batch is corrupt.
[ "next", "returns", "the", "next", "operation", "in", "this", "batch", ".", "The", "final", "return", "value", "is", "false", "if", "the", "batch", "is", "corrupt", "." ]
259d9253d71996b7778a3efb4144fe4892342b18
https://github.com/golang/leveldb/blob/259d9253d71996b7778a3efb4144fe4892342b18/batch.go#L116-L136
148,849
chzyer/readline
rawreader_windows.go
Read
func (r *RawReader) Read(buf []byte) (int, error) { ir := new(_INPUT_RECORD) var read int var err error next: err = kernel.ReadConsoleInputW(stdin, uintptr(unsafe.Pointer(ir)), 1, uintptr(unsafe.Pointer(&read)), ) if err != nil { return 0, err } if ir.EventType != EVENT_KEY { goto next } ker := (*_K...
go
func (r *RawReader) Read(buf []byte) (int, error) { ir := new(_INPUT_RECORD) var read int var err error next: err = kernel.ReadConsoleInputW(stdin, uintptr(unsafe.Pointer(ir)), 1, uintptr(unsafe.Pointer(&read)), ) if err != nil { return 0, err } if ir.EventType != EVENT_KEY { goto next } ker := (*_K...
[ "func", "(", "r", "*", "RawReader", ")", "Read", "(", "buf", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "ir", ":=", "new", "(", "_INPUT_RECORD", ")", "\n", "var", "read", "int", "\n", "var", "err", "error", "\n", "next", ":", "e...
// only process one action in one read
[ "only", "process", "one", "action", "in", "one", "read" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/rawreader_windows.go#L40-L110
148,850
chzyer/readline
example/readline-pass-strength/readline-pass-strength.go
Colorize
func Colorize(msg string, color int) string { return ColorEscape(color) + msg + ColorResetEscape }
go
func Colorize(msg string, color int) string { return ColorEscape(color) + msg + ColorResetEscape }
[ "func", "Colorize", "(", "msg", "string", ",", "color", "int", ")", "string", "{", "return", "ColorEscape", "(", "color", ")", "+", "msg", "+", "ColorResetEscape", "\n", "}" ]
// Colorize the msg using ANSI color escapes
[ "Colorize", "the", "msg", "using", "ANSI", "color", "escapes" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/example/readline-pass-strength/readline-pass-strength.go#L47-L49
148,851
chzyer/readline
history.go
historyUpdatePath
func (o *opHistory) historyUpdatePath(path string) { o.fdLock.Lock() defer o.fdLock.Unlock() f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666) if err != nil { return } o.fd = f r := bufio.NewReader(o.fd) total := 0 for ; ; total++ { line, err := r.ReadString('\n') if err != nil { br...
go
func (o *opHistory) historyUpdatePath(path string) { o.fdLock.Lock() defer o.fdLock.Unlock() f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666) if err != nil { return } o.fd = f r := bufio.NewReader(o.fd) total := 0 for ; ; total++ { line, err := r.ReadString('\n') if err != nil { br...
[ "func", "(", "o", "*", "opHistory", ")", "historyUpdatePath", "(", "path", "string", ")", "{", "o", ".", "fdLock", ".", "Lock", "(", ")", "\n", "defer", "o", ".", "fdLock", ".", "Unlock", "(", ")", "\n", "f", ",", "err", ":=", "os", ".", "OpenFil...
// only called by newOpHistory
[ "only", "called", "by", "newOpHistory" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/history.go#L66-L95
148,852
chzyer/readline
utils_unix.go
SuspendMe
func SuspendMe() { p, _ := os.FindProcess(os.Getppid()) p.Signal(syscall.SIGTSTP) p, _ = os.FindProcess(os.Getpid()) p.Signal(syscall.SIGTSTP) }
go
func SuspendMe() { p, _ := os.FindProcess(os.Getppid()) p.Signal(syscall.SIGTSTP) p, _ = os.FindProcess(os.Getpid()) p.Signal(syscall.SIGTSTP) }
[ "func", "SuspendMe", "(", ")", "{", "p", ",", "_", ":=", "os", ".", "FindProcess", "(", "os", ".", "Getppid", "(", ")", ")", "\n", "p", ".", "Signal", "(", "syscall", ".", "SIGTSTP", ")", "\n", "p", ",", "_", "=", "os", ".", "FindProcess", "(",...
// SuspendMe use to send suspend signal to myself, when we in the raw mode. // For OSX it need to send to parent's pid // For Linux it need to send to myself
[ "SuspendMe", "use", "to", "send", "suspend", "signal", "to", "myself", "when", "we", "in", "the", "raw", "mode", ".", "For", "OSX", "it", "need", "to", "send", "to", "parent", "s", "pid", "For", "Linux", "it", "need", "to", "send", "to", "myself" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/utils_unix.go#L23-L28
148,853
chzyer/readline
example/readline-demo/readline-demo.go
listFiles
func listFiles(path string) func(string) []string { return func(line string) []string { names := make([]string, 0) files, _ := ioutil.ReadDir(path) for _, f := range files { names = append(names, f.Name()) } return names } }
go
func listFiles(path string) func(string) []string { return func(line string) []string { names := make([]string, 0) files, _ := ioutil.ReadDir(path) for _, f := range files { names = append(names, f.Name()) } return names } }
[ "func", "listFiles", "(", "path", "string", ")", "func", "(", "string", ")", "[", "]", "string", "{", "return", "func", "(", "line", "string", ")", "[", "]", "string", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "fil...
// Function constructor - constructs new function for listing given directory
[ "Function", "constructor", "-", "constructs", "new", "function", "for", "listing", "given", "directory" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/example/readline-demo/readline-demo.go#L21-L30
148,854
chzyer/readline
terminal.go
SleepToResume
func (t *Terminal) SleepToResume() { if !atomic.CompareAndSwapInt32(&t.sleeping, 0, 1) { return } defer atomic.StoreInt32(&t.sleeping, 0) t.ExitRawMode() ch := WaitForResume() SuspendMe() <-ch t.EnterRawMode() }
go
func (t *Terminal) SleepToResume() { if !atomic.CompareAndSwapInt32(&t.sleeping, 0, 1) { return } defer atomic.StoreInt32(&t.sleeping, 0) t.ExitRawMode() ch := WaitForResume() SuspendMe() <-ch t.EnterRawMode() }
[ "func", "(", "t", "*", "Terminal", ")", "SleepToResume", "(", ")", "{", "if", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "t", ".", "sleeping", ",", "0", ",", "1", ")", "{", "return", "\n", "}", "\n", "defer", "atomic", ".", "StoreInt32", ...
// SleepToResume will sleep myself, and return only if I'm resumed.
[ "SleepToResume", "will", "sleep", "myself", "and", "return", "only", "if", "I", "m", "resumed", "." ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/terminal.go#L43-L54
148,855
chzyer/readline
operation.go
SaveHistory
func (o *Operation) SaveHistory(content string) error { return o.history.New([]rune(content)) }
go
func (o *Operation) SaveHistory(content string) error { return o.history.New([]rune(content)) }
[ "func", "(", "o", "*", "Operation", ")", "SaveHistory", "(", "content", "string", ")", "error", "{", "return", "o", ".", "history", ".", "New", "(", "[", "]", "rune", "(", "content", ")", ")", "\n", "}" ]
// if err is not nil, it just mean it fail to write to file // other things goes fine.
[ "if", "err", "is", "not", "nil", "it", "just", "mean", "it", "fail", "to", "write", "to", "file", "other", "things", "goes", "fine", "." ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/operation.go#L493-L495
148,856
chzyer/readline
std.go
getInstance
func getInstance() *Instance { stdOnce.Do(func() { std, _ = NewEx(&Config{ DisableAutoSaveHistory: true, }) }) return std }
go
func getInstance() *Instance { stdOnce.Do(func() { std, _ = NewEx(&Config{ DisableAutoSaveHistory: true, }) }) return std }
[ "func", "getInstance", "(", ")", "*", "Instance", "{", "stdOnce", ".", "Do", "(", "func", "(", ")", "{", "std", ",", "_", "=", "NewEx", "(", "&", "Config", "{", "DisableAutoSaveHistory", ":", "true", ",", "}", ")", "\n", "}", ")", "\n", "return", ...
// global instance will not submit history automatic
[ "global", "instance", "will", "not", "submit", "history", "automatic" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/std.go#L22-L29
148,857
chzyer/readline
std.go
SetHistoryPath
func SetHistoryPath(fp string) { ins := getInstance() cfg := ins.Config.Clone() cfg.HistoryFile = fp ins.SetConfig(cfg) }
go
func SetHistoryPath(fp string) { ins := getInstance() cfg := ins.Config.Clone() cfg.HistoryFile = fp ins.SetConfig(cfg) }
[ "func", "SetHistoryPath", "(", "fp", "string", ")", "{", "ins", ":=", "getInstance", "(", ")", "\n", "cfg", ":=", "ins", ".", "Config", ".", "Clone", "(", ")", "\n", "cfg", ".", "HistoryFile", "=", "fp", "\n", "ins", ".", "SetConfig", "(", "cfg", "...
// let readline load history from filepath // and try to persist history into disk // set fp to "" to prevent readline persisting history to disk // so the `AddHistory` will return nil error forever.
[ "let", "readline", "load", "history", "from", "filepath", "and", "try", "to", "persist", "history", "into", "disk", "set", "fp", "to", "to", "prevent", "readline", "persisting", "history", "to", "disk", "so", "the", "AddHistory", "will", "return", "nil", "er...
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/std.go#L35-L40
148,858
chzyer/readline
std.go
SetAutoComplete
func SetAutoComplete(completer AutoCompleter) { ins := getInstance() cfg := ins.Config.Clone() cfg.AutoComplete = completer ins.SetConfig(cfg) }
go
func SetAutoComplete(completer AutoCompleter) { ins := getInstance() cfg := ins.Config.Clone() cfg.AutoComplete = completer ins.SetConfig(cfg) }
[ "func", "SetAutoComplete", "(", "completer", "AutoCompleter", ")", "{", "ins", ":=", "getInstance", "(", ")", "\n", "cfg", ":=", "ins", ".", "Config", ".", "Clone", "(", ")", "\n", "cfg", ".", "AutoComplete", "=", "completer", "\n", "ins", ".", "SetConfi...
// set auto completer to global instance
[ "set", "auto", "completer", "to", "global", "instance" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/std.go#L43-L48
148,859
chzyer/readline
std.go
Line
func Line(prompt string) (string, error) { ins := getInstance() ins.SetPrompt(prompt) return ins.Readline() }
go
func Line(prompt string) (string, error) { ins := getInstance() ins.SetPrompt(prompt) return ins.Readline() }
[ "func", "Line", "(", "prompt", "string", ")", "(", "string", ",", "error", ")", "{", "ins", ":=", "getInstance", "(", ")", "\n", "ins", ".", "SetPrompt", "(", "prompt", ")", "\n", "return", "ins", ".", "Readline", "(", ")", "\n", "}" ]
// readline with global configs
[ "readline", "with", "global", "configs" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/std.go#L63-L67
148,860
chzyer/readline
std.go
NewFillableStdin
func NewFillableStdin(stdin io.Reader) (io.ReadCloser, io.Writer) { r, w := io.Pipe() s := &FillableStdin{ stdinBuffer: r, stdin: stdin, } s.ioloop() return s, w }
go
func NewFillableStdin(stdin io.Reader) (io.ReadCloser, io.Writer) { r, w := io.Pipe() s := &FillableStdin{ stdinBuffer: r, stdin: stdin, } s.ioloop() return s, w }
[ "func", "NewFillableStdin", "(", "stdin", "io", ".", "Reader", ")", "(", "io", ".", "ReadCloser", ",", "io", ".", "Writer", ")", "{", "r", ",", "w", ":=", "io", ".", "Pipe", "(", ")", "\n", "s", ":=", "&", "FillableStdin", "{", "stdinBuffer", ":", ...
// NewFillableStdin gives you FillableStdin
[ "NewFillableStdin", "gives", "you", "FillableStdin" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/std.go#L146-L154
148,861
chzyer/readline
std.go
Read
func (s *FillableStdin) Read(p []byte) (n int, err error) { s.Lock() i := len(s.buf) if len(p) < i { i = len(p) } if i > 0 { n := copy(p, s.buf) s.buf = s.buf[:0] cerr := s.bufErr s.bufErr = nil s.Unlock() return n, cerr } s.Unlock() n, err = s.stdin.Read(p) return n, err }
go
func (s *FillableStdin) Read(p []byte) (n int, err error) { s.Lock() i := len(s.buf) if len(p) < i { i = len(p) } if i > 0 { n := copy(p, s.buf) s.buf = s.buf[:0] cerr := s.bufErr s.bufErr = nil s.Unlock() return n, cerr } s.Unlock() n, err = s.stdin.Read(p) return n, err }
[ "func", "(", "s", "*", "FillableStdin", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "s", ".", "Lock", "(", ")", "\n", "i", ":=", "len", "(", "s", ".", "buf", ")", "\n", "if", "len", "(", "...
// Read will read from the local buffer and if no data, read from stdin
[ "Read", "will", "read", "from", "the", "local", "buffer", "and", "if", "no", "data", "read", "from", "stdin" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/std.go#L175-L192
148,862
chzyer/readline
runes.go
IndexAll
func (rs Runes) IndexAll(r, sub []rune) int { return rs.IndexAllEx(r, sub, false) }
go
func (rs Runes) IndexAll(r, sub []rune) int { return rs.IndexAllEx(r, sub, false) }
[ "func", "(", "rs", "Runes", ")", "IndexAll", "(", "r", ",", "sub", "[", "]", "rune", ")", "int", "{", "return", "rs", ".", "IndexAllEx", "(", "r", ",", "sub", ",", "false", ")", "\n", "}" ]
// Search in runes from front to end
[ "Search", "in", "runes", "from", "front", "to", "end" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/runes.go#L84-L86
148,863
chzyer/readline
utils.go
WaitForResume
func WaitForResume() chan struct{} { ch := make(chan struct{}) var wg sync.WaitGroup wg.Add(1) go func() { ticker := time.NewTicker(10 * time.Millisecond) t := time.Now() wg.Done() for { now := <-ticker.C if now.Sub(t) > 100*time.Millisecond { break } t = now } ticker.Stop() ch <- stru...
go
func WaitForResume() chan struct{} { ch := make(chan struct{}) var wg sync.WaitGroup wg.Add(1) go func() { ticker := time.NewTicker(10 * time.Millisecond) t := time.Now() wg.Done() for { now := <-ticker.C if now.Sub(t) > 100*time.Millisecond { break } t = now } ticker.Stop() ch <- stru...
[ "func", "WaitForResume", "(", ")", "chan", "struct", "{", "}", "{", "ch", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "var", "wg", "sync", ".", "WaitGroup", "\n", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{",...
// WaitForResume need to call before current process got suspend. // It will run a ticker until a long duration is occurs, // which means this process is resumed.
[ "WaitForResume", "need", "to", "call", "before", "current", "process", "got", "suspend", ".", "It", "will", "run", "a", "ticker", "until", "a", "long", "duration", "is", "occurs", "which", "means", "this", "process", "is", "resumed", "." ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/utils.go#L59-L79
148,864
chzyer/readline
utils.go
escapeExKey
func escapeExKey(key *escapeKeyPair) rune { var r rune switch key.typ { case 'D': r = CharBackward case 'C': r = CharForward case 'A': r = CharPrev case 'B': r = CharNext case 'H': r = CharLineStart case 'F': r = CharLineEnd case '~': if key.attr == "3" { r = CharDelete } default: } retur...
go
func escapeExKey(key *escapeKeyPair) rune { var r rune switch key.typ { case 'D': r = CharBackward case 'C': r = CharForward case 'A': r = CharPrev case 'B': r = CharNext case 'H': r = CharLineStart case 'F': r = CharLineEnd case '~': if key.attr == "3" { r = CharDelete } default: } retur...
[ "func", "escapeExKey", "(", "key", "*", "escapeKeyPair", ")", "rune", "{", "var", "r", "rune", "\n", "switch", "key", ".", "typ", "{", "case", "'D'", ":", "r", "=", "CharBackward", "\n", "case", "'C'", ":", "r", "=", "CharForward", "\n", "case", "'A'...
// translate Esc[X
[ "translate", "Esc", "[", "X" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/utils.go#L100-L122
148,865
chzyer/readline
utils.go
escapeKey
func escapeKey(r rune, reader *bufio.Reader) rune { switch r { case 'b': r = MetaBackward case 'f': r = MetaForward case 'd': r = MetaDelete case CharTranspose: r = MetaTranspose case CharBackspace: r = MetaBackspace case 'O': d, _, _ := reader.ReadRune() switch d { case 'H': r = CharLineStart...
go
func escapeKey(r rune, reader *bufio.Reader) rune { switch r { case 'b': r = MetaBackward case 'f': r = MetaForward case 'd': r = MetaDelete case CharTranspose: r = MetaTranspose case CharBackspace: r = MetaBackspace case 'O': d, _, _ := reader.ReadRune() switch d { case 'H': r = CharLineStart...
[ "func", "escapeKey", "(", "r", "rune", ",", "reader", "*", "bufio", ".", "Reader", ")", "rune", "{", "switch", "r", "{", "case", "'b'", ":", "r", "=", "MetaBackward", "\n", "case", "'f'", ":", "r", "=", "MetaForward", "\n", "case", "'d'", ":", "r",...
// translate EscX to Meta+X
[ "translate", "EscX", "to", "Meta", "+", "X" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/utils.go#L163-L189
148,866
chzyer/readline
utils.go
LineCount
func LineCount(screenWidth, w int) int { r := w / screenWidth if w%screenWidth != 0 { r++ } return r }
go
func LineCount(screenWidth, w int) int { r := w / screenWidth if w%screenWidth != 0 { r++ } return r }
[ "func", "LineCount", "(", "screenWidth", ",", "w", "int", ")", "int", "{", "r", ":=", "w", "/", "screenWidth", "\n", "if", "w", "%", "screenWidth", "!=", "0", "{", "r", "++", "\n", "}", "\n", "return", "r", "\n", "}" ]
// calculate how many lines for N character
[ "calculate", "how", "many", "lines", "for", "N", "character" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/utils.go#L210-L216
148,867
chzyer/readline
utils.go
Debug
func Debug(o ...interface{}) { f, _ := os.OpenFile("debug.tmp", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) fmt.Fprintln(f, o...) f.Close() }
go
func Debug(o ...interface{}) { f, _ := os.OpenFile("debug.tmp", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) fmt.Fprintln(f, o...) f.Close() }
[ "func", "Debug", "(", "o", "...", "interface", "{", "}", ")", "{", "f", ",", "_", ":=", "os", ".", "OpenFile", "(", "\"", "\"", ",", "os", ".", "O_RDWR", "|", "os", ".", "O_CREATE", "|", "os", ".", "O_APPEND", ",", "0666", ")", "\n", "fmt", "...
// append log info to another file
[ "append", "log", "info", "to", "another", "file" ]
2972be24d48e78746da79ba8e24e8b488c9880de
https://github.com/chzyer/readline/blob/2972be24d48e78746da79ba8e24e8b488c9880de/utils.go#L273-L277
148,868
hoisie/web
web.go
SetCookie
func (ctx *Context) SetCookie(cookie *http.Cookie) { ctx.SetHeader("Set-Cookie", cookie.String(), false) }
go
func (ctx *Context) SetCookie(cookie *http.Cookie) { ctx.SetHeader("Set-Cookie", cookie.String(), false) }
[ "func", "(", "ctx", "*", "Context", ")", "SetCookie", "(", "cookie", "*", "http", ".", "Cookie", ")", "{", "ctx", ".", "SetHeader", "(", "\"", "\"", ",", "cookie", ".", "String", "(", ")", ",", "false", ")", "\n", "}" ]
// SetCookie adds a cookie header to the response.
[ "SetCookie", "adds", "a", "cookie", "header", "to", "the", "response", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/web.go#L108-L110
148,869
hoisie/web
web.go
Process
func Process(c http.ResponseWriter, req *http.Request) { mainServer.Process(c, req) }
go
func Process(c http.ResponseWriter, req *http.Request) { mainServer.Process(c, req) }
[ "func", "Process", "(", "c", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "mainServer", ".", "Process", "(", "c", ",", "req", ")", "\n", "}" ]
// Process invokes the main server's routing system.
[ "Process", "invokes", "the", "main", "server", "s", "routing", "system", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/web.go#L136-L138
148,870
hoisie/web
web.go
RunTLS
func RunTLS(addr string, config *tls.Config) { mainServer.RunTLS(addr, config) }
go
func RunTLS(addr string, config *tls.Config) { mainServer.RunTLS(addr, config) }
[ "func", "RunTLS", "(", "addr", "string", ",", "config", "*", "tls", ".", "Config", ")", "{", "mainServer", ".", "RunTLS", "(", "addr", ",", "config", ")", "\n", "}" ]
// RunTLS starts the web application and serves HTTPS requests for the main server.
[ "RunTLS", "starts", "the", "web", "application", "and", "serves", "HTTPS", "requests", "for", "the", "main", "server", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/web.go#L146-L148
148,871
hoisie/web
web.go
Match
func Match(method string, route string, handler interface{}) { mainServer.addRoute(route, method, handler) }
go
func Match(method string, route string, handler interface{}) { mainServer.addRoute(route, method, handler) }
[ "func", "Match", "(", "method", "string", ",", "route", "string", ",", "handler", "interface", "{", "}", ")", "{", "mainServer", ".", "addRoute", "(", "route", ",", "method", ",", "handler", ")", "\n", "}" ]
// Match adds a handler for an arbitrary http method in the main server.
[ "Match", "adds", "a", "handler", "for", "an", "arbitrary", "http", "method", "in", "the", "main", "server", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/web.go#L186-L188
148,872
hoisie/web
server.go
ServeHTTP
func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request) { s.Process(c, req) }
go
func (s *Server) ServeHTTP(c http.ResponseWriter, req *http.Request) { s.Process(c, req) }
[ "func", "(", "s", "*", "Server", ")", "ServeHTTP", "(", "c", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "s", ".", "Process", "(", "c", ",", "req", ")", "\n", "}" ]
// ServeHTTP is the interface method for Go's http server package
[ "ServeHTTP", "is", "the", "interface", "method", "for", "Go", "s", "http", "server", "package" ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L97-L99
148,873
hoisie/web
server.go
Process
func (s *Server) Process(c http.ResponseWriter, req *http.Request) { route := s.routeHandler(req, c) if route != nil { route.httpHandler.ServeHTTP(c, req) } }
go
func (s *Server) Process(c http.ResponseWriter, req *http.Request) { route := s.routeHandler(req, c) if route != nil { route.httpHandler.ServeHTTP(c, req) } }
[ "func", "(", "s", "*", "Server", ")", "Process", "(", "c", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "route", ":=", "s", ".", "routeHandler", "(", "req", ",", "c", ")", "\n", "if", "route", "!=", "nil", "{"...
// Process invokes the routing system for server s
[ "Process", "invokes", "the", "routing", "system", "for", "server", "s" ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L102-L107
148,874
hoisie/web
server.go
Get
func (s *Server) Get(route string, handler interface{}) { s.addRoute(route, "GET", handler) }
go
func (s *Server) Get(route string, handler interface{}) { s.addRoute(route, "GET", handler) }
[ "func", "(", "s", "*", "Server", ")", "Get", "(", "route", "string", ",", "handler", "interface", "{", "}", ")", "{", "s", ".", "addRoute", "(", "route", ",", "\"", "\"", ",", "handler", ")", "\n", "}" ]
// Get adds a handler for the 'GET' http method for server s.
[ "Get", "adds", "a", "handler", "for", "the", "GET", "http", "method", "for", "server", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L110-L112
148,875
hoisie/web
server.go
Post
func (s *Server) Post(route string, handler interface{}) { s.addRoute(route, "POST", handler) }
go
func (s *Server) Post(route string, handler interface{}) { s.addRoute(route, "POST", handler) }
[ "func", "(", "s", "*", "Server", ")", "Post", "(", "route", "string", ",", "handler", "interface", "{", "}", ")", "{", "s", ".", "addRoute", "(", "route", ",", "\"", "\"", ",", "handler", ")", "\n", "}" ]
// Post adds a handler for the 'POST' http method for server s.
[ "Post", "adds", "a", "handler", "for", "the", "POST", "http", "method", "for", "server", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L115-L117
148,876
hoisie/web
server.go
Put
func (s *Server) Put(route string, handler interface{}) { s.addRoute(route, "PUT", handler) }
go
func (s *Server) Put(route string, handler interface{}) { s.addRoute(route, "PUT", handler) }
[ "func", "(", "s", "*", "Server", ")", "Put", "(", "route", "string", ",", "handler", "interface", "{", "}", ")", "{", "s", ".", "addRoute", "(", "route", ",", "\"", "\"", ",", "handler", ")", "\n", "}" ]
// Put adds a handler for the 'PUT' http method for server s.
[ "Put", "adds", "a", "handler", "for", "the", "PUT", "http", "method", "for", "server", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L120-L122
148,877
hoisie/web
server.go
Delete
func (s *Server) Delete(route string, handler interface{}) { s.addRoute(route, "DELETE", handler) }
go
func (s *Server) Delete(route string, handler interface{}) { s.addRoute(route, "DELETE", handler) }
[ "func", "(", "s", "*", "Server", ")", "Delete", "(", "route", "string", ",", "handler", "interface", "{", "}", ")", "{", "s", ".", "addRoute", "(", "route", ",", "\"", "\"", ",", "handler", ")", "\n", "}" ]
// Delete adds a handler for the 'DELETE' http method for server s.
[ "Delete", "adds", "a", "handler", "for", "the", "DELETE", "http", "method", "for", "server", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L125-L127
148,878
hoisie/web
server.go
Match
func (s *Server) Match(method string, route string, handler interface{}) { s.addRoute(route, method, handler) }
go
func (s *Server) Match(method string, route string, handler interface{}) { s.addRoute(route, method, handler) }
[ "func", "(", "s", "*", "Server", ")", "Match", "(", "method", "string", ",", "route", "string", ",", "handler", "interface", "{", "}", ")", "{", "s", ".", "addRoute", "(", "route", ",", "method", ",", "handler", ")", "\n", "}" ]
// Match adds a handler for an arbitrary http method for server s.
[ "Match", "adds", "a", "handler", "for", "an", "arbitrary", "http", "method", "for", "server", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L130-L132
148,879
hoisie/web
server.go
Run
func (s *Server) Run(addr string) { s.initServer() mux := http.NewServeMux() if s.Config.Profiler { mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) mux.Handle("/debug/pprof/heap", pprof.Handler("heap")) mux.Handle("/debu...
go
func (s *Server) Run(addr string) { s.initServer() mux := http.NewServeMux() if s.Config.Profiler { mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) mux.Handle("/debug/pprof/heap", pprof.Handler("heap")) mux.Handle("/debu...
[ "func", "(", "s", "*", "Server", ")", "Run", "(", "addr", "string", ")", "{", "s", ".", "initServer", "(", ")", "\n\n", "mux", ":=", "http", ".", "NewServeMux", "(", ")", "\n", "if", "s", ".", "Config", ".", "Profiler", "{", "mux", ".", "Handle",...
// Run starts the web application and serves HTTP requests for s
[ "Run", "starts", "the", "web", "application", "and", "serves", "HTTP", "requests", "for", "s" ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L145-L167
148,880
hoisie/web
server.go
RunFcgi
func (s *Server) RunFcgi(addr string) { s.initServer() s.Logger.Printf("web.go serving fcgi %s\n", addr) s.listenAndServeFcgi(addr) }
go
func (s *Server) RunFcgi(addr string) { s.initServer() s.Logger.Printf("web.go serving fcgi %s\n", addr) s.listenAndServeFcgi(addr) }
[ "func", "(", "s", "*", "Server", ")", "RunFcgi", "(", "addr", "string", ")", "{", "s", ".", "initServer", "(", ")", "\n", "s", ".", "Logger", ".", "Printf", "(", "\"", "\\n", "\"", ",", "addr", ")", "\n", "s", ".", "listenAndServeFcgi", "(", "add...
// RunFcgi starts the web application and serves FastCGI requests for s.
[ "RunFcgi", "starts", "the", "web", "application", "and", "serves", "FastCGI", "requests", "for", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L170-L174
148,881
hoisie/web
server.go
RunScgi
func (s *Server) RunScgi(addr string) { s.initServer() s.Logger.Printf("web.go serving scgi %s\n", addr) s.listenAndServeScgi(addr) }
go
func (s *Server) RunScgi(addr string) { s.initServer() s.Logger.Printf("web.go serving scgi %s\n", addr) s.listenAndServeScgi(addr) }
[ "func", "(", "s", "*", "Server", ")", "RunScgi", "(", "addr", "string", ")", "{", "s", ".", "initServer", "(", ")", "\n", "s", ".", "Logger", ".", "Printf", "(", "\"", "\\n", "\"", ",", "addr", ")", "\n", "s", ".", "listenAndServeScgi", "(", "add...
// RunScgi starts the web application and serves SCGI requests for s.
[ "RunScgi", "starts", "the", "web", "application", "and", "serves", "SCGI", "requests", "for", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L177-L181
148,882
hoisie/web
server.go
RunTLS
func (s *Server) RunTLS(addr string, config *tls.Config) error { s.initServer() mux := http.NewServeMux() mux.Handle("/", s) l, err := tls.Listen("tcp", addr, config) if err != nil { log.Fatal("Listen:", err) return err } s.Logger.Printf("web.go serving %s\n", l.Addr()) s.l = l return http.Serve(s.l, mux...
go
func (s *Server) RunTLS(addr string, config *tls.Config) error { s.initServer() mux := http.NewServeMux() mux.Handle("/", s) l, err := tls.Listen("tcp", addr, config) if err != nil { log.Fatal("Listen:", err) return err } s.Logger.Printf("web.go serving %s\n", l.Addr()) s.l = l return http.Serve(s.l, mux...
[ "func", "(", "s", "*", "Server", ")", "RunTLS", "(", "addr", "string", ",", "config", "*", "tls", ".", "Config", ")", "error", "{", "s", ".", "initServer", "(", ")", "\n", "mux", ":=", "http", ".", "NewServeMux", "(", ")", "\n", "mux", ".", "Hand...
// RunTLS starts the web application and serves HTTPS requests for s.
[ "RunTLS", "starts", "the", "web", "application", "and", "serves", "HTTPS", "requests", "for", "s", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L184-L198
148,883
hoisie/web
server.go
requiresContext
func requiresContext(handlerType reflect.Type) bool { //if the method doesn't take arguments, no if handlerType.NumIn() == 0 { return false } //if the first argument is not a pointer, no a0 := handlerType.In(0) if a0.Kind() != reflect.Ptr { return false } //if the first argument is a context, yes if a0.El...
go
func requiresContext(handlerType reflect.Type) bool { //if the method doesn't take arguments, no if handlerType.NumIn() == 0 { return false } //if the first argument is not a pointer, no a0 := handlerType.In(0) if a0.Kind() != reflect.Ptr { return false } //if the first argument is a context, yes if a0.El...
[ "func", "requiresContext", "(", "handlerType", "reflect", ".", "Type", ")", "bool", "{", "//if the method doesn't take arguments, no", "if", "handlerType", ".", "NumIn", "(", ")", "==", "0", "{", "return", "false", "\n", "}", "\n\n", "//if the first argument is not ...
// requiresContext determines whether 'handlerType' contains // an argument to 'web.Ctx' as its first argument
[ "requiresContext", "determines", "whether", "handlerType", "contains", "an", "argument", "to", "web", ".", "Ctx", "as", "its", "first", "argument" ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/server.go#L233-L250
148,884
hoisie/web
helpers.go
webTime
func webTime(t time.Time) string { ftime := t.Format(time.RFC1123) if strings.HasSuffix(ftime, "UTC") { ftime = ftime[0:len(ftime)-3] + "GMT" } return ftime }
go
func webTime(t time.Time) string { ftime := t.Format(time.RFC1123) if strings.HasSuffix(ftime, "UTC") { ftime = ftime[0:len(ftime)-3] + "GMT" } return ftime }
[ "func", "webTime", "(", "t", "time", ".", "Time", ")", "string", "{", "ftime", ":=", "t", ".", "Format", "(", "time", ".", "RFC1123", ")", "\n", "if", "strings", ".", "HasSuffix", "(", "ftime", ",", "\"", "\"", ")", "{", "ftime", "=", "ftime", "[...
// internal utility methods
[ "internal", "utility", "methods" ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/helpers.go#L16-L22
148,885
hoisie/web
helpers.go
Urlencode
func Urlencode(data map[string]string) string { var buf bytes.Buffer for k, v := range data { buf.WriteString(url.QueryEscape(k)) buf.WriteByte('=') buf.WriteString(url.QueryEscape(v)) buf.WriteByte('&') } s := buf.String() return s[0 : len(s)-1] }
go
func Urlencode(data map[string]string) string { var buf bytes.Buffer for k, v := range data { buf.WriteString(url.QueryEscape(k)) buf.WriteByte('=') buf.WriteString(url.QueryEscape(v)) buf.WriteByte('&') } s := buf.String() return s[0 : len(s)-1] }
[ "func", "Urlencode", "(", "data", "map", "[", "string", "]", "string", ")", "string", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "for", "k", ",", "v", ":=", "range", "data", "{", "buf", ".", "WriteString", "(", "url", ".", "QueryEscape", "(", ...
// Urlencode is a helper method that converts a map into URL-encoded form data. // It is a useful when constructing HTTP POST requests.
[ "Urlencode", "is", "a", "helper", "method", "that", "converts", "a", "map", "into", "URL", "-", "encoded", "form", "data", ".", "It", "is", "a", "useful", "when", "constructing", "HTTP", "POST", "requests", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/helpers.go#L47-L57
148,886
hoisie/web
helpers.go
Slug
func Slug(s string, sep string) string { if s == "" { return "" } slug := slugRegex.ReplaceAllString(s, sep) if slug == "" { return "" } quoted := regexp.QuoteMeta(sep) sepRegex := regexp.MustCompile("(" + quoted + "){2,}") slug = sepRegex.ReplaceAllString(slug, sep) sepEnds := regexp.MustCompile("^" + quo...
go
func Slug(s string, sep string) string { if s == "" { return "" } slug := slugRegex.ReplaceAllString(s, sep) if slug == "" { return "" } quoted := regexp.QuoteMeta(sep) sepRegex := regexp.MustCompile("(" + quoted + "){2,}") slug = sepRegex.ReplaceAllString(slug, sep) sepEnds := regexp.MustCompile("^" + quo...
[ "func", "Slug", "(", "s", "string", ",", "sep", "string", ")", "string", "{", "if", "s", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "slug", ":=", "slugRegex", ".", "ReplaceAllString", "(", "s", ",", "sep", ")", "\n", "if", "slu...
// Slug is a helper function that returns the URL slug for string s. // It's used to return clean, URL-friendly strings that can be // used in routing.
[ "Slug", "is", "a", "helper", "function", "that", "returns", "the", "URL", "slug", "for", "string", "s", ".", "It", "s", "used", "to", "return", "clean", "URL", "-", "friendly", "strings", "that", "can", "be", "used", "in", "routing", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/helpers.go#L64-L78
148,887
hoisie/web
helpers.go
GetBasicAuth
func (ctx *Context) GetBasicAuth() (string, string, error) { if len(ctx.Request.Header["Authorization"]) == 0 { return "", "", errors.New("No Authorization header provided") } authHeader := ctx.Request.Header["Authorization"][0] authString := strings.Split(string(authHeader), " ") if authString[0] != "Basic" { ...
go
func (ctx *Context) GetBasicAuth() (string, string, error) { if len(ctx.Request.Header["Authorization"]) == 0 { return "", "", errors.New("No Authorization header provided") } authHeader := ctx.Request.Header["Authorization"][0] authString := strings.Split(string(authHeader), " ") if authString[0] != "Basic" { ...
[ "func", "(", "ctx", "*", "Context", ")", "GetBasicAuth", "(", ")", "(", "string", ",", "string", ",", "error", ")", "{", "if", "len", "(", "ctx", ".", "Request", ".", "Header", "[", "\"", "\"", "]", ")", "==", "0", "{", "return", "\"", "\"", ",...
// GetBasicAuth returns the decoded user and password from the context's // 'Authorization' header.
[ "GetBasicAuth", "returns", "the", "decoded", "user", "and", "password", "from", "the", "context", "s", "Authorization", "header", "." ]
a498c022b2c0babab2bf9c0400754190b24c8c39
https://github.com/hoisie/web/blob/a498c022b2c0babab2bf9c0400754190b24c8c39/helpers.go#L96-L114
148,888
magefile/mage
sh/helpers.go
Rm
func Rm(path string) error { err := os.RemoveAll(path) if err == nil || os.IsNotExist(err) { return nil } return fmt.Errorf(`failed to remove %s: %v`, path, err) }
go
func Rm(path string) error { err := os.RemoveAll(path) if err == nil || os.IsNotExist(err) { return nil } return fmt.Errorf(`failed to remove %s: %v`, path, err) }
[ "func", "Rm", "(", "path", "string", ")", "error", "{", "err", ":=", "os", ".", "RemoveAll", "(", "path", ")", "\n", "if", "err", "==", "nil", "||", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", "\n", "}", "\n", "return", "fmt",...
// Rm removes the given file or directory even if non-empty. It will not return // an error if the target doesn't exist, only if the target cannot be removed.
[ "Rm", "removes", "the", "given", "file", "or", "directory", "even", "if", "non", "-", "empty", ".", "It", "will", "not", "return", "an", "error", "if", "the", "target", "doesn", "t", "exist", "only", "if", "the", "target", "cannot", "be", "removed", "....
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/helpers.go#L11-L17
148,889
magefile/mage
sh/helpers.go
Copy
func Copy(dst string, src string) error { from, err := os.Open(src) if err != nil { return fmt.Errorf(`can't copy %s: %v`, src, err) } defer from.Close() finfo, err := from.Stat() if err != nil { return fmt.Errorf(`can't stat %s: %v`, src, err) } to, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUN...
go
func Copy(dst string, src string) error { from, err := os.Open(src) if err != nil { return fmt.Errorf(`can't copy %s: %v`, src, err) } defer from.Close() finfo, err := from.Stat() if err != nil { return fmt.Errorf(`can't stat %s: %v`, src, err) } to, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUN...
[ "func", "Copy", "(", "dst", "string", ",", "src", "string", ")", "error", "{", "from", ",", "err", ":=", "os", ".", "Open", "(", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "`can't copy %s: %v`", ",", "src"...
// Copy robustly copies the source file to the destination, overwriting the destination if necessary.
[ "Copy", "robustly", "copies", "the", "source", "file", "to", "the", "destination", "overwriting", "the", "destination", "if", "necessary", "." ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/sh/helpers.go#L20-L40
148,890
magefile/mage
internal/run.go
EnvWithCurrentGOOS
func EnvWithCurrentGOOS() ([]string, error) { vals, err := splitEnv(os.Environ()) if err != nil { return nil, err } vals["GOOS"] = runtime.GOOS vals["GOARCH"] = runtime.GOARCH return joinEnv(vals), nil }
go
func EnvWithCurrentGOOS() ([]string, error) { vals, err := splitEnv(os.Environ()) if err != nil { return nil, err } vals["GOOS"] = runtime.GOOS vals["GOARCH"] = runtime.GOARCH return joinEnv(vals), nil }
[ "func", "EnvWithCurrentGOOS", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "vals", ",", "err", ":=", "splitEnv", "(", "os", ".", "Environ", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", ...
// EnvWithCurrentGOOS returns a copy of os.Environ with the GOOS and GOARCH set // to runtime.GOOS and runtime.GOARCH.
[ "EnvWithCurrentGOOS", "returns", "a", "copy", "of", "os", ".", "Environ", "with", "the", "GOOS", "and", "GOARCH", "set", "to", "runtime", ".", "GOOS", "and", "runtime", ".", "GOARCH", "." ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/internal/run.go#L86-L94
148,891
magefile/mage
mg/runtime.go
Verbose
func Verbose() bool { b, _ := strconv.ParseBool(os.Getenv(VerboseEnv)) return b }
go
func Verbose() bool { b, _ := strconv.ParseBool(os.Getenv(VerboseEnv)) return b }
[ "func", "Verbose", "(", ")", "bool", "{", "b", ",", "_", ":=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "VerboseEnv", ")", ")", "\n", "return", "b", "\n", "}" ]
// Verbose reports whether a magefile was run with the verbose flag.
[ "Verbose", "reports", "whether", "a", "magefile", "was", "run", "with", "the", "verbose", "flag", "." ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/runtime.go#L31-L34
148,892
magefile/mage
mg/runtime.go
Debug
func Debug() bool { b, _ := strconv.ParseBool(os.Getenv(DebugEnv)) return b }
go
func Debug() bool { b, _ := strconv.ParseBool(os.Getenv(DebugEnv)) return b }
[ "func", "Debug", "(", ")", "bool", "{", "b", ",", "_", ":=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "DebugEnv", ")", ")", "\n", "return", "b", "\n", "}" ]
// Debug reports whether a magefile was run with the verbose flag.
[ "Debug", "reports", "whether", "a", "magefile", "was", "run", "with", "the", "verbose", "flag", "." ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/runtime.go#L37-L40
148,893
magefile/mage
mg/runtime.go
IgnoreDefault
func IgnoreDefault() bool { b, _ := strconv.ParseBool(os.Getenv(IgnoreDefaultEnv)) return b }
go
func IgnoreDefault() bool { b, _ := strconv.ParseBool(os.Getenv(IgnoreDefaultEnv)) return b }
[ "func", "IgnoreDefault", "(", ")", "bool", "{", "b", ",", "_", ":=", "strconv", ".", "ParseBool", "(", "os", ".", "Getenv", "(", "IgnoreDefaultEnv", ")", ")", "\n", "return", "b", "\n", "}" ]
// IgnoreDefault reports whether the user has requested to ignore the default target // in the magefile.
[ "IgnoreDefault", "reports", "whether", "the", "user", "has", "requested", "to", "ignore", "the", "default", "target", "in", "the", "magefile", "." ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/runtime.go#L53-L56
148,894
magefile/mage
mg/deps.go
SerialDeps
func SerialDeps(fns ...interface{}) { types := checkFns(fns) ctx := context.Background() for i := range fns { runDeps(ctx, types[i:i+1], fns[i:i+1]) } }
go
func SerialDeps(fns ...interface{}) { types := checkFns(fns) ctx := context.Background() for i := range fns { runDeps(ctx, types[i:i+1], fns[i:i+1]) } }
[ "func", "SerialDeps", "(", "fns", "...", "interface", "{", "}", ")", "{", "types", ":=", "checkFns", "(", "fns", ")", "\n", "ctx", ":=", "context", ".", "Background", "(", ")", "\n", "for", "i", ":=", "range", "fns", "{", "runDeps", "(", "ctx", ","...
// SerialDeps is like Deps except it runs each dependency serially, instead of // in parallel. This can be useful for resource intensive dependencies that // shouldn't be run at the same time.
[ "SerialDeps", "is", "like", "Deps", "except", "it", "runs", "each", "dependency", "serially", "instead", "of", "in", "parallel", ".", "This", "can", "be", "useful", "for", "resource", "intensive", "dependencies", "that", "shouldn", "t", "be", "run", "at", "t...
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/deps.go#L57-L63
148,895
magefile/mage
mg/deps.go
SerialCtxDeps
func SerialCtxDeps(ctx context.Context, fns ...interface{}) { types := checkFns(fns) for i := range fns { runDeps(ctx, types[i:i+1], fns[i:i+1]) } }
go
func SerialCtxDeps(ctx context.Context, fns ...interface{}) { types := checkFns(fns) for i := range fns { runDeps(ctx, types[i:i+1], fns[i:i+1]) } }
[ "func", "SerialCtxDeps", "(", "ctx", "context", ".", "Context", ",", "fns", "...", "interface", "{", "}", ")", "{", "types", ":=", "checkFns", "(", "fns", ")", "\n", "for", "i", ":=", "range", "fns", "{", "runDeps", "(", "ctx", ",", "types", "[", "...
// SerialCtxDeps is like CtxDeps except it runs each dependency serially, // instead of in parallel. This can be useful for resource intensive // dependencies that shouldn't be run at the same time.
[ "SerialCtxDeps", "is", "like", "CtxDeps", "except", "it", "runs", "each", "dependency", "serially", "instead", "of", "in", "parallel", ".", "This", "can", "be", "useful", "for", "resource", "intensive", "dependencies", "that", "shouldn", "t", "be", "run", "at"...
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/deps.go#L68-L73
148,896
magefile/mage
mg/deps.go
runDeps
func runDeps(ctx context.Context, types []funcType, fns []interface{}) { mu := &sync.Mutex{} var errs []string var exit int wg := &sync.WaitGroup{} for i, f := range fns { fn := addDep(ctx, types[i], f) wg.Add(1) go func() { defer func() { if v := recover(); v != nil { mu.Lock() if err, ok :...
go
func runDeps(ctx context.Context, types []funcType, fns []interface{}) { mu := &sync.Mutex{} var errs []string var exit int wg := &sync.WaitGroup{} for i, f := range fns { fn := addDep(ctx, types[i], f) wg.Add(1) go func() { defer func() { if v := recover(); v != nil { mu.Lock() if err, ok :...
[ "func", "runDeps", "(", "ctx", "context", ".", "Context", ",", "types", "[", "]", "funcType", ",", "fns", "[", "]", "interface", "{", "}", ")", "{", "mu", ":=", "&", "sync", ".", "Mutex", "{", "}", "\n", "var", "errs", "[", "]", "string", "\n", ...
// runDeps assumes you've already called checkFns.
[ "runDeps", "assumes", "you", "ve", "already", "called", "checkFns", "." ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/deps.go#L94-L129
148,897
magefile/mage
mg/deps.go
funcCheck
func funcCheck(fn interface{}) (funcType, error) { switch fn.(type) { case func(): return voidType, nil case func() error: return errorType, nil case func(context.Context): return contextVoidType, nil case func(context.Context) error: return contextErrorType, nil } err := fmt.Errorf("Invalid type for de...
go
func funcCheck(fn interface{}) (funcType, error) { switch fn.(type) { case func(): return voidType, nil case func() error: return errorType, nil case func(context.Context): return contextVoidType, nil case func(context.Context) error: return contextErrorType, nil } err := fmt.Errorf("Invalid type for de...
[ "func", "funcCheck", "(", "fn", "interface", "{", "}", ")", "(", "funcType", ",", "error", ")", "{", "switch", "fn", ".", "(", "type", ")", "{", "case", "func", "(", ")", ":", "return", "voidType", ",", "nil", "\n", "case", "func", "(", ")", "err...
// funcCheck tests if a function is one of funcType
[ "funcCheck", "tests", "if", "a", "function", "is", "one", "of", "funcType" ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/deps.go#L218-L278
148,898
magefile/mage
mg/deps.go
funcTypeWrap
func funcTypeWrap(t funcType, fn interface{}) func(context.Context) error { switch f := fn.(type) { case func(): return func(context.Context) error { f() return nil } case func() error: return func(context.Context) error { return f() } case func(context.Context): return func(ctx context.Context) ...
go
func funcTypeWrap(t funcType, fn interface{}) func(context.Context) error { switch f := fn.(type) { case func(): return func(context.Context) error { f() return nil } case func() error: return func(context.Context) error { return f() } case func(context.Context): return func(ctx context.Context) ...
[ "func", "funcTypeWrap", "(", "t", "funcType", ",", "fn", "interface", "{", "}", ")", "func", "(", "context", ".", "Context", ")", "error", "{", "switch", "f", ":=", "fn", ".", "(", "type", ")", "{", "case", "func", "(", ")", ":", "return", "func", ...
// funcTypeWrap wraps a valid FuncType to FuncContextError
[ "funcTypeWrap", "wraps", "a", "valid", "FuncType", "to", "FuncContextError" ]
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mg/deps.go#L281-L337
148,899
magefile/mage
mage/main.go
Main
func Main() int { return ParseAndRun(os.Stdout, os.Stderr, os.Stdin, os.Args[1:]) }
go
func Main() int { return ParseAndRun(os.Stdout, os.Stderr, os.Stdin, os.Args[1:]) }
[ "func", "Main", "(", ")", "int", "{", "return", "ParseAndRun", "(", "os", ".", "Stdout", ",", "os", ".", "Stderr", ",", "os", ".", "Stdin", ",", "os", ".", "Args", "[", "1", ":", "]", ")", "\n", "}" ]
// Main is the entrypoint for running mage. It exists external to mage's main // function to allow it to be used from other programs, specifically so you can // go run a simple file that run's mage's Main.
[ "Main", "is", "the", "entrypoint", "for", "running", "mage", ".", "It", "exists", "external", "to", "mage", "s", "main", "function", "to", "allow", "it", "to", "be", "used", "from", "other", "programs", "specifically", "so", "you", "can", "go", "run", "a...
5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed
https://github.com/magefile/mage/blob/5bc3a8ab86d5a23d6eb3bdbcd60e79ac4d9ad0ed/mage/main.go#L90-L92