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
a... | 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
a... | [
"func",
"(",
"ab",
"*",
"AccessBarrier",
")",
"FlushSession",
"(",
"ref",
"unsafe",
".",
"Pointer",
")",
"{",
"if",
"ab",
".",
"active",
"{",
"ab",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ab",
".",
"Unlock",
"(",
")",
"\n",
"bsPtr",
":=",
"atomic",
... | // 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(nodesA... | 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(nodesA... | [
"func",
"(",
"report",
"*",
"StatsReport",
")",
"Apply",
"(",
"s",
"*",
"Stats",
")",
"{",
"var",
"totalNextPtrs",
"int",
"\n",
"var",
"totalNodes",
"int",
"\n",
"report",
".",
"ReadConflicts",
"+=",
"s",
".",
"readConflicts",
"\n",
"report",
".",
"Inser... | // 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",
")",
... | // 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",
")... | // 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)
st... | 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)
st... | [
"func",
"(",
"s",
"*",
"Stats",
")",
"Merge",
"(",
"sts",
"*",
"Stats",
")",
"{",
"atomic",
".",
"AddUint64",
"(",
"&",
"s",
".",
"insertConflicts",
",",
"sts",
".",
"insertConflicts",
")",
"\n",
"sts",
".",
"insertConflicts",
"=",
"0",
"\n",
"atomic... | // 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",
... | // 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",
".",
... | // 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()) =... | 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()) =... | [
"func",
"(",
"it",
"*",
"Iterator",
")",
"SeekWithCmp",
"(",
"itm",
"unsafe",
".",
"Pointer",
",",
"cmp",
"CompareFn",
",",
"eqCmp",
"CompareFn",
")",
"bool",
"{",
"var",
"found",
"bool",
"\n",
"if",
"found",
"=",
"it",
".",
"s",
".",
"findPath",
"("... | // 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",
".",
... | // 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... | // 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",
"=",
"t... | // 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 cu... | 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 cu... | [
"func",
"(",
"it",
"*",
"Iterator",
")",
"Next",
"(",
")",
"{",
"if",
"it",
".",
"deleted",
"{",
"it",
".",
"deleted",
"=",
"false",
"\n",
"return",
"\n",
"}",
"\n",
"retry",
":",
"it",
".",
"valid",
"=",
"true",
"\n",
"next",
",",
"deleted",
"... | // 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",
... | // 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",
"... | // 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",... | // 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:], ... | 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:], ... | [
"func",
"(",
"t",
"*",
"TupleHeader",
")",
"WriteTo",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"len",
"(",
"t",
".",
"Offsets",
")",
"!=",
"int",
"(",
"t",
".",
"FieldCount",
")",
"{",
"return",
"0",
",",
... | // 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.Me... | 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.Me... | [
"func",
"Static",
"(",
"directory",
"string",
",",
"staticOpt",
"...",
"StaticOptions",
")",
"Handler",
"{",
"if",
"!",
"path",
".",
"IsAbs",
"(",
"directory",
")",
"{",
"directory",
"=",
"path",
".",
"Join",
"(",
"Root",
",",
"directory",
")",
"\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 {
sec... | 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 {
sec... | [
"func",
"(",
"c",
"*",
"Config",
")",
"Read",
"(",
")",
"error",
"{",
"in",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"c",
".",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"in",
".",
"Close... | // 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",
"]",... | // 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,... | 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,... | [
"func",
"(",
"c",
"*",
"Config",
")",
"WriteTo",
"(",
"filename",
"string",
")",
"error",
"{",
"content",
":=",
"\"\"",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"config",
"{",
"format",
":=",
"\"%v = %v\\n\"",
"\n",
"\\n",
"\n",
"if",
"... | // 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",
"\... | // 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",
"i... | // 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",
"[",... | // 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",
")... | // 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",
".",
"Clos... | // 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",
"wi... | 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 ... | 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 ... | [
"func",
"Logger",
"(",
"next",
"http",
".",
"Handler",
")",
"http",
".",
"HandlerFunc",
"{",
"stdlogger",
":=",
"log",
".",
"New",
"(",
"os",
".",
"Stdout",
",",
"\"\"",
",",
"0",
")",
"\n",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
... | // 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",
"onceLoadInvento... | //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",
"}",... | // 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(opt... | 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(opt... | [
"func",
"TokenGenerator",
"(",
"h",
"http",
".",
"Handler",
",",
"auth",
"Authenticator",
",",
"secret",
"[",
"]",
"byte",
",",
"opts",
"...",
"TokenOpt",
")",
"http",
".",
"Handler",
"{",
"o",
":=",
"options",
"{",
"logger",
":",
"handler",
".",
"NopL... | // 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",
"re... | 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",
"}"... | // 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",
"{",
... | // 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",
... | // 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",
",",
"}",
... | // 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",
":... | // 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",... | // 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",
... | // 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",
"!=",
"-",
... | // 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",
"(... | // 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... | 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... | [
"func",
"lexText",
"(",
"l",
"*",
"Lexer",
")",
"stateFn",
"{",
"OUTER",
":",
"for",
"{",
"l",
".",
"skipWhitespace",
"(",
")",
"\n",
"remaining",
":=",
"l",
".",
"remaining",
"(",
")",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"remaining",
",",
... | // 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 {
... | 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 {
... | [
"func",
"lexComment",
"(",
"l",
"*",
"Lexer",
")",
"stateFn",
"{",
"l",
".",
"skipWhitespace",
"(",
")",
"\n",
"l",
".",
"Pos",
"+=",
"len",
"(",
"comment",
")",
"\n",
"if",
"index",
":=",
"strings",
".",
"Index",
"(",
"l",
".",
"remaining",
"(",
... | // 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",
"(",
"[",
... | // 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",
... | // 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",
"<",... | // 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",
"]",... | //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",... | //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",
",",... | //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",
"... | // 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 {
... | 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 {
... | [
"func",
"HTTP",
"(",
"h",
"http",
".",
"Handler",
",",
"verb",
"Verb",
",",
"verbs",
"...",
"Verb",
")",
"http",
".",
"Handler",
"{",
"verbSet",
":=",
"map",
"[",
"Verb",
"]",
"struct",
"{",
"}",
"{",
"verb",
":",
"struct",
"{",
"}",
"{",
"}",
... | // 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",
... | 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... | 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... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutUint8",
"(",
"field",
"string",
",",
"value",
"uint8",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Uint8Field",
")",
";",
"... | // 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 r... | [
"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... | 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[... | 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[... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutInt8",
"(",
"field",
"string",
",",
"value",
"int8",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Int8Field",
")",
";",
"err... | // 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 re... | [
"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",
... | 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.ErrOutOfRa... | 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.ErrOutOfRa... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutUint16",
"(",
"field",
"string",
",",
"value",
"uint16",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Uint16Field",
")",
";",
... | // 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... | [
"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",
"buffe... | 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.ErrOu... | 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.ErrOu... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutInt16",
"(",
"field",
"string",
",",
"value",
"int16",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Int16Field",
")",
";",
"... | // 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 ... | [
"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",
"b... | 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.ErrOutOfRa... | 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.ErrOutOfRa... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutUint32",
"(",
"field",
"string",
",",
"value",
"uint32",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Uint32Field",
")",
";",
... | // 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 ... | [
"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",
"buffe... | 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 {
r... | 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 {
r... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutInt32",
"(",
"field",
"string",
",",
"value",
"int32",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Int32Field",
")",
";",
"... | // 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 erro... | [
"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",
"bu... | 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.ErrOutOfRa... | 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.ErrOutOfRa... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutUint64",
"(",
"field",
"string",
",",
"value",
"uint64",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Uint64Field",
")",
";",
... | // 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 ni... | [
"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",... | 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 {
r... | 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 {
r... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutInt64",
"(",
"field",
"string",
",",
"value",
"int64",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Int64Field",
")",
";",
"... | // 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 er... | [
"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",
"... | 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)
... | 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)
... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutFloat32",
"(",
"field",
"string",
",",
"value",
"float32",
")",
"(",
"wrote",
"uint64",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Float32Field",
")",
";... | // 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",... | 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"... | // 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"... | 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",
... | //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",
"=",
"\"... | // 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",
"(",
... | // 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 provisionHostIn... | 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 provisionHostIn... | [
"func",
"GetRequestIDFromTaskResponse",
"(",
"taskResponse",
"TaskResponse",
")",
"(",
"requestID",
"string",
",",
"err",
"error",
")",
"{",
"var",
"provisionHostInfoBytes",
"[",
"]",
"byte",
"\n",
"firstRecordIndex",
":=",
"0",
"\n",
"meta",
":=",
"taskResponse",... | //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 len... | 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 len... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutString",
"(",
"field",
"string",
",",
"value",
"string",
")",
"(",
"wrote",
"int",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"StringField",
")",
";",
"... | // 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 ... | [
"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"... | 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 {
... | 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 {
... | [
"func",
"LoadDirectory",
"(",
"dir",
"string",
",",
"parser",
"Parser",
")",
"(",
"err",
"error",
")",
"{",
"d",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
"{",
"... | // 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 an... | 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 an... | [
"func",
"LoadFile",
"(",
"filename",
"string",
",",
"parser",
"Parser",
")",
"(",
"Package",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Package",
"{",
"... | // 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",
")",
",",
"buf... | // 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",
"(",
... | // 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... | 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... | [
"func",
"Panic",
"(",
"h",
"http",
".",
"Handler",
",",
"opts",
"...",
"Option",
")",
"http",
".",
"Handler",
"{",
"o",
":=",
"options",
"{",
"logger",
":",
"handler",
".",
"ErrLogger",
"(",
")",
",",
"dateFormat",
":",
"PanicDateFormat",
"}",
"\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",
"... | 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",
... | //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",
"."... | //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",
".",
... | //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",
",... | // 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 := ... | 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 := ... | [
"func",
"Nonce",
"(",
"h",
"http",
".",
"Handler",
",",
"opts",
"...",
"Option",
")",
"http",
".",
"Handler",
"{",
"headerStorage",
":=",
"nonceHeaderStorage",
"{",
"}",
"\n",
"o",
":=",
"options",
"{",
"logger",
":",
"handler",
".",
"OutLogger",
"(",
... | // 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 s... | [
"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",
"recor... | 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",
... | // 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",
"!=",
"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
... | 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
... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutFloat32Array",
"(",
"field",
"string",
",",
"value",
"[",
"]",
"float32",
")",
"(",
"wrote",
"int",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Float32Arr... | // 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 s... | [
"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... | 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
... | 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
... | [
"func",
"(",
"b",
"*",
"TupleBuilder",
")",
"PutFloat64Array",
"(",
"field",
"string",
",",
"value",
"[",
"]",
"float64",
")",
"(",
"wrote",
"int",
",",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"b",
".",
"typeCheck",
"(",
"field",
",",
"Float64Arr... | // 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 s... | [
"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... | 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",... | //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",
",",
"tas... | //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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.