repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
t3rm1n4l/nitro
skiplist/access_barrier.go
FlushSession
func (ab *AccessBarrier) FlushSession(ref unsafe.Pointer) { if ab.active { ab.Lock() defer ab.Unlock() bsPtr := atomic.LoadPointer(&ab.session) newBsPtr := unsafe.Pointer(newBarrierSession()) atomic.CompareAndSwapPointer(&ab.session, bsPtr, newBsPtr) bs := (*BarrierSession)(bsPtr) bs.objectRef = ref ab.activeSeqno++ bs.seqno = ab.activeSeqno atomic.AddInt32(bs.liveCount, barrierFlushOffset+1) ab.Release(bs) } }
go
func (ab *AccessBarrier) FlushSession(ref unsafe.Pointer) { if ab.active { ab.Lock() defer ab.Unlock() bsPtr := atomic.LoadPointer(&ab.session) newBsPtr := unsafe.Pointer(newBarrierSession()) atomic.CompareAndSwapPointer(&ab.session, bsPtr, newBsPtr) bs := (*BarrierSession)(bsPtr) bs.objectRef = ref ab.activeSeqno++ bs.seqno = ab.activeSeqno atomic.AddInt32(bs.liveCount, barrierFlushOffset+1) ab.Release(bs) } }
[ "func", "(", "ab", "*", "AccessBarrier", ")", "FlushSession", "(", "ref", "unsafe", ".", "Pointer", ")", "{", "if", "ab", ".", "active", "{", "ab", ".", "Lock", "(", ")", "\n", "defer", "ab", ".", "Unlock", "(", ")", "\n", "bsPtr", ":=", "atomic", ".", "LoadPointer", "(", "&", "ab", ".", "session", ")", "\n", "newBsPtr", ":=", "unsafe", ".", "Pointer", "(", "newBarrierSession", "(", ")", ")", "\n", "atomic", ".", "CompareAndSwapPointer", "(", "&", "ab", ".", "session", ",", "bsPtr", ",", "newBsPtr", ")", "\n", "bs", ":=", "(", "*", "BarrierSession", ")", "(", "bsPtr", ")", "\n", "bs", ".", "objectRef", "=", "ref", "\n", "ab", ".", "activeSeqno", "++", "\n", "bs", ".", "seqno", "=", "ab", ".", "activeSeqno", "\n", "atomic", ".", "AddInt32", "(", "bs", ".", "liveCount", ",", "barrierFlushOffset", "+", "1", ")", "\n", "ab", ".", "Release", "(", "bs", ")", "\n", "}", "\n", "}" ]
// FlushSession closes the current barrier session and starts the new session. // The caller should provide the destructor pointer for the new session.
[ "FlushSession", "closes", "the", "current", "barrier", "session", "and", "starts", "the", "new", "session", ".", "The", "caller", "should", "provide", "the", "destructor", "pointer", "for", "the", "new", "session", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/access_barrier.go#L180-L196
test
t3rm1n4l/nitro
skiplist/stats.go
Apply
func (report *StatsReport) Apply(s *Stats) { var totalNextPtrs int var totalNodes int report.ReadConflicts += s.readConflicts report.InsertConflicts += s.insertConflicts for i, c := range s.levelNodesCount { report.NodeDistribution[i] += c nodesAtlevel := report.NodeDistribution[i] totalNodes += int(nodesAtlevel) totalNextPtrs += (i + 1) * int(nodesAtlevel) } report.SoftDeletes += s.softDeletes report.NodeCount = totalNodes report.NextPointersPerNode = float64(totalNextPtrs) / float64(totalNodes) report.NodeAllocs += s.nodeAllocs report.NodeFrees += s.nodeFrees report.Memory += s.usedBytes }
go
func (report *StatsReport) Apply(s *Stats) { var totalNextPtrs int var totalNodes int report.ReadConflicts += s.readConflicts report.InsertConflicts += s.insertConflicts for i, c := range s.levelNodesCount { report.NodeDistribution[i] += c nodesAtlevel := report.NodeDistribution[i] totalNodes += int(nodesAtlevel) totalNextPtrs += (i + 1) * int(nodesAtlevel) } report.SoftDeletes += s.softDeletes report.NodeCount = totalNodes report.NextPointersPerNode = float64(totalNextPtrs) / float64(totalNodes) report.NodeAllocs += s.nodeAllocs report.NodeFrees += s.nodeFrees report.Memory += s.usedBytes }
[ "func", "(", "report", "*", "StatsReport", ")", "Apply", "(", "s", "*", "Stats", ")", "{", "var", "totalNextPtrs", "int", "\n", "var", "totalNodes", "int", "\n", "report", ".", "ReadConflicts", "+=", "s", ".", "readConflicts", "\n", "report", ".", "InsertConflicts", "+=", "s", ".", "insertConflicts", "\n", "for", "i", ",", "c", ":=", "range", "s", ".", "levelNodesCount", "{", "report", ".", "NodeDistribution", "[", "i", "]", "+=", "c", "\n", "nodesAtlevel", ":=", "report", ".", "NodeDistribution", "[", "i", "]", "\n", "totalNodes", "+=", "int", "(", "nodesAtlevel", ")", "\n", "totalNextPtrs", "+=", "(", "i", "+", "1", ")", "*", "int", "(", "nodesAtlevel", ")", "\n", "}", "\n", "report", ".", "SoftDeletes", "+=", "s", ".", "softDeletes", "\n", "report", ".", "NodeCount", "=", "totalNodes", "\n", "report", ".", "NextPointersPerNode", "=", "float64", "(", "totalNextPtrs", ")", "/", "float64", "(", "totalNodes", ")", "\n", "report", ".", "NodeAllocs", "+=", "s", ".", "nodeAllocs", "\n", "report", ".", "NodeFrees", "+=", "s", ".", "nodeFrees", "\n", "report", ".", "Memory", "+=", "s", ".", "usedBytes", "\n", "}" ]
// Apply updates the report with provided paritial stats
[ "Apply", "updates", "the", "report", "with", "provided", "paritial", "stats" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/stats.go#L30-L50
test
t3rm1n4l/nitro
skiplist/stats.go
AddInt64
func (s *Stats) AddInt64(src *int64, val int64) { if s.isLocal { *src += val } else { atomic.AddInt64(src, val) } }
go
func (s *Stats) AddInt64(src *int64, val int64) { if s.isLocal { *src += val } else { atomic.AddInt64(src, val) } }
[ "func", "(", "s", "*", "Stats", ")", "AddInt64", "(", "src", "*", "int64", ",", "val", "int64", ")", "{", "if", "s", ".", "isLocal", "{", "*", "src", "+=", "val", "\n", "}", "else", "{", "atomic", ".", "AddInt64", "(", "src", ",", "val", ")", "\n", "}", "\n", "}" ]
// AddInt64 provides atomic add
[ "AddInt64", "provides", "atomic", "add" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/stats.go#L70-L76
test
t3rm1n4l/nitro
skiplist/stats.go
AddUint64
func (s *Stats) AddUint64(src *uint64, val uint64) { if s.isLocal { *src += val } else { atomic.AddUint64(src, val) } }
go
func (s *Stats) AddUint64(src *uint64, val uint64) { if s.isLocal { *src += val } else { atomic.AddUint64(src, val) } }
[ "func", "(", "s", "*", "Stats", ")", "AddUint64", "(", "src", "*", "uint64", ",", "val", "uint64", ")", "{", "if", "s", ".", "isLocal", "{", "*", "src", "+=", "val", "\n", "}", "else", "{", "atomic", ".", "AddUint64", "(", "src", ",", "val", ")", "\n", "}", "\n", "}" ]
// AddUint64 provides atomic add
[ "AddUint64", "provides", "atomic", "add" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/stats.go#L79-L85
test
t3rm1n4l/nitro
skiplist/stats.go
Merge
func (s *Stats) Merge(sts *Stats) { atomic.AddUint64(&s.insertConflicts, sts.insertConflicts) sts.insertConflicts = 0 atomic.AddUint64(&s.readConflicts, sts.readConflicts) sts.readConflicts = 0 atomic.AddInt64(&s.softDeletes, sts.softDeletes) sts.softDeletes = 0 atomic.AddInt64(&s.nodeAllocs, sts.nodeAllocs) sts.nodeAllocs = 0 atomic.AddInt64(&s.nodeFrees, sts.nodeFrees) sts.nodeFrees = 0 atomic.AddInt64(&s.usedBytes, sts.usedBytes) sts.usedBytes = 0 for i, val := range sts.levelNodesCount { if val != 0 { atomic.AddInt64(&s.levelNodesCount[i], val) sts.levelNodesCount[i] = 0 } } }
go
func (s *Stats) Merge(sts *Stats) { atomic.AddUint64(&s.insertConflicts, sts.insertConflicts) sts.insertConflicts = 0 atomic.AddUint64(&s.readConflicts, sts.readConflicts) sts.readConflicts = 0 atomic.AddInt64(&s.softDeletes, sts.softDeletes) sts.softDeletes = 0 atomic.AddInt64(&s.nodeAllocs, sts.nodeAllocs) sts.nodeAllocs = 0 atomic.AddInt64(&s.nodeFrees, sts.nodeFrees) sts.nodeFrees = 0 atomic.AddInt64(&s.usedBytes, sts.usedBytes) sts.usedBytes = 0 for i, val := range sts.levelNodesCount { if val != 0 { atomic.AddInt64(&s.levelNodesCount[i], val) sts.levelNodesCount[i] = 0 } } }
[ "func", "(", "s", "*", "Stats", ")", "Merge", "(", "sts", "*", "Stats", ")", "{", "atomic", ".", "AddUint64", "(", "&", "s", ".", "insertConflicts", ",", "sts", ".", "insertConflicts", ")", "\n", "sts", ".", "insertConflicts", "=", "0", "\n", "atomic", ".", "AddUint64", "(", "&", "s", ".", "readConflicts", ",", "sts", ".", "readConflicts", ")", "\n", "sts", ".", "readConflicts", "=", "0", "\n", "atomic", ".", "AddInt64", "(", "&", "s", ".", "softDeletes", ",", "sts", ".", "softDeletes", ")", "\n", "sts", ".", "softDeletes", "=", "0", "\n", "atomic", ".", "AddInt64", "(", "&", "s", ".", "nodeAllocs", ",", "sts", ".", "nodeAllocs", ")", "\n", "sts", ".", "nodeAllocs", "=", "0", "\n", "atomic", ".", "AddInt64", "(", "&", "s", ".", "nodeFrees", ",", "sts", ".", "nodeFrees", ")", "\n", "sts", ".", "nodeFrees", "=", "0", "\n", "atomic", ".", "AddInt64", "(", "&", "s", ".", "usedBytes", ",", "sts", ".", "usedBytes", ")", "\n", "sts", ".", "usedBytes", "=", "0", "\n", "for", "i", ",", "val", ":=", "range", "sts", ".", "levelNodesCount", "{", "if", "val", "!=", "0", "{", "atomic", ".", "AddInt64", "(", "&", "s", ".", "levelNodesCount", "[", "i", "]", ",", "val", ")", "\n", "sts", ".", "levelNodesCount", "[", "i", "]", "=", "0", "\n", "}", "\n", "}", "\n", "}" ]
// Merge updates global stats with partial stats and resets partial stats
[ "Merge", "updates", "global", "stats", "with", "partial", "stats", "and", "resets", "partial", "stats" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/stats.go#L88-L108
test
t3rm1n4l/nitro
skiplist/stats.go
GetStats
func (s *Skiplist) GetStats() StatsReport { var report StatsReport report.Apply(&s.Stats) return report }
go
func (s *Skiplist) GetStats() StatsReport { var report StatsReport report.Apply(&s.Stats) return report }
[ "func", "(", "s", "*", "Skiplist", ")", "GetStats", "(", ")", "StatsReport", "{", "var", "report", "StatsReport", "\n", "report", ".", "Apply", "(", "&", "s", ".", "Stats", ")", "\n", "return", "report", "\n", "}" ]
// GetStats returns skiplist stats
[ "GetStats", "returns", "skiplist", "stats" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/stats.go#L134-L138
test
t3rm1n4l/nitro
skiplist/iterator.go
NewIterator
func (s *Skiplist) NewIterator(cmp CompareFn, buf *ActionBuffer) *Iterator { return &Iterator{ cmp: cmp, s: s, buf: buf, bs: s.barrier.Acquire(), } }
go
func (s *Skiplist) NewIterator(cmp CompareFn, buf *ActionBuffer) *Iterator { return &Iterator{ cmp: cmp, s: s, buf: buf, bs: s.barrier.Acquire(), } }
[ "func", "(", "s", "*", "Skiplist", ")", "NewIterator", "(", "cmp", "CompareFn", ",", "buf", "*", "ActionBuffer", ")", "*", "Iterator", "{", "return", "&", "Iterator", "{", "cmp", ":", "cmp", ",", "s", ":", "s", ",", "buf", ":", "buf", ",", "bs", ":", "s", ".", "barrier", ".", "Acquire", "(", ")", ",", "}", "\n", "}" ]
// NewIterator creates an iterator for skiplist
[ "NewIterator", "creates", "an", "iterator", "for", "skiplist" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/iterator.go#L28-L37
test
t3rm1n4l/nitro
skiplist/iterator.go
SeekFirst
func (it *Iterator) SeekFirst() { it.prev = it.s.head it.curr, _ = it.s.head.getNext(0) it.valid = true }
go
func (it *Iterator) SeekFirst() { it.prev = it.s.head it.curr, _ = it.s.head.getNext(0) it.valid = true }
[ "func", "(", "it", "*", "Iterator", ")", "SeekFirst", "(", ")", "{", "it", ".", "prev", "=", "it", ".", "s", ".", "head", "\n", "it", ".", "curr", ",", "_", "=", "it", ".", "s", ".", "head", ".", "getNext", "(", "0", ")", "\n", "it", ".", "valid", "=", "true", "\n", "}" ]
// SeekFirst moves cursor to the start
[ "SeekFirst", "moves", "cursor", "to", "the", "start" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/iterator.go#L40-L44
test
t3rm1n4l/nitro
skiplist/iterator.go
SeekWithCmp
func (it *Iterator) SeekWithCmp(itm unsafe.Pointer, cmp CompareFn, eqCmp CompareFn) bool { var found bool if found = it.s.findPath(itm, cmp, it.buf, &it.s.Stats) != nil; found { it.prev = it.buf.preds[0] it.curr = it.buf.succs[0] } else { if found = eqCmp != nil && compare(eqCmp, itm, it.buf.preds[0].Item()) == 0; found { it.prev = nil it.curr = it.buf.preds[0] } } return found }
go
func (it *Iterator) SeekWithCmp(itm unsafe.Pointer, cmp CompareFn, eqCmp CompareFn) bool { var found bool if found = it.s.findPath(itm, cmp, it.buf, &it.s.Stats) != nil; found { it.prev = it.buf.preds[0] it.curr = it.buf.succs[0] } else { if found = eqCmp != nil && compare(eqCmp, itm, it.buf.preds[0].Item()) == 0; found { it.prev = nil it.curr = it.buf.preds[0] } } return found }
[ "func", "(", "it", "*", "Iterator", ")", "SeekWithCmp", "(", "itm", "unsafe", ".", "Pointer", ",", "cmp", "CompareFn", ",", "eqCmp", "CompareFn", ")", "bool", "{", "var", "found", "bool", "\n", "if", "found", "=", "it", ".", "s", ".", "findPath", "(", "itm", ",", "cmp", ",", "it", ".", "buf", ",", "&", "it", ".", "s", ".", "Stats", ")", "!=", "nil", ";", "found", "{", "it", ".", "prev", "=", "it", ".", "buf", ".", "preds", "[", "0", "]", "\n", "it", ".", "curr", "=", "it", ".", "buf", ".", "succs", "[", "0", "]", "\n", "}", "else", "{", "if", "found", "=", "eqCmp", "!=", "nil", "&&", "compare", "(", "eqCmp", ",", "itm", ",", "it", ".", "buf", ".", "preds", "[", "0", "]", ".", "Item", "(", ")", ")", "==", "0", ";", "found", "{", "it", ".", "prev", "=", "nil", "\n", "it", ".", "curr", "=", "it", ".", "buf", ".", "preds", "[", "0", "]", "\n", "}", "\n", "}", "\n", "return", "found", "\n", "}" ]
// SeekWithCmp moves iterator to a provided item by using custom comparator
[ "SeekWithCmp", "moves", "iterator", "to", "a", "provided", "item", "by", "using", "custom", "comparator" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/iterator.go#L47-L59
test
t3rm1n4l/nitro
skiplist/iterator.go
Seek
func (it *Iterator) Seek(itm unsafe.Pointer) bool { it.valid = true found := it.s.findPath(itm, it.cmp, it.buf, &it.s.Stats) != nil it.prev = it.buf.preds[0] it.curr = it.buf.succs[0] return found }
go
func (it *Iterator) Seek(itm unsafe.Pointer) bool { it.valid = true found := it.s.findPath(itm, it.cmp, it.buf, &it.s.Stats) != nil it.prev = it.buf.preds[0] it.curr = it.buf.succs[0] return found }
[ "func", "(", "it", "*", "Iterator", ")", "Seek", "(", "itm", "unsafe", ".", "Pointer", ")", "bool", "{", "it", ".", "valid", "=", "true", "\n", "found", ":=", "it", ".", "s", ".", "findPath", "(", "itm", ",", "it", ".", "cmp", ",", "it", ".", "buf", ",", "&", "it", ".", "s", ".", "Stats", ")", "!=", "nil", "\n", "it", ".", "prev", "=", "it", ".", "buf", ".", "preds", "[", "0", "]", "\n", "it", ".", "curr", "=", "it", ".", "buf", ".", "succs", "[", "0", "]", "\n", "return", "found", "\n", "}" ]
// Seek moves iterator to a provided item
[ "Seek", "moves", "iterator", "to", "a", "provided", "item" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/iterator.go#L62-L68
test
t3rm1n4l/nitro
skiplist/iterator.go
Valid
func (it *Iterator) Valid() bool { if it.valid && it.curr == it.s.tail { it.valid = false } return it.valid }
go
func (it *Iterator) Valid() bool { if it.valid && it.curr == it.s.tail { it.valid = false } return it.valid }
[ "func", "(", "it", "*", "Iterator", ")", "Valid", "(", ")", "bool", "{", "if", "it", ".", "valid", "&&", "it", ".", "curr", "==", "it", ".", "s", ".", "tail", "{", "it", ".", "valid", "=", "false", "\n", "}", "\n", "return", "it", ".", "valid", "\n", "}" ]
// Valid returns true when iterator reaches the end
[ "Valid", "returns", "true", "when", "iterator", "reaches", "the", "end" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/iterator.go#L71-L77
test
t3rm1n4l/nitro
skiplist/iterator.go
Delete
func (it *Iterator) Delete() { it.s.softDelete(it.curr, &it.s.Stats) // It will observe that current item is deleted // Run delete helper and move to the next possible item it.Next() it.deleted = true }
go
func (it *Iterator) Delete() { it.s.softDelete(it.curr, &it.s.Stats) // It will observe that current item is deleted // Run delete helper and move to the next possible item it.Next() it.deleted = true }
[ "func", "(", "it", "*", "Iterator", ")", "Delete", "(", ")", "{", "it", ".", "s", ".", "softDelete", "(", "it", ".", "curr", ",", "&", "it", ".", "s", ".", "Stats", ")", "\n", "it", ".", "Next", "(", ")", "\n", "it", ".", "deleted", "=", "true", "\n", "}" ]
// Delete removes the current item from the skiplist
[ "Delete", "removes", "the", "current", "item", "from", "the", "skiplist" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/iterator.go#L90-L96
test
t3rm1n4l/nitro
skiplist/iterator.go
Next
func (it *Iterator) Next() { if it.deleted { it.deleted = false return } retry: it.valid = true next, deleted := it.curr.getNext(0) if deleted { // Current node is deleted. Unlink current node from the level // and make next node as current node. // If it fails, refresh the path buffer and obtain new current node. if it.s.helpDelete(0, it.prev, it.curr, next, &it.s.Stats) { it.curr = next } else { atomic.AddUint64(&it.s.Stats.readConflicts, 1) found := it.s.findPath(it.curr.Item(), it.cmp, it.buf, &it.s.Stats) != nil last := it.curr it.prev = it.buf.preds[0] it.curr = it.buf.succs[0] if found && last == it.curr { goto retry } } } else { it.prev = it.curr it.curr = next } }
go
func (it *Iterator) Next() { if it.deleted { it.deleted = false return } retry: it.valid = true next, deleted := it.curr.getNext(0) if deleted { // Current node is deleted. Unlink current node from the level // and make next node as current node. // If it fails, refresh the path buffer and obtain new current node. if it.s.helpDelete(0, it.prev, it.curr, next, &it.s.Stats) { it.curr = next } else { atomic.AddUint64(&it.s.Stats.readConflicts, 1) found := it.s.findPath(it.curr.Item(), it.cmp, it.buf, &it.s.Stats) != nil last := it.curr it.prev = it.buf.preds[0] it.curr = it.buf.succs[0] if found && last == it.curr { goto retry } } } else { it.prev = it.curr it.curr = next } }
[ "func", "(", "it", "*", "Iterator", ")", "Next", "(", ")", "{", "if", "it", ".", "deleted", "{", "it", ".", "deleted", "=", "false", "\n", "return", "\n", "}", "\n", "retry", ":", "it", ".", "valid", "=", "true", "\n", "next", ",", "deleted", ":=", "it", ".", "curr", ".", "getNext", "(", "0", ")", "\n", "if", "deleted", "{", "if", "it", ".", "s", ".", "helpDelete", "(", "0", ",", "it", ".", "prev", ",", "it", ".", "curr", ",", "next", ",", "&", "it", ".", "s", ".", "Stats", ")", "{", "it", ".", "curr", "=", "next", "\n", "}", "else", "{", "atomic", ".", "AddUint64", "(", "&", "it", ".", "s", ".", "Stats", ".", "readConflicts", ",", "1", ")", "\n", "found", ":=", "it", ".", "s", ".", "findPath", "(", "it", ".", "curr", ".", "Item", "(", ")", ",", "it", ".", "cmp", ",", "it", ".", "buf", ",", "&", "it", ".", "s", ".", "Stats", ")", "!=", "nil", "\n", "last", ":=", "it", ".", "curr", "\n", "it", ".", "prev", "=", "it", ".", "buf", ".", "preds", "[", "0", "]", "\n", "it", ".", "curr", "=", "it", ".", "buf", ".", "succs", "[", "0", "]", "\n", "if", "found", "&&", "last", "==", "it", ".", "curr", "{", "goto", "retry", "\n", "}", "\n", "}", "\n", "}", "else", "{", "it", ".", "prev", "=", "it", ".", "curr", "\n", "it", ".", "curr", "=", "next", "\n", "}", "\n", "}" ]
// Next moves iterator to the next item
[ "Next", "moves", "iterator", "to", "the", "next", "item" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/iterator.go#L99-L128
test
pivotal-pez/pezdispenser
skus/m1small/types.go
Init
func Init() { s := new(SkuM1SmallBuilder) s.Client, _ = new(SkuM1Small).GetInnkeeperClient() skurepo.Register(SkuName, s) }
go
func Init() { s := new(SkuM1SmallBuilder) s.Client, _ = new(SkuM1Small).GetInnkeeperClient() skurepo.Register(SkuName, s) }
[ "func", "Init", "(", ")", "{", "s", ":=", "new", "(", "SkuM1SmallBuilder", ")", "\n", "s", ".", "Client", ",", "_", "=", "new", "(", "SkuM1Small", ")", ".", "GetInnkeeperClient", "(", ")", "\n", "skurepo", ".", "Register", "(", "SkuName", ",", "s", ")", "\n", "}" ]
// Init - externally available init method
[ "Init", "-", "externally", "available", "init", "method" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/skus/m1small/types.go#L31-L35
test
getantibody/folder
main.go
FromURL
func FromURL(url string) string { result := url for _, replace := range replaces { result = strings.Replace(result, replace.a, replace.b, -1) } return result }
go
func FromURL(url string) string { result := url for _, replace := range replaces { result = strings.Replace(result, replace.a, replace.b, -1) } return result }
[ "func", "FromURL", "(", "url", "string", ")", "string", "{", "result", ":=", "url", "\n", "for", "_", ",", "replace", ":=", "range", "replaces", "{", "result", "=", "strings", ".", "Replace", "(", "result", ",", "replace", ".", "a", ",", "replace", ".", "b", ",", "-", "1", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// FromURL converts the given URL to a folder name
[ "FromURL", "converts", "the", "given", "URL", "to", "a", "folder", "name" ]
e65aa38ebeb03e6d6e91b90a637f3b7c17e1b6d6
https://github.com/getantibody/folder/blob/e65aa38ebeb03e6d6e91b90a637f3b7c17e1b6d6/main.go#L12-L18
test
getantibody/folder
main.go
ToURL
func ToURL(folder string) string { result := folder for _, replace := range replaces { result = strings.Replace(result, replace.b, replace.a, -1) } return result }
go
func ToURL(folder string) string { result := folder for _, replace := range replaces { result = strings.Replace(result, replace.b, replace.a, -1) } return result }
[ "func", "ToURL", "(", "folder", "string", ")", "string", "{", "result", ":=", "folder", "\n", "for", "_", ",", "replace", ":=", "range", "replaces", "{", "result", "=", "strings", ".", "Replace", "(", "result", ",", "replace", ".", "b", ",", "replace", ".", "a", ",", "-", "1", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// ToURL converts the given folder to an URL
[ "ToURL", "converts", "the", "given", "folder", "to", "an", "URL" ]
e65aa38ebeb03e6d6e91b90a637f3b7c17e1b6d6
https://github.com/getantibody/folder/blob/e65aa38ebeb03e6d6e91b90a637f3b7c17e1b6d6/main.go#L21-L27
test
blacklabeldata/namedtuple
header.go
Size
func (t *TupleHeader) Size() int { return VersionOneTupleHeaderSize + int(t.FieldSize)*int(t.FieldCount) }
go
func (t *TupleHeader) Size() int { return VersionOneTupleHeaderSize + int(t.FieldSize)*int(t.FieldCount) }
[ "func", "(", "t", "*", "TupleHeader", ")", "Size", "(", ")", "int", "{", "return", "VersionOneTupleHeaderSize", "+", "int", "(", "t", ".", "FieldSize", ")", "*", "int", "(", "t", ".", "FieldCount", ")", "\n", "}" ]
// Size returns the Version 1 header size plus the size of all the offsets
[ "Size", "returns", "the", "Version", "1", "header", "size", "plus", "the", "size", "of", "all", "the", "offsets" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/header.go#L36-L38
test
blacklabeldata/namedtuple
header.go
WriteTo
func (t *TupleHeader) WriteTo(w io.Writer) (int64, error) { if len(t.Offsets) != int(t.FieldCount) { return 0, errors.New("Invalid Header: Field count does not equal number of field offsets") } // Encode Header dst := make([]byte, t.Size()) dst[0] = byte(t.TupleVersion) binary.LittleEndian.PutUint32(dst[1:], t.NamespaceHash) binary.LittleEndian.PutUint32(dst[5:], t.Hash) binary.LittleEndian.PutUint32(dst[9:], t.FieldCount) pos := int64(13) switch t.FieldSize { case 1: // Write field offsets for _, offset := range t.Offsets { dst[pos] = byte(offset) pos++ } case 2: // Set size enum dst[0] |= 64 // Write field offsets for _, offset := range t.Offsets { binary.LittleEndian.PutUint16(dst[pos:], uint16(offset)) pos += 2 } case 4: // Set size enum dst[0] |= 128 // Write field offsets for _, offset := range t.Offsets { binary.LittleEndian.PutUint32(dst[pos:], uint32(offset)) pos += 4 } case 8: // Set size enum dst[0] |= 192 // Write field offsets for _, offset := range t.Offsets { binary.LittleEndian.PutUint64(dst[pos:], offset) pos += 8 } default: return pos, errors.New("Invalid Header: Field size must be 1,2,4 or 8 bytes") } n, err := w.Write(dst) return int64(n), err }
go
func (t *TupleHeader) WriteTo(w io.Writer) (int64, error) { if len(t.Offsets) != int(t.FieldCount) { return 0, errors.New("Invalid Header: Field count does not equal number of field offsets") } // Encode Header dst := make([]byte, t.Size()) dst[0] = byte(t.TupleVersion) binary.LittleEndian.PutUint32(dst[1:], t.NamespaceHash) binary.LittleEndian.PutUint32(dst[5:], t.Hash) binary.LittleEndian.PutUint32(dst[9:], t.FieldCount) pos := int64(13) switch t.FieldSize { case 1: // Write field offsets for _, offset := range t.Offsets { dst[pos] = byte(offset) pos++ } case 2: // Set size enum dst[0] |= 64 // Write field offsets for _, offset := range t.Offsets { binary.LittleEndian.PutUint16(dst[pos:], uint16(offset)) pos += 2 } case 4: // Set size enum dst[0] |= 128 // Write field offsets for _, offset := range t.Offsets { binary.LittleEndian.PutUint32(dst[pos:], uint32(offset)) pos += 4 } case 8: // Set size enum dst[0] |= 192 // Write field offsets for _, offset := range t.Offsets { binary.LittleEndian.PutUint64(dst[pos:], offset) pos += 8 } default: return pos, errors.New("Invalid Header: Field size must be 1,2,4 or 8 bytes") } n, err := w.Write(dst) return int64(n), err }
[ "func", "(", "t", "*", "TupleHeader", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "if", "len", "(", "t", ".", "Offsets", ")", "!=", "int", "(", "t", ".", "FieldCount", ")", "{", "return", "0", ",", "errors", ".", "New", "(", "\"Invalid Header: Field count does not equal number of field offsets\"", ")", "\n", "}", "\n", "dst", ":=", "make", "(", "[", "]", "byte", ",", "t", ".", "Size", "(", ")", ")", "\n", "dst", "[", "0", "]", "=", "byte", "(", "t", ".", "TupleVersion", ")", "\n", "binary", ".", "LittleEndian", ".", "PutUint32", "(", "dst", "[", "1", ":", "]", ",", "t", ".", "NamespaceHash", ")", "\n", "binary", ".", "LittleEndian", ".", "PutUint32", "(", "dst", "[", "5", ":", "]", ",", "t", ".", "Hash", ")", "\n", "binary", ".", "LittleEndian", ".", "PutUint32", "(", "dst", "[", "9", ":", "]", ",", "t", ".", "FieldCount", ")", "\n", "pos", ":=", "int64", "(", "13", ")", "\n", "switch", "t", ".", "FieldSize", "{", "case", "1", ":", "for", "_", ",", "offset", ":=", "range", "t", ".", "Offsets", "{", "dst", "[", "pos", "]", "=", "byte", "(", "offset", ")", "\n", "pos", "++", "\n", "}", "\n", "case", "2", ":", "dst", "[", "0", "]", "|=", "64", "\n", "for", "_", ",", "offset", ":=", "range", "t", ".", "Offsets", "{", "binary", ".", "LittleEndian", ".", "PutUint16", "(", "dst", "[", "pos", ":", "]", ",", "uint16", "(", "offset", ")", ")", "\n", "pos", "+=", "2", "\n", "}", "\n", "case", "4", ":", "dst", "[", "0", "]", "|=", "128", "\n", "for", "_", ",", "offset", ":=", "range", "t", ".", "Offsets", "{", "binary", ".", "LittleEndian", ".", "PutUint32", "(", "dst", "[", "pos", ":", "]", ",", "uint32", "(", "offset", ")", ")", "\n", "pos", "+=", "4", "\n", "}", "\n", "case", "8", ":", "dst", "[", "0", "]", "|=", "192", "\n", "for", "_", ",", "offset", ":=", "range", "t", ".", "Offsets", "{", "binary", ".", "LittleEndian", ".", "PutUint64", "(", "dst", "[", "pos", ":", "]", ",", "offset", ")", "\n", "pos", "+=", "8", "\n", "}", "\n", "default", ":", "return", "pos", ",", "errors", ".", "New", "(", "\"Invalid Header: Field size must be 1,2,4 or 8 bytes\"", ")", "\n", "}", "\n", "n", ",", "err", ":=", "w", ".", "Write", "(", "dst", ")", "\n", "return", "int64", "(", "n", ")", ",", "err", "\n", "}" ]
// WriteTo writes the TupleHeader into the given writer.
[ "WriteTo", "writes", "the", "TupleHeader", "into", "the", "given", "writer", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/header.go#L41-L96
test
insionng/martini
static.go
Static
func Static(directory string, staticOpt ...StaticOptions) Handler { if !path.IsAbs(directory) { directory = path.Join(Root, directory) } dir := http.Dir(directory) opt := prepareStaticOptions(staticOpt) return func(res http.ResponseWriter, req *http.Request, log *log.Logger) { if req.Method != "GET" && req.Method != "HEAD" { return } file := req.URL.Path // if we have a prefix, filter requests by stripping the prefix if opt.Prefix != "" { if !strings.HasPrefix(file, opt.Prefix) { return } file = file[len(opt.Prefix):] if file != "" && file[0] != '/' { return } } f, err := dir.Open(file) if err != nil { // discard the error? return } defer f.Close() fi, err := f.Stat() if err != nil { return } // try to serve index file if fi.IsDir() { // redirect if missing trailing slash if !strings.HasSuffix(req.URL.Path, "/") { http.Redirect(res, req, req.URL.Path+"/", http.StatusFound) return } file = path.Join(file, opt.IndexFile) f, err = dir.Open(file) if err != nil { return } defer f.Close() fi, err = f.Stat() if err != nil || fi.IsDir() { return } } if !opt.SkipLogging { log.Println("[Static] Serving " + file) } // Add an Expires header to the static content if opt.Expires != nil { res.Header().Set("Expires", opt.Expires()) } http.ServeContent(res, req, file, fi.ModTime(), f) } }
go
func Static(directory string, staticOpt ...StaticOptions) Handler { if !path.IsAbs(directory) { directory = path.Join(Root, directory) } dir := http.Dir(directory) opt := prepareStaticOptions(staticOpt) return func(res http.ResponseWriter, req *http.Request, log *log.Logger) { if req.Method != "GET" && req.Method != "HEAD" { return } file := req.URL.Path // if we have a prefix, filter requests by stripping the prefix if opt.Prefix != "" { if !strings.HasPrefix(file, opt.Prefix) { return } file = file[len(opt.Prefix):] if file != "" && file[0] != '/' { return } } f, err := dir.Open(file) if err != nil { // discard the error? return } defer f.Close() fi, err := f.Stat() if err != nil { return } // try to serve index file if fi.IsDir() { // redirect if missing trailing slash if !strings.HasSuffix(req.URL.Path, "/") { http.Redirect(res, req, req.URL.Path+"/", http.StatusFound) return } file = path.Join(file, opt.IndexFile) f, err = dir.Open(file) if err != nil { return } defer f.Close() fi, err = f.Stat() if err != nil || fi.IsDir() { return } } if !opt.SkipLogging { log.Println("[Static] Serving " + file) } // Add an Expires header to the static content if opt.Expires != nil { res.Header().Set("Expires", opt.Expires()) } http.ServeContent(res, req, file, fi.ModTime(), f) } }
[ "func", "Static", "(", "directory", "string", ",", "staticOpt", "...", "StaticOptions", ")", "Handler", "{", "if", "!", "path", ".", "IsAbs", "(", "directory", ")", "{", "directory", "=", "path", ".", "Join", "(", "Root", ",", "directory", ")", "\n", "}", "\n", "dir", ":=", "http", ".", "Dir", "(", "directory", ")", "\n", "opt", ":=", "prepareStaticOptions", "(", "staticOpt", ")", "\n", "return", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "log", "*", "log", ".", "Logger", ")", "{", "if", "req", ".", "Method", "!=", "\"GET\"", "&&", "req", ".", "Method", "!=", "\"HEAD\"", "{", "return", "\n", "}", "\n", "file", ":=", "req", ".", "URL", ".", "Path", "\n", "if", "opt", ".", "Prefix", "!=", "\"\"", "{", "if", "!", "strings", ".", "HasPrefix", "(", "file", ",", "opt", ".", "Prefix", ")", "{", "return", "\n", "}", "\n", "file", "=", "file", "[", "len", "(", "opt", ".", "Prefix", ")", ":", "]", "\n", "if", "file", "!=", "\"\"", "&&", "file", "[", "0", "]", "!=", "'/'", "{", "return", "\n", "}", "\n", "}", "\n", "f", ",", "err", ":=", "dir", ".", "Open", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "fi", ",", "err", ":=", "f", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "fi", ".", "IsDir", "(", ")", "{", "if", "!", "strings", ".", "HasSuffix", "(", "req", ".", "URL", ".", "Path", ",", "\"/\"", ")", "{", "http", ".", "Redirect", "(", "res", ",", "req", ",", "req", ".", "URL", ".", "Path", "+", "\"/\"", ",", "http", ".", "StatusFound", ")", "\n", "return", "\n", "}", "\n", "file", "=", "path", ".", "Join", "(", "file", ",", "opt", ".", "IndexFile", ")", "\n", "f", ",", "err", "=", "dir", ".", "Open", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "fi", ",", "err", "=", "f", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "||", "fi", ".", "IsDir", "(", ")", "{", "return", "\n", "}", "\n", "}", "\n", "if", "!", "opt", ".", "SkipLogging", "{", "log", ".", "Println", "(", "\"[Static] Serving \"", "+", "file", ")", "\n", "}", "\n", "if", "opt", ".", "Expires", "!=", "nil", "{", "res", ".", "Header", "(", ")", ".", "Set", "(", "\"Expires\"", ",", "opt", ".", "Expires", "(", ")", ")", "\n", "}", "\n", "http", ".", "ServeContent", "(", "res", ",", "req", ",", "file", ",", "fi", ".", "ModTime", "(", ")", ",", "f", ")", "\n", "}", "\n", "}" ]
// Static returns a middleware handler that serves static files in the given directory.
[ "Static", "returns", "a", "middleware", "handler", "that", "serves", "static", "files", "in", "the", "given", "directory", "." ]
2d0ba5dc75fe9549c10e2f71927803a11e5e4957
https://github.com/insionng/martini/blob/2d0ba5dc75fe9549c10e2f71927803a11e5e4957/static.go#L46-L112
test
ccding/go-config-reader
config/config.go
Read
func (c *Config) Read() error { in, err := os.Open(c.filename) if err != nil { return err } defer in.Close() scanner := bufio.NewScanner(in) line := "" section := "" for scanner.Scan() { if scanner.Text() == "" { continue } if line == "" { sec, ok := checkSection(scanner.Text()) if ok { section = sec continue } } if checkComment(scanner.Text()) { continue } line += scanner.Text() if strings.HasSuffix(line, "\\") { line = line[:len(line)-1] continue } key, value, ok := checkLine(line) if !ok { return errors.New("WRONG: " + line) } c.Set(section, key, value) line = "" } return nil }
go
func (c *Config) Read() error { in, err := os.Open(c.filename) if err != nil { return err } defer in.Close() scanner := bufio.NewScanner(in) line := "" section := "" for scanner.Scan() { if scanner.Text() == "" { continue } if line == "" { sec, ok := checkSection(scanner.Text()) if ok { section = sec continue } } if checkComment(scanner.Text()) { continue } line += scanner.Text() if strings.HasSuffix(line, "\\") { line = line[:len(line)-1] continue } key, value, ok := checkLine(line) if !ok { return errors.New("WRONG: " + line) } c.Set(section, key, value) line = "" } return nil }
[ "func", "(", "c", "*", "Config", ")", "Read", "(", ")", "error", "{", "in", ",", "err", ":=", "os", ".", "Open", "(", "c", ".", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "in", ".", "Close", "(", ")", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "in", ")", "\n", "line", ":=", "\"\"", "\n", "section", ":=", "\"\"", "\n", "for", "scanner", ".", "Scan", "(", ")", "{", "if", "scanner", ".", "Text", "(", ")", "==", "\"\"", "{", "continue", "\n", "}", "\n", "if", "line", "==", "\"\"", "{", "sec", ",", "ok", ":=", "checkSection", "(", "scanner", ".", "Text", "(", ")", ")", "\n", "if", "ok", "{", "section", "=", "sec", "\n", "continue", "\n", "}", "\n", "}", "\n", "if", "checkComment", "(", "scanner", ".", "Text", "(", ")", ")", "{", "continue", "\n", "}", "\n", "line", "+=", "scanner", ".", "Text", "(", ")", "\n", "if", "strings", ".", "HasSuffix", "(", "line", ",", "\"\\\\\"", ")", "\\\\", "\n", "{", "line", "=", "line", "[", ":", "len", "(", "line", ")", "-", "1", "]", "\n", "continue", "\n", "}", "\n", "key", ",", "value", ",", "ok", ":=", "checkLine", "(", "line", ")", "\n", "if", "!", "ok", "{", "return", "errors", ".", "New", "(", "\"WRONG: \"", "+", "line", ")", "\n", "}", "\n", "c", ".", "Set", "(", "section", ",", "key", ",", "value", ")", "\n", "}", "\n", "line", "=", "\"\"", "\n", "}" ]
// Read function reads configurations from the file defined in // Config.filename.
[ "Read", "function", "reads", "configurations", "from", "the", "file", "defined", "in", "Config", ".", "filename", "." ]
8b6c2b50197f20da3b1c5944c274c173634dc056
https://github.com/ccding/go-config-reader/blob/8b6c2b50197f20da3b1c5944c274c173634dc056/config/config.go#L66-L102
test
ccding/go-config-reader
config/config.go
Del
func (c *Config) Del(section string, key string) { _, ok := c.config[section] if ok { delete(c.config[section], key) if len(c.config[section]) == 0 { delete(c.config, section) } } }
go
func (c *Config) Del(section string, key string) { _, ok := c.config[section] if ok { delete(c.config[section], key) if len(c.config[section]) == 0 { delete(c.config, section) } } }
[ "func", "(", "c", "*", "Config", ")", "Del", "(", "section", "string", ",", "key", "string", ")", "{", "_", ",", "ok", ":=", "c", ".", "config", "[", "section", "]", "\n", "if", "ok", "{", "delete", "(", "c", ".", "config", "[", "section", "]", ",", "key", ")", "\n", "if", "len", "(", "c", ".", "config", "[", "section", "]", ")", "==", "0", "{", "delete", "(", "c", ".", "config", ",", "section", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Del function deletes a key from the configuration.
[ "Del", "function", "deletes", "a", "key", "from", "the", "configuration", "." ]
8b6c2b50197f20da3b1c5944c274c173634dc056
https://github.com/ccding/go-config-reader/blob/8b6c2b50197f20da3b1c5944c274c173634dc056/config/config.go#L131-L139
test
ccding/go-config-reader
config/config.go
WriteTo
func (c *Config) WriteTo(filename string) error { content := "" for k, v := range c.config { format := "%v = %v\n" if k != "" { content += fmt.Sprintf("[%v]\n", k) format = "\t" + format } for key, value := range v { content += fmt.Sprintf(format, key, value) } } return ioutil.WriteFile(filename, []byte(content), 0644) }
go
func (c *Config) WriteTo(filename string) error { content := "" for k, v := range c.config { format := "%v = %v\n" if k != "" { content += fmt.Sprintf("[%v]\n", k) format = "\t" + format } for key, value := range v { content += fmt.Sprintf(format, key, value) } } return ioutil.WriteFile(filename, []byte(content), 0644) }
[ "func", "(", "c", "*", "Config", ")", "WriteTo", "(", "filename", "string", ")", "error", "{", "content", ":=", "\"\"", "\n", "for", "k", ",", "v", ":=", "range", "c", ".", "config", "{", "format", ":=", "\"%v = %v\\n\"", "\n", "\\n", "\n", "if", "k", "!=", "\"\"", "{", "content", "+=", "fmt", ".", "Sprintf", "(", "\"[%v]\\n\"", ",", "\\n", ")", "\n", "k", "\n", "}", "\n", "}", "\n", "format", "=", "\"\\t\"", "+", "\\t", "\n", "}" ]
// WriteTo function writes the configuration to a new file. This function // re-organizes the configuration and deletes all the comments.
[ "WriteTo", "function", "writes", "the", "configuration", "to", "a", "new", "file", ".", "This", "function", "re", "-", "organizes", "the", "configuration", "and", "deletes", "all", "the", "comments", "." ]
8b6c2b50197f20da3b1c5944c274c173634dc056
https://github.com/ccding/go-config-reader/blob/8b6c2b50197f20da3b1c5944c274c173634dc056/config/config.go#L148-L161
test
ccding/go-config-reader
config/config.go
checkSection
func checkSection(line string) (string, bool) { line = strings.TrimSpace(line) lineLen := len(line) if lineLen < 2 { return "", false } if line[0] == '[' && line[lineLen-1] == ']' { return line[1 : lineLen-1], true } return "", false }
go
func checkSection(line string) (string, bool) { line = strings.TrimSpace(line) lineLen := len(line) if lineLen < 2 { return "", false } if line[0] == '[' && line[lineLen-1] == ']' { return line[1 : lineLen-1], true } return "", false }
[ "func", "checkSection", "(", "line", "string", ")", "(", "string", ",", "bool", ")", "{", "line", "=", "strings", ".", "TrimSpace", "(", "line", ")", "\n", "lineLen", ":=", "len", "(", "line", ")", "\n", "if", "lineLen", "<", "2", "{", "return", "\"\"", ",", "false", "\n", "}", "\n", "if", "line", "[", "0", "]", "==", "'['", "&&", "line", "[", "lineLen", "-", "1", "]", "==", "']'", "{", "return", "line", "[", "1", ":", "lineLen", "-", "1", "]", ",", "true", "\n", "}", "\n", "return", "\"\"", ",", "false", "\n", "}" ]
// To check this line is a section or not. If it is not a section, it returns // "".
[ "To", "check", "this", "line", "is", "a", "section", "or", "not", ".", "If", "it", "is", "not", "a", "section", "it", "returns", "." ]
8b6c2b50197f20da3b1c5944c274c173634dc056
https://github.com/ccding/go-config-reader/blob/8b6c2b50197f20da3b1c5944c274c173634dc056/config/config.go#L165-L175
test
ccding/go-config-reader
config/config.go
checkLine
func checkLine(line string) (string, string, bool) { key := "" value := "" sp := strings.SplitN(line, "=", 2) if len(sp) != 2 { return key, value, false } key = strings.TrimSpace(sp[0]) value = strings.TrimSpace(sp[1]) return key, value, true }
go
func checkLine(line string) (string, string, bool) { key := "" value := "" sp := strings.SplitN(line, "=", 2) if len(sp) != 2 { return key, value, false } key = strings.TrimSpace(sp[0]) value = strings.TrimSpace(sp[1]) return key, value, true }
[ "func", "checkLine", "(", "line", "string", ")", "(", "string", ",", "string", ",", "bool", ")", "{", "key", ":=", "\"\"", "\n", "value", ":=", "\"\"", "\n", "sp", ":=", "strings", ".", "SplitN", "(", "line", ",", "\"=\"", ",", "2", ")", "\n", "if", "len", "(", "sp", ")", "!=", "2", "{", "return", "key", ",", "value", ",", "false", "\n", "}", "\n", "key", "=", "strings", ".", "TrimSpace", "(", "sp", "[", "0", "]", ")", "\n", "value", "=", "strings", ".", "TrimSpace", "(", "sp", "[", "1", "]", ")", "\n", "return", "key", ",", "value", ",", "true", "\n", "}" ]
// To check this line is a valid key-value pair or not.
[ "To", "check", "this", "line", "is", "a", "valid", "key", "-", "value", "pair", "or", "not", "." ]
8b6c2b50197f20da3b1c5944c274c173634dc056
https://github.com/ccding/go-config-reader/blob/8b6c2b50197f20da3b1c5944c274c173634dc056/config/config.go#L178-L188
test
ccding/go-config-reader
config/config.go
checkComment
func checkComment(line string) bool { line = strings.TrimSpace(line) for p := range commentPrefix { if strings.HasPrefix(line, commentPrefix[p]) { return true } } return false }
go
func checkComment(line string) bool { line = strings.TrimSpace(line) for p := range commentPrefix { if strings.HasPrefix(line, commentPrefix[p]) { return true } } return false }
[ "func", "checkComment", "(", "line", "string", ")", "bool", "{", "line", "=", "strings", ".", "TrimSpace", "(", "line", ")", "\n", "for", "p", ":=", "range", "commentPrefix", "{", "if", "strings", ".", "HasPrefix", "(", "line", ",", "commentPrefix", "[", "p", "]", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// To check this line is a whole line comment or not.
[ "To", "check", "this", "line", "is", "a", "whole", "line", "comment", "or", "not", "." ]
8b6c2b50197f20da3b1c5944c274c173634dc056
https://github.com/ccding/go-config-reader/blob/8b6c2b50197f20da3b1c5944c274c173634dc056/config/config.go#L191-L199
test
urandom/handler
response_wrapper.go
NewResponseWrapper
func NewResponseWrapper(w http.ResponseWriter) *ResponseWrapper { return &ResponseWrapper{ResponseRecorder: httptest.NewRecorder(), writer: w} }
go
func NewResponseWrapper(w http.ResponseWriter) *ResponseWrapper { return &ResponseWrapper{ResponseRecorder: httptest.NewRecorder(), writer: w} }
[ "func", "NewResponseWrapper", "(", "w", "http", ".", "ResponseWriter", ")", "*", "ResponseWrapper", "{", "return", "&", "ResponseWrapper", "{", "ResponseRecorder", ":", "httptest", ".", "NewRecorder", "(", ")", ",", "writer", ":", "w", "}", "\n", "}" ]
// NewResponseWrapper creates a new wrapper. The passed http.ResponseWriter is // used in case the wrapper needs to be hijacked.
[ "NewResponseWrapper", "creates", "a", "new", "wrapper", ".", "The", "passed", "http", ".", "ResponseWriter", "is", "used", "in", "case", "the", "wrapper", "needs", "to", "be", "hijacked", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/response_wrapper.go#L25-L27
test
urandom/handler
response_wrapper.go
Hijack
func (w *ResponseWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) { if hijacker, ok := w.writer.(http.Hijacker); ok { c, rw, err := hijacker.Hijack() if err == nil { w.Hijacked = true } return c, rw, err } return nil, nil, errors.New("Wrapped ResponseWriter is not a Hijacker") }
go
func (w *ResponseWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) { if hijacker, ok := w.writer.(http.Hijacker); ok { c, rw, err := hijacker.Hijack() if err == nil { w.Hijacked = true } return c, rw, err } return nil, nil, errors.New("Wrapped ResponseWriter is not a Hijacker") }
[ "func", "(", "w", "*", "ResponseWrapper", ")", "Hijack", "(", ")", "(", "net", ".", "Conn", ",", "*", "bufio", ".", "ReadWriter", ",", "error", ")", "{", "if", "hijacker", ",", "ok", ":=", "w", ".", "writer", ".", "(", "http", ".", "Hijacker", ")", ";", "ok", "{", "c", ",", "rw", ",", "err", ":=", "hijacker", ".", "Hijack", "(", ")", "\n", "if", "err", "==", "nil", "{", "w", ".", "Hijacked", "=", "true", "\n", "}", "\n", "return", "c", ",", "rw", ",", "err", "\n", "}", "\n", "return", "nil", ",", "nil", ",", "errors", ".", "New", "(", "\"Wrapped ResponseWriter is not a Hijacker\"", ")", "\n", "}" ]
// Hijack tries to use the original http.ResponseWriter for hijacking. If the // original writer doesn't implement http.Hijacker, it returns an error.
[ "Hijack", "tries", "to", "use", "the", "original", "http", ".", "ResponseWriter", "for", "hijacking", ".", "If", "the", "original", "writer", "doesn", "t", "implement", "http", ".", "Hijacker", "it", "returns", "an", "error", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/response_wrapper.go#L31-L43
test
urandom/handler
response_wrapper.go
CloseNotify
func (w *ResponseWrapper) CloseNotify() <-chan bool { if notifier, ok := w.writer.(http.CloseNotifier); ok { c := notifier.CloseNotify() return c } return make(chan bool) }
go
func (w *ResponseWrapper) CloseNotify() <-chan bool { if notifier, ok := w.writer.(http.CloseNotifier); ok { c := notifier.CloseNotify() return c } return make(chan bool) }
[ "func", "(", "w", "*", "ResponseWrapper", ")", "CloseNotify", "(", ")", "<-", "chan", "bool", "{", "if", "notifier", ",", "ok", ":=", "w", ".", "writer", ".", "(", "http", ".", "CloseNotifier", ")", ";", "ok", "{", "c", ":=", "notifier", ".", "CloseNotify", "(", ")", "\n", "return", "c", "\n", "}", "\n", "return", "make", "(", "chan", "bool", ")", "\n", "}" ]
// CloseNotify tries to use the original http.ResponseWriter for close // notification. If the original writer doesn't implement http.CloseNotifier, // it returns a channel that will never close.
[ "CloseNotify", "tries", "to", "use", "the", "original", "http", ".", "ResponseWriter", "for", "close", "notification", ".", "If", "the", "original", "writer", "doesn", "t", "implement", "http", ".", "CloseNotifier", "it", "returns", "a", "channel", "that", "will", "never", "close", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/response_wrapper.go#L48-L55
test
urandom/handler
log/access.go
DateFormat
func DateFormat(f string) Option { return Option{func(o *options) { o.dateFormat = f }} }
go
func DateFormat(f string) Option { return Option{func(o *options) { o.dateFormat = f }} }
[ "func", "DateFormat", "(", "f", "string", ")", "Option", "{", "return", "Option", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "dateFormat", "=", "f", "\n", "}", "}", "\n", "}" ]
// DateFormat is used to format the timestamp.
[ "DateFormat", "is", "used", "to", "format", "the", "timestamp", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/log/access.go#L36-L40
test
lucas-clemente/go-http-logger
logger.go
Logger
func Logger(next http.Handler) http.HandlerFunc { stdlogger := log.New(os.Stdout, "", 0) //errlogger := log.New(os.Stderr, "", 0) return func(w http.ResponseWriter, r *http.Request) { // Start timer start := time.Now() // Process request writer := statusWriter{w, 0} next.ServeHTTP(&writer, r) // Stop timer end := time.Now() latency := end.Sub(start) clientIP := r.RemoteAddr method := r.Method statusCode := writer.status statusColor := colorForStatus(statusCode) methodColor := colorForMethod(method) stdlogger.Printf("[HTTP] %v |%s %3d %s| %12v | %s |%s %s %-7s %s\n", end.Format("2006/01/02 - 15:04:05"), statusColor, statusCode, reset, latency, clientIP, methodColor, reset, method, r.URL.Path, ) } }
go
func Logger(next http.Handler) http.HandlerFunc { stdlogger := log.New(os.Stdout, "", 0) //errlogger := log.New(os.Stderr, "", 0) return func(w http.ResponseWriter, r *http.Request) { // Start timer start := time.Now() // Process request writer := statusWriter{w, 0} next.ServeHTTP(&writer, r) // Stop timer end := time.Now() latency := end.Sub(start) clientIP := r.RemoteAddr method := r.Method statusCode := writer.status statusColor := colorForStatus(statusCode) methodColor := colorForMethod(method) stdlogger.Printf("[HTTP] %v |%s %3d %s| %12v | %s |%s %s %-7s %s\n", end.Format("2006/01/02 - 15:04:05"), statusColor, statusCode, reset, latency, clientIP, methodColor, reset, method, r.URL.Path, ) } }
[ "func", "Logger", "(", "next", "http", ".", "Handler", ")", "http", ".", "HandlerFunc", "{", "stdlogger", ":=", "log", ".", "New", "(", "os", ".", "Stdout", ",", "\"\"", ",", "0", ")", "\n", "return", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "start", ":=", "time", ".", "Now", "(", ")", "\n", "writer", ":=", "statusWriter", "{", "w", ",", "0", "}", "\n", "next", ".", "ServeHTTP", "(", "&", "writer", ",", "r", ")", "\n", "end", ":=", "time", ".", "Now", "(", ")", "\n", "latency", ":=", "end", ".", "Sub", "(", "start", ")", "\n", "clientIP", ":=", "r", ".", "RemoteAddr", "\n", "method", ":=", "r", ".", "Method", "\n", "statusCode", ":=", "writer", ".", "status", "\n", "statusColor", ":=", "colorForStatus", "(", "statusCode", ")", "\n", "methodColor", ":=", "colorForMethod", "(", "method", ")", "\n", "stdlogger", ".", "Printf", "(", "\"[HTTP] %v |%s %3d %s| %12v | %s |%s %s %-7s %s\\n\"", ",", "\\n", ",", "end", ".", "Format", "(", "\"2006/01/02 - 15:04:05\"", ")", ",", "statusColor", ",", "statusCode", ",", "reset", ",", "latency", ",", "clientIP", ",", "methodColor", ",", "reset", ",", "method", ",", ")", "\n", "}", "\n", "}" ]
// Logger returns a new logger to be wrapped around your main http.Handler
[ "Logger", "returns", "a", "new", "logger", "to", "be", "wrapped", "around", "your", "main", "http", ".", "Handler" ]
0ba07d157a1e5a262f5e7f5ee7bf37719fa8b5d9
https://github.com/lucas-clemente/go-http-logger/blob/0ba07d157a1e5a262f5e7f5ee7bf37719fa8b5d9/logger.go#L40-L71
test
pivotal-pez/pezdispenser
service/available_inventory.go
GetAvailableInventory
func GetAvailableInventory(taskCollection integrations.Collection) (inventory map[string]skurepo.SkuBuilder) { inventory = skurepo.GetRegistry() onceLoadInventoryPoller.Do(func() { startTaskPollingForRegisteredSkus(taskCollection) }) return }
go
func GetAvailableInventory(taskCollection integrations.Collection) (inventory map[string]skurepo.SkuBuilder) { inventory = skurepo.GetRegistry() onceLoadInventoryPoller.Do(func() { startTaskPollingForRegisteredSkus(taskCollection) }) return }
[ "func", "GetAvailableInventory", "(", "taskCollection", "integrations", ".", "Collection", ")", "(", "inventory", "map", "[", "string", "]", "skurepo", ".", "SkuBuilder", ")", "{", "inventory", "=", "skurepo", ".", "GetRegistry", "(", ")", "\n", "onceLoadInventoryPoller", ".", "Do", "(", "func", "(", ")", "{", "startTaskPollingForRegisteredSkus", "(", "taskCollection", ")", "\n", "}", ")", "\n", "return", "\n", "}" ]
//GetAvailableInventory - this should return available inventory and start a long task poller
[ "GetAvailableInventory", "-", "this", "should", "return", "available", "inventory", "and", "start", "a", "long", "task", "poller" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/service/available_inventory.go#L21-L28
test
urandom/handler
auth/jwt.go
Expiration
func Expiration(e time.Duration) TokenOpt { return TokenOpt{func(o *options) { o.expiration = e }} }
go
func Expiration(e time.Duration) TokenOpt { return TokenOpt{func(o *options) { o.expiration = e }} }
[ "func", "Expiration", "(", "e", "time", ".", "Duration", ")", "TokenOpt", "{", "return", "TokenOpt", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "expiration", "=", "e", "\n", "}", "}", "\n", "}" ]
// Expiration sets the expiration time of the auth token
[ "Expiration", "sets", "the", "expiration", "time", "of", "the", "auth", "token" ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L70-L74
test
urandom/handler
auth/jwt.go
Claimer
func Claimer(c func(claims *jwt.StandardClaims) jwt.Claims) TokenOpt { return TokenOpt{func(o *options) { o.claimer = c }} }
go
func Claimer(c func(claims *jwt.StandardClaims) jwt.Claims) TokenOpt { return TokenOpt{func(o *options) { o.claimer = c }} }
[ "func", "Claimer", "(", "c", "func", "(", "claims", "*", "jwt", ".", "StandardClaims", ")", "jwt", ".", "Claims", ")", "TokenOpt", "{", "return", "TokenOpt", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "claimer", "=", "c", "\n", "}", "}", "\n", "}" ]
// Claimer is responsible for transforming a standard claims object into a // custom one.
[ "Claimer", "is", "responsible", "for", "transforming", "a", "standard", "claims", "object", "into", "a", "custom", "one", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L78-L82
test
urandom/handler
auth/jwt.go
Issuer
func Issuer(issuer string) TokenOpt { return TokenOpt{func(o *options) { o.issuer = issuer }} }
go
func Issuer(issuer string) TokenOpt { return TokenOpt{func(o *options) { o.issuer = issuer }} }
[ "func", "Issuer", "(", "issuer", "string", ")", "TokenOpt", "{", "return", "TokenOpt", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "issuer", "=", "issuer", "\n", "}", "}", "\n", "}" ]
// Issuer sets the issuer in the standart claims object.
[ "Issuer", "sets", "the", "issuer", "in", "the", "standart", "claims", "object", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L85-L89
test
urandom/handler
auth/jwt.go
User
func User(user string) TokenOpt { return TokenOpt{func(o *options) { o.user = user }} }
go
func User(user string) TokenOpt { return TokenOpt{func(o *options) { o.user = user }} }
[ "func", "User", "(", "user", "string", ")", "TokenOpt", "{", "return", "TokenOpt", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "user", "=", "user", "\n", "}", "}", "\n", "}" ]
// User sets the query key from which to obtain the user.
[ "User", "sets", "the", "query", "key", "from", "which", "to", "obtain", "the", "user", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L92-L96
test
urandom/handler
auth/jwt.go
Password
func Password(password string) TokenOpt { return TokenOpt{func(o *options) { o.password = password }} }
go
func Password(password string) TokenOpt { return TokenOpt{func(o *options) { o.password = password }} }
[ "func", "Password", "(", "password", "string", ")", "TokenOpt", "{", "return", "TokenOpt", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "password", "=", "password", "\n", "}", "}", "\n", "}" ]
// Password sets the query key from which to obtain the password.
[ "Password", "sets", "the", "query", "key", "from", "which", "to", "obtain", "the", "password", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L99-L103
test
urandom/handler
auth/jwt.go
Extractor
func Extractor(e request.Extractor) TokenOpt { return TokenOpt{func(o *options) { o.extractor = e }} }
go
func Extractor(e request.Extractor) TokenOpt { return TokenOpt{func(o *options) { o.extractor = e }} }
[ "func", "Extractor", "(", "e", "request", ".", "Extractor", ")", "TokenOpt", "{", "return", "TokenOpt", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "extractor", "=", "e", "\n", "}", "}", "\n", "}" ]
// Extractor extracts a token from a request
[ "Extractor", "extracts", "a", "token", "from", "a", "request" ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L106-L110
test
urandom/handler
auth/jwt.go
TokenGenerator
func TokenGenerator(h http.Handler, auth Authenticator, secret []byte, opts ...TokenOpt) http.Handler { o := options{ logger: handler.NopLogger(), claimer: func(c *jwt.StandardClaims) jwt.Claims { return c }, expiration: time.Hour * 24 * 15, user: "user", password: "password", } o.apply(opts) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var err error if strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data") { err = r.ParseMultipartForm(0) } else { err = r.ParseForm() } if err != nil { o.logger.Print("Invalid request form: ", err) http.Error(w, err.Error(), http.StatusBadRequest) return } user := r.FormValue(o.user) password := r.FormValue(o.password) if user == "" || password == "" || !auth.Authenticate(user, password) { w.WriteHeader(http.StatusUnauthorized) return } expiration := time.Now().Add(o.expiration) t := jwt.NewWithClaims(jwt.SigningMethodHS512, o.claimer(&jwt.StandardClaims{ Subject: user, ExpiresAt: expiration.Unix(), Issuer: o.issuer, })) if token, err := t.SignedString(secret); err == nil { if h == nil { w.Header().Add("Authorization", "Bearer "+token) w.Write([]byte(token)) return } r = r.WithContext(context.WithValue(r.Context(), TokenKey, token)) h.ServeHTTP(w, r) } else { o.logger.Print("Error authenticating user:", err) w.WriteHeader(http.StatusInternalServerError) return } }) }
go
func TokenGenerator(h http.Handler, auth Authenticator, secret []byte, opts ...TokenOpt) http.Handler { o := options{ logger: handler.NopLogger(), claimer: func(c *jwt.StandardClaims) jwt.Claims { return c }, expiration: time.Hour * 24 * 15, user: "user", password: "password", } o.apply(opts) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var err error if strings.HasPrefix(r.Header.Get("Content-Type"), "multipart/form-data") { err = r.ParseMultipartForm(0) } else { err = r.ParseForm() } if err != nil { o.logger.Print("Invalid request form: ", err) http.Error(w, err.Error(), http.StatusBadRequest) return } user := r.FormValue(o.user) password := r.FormValue(o.password) if user == "" || password == "" || !auth.Authenticate(user, password) { w.WriteHeader(http.StatusUnauthorized) return } expiration := time.Now().Add(o.expiration) t := jwt.NewWithClaims(jwt.SigningMethodHS512, o.claimer(&jwt.StandardClaims{ Subject: user, ExpiresAt: expiration.Unix(), Issuer: o.issuer, })) if token, err := t.SignedString(secret); err == nil { if h == nil { w.Header().Add("Authorization", "Bearer "+token) w.Write([]byte(token)) return } r = r.WithContext(context.WithValue(r.Context(), TokenKey, token)) h.ServeHTTP(w, r) } else { o.logger.Print("Error authenticating user:", err) w.WriteHeader(http.StatusInternalServerError) return } }) }
[ "func", "TokenGenerator", "(", "h", "http", ".", "Handler", ",", "auth", "Authenticator", ",", "secret", "[", "]", "byte", ",", "opts", "...", "TokenOpt", ")", "http", ".", "Handler", "{", "o", ":=", "options", "{", "logger", ":", "handler", ".", "NopLogger", "(", ")", ",", "claimer", ":", "func", "(", "c", "*", "jwt", ".", "StandardClaims", ")", "jwt", ".", "Claims", "{", "return", "c", "}", ",", "expiration", ":", "time", ".", "Hour", "*", "24", "*", "15", ",", "user", ":", "\"user\"", ",", "password", ":", "\"password\"", ",", "}", "\n", "o", ".", "apply", "(", "opts", ")", "\n", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "var", "err", "error", "\n", "if", "strings", ".", "HasPrefix", "(", "r", ".", "Header", ".", "Get", "(", "\"Content-Type\"", ")", ",", "\"multipart/form-data\"", ")", "{", "err", "=", "r", ".", "ParseMultipartForm", "(", "0", ")", "\n", "}", "else", "{", "err", "=", "r", ".", "ParseForm", "(", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "o", ".", "logger", ".", "Print", "(", "\"Invalid request form: \"", ",", "err", ")", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusBadRequest", ")", "\n", "return", "\n", "}", "\n", "user", ":=", "r", ".", "FormValue", "(", "o", ".", "user", ")", "\n", "password", ":=", "r", ".", "FormValue", "(", "o", ".", "password", ")", "\n", "if", "user", "==", "\"\"", "||", "password", "==", "\"\"", "||", "!", "auth", ".", "Authenticate", "(", "user", ",", "password", ")", "{", "w", ".", "WriteHeader", "(", "http", ".", "StatusUnauthorized", ")", "\n", "return", "\n", "}", "\n", "expiration", ":=", "time", ".", "Now", "(", ")", ".", "Add", "(", "o", ".", "expiration", ")", "\n", "t", ":=", "jwt", ".", "NewWithClaims", "(", "jwt", ".", "SigningMethodHS512", ",", "o", ".", "claimer", "(", "&", "jwt", ".", "StandardClaims", "{", "Subject", ":", "user", ",", "ExpiresAt", ":", "expiration", ".", "Unix", "(", ")", ",", "Issuer", ":", "o", ".", "issuer", ",", "}", ")", ")", "\n", "if", "token", ",", "err", ":=", "t", ".", "SignedString", "(", "secret", ")", ";", "err", "==", "nil", "{", "if", "h", "==", "nil", "{", "w", ".", "Header", "(", ")", ".", "Add", "(", "\"Authorization\"", ",", "\"Bearer \"", "+", "token", ")", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "token", ")", ")", "\n", "return", "\n", "}", "\n", "r", "=", "r", ".", "WithContext", "(", "context", ".", "WithValue", "(", "r", ".", "Context", "(", ")", ",", "TokenKey", ",", "token", ")", ")", "\n", "h", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n", "}", "else", "{", "o", ".", "logger", ".", "Print", "(", "\"Error authenticating user:\"", ",", "err", ")", "\n", "w", ".", "WriteHeader", "(", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "}", ")", "\n", "}" ]
// TokenGenerator returns a handler that will read a username and password from // a request form, create a jwt token if they are valid, and store the signed // token in the request context for later consumption. // // If handler h is nil, the generated token will be written verbatim in the // response.
[ "TokenGenerator", "returns", "a", "handler", "that", "will", "read", "a", "username", "and", "password", "from", "a", "request", "form", "create", "a", "jwt", "token", "if", "they", "are", "valid", "and", "store", "the", "signed", "token", "in", "the", "request", "context", "for", "later", "consumption", ".", "If", "handler", "h", "is", "nil", "the", "generated", "token", "will", "be", "written", "verbatim", "in", "the", "response", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L141-L198
test
urandom/handler
auth/jwt.go
Token
func Token(r *http.Request) string { if token, ok := r.Context().Value(TokenKey).(string); ok { return token } return "" }
go
func Token(r *http.Request) string { if token, ok := r.Context().Value(TokenKey).(string); ok { return token } return "" }
[ "func", "Token", "(", "r", "*", "http", ".", "Request", ")", "string", "{", "if", "token", ",", "ok", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "TokenKey", ")", ".", "(", "string", ")", ";", "ok", "{", "return", "token", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// Token returns the token string stored in the request context, or an empty // string.
[ "Token", "returns", "the", "token", "string", "stored", "in", "the", "request", "context", "or", "an", "empty", "string", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L328-L334
test
urandom/handler
auth/jwt.go
Claims
func Claims(r *http.Request) jwt.Claims { if claims, ok := r.Context().Value(ClaimsKey).(jwt.Claims); ok { return claims } return nil }
go
func Claims(r *http.Request) jwt.Claims { if claims, ok := r.Context().Value(ClaimsKey).(jwt.Claims); ok { return claims } return nil }
[ "func", "Claims", "(", "r", "*", "http", ".", "Request", ")", "jwt", ".", "Claims", "{", "if", "claims", ",", "ok", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "ClaimsKey", ")", ".", "(", "jwt", ".", "Claims", ")", ";", "ok", "{", "return", "claims", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Claims returns the claims stored in the request
[ "Claims", "returns", "the", "claims", "stored", "in", "the", "request" ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/auth/jwt.go#L337-L343
test
blacklabeldata/namedtuple
schema/lexer.go
String
func (t Token) String() string { switch t.Type { case TokenEOF: return "EOF" case TokenError: return t.Value } if len(t.Value) > 10 { return fmt.Sprintf("%.25q...", t.Value) } return fmt.Sprintf("%q", t.Value) }
go
func (t Token) String() string { switch t.Type { case TokenEOF: return "EOF" case TokenError: return t.Value } if len(t.Value) > 10 { return fmt.Sprintf("%.25q...", t.Value) } return fmt.Sprintf("%q", t.Value) }
[ "func", "(", "t", "Token", ")", "String", "(", ")", "string", "{", "switch", "t", ".", "Type", "{", "case", "TokenEOF", ":", "return", "\"EOF\"", "\n", "case", "TokenError", ":", "return", "t", ".", "Value", "\n", "}", "\n", "if", "len", "(", "t", ".", "Value", ")", ">", "10", "{", "return", "fmt", ".", "Sprintf", "(", "\"%.25q...\"", ",", "t", ".", "Value", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%q\"", ",", "t", ".", "Value", ")", "\n", "}" ]
// Used to print tokens
[ "Used", "to", "print", "tokens" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L79-L90
test
blacklabeldata/namedtuple
schema/lexer.go
NewLexer
func NewLexer(name, input string, h Handler) *Lexer { return &Lexer{ Name: name, input: input + "\n", state: lexText, handler: h, } }
go
func NewLexer(name, input string, h Handler) *Lexer { return &Lexer{ Name: name, input: input + "\n", state: lexText, handler: h, } }
[ "func", "NewLexer", "(", "name", ",", "input", "string", ",", "h", "Handler", ")", "*", "Lexer", "{", "return", "&", "Lexer", "{", "Name", ":", "name", ",", "input", ":", "input", "+", "\"\\n\"", ",", "\\n", ",", "state", ":", "lexText", ",", "}", "\n", "}" ]
// NewLexer creates a new scanner from the input
[ "NewLexer", "creates", "a", "new", "scanner", "from", "the", "input" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L100-L107
test
blacklabeldata/namedtuple
schema/lexer.go
run
func (l *Lexer) run() { for state := lexText; state != nil; { state = state(l) } }
go
func (l *Lexer) run() { for state := lexText; state != nil; { state = state(l) } }
[ "func", "(", "l", "*", "Lexer", ")", "run", "(", ")", "{", "for", "state", ":=", "lexText", ";", "state", "!=", "nil", ";", "{", "state", "=", "state", "(", "l", ")", "\n", "}", "\n", "}" ]
// Run lexes the input by executing state functions // until the state is nil
[ "Run", "lexes", "the", "input", "by", "executing", "state", "functions", "until", "the", "state", "is", "nil" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L122-L126
test
blacklabeldata/namedtuple
schema/lexer.go
emit
func (l *Lexer) emit(t TokenType) { // if the position is the same as the start, do not emit a token if l.Pos == l.Start { return } tok := Token{t, l.input[l.Start:l.Pos]} l.handler(tok) l.Start = l.Pos }
go
func (l *Lexer) emit(t TokenType) { // if the position is the same as the start, do not emit a token if l.Pos == l.Start { return } tok := Token{t, l.input[l.Start:l.Pos]} l.handler(tok) l.Start = l.Pos }
[ "func", "(", "l", "*", "Lexer", ")", "emit", "(", "t", "TokenType", ")", "{", "if", "l", ".", "Pos", "==", "l", ".", "Start", "{", "return", "\n", "}", "\n", "tok", ":=", "Token", "{", "t", ",", "l", ".", "input", "[", "l", ".", "Start", ":", "l", ".", "Pos", "]", "}", "\n", "l", ".", "handler", "(", "tok", ")", "\n", "l", ".", "Start", "=", "l", ".", "Pos", "\n", "}" ]
// emit passes an item pack to the client
[ "emit", "passes", "an", "item", "pack", "to", "the", "client" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L129-L139
test
blacklabeldata/namedtuple
schema/lexer.go
skipWhitespace
func (l *Lexer) skipWhitespace() { for unicode.Is(unicode.White_Space, l.next()) { } l.backup() l.ignore() }
go
func (l *Lexer) skipWhitespace() { for unicode.Is(unicode.White_Space, l.next()) { } l.backup() l.ignore() }
[ "func", "(", "l", "*", "Lexer", ")", "skipWhitespace", "(", ")", "{", "for", "unicode", ".", "Is", "(", "unicode", ".", "White_Space", ",", "l", ".", "next", "(", ")", ")", "{", "}", "\n", "l", ".", "backup", "(", ")", "\n", "l", ".", "ignore", "(", ")", "\n", "}" ]
// skipWhitespace ignores all whitespace characters
[ "skipWhitespace", "ignores", "all", "whitespace", "characters" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L153-L158
test
blacklabeldata/namedtuple
schema/lexer.go
next
func (l *Lexer) next() (r rune) { if l.Pos >= len(l.input) { l.Width = 0 return eof } r, l.Width = utf8.DecodeRuneInString(l.remaining()) l.advance(l.Width) return }
go
func (l *Lexer) next() (r rune) { if l.Pos >= len(l.input) { l.Width = 0 return eof } r, l.Width = utf8.DecodeRuneInString(l.remaining()) l.advance(l.Width) return }
[ "func", "(", "l", "*", "Lexer", ")", "next", "(", ")", "(", "r", "rune", ")", "{", "if", "l", ".", "Pos", ">=", "len", "(", "l", ".", "input", ")", "{", "l", ".", "Width", "=", "0", "\n", "return", "eof", "\n", "}", "\n", "r", ",", "l", ".", "Width", "=", "utf8", ".", "DecodeRuneInString", "(", "l", ".", "remaining", "(", ")", ")", "\n", "l", ".", "advance", "(", "l", ".", "Width", ")", "\n", "return", "\n", "}" ]
// next advances the lexer position and returns the next rune. If the input // does not have any more runes, an `eof` is returned.
[ "next", "advances", "the", "lexer", "position", "and", "returns", "the", "next", "rune", ".", "If", "the", "input", "does", "not", "have", "any", "more", "runes", "an", "eof", "is", "returned", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L162-L170
test
blacklabeldata/namedtuple
schema/lexer.go
LineNum
func (l *Lexer) LineNum() int { return strings.Count(l.input[:l.Pos], "\n") }
go
func (l *Lexer) LineNum() int { return strings.Count(l.input[:l.Pos], "\n") }
[ "func", "(", "l", "*", "Lexer", ")", "LineNum", "(", ")", "int", "{", "return", "strings", ".", "Count", "(", "l", ".", "input", "[", ":", "l", ".", "Pos", "]", ",", "\"\\n\"", ")", "\n", "}" ]
// LineNum returns the current line based on the data processed so far
[ "LineNum", "returns", "the", "current", "line", "based", "on", "the", "data", "processed", "so", "far" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L206-L208
test
blacklabeldata/namedtuple
schema/lexer.go
Offset
func (l *Lexer) Offset() int { // find last line break lineoffset := strings.LastIndex(l.input[:l.Pos], "\n") if lineoffset != -1 { // calculate current offset from last line break return l.Pos - lineoffset } // first line return l.Pos }
go
func (l *Lexer) Offset() int { // find last line break lineoffset := strings.LastIndex(l.input[:l.Pos], "\n") if lineoffset != -1 { // calculate current offset from last line break return l.Pos - lineoffset } // first line return l.Pos }
[ "func", "(", "l", "*", "Lexer", ")", "Offset", "(", ")", "int", "{", "lineoffset", ":=", "strings", ".", "LastIndex", "(", "l", ".", "input", "[", ":", "l", ".", "Pos", "]", ",", "\"\\n\"", ")", "\n", "\\n", "\n", "if", "lineoffset", "!=", "-", "1", "{", "return", "l", ".", "Pos", "-", "lineoffset", "\n", "}", "\n", "}" ]
// Offset determines the character offset from the beginning of the current line
[ "Offset", "determines", "the", "character", "offset", "from", "the", "beginning", "of", "the", "current", "line" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L211-L223
test
blacklabeldata/namedtuple
schema/lexer.go
errorf
func (l *Lexer) errorf(format string, args ...interface{}) stateFn { l.handler(Token{TokenError, fmt.Sprintf(fmt.Sprintf("%s[%d:%d] ", l.Name, l.LineNum(), l.Offset())+format, args...)}) return nil }
go
func (l *Lexer) errorf(format string, args ...interface{}) stateFn { l.handler(Token{TokenError, fmt.Sprintf(fmt.Sprintf("%s[%d:%d] ", l.Name, l.LineNum(), l.Offset())+format, args...)}) return nil }
[ "func", "(", "l", "*", "Lexer", ")", "errorf", "(", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "stateFn", "{", "l", ".", "handler", "(", "Token", "{", "TokenError", ",", "fmt", ".", "Sprintf", "(", "fmt", ".", "Sprintf", "(", "\"%s[%d:%d] \"", ",", "l", ".", "Name", ",", "l", ".", "LineNum", "(", ")", ",", "l", ".", "Offset", "(", ")", ")", "+", "format", ",", "args", "...", ")", "}", ")", "\n", "return", "nil", "\n", "}" ]
// errorf returns an error token and terminates the scan // by passing back a nil pointer that will be the next // state thus terminating the lexer
[ "errorf", "returns", "an", "error", "token", "and", "terminates", "the", "scan", "by", "passing", "back", "a", "nil", "pointer", "that", "will", "be", "the", "next", "state", "thus", "terminating", "the", "lexer" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L228-L231
test
blacklabeldata/namedtuple
schema/lexer.go
lexText
func lexText(l *Lexer) stateFn { OUTER: for { l.skipWhitespace() remaining := l.remaining() if strings.HasPrefix(remaining, comment) { // Start comment // state function which lexes a comment return lexComment } else if strings.HasPrefix(remaining, pkg) { // Start package decl // state function which lexes a package decl return lexPackage } else if strings.HasPrefix(remaining, from) { // Start from decl // state function which lexes a from decl return lexFrom } else if strings.HasPrefix(remaining, typeDef) { // Start type def // state function which lexes a type return lexTypeDef } else if strings.HasPrefix(remaining, version) { // Start version // state function which lexes a version return lexVersion } else if strings.HasPrefix(remaining, required) { // Start required field // state function which lexes a field l.Pos += len(required) l.emit(TokenRequired) l.skipWhitespace() return lexType } else if strings.HasPrefix(remaining, optional) { // Start optional field // state function which lexes a field l.Pos += len(optional) l.emit(TokenOptional) l.skipWhitespace() return lexType } else if strings.HasPrefix(remaining, openScope) { // Open scope l.Pos += len(openScope) l.emit(TokenOpenCurlyBracket) } else if strings.HasPrefix(remaining, closeScope) { // Close scope l.Pos += len(closeScope) l.emit(TokenCloseCurlyBracket) } else { switch r := l.next(); { case r == eof: // reached EOF? l.emit(TokenEOF) break OUTER default: l.errorf("unknown token: %#v", string(r)) } } } // Stops the run loop return nil }
go
func lexText(l *Lexer) stateFn { OUTER: for { l.skipWhitespace() remaining := l.remaining() if strings.HasPrefix(remaining, comment) { // Start comment // state function which lexes a comment return lexComment } else if strings.HasPrefix(remaining, pkg) { // Start package decl // state function which lexes a package decl return lexPackage } else if strings.HasPrefix(remaining, from) { // Start from decl // state function which lexes a from decl return lexFrom } else if strings.HasPrefix(remaining, typeDef) { // Start type def // state function which lexes a type return lexTypeDef } else if strings.HasPrefix(remaining, version) { // Start version // state function which lexes a version return lexVersion } else if strings.HasPrefix(remaining, required) { // Start required field // state function which lexes a field l.Pos += len(required) l.emit(TokenRequired) l.skipWhitespace() return lexType } else if strings.HasPrefix(remaining, optional) { // Start optional field // state function which lexes a field l.Pos += len(optional) l.emit(TokenOptional) l.skipWhitespace() return lexType } else if strings.HasPrefix(remaining, openScope) { // Open scope l.Pos += len(openScope) l.emit(TokenOpenCurlyBracket) } else if strings.HasPrefix(remaining, closeScope) { // Close scope l.Pos += len(closeScope) l.emit(TokenCloseCurlyBracket) } else { switch r := l.next(); { case r == eof: // reached EOF? l.emit(TokenEOF) break OUTER default: l.errorf("unknown token: %#v", string(r)) } } } // Stops the run loop return nil }
[ "func", "lexText", "(", "l", "*", "Lexer", ")", "stateFn", "{", "OUTER", ":", "for", "{", "l", ".", "skipWhitespace", "(", ")", "\n", "remaining", ":=", "l", ".", "remaining", "(", ")", "\n", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "comment", ")", "{", "return", "lexComment", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "pkg", ")", "{", "return", "lexPackage", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "from", ")", "{", "return", "lexFrom", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "typeDef", ")", "{", "return", "lexTypeDef", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "version", ")", "{", "return", "lexVersion", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "required", ")", "{", "l", ".", "Pos", "+=", "len", "(", "required", ")", "\n", "l", ".", "emit", "(", "TokenRequired", ")", "\n", "l", ".", "skipWhitespace", "(", ")", "\n", "return", "lexType", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "optional", ")", "{", "l", ".", "Pos", "+=", "len", "(", "optional", ")", "\n", "l", ".", "emit", "(", "TokenOptional", ")", "\n", "l", ".", "skipWhitespace", "(", ")", "\n", "return", "lexType", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "openScope", ")", "{", "l", ".", "Pos", "+=", "len", "(", "openScope", ")", "\n", "l", ".", "emit", "(", "TokenOpenCurlyBracket", ")", "\n", "}", "else", "if", "strings", ".", "HasPrefix", "(", "remaining", ",", "closeScope", ")", "{", "l", ".", "Pos", "+=", "len", "(", "closeScope", ")", "\n", "l", ".", "emit", "(", "TokenCloseCurlyBracket", ")", "\n", "}", "else", "{", "switch", "r", ":=", "l", ".", "next", "(", ")", ";", "{", "case", "r", "==", "eof", ":", "l", ".", "emit", "(", "TokenEOF", ")", "\n", "break", "OUTER", "\n", "default", ":", "l", ".", "errorf", "(", "\"unknown token: %#v\"", ",", "string", "(", "r", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Main lexer loop
[ "Main", "lexer", "loop" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L234-L288
test
blacklabeldata/namedtuple
schema/lexer.go
lexComment
func lexComment(l *Lexer) stateFn { l.skipWhitespace() // if strings.HasPrefix(l.remaining(), comment) { // skip comment // l.Pos += len(comment) // find next new line and add location to pos which // advances the scanner if index := strings.Index(l.remaining(), "\n"); index > 0 { l.Pos += index } else { l.Pos += len(l.remaining()) // l.emit(TokenComment) // break } // emit the comment string l.emit(TokenComment) l.skipWhitespace() // } // continue on scanner return lexText }
go
func lexComment(l *Lexer) stateFn { l.skipWhitespace() // if strings.HasPrefix(l.remaining(), comment) { // skip comment // l.Pos += len(comment) // find next new line and add location to pos which // advances the scanner if index := strings.Index(l.remaining(), "\n"); index > 0 { l.Pos += index } else { l.Pos += len(l.remaining()) // l.emit(TokenComment) // break } // emit the comment string l.emit(TokenComment) l.skipWhitespace() // } // continue on scanner return lexText }
[ "func", "lexComment", "(", "l", "*", "Lexer", ")", "stateFn", "{", "l", ".", "skipWhitespace", "(", ")", "\n", "l", ".", "Pos", "+=", "len", "(", "comment", ")", "\n", "if", "index", ":=", "strings", ".", "Index", "(", "l", ".", "remaining", "(", ")", ",", "\"\\n\"", ")", ";", "\\n", "index", ">", "0", "else", "{", "l", ".", "Pos", "+=", "index", "\n", "}", "\n", "{", "l", ".", "Pos", "+=", "len", "(", "l", ".", "remaining", "(", ")", ")", "\n", "}", "\n", "l", ".", "emit", "(", "TokenComment", ")", "\n", "l", ".", "skipWhitespace", "(", ")", "\n", "}" ]
// Lexes a comment line
[ "Lexes", "a", "comment", "line" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/lexer.go#L291-L316
test
blacklabeldata/namedtuple
types.go
New
func New(namespace string, name string) (t TupleType) { hash := syncHash.Hash([]byte(name)) ns_hash := syncHash.Hash([]byte(namespace)) t = TupleType{namespace, name, ns_hash, hash, make([][]Field, 0), make(map[string]int)} return }
go
func New(namespace string, name string) (t TupleType) { hash := syncHash.Hash([]byte(name)) ns_hash := syncHash.Hash([]byte(namespace)) t = TupleType{namespace, name, ns_hash, hash, make([][]Field, 0), make(map[string]int)} return }
[ "func", "New", "(", "namespace", "string", ",", "name", "string", ")", "(", "t", "TupleType", ")", "{", "hash", ":=", "syncHash", ".", "Hash", "(", "[", "]", "byte", "(", "name", ")", ")", "\n", "ns_hash", ":=", "syncHash", ".", "Hash", "(", "[", "]", "byte", "(", "namespace", ")", ")", "\n", "t", "=", "TupleType", "{", "namespace", ",", "name", ",", "ns_hash", ",", "hash", ",", "make", "(", "[", "]", "[", "]", "Field", ",", "0", ")", ",", "make", "(", "map", "[", "string", "]", "int", ")", "}", "\n", "return", "\n", "}" ]
// New creates a new TupleType with the given namespace and type name
[ "New", "creates", "a", "new", "TupleType", "with", "the", "given", "namespace", "and", "type", "name" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/types.go#L31-L36
test
blacklabeldata/namedtuple
types.go
AddVersion
func (t *TupleType) AddVersion(fields ...Field) { t.versions = append(t.versions, fields) for _, field := range fields { t.fields[field.Name] = len(t.fields) } }
go
func (t *TupleType) AddVersion(fields ...Field) { t.versions = append(t.versions, fields) for _, field := range fields { t.fields[field.Name] = len(t.fields) } }
[ "func", "(", "t", "*", "TupleType", ")", "AddVersion", "(", "fields", "...", "Field", ")", "{", "t", ".", "versions", "=", "append", "(", "t", ".", "versions", ",", "fields", ")", "\n", "for", "_", ",", "field", ":=", "range", "fields", "{", "t", ".", "fields", "[", "field", ".", "Name", "]", "=", "len", "(", "t", ".", "fields", ")", "\n", "}", "\n", "}" ]
// AddVersion adds a version to the tuple type
[ "AddVersion", "adds", "a", "version", "to", "the", "tuple", "type" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/types.go#L39-L44
test
blacklabeldata/namedtuple
types.go
Contains
func (t *TupleType) Contains(field string) bool { _, exists := t.fields[field] return exists }
go
func (t *TupleType) Contains(field string) bool { _, exists := t.fields[field] return exists }
[ "func", "(", "t", "*", "TupleType", ")", "Contains", "(", "field", "string", ")", "bool", "{", "_", ",", "exists", ":=", "t", ".", "fields", "[", "field", "]", "\n", "return", "exists", "\n", "}" ]
// Contains determines is a field exists in the TupleType
[ "Contains", "determines", "is", "a", "field", "exists", "in", "the", "TupleType" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/types.go#L47-L50
test
blacklabeldata/namedtuple
types.go
Offset
func (t *TupleType) Offset(field string) (offset int, exists bool) { offset, exists = t.fields[field] return }
go
func (t *TupleType) Offset(field string) (offset int, exists bool) { offset, exists = t.fields[field] return }
[ "func", "(", "t", "*", "TupleType", ")", "Offset", "(", "field", "string", ")", "(", "offset", "int", ",", "exists", "bool", ")", "{", "offset", ",", "exists", "=", "t", ".", "fields", "[", "field", "]", "\n", "return", "\n", "}" ]
// Offset determines the numerical offset for the given field
[ "Offset", "determines", "the", "numerical", "offset", "for", "the", "given", "field" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/types.go#L53-L56
test
blacklabeldata/namedtuple
types.go
Versions
func (t *TupleType) Versions() (vers []Version) { vers = make([]Version, t.NumVersions()) for i := 0; i < t.NumVersions(); i++ { vers[i] = Version{uint8(i + 1), t.versions[i]} } return }
go
func (t *TupleType) Versions() (vers []Version) { vers = make([]Version, t.NumVersions()) for i := 0; i < t.NumVersions(); i++ { vers[i] = Version{uint8(i + 1), t.versions[i]} } return }
[ "func", "(", "t", "*", "TupleType", ")", "Versions", "(", ")", "(", "vers", "[", "]", "Version", ")", "{", "vers", "=", "make", "(", "[", "]", "Version", ",", "t", ".", "NumVersions", "(", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "t", ".", "NumVersions", "(", ")", ";", "i", "++", "{", "vers", "[", "i", "]", "=", "Version", "{", "uint8", "(", "i", "+", "1", ")", ",", "t", ".", "versions", "[", "i", "]", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Versions returns an array of versions contained in this type
[ "Versions", "returns", "an", "array", "of", "versions", "contained", "in", "this", "type" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/types.go#L64-L70
test
pivotal-pez/pezdispenser
taskmanager/task.go
SetPrivateMeta
func (s *Task) SetPrivateMeta(name string, value interface{}) { if s.PrivateMetaData == nil { s.PrivateMetaData = make(map[string]interface{}) } s.PrivateMetaData[name] = value }
go
func (s *Task) SetPrivateMeta(name string, value interface{}) { if s.PrivateMetaData == nil { s.PrivateMetaData = make(map[string]interface{}) } s.PrivateMetaData[name] = value }
[ "func", "(", "s", "*", "Task", ")", "SetPrivateMeta", "(", "name", "string", ",", "value", "interface", "{", "}", ")", "{", "if", "s", ".", "PrivateMetaData", "==", "nil", "{", "s", ".", "PrivateMetaData", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "s", ".", "PrivateMetaData", "[", "name", "]", "=", "value", "\n", "}" ]
//SetPrivateMeta - set a private meta data record
[ "SetPrivateMeta", "-", "set", "a", "private", "meta", "data", "record" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/taskmanager/task.go#L9-L15
test
pivotal-pez/pezdispenser
taskmanager/task.go
SetPublicMeta
func (s *Task) SetPublicMeta(name string, value interface{}) { if s.MetaData == nil { s.MetaData = make(map[string]interface{}) } s.MetaData[name] = value }
go
func (s *Task) SetPublicMeta(name string, value interface{}) { if s.MetaData == nil { s.MetaData = make(map[string]interface{}) } s.MetaData[name] = value }
[ "func", "(", "s", "*", "Task", ")", "SetPublicMeta", "(", "name", "string", ",", "value", "interface", "{", "}", ")", "{", "if", "s", ".", "MetaData", "==", "nil", "{", "s", ".", "MetaData", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "s", ".", "MetaData", "[", "name", "]", "=", "value", "\n", "}" ]
//SetPublicMeta - set a public metadata record
[ "SetPublicMeta", "-", "set", "a", "public", "metadata", "record" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/taskmanager/task.go#L18-L23
test
pivotal-pez/pezdispenser
taskmanager/task.go
GetRedactedVersion
func (s *Task) GetRedactedVersion() RedactedTask { s.mutex.RLock() rt := RedactedTask{ ID: s.ID, Timestamp: s.Timestamp, Expires: s.Expires, Status: s.Status, Profile: s.Profile, CallerName: s.CallerName, MetaData: s.MetaData, } s.mutex.RUnlock() return rt }
go
func (s *Task) GetRedactedVersion() RedactedTask { s.mutex.RLock() rt := RedactedTask{ ID: s.ID, Timestamp: s.Timestamp, Expires: s.Expires, Status: s.Status, Profile: s.Profile, CallerName: s.CallerName, MetaData: s.MetaData, } s.mutex.RUnlock() return rt }
[ "func", "(", "s", "*", "Task", ")", "GetRedactedVersion", "(", ")", "RedactedTask", "{", "s", ".", "mutex", ".", "RLock", "(", ")", "\n", "rt", ":=", "RedactedTask", "{", "ID", ":", "s", ".", "ID", ",", "Timestamp", ":", "s", ".", "Timestamp", ",", "Expires", ":", "s", ".", "Expires", ",", "Status", ":", "s", ".", "Status", ",", "Profile", ":", "s", ".", "Profile", ",", "CallerName", ":", "s", ".", "CallerName", ",", "MetaData", ":", "s", ".", "MetaData", ",", "}", "\n", "s", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "rt", "\n", "}" ]
//GetRedactedVersion - returns a redacted version of this task, removing private info
[ "GetRedactedVersion", "-", "returns", "a", "redacted", "version", "of", "this", "task", "removing", "private", "info" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/taskmanager/task.go#L36-L49
test
pivotal-pez/pezdispenser
taskmanager/task.go
Equal
func (s Task) Equal(b Task) bool { return (s.ID == b.ID && s.Timestamp == b.Timestamp && s.Expires == b.Expires && s.Status == b.Status && s.Profile == b.Profile && s.CallerName == b.CallerName) }
go
func (s Task) Equal(b Task) bool { return (s.ID == b.ID && s.Timestamp == b.Timestamp && s.Expires == b.Expires && s.Status == b.Status && s.Profile == b.Profile && s.CallerName == b.CallerName) }
[ "func", "(", "s", "Task", ")", "Equal", "(", "b", "Task", ")", "bool", "{", "return", "(", "s", ".", "ID", "==", "b", ".", "ID", "&&", "s", ".", "Timestamp", "==", "b", ".", "Timestamp", "&&", "s", ".", "Expires", "==", "b", ".", "Expires", "&&", "s", ".", "Status", "==", "b", ".", "Status", "&&", "s", ".", "Profile", "==", "b", ".", "Profile", "&&", "s", ".", "CallerName", "==", "b", ".", "CallerName", ")", "\n", "}" ]
// Equal - define task equality
[ "Equal", "-", "define", "task", "equality" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/taskmanager/task.go#L75-L82
test
urandom/handler
method/verb.go
HTTP
func HTTP(h http.Handler, verb Verb, verbs ...Verb) http.Handler { verbSet := map[Verb]struct{}{verb: struct{}{}} for _, v := range verbs { verbSet[v] = struct{}{} } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if _, ok := verbSet[Verb(r.Method)]; ok { h.ServeHTTP(w, r) } else { w.WriteHeader(http.StatusBadRequest) } }) }
go
func HTTP(h http.Handler, verb Verb, verbs ...Verb) http.Handler { verbSet := map[Verb]struct{}{verb: struct{}{}} for _, v := range verbs { verbSet[v] = struct{}{} } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if _, ok := verbSet[Verb(r.Method)]; ok { h.ServeHTTP(w, r) } else { w.WriteHeader(http.StatusBadRequest) } }) }
[ "func", "HTTP", "(", "h", "http", ".", "Handler", ",", "verb", "Verb", ",", "verbs", "...", "Verb", ")", "http", ".", "Handler", "{", "verbSet", ":=", "map", "[", "Verb", "]", "struct", "{", "}", "{", "verb", ":", "struct", "{", "}", "{", "}", "}", "\n", "for", "_", ",", "v", ":=", "range", "verbs", "{", "verbSet", "[", "v", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "_", ",", "ok", ":=", "verbSet", "[", "Verb", "(", "r", ".", "Method", ")", "]", ";", "ok", "{", "h", ".", "ServeHTTP", "(", "w", ",", "r", ")", "\n", "}", "else", "{", "w", ".", "WriteHeader", "(", "http", ".", "StatusBadRequest", ")", "\n", "}", "\n", "}", ")", "\n", "}" ]
// HTTP returns a handler that will check each request's method against a // predefined whitelist. If the request's method is not part of the list, // the response will be a 400 Bad Request.
[ "HTTP", "returns", "a", "handler", "that", "will", "check", "each", "request", "s", "method", "against", "a", "predefined", "whitelist", ".", "If", "the", "request", "s", "method", "is", "not", "part", "of", "the", "list", "the", "response", "will", "be", "a", "400", "Bad", "Request", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/method/verb.go#L19-L32
test
blacklabeldata/namedtuple
integers.go
PutUint8
func (b *TupleBuilder) PutUint8(field string, value uint8) (wrote uint64, err error) { // field type should be a Uint8Field if err = b.typeCheck(field, Uint8Field); err != nil { return 0, err } // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedInt8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil }
go
func (b *TupleBuilder) PutUint8(field string, value uint8) (wrote uint64, err error) { // field type should be a Uint8Field if err = b.typeCheck(field, Uint8Field); err != nil { return 0, err } // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedInt8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutUint8", "(", "field", "string", ",", "value", "uint8", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Uint8Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedInt8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}" ]
// PutUint8 sets an 8-bit unsigned value for the given string name. The field name must be a Uint8Field otherwise an error will be returned. If the type buffer no longer has enough space to write this value an xbinary.ErrOutOfRange error will be returned. Upon success 2 bytes should be written into the buffer and the returned error should be nil. The type code is written first then the byte value.
[ "PutUint8", "sets", "an", "8", "-", "bit", "unsigned", "value", "for", "the", "given", "string", "name", ".", "The", "field", "name", "must", "be", "a", "Uint8Field", "otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "this", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "2", "bytes", "should", "be", "written", "into", "the", "buffer", "and", "the", "returned", "error", "should", "be", "nil", ".", "The", "type", "code", "is", "written", "first", "then", "the", "byte", "value", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L10-L35
test
blacklabeldata/namedtuple
integers.go
PutInt8
func (b *TupleBuilder) PutInt8(field string, value int8) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int8Field); err != nil { return 0, err } // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Int8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil }
go
func (b *TupleBuilder) PutInt8(field string, value int8) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int8Field); err != nil { return 0, err } // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Int8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutInt8", "(", "field", "string", ",", "value", "int8", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Int8Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Int8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}" ]
// PutInt8 sets an 8-bit signed value for the given string name. The field name must be an Int8Field otherwise an error will be returned. If the type buffer no longer has enough space to write this value, an xbinary.ErrOutOfRange error will be returned. Upon success, 2 bytes should be written into the buffer and the returned error should be nil. The type code is written first then the byte value.
[ "PutInt8", "sets", "an", "8", "-", "bit", "signed", "value", "for", "the", "given", "string", "name", ".", "The", "field", "name", "must", "be", "an", "Int8Field", "otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "this", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "2", "bytes", "should", "be", "written", "into", "the", "buffer", "and", "the", "returned", "error", "should", "be", "nil", ".", "The", "type", "code", "is", "written", "first", "then", "the", "byte", "value", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L38-L63
test
blacklabeldata/namedtuple
integers.go
PutUint16
func (b *TupleBuilder) PutUint16(field string, value uint16) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Uint16Field); err != nil { return 0, err } if value < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedShort8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedShort16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil }
go
func (b *TupleBuilder) PutUint16(field string, value uint16) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Uint16Field); err != nil { return 0, err } if value < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedShort8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedShort16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutUint16", "(", "field", "string", ",", "value", "uint16", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Uint16Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "value", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedShort8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}", "\n", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutUint16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedShort16Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "3", "\n", "return", "3", ",", "nil", "\n", "}" ]
// PutUint16 sets a 16-bit unsigned value for the given field name.The field name must be a Uint16Field otherwise an error will be returned. If the type buffer no longer has enough space to write the value, an xbinary.ErrOutOfRange error will be returned. Upon success, the number of bytes written as well as a nil error will be returned. The type code will be writtn first. If the value is `< math.MaxUint8`, only 1 byte will be written. Otherwise, the entire 16-bit value will be written.
[ "PutUint16", "sets", "a", "16", "-", "bit", "unsigned", "value", "for", "the", "given", "field", "name", ".", "The", "field", "name", "must", "be", "a", "Uint16Field", "otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "the", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "the", "number", "of", "bytes", "written", "as", "well", "as", "a", "nil", "error", "will", "be", "returned", ".", "The", "type", "code", "will", "be", "writtn", "first", ".", "If", "the", "value", "is", "<", "math", ".", "MaxUint8", "only", "1", "byte", "will", "be", "written", ".", "Otherwise", "the", "entire", "16", "-", "bit", "value", "will", "be", "written", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L66-L114
test
blacklabeldata/namedtuple
integers.go
PutInt16
func (b *TupleBuilder) PutInt16(field string, value int16) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int16Field); err != nil { return 0, err } if uint16(value) < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Short8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt16(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Short16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil }
go
func (b *TupleBuilder) PutInt16(field string, value int16) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int16Field); err != nil { return 0, err } if uint16(value) < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Short8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt16(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Short16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutInt16", "(", "field", "string", ",", "value", "int16", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Int16Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "uint16", "(", "value", ")", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Short8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}", "\n", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutInt16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Short16Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "3", "\n", "return", "3", ",", "nil", "\n", "}" ]
// PutInt16 sets a 16-bit signed value for the given field name.The field name must be an Int16Field; otherwise, an error will be returned. If the type buffer no longer has enough space to write the value, an xbinary.ErrOutOfRange error will be returned. Upon success, the number of bytes written as well as a nil error will be returned. The type code will be written first. If the value is `< math.MaxUint8`, only 1 byte will be written. Otherwise, the entire 16-bit value will be written.
[ "PutInt16", "sets", "a", "16", "-", "bit", "signed", "value", "for", "the", "given", "field", "name", ".", "The", "field", "name", "must", "be", "an", "Int16Field", ";", "otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "the", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "the", "number", "of", "bytes", "written", "as", "well", "as", "a", "nil", "error", "will", "be", "returned", ".", "The", "type", "code", "will", "be", "written", "first", ".", "If", "the", "value", "is", "<", "math", ".", "MaxUint8", "only", "1", "byte", "will", "be", "written", ".", "Otherwise", "the", "entire", "16", "-", "bit", "value", "will", "be", "written", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L117-L165
test
blacklabeldata/namedtuple
integers.go
PutUint32
func (b *TupleBuilder) PutUint32(field string, value uint32) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Uint32Field); err != nil { return 0, err } if value < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedInt8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if value < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedInt16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedInt32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil }
go
func (b *TupleBuilder) PutUint32(field string, value uint32) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Uint32Field); err != nil { return 0, err } if value < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedInt8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if value < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedInt16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedInt32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutUint32", "(", "field", "string", ",", "value", "uint32", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Uint32Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "value", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedInt8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}", "else", "if", "value", "<", "math", ".", "MaxUint16", "{", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutUint16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint16", "(", "value", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedInt16Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "3", "\n", "return", "3", ",", "nil", "\n", "}", "\n", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutUint32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedInt32Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "5", "\n", "return", "5", ",", "nil", "\n", "}" ]
// PutUint32 sets a 32-bit unsigned value for the given field name. The field name must be a Uint32Field, otherwise, an error will be returned. If the type buffer no longer has enough space to write the value, an `xbinary.ErrOutOfRange` error will be returned. Upon success, the number of bytes written as well as a nil error will be returned. The type code will be written first. If the value is `< math.MaxUint8`, only 1 byte will be written. If the value is `< math.MaxUint16`, only 2 bytes will be written. Otherwise, the entire 32-bit value will be written.
[ "PutUint32", "sets", "a", "32", "-", "bit", "unsigned", "value", "for", "the", "given", "field", "name", ".", "The", "field", "name", "must", "be", "a", "Uint32Field", "otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "the", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "the", "number", "of", "bytes", "written", "as", "well", "as", "a", "nil", "error", "will", "be", "returned", ".", "The", "type", "code", "will", "be", "written", "first", ".", "If", "the", "value", "is", "<", "math", ".", "MaxUint8", "only", "1", "byte", "will", "be", "written", ".", "If", "the", "value", "is", "<", "math", ".", "MaxUint16", "only", "2", "bytes", "will", "be", "written", ".", "Otherwise", "the", "entire", "32", "-", "bit", "value", "will", "be", "written", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L168-L234
test
blacklabeldata/namedtuple
integers.go
PutInt32
func (b *TupleBuilder) PutInt32(field string, value int32) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int32Field); err != nil { return 0, err } unsigned := uint32(value) if unsigned < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Int8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if unsigned < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt16(b.buffer, b.pos+1, int16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Int16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt32(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Int32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil }
go
func (b *TupleBuilder) PutInt32(field string, value int32) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int32Field); err != nil { return 0, err } unsigned := uint32(value) if unsigned < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Int8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if unsigned < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt16(b.buffer, b.pos+1, int16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Int16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt32(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Int32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutInt32", "(", "field", "string", ",", "value", "int32", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Int32Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "unsigned", ":=", "uint32", "(", "value", ")", "\n", "if", "unsigned", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Int8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}", "else", "if", "unsigned", "<", "math", ".", "MaxUint16", "{", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutInt16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "int16", "(", "value", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Int16Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "3", "\n", "return", "3", ",", "nil", "\n", "}", "\n", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutInt32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Int32Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "5", "\n", "return", "5", ",", "nil", "\n", "}" ]
// PutInt32 sets a 32-bit signed value for the given field name. The field name must be a Int32Field. Otherwise, an error will be returned. If the type buffer no longer has enough space to write the value, an `xbinary.ErrOutOfRange` error will be returned. Upon success, the number of bytes written as well as a nil error will be returned. The type code will be written first. If the absolute value is `< math.MaxUint8`, only 1 byte will be written. If the absolute value is `< math.MaxUint16`, only 2 bytes will be written. Otherwise, the entire 32-bit value will be written.
[ "PutInt32", "sets", "a", "32", "-", "bit", "signed", "value", "for", "the", "given", "field", "name", ".", "The", "field", "name", "must", "be", "a", "Int32Field", ".", "Otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "the", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "the", "number", "of", "bytes", "written", "as", "well", "as", "a", "nil", "error", "will", "be", "returned", ".", "The", "type", "code", "will", "be", "written", "first", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint8", "only", "1", "byte", "will", "be", "written", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint16", "only", "2", "bytes", "will", "be", "written", ".", "Otherwise", "the", "entire", "32", "-", "bit", "value", "will", "be", "written", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L237-L305
test
blacklabeldata/namedtuple
integers.go
PutUint64
func (b *TupleBuilder) PutUint64(field string, value uint64) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Uint64Field); err != nil { return 0, err } if value < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedLong8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if value < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedLong16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } else if value < math.MaxUint32 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedLong32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedLong64Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 9 // wrote 9 bytes return 9, nil }
go
func (b *TupleBuilder) PutUint64(field string, value uint64) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Uint64Field); err != nil { return 0, err } if value < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(UnsignedLong8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if value < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedLong16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } else if value < math.MaxUint32 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedLong32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(UnsignedLong64Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 9 // wrote 9 bytes return 9, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutUint64", "(", "field", "string", ",", "value", "uint64", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Uint64Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "value", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedLong8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}", "else", "if", "value", "<", "math", ".", "MaxUint16", "{", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutUint16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint16", "(", "value", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedLong16Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "3", "\n", "return", "3", ",", "nil", "\n", "}", "else", "if", "value", "<", "math", ".", "MaxUint32", "{", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutUint32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint32", "(", "value", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedLong32Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "5", "\n", "return", "5", ",", "nil", "\n", "}", "\n", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutUint64", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "UnsignedLong64Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "9", "\n", "return", "9", ",", "nil", "\n", "}" ]
// PutUint64 sets a 64-bit unsigned integer for the given field name. The field name must be a Uint64Field. Otherwise, an error will be returned. If the type buffer no longer has enough space to write the value, an `xbinary.ErrOutOfRange` error will be returned. Upon success, the number of bytes written as well as a nil error will be returned. The type code will be written first. If the absolute value is `< math.MaxUint8`, only 1 byte will be written. If the absolute value is `< math.MaxUint16`, only 2 bytes will be written. If the absolute value is `< math.MaxUint32`, only 4 bytes will be written. Otherwise, the entire 64-bit value will be written.
[ "PutUint64", "sets", "a", "64", "-", "bit", "unsigned", "integer", "for", "the", "given", "field", "name", ".", "The", "field", "name", "must", "be", "a", "Uint64Field", ".", "Otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "the", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "the", "number", "of", "bytes", "written", "as", "well", "as", "a", "nil", "error", "will", "be", "returned", ".", "The", "type", "code", "will", "be", "written", "first", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint8", "only", "1", "byte", "will", "be", "written", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint16", "only", "2", "bytes", "will", "be", "written", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint32", "only", "4", "bytes", "will", "be", "written", ".", "Otherwise", "the", "entire", "64", "-", "bit", "value", "will", "be", "written", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L308-L395
test
blacklabeldata/namedtuple
integers.go
PutInt64
func (b *TupleBuilder) PutInt64(field string, value int64) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int64Field); err != nil { return 0, err } unsigned := uint64(value) if unsigned < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Long8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if unsigned < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt16(b.buffer, b.pos+1, int16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Long16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } else if unsigned < math.MaxUint32 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt32(b.buffer, b.pos+1, int32(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Long32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt64(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Long64Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 9 // wrote 9 bytes return 9, nil }
go
func (b *TupleBuilder) PutInt64(field string, value int64) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Int64Field); err != nil { return 0, err } unsigned := uint64(value) if unsigned < math.MaxUint8 { // minimum bytes is 2 (type code + value) if b.available() < 2 { return 0, xbinary.ErrOutOfRange } // write type code b.buffer[b.pos] = byte(Long8Code.OpCode) // write value b.buffer[b.pos+1] = byte(value) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 2 return 2, nil } else if unsigned < math.MaxUint16 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt16(b.buffer, b.pos+1, int16(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Long16Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 3 // wrote 3 bytes return 3, nil } else if unsigned < math.MaxUint32 { // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt32(b.buffer, b.pos+1, int32(value)) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Long32Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 // wrote 5 bytes return 5, nil } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutInt64(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(Long64Code.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 9 // wrote 9 bytes return 9, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutInt64", "(", "field", "string", ",", "value", "int64", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Int64Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "unsigned", ":=", "uint64", "(", "value", ")", "\n", "if", "unsigned", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Long8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "value", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "2", "\n", "return", "2", ",", "nil", "\n", "}", "else", "if", "unsigned", "<", "math", ".", "MaxUint16", "{", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutInt16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "int16", "(", "value", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Long16Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "3", "\n", "return", "3", ",", "nil", "\n", "}", "else", "if", "unsigned", "<", "math", ".", "MaxUint32", "{", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutInt32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "int32", "(", "value", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Long32Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "5", "\n", "return", "5", ",", "nil", "\n", "}", "\n", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutInt64", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "Long64Code", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "9", "\n", "return", "9", ",", "nil", "\n", "}" ]
// PutInt64 sets a 64-bit signed integer for the given field name. The field name must be a Int64Field. Otherwise, an error will be returned. If the type buffer no longer has enough space to write the value, an `xbinary.ErrOutOfRange` error will be returned. Upon success, the number of bytes written as well as a nil error will be returned. The type code will be written first. If the absolute value is `< math.MaxUint8`, only 1 byte will be written. If the absolute value is `< math.MaxUint16`, only 2 bytes will be written. If the absolute value is `< math.MaxUint32`, only 4 bytes will be written. Otherwise, the entire 64-bit value will be written.
[ "PutInt64", "sets", "a", "64", "-", "bit", "signed", "integer", "for", "the", "given", "field", "name", ".", "The", "field", "name", "must", "be", "a", "Int64Field", ".", "Otherwise", "an", "error", "will", "be", "returned", ".", "If", "the", "type", "buffer", "no", "longer", "has", "enough", "space", "to", "write", "the", "value", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "Upon", "success", "the", "number", "of", "bytes", "written", "as", "well", "as", "a", "nil", "error", "will", "be", "returned", ".", "The", "type", "code", "will", "be", "written", "first", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint8", "only", "1", "byte", "will", "be", "written", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint16", "only", "2", "bytes", "will", "be", "written", ".", "If", "the", "absolute", "value", "is", "<", "math", ".", "MaxUint32", "only", "4", "bytes", "will", "be", "written", ".", "Otherwise", "the", "entire", "64", "-", "bit", "value", "will", "be", "written", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/integers.go#L398-L486
test
blacklabeldata/namedtuple
schema/ast.go
NewPackageList
func NewPackageList() PackageList { var lock sync.Mutex return &packageList{make(map[string]Package), lock} }
go
func NewPackageList() PackageList { var lock sync.Mutex return &packageList{make(map[string]Package), lock} }
[ "func", "NewPackageList", "(", ")", "PackageList", "{", "var", "lock", "sync", ".", "Mutex", "\n", "return", "&", "packageList", "{", "make", "(", "map", "[", "string", "]", "Package", ")", ",", "lock", "}", "\n", "}" ]
// NewPackageList creates a new package registry
[ "NewPackageList", "creates", "a", "new", "package", "registry" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/ast.go#L40-L43
test
blacklabeldata/namedtuple
floats.go
PutFloat32
func (b *TupleBuilder) PutFloat32(field string, value float32) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Float32Field); err != nil { return 0, err } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutFloat32(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(FloatCode.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 return 5, nil }
go
func (b *TupleBuilder) PutFloat32(field string, value float32) (wrote uint64, err error) { // field type should be if err = b.typeCheck(field, Float32Field); err != nil { return 0, err } // write value // length check performed by xbinary wrote, err = xbinary.LittleEndian.PutFloat32(b.buffer, b.pos+1, value) if err != nil { return 0, err } // write type code b.buffer[b.pos] = byte(FloatCode.OpCode) // set field offset b.offsets[field] = b.pos // incr pos b.pos += 5 return 5, nil }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutFloat32", "(", "field", "string", ",", "value", "float32", ")", "(", "wrote", "uint64", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Float32Field", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "wrote", ",", "err", "=", "xbinary", ".", "LittleEndian", ".", "PutFloat32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "FloatCode", ".", "OpCode", ")", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "5", "\n", "return", "5", ",", "nil", "\n", "}" ]
// PutFloat32 writes a 32-bit float for the given string field. The field type must be `Float32Field`, otherwise an error is returned. The type code is written first then the value. Upon success, the number of bytes written is returned along with a nil error.
[ "PutFloat32", "writes", "a", "32", "-", "bit", "float", "for", "the", "given", "string", "field", ".", "The", "field", "type", "must", "be", "Float32Field", "otherwise", "an", "error", "is", "returned", ".", "The", "type", "code", "is", "written", "first", "then", "the", "value", ".", "Upon", "success", "the", "number", "of", "bytes", "written", "is", "returned", "along", "with", "a", "nil", "error", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/floats.go#L6-L30
test
insionng/martini
martini.go
Classic
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("static")) m.Use(ContextRender("", RenderOptions{ Extensions: []string{".html", ".tmpl", "tpl"}, })) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
go
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("static")) m.Use(ContextRender("", RenderOptions{ Extensions: []string{".html", ".tmpl", "tpl"}, })) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
[ "func", "Classic", "(", ")", "*", "ClassicMartini", "{", "r", ":=", "NewRouter", "(", ")", "\n", "m", ":=", "New", "(", ")", "\n", "m", ".", "Use", "(", "Logger", "(", ")", ")", "\n", "m", ".", "Use", "(", "Recovery", "(", ")", ")", "\n", "m", ".", "Use", "(", "Static", "(", "\"static\"", ")", ")", "\n", "m", ".", "Use", "(", "ContextRender", "(", "\"\"", ",", "RenderOptions", "{", "Extensions", ":", "[", "]", "string", "{", "\".html\"", ",", "\".tmpl\"", ",", "\"tpl\"", "}", ",", "}", ")", ")", "\n", "m", ".", "MapTo", "(", "r", ",", "(", "*", "Routes", ")", "(", "nil", ")", ")", "\n", "m", ".", "Action", "(", "r", ".", "Handle", ")", "\n", "return", "&", "ClassicMartini", "{", "m", ",", "r", "}", "\n", "}" ]
// Classic creates a classic Martini with some basic default middleware - martini.Logger, martini.Recovery and martini.Static. // Classic also maps martini.Routes as a service.
[ "Classic", "creates", "a", "classic", "Martini", "with", "some", "basic", "default", "middleware", "-", "martini", ".", "Logger", "martini", ".", "Recovery", "and", "martini", ".", "Static", ".", "Classic", "also", "maps", "martini", ".", "Routes", "as", "a", "service", "." ]
2d0ba5dc75fe9549c10e2f71927803a11e5e4957
https://github.com/insionng/martini/blob/2d0ba5dc75fe9549c10e2f71927803a11e5e4957/martini.go#L104-L116
test
urandom/handler
lang/i18n.go
Languages
func Languages(tags []xlang.Tag) Option { return Option{func(o *options) { o.languages = tags }} }
go
func Languages(tags []xlang.Tag) Option { return Option{func(o *options) { o.languages = tags }} }
[ "func", "Languages", "(", "tags", "[", "]", "xlang", ".", "Tag", ")", "Option", "{", "return", "Option", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "languages", "=", "tags", "\n", "}", "}", "\n", "}" ]
// Languages provides the handler with supported languages.
[ "Languages", "provides", "the", "handler", "with", "supported", "languages", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/lang/i18n.go#L28-L32
test
urandom/handler
lang/i18n.go
Session
func Session(s handler.Session) Option { return Option{func(o *options) { o.session = s }} }
go
func Session(s handler.Session) Option { return Option{func(o *options) { o.session = s }} }
[ "func", "Session", "(", "s", "handler", ".", "Session", ")", "Option", "{", "return", "Option", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "session", "=", "s", "\n", "}", "}", "\n", "}" ]
// Session will be used to set the current language.
[ "Session", "will", "be", "used", "to", "set", "the", "current", "language", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/lang/i18n.go#L35-L39
test
urandom/handler
lang/i18n.go
Data
func Data(r *http.Request) ContextValue { if v, ok := r.Context().Value(ContextKey).(ContextValue); ok { return v } return ContextValue{} }
go
func Data(r *http.Request) ContextValue { if v, ok := r.Context().Value(ContextKey).(ContextValue); ok { return v } return ContextValue{} }
[ "func", "Data", "(", "r", "*", "http", ".", "Request", ")", "ContextValue", "{", "if", "v", ",", "ok", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "ContextKey", ")", ".", "(", "ContextValue", ")", ";", "ok", "{", "return", "v", "\n", "}", "\n", "return", "ContextValue", "{", "}", "\n", "}" ]
//Data returns the language data stored in the request.
[ "Data", "returns", "the", "language", "data", "stored", "in", "the", "request", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/lang/i18n.go#L204-L210
test
urandom/handler
lang/i18n.go
URL
func URL(url, prefix string, data ContextValue) string { if data.Current.IsRoot() { return url } if prefix == "" { prefix = "/" } else if prefix[len(prefix)-1] != '/' { prefix += "/" } if url == "" { url = "/" } if url[0] != '/' { url = "/" + url } return prefix + data.Current.String() + url }
go
func URL(url, prefix string, data ContextValue) string { if data.Current.IsRoot() { return url } if prefix == "" { prefix = "/" } else if prefix[len(prefix)-1] != '/' { prefix += "/" } if url == "" { url = "/" } if url[0] != '/' { url = "/" + url } return prefix + data.Current.String() + url }
[ "func", "URL", "(", "url", ",", "prefix", "string", ",", "data", "ContextValue", ")", "string", "{", "if", "data", ".", "Current", ".", "IsRoot", "(", ")", "{", "return", "url", "\n", "}", "\n", "if", "prefix", "==", "\"\"", "{", "prefix", "=", "\"/\"", "\n", "}", "else", "if", "prefix", "[", "len", "(", "prefix", ")", "-", "1", "]", "!=", "'/'", "{", "prefix", "+=", "\"/\"", "\n", "}", "\n", "if", "url", "==", "\"\"", "{", "url", "=", "\"/\"", "\n", "}", "\n", "if", "url", "[", "0", "]", "!=", "'/'", "{", "url", "=", "\"/\"", "+", "url", "\n", "}", "\n", "return", "prefix", "+", "data", ".", "Current", ".", "String", "(", ")", "+", "url", "\n", "}" ]
// URL prefixes a url string with the request language.
[ "URL", "prefixes", "a", "url", "string", "with", "the", "request", "language", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/lang/i18n.go#L213-L233
test
DeMille/termsize
termsize.go
Size
func Size() (w, h int, err error) { if !IsInit { err = errors.New("termsize not yet iniitialied") return } return get_size() }
go
func Size() (w, h int, err error) { if !IsInit { err = errors.New("termsize not yet iniitialied") return } return get_size() }
[ "func", "Size", "(", ")", "(", "w", ",", "h", "int", ",", "err", "error", ")", "{", "if", "!", "IsInit", "{", "err", "=", "errors", ".", "New", "(", "\"termsize not yet iniitialied\"", ")", "\n", "return", "\n", "}", "\n", "return", "get_size", "(", ")", "\n", "}" ]
// Returns the terminal size
[ "Returns", "the", "terminal", "size" ]
b7100f0f89ccfa4a591ca92363fe5d434f54666f
https://github.com/DeMille/termsize/blob/b7100f0f89ccfa4a591ca92363fe5d434f54666f/termsize.go#L50-L57
test
pivotal-pez/pezdispenser
pdclient/get_requestid_from_task.go
GetRequestIDFromTaskResponse
func GetRequestIDFromTaskResponse(taskResponse TaskResponse) (requestID string, err error) { var provisionHostInfoBytes []byte firstRecordIndex := 0 meta := taskResponse.MetaData provisionHostInfo := ProvisionHostInfo{} lo.G.Debug("taskResponse: ", taskResponse) lo.G.Debug("metadata: ", meta) if provisionHostInfoBytes, err = json.Marshal(meta[ProvisionHostInformationFieldname]); err == nil { if err = json.Unmarshal(provisionHostInfoBytes, &provisionHostInfo); err == nil { if len(provisionHostInfo.Data) > firstRecordIndex { requestID = provisionHostInfo.Data[firstRecordIndex].RequestID } else { lo.G.Error("no request id found in: ", provisionHostInfo) } } else { lo.G.Error("error unmarshalling: ", err, meta) lo.G.Error("metadata: ", meta) } } else { lo.G.Error("error marshalling: ", err) } return }
go
func GetRequestIDFromTaskResponse(taskResponse TaskResponse) (requestID string, err error) { var provisionHostInfoBytes []byte firstRecordIndex := 0 meta := taskResponse.MetaData provisionHostInfo := ProvisionHostInfo{} lo.G.Debug("taskResponse: ", taskResponse) lo.G.Debug("metadata: ", meta) if provisionHostInfoBytes, err = json.Marshal(meta[ProvisionHostInformationFieldname]); err == nil { if err = json.Unmarshal(provisionHostInfoBytes, &provisionHostInfo); err == nil { if len(provisionHostInfo.Data) > firstRecordIndex { requestID = provisionHostInfo.Data[firstRecordIndex].RequestID } else { lo.G.Error("no request id found in: ", provisionHostInfo) } } else { lo.G.Error("error unmarshalling: ", err, meta) lo.G.Error("metadata: ", meta) } } else { lo.G.Error("error marshalling: ", err) } return }
[ "func", "GetRequestIDFromTaskResponse", "(", "taskResponse", "TaskResponse", ")", "(", "requestID", "string", ",", "err", "error", ")", "{", "var", "provisionHostInfoBytes", "[", "]", "byte", "\n", "firstRecordIndex", ":=", "0", "\n", "meta", ":=", "taskResponse", ".", "MetaData", "\n", "provisionHostInfo", ":=", "ProvisionHostInfo", "{", "}", "\n", "lo", ".", "G", ".", "Debug", "(", "\"taskResponse: \"", ",", "taskResponse", ")", "\n", "lo", ".", "G", ".", "Debug", "(", "\"metadata: \"", ",", "meta", ")", "\n", "if", "provisionHostInfoBytes", ",", "err", "=", "json", ".", "Marshal", "(", "meta", "[", "ProvisionHostInformationFieldname", "]", ")", ";", "err", "==", "nil", "{", "if", "err", "=", "json", ".", "Unmarshal", "(", "provisionHostInfoBytes", ",", "&", "provisionHostInfo", ")", ";", "err", "==", "nil", "{", "if", "len", "(", "provisionHostInfo", ".", "Data", ")", ">", "firstRecordIndex", "{", "requestID", "=", "provisionHostInfo", ".", "Data", "[", "firstRecordIndex", "]", ".", "RequestID", "\n", "}", "else", "{", "lo", ".", "G", ".", "Error", "(", "\"no request id found in: \"", ",", "provisionHostInfo", ")", "\n", "}", "\n", "}", "else", "{", "lo", ".", "G", ".", "Error", "(", "\"error unmarshalling: \"", ",", "err", ",", "meta", ")", "\n", "lo", ".", "G", ".", "Error", "(", "\"metadata: \"", ",", "meta", ")", "\n", "}", "\n", "}", "else", "{", "lo", ".", "G", ".", "Error", "(", "\"error marshalling: \"", ",", "err", ")", "\n", "}", "\n", "return", "\n", "}" ]
//GetRequestIDFromTaskResponse - a function to get a request id from a taskresponse object
[ "GetRequestIDFromTaskResponse", "-", "a", "function", "to", "get", "a", "request", "id", "from", "a", "taskresponse", "object" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/pdclient/get_requestid_from_task.go#L10-L38
test
blacklabeldata/namedtuple
strings.go
PutString
func (b *TupleBuilder) PutString(field string, value string) (wrote int, err error) { // field type should be if err = b.typeCheck(field, StringField); err != nil { return 0, err } size := len(value) if size < math.MaxUint8 { if b.available() < size+2 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutString(b.buffer, b.pos+2, value) // write type code b.buffer[b.pos] = byte(String8Code.OpCode) // write length b.buffer[b.pos+1] = byte(size) wrote += size + 2 } else if size < math.MaxUint16 { if b.available() < size+3 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size)) // write value xbinary.LittleEndian.PutString(b.buffer, b.pos+3, value) // write type code b.buffer[b.pos] = byte(String16Code.OpCode) wrote += 3 + size } else if size < math.MaxUint32 { if b.available() < size+5 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size)) // write value xbinary.LittleEndian.PutString(b.buffer, b.pos+5, value) // write type code b.buffer[b.pos] = byte(String32Code.OpCode) wrote += 5 + size } else { if b.available() < size+9 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size)) // write value xbinary.LittleEndian.PutString(b.buffer, b.pos+9, value) // write type code b.buffer[b.pos] = byte(String64Code.OpCode) wrote += 9 + size } b.offsets[field] = b.pos b.pos += wrote return }
go
func (b *TupleBuilder) PutString(field string, value string) (wrote int, err error) { // field type should be if err = b.typeCheck(field, StringField); err != nil { return 0, err } size := len(value) if size < math.MaxUint8 { if b.available() < size+2 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutString(b.buffer, b.pos+2, value) // write type code b.buffer[b.pos] = byte(String8Code.OpCode) // write length b.buffer[b.pos+1] = byte(size) wrote += size + 2 } else if size < math.MaxUint16 { if b.available() < size+3 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size)) // write value xbinary.LittleEndian.PutString(b.buffer, b.pos+3, value) // write type code b.buffer[b.pos] = byte(String16Code.OpCode) wrote += 3 + size } else if size < math.MaxUint32 { if b.available() < size+5 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size)) // write value xbinary.LittleEndian.PutString(b.buffer, b.pos+5, value) // write type code b.buffer[b.pos] = byte(String32Code.OpCode) wrote += 5 + size } else { if b.available() < size+9 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size)) // write value xbinary.LittleEndian.PutString(b.buffer, b.pos+9, value) // write type code b.buffer[b.pos] = byte(String64Code.OpCode) wrote += 9 + size } b.offsets[field] = b.pos b.pos += wrote return }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutString", "(", "field", "string", ",", "value", "string", ")", "(", "wrote", "int", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "StringField", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "size", ":=", "len", "(", "value", ")", "\n", "if", "size", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "size", "+", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutString", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "2", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "String8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "size", ")", "\n", "wrote", "+=", "size", "+", "2", "\n", "}", "else", "if", "size", "<", "math", ".", "MaxUint16", "{", "if", "b", ".", "available", "(", ")", "<", "size", "+", "3", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint16", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutString", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "3", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "String16Code", ".", "OpCode", ")", "\n", "wrote", "+=", "3", "+", "size", "\n", "}", "else", "if", "size", "<", "math", ".", "MaxUint32", "{", "if", "b", ".", "available", "(", ")", "<", "size", "+", "5", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint32", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutString", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "5", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "String32Code", ".", "OpCode", ")", "\n", "wrote", "+=", "5", "+", "size", "\n", "}", "else", "{", "if", "b", ".", "available", "(", ")", "<", "size", "+", "9", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint64", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint64", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutString", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "9", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "String64Code", ".", "OpCode", ")", "\n", "wrote", "+=", "9", "+", "size", "\n", "}", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "wrote", "\n", "return", "\n", "}" ]
// PutString writes a string value for the given field. The field type must be a `StringField` otherwise an error will be returned. The type code is written first, then a length, and finally the value. If the size of the string is `< math.MaxUint8`, a single byte will represent the length. If the size of the string is `< math.MaxUint16`, a uint16 value will represent the length and so on. If the buffer does not have enough space for the entire string and field header, an error will be returned. If successful, the number of bytes written will be returned as well as a nil error.
[ "PutString", "writes", "a", "string", "value", "for", "the", "given", "field", ".", "The", "field", "type", "must", "be", "a", "StringField", "otherwise", "an", "error", "will", "be", "returned", ".", "The", "type", "code", "is", "written", "first", "then", "a", "length", "and", "finally", "the", "value", ".", "If", "the", "size", "of", "the", "string", "is", "<", "math", ".", "MaxUint8", "a", "single", "byte", "will", "represent", "the", "length", ".", "If", "the", "size", "of", "the", "string", "is", "<", "math", ".", "MaxUint16", "a", "uint16", "value", "will", "represent", "the", "length", "and", "so", "on", ".", "If", "the", "buffer", "does", "not", "have", "enough", "space", "for", "the", "entire", "string", "and", "field", "header", "an", "error", "will", "be", "returned", ".", "If", "successful", "the", "number", "of", "bytes", "written", "will", "be", "returned", "as", "well", "as", "a", "nil", "error", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/strings.go#L10-L87
test
blacklabeldata/namedtuple
schema/parser.go
LoadDirectory
func LoadDirectory(dir string, parser Parser) (err error) { // Open dir for reading d, err := os.Open(dir) if err != nil { return } // Iterate over all the files in the directory. for { // Only read 128 files at a time. if fis, err := d.Readdir(128); err == nil { // Read each entry for _, fi := range fis { // fmt.Println("%#v", fi) // If the FileInfo is a directory, read the directory. // Otherwise, read the file. switch fi.IsDir() { case true: // return error if there is one if err := LoadDirectory(fi.Name(), parser); err != nil { return err } case false: // All schema files should end with .nt if !strings.HasSuffix(fi.Name(), ".ent") { break } // Read the file if _, err := LoadFile(filepath.Join(dir, fi.Name()), parser); err != nil { return err } } } } else if err == io.EOF { // If there are no more files in the directory, break. break } else { // If there is any other error, return it. return err } } // If you have reached this far, you are done. return nil }
go
func LoadDirectory(dir string, parser Parser) (err error) { // Open dir for reading d, err := os.Open(dir) if err != nil { return } // Iterate over all the files in the directory. for { // Only read 128 files at a time. if fis, err := d.Readdir(128); err == nil { // Read each entry for _, fi := range fis { // fmt.Println("%#v", fi) // If the FileInfo is a directory, read the directory. // Otherwise, read the file. switch fi.IsDir() { case true: // return error if there is one if err := LoadDirectory(fi.Name(), parser); err != nil { return err } case false: // All schema files should end with .nt if !strings.HasSuffix(fi.Name(), ".ent") { break } // Read the file if _, err := LoadFile(filepath.Join(dir, fi.Name()), parser); err != nil { return err } } } } else if err == io.EOF { // If there are no more files in the directory, break. break } else { // If there is any other error, return it. return err } } // If you have reached this far, you are done. return nil }
[ "func", "LoadDirectory", "(", "dir", "string", ",", "parser", "Parser", ")", "(", "err", "error", ")", "{", "d", ",", "err", ":=", "os", ".", "Open", "(", "dir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "for", "{", "if", "fis", ",", "err", ":=", "d", ".", "Readdir", "(", "128", ")", ";", "err", "==", "nil", "{", "for", "_", ",", "fi", ":=", "range", "fis", "{", "switch", "fi", ".", "IsDir", "(", ")", "{", "case", "true", ":", "if", "err", ":=", "LoadDirectory", "(", "fi", ".", "Name", "(", ")", ",", "parser", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "case", "false", ":", "if", "!", "strings", ".", "HasSuffix", "(", "fi", ".", "Name", "(", ")", ",", "\".ent\"", ")", "{", "break", "\n", "}", "\n", "if", "_", ",", "err", ":=", "LoadFile", "(", "filepath", ".", "Join", "(", "dir", ",", "fi", ".", "Name", "(", ")", ")", ",", "parser", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "else", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "else", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LoadDirectory reads all the schema files from a directory.
[ "LoadDirectory", "reads", "all", "the", "schema", "files", "from", "a", "directory", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/parser.go#L28-L79
test
blacklabeldata/namedtuple
schema/parser.go
LoadFile
func LoadFile(filename string, parser Parser) (Package, error) { file, err := os.Open(filename) if err != nil { return Package{}, err } defer file.Close() // read file bytes, err := ioutil.ReadAll(file) if err != nil { return Package{}, err } // convert to string and load return parser.Parse(file.Name(), string(bytes)) }
go
func LoadFile(filename string, parser Parser) (Package, error) { file, err := os.Open(filename) if err != nil { return Package{}, err } defer file.Close() // read file bytes, err := ioutil.ReadAll(file) if err != nil { return Package{}, err } // convert to string and load return parser.Parse(file.Name(), string(bytes)) }
[ "func", "LoadFile", "(", "filename", "string", ",", "parser", "Parser", ")", "(", "Package", ",", "error", ")", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Package", "{", "}", ",", "err", "\n", "}", "\n", "defer", "file", ".", "Close", "(", ")", "\n", "bytes", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Package", "{", "}", ",", "err", "\n", "}", "\n", "return", "parser", ".", "Parse", "(", "file", ".", "Name", "(", ")", ",", "string", "(", "bytes", ")", ")", "\n", "}" ]
// LoadFile reads a schema document from a file.
[ "LoadFile", "reads", "a", "schema", "document", "from", "a", "file", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/parser.go#L82-L97
test
blacklabeldata/namedtuple
schema/parser.go
LoadPackage
func LoadPackage(parser Parser, name, text string) (Package, error) { return parser.Parse(name, text) }
go
func LoadPackage(parser Parser, name, text string) (Package, error) { return parser.Parse(name, text) }
[ "func", "LoadPackage", "(", "parser", "Parser", ",", "name", ",", "text", "string", ")", "(", "Package", ",", "error", ")", "{", "return", "parser", ".", "Parse", "(", "name", ",", "text", ")", "\n", "}" ]
// LoadPackage parses a text string.
[ "LoadPackage", "parses", "a", "text", "string", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/schema/parser.go#L100-L102
test
blacklabeldata/namedtuple
decoder.go
NewDecoder
func NewDecoder(reg Registry, r io.Reader) Decoder { var buf []byte return decoder{reg, DefaultMaxSize, bytes.NewBuffer(buf), bufio.NewReader(r)} }
go
func NewDecoder(reg Registry, r io.Reader) Decoder { var buf []byte return decoder{reg, DefaultMaxSize, bytes.NewBuffer(buf), bufio.NewReader(r)} }
[ "func", "NewDecoder", "(", "reg", "Registry", ",", "r", "io", ".", "Reader", ")", "Decoder", "{", "var", "buf", "[", "]", "byte", "\n", "return", "decoder", "{", "reg", ",", "DefaultMaxSize", ",", "bytes", ".", "NewBuffer", "(", "buf", ")", ",", "bufio", ".", "NewReader", "(", "r", ")", "}", "\n", "}" ]
// NewDecoder creates a new Decoder using a type Registry and an io.Reader.
[ "NewDecoder", "creates", "a", "new", "Decoder", "using", "a", "type", "Registry", "and", "an", "io", ".", "Reader", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/decoder.go#L57-L60
test
blacklabeldata/namedtuple
decoder.go
NewDecoderSize
func NewDecoderSize(reg Registry, maxSize uint64, r io.Reader) Decoder { var buf []byte return decoder{reg, maxSize, bytes.NewBuffer(buf), bufio.NewReader(r)} }
go
func NewDecoderSize(reg Registry, maxSize uint64, r io.Reader) Decoder { var buf []byte return decoder{reg, maxSize, bytes.NewBuffer(buf), bufio.NewReader(r)} }
[ "func", "NewDecoderSize", "(", "reg", "Registry", ",", "maxSize", "uint64", ",", "r", "io", ".", "Reader", ")", "Decoder", "{", "var", "buf", "[", "]", "byte", "\n", "return", "decoder", "{", "reg", ",", "maxSize", ",", "bytes", ".", "NewBuffer", "(", "buf", ")", ",", "bufio", ".", "NewReader", "(", "r", ")", "}", "\n", "}" ]
// NewDecoderSize creates a new Decoder using a type Registry, a max size and an io.Reader.
[ "NewDecoderSize", "creates", "a", "new", "Decoder", "using", "a", "type", "Registry", "a", "max", "size", "and", "an", "io", ".", "Reader", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/decoder.go#L63-L66
test
urandom/handler
log/panic.go
Panic
func Panic(h http.Handler, opts ...Option) http.Handler { o := options{logger: handler.ErrLogger(), dateFormat: PanicDateFormat} o.apply(opts) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer func() { if rec := recover(); rec != nil { stack := debug.Stack() timestamp := time.Now().Format(o.dateFormat) message := fmt.Sprintf("%s - %s\n%s\n", timestamp, rec, stack) o.logger.Print(message) w.WriteHeader(http.StatusInternalServerError) if !o.showStack { message = "Internal Server Error" } w.Write([]byte(message)) } }() h.ServeHTTP(w, r) }) }
go
func Panic(h http.Handler, opts ...Option) http.Handler { o := options{logger: handler.ErrLogger(), dateFormat: PanicDateFormat} o.apply(opts) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer func() { if rec := recover(); rec != nil { stack := debug.Stack() timestamp := time.Now().Format(o.dateFormat) message := fmt.Sprintf("%s - %s\n%s\n", timestamp, rec, stack) o.logger.Print(message) w.WriteHeader(http.StatusInternalServerError) if !o.showStack { message = "Internal Server Error" } w.Write([]byte(message)) } }() h.ServeHTTP(w, r) }) }
[ "func", "Panic", "(", "h", "http", ".", "Handler", ",", "opts", "...", "Option", ")", "http", ".", "Handler", "{", "o", ":=", "options", "{", "logger", ":", "handler", ".", "ErrLogger", "(", ")", ",", "dateFormat", ":", "PanicDateFormat", "}", "\n", "o", ".", "apply", "(", "opts", ")", "\n", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "defer", "func", "(", ")", "{", "if", "rec", ":=", "recover", "(", ")", ";", "rec", "!=", "nil", "{", "stack", ":=", "debug", ".", "Stack", "(", ")", "\n", "timestamp", ":=", "time", ".", "Now", "(", ")", ".", "Format", "(", "o", ".", "dateFormat", ")", "\n", "message", ":=", "fmt", ".", "Sprintf", "(", "\"%s - %s\\n%s\\n\"", ",", "\\n", ",", "\\n", ",", "timestamp", ")", "\n", "rec", "\n", "stack", "\n", "o", ".", "logger", ".", "Print", "(", "message", ")", "\n", "w", ".", "WriteHeader", "(", "http", ".", "StatusInternalServerError", ")", "\n", "}", "\n", "}", "if", "!", "o", ".", "showStack", "{", "message", "=", "\"Internal Server Error\"", "\n", "}", "\n", "w", ".", "Write", "(", "[", "]", "byte", "(", "message", ")", ")", "\n", "}", ")", "\n", "}" ]
// Panic returns a handler that invokes the passed handler h, catching any // panics. If one occurs, an HTTP 500 response is produced. // // By default, all messages are printed out to os.Stderr.
[ "Panic", "returns", "a", "handler", "that", "invokes", "the", "passed", "handler", "h", "catching", "any", "panics", ".", "If", "one", "occurs", "an", "HTTP", "500", "response", "is", "produced", ".", "By", "default", "all", "messages", "are", "printed", "out", "to", "os", ".", "Stderr", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/log/panic.go#L28-L53
test
pivotal-pez/pezdispenser
fakes/fake.go
DeployVApp
func (s *FakeVCDClient) DeployVApp(templateName, templateHref, vcdHref string) (vapp *vcloudclient.VApp, err error) { return s.FakeVApp, s.ErrUnDeployFake }
go
func (s *FakeVCDClient) DeployVApp(templateName, templateHref, vcdHref string) (vapp *vcloudclient.VApp, err error) { return s.FakeVApp, s.ErrUnDeployFake }
[ "func", "(", "s", "*", "FakeVCDClient", ")", "DeployVApp", "(", "templateName", ",", "templateHref", ",", "vcdHref", "string", ")", "(", "vapp", "*", "vcloudclient", ".", "VApp", ",", "err", "error", ")", "{", "return", "s", ".", "FakeVApp", ",", "s", ".", "ErrUnDeployFake", "\n", "}" ]
//DeployVApp - fake out calling deploy vapp
[ "DeployVApp", "-", "fake", "out", "calling", "deploy", "vapp" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/fakes/fake.go#L120-L122
test
pivotal-pez/pezdispenser
fakes/fake.go
UnDeployVApp
func (s *FakeVCDClient) UnDeployVApp(vappID string) (task *vcloudclient.TaskElem, err error) { return &s.FakeVApp.Tasks.Task, s.ErrDeployFake }
go
func (s *FakeVCDClient) UnDeployVApp(vappID string) (task *vcloudclient.TaskElem, err error) { return &s.FakeVApp.Tasks.Task, s.ErrDeployFake }
[ "func", "(", "s", "*", "FakeVCDClient", ")", "UnDeployVApp", "(", "vappID", "string", ")", "(", "task", "*", "vcloudclient", ".", "TaskElem", ",", "err", "error", ")", "{", "return", "&", "s", ".", "FakeVApp", ".", "Tasks", ".", "Task", ",", "s", ".", "ErrDeployFake", "\n", "}" ]
//UnDeployVApp - executes a fake undeploy on a fake client
[ "UnDeployVApp", "-", "executes", "a", "fake", "undeploy", "on", "a", "fake", "client" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/fakes/fake.go#L125-L127
test
pivotal-pez/pezdispenser
fakes/fake.go
Auth
func (s *FakeVCDClient) Auth(username, password string) (err error) { return s.ErrAuthFake }
go
func (s *FakeVCDClient) Auth(username, password string) (err error) { return s.ErrAuthFake }
[ "func", "(", "s", "*", "FakeVCDClient", ")", "Auth", "(", "username", ",", "password", "string", ")", "(", "err", "error", ")", "{", "return", "s", ".", "ErrAuthFake", "\n", "}" ]
//Auth - fake out making an auth call
[ "Auth", "-", "fake", "out", "making", "an", "auth", "call" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/fakes/fake.go#L130-L132
test
pivotal-pez/pezdispenser
fakes/fake.go
QueryTemplate
func (s *FakeVCDClient) QueryTemplate(templateName string) (vappTemplate *vcloudclient.VAppTemplateRecord, err error) { return s.FakeVAppTemplateRecord, s.ErrDeployFake }
go
func (s *FakeVCDClient) QueryTemplate(templateName string) (vappTemplate *vcloudclient.VAppTemplateRecord, err error) { return s.FakeVAppTemplateRecord, s.ErrDeployFake }
[ "func", "(", "s", "*", "FakeVCDClient", ")", "QueryTemplate", "(", "templateName", "string", ")", "(", "vappTemplate", "*", "vcloudclient", ".", "VAppTemplateRecord", ",", "err", "error", ")", "{", "return", "s", ".", "FakeVAppTemplateRecord", ",", "s", ".", "ErrDeployFake", "\n", "}" ]
//QueryTemplate - fake querying for a template
[ "QueryTemplate", "-", "fake", "querying", "for", "a", "template" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/fakes/fake.go#L135-L137
test
blacklabeldata/namedtuple
encoder.go
NewEncoder
func NewEncoder(w io.Writer) Encoder { return versionOneEncoder{w, make([]byte, 9), bytes.NewBuffer(make([]byte, 0, 4096))} }
go
func NewEncoder(w io.Writer) Encoder { return versionOneEncoder{w, make([]byte, 9), bytes.NewBuffer(make([]byte, 0, 4096))} }
[ "func", "NewEncoder", "(", "w", "io", ".", "Writer", ")", "Encoder", "{", "return", "versionOneEncoder", "{", "w", ",", "make", "(", "[", "]", "byte", ",", "9", ")", ",", "bytes", ".", "NewBuffer", "(", "make", "(", "[", "]", "byte", ",", "0", ",", "4096", ")", ")", "}", "\n", "}" ]
// NewEncoder creates a new encoder with the given io.Writer
[ "NewEncoder", "creates", "a", "new", "encoder", "with", "the", "given", "io", ".", "Writer" ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/encoder.go#L23-L25
test
urandom/handler
security/nonce.go
Getter
func Getter(g NonceGetter) Option { return Option{func(o *options) { o.getter = g }} }
go
func Getter(g NonceGetter) Option { return Option{func(o *options) { o.getter = g }} }
[ "func", "Getter", "(", "g", "NonceGetter", ")", "Option", "{", "return", "Option", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "getter", "=", "g", "\n", "}", "}", "\n", "}" ]
// Getter allows the user to set the method by which a nonce is retrieved from // the incoming request.
[ "Getter", "allows", "the", "user", "to", "set", "the", "method", "by", "which", "a", "nonce", "is", "retrieved", "from", "the", "incoming", "request", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/security/nonce.go#L63-L67
test
urandom/handler
security/nonce.go
Setter
func Setter(s NonceSetter) Option { return Option{func(o *options) { o.setter = s }} }
go
func Setter(s NonceSetter) Option { return Option{func(o *options) { o.setter = s }} }
[ "func", "Setter", "(", "s", "NonceSetter", ")", "Option", "{", "return", "Option", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "setter", "=", "s", "\n", "}", "}", "\n", "}" ]
// Setter allows the user to set the method by which a nonce is stored in // the outgoing response.
[ "Setter", "allows", "the", "user", "to", "set", "the", "method", "by", "which", "a", "nonce", "is", "stored", "in", "the", "outgoing", "response", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/security/nonce.go#L71-L75
test
urandom/handler
security/nonce.go
Age
func Age(age time.Duration) Option { return Option{func(o *options) { o.age = age }} }
go
func Age(age time.Duration) Option { return Option{func(o *options) { o.age = age }} }
[ "func", "Age", "(", "age", "time", ".", "Duration", ")", "Option", "{", "return", "Option", "{", "func", "(", "o", "*", "options", ")", "{", "o", ".", "age", "=", "age", "\n", "}", "}", "\n", "}" ]
// Age sets the maximum time duration a nonce can be valid
[ "Age", "sets", "the", "maximum", "time", "duration", "a", "nonce", "can", "be", "valid" ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/security/nonce.go#L78-L82
test
urandom/handler
security/nonce.go
Nonce
func Nonce(h http.Handler, opts ...Option) http.Handler { headerStorage := nonceHeaderStorage{} o := options{ logger: handler.OutLogger(), generator: timeRandomGenerator, getter: headerStorage, setter: headerStorage, age: 45 * time.Second, } o.apply(opts) store := nonceStore{} opChan := make(chan func(nonceStore)) go func() { for op := range opChan { op(store) } }() go func() { for { select { case <-time.After(5 * time.Minute): cleanup(o.age, opChan) } } }() setter := func(w http.ResponseWriter, r *http.Request) error { nonce, err := generateAndStore(o.age, o.generator, opChan) if err != nil { return err } return o.setter.SetNonce(nonce, w, r) } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() nonce := o.getter.GetNonce(r) if nonce != "" { if validateAndRemoveNonce(nonce, o.age, opChan) { ctx = context.WithValue(ctx, nonceValueKey, NonceStatus{NonceValid}) } else { ctx = context.WithValue(ctx, nonceValueKey, NonceStatus{NonceInvalid}) } } h.ServeHTTP(w, r.WithContext(context.WithValue(ctx, nonceSetterKey, setter))) }) }
go
func Nonce(h http.Handler, opts ...Option) http.Handler { headerStorage := nonceHeaderStorage{} o := options{ logger: handler.OutLogger(), generator: timeRandomGenerator, getter: headerStorage, setter: headerStorage, age: 45 * time.Second, } o.apply(opts) store := nonceStore{} opChan := make(chan func(nonceStore)) go func() { for op := range opChan { op(store) } }() go func() { for { select { case <-time.After(5 * time.Minute): cleanup(o.age, opChan) } } }() setter := func(w http.ResponseWriter, r *http.Request) error { nonce, err := generateAndStore(o.age, o.generator, opChan) if err != nil { return err } return o.setter.SetNonce(nonce, w, r) } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() nonce := o.getter.GetNonce(r) if nonce != "" { if validateAndRemoveNonce(nonce, o.age, opChan) { ctx = context.WithValue(ctx, nonceValueKey, NonceStatus{NonceValid}) } else { ctx = context.WithValue(ctx, nonceValueKey, NonceStatus{NonceInvalid}) } } h.ServeHTTP(w, r.WithContext(context.WithValue(ctx, nonceSetterKey, setter))) }) }
[ "func", "Nonce", "(", "h", "http", ".", "Handler", ",", "opts", "...", "Option", ")", "http", ".", "Handler", "{", "headerStorage", ":=", "nonceHeaderStorage", "{", "}", "\n", "o", ":=", "options", "{", "logger", ":", "handler", ".", "OutLogger", "(", ")", ",", "generator", ":", "timeRandomGenerator", ",", "getter", ":", "headerStorage", ",", "setter", ":", "headerStorage", ",", "age", ":", "45", "*", "time", ".", "Second", ",", "}", "\n", "o", ".", "apply", "(", "opts", ")", "\n", "store", ":=", "nonceStore", "{", "}", "\n", "opChan", ":=", "make", "(", "chan", "func", "(", "nonceStore", ")", ")", "\n", "go", "func", "(", ")", "{", "for", "op", ":=", "range", "opChan", "{", "op", "(", "store", ")", "\n", "}", "\n", "}", "(", ")", "\n", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "<-", "time", ".", "After", "(", "5", "*", "time", ".", "Minute", ")", ":", "cleanup", "(", "o", ".", "age", ",", "opChan", ")", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "setter", ":=", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "nonce", ",", "err", ":=", "generateAndStore", "(", "o", ".", "age", ",", "o", ".", "generator", ",", "opChan", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "o", ".", "setter", ".", "SetNonce", "(", "nonce", ",", "w", ",", "r", ")", "\n", "}", "\n", "return", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "ctx", ":=", "r", ".", "Context", "(", ")", "\n", "nonce", ":=", "o", ".", "getter", ".", "GetNonce", "(", "r", ")", "\n", "if", "nonce", "!=", "\"\"", "{", "if", "validateAndRemoveNonce", "(", "nonce", ",", "o", ".", "age", ",", "opChan", ")", "{", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "nonceValueKey", ",", "NonceStatus", "{", "NonceValid", "}", ")", "\n", "}", "else", "{", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "nonceValueKey", ",", "NonceStatus", "{", "NonceInvalid", "}", ")", "\n", "}", "\n", "}", "\n", "h", ".", "ServeHTTP", "(", "w", ",", "r", ".", "WithContext", "(", "context", ".", "WithValue", "(", "ctx", ",", "nonceSetterKey", ",", "setter", ")", ")", ")", "\n", "}", ")", "\n", "}" ]
// Nonce returns a handler that will check each request for the // existence of a nonce. If a nonce exists, it will be checked for // expiration. A status will be recorded in the request's context, // indicating whether there was a nonce in the request, and if so, // whether it is valid or expired. // // The recorded status can later be obtained using the // NonceValueFromRequest function. // // A nonce can be set for later checking using the StoreNonce // function.
[ "Nonce", "returns", "a", "handler", "that", "will", "check", "each", "request", "for", "the", "existence", "of", "a", "nonce", ".", "If", "a", "nonce", "exists", "it", "will", "be", "checked", "for", "expiration", ".", "A", "status", "will", "be", "recorded", "in", "the", "request", "s", "context", "indicating", "whether", "there", "was", "a", "nonce", "in", "the", "request", "and", "if", "so", "whether", "it", "is", "valid", "or", "expired", ".", "The", "recorded", "status", "can", "later", "be", "obtained", "using", "the", "NonceValueFromRequest", "function", ".", "A", "nonce", "can", "be", "set", "for", "later", "checking", "using", "the", "StoreNonce", "function", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/security/nonce.go#L113-L165
test
urandom/handler
security/nonce.go
NonceValueFromRequest
func NonceValueFromRequest(r *http.Request) NonceStatus { if c := r.Context().Value(nonceValueKey); c != nil { if v, ok := c.(NonceStatus); ok { return v } } return NonceStatus{NonceNotRequested} }
go
func NonceValueFromRequest(r *http.Request) NonceStatus { if c := r.Context().Value(nonceValueKey); c != nil { if v, ok := c.(NonceStatus); ok { return v } } return NonceStatus{NonceNotRequested} }
[ "func", "NonceValueFromRequest", "(", "r", "*", "http", ".", "Request", ")", "NonceStatus", "{", "if", "c", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "nonceValueKey", ")", ";", "c", "!=", "nil", "{", "if", "v", ",", "ok", ":=", "c", ".", "(", "NonceStatus", ")", ";", "ok", "{", "return", "v", "\n", "}", "\n", "}", "\n", "return", "NonceStatus", "{", "NonceNotRequested", "}", "\n", "}" ]
// NonceValueFromRequest validates a nonce in the given request, and returns // the validation status.
[ "NonceValueFromRequest", "validates", "a", "nonce", "in", "the", "given", "request", "and", "returns", "the", "validation", "status", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/security/nonce.go#L169-L177
test
urandom/handler
security/nonce.go
StoreNonce
func StoreNonce(w http.ResponseWriter, r *http.Request) (err error) { if c := r.Context().Value(nonceSetterKey); c != nil { if setter, ok := c.(func(http.ResponseWriter, *http.Request) error); ok { err = setter(w, r) } } return err }
go
func StoreNonce(w http.ResponseWriter, r *http.Request) (err error) { if c := r.Context().Value(nonceSetterKey); c != nil { if setter, ok := c.(func(http.ResponseWriter, *http.Request) error); ok { err = setter(w, r) } } return err }
[ "func", "StoreNonce", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "(", "err", "error", ")", "{", "if", "c", ":=", "r", ".", "Context", "(", ")", ".", "Value", "(", "nonceSetterKey", ")", ";", "c", "!=", "nil", "{", "if", "setter", ",", "ok", ":=", "c", ".", "(", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", "error", ")", ";", "ok", "{", "err", "=", "setter", "(", "w", ",", "r", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// StoreNonce generates and stores a nonce in the outgoing response.
[ "StoreNonce", "generates", "and", "stores", "a", "nonce", "in", "the", "outgoing", "response", "." ]
61508044a5569d1609521d81e81f6737567fd104
https://github.com/urandom/handler/blob/61508044a5569d1609521d81e81f6737567fd104/security/nonce.go#L180-L188
test
blacklabeldata/namedtuple
float_array.go
PutFloat32Array
func (b *TupleBuilder) PutFloat32Array(field string, value []float32) (wrote int, err error) { // field type should be if err = b.typeCheck(field, Float32ArrayField); err != nil { return 0, err } size := len(value) if size < math.MaxUint8 { if b.available() < size*4+2 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+2, value) // write type code b.buffer[b.pos] = byte(FloatArray8Code.OpCode) // write length b.buffer[b.pos+1] = byte(size) wrote += size + 2 } else if size < math.MaxUint16 { if b.available() < size*4+3 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size)) // write value xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+3, value) // write type code b.buffer[b.pos] = byte(FloatArray16Code.OpCode) wrote += 3 + size } else if size < math.MaxUint32 { if b.available() < size*4+5 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size)) // write value xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+5, value) // write type code b.buffer[b.pos] = byte(FloatArray32Code.OpCode) wrote += 5 + size } else { if b.available() < size*4+9 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size)) // write value xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+9, value) // write type code b.buffer[b.pos] = byte(FloatArray64Code.OpCode) wrote += 9 + size } b.offsets[field] = b.pos b.pos += wrote return }
go
func (b *TupleBuilder) PutFloat32Array(field string, value []float32) (wrote int, err error) { // field type should be if err = b.typeCheck(field, Float32ArrayField); err != nil { return 0, err } size := len(value) if size < math.MaxUint8 { if b.available() < size*4+2 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+2, value) // write type code b.buffer[b.pos] = byte(FloatArray8Code.OpCode) // write length b.buffer[b.pos+1] = byte(size) wrote += size + 2 } else if size < math.MaxUint16 { if b.available() < size*4+3 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size)) // write value xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+3, value) // write type code b.buffer[b.pos] = byte(FloatArray16Code.OpCode) wrote += 3 + size } else if size < math.MaxUint32 { if b.available() < size*4+5 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size)) // write value xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+5, value) // write type code b.buffer[b.pos] = byte(FloatArray32Code.OpCode) wrote += 5 + size } else { if b.available() < size*4+9 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size)) // write value xbinary.LittleEndian.PutFloat32Array(b.buffer, b.pos+9, value) // write type code b.buffer[b.pos] = byte(FloatArray64Code.OpCode) wrote += 9 + size } b.offsets[field] = b.pos b.pos += wrote return }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutFloat32Array", "(", "field", "string", ",", "value", "[", "]", "float32", ")", "(", "wrote", "int", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Float32ArrayField", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "size", ":=", "len", "(", "value", ")", "\n", "if", "size", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "4", "+", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat32Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "2", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "FloatArray8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "size", ")", "\n", "wrote", "+=", "size", "+", "2", "\n", "}", "else", "if", "size", "<", "math", ".", "MaxUint16", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "4", "+", "3", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint16", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat32Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "3", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "FloatArray16Code", ".", "OpCode", ")", "\n", "wrote", "+=", "3", "+", "size", "\n", "}", "else", "if", "size", "<", "math", ".", "MaxUint32", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "4", "+", "5", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint32", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat32Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "5", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "FloatArray32Code", ".", "OpCode", ")", "\n", "wrote", "+=", "5", "+", "size", "\n", "}", "else", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "4", "+", "9", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint64", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint64", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat32Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "9", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "FloatArray64Code", ".", "OpCode", ")", "\n", "wrote", "+=", "9", "+", "size", "\n", "}", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "wrote", "\n", "return", "\n", "}" ]
// PutFloat32Array writes a float array for the given field. The field type must be a 'Float32ArrayField', otherwise as error will be returned. The type code is written first followed by the array size in bytes. If the size of the array is less than `math.MaxUint8`, a byte will be used to represent the length. If the size of the array is less than `math.MaxUint16`, a 16-bit unsigned integer will be used to represent the length and so on. If the buffer is too small to store the entire array, an `xbinary.ErrOutOfRange` error will be returned. If the write is successful, the total number of bytes will be returned as well as a nil error.
[ "PutFloat32Array", "writes", "a", "float", "array", "for", "the", "given", "field", ".", "The", "field", "type", "must", "be", "a", "Float32ArrayField", "otherwise", "as", "error", "will", "be", "returned", ".", "The", "type", "code", "is", "written", "first", "followed", "by", "the", "array", "size", "in", "bytes", ".", "If", "the", "size", "of", "the", "array", "is", "less", "than", "math", ".", "MaxUint8", "a", "byte", "will", "be", "used", "to", "represent", "the", "length", ".", "If", "the", "size", "of", "the", "array", "is", "less", "than", "math", ".", "MaxUint16", "a", "16", "-", "bit", "unsigned", "integer", "will", "be", "used", "to", "represent", "the", "length", "and", "so", "on", ".", "If", "the", "buffer", "is", "too", "small", "to", "store", "the", "entire", "array", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "If", "the", "write", "is", "successful", "the", "total", "number", "of", "bytes", "will", "be", "returned", "as", "well", "as", "a", "nil", "error", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/float_array.go#L10-L87
test
blacklabeldata/namedtuple
float_array.go
PutFloat64Array
func (b *TupleBuilder) PutFloat64Array(field string, value []float64) (wrote int, err error) { // field type should be if err = b.typeCheck(field, Float64ArrayField); err != nil { return 0, err } size := len(value) if size < math.MaxUint8 { if b.available() < size*8+2 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+2, value) // write type code b.buffer[b.pos] = byte(DoubleArray8Code.OpCode) // write length b.buffer[b.pos+1] = byte(size) wrote += size + 2 } else if size < math.MaxUint16 { if b.available() < size*8+3 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size)) // write value xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+3, value) // write type code b.buffer[b.pos] = byte(DoubleArray16Code.OpCode) wrote += 3 + size } else if size < math.MaxUint32 { if b.available() < size*8+5 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size)) // write value xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+5, value) // write type code b.buffer[b.pos] = byte(DoubleArray32Code.OpCode) wrote += 5 + size } else { if b.available() < size*8+9 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size)) // write value xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+9, value) // write type code b.buffer[b.pos] = byte(DoubleArray64Code.OpCode) wrote += 9 + size } b.offsets[field] = b.pos b.pos += wrote return }
go
func (b *TupleBuilder) PutFloat64Array(field string, value []float64) (wrote int, err error) { // field type should be if err = b.typeCheck(field, Float64ArrayField); err != nil { return 0, err } size := len(value) if size < math.MaxUint8 { if b.available() < size*8+2 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+2, value) // write type code b.buffer[b.pos] = byte(DoubleArray8Code.OpCode) // write length b.buffer[b.pos+1] = byte(size) wrote += size + 2 } else if size < math.MaxUint16 { if b.available() < size*8+3 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint16(b.buffer, b.pos+1, uint16(size)) // write value xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+3, value) // write type code b.buffer[b.pos] = byte(DoubleArray16Code.OpCode) wrote += 3 + size } else if size < math.MaxUint32 { if b.available() < size*8+5 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint32(b.buffer, b.pos+1, uint32(size)) // write value xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+5, value) // write type code b.buffer[b.pos] = byte(DoubleArray32Code.OpCode) wrote += 5 + size } else { if b.available() < size*8+9 { return 0, xbinary.ErrOutOfRange } // write length xbinary.LittleEndian.PutUint64(b.buffer, b.pos+1, uint64(size)) // write value xbinary.LittleEndian.PutFloat64Array(b.buffer, b.pos+9, value) // write type code b.buffer[b.pos] = byte(DoubleArray64Code.OpCode) wrote += 9 + size } b.offsets[field] = b.pos b.pos += wrote return }
[ "func", "(", "b", "*", "TupleBuilder", ")", "PutFloat64Array", "(", "field", "string", ",", "value", "[", "]", "float64", ")", "(", "wrote", "int", ",", "err", "error", ")", "{", "if", "err", "=", "b", ".", "typeCheck", "(", "field", ",", "Float64ArrayField", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "size", ":=", "len", "(", "value", ")", "\n", "if", "size", "<", "math", ".", "MaxUint8", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "8", "+", "2", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat64Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "2", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "DoubleArray8Code", ".", "OpCode", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "+", "1", "]", "=", "byte", "(", "size", ")", "\n", "wrote", "+=", "size", "+", "2", "\n", "}", "else", "if", "size", "<", "math", ".", "MaxUint16", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "8", "+", "3", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint16", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint16", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat64Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "3", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "DoubleArray16Code", ".", "OpCode", ")", "\n", "wrote", "+=", "3", "+", "size", "\n", "}", "else", "if", "size", "<", "math", ".", "MaxUint32", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "8", "+", "5", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint32", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint32", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat64Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "5", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "DoubleArray32Code", ".", "OpCode", ")", "\n", "wrote", "+=", "5", "+", "size", "\n", "}", "else", "{", "if", "b", ".", "available", "(", ")", "<", "size", "*", "8", "+", "9", "{", "return", "0", ",", "xbinary", ".", "ErrOutOfRange", "\n", "}", "\n", "xbinary", ".", "LittleEndian", ".", "PutUint64", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "1", ",", "uint64", "(", "size", ")", ")", "\n", "xbinary", ".", "LittleEndian", ".", "PutFloat64Array", "(", "b", ".", "buffer", ",", "b", ".", "pos", "+", "9", ",", "value", ")", "\n", "b", ".", "buffer", "[", "b", ".", "pos", "]", "=", "byte", "(", "DoubleArray64Code", ".", "OpCode", ")", "\n", "wrote", "+=", "9", "+", "size", "\n", "}", "\n", "b", ".", "offsets", "[", "field", "]", "=", "b", ".", "pos", "\n", "b", ".", "pos", "+=", "wrote", "\n", "return", "\n", "}" ]
// PutFloat64Array writes a float array for the given field. The field type must be a 'Float64ArrayField', otherwise as error will be returned. The type code is written first followed by the array size in bytes. If the size of the array is less than `math.MaxUint8`, a byte will be used to represent the length. If the size of the array is less than `math.MaxUint16`, a 16-bit unsigned integer will be used to represent the length and so on. If the buffer is too small to store the entire array, an `xbinary.ErrOutOfRange` error will be returned. If the write is successful, the total number of bytes will be returned as well as a nil error.
[ "PutFloat64Array", "writes", "a", "float", "array", "for", "the", "given", "field", ".", "The", "field", "type", "must", "be", "a", "Float64ArrayField", "otherwise", "as", "error", "will", "be", "returned", ".", "The", "type", "code", "is", "written", "first", "followed", "by", "the", "array", "size", "in", "bytes", ".", "If", "the", "size", "of", "the", "array", "is", "less", "than", "math", ".", "MaxUint8", "a", "byte", "will", "be", "used", "to", "represent", "the", "length", ".", "If", "the", "size", "of", "the", "array", "is", "less", "than", "math", ".", "MaxUint16", "a", "16", "-", "bit", "unsigned", "integer", "will", "be", "used", "to", "represent", "the", "length", "and", "so", "on", ".", "If", "the", "buffer", "is", "too", "small", "to", "store", "the", "entire", "array", "an", "xbinary", ".", "ErrOutOfRange", "error", "will", "be", "returned", ".", "If", "the", "write", "is", "successful", "the", "total", "number", "of", "bytes", "will", "be", "returned", "as", "well", "as", "a", "nil", "error", "." ]
c341f1db44f30b8164294aa8605ede42be604aba
https://github.com/blacklabeldata/namedtuple/blob/c341f1db44f30b8164294aa8605ede42be604aba/float_array.go#L90-L167
test
pivotal-pez/pezdispenser
pdclient/fake/fake.go
Do
func (s *ClientDoer) Do(req *http.Request) (resp *http.Response, err error) { s.SpyRequest = *req return s.Response, s.Error }
go
func (s *ClientDoer) Do(req *http.Request) (resp *http.Response, err error) { s.SpyRequest = *req return s.Response, s.Error }
[ "func", "(", "s", "*", "ClientDoer", ")", "Do", "(", "req", "*", "http", ".", "Request", ")", "(", "resp", "*", "http", ".", "Response", ",", "err", "error", ")", "{", "s", ".", "SpyRequest", "=", "*", "req", "\n", "return", "s", ".", "Response", ",", "s", ".", "Error", "\n", "}" ]
//Do - fake do method
[ "Do", "-", "fake", "do", "method" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/pdclient/fake/fake.go#L13-L16
test
pivotal-pez/pezdispenser
service/lease.go
NewLease
func NewLease(taskCollection integrations.Collection, availableSkus map[string]skurepo.SkuBuilder) *Lease { return &Lease{ taskCollection: taskCollection, taskManager: taskmanager.NewTaskManager(taskCollection), availableSkus: availableSkus, Task: taskmanager.RedactedTask{}, } }
go
func NewLease(taskCollection integrations.Collection, availableSkus map[string]skurepo.SkuBuilder) *Lease { return &Lease{ taskCollection: taskCollection, taskManager: taskmanager.NewTaskManager(taskCollection), availableSkus: availableSkus, Task: taskmanager.RedactedTask{}, } }
[ "func", "NewLease", "(", "taskCollection", "integrations", ".", "Collection", ",", "availableSkus", "map", "[", "string", "]", "skurepo", ".", "SkuBuilder", ")", "*", "Lease", "{", "return", "&", "Lease", "{", "taskCollection", ":", "taskCollection", ",", "taskManager", ":", "taskmanager", ".", "NewTaskManager", "(", "taskCollection", ")", ",", "availableSkus", ":", "availableSkus", ",", "Task", ":", "taskmanager", ".", "RedactedTask", "{", "}", ",", "}", "\n", "}" ]
//NewLease - create and return a new lease object
[ "NewLease", "-", "create", "and", "return", "a", "new", "lease", "object" ]
768e2777520868857916b66cfd4cfb7149383ca5
https://github.com/pivotal-pez/pezdispenser/blob/768e2777520868857916b66cfd4cfb7149383ca5/service/lease.go#L18-L26
test