repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
libgit2/git2go | reference.go | Owner | func (v *Reference) Owner() *Repository {
return &Repository{
ptr: C.git_reference_owner(v.ptr),
}
} | go | func (v *Reference) Owner() *Repository {
return &Repository{
ptr: C.git_reference_owner(v.ptr),
}
} | [
"func",
"(",
"v",
"*",
"Reference",
")",
"Owner",
"(",
")",
"*",
"Repository",
"{",
"return",
"&",
"Repository",
"{",
"ptr",
":",
"C",
".",
"git_reference_owner",
"(",
"v",
".",
"ptr",
")",
",",
"}",
"\n",
"}"
] | // Owner returns a weak reference to the repository which owns this
// reference. | [
"Owner",
"returns",
"a",
"weak",
"reference",
"to",
"the",
"repository",
"which",
"owns",
"this",
"reference",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L298-L302 | train |
libgit2/git2go | reference.go | Cmp | func (v *Reference) Cmp(ref2 *Reference) int {
ret := int(C.git_reference_cmp(v.ptr, ref2.ptr))
runtime.KeepAlive(v)
runtime.KeepAlive(ref2)
return ret
} | go | func (v *Reference) Cmp(ref2 *Reference) int {
ret := int(C.git_reference_cmp(v.ptr, ref2.ptr))
runtime.KeepAlive(v)
runtime.KeepAlive(ref2)
return ret
} | [
"func",
"(",
"v",
"*",
"Reference",
")",
"Cmp",
"(",
"ref2",
"*",
"Reference",
")",
"int",
"{",
"ret",
":=",
"int",
"(",
"C",
".",
"git_reference_cmp",
"(",
"v",
".",
"ptr",
",",
"ref2",
".",
"ptr",
")",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(... | // Cmp compares v to ref2. It returns 0 on equality, otherwise a
// stable sorting. | [
"Cmp",
"compares",
"v",
"to",
"ref2",
".",
"It",
"returns",
"0",
"on",
"equality",
"otherwise",
"a",
"stable",
"sorting",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L306-L311 | train |
libgit2/git2go | reference.go | Shorthand | func (v *Reference) Shorthand() string {
ret := C.GoString(C.git_reference_shorthand(v.ptr))
runtime.KeepAlive(v)
return ret
} | go | func (v *Reference) Shorthand() string {
ret := C.GoString(C.git_reference_shorthand(v.ptr))
runtime.KeepAlive(v)
return ret
} | [
"func",
"(",
"v",
"*",
"Reference",
")",
"Shorthand",
"(",
")",
"string",
"{",
"ret",
":=",
"C",
".",
"GoString",
"(",
"C",
".",
"git_reference_shorthand",
"(",
"v",
".",
"ptr",
")",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"v",
")",
"\n",
"ret... | // Shorthand returns a "human-readable" short reference name. | [
"Shorthand",
"returns",
"a",
"human",
"-",
"readable",
"short",
"reference",
"name",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L314-L318 | train |
libgit2/git2go | reference.go | Name | func (v *Reference) Name() string {
ret := C.GoString(C.git_reference_name(v.ptr))
runtime.KeepAlive(v)
return ret
} | go | func (v *Reference) Name() string {
ret := C.GoString(C.git_reference_name(v.ptr))
runtime.KeepAlive(v)
return ret
} | [
"func",
"(",
"v",
"*",
"Reference",
")",
"Name",
"(",
")",
"string",
"{",
"ret",
":=",
"C",
".",
"GoString",
"(",
"C",
".",
"git_reference_name",
"(",
"v",
".",
"ptr",
")",
")",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"v",
")",
"\n",
"return",
"r... | // Name returns the full name of v. | [
"Name",
"returns",
"the",
"full",
"name",
"of",
"v",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L321-L325 | train |
libgit2/git2go | reference.go | IsNote | func (v *Reference) IsNote() bool {
ret := C.git_reference_is_note(v.ptr) == 1
runtime.KeepAlive(v)
return ret
} | go | func (v *Reference) IsNote() bool {
ret := C.git_reference_is_note(v.ptr) == 1
runtime.KeepAlive(v)
return ret
} | [
"func",
"(",
"v",
"*",
"Reference",
")",
"IsNote",
"(",
")",
"bool",
"{",
"ret",
":=",
"C",
".",
"git_reference_is_note",
"(",
"v",
".",
"ptr",
")",
"==",
"1",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"v",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // IsNote checks if the reference is a note. | [
"IsNote",
"checks",
"if",
"the",
"reference",
"is",
"a",
"note",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L352-L356 | train |
libgit2/git2go | reference.go | NewReferenceIterator | func (repo *Repository) NewReferenceIterator() (*ReferenceIterator, error) {
var ptr *C.git_reference_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_iterator_new(&ptr, repo.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceIteratorFromC(ptr, repo), nil
} | go | func (repo *Repository) NewReferenceIterator() (*ReferenceIterator, error) {
var ptr *C.git_reference_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_iterator_new(&ptr, repo.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceIteratorFromC(ptr, repo), nil
} | [
"func",
"(",
"repo",
"*",
"Repository",
")",
"NewReferenceIterator",
"(",
")",
"(",
"*",
"ReferenceIterator",
",",
"error",
")",
"{",
"var",
"ptr",
"*",
"C",
".",
"git_reference_iterator",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"r... | // NewReferenceIterator creates a new iterator over reference names | [
"NewReferenceIterator",
"creates",
"a",
"new",
"iterator",
"over",
"reference",
"names"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L373-L385 | train |
libgit2/git2go | reference.go | NewReferenceNameIterator | func (repo *Repository) NewReferenceNameIterator() (*ReferenceNameIterator, error) {
var ptr *C.git_reference_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_iterator_new(&ptr, repo.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
iter := newReferenceIteratorFromC(ptr, repo)
return iter.Names(), nil
} | go | func (repo *Repository) NewReferenceNameIterator() (*ReferenceNameIterator, error) {
var ptr *C.git_reference_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_iterator_new(&ptr, repo.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
iter := newReferenceIteratorFromC(ptr, repo)
return iter.Names(), nil
} | [
"func",
"(",
"repo",
"*",
"Repository",
")",
"NewReferenceNameIterator",
"(",
")",
"(",
"*",
"ReferenceNameIterator",
",",
"error",
")",
"{",
"var",
"ptr",
"*",
"C",
".",
"git_reference_iterator",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defe... | // NewReferenceIterator creates a new branch iterator over reference names | [
"NewReferenceIterator",
"creates",
"a",
"new",
"branch",
"iterator",
"over",
"reference",
"names"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L388-L401 | train |
libgit2/git2go | reference.go | NewReferenceIteratorGlob | func (repo *Repository) NewReferenceIteratorGlob(glob string) (*ReferenceIterator, error) {
cstr := C.CString(glob)
defer C.free(unsafe.Pointer(cstr))
var ptr *C.git_reference_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_iterator_glob_new(&ptr, repo.ptr, cstr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceIteratorFromC(ptr, repo), nil
} | go | func (repo *Repository) NewReferenceIteratorGlob(glob string) (*ReferenceIterator, error) {
cstr := C.CString(glob)
defer C.free(unsafe.Pointer(cstr))
var ptr *C.git_reference_iterator
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_iterator_glob_new(&ptr, repo.ptr, cstr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceIteratorFromC(ptr, repo), nil
} | [
"func",
"(",
"repo",
"*",
"Repository",
")",
"NewReferenceIteratorGlob",
"(",
"glob",
"string",
")",
"(",
"*",
"ReferenceIterator",
",",
"error",
")",
"{",
"cstr",
":=",
"C",
".",
"CString",
"(",
"glob",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsa... | // NewReferenceIteratorGlob creates an iterator over reference names
// that match the speicified glob. The glob is of the usual fnmatch
// type. | [
"NewReferenceIteratorGlob",
"creates",
"an",
"iterator",
"over",
"reference",
"names",
"that",
"match",
"the",
"speicified",
"glob",
".",
"The",
"glob",
"is",
"of",
"the",
"usual",
"fnmatch",
"type",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L406-L420 | train |
libgit2/git2go | reference.go | Next | func (v *ReferenceNameIterator) Next() (string, error) {
var ptr *C.char
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_next_name(&ptr, v.ptr)
if ret < 0 {
return "", MakeGitError(ret)
}
return C.GoString(ptr), nil
} | go | func (v *ReferenceNameIterator) Next() (string, error) {
var ptr *C.char
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_next_name(&ptr, v.ptr)
if ret < 0 {
return "", MakeGitError(ret)
}
return C.GoString(ptr), nil
} | [
"func",
"(",
"v",
"*",
"ReferenceNameIterator",
")",
"Next",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"ptr",
"*",
"C",
".",
"char",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
... | // NextName retrieves the next reference name. If the iteration is over,
// the returned error is git.ErrIterOver | [
"NextName",
"retrieves",
"the",
"next",
"reference",
"name",
".",
"If",
"the",
"iteration",
"is",
"over",
"the",
"returned",
"error",
"is",
"git",
".",
"ErrIterOver"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L428-L440 | train |
libgit2/git2go | reference.go | Next | func (v *ReferenceIterator) Next() (*Reference, error) {
var ptr *C.git_reference
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_next(&ptr, v.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceFromC(ptr, v.repo), nil
} | go | func (v *ReferenceIterator) Next() (*Reference, error) {
var ptr *C.git_reference
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_reference_next(&ptr, v.ptr)
if ret < 0 {
return nil, MakeGitError(ret)
}
return newReferenceFromC(ptr, v.repo), nil
} | [
"func",
"(",
"v",
"*",
"ReferenceIterator",
")",
"Next",
"(",
")",
"(",
"*",
"Reference",
",",
"error",
")",
"{",
"var",
"ptr",
"*",
"C",
".",
"git_reference",
"\n\n",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSTh... | // Next retrieves the next reference. If the iterationis over, the
// returned error is git.ErrIterOver | [
"Next",
"retrieves",
"the",
"next",
"reference",
".",
"If",
"the",
"iterationis",
"over",
"the",
"returned",
"error",
"is",
"git",
".",
"ErrIterOver"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L444-L456 | train |
libgit2/git2go | reference.go | Free | func (v *ReferenceIterator) Free() {
runtime.SetFinalizer(v, nil)
C.git_reference_iterator_free(v.ptr)
} | go | func (v *ReferenceIterator) Free() {
runtime.SetFinalizer(v, nil)
C.git_reference_iterator_free(v.ptr)
} | [
"func",
"(",
"v",
"*",
"ReferenceIterator",
")",
"Free",
"(",
")",
"{",
"runtime",
".",
"SetFinalizer",
"(",
"v",
",",
"nil",
")",
"\n",
"C",
".",
"git_reference_iterator_free",
"(",
"v",
".",
"ptr",
")",
"\n",
"}"
] | // Free the reference iterator | [
"Free",
"the",
"reference",
"iterator"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/reference.go#L468-L471 | train |
libgit2/git2go | checkout.go | populateCheckoutOpts | func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.git_checkout_options {
if opts == nil {
return nil
}
C.git_checkout_init_options(ptr, 1)
ptr.checkout_strategy = C.uint(opts.Strategy)
ptr.disable_filters = cbool(opts.DisableFilters)
ptr.dir_mode = C.uint(opts.DirMode.Perm())
ptr.file_mode = C.uint(opts.FileMode.Perm())
ptr.notify_flags = C.uint(opts.NotifyFlags)
if opts.NotifyCallback != nil || opts.ProgressCallback != nil {
C._go_git_populate_checkout_cb(ptr)
}
payload := pointerHandles.Track(opts)
if opts.NotifyCallback != nil {
ptr.notify_payload = payload
}
if opts.ProgressCallback != nil {
ptr.progress_payload = payload
}
if opts.TargetDirectory != "" {
ptr.target_directory = C.CString(opts.TargetDirectory)
}
if len(opts.Paths) > 0 {
ptr.paths.strings = makeCStringsFromStrings(opts.Paths)
ptr.paths.count = C.size_t(len(opts.Paths))
}
if opts.Baseline != nil {
ptr.baseline = opts.Baseline.cast_ptr
}
return ptr
} | go | func populateCheckoutOpts(ptr *C.git_checkout_options, opts *CheckoutOpts) *C.git_checkout_options {
if opts == nil {
return nil
}
C.git_checkout_init_options(ptr, 1)
ptr.checkout_strategy = C.uint(opts.Strategy)
ptr.disable_filters = cbool(opts.DisableFilters)
ptr.dir_mode = C.uint(opts.DirMode.Perm())
ptr.file_mode = C.uint(opts.FileMode.Perm())
ptr.notify_flags = C.uint(opts.NotifyFlags)
if opts.NotifyCallback != nil || opts.ProgressCallback != nil {
C._go_git_populate_checkout_cb(ptr)
}
payload := pointerHandles.Track(opts)
if opts.NotifyCallback != nil {
ptr.notify_payload = payload
}
if opts.ProgressCallback != nil {
ptr.progress_payload = payload
}
if opts.TargetDirectory != "" {
ptr.target_directory = C.CString(opts.TargetDirectory)
}
if len(opts.Paths) > 0 {
ptr.paths.strings = makeCStringsFromStrings(opts.Paths)
ptr.paths.count = C.size_t(len(opts.Paths))
}
if opts.Baseline != nil {
ptr.baseline = opts.Baseline.cast_ptr
}
return ptr
} | [
"func",
"populateCheckoutOpts",
"(",
"ptr",
"*",
"C",
".",
"git_checkout_options",
",",
"opts",
"*",
"CheckoutOpts",
")",
"*",
"C",
".",
"git_checkout_options",
"{",
"if",
"opts",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"C",
".",
"git_checkou... | // Convert the CheckoutOpts struct to the corresponding
// C-struct. Returns a pointer to ptr, or nil if opts is nil, in order
// to help with what to pass. | [
"Convert",
"the",
"CheckoutOpts",
"struct",
"to",
"the",
"corresponding",
"C",
"-",
"struct",
".",
"Returns",
"a",
"pointer",
"to",
"ptr",
"or",
"nil",
"if",
"opts",
"is",
"nil",
"in",
"order",
"to",
"help",
"with",
"what",
"to",
"pass",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/checkout.go#L132-L166 | train |
libgit2/git2go | checkout.go | CheckoutHead | func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
cOpts := opts.toC()
defer freeCheckoutOpts(cOpts)
ret := C.git_checkout_head(v.ptr, cOpts)
runtime.KeepAlive(v)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (v *Repository) CheckoutHead(opts *CheckoutOpts) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
cOpts := opts.toC()
defer freeCheckoutOpts(cOpts)
ret := C.git_checkout_head(v.ptr, cOpts)
runtime.KeepAlive(v)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"v",
"*",
"Repository",
")",
"CheckoutHead",
"(",
"opts",
"*",
"CheckoutOpts",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"cOpts",
":=",
"opts",
".",
"toC",... | // Updates files in the index and the working tree to match the content of
// the commit pointed at by HEAD. opts may be nil. | [
"Updates",
"files",
"in",
"the",
"index",
"and",
"the",
"working",
"tree",
"to",
"match",
"the",
"content",
"of",
"the",
"commit",
"pointed",
"at",
"by",
"HEAD",
".",
"opts",
"may",
"be",
"nil",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/checkout.go#L183-L197 | train |
libgit2/git2go | checkout.go | CheckoutIndex | func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
var iptr *C.git_index = nil
if index != nil {
iptr = index.ptr
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
cOpts := opts.toC()
defer freeCheckoutOpts(cOpts)
ret := C.git_checkout_index(v.ptr, iptr, cOpts)
runtime.KeepAlive(v)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
var iptr *C.git_index = nil
if index != nil {
iptr = index.ptr
}
runtime.LockOSThread()
defer runtime.UnlockOSThread()
cOpts := opts.toC()
defer freeCheckoutOpts(cOpts)
ret := C.git_checkout_index(v.ptr, iptr, cOpts)
runtime.KeepAlive(v)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"v",
"*",
"Repository",
")",
"CheckoutIndex",
"(",
"index",
"*",
"Index",
",",
"opts",
"*",
"CheckoutOpts",
")",
"error",
"{",
"var",
"iptr",
"*",
"C",
".",
"git_index",
"=",
"nil",
"\n",
"if",
"index",
"!=",
"nil",
"{",
"iptr",
"=",
"... | // Updates files in the working tree to match the content of the given
// index. If index is nil, the repository's index will be used. opts
// may be nil. | [
"Updates",
"files",
"in",
"the",
"working",
"tree",
"to",
"match",
"the",
"content",
"of",
"the",
"given",
"index",
".",
"If",
"index",
"is",
"nil",
"the",
"repository",
"s",
"index",
"will",
"be",
"used",
".",
"opts",
"may",
"be",
"nil",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/checkout.go#L202-L221 | train |
libgit2/git2go | packbuilder.go | ForEach | func (pb *Packbuilder) ForEach(callback PackbuilderForeachCallback) error {
data := packbuilderCbData{
callback: callback,
err: nil,
}
handle := pointerHandles.Track(&data)
defer pointerHandles.Untrack(handle)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C._go_git_packbuilder_foreach(pb.ptr, handle)
runtime.KeepAlive(pb)
if err == C.GIT_EUSER {
return data.err
}
if err < 0 {
return MakeGitError(err)
}
return nil
} | go | func (pb *Packbuilder) ForEach(callback PackbuilderForeachCallback) error {
data := packbuilderCbData{
callback: callback,
err: nil,
}
handle := pointerHandles.Track(&data)
defer pointerHandles.Untrack(handle)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := C._go_git_packbuilder_foreach(pb.ptr, handle)
runtime.KeepAlive(pb)
if err == C.GIT_EUSER {
return data.err
}
if err < 0 {
return MakeGitError(err)
}
return nil
} | [
"func",
"(",
"pb",
"*",
"Packbuilder",
")",
"ForEach",
"(",
"callback",
"PackbuilderForeachCallback",
")",
"error",
"{",
"data",
":=",
"packbuilderCbData",
"{",
"callback",
":",
"callback",
",",
"err",
":",
"nil",
",",
"}",
"\n",
"handle",
":=",
"pointerHand... | // ForEach repeatedly calls the callback with new packfile data until
// there is no more data or the callback returns an error | [
"ForEach",
"repeatedly",
"calls",
"the",
"callback",
"with",
"new",
"packfile",
"data",
"until",
"there",
"is",
"no",
"more",
"data",
"or",
"the",
"callback",
"returns",
"an",
"error"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/packbuilder.go#L162-L183 | train |
libgit2/git2go | object.go | Owner | func (o *Object) Owner() *Repository {
ret := &Repository{
ptr: C.git_object_owner(o.ptr),
}
runtime.KeepAlive(o)
return ret
} | go | func (o *Object) Owner() *Repository {
ret := &Repository{
ptr: C.git_object_owner(o.ptr),
}
runtime.KeepAlive(o)
return ret
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"Owner",
"(",
")",
"*",
"Repository",
"{",
"ret",
":=",
"&",
"Repository",
"{",
"ptr",
":",
"C",
".",
"git_object_owner",
"(",
"o",
".",
"ptr",
")",
",",
"}",
"\n",
"runtime",
".",
"KeepAlive",
"(",
"o",
")",... | // Owner returns a weak reference to the repository which owns this
// object. This won't keep the underlying repository alive. | [
"Owner",
"returns",
"a",
"weak",
"reference",
"to",
"the",
"repository",
"which",
"owns",
"this",
"object",
".",
"This",
"won",
"t",
"keep",
"the",
"underlying",
"repository",
"alive",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/object.go#L82-L88 | train |
libgit2/git2go | odb.go | NewReadStream | func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
stream := new(OdbReadStream)
var ctype C.git_object_t
var csize C.size_t
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_open_rstream(&stream.ptr, &csize, &ctype, v.ptr, id.toC())
runtime.KeepAlive(v)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
stream.Size = uint64(csize)
stream.Type = ObjectType(ctype)
runtime.SetFinalizer(stream, (*OdbReadStream).Free)
return stream, nil
} | go | func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
stream := new(OdbReadStream)
var ctype C.git_object_t
var csize C.size_t
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_open_rstream(&stream.ptr, &csize, &ctype, v.ptr, id.toC())
runtime.KeepAlive(v)
runtime.KeepAlive(id)
if ret < 0 {
return nil, MakeGitError(ret)
}
stream.Size = uint64(csize)
stream.Type = ObjectType(ctype)
runtime.SetFinalizer(stream, (*OdbReadStream).Free)
return stream, nil
} | [
"func",
"(",
"v",
"*",
"Odb",
")",
"NewReadStream",
"(",
"id",
"*",
"Oid",
")",
"(",
"*",
"OdbReadStream",
",",
"error",
")",
"{",
"stream",
":=",
"new",
"(",
"OdbReadStream",
")",
"\n",
"var",
"ctype",
"C",
".",
"git_object_t",
"\n",
"var",
"csize",... | // NewReadStream opens a read stream from the ODB. Reading from it will give you the
// contents of the object. | [
"NewReadStream",
"opens",
"a",
"read",
"stream",
"from",
"the",
"ODB",
".",
"Reading",
"from",
"it",
"will",
"give",
"you",
"the",
"contents",
"of",
"the",
"object",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/odb.go#L194-L213 | train |
libgit2/git2go | odb.go | NewWriteStream | func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, error) {
stream := new(OdbWriteStream)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_object_t(otype))
runtime.KeepAlive(v)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(stream, (*OdbWriteStream).Free)
return stream, nil
} | go | func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, error) {
stream := new(OdbWriteStream)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_object_t(otype))
runtime.KeepAlive(v)
if ret < 0 {
return nil, MakeGitError(ret)
}
runtime.SetFinalizer(stream, (*OdbWriteStream).Free)
return stream, nil
} | [
"func",
"(",
"v",
"*",
"Odb",
")",
"NewWriteStream",
"(",
"size",
"int64",
",",
"otype",
"ObjectType",
")",
"(",
"*",
"OdbWriteStream",
",",
"error",
")",
"{",
"stream",
":=",
"new",
"(",
"OdbWriteStream",
")",
"\n\n",
"runtime",
".",
"LockOSThread",
"("... | // NewWriteStream opens a write stream to the ODB, which allows you to
// create a new object in the database. The size and type must be
// known in advance | [
"NewWriteStream",
"opens",
"a",
"write",
"stream",
"to",
"the",
"ODB",
"which",
"allows",
"you",
"to",
"create",
"a",
"new",
"object",
"in",
"the",
"database",
".",
"The",
"size",
"and",
"type",
"must",
"be",
"known",
"in",
"advance"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/odb.go#L218-L232 | train |
libgit2/git2go | odb.go | Data | func (object *OdbObject) Data() (data []byte) {
var c_blob unsafe.Pointer = C.git_odb_object_data(object.ptr)
var blob []byte
len := int(C.git_odb_object_size(object.ptr))
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&blob)))
sliceHeader.Cap = len
sliceHeader.Len = len
sliceHeader.Data = uintptr(c_blob)
return blob
} | go | func (object *OdbObject) Data() (data []byte) {
var c_blob unsafe.Pointer = C.git_odb_object_data(object.ptr)
var blob []byte
len := int(C.git_odb_object_size(object.ptr))
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&blob)))
sliceHeader.Cap = len
sliceHeader.Len = len
sliceHeader.Data = uintptr(c_blob)
return blob
} | [
"func",
"(",
"object",
"*",
"OdbObject",
")",
"Data",
"(",
")",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"var",
"c_blob",
"unsafe",
".",
"Pointer",
"=",
"C",
".",
"git_odb_object_data",
"(",
"object",
".",
"ptr",
")",
"\n",
"var",
"blob",
"[",
"]",... | // Data returns a slice pointing to the unmanaged object memory. You must make
// sure the object is referenced for at least as long as the slice is used. | [
"Data",
"returns",
"a",
"slice",
"pointing",
"to",
"the",
"unmanaged",
"object",
"memory",
".",
"You",
"must",
"make",
"sure",
"the",
"object",
"is",
"referenced",
"for",
"at",
"least",
"as",
"long",
"as",
"the",
"slice",
"is",
"used",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/odb.go#L267-L279 | train |
libgit2/git2go | odb.go | Read | func (stream *OdbReadStream) Read(data []byte) (int, error) {
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
ptr := (*C.char)(unsafe.Pointer(header.Data))
size := C.size_t(header.Cap)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_read(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ret < 0 {
return 0, MakeGitError(ret)
}
if ret == 0 {
return 0, io.EOF
}
header.Len = int(ret)
return len(data), nil
} | go | func (stream *OdbReadStream) Read(data []byte) (int, error) {
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
ptr := (*C.char)(unsafe.Pointer(header.Data))
size := C.size_t(header.Cap)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_read(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ret < 0 {
return 0, MakeGitError(ret)
}
if ret == 0 {
return 0, io.EOF
}
header.Len = int(ret)
return len(data), nil
} | [
"func",
"(",
"stream",
"*",
"OdbReadStream",
")",
"Read",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"header",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"data",
")",
... | // Read reads from the stream | [
"Read",
"reads",
"from",
"the",
"stream"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/odb.go#L288-L308 | train |
libgit2/git2go | odb.go | Write | func (stream *OdbWriteStream) Write(data []byte) (int, error) {
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
ptr := (*C.char)(unsafe.Pointer(header.Data))
size := C.size_t(header.Len)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_write(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ret < 0 {
return 0, MakeGitError(ret)
}
return len(data), nil
} | go | func (stream *OdbWriteStream) Write(data []byte) (int, error) {
header := (*reflect.SliceHeader)(unsafe.Pointer(&data))
ptr := (*C.char)(unsafe.Pointer(header.Data))
size := C.size_t(header.Len)
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_write(stream.ptr, ptr, size)
runtime.KeepAlive(stream)
if ret < 0 {
return 0, MakeGitError(ret)
}
return len(data), nil
} | [
"func",
"(",
"stream",
"*",
"OdbWriteStream",
")",
"Write",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"header",
":=",
"(",
"*",
"reflect",
".",
"SliceHeader",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"data",
")",
... | // Write writes to the stream | [
"Write",
"writes",
"to",
"the",
"stream"
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/odb.go#L327-L342 | train |
libgit2/git2go | odb.go | Close | func (stream *OdbWriteStream) Close() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_finalize_write(stream.Id.toC(), stream.ptr)
runtime.KeepAlive(stream)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | go | func (stream *OdbWriteStream) Close() error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
ret := C.git_odb_stream_finalize_write(stream.Id.toC(), stream.ptr)
runtime.KeepAlive(stream)
if ret < 0 {
return MakeGitError(ret)
}
return nil
} | [
"func",
"(",
"stream",
"*",
"OdbWriteStream",
")",
"Close",
"(",
")",
"error",
"{",
"runtime",
".",
"LockOSThread",
"(",
")",
"\n",
"defer",
"runtime",
".",
"UnlockOSThread",
"(",
")",
"\n\n",
"ret",
":=",
"C",
".",
"git_odb_stream_finalize_write",
"(",
"s... | // Close signals that all the data has been written and stores the
// resulting object id in the stream's Id field. | [
"Close",
"signals",
"that",
"all",
"the",
"data",
"has",
"been",
"written",
"and",
"stores",
"the",
"resulting",
"object",
"id",
"in",
"the",
"stream",
"s",
"Id",
"field",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/odb.go#L346-L357 | train |
libgit2/git2go | credentials.go | NewCredSshKey | func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (int, Cred) {
cred := Cred{}
cusername := C.CString(username)
defer C.free(unsafe.Pointer(cusername))
cpublickey := C.CString(publicKeyPath)
defer C.free(unsafe.Pointer(cpublickey))
cprivatekey := C.CString(privateKeyPath)
defer C.free(unsafe.Pointer(cprivatekey))
cpassphrase := C.CString(passphrase)
defer C.free(unsafe.Pointer(cpassphrase))
ret := C.git_cred_ssh_key_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
return int(ret), cred
} | go | func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (int, Cred) {
cred := Cred{}
cusername := C.CString(username)
defer C.free(unsafe.Pointer(cusername))
cpublickey := C.CString(publicKeyPath)
defer C.free(unsafe.Pointer(cpublickey))
cprivatekey := C.CString(privateKeyPath)
defer C.free(unsafe.Pointer(cprivatekey))
cpassphrase := C.CString(passphrase)
defer C.free(unsafe.Pointer(cpassphrase))
ret := C.git_cred_ssh_key_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
return int(ret), cred
} | [
"func",
"NewCredSshKey",
"(",
"username",
"string",
",",
"publicKeyPath",
"string",
",",
"privateKeyPath",
"string",
",",
"passphrase",
"string",
")",
"(",
"int",
",",
"Cred",
")",
"{",
"cred",
":=",
"Cred",
"{",
"}",
"\n",
"cusername",
":=",
"C",
".",
"... | // NewCredSshKey creates new ssh credentials reading the public and private keys
// from the file system. | [
"NewCredSshKey",
"creates",
"new",
"ssh",
"credentials",
"reading",
"the",
"public",
"and",
"private",
"keys",
"from",
"the",
"file",
"system",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/credentials.go#L49-L61 | train |
libgit2/git2go | credentials.go | NewCredSshKeyFromMemory | func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (int, Cred) {
cred := Cred{}
cusername := C.CString(username)
defer C.free(unsafe.Pointer(cusername))
cpublickey := C.CString(publicKey)
defer C.free(unsafe.Pointer(cpublickey))
cprivatekey := C.CString(privateKey)
defer C.free(unsafe.Pointer(cprivatekey))
cpassphrase := C.CString(passphrase)
defer C.free(unsafe.Pointer(cpassphrase))
ret := C.git_cred_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
return int(ret), cred
} | go | func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (int, Cred) {
cred := Cred{}
cusername := C.CString(username)
defer C.free(unsafe.Pointer(cusername))
cpublickey := C.CString(publicKey)
defer C.free(unsafe.Pointer(cpublickey))
cprivatekey := C.CString(privateKey)
defer C.free(unsafe.Pointer(cprivatekey))
cpassphrase := C.CString(passphrase)
defer C.free(unsafe.Pointer(cpassphrase))
ret := C.git_cred_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
return int(ret), cred
} | [
"func",
"NewCredSshKeyFromMemory",
"(",
"username",
"string",
",",
"publicKey",
"string",
",",
"privateKey",
"string",
",",
"passphrase",
"string",
")",
"(",
"int",
",",
"Cred",
")",
"{",
"cred",
":=",
"Cred",
"{",
"}",
"\n",
"cusername",
":=",
"C",
".",
... | // NewCredSshKeyFromMemory creates new ssh credentials using the publicKey and privateKey
// arguments as the values for the public and private keys. | [
"NewCredSshKeyFromMemory",
"creates",
"new",
"ssh",
"credentials",
"using",
"the",
"publicKey",
"and",
"privateKey",
"arguments",
"as",
"the",
"values",
"for",
"the",
"public",
"and",
"private",
"keys",
"."
] | bf1e8a4338822ad2539a3876f58b15b590eb9e1f | https://github.com/libgit2/git2go/blob/bf1e8a4338822ad2539a3876f58b15b590eb9e1f/credentials.go#L65-L77 | train |
uber-go/fx | shutdown.go | Shutdown | func (s *shutdowner) Shutdown(opts ...ShutdownOption) error {
return s.app.broadcastSignal(syscall.SIGTERM)
} | go | func (s *shutdowner) Shutdown(opts ...ShutdownOption) error {
return s.app.broadcastSignal(syscall.SIGTERM)
} | [
"func",
"(",
"s",
"*",
"shutdowner",
")",
"Shutdown",
"(",
"opts",
"...",
"ShutdownOption",
")",
"error",
"{",
"return",
"s",
".",
"app",
".",
"broadcastSignal",
"(",
"syscall",
".",
"SIGTERM",
")",
"\n",
"}"
] | // Shutdown broadcasts a signal to all of the application's Done channels
// and begins the Stop process. | [
"Shutdown",
"broadcasts",
"a",
"signal",
"to",
"all",
"of",
"the",
"application",
"s",
"Done",
"channels",
"and",
"begins",
"the",
"Stop",
"process",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/shutdown.go#L49-L51 | train |
uber-go/fx | internal/lifecycle/lifecycle.go | New | func New(logger *fxlog.Logger) *Lifecycle {
if logger == nil {
logger = fxlog.New()
}
return &Lifecycle{logger: logger}
} | go | func New(logger *fxlog.Logger) *Lifecycle {
if logger == nil {
logger = fxlog.New()
}
return &Lifecycle{logger: logger}
} | [
"func",
"New",
"(",
"logger",
"*",
"fxlog",
".",
"Logger",
")",
"*",
"Lifecycle",
"{",
"if",
"logger",
"==",
"nil",
"{",
"logger",
"=",
"fxlog",
".",
"New",
"(",
")",
"\n",
"}",
"\n",
"return",
"&",
"Lifecycle",
"{",
"logger",
":",
"logger",
"}",
... | // New constructs a new Lifecycle. | [
"New",
"constructs",
"a",
"new",
"Lifecycle",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/lifecycle/lifecycle.go#L47-L52 | train |
uber-go/fx | internal/lifecycle/lifecycle.go | Append | func (l *Lifecycle) Append(hook Hook) {
hook.caller = fxreflect.Caller()
l.hooks = append(l.hooks, hook)
} | go | func (l *Lifecycle) Append(hook Hook) {
hook.caller = fxreflect.Caller()
l.hooks = append(l.hooks, hook)
} | [
"func",
"(",
"l",
"*",
"Lifecycle",
")",
"Append",
"(",
"hook",
"Hook",
")",
"{",
"hook",
".",
"caller",
"=",
"fxreflect",
".",
"Caller",
"(",
")",
"\n",
"l",
".",
"hooks",
"=",
"append",
"(",
"l",
".",
"hooks",
",",
"hook",
")",
"\n",
"}"
] | // Append adds a Hook to the lifecycle. | [
"Append",
"adds",
"a",
"Hook",
"to",
"the",
"lifecycle",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/lifecycle/lifecycle.go#L55-L58 | train |
uber-go/fx | internal/lifecycle/lifecycle.go | Start | func (l *Lifecycle) Start(ctx context.Context) error {
for _, hook := range l.hooks {
if hook.OnStart != nil {
l.logger.Printf("START\t\t%s()", hook.caller)
if err := hook.OnStart(ctx); err != nil {
return err
}
}
l.numStarted++
}
return nil
} | go | func (l *Lifecycle) Start(ctx context.Context) error {
for _, hook := range l.hooks {
if hook.OnStart != nil {
l.logger.Printf("START\t\t%s()", hook.caller)
if err := hook.OnStart(ctx); err != nil {
return err
}
}
l.numStarted++
}
return nil
} | [
"func",
"(",
"l",
"*",
"Lifecycle",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"for",
"_",
",",
"hook",
":=",
"range",
"l",
".",
"hooks",
"{",
"if",
"hook",
".",
"OnStart",
"!=",
"nil",
"{",
"l",
".",
"logger",
".",
... | // Start runs all OnStart hooks, returning immediately if it encounters an
// error. | [
"Start",
"runs",
"all",
"OnStart",
"hooks",
"returning",
"immediately",
"if",
"it",
"encounters",
"an",
"error",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/lifecycle/lifecycle.go#L62-L73 | train |
uber-go/fx | internal/lifecycle/lifecycle.go | Stop | func (l *Lifecycle) Stop(ctx context.Context) error {
var errs []error
// Run backward from last successful OnStart.
for ; l.numStarted > 0; l.numStarted-- {
hook := l.hooks[l.numStarted-1]
if hook.OnStop == nil {
continue
}
l.logger.Printf("STOP\t\t%s()", hook.caller)
if err := hook.OnStop(ctx); err != nil {
// For best-effort cleanup, keep going after errors.
errs = append(errs, err)
}
}
return multierr.Combine(errs...)
} | go | func (l *Lifecycle) Stop(ctx context.Context) error {
var errs []error
// Run backward from last successful OnStart.
for ; l.numStarted > 0; l.numStarted-- {
hook := l.hooks[l.numStarted-1]
if hook.OnStop == nil {
continue
}
l.logger.Printf("STOP\t\t%s()", hook.caller)
if err := hook.OnStop(ctx); err != nil {
// For best-effort cleanup, keep going after errors.
errs = append(errs, err)
}
}
return multierr.Combine(errs...)
} | [
"func",
"(",
"l",
"*",
"Lifecycle",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"var",
"errs",
"[",
"]",
"error",
"\n",
"// Run backward from last successful OnStart.",
"for",
";",
"l",
".",
"numStarted",
">",
"0",
";",
"l",
".... | // Stop runs any OnStop hooks whose OnStart counterpart succeeded. OnStop
// hooks run in reverse order. | [
"Stop",
"runs",
"any",
"OnStop",
"hooks",
"whose",
"OnStart",
"counterpart",
"succeeded",
".",
"OnStop",
"hooks",
"run",
"in",
"reverse",
"order",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/lifecycle/lifecycle.go#L77-L92 | train |
uber-go/fx | internal/fxlog/fxlog.go | PrintProvide | func (l *Logger) PrintProvide(t interface{}) {
for _, rtype := range fxreflect.ReturnTypes(t) {
l.Printf("PROVIDE\t%s <= %s", rtype, fxreflect.FuncName(t))
}
} | go | func (l *Logger) PrintProvide(t interface{}) {
for _, rtype := range fxreflect.ReturnTypes(t) {
l.Printf("PROVIDE\t%s <= %s", rtype, fxreflect.FuncName(t))
}
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"PrintProvide",
"(",
"t",
"interface",
"{",
"}",
")",
"{",
"for",
"_",
",",
"rtype",
":=",
"range",
"fxreflect",
".",
"ReturnTypes",
"(",
"t",
")",
"{",
"l",
".",
"Printf",
"(",
"\"",
"\\t",
"\"",
",",
"rtype... | // PrintProvide logs a type provided into the dig.Container. | [
"PrintProvide",
"logs",
"a",
"type",
"provided",
"into",
"the",
"dig",
".",
"Container",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxlog/fxlog.go#L55-L59 | train |
uber-go/fx | internal/fxlog/fxlog.go | PrintSignal | func (l *Logger) PrintSignal(signal os.Signal) {
l.Printf(strings.ToUpper(signal.String()))
} | go | func (l *Logger) PrintSignal(signal os.Signal) {
l.Printf(strings.ToUpper(signal.String()))
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"PrintSignal",
"(",
"signal",
"os",
".",
"Signal",
")",
"{",
"l",
".",
"Printf",
"(",
"strings",
".",
"ToUpper",
"(",
"signal",
".",
"String",
"(",
")",
")",
")",
"\n",
"}"
] | // PrintSignal logs an os.Signal. | [
"PrintSignal",
"logs",
"an",
"os",
".",
"Signal",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxlog/fxlog.go#L62-L64 | train |
uber-go/fx | internal/fxlog/fxlog.go | Panic | func (l *Logger) Panic(err error) {
l.Printer.Printf(prepend(err.Error()))
panic(err)
} | go | func (l *Logger) Panic(err error) {
l.Printer.Printf(prepend(err.Error()))
panic(err)
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Panic",
"(",
"err",
"error",
")",
"{",
"l",
".",
"Printer",
".",
"Printf",
"(",
"prepend",
"(",
"err",
".",
"Error",
"(",
")",
")",
")",
"\n",
"panic",
"(",
"err",
")",
"\n",
"}"
] | // Panic logs an Fx line then panics. | [
"Panic",
"logs",
"an",
"Fx",
"line",
"then",
"panics",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxlog/fxlog.go#L67-L70 | train |
uber-go/fx | internal/fxlog/fxlog.go | Fatalf | func (l *Logger) Fatalf(format string, v ...interface{}) {
l.Printer.Printf(prepend(format), v...)
_exit()
} | go | func (l *Logger) Fatalf(format string, v ...interface{}) {
l.Printer.Printf(prepend(format), v...)
_exit()
} | [
"func",
"(",
"l",
"*",
"Logger",
")",
"Fatalf",
"(",
"format",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Printer",
".",
"Printf",
"(",
"prepend",
"(",
"format",
")",
",",
"v",
"...",
")",
"\n",
"_exit",
"(",
")",
"\... | // Fatalf logs an Fx line then fatals. | [
"Fatalf",
"logs",
"an",
"Fx",
"line",
"then",
"fatals",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxlog/fxlog.go#L73-L76 | train |
uber-go/fx | internal/fxreflect/fxreflect.go | ReturnTypes | func ReturnTypes(t interface{}) []string {
if reflect.TypeOf(t).Kind() != reflect.Func {
// Invalid provide, will be logged as an error.
return []string{}
}
rtypes := []string{}
ft := reflect.ValueOf(t).Type()
for i := 0; i < ft.NumOut(); i++ {
t := ft.Out(i)
traverseOuts(key{t: t}, func(s string) {
rtypes = append(rtypes, s)
})
}
return rtypes
} | go | func ReturnTypes(t interface{}) []string {
if reflect.TypeOf(t).Kind() != reflect.Func {
// Invalid provide, will be logged as an error.
return []string{}
}
rtypes := []string{}
ft := reflect.ValueOf(t).Type()
for i := 0; i < ft.NumOut(); i++ {
t := ft.Out(i)
traverseOuts(key{t: t}, func(s string) {
rtypes = append(rtypes, s)
})
}
return rtypes
} | [
"func",
"ReturnTypes",
"(",
"t",
"interface",
"{",
"}",
")",
"[",
"]",
"string",
"{",
"if",
"reflect",
".",
"TypeOf",
"(",
"t",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Func",
"{",
"// Invalid provide, will be logged as an error.",
"return",
"[",... | // ReturnTypes takes a func and returns a slice of string'd types. | [
"ReturnTypes",
"takes",
"a",
"func",
"and",
"returns",
"a",
"slice",
"of",
"string",
"d",
"types",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxreflect/fxreflect.go#L38-L56 | train |
uber-go/fx | internal/fxreflect/fxreflect.go | sanitize | func sanitize(function string) string {
// Use the stdlib to un-escape any package import paths which can happen
// in the case of the "dot-git" postfix. Seems like a bug in stdlib =/
if unescaped, err := url.QueryUnescape(function); err == nil {
function = unescaped
}
// strip everything prior to the vendor
return vendorRe.ReplaceAllString(function, "vendor/")
} | go | func sanitize(function string) string {
// Use the stdlib to un-escape any package import paths which can happen
// in the case of the "dot-git" postfix. Seems like a bug in stdlib =/
if unescaped, err := url.QueryUnescape(function); err == nil {
function = unescaped
}
// strip everything prior to the vendor
return vendorRe.ReplaceAllString(function, "vendor/")
} | [
"func",
"sanitize",
"(",
"function",
"string",
")",
"string",
"{",
"// Use the stdlib to un-escape any package import paths which can happen",
"// in the case of the \"dot-git\" postfix. Seems like a bug in stdlib =/",
"if",
"unescaped",
",",
"err",
":=",
"url",
".",
"QueryUnescape... | // sanitize makes the function name suitable for logging display. It removes
// url-encoded elements from the `dot.git` package names and shortens the
// vendored paths. | [
"sanitize",
"makes",
"the",
"function",
"name",
"suitable",
"for",
"logging",
"display",
".",
"It",
"removes",
"url",
"-",
"encoded",
"elements",
"from",
"the",
"dot",
".",
"git",
"package",
"names",
"and",
"shortens",
"the",
"vendored",
"paths",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxreflect/fxreflect.go#L104-L113 | train |
uber-go/fx | internal/fxreflect/fxreflect.go | Caller | func Caller() string {
// Ascend at most 8 frames looking for a caller outside fx.
pcs := make([]uintptr, 8)
// Don't include this frame.
n := runtime.Callers(2, pcs)
if n == 0 {
return "n/a"
}
frames := runtime.CallersFrames(pcs)
for f, more := frames.Next(); more; f, more = frames.Next() {
if shouldIgnoreFrame(f) {
continue
}
return sanitize(f.Function)
}
return "n/a"
} | go | func Caller() string {
// Ascend at most 8 frames looking for a caller outside fx.
pcs := make([]uintptr, 8)
// Don't include this frame.
n := runtime.Callers(2, pcs)
if n == 0 {
return "n/a"
}
frames := runtime.CallersFrames(pcs)
for f, more := frames.Next(); more; f, more = frames.Next() {
if shouldIgnoreFrame(f) {
continue
}
return sanitize(f.Function)
}
return "n/a"
} | [
"func",
"Caller",
"(",
")",
"string",
"{",
"// Ascend at most 8 frames looking for a caller outside fx.",
"pcs",
":=",
"make",
"(",
"[",
"]",
"uintptr",
",",
"8",
")",
"\n\n",
"// Don't include this frame.",
"n",
":=",
"runtime",
".",
"Callers",
"(",
"2",
",",
"... | // Caller returns the formatted calling func name | [
"Caller",
"returns",
"the",
"formatted",
"calling",
"func",
"name"
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxreflect/fxreflect.go#L116-L134 | train |
uber-go/fx | internal/fxreflect/fxreflect.go | FuncName | func FuncName(fn interface{}) string {
fnV := reflect.ValueOf(fn)
if fnV.Kind() != reflect.Func {
return "n/a"
}
function := runtime.FuncForPC(fnV.Pointer()).Name()
return fmt.Sprintf("%s()", sanitize(function))
} | go | func FuncName(fn interface{}) string {
fnV := reflect.ValueOf(fn)
if fnV.Kind() != reflect.Func {
return "n/a"
}
function := runtime.FuncForPC(fnV.Pointer()).Name()
return fmt.Sprintf("%s()", sanitize(function))
} | [
"func",
"FuncName",
"(",
"fn",
"interface",
"{",
"}",
")",
"string",
"{",
"fnV",
":=",
"reflect",
".",
"ValueOf",
"(",
"fn",
")",
"\n",
"if",
"fnV",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Func",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n"... | // FuncName returns a funcs formatted name | [
"FuncName",
"returns",
"a",
"funcs",
"formatted",
"name"
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxreflect/fxreflect.go#L137-L145 | train |
uber-go/fx | internal/fxreflect/fxreflect.go | shouldIgnoreFrame | func shouldIgnoreFrame(f runtime.Frame) bool {
if strings.Contains(f.File, "_test.go") {
return false
}
if strings.Contains(f.File, "go.uber.org/fx") {
return true
}
return false
} | go | func shouldIgnoreFrame(f runtime.Frame) bool {
if strings.Contains(f.File, "_test.go") {
return false
}
if strings.Contains(f.File, "go.uber.org/fx") {
return true
}
return false
} | [
"func",
"shouldIgnoreFrame",
"(",
"f",
"runtime",
".",
"Frame",
")",
"bool",
"{",
"if",
"strings",
".",
"Contains",
"(",
"f",
".",
"File",
",",
"\"",
"\"",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"f",
".... | // Ascend the call stack until we leave the Fx production code. This allows us
// to avoid hard-coding a frame skip, which makes this code work well even
// when it's wrapped. | [
"Ascend",
"the",
"call",
"stack",
"until",
"we",
"leave",
"the",
"Fx",
"production",
"code",
".",
"This",
"allows",
"us",
"to",
"avoid",
"hard",
"-",
"coding",
"a",
"frame",
"skip",
"which",
"makes",
"this",
"code",
"work",
"well",
"even",
"when",
"it",
... | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/internal/fxreflect/fxreflect.go#L155-L163 | train |
uber-go/fx | app.go | Error | func Error(errs ...error) Option {
return optionFunc(func(app *App) {
app.err = multierr.Append(app.err, multierr.Combine(errs...))
})
} | go | func Error(errs ...error) Option {
return optionFunc(func(app *App) {
app.err = multierr.Append(app.err, multierr.Combine(errs...))
})
} | [
"func",
"Error",
"(",
"errs",
"...",
"error",
")",
"Option",
"{",
"return",
"optionFunc",
"(",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"app",
".",
"err",
"=",
"multierr",
".",
"Append",
"(",
"app",
".",
"err",
",",
"multierr",
".",
"Combine",
"("... | // Error registers any number of errors with the application to short-circuit
// startup. If more than one error is given, the errors are combined into a
// single error.
//
// Similar to invocations, errors are applied in order. All Provide and Invoke
// options registered before or after an Error option will not be applied. | [
"Error",
"registers",
"any",
"number",
"of",
"errors",
"with",
"the",
"application",
"to",
"short",
"-",
"circuit",
"startup",
".",
"If",
"more",
"than",
"one",
"error",
"is",
"given",
"the",
"errors",
"are",
"combined",
"into",
"a",
"single",
"error",
"."... | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L149-L153 | train |
uber-go/fx | app.go | StartTimeout | func StartTimeout(v time.Duration) Option {
return optionFunc(func(app *App) {
app.startTimeout = v
})
} | go | func StartTimeout(v time.Duration) Option {
return optionFunc(func(app *App) {
app.startTimeout = v
})
} | [
"func",
"StartTimeout",
"(",
"v",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"optionFunc",
"(",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"app",
".",
"startTimeout",
"=",
"v",
"\n",
"}",
")",
"\n",
"}"
] | // StartTimeout changes the application's start timeout. | [
"StartTimeout",
"changes",
"the",
"application",
"s",
"start",
"timeout",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L207-L211 | train |
uber-go/fx | app.go | StopTimeout | func StopTimeout(v time.Duration) Option {
return optionFunc(func(app *App) {
app.stopTimeout = v
})
} | go | func StopTimeout(v time.Duration) Option {
return optionFunc(func(app *App) {
app.stopTimeout = v
})
} | [
"func",
"StopTimeout",
"(",
"v",
"time",
".",
"Duration",
")",
"Option",
"{",
"return",
"optionFunc",
"(",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"app",
".",
"stopTimeout",
"=",
"v",
"\n",
"}",
")",
"\n",
"}"
] | // StopTimeout changes the application's stop timeout. | [
"StopTimeout",
"changes",
"the",
"application",
"s",
"stop",
"timeout",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L214-L218 | train |
uber-go/fx | app.go | Logger | func Logger(p Printer) Option {
return optionFunc(func(app *App) {
app.logger = &fxlog.Logger{Printer: p}
app.lifecycle = &lifecycleWrapper{lifecycle.New(app.logger)}
})
} | go | func Logger(p Printer) Option {
return optionFunc(func(app *App) {
app.logger = &fxlog.Logger{Printer: p}
app.lifecycle = &lifecycleWrapper{lifecycle.New(app.logger)}
})
} | [
"func",
"Logger",
"(",
"p",
"Printer",
")",
"Option",
"{",
"return",
"optionFunc",
"(",
"func",
"(",
"app",
"*",
"App",
")",
"{",
"app",
".",
"logger",
"=",
"&",
"fxlog",
".",
"Logger",
"{",
"Printer",
":",
"p",
"}",
"\n",
"app",
".",
"lifecycle",
... | // Logger redirects the application's log output to the provided printer. | [
"Logger",
"redirects",
"the",
"application",
"s",
"log",
"output",
"to",
"the",
"provided",
"printer",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L227-L232 | train |
uber-go/fx | app.go | New | func New(opts ...Option) *App {
logger := fxlog.New()
lc := &lifecycleWrapper{lifecycle.New(logger)}
app := &App{
container: dig.New(dig.DeferAcyclicVerification()),
lifecycle: lc,
logger: logger,
startTimeout: DefaultTimeout,
stopTimeout: DefaultTimeout,
}
for _, opt := range opts {
opt.apply(app)
}
for _, p := range app.provides {
app.provide(p)
}
app.provide(func() Lifecycle { return app.lifecycle })
app.provide(app.shutdowner)
app.provide(app.dotGraph)
if app.err != nil {
app.logger.Printf("Error after options were applied: %v", app.err)
return app
}
if err := app.executeInvokes(); err != nil {
app.err = err
if dig.CanVisualizeError(err) {
var b bytes.Buffer
dig.Visualize(app.container, &b, dig.VisualizeError(err))
err = errorWithGraph{
graph: b.String(),
err: err,
}
}
errorHandlerList(app.errorHooks).HandleError(err)
}
return app
} | go | func New(opts ...Option) *App {
logger := fxlog.New()
lc := &lifecycleWrapper{lifecycle.New(logger)}
app := &App{
container: dig.New(dig.DeferAcyclicVerification()),
lifecycle: lc,
logger: logger,
startTimeout: DefaultTimeout,
stopTimeout: DefaultTimeout,
}
for _, opt := range opts {
opt.apply(app)
}
for _, p := range app.provides {
app.provide(p)
}
app.provide(func() Lifecycle { return app.lifecycle })
app.provide(app.shutdowner)
app.provide(app.dotGraph)
if app.err != nil {
app.logger.Printf("Error after options were applied: %v", app.err)
return app
}
if err := app.executeInvokes(); err != nil {
app.err = err
if dig.CanVisualizeError(err) {
var b bytes.Buffer
dig.Visualize(app.container, &b, dig.VisualizeError(err))
err = errorWithGraph{
graph: b.String(),
err: err,
}
}
errorHandlerList(app.errorHooks).HandleError(err)
}
return app
} | [
"func",
"New",
"(",
"opts",
"...",
"Option",
")",
"*",
"App",
"{",
"logger",
":=",
"fxlog",
".",
"New",
"(",
")",
"\n",
"lc",
":=",
"&",
"lifecycleWrapper",
"{",
"lifecycle",
".",
"New",
"(",
"logger",
")",
"}",
"\n\n",
"app",
":=",
"&",
"App",
"... | // New creates and initializes an App, immediately executing any functions
// registered via Invoke options. See the documentation of the App struct for
// details on the application's initialization, startup, and shutdown logic. | [
"New",
"creates",
"and",
"initializes",
"an",
"App",
"immediately",
"executing",
"any",
"functions",
"registered",
"via",
"Invoke",
"options",
".",
"See",
"the",
"documentation",
"of",
"the",
"App",
"struct",
"for",
"details",
"on",
"the",
"application",
"s",
... | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L322-L364 | train |
uber-go/fx | app.go | VisualizeError | func VisualizeError(err error) (string, error) {
if e, ok := err.(errWithGraph); ok && e.Graph() != "" {
return string(e.Graph()), nil
}
return "", errors.New("unable to visualize error")
} | go | func VisualizeError(err error) (string, error) {
if e, ok := err.(errWithGraph); ok && e.Graph() != "" {
return string(e.Graph()), nil
}
return "", errors.New("unable to visualize error")
} | [
"func",
"VisualizeError",
"(",
"err",
"error",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"errWithGraph",
")",
";",
"ok",
"&&",
"e",
".",
"Graph",
"(",
")",
"!=",
"\"",
"\"",
"{",
"return",
"string",
... | // VisualizeError returns the visualization of the error if available. | [
"VisualizeError",
"returns",
"the",
"visualization",
"of",
"the",
"error",
"if",
"available",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L391-L396 | train |
uber-go/fx | app.go | Start | func (app *App) Start(ctx context.Context) error {
return withTimeout(ctx, app.start)
} | go | func (app *App) Start(ctx context.Context) error {
return withTimeout(ctx, app.start)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"return",
"withTimeout",
"(",
"ctx",
",",
"app",
".",
"start",
")",
"\n",
"}"
] | // Start kicks off all long-running goroutines, like network servers or
// message queue consumers. It does this by interacting with the application's
// Lifecycle.
//
// By taking a dependency on the Lifecycle type, some of the user-supplied
// functions called during initialization may have registered start and stop
// hooks. Because initialization calls constructors serially and in dependency
// order, hooks are naturally registered in dependency order too.
//
// Start executes all OnStart hooks registered with the application's
// Lifecycle, one at a time and in order. This ensures that each constructor's
// start hooks aren't executed until all its dependencies' start hooks
// complete. If any of the start hooks return an error, Start short-circuits,
// calls Stop, and returns the inciting error.
//
// Note that Start short-circuits immediately if the New constructor
// encountered any errors in application initialization. | [
"Start",
"kicks",
"off",
"all",
"long",
"-",
"running",
"goroutines",
"like",
"network",
"servers",
"or",
"message",
"queue",
"consumers",
".",
"It",
"does",
"this",
"by",
"interacting",
"with",
"the",
"application",
"s",
"Lifecycle",
".",
"By",
"taking",
"a... | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L439-L441 | train |
uber-go/fx | app.go | Stop | func (app *App) Stop(ctx context.Context) error {
return withTimeout(ctx, app.lifecycle.Stop)
} | go | func (app *App) Stop(ctx context.Context) error {
return withTimeout(ctx, app.lifecycle.Stop)
} | [
"func",
"(",
"app",
"*",
"App",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"return",
"withTimeout",
"(",
"ctx",
",",
"app",
".",
"lifecycle",
".",
"Stop",
")",
"\n",
"}"
] | // Stop gracefully stops the application. It executes any registered OnStop
// hooks in reverse order, so that each constructor's stop hooks are called
// before its dependencies' stop hooks.
//
// If the application didn't start cleanly, only hooks whose OnStart phase was
// called are executed. However, all those hooks are executed, even if some
// fail. | [
"Stop",
"gracefully",
"stops",
"the",
"application",
".",
"It",
"executes",
"any",
"registered",
"OnStop",
"hooks",
"in",
"reverse",
"order",
"so",
"that",
"each",
"constructor",
"s",
"stop",
"hooks",
"are",
"called",
"before",
"its",
"dependencies",
"stop",
"... | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L450-L452 | train |
uber-go/fx | app.go | executeInvokes | func (app *App) executeInvokes() error {
// TODO: consider taking a context to limit the time spent running invocations.
var err error
for _, fn := range app.invokes {
fname := fxreflect.FuncName(fn)
app.logger.Printf("INVOKE\t\t%s", fname)
if _, ok := fn.(Option); ok {
err = fmt.Errorf("fx.Option should be passed to fx.New directly, not to fx.Invoke: fx.Invoke received %v", fn)
} else {
err = app.container.Invoke(fn)
}
if err != nil {
app.logger.Printf("Error during %q invoke: %v", fname, err)
break
}
}
return err
} | go | func (app *App) executeInvokes() error {
// TODO: consider taking a context to limit the time spent running invocations.
var err error
for _, fn := range app.invokes {
fname := fxreflect.FuncName(fn)
app.logger.Printf("INVOKE\t\t%s", fname)
if _, ok := fn.(Option); ok {
err = fmt.Errorf("fx.Option should be passed to fx.New directly, not to fx.Invoke: fx.Invoke received %v", fn)
} else {
err = app.container.Invoke(fn)
}
if err != nil {
app.logger.Printf("Error during %q invoke: %v", fname, err)
break
}
}
return err
} | [
"func",
"(",
"app",
"*",
"App",
")",
"executeInvokes",
"(",
")",
"error",
"{",
"// TODO: consider taking a context to limit the time spent running invocations.",
"var",
"err",
"error",
"\n\n",
"for",
"_",
",",
"fn",
":=",
"range",
"app",
".",
"invokes",
"{",
"fnam... | // Execute invokes in order supplied to New, returning the first error
// encountered. | [
"Execute",
"invokes",
"in",
"order",
"supplied",
"to",
"New",
"returning",
"the",
"first",
"error",
"encountered",
"."
] | 544d97a6e020226621cefffcbc38a9e2d320584c | https://github.com/uber-go/fx/blob/544d97a6e020226621cefffcbc38a9e2d320584c/app.go#L541-L562 | train |
fatih/pool | channel.go | put | func (c *channelPool) put(conn net.Conn) error {
if conn == nil {
return errors.New("connection is nil. rejecting")
}
c.mu.RLock()
defer c.mu.RUnlock()
if c.conns == nil {
// pool is closed, close passed connection
return conn.Close()
}
// put the resource back into the pool. If the pool is full, this will
// block and the default case will be executed.
select {
case c.conns <- conn:
return nil
default:
// pool is full, close passed connection
return conn.Close()
}
} | go | func (c *channelPool) put(conn net.Conn) error {
if conn == nil {
return errors.New("connection is nil. rejecting")
}
c.mu.RLock()
defer c.mu.RUnlock()
if c.conns == nil {
// pool is closed, close passed connection
return conn.Close()
}
// put the resource back into the pool. If the pool is full, this will
// block and the default case will be executed.
select {
case c.conns <- conn:
return nil
default:
// pool is full, close passed connection
return conn.Close()
}
} | [
"func",
"(",
"c",
"*",
"channelPool",
")",
"put",
"(",
"conn",
"net",
".",
"Conn",
")",
"error",
"{",
"if",
"conn",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"RLock",
"(",
... | // put puts the connection back to the pool. If the pool is full or closed,
// conn is simply closed. A nil conn will be rejected. | [
"put",
"puts",
"the",
"connection",
"back",
"to",
"the",
"pool",
".",
"If",
"the",
"pool",
"is",
"full",
"or",
"closed",
"conn",
"is",
"simply",
"closed",
".",
"A",
"nil",
"conn",
"will",
"be",
"rejected",
"."
] | d817ebe42acfb2147a68af2007324c3492260c4a | https://github.com/fatih/pool/blob/d817ebe42acfb2147a68af2007324c3492260c4a/channel.go#L91-L113 | train |
fatih/pool | conn.go | wrapConn | func (c *channelPool) wrapConn(conn net.Conn) net.Conn {
p := &PoolConn{c: c}
p.Conn = conn
return p
} | go | func (c *channelPool) wrapConn(conn net.Conn) net.Conn {
p := &PoolConn{c: c}
p.Conn = conn
return p
} | [
"func",
"(",
"c",
"*",
"channelPool",
")",
"wrapConn",
"(",
"conn",
"net",
".",
"Conn",
")",
"net",
".",
"Conn",
"{",
"p",
":=",
"&",
"PoolConn",
"{",
"c",
":",
"c",
"}",
"\n",
"p",
".",
"Conn",
"=",
"conn",
"\n",
"return",
"p",
"\n",
"}"
] | // newConn wraps a standard net.Conn to a poolConn net.Conn. | [
"newConn",
"wraps",
"a",
"standard",
"net",
".",
"Conn",
"to",
"a",
"poolConn",
"net",
".",
"Conn",
"."
] | d817ebe42acfb2147a68af2007324c3492260c4a | https://github.com/fatih/pool/blob/d817ebe42acfb2147a68af2007324c3492260c4a/conn.go#L39-L43 | train |
imroc/req | resp.go | String | func (r *Resp) String() string {
data, _ := r.ToBytes()
return string(data)
} | go | func (r *Resp) String() string {
data, _ := r.ToBytes()
return string(data)
} | [
"func",
"(",
"r",
"*",
"Resp",
")",
"String",
"(",
")",
"string",
"{",
"data",
",",
"_",
":=",
"r",
".",
"ToBytes",
"(",
")",
"\n",
"return",
"string",
"(",
"data",
")",
"\n",
"}"
] | // String returns response body as string | [
"String",
"returns",
"response",
"body",
"as",
"string"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/resp.go#L66-L69 | train |
imroc/req | resp.go | ToString | func (r *Resp) ToString() (string, error) {
data, err := r.ToBytes()
return string(data), err
} | go | func (r *Resp) ToString() (string, error) {
data, err := r.ToBytes()
return string(data), err
} | [
"func",
"(",
"r",
"*",
"Resp",
")",
"ToString",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"r",
".",
"ToBytes",
"(",
")",
"\n",
"return",
"string",
"(",
"data",
")",
",",
"err",
"\n",
"}"
] | // ToString returns response body as string,
// return error if error happend when reading
// the response body | [
"ToString",
"returns",
"response",
"body",
"as",
"string",
"return",
"error",
"if",
"error",
"happend",
"when",
"reading",
"the",
"response",
"body"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/resp.go#L74-L77 | train |
imroc/req | resp.go | ToJSON | func (r *Resp) ToJSON(v interface{}) error {
data, err := r.ToBytes()
if err != nil {
return err
}
return json.Unmarshal(data, v)
} | go | func (r *Resp) ToJSON(v interface{}) error {
data, err := r.ToBytes()
if err != nil {
return err
}
return json.Unmarshal(data, v)
} | [
"func",
"(",
"r",
"*",
"Resp",
")",
"ToJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"data",
",",
"err",
":=",
"r",
".",
"ToBytes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"json",
... | // ToJSON convert json response body to struct or map | [
"ToJSON",
"convert",
"json",
"response",
"body",
"to",
"struct",
"or",
"map"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/resp.go#L80-L86 | train |
imroc/req | resp.go | ToXML | func (r *Resp) ToXML(v interface{}) error {
data, err := r.ToBytes()
if err != nil {
return err
}
return xml.Unmarshal(data, v)
} | go | func (r *Resp) ToXML(v interface{}) error {
data, err := r.ToBytes()
if err != nil {
return err
}
return xml.Unmarshal(data, v)
} | [
"func",
"(",
"r",
"*",
"Resp",
")",
"ToXML",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"data",
",",
"err",
":=",
"r",
".",
"ToBytes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"xml",
... | // ToXML convert xml response body to struct or map | [
"ToXML",
"convert",
"xml",
"response",
"body",
"to",
"struct",
"or",
"map"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/resp.go#L89-L95 | train |
imroc/req | resp.go | ToFile | func (r *Resp) ToFile(name string) error {
//TODO set name to the suffix of url path if name == ""
file, err := os.Create(name)
if err != nil {
return err
}
defer file.Close()
if r.respBody != nil {
_, err = file.Write(r.respBody)
return err
}
if r.downloadProgress != nil && r.resp.ContentLength > 0 {
return r.download(file)
}
defer r.resp.Body.Close()
_, err = io.Copy(file, r.resp.Body)
return err
} | go | func (r *Resp) ToFile(name string) error {
//TODO set name to the suffix of url path if name == ""
file, err := os.Create(name)
if err != nil {
return err
}
defer file.Close()
if r.respBody != nil {
_, err = file.Write(r.respBody)
return err
}
if r.downloadProgress != nil && r.resp.ContentLength > 0 {
return r.download(file)
}
defer r.resp.Body.Close()
_, err = io.Copy(file, r.resp.Body)
return err
} | [
"func",
"(",
"r",
"*",
"Resp",
")",
"ToFile",
"(",
"name",
"string",
")",
"error",
"{",
"//TODO set name to the suffix of url path if name == \"\"",
"file",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | // ToFile download the response body to file with optional download callback | [
"ToFile",
"download",
"the",
"response",
"body",
"to",
"file",
"with",
"optional",
"download",
"callback"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/resp.go#L98-L118 | train |
imroc/req | resp.go | Format | func (r *Resp) Format(s fmt.State, verb rune) {
if r == nil || r.req == nil {
return
}
if s.Flag('+') { // include header and format pretty.
fmt.Fprint(s, r.Dump())
} else if s.Flag('-') { // keep all informations in one line.
r.miniFormat(s)
} else { // auto
r.autoFormat(s)
}
} | go | func (r *Resp) Format(s fmt.State, verb rune) {
if r == nil || r.req == nil {
return
}
if s.Flag('+') { // include header and format pretty.
fmt.Fprint(s, r.Dump())
} else if s.Flag('-') { // keep all informations in one line.
r.miniFormat(s)
} else { // auto
r.autoFormat(s)
}
} | [
"func",
"(",
"r",
"*",
"Resp",
")",
"Format",
"(",
"s",
"fmt",
".",
"State",
",",
"verb",
"rune",
")",
"{",
"if",
"r",
"==",
"nil",
"||",
"r",
".",
"req",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"s",
".",
"Flag",
"(",
"'+'",
")",... | // Format fort the response | [
"Format",
"fort",
"the",
"response"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/resp.go#L204-L215 | train |
imroc/req | setting.go | newClient | func newClient() *http.Client {
jar, _ := cookiejar.New(nil)
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
return &http.Client{
Jar: jar,
Transport: transport,
Timeout: 2 * time.Minute,
}
} | go | func newClient() *http.Client {
jar, _ := cookiejar.New(nil)
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
return &http.Client{
Jar: jar,
Transport: transport,
Timeout: 2 * time.Minute,
}
} | [
"func",
"newClient",
"(",
")",
"*",
"http",
".",
"Client",
"{",
"jar",
",",
"_",
":=",
"cookiejar",
".",
"New",
"(",
"nil",
")",
"\n",
"transport",
":=",
"&",
"http",
".",
"Transport",
"{",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"Dia... | // create a default client | [
"create",
"a",
"default",
"client"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/setting.go#L14-L33 | train |
imroc/req | setting.go | Client | func (r *Req) Client() *http.Client {
if r.client == nil {
r.client = newClient()
}
return r.client
} | go | func (r *Req) Client() *http.Client {
if r.client == nil {
r.client = newClient()
}
return r.client
} | [
"func",
"(",
"r",
"*",
"Req",
")",
"Client",
"(",
")",
"*",
"http",
".",
"Client",
"{",
"if",
"r",
".",
"client",
"==",
"nil",
"{",
"r",
".",
"client",
"=",
"newClient",
"(",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"client",
"\n",
"}"
] | // Client return the default underlying http client | [
"Client",
"return",
"the",
"default",
"underlying",
"http",
"client"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/setting.go#L36-L41 | train |
imroc/req | setting.go | EnableInsecureTLS | func (r *Req) EnableInsecureTLS(enable bool) {
trans := r.getTransport()
if trans == nil {
return
}
if trans.TLSClientConfig == nil {
trans.TLSClientConfig = &tls.Config{}
}
trans.TLSClientConfig.InsecureSkipVerify = enable
} | go | func (r *Req) EnableInsecureTLS(enable bool) {
trans := r.getTransport()
if trans == nil {
return
}
if trans.TLSClientConfig == nil {
trans.TLSClientConfig = &tls.Config{}
}
trans.TLSClientConfig.InsecureSkipVerify = enable
} | [
"func",
"(",
"r",
"*",
"Req",
")",
"EnableInsecureTLS",
"(",
"enable",
"bool",
")",
"{",
"trans",
":=",
"r",
".",
"getTransport",
"(",
")",
"\n",
"if",
"trans",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"trans",
".",
"TLSClientConfig",
"==",... | // EnableInsecureTLS allows insecure https | [
"EnableInsecureTLS",
"allows",
"insecure",
"https"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/setting.go#L84-L93 | train |
imroc/req | setting.go | EnableCookie | func (r *Req) EnableCookie(enable bool) {
if enable {
jar, _ := cookiejar.New(nil)
r.Client().Jar = jar
} else {
r.Client().Jar = nil
}
} | go | func (r *Req) EnableCookie(enable bool) {
if enable {
jar, _ := cookiejar.New(nil)
r.Client().Jar = jar
} else {
r.Client().Jar = nil
}
} | [
"func",
"(",
"r",
"*",
"Req",
")",
"EnableCookie",
"(",
"enable",
"bool",
")",
"{",
"if",
"enable",
"{",
"jar",
",",
"_",
":=",
"cookiejar",
".",
"New",
"(",
"nil",
")",
"\n",
"r",
".",
"Client",
"(",
")",
".",
"Jar",
"=",
"jar",
"\n",
"}",
"... | // EnableCookieenable or disable cookie manager | [
"EnableCookieenable",
"or",
"disable",
"cookie",
"manager"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/setting.go#L100-L107 | train |
imroc/req | setting.go | SetTimeout | func (r *Req) SetTimeout(d time.Duration) {
r.Client().Timeout = d
} | go | func (r *Req) SetTimeout(d time.Duration) {
r.Client().Timeout = d
} | [
"func",
"(",
"r",
"*",
"Req",
")",
"SetTimeout",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"r",
".",
"Client",
"(",
")",
".",
"Timeout",
"=",
"d",
"\n",
"}"
] | // SetTimeout sets the timeout for every request | [
"SetTimeout",
"sets",
"the",
"timeout",
"for",
"every",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/setting.go#L115-L117 | train |
imroc/req | setting.go | SetProxyUrl | func (r *Req) SetProxyUrl(rawurl string) error {
trans := r.getTransport()
if trans == nil {
return errors.New("req: no transport")
}
u, err := url.Parse(rawurl)
if err != nil {
return err
}
trans.Proxy = http.ProxyURL(u)
return nil
} | go | func (r *Req) SetProxyUrl(rawurl string) error {
trans := r.getTransport()
if trans == nil {
return errors.New("req: no transport")
}
u, err := url.Parse(rawurl)
if err != nil {
return err
}
trans.Proxy = http.ProxyURL(u)
return nil
} | [
"func",
"(",
"r",
"*",
"Req",
")",
"SetProxyUrl",
"(",
"rawurl",
"string",
")",
"error",
"{",
"trans",
":=",
"r",
".",
"getTransport",
"(",
")",
"\n",
"if",
"trans",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}... | // SetProxyUrl set the simple proxy with fixed proxy url | [
"SetProxyUrl",
"set",
"the",
"simple",
"proxy",
"with",
"fixed",
"proxy",
"url"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/setting.go#L125-L136 | train |
imroc/req | setting.go | SetXMLIndent | func (r *Req) SetXMLIndent(prefix, indent string) {
opts := r.getXMLEncOpts()
opts.prefix = prefix
opts.indent = indent
} | go | func (r *Req) SetXMLIndent(prefix, indent string) {
opts := r.getXMLEncOpts()
opts.prefix = prefix
opts.indent = indent
} | [
"func",
"(",
"r",
"*",
"Req",
")",
"SetXMLIndent",
"(",
"prefix",
",",
"indent",
"string",
")",
"{",
"opts",
":=",
"r",
".",
"getXMLEncOpts",
"(",
")",
"\n",
"opts",
".",
"prefix",
"=",
"prefix",
"\n",
"opts",
".",
"indent",
"=",
"indent",
"\n",
"}... | // SetXMLIndent sets the encoder to generate XML in which each element
// begins on a new indented line that starts with prefix and is followed by
// one or more copies of indent according to the nesting depth. | [
"SetXMLIndent",
"sets",
"the",
"encoder",
"to",
"generate",
"XML",
"in",
"which",
"each",
"element",
"begins",
"on",
"a",
"new",
"indented",
"line",
"that",
"starts",
"with",
"prefix",
"and",
"is",
"followed",
"by",
"one",
"or",
"more",
"copies",
"of",
"in... | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/setting.go#L225-L229 | train |
imroc/req | dump.go | Dump | func (r *Resp) Dump() string {
dump := new(dumpBuffer)
if r.r.flag&Lcost != 0 {
dump.WriteString(fmt.Sprint(r.cost))
}
r.dumpRequest(dump)
l := dump.Len()
if l > 0 {
dump.WriteString("=================================")
l = dump.Len()
}
r.dumpResponse(dump)
return dump.String()
} | go | func (r *Resp) Dump() string {
dump := new(dumpBuffer)
if r.r.flag&Lcost != 0 {
dump.WriteString(fmt.Sprint(r.cost))
}
r.dumpRequest(dump)
l := dump.Len()
if l > 0 {
dump.WriteString("=================================")
l = dump.Len()
}
r.dumpResponse(dump)
return dump.String()
} | [
"func",
"(",
"r",
"*",
"Resp",
")",
"Dump",
"(",
")",
"string",
"{",
"dump",
":=",
"new",
"(",
"dumpBuffer",
")",
"\n",
"if",
"r",
".",
"r",
".",
"flag",
"&",
"Lcost",
"!=",
"0",
"{",
"dump",
".",
"WriteString",
"(",
"fmt",
".",
"Sprint",
"(",
... | // Dump dump the request | [
"Dump",
"dump",
"the",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/dump.go#L201-L216 | train |
imroc/req | req.go | Post | func Post(url string, v ...interface{}) (*Resp, error) {
return std.Post(url, v...)
} | go | func Post(url string, v ...interface{}) (*Resp, error) {
return std.Post(url, v...)
} | [
"func",
"Post",
"(",
"url",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Resp",
",",
"error",
")",
"{",
"return",
"std",
".",
"Post",
"(",
"url",
",",
"v",
"...",
")",
"\n",
"}"
] | // Post execute a http POST request | [
"Post",
"execute",
"a",
"http",
"POST",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/req.go#L655-L657 | train |
imroc/req | req.go | Put | func Put(url string, v ...interface{}) (*Resp, error) {
return std.Put(url, v...)
} | go | func Put(url string, v ...interface{}) (*Resp, error) {
return std.Put(url, v...)
} | [
"func",
"Put",
"(",
"url",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Resp",
",",
"error",
")",
"{",
"return",
"std",
".",
"Put",
"(",
"url",
",",
"v",
"...",
")",
"\n",
"}"
] | // Put execute a http PUT request | [
"Put",
"execute",
"a",
"http",
"PUT",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/req.go#L660-L662 | train |
imroc/req | req.go | Head | func Head(url string, v ...interface{}) (*Resp, error) {
return std.Head(url, v...)
} | go | func Head(url string, v ...interface{}) (*Resp, error) {
return std.Head(url, v...)
} | [
"func",
"Head",
"(",
"url",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Resp",
",",
"error",
")",
"{",
"return",
"std",
".",
"Head",
"(",
"url",
",",
"v",
"...",
")",
"\n",
"}"
] | // Head execute a http HEAD request | [
"Head",
"execute",
"a",
"http",
"HEAD",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/req.go#L665-L667 | train |
imroc/req | req.go | Options | func Options(url string, v ...interface{}) (*Resp, error) {
return std.Options(url, v...)
} | go | func Options(url string, v ...interface{}) (*Resp, error) {
return std.Options(url, v...)
} | [
"func",
"Options",
"(",
"url",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Resp",
",",
"error",
")",
"{",
"return",
"std",
".",
"Options",
"(",
"url",
",",
"v",
"...",
")",
"\n",
"}"
] | // Options execute a http OPTIONS request | [
"Options",
"execute",
"a",
"http",
"OPTIONS",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/req.go#L670-L672 | train |
imroc/req | req.go | Delete | func Delete(url string, v ...interface{}) (*Resp, error) {
return std.Delete(url, v...)
} | go | func Delete(url string, v ...interface{}) (*Resp, error) {
return std.Delete(url, v...)
} | [
"func",
"Delete",
"(",
"url",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Resp",
",",
"error",
")",
"{",
"return",
"std",
".",
"Delete",
"(",
"url",
",",
"v",
"...",
")",
"\n",
"}"
] | // Delete execute a http DELETE request | [
"Delete",
"execute",
"a",
"http",
"DELETE",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/req.go#L675-L677 | train |
imroc/req | req.go | Patch | func Patch(url string, v ...interface{}) (*Resp, error) {
return std.Patch(url, v...)
} | go | func Patch(url string, v ...interface{}) (*Resp, error) {
return std.Patch(url, v...)
} | [
"func",
"Patch",
"(",
"url",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Resp",
",",
"error",
")",
"{",
"return",
"std",
".",
"Patch",
"(",
"url",
",",
"v",
"...",
")",
"\n",
"}"
] | // Patch execute a http PATCH request | [
"Patch",
"execute",
"a",
"http",
"PATCH",
"request"
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/req.go#L680-L682 | train |
imroc/req | req.go | Do | func Do(method, url string, v ...interface{}) (*Resp, error) {
return std.Do(method, url, v...)
} | go | func Do(method, url string, v ...interface{}) (*Resp, error) {
return std.Do(method, url, v...)
} | [
"func",
"Do",
"(",
"method",
",",
"url",
"string",
",",
"v",
"...",
"interface",
"{",
"}",
")",
"(",
"*",
"Resp",
",",
"error",
")",
"{",
"return",
"std",
".",
"Do",
"(",
"method",
",",
"url",
",",
"v",
"...",
")",
"\n",
"}"
] | // Do execute request. | [
"Do",
"execute",
"request",
"."
] | b355b6f6842fbda1bee879f2846cb79424cad4de | https://github.com/imroc/req/blob/b355b6f6842fbda1bee879f2846cb79424cad4de/req.go#L685-L687 | train |
armon/go-metrics | circonus/circonus.go | SetGauge | func (s *CirconusSink) SetGauge(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.SetGauge(flatKey, int64(val))
} | go | func (s *CirconusSink) SetGauge(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.SetGauge(flatKey, int64(val))
} | [
"func",
"(",
"s",
"*",
"CirconusSink",
")",
"SetGauge",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
")",
"{",
"flatKey",
":=",
"s",
".",
"flattenKey",
"(",
"key",
")",
"\n",
"s",
".",
"metrics",
".",
"SetGauge",
"(",
"flatKey",
",",
"int... | // SetGauge sets value for a gauge metric | [
"SetGauge",
"sets",
"value",
"for",
"a",
"gauge",
"metric"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/circonus/circonus.go#L60-L63 | train |
armon/go-metrics | circonus/circonus.go | SetGaugeWithLabels | func (s *CirconusSink) SetGaugeWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.SetGauge(flatKey, int64(val))
} | go | func (s *CirconusSink) SetGaugeWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.SetGauge(flatKey, int64(val))
} | [
"func",
"(",
"s",
"*",
"CirconusSink",
")",
"SetGaugeWithLabels",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
",",
"labels",
"[",
"]",
"metrics",
".",
"Label",
")",
"{",
"flatKey",
":=",
"s",
".",
"flattenKeyLabels",
"(",
"key",
",",
"labels... | // SetGaugeWithLabels sets value for a gauge metric with the given labels | [
"SetGaugeWithLabels",
"sets",
"value",
"for",
"a",
"gauge",
"metric",
"with",
"the",
"given",
"labels"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/circonus/circonus.go#L66-L69 | train |
armon/go-metrics | circonus/circonus.go | IncrCounter | func (s *CirconusSink) IncrCounter(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.IncrementByValue(flatKey, uint64(val))
} | go | func (s *CirconusSink) IncrCounter(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.IncrementByValue(flatKey, uint64(val))
} | [
"func",
"(",
"s",
"*",
"CirconusSink",
")",
"IncrCounter",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
")",
"{",
"flatKey",
":=",
"s",
".",
"flattenKey",
"(",
"key",
")",
"\n",
"s",
".",
"metrics",
".",
"IncrementByValue",
"(",
"flatKey",
... | // IncrCounter increments a counter metric | [
"IncrCounter",
"increments",
"a",
"counter",
"metric"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/circonus/circonus.go#L77-L80 | train |
armon/go-metrics | circonus/circonus.go | IncrCounterWithLabels | func (s *CirconusSink) IncrCounterWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.IncrementByValue(flatKey, uint64(val))
} | go | func (s *CirconusSink) IncrCounterWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.IncrementByValue(flatKey, uint64(val))
} | [
"func",
"(",
"s",
"*",
"CirconusSink",
")",
"IncrCounterWithLabels",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
",",
"labels",
"[",
"]",
"metrics",
".",
"Label",
")",
"{",
"flatKey",
":=",
"s",
".",
"flattenKeyLabels",
"(",
"key",
",",
"lab... | // IncrCounterWithLabels increments a counter metric with the given labels | [
"IncrCounterWithLabels",
"increments",
"a",
"counter",
"metric",
"with",
"the",
"given",
"labels"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/circonus/circonus.go#L83-L86 | train |
armon/go-metrics | circonus/circonus.go | AddSample | func (s *CirconusSink) AddSample(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.RecordValue(flatKey, float64(val))
} | go | func (s *CirconusSink) AddSample(key []string, val float32) {
flatKey := s.flattenKey(key)
s.metrics.RecordValue(flatKey, float64(val))
} | [
"func",
"(",
"s",
"*",
"CirconusSink",
")",
"AddSample",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
")",
"{",
"flatKey",
":=",
"s",
".",
"flattenKey",
"(",
"key",
")",
"\n",
"s",
".",
"metrics",
".",
"RecordValue",
"(",
"flatKey",
",",
... | // AddSample adds a sample to a histogram metric | [
"AddSample",
"adds",
"a",
"sample",
"to",
"a",
"histogram",
"metric"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/circonus/circonus.go#L89-L92 | train |
armon/go-metrics | circonus/circonus.go | AddSampleWithLabels | func (s *CirconusSink) AddSampleWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.RecordValue(flatKey, float64(val))
} | go | func (s *CirconusSink) AddSampleWithLabels(key []string, val float32, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.RecordValue(flatKey, float64(val))
} | [
"func",
"(",
"s",
"*",
"CirconusSink",
")",
"AddSampleWithLabels",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
",",
"labels",
"[",
"]",
"metrics",
".",
"Label",
")",
"{",
"flatKey",
":=",
"s",
".",
"flattenKeyLabels",
"(",
"key",
",",
"label... | // AddSampleWithLabels adds a sample to a histogram metric with the given labels | [
"AddSampleWithLabels",
"adds",
"a",
"sample",
"to",
"a",
"histogram",
"metric",
"with",
"the",
"given",
"labels"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/circonus/circonus.go#L95-L98 | train |
armon/go-metrics | statsite.go | NewStatsiteSink | func NewStatsiteSink(addr string) (*StatsiteSink, error) {
s := &StatsiteSink{
addr: addr,
metricQueue: make(chan string, 4096),
}
go s.flushMetrics()
return s, nil
} | go | func NewStatsiteSink(addr string) (*StatsiteSink, error) {
s := &StatsiteSink{
addr: addr,
metricQueue: make(chan string, 4096),
}
go s.flushMetrics()
return s, nil
} | [
"func",
"NewStatsiteSink",
"(",
"addr",
"string",
")",
"(",
"*",
"StatsiteSink",
",",
"error",
")",
"{",
"s",
":=",
"&",
"StatsiteSink",
"{",
"addr",
":",
"addr",
",",
"metricQueue",
":",
"make",
"(",
"chan",
"string",
",",
"4096",
")",
",",
"}",
"\n... | // NewStatsiteSink is used to create a new StatsiteSink | [
"NewStatsiteSink",
"is",
"used",
"to",
"create",
"a",
"new",
"StatsiteSink"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/statsite.go#L34-L41 | train |
armon/go-metrics | datadog/dogstatsd.go | NewDogStatsdSink | func NewDogStatsdSink(addr string, hostName string) (*DogStatsdSink, error) {
client, err := statsd.New(addr)
if err != nil {
return nil, err
}
sink := &DogStatsdSink{
client: client,
hostName: hostName,
propagateHostname: false,
}
return sink, nil
} | go | func NewDogStatsdSink(addr string, hostName string) (*DogStatsdSink, error) {
client, err := statsd.New(addr)
if err != nil {
return nil, err
}
sink := &DogStatsdSink{
client: client,
hostName: hostName,
propagateHostname: false,
}
return sink, nil
} | [
"func",
"NewDogStatsdSink",
"(",
"addr",
"string",
",",
"hostName",
"string",
")",
"(",
"*",
"DogStatsdSink",
",",
"error",
")",
"{",
"client",
",",
"err",
":=",
"statsd",
".",
"New",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"... | // NewDogStatsdSink is used to create a new DogStatsdSink with sane defaults | [
"NewDogStatsdSink",
"is",
"used",
"to",
"create",
"a",
"new",
"DogStatsdSink",
"with",
"sane",
"defaults"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/datadog/dogstatsd.go#L20-L31 | train |
armon/go-metrics | datadog/dogstatsd.go | SetGauge | func (s *DogStatsdSink) SetGauge(key []string, val float32) {
s.SetGaugeWithLabels(key, val, nil)
} | go | func (s *DogStatsdSink) SetGauge(key []string, val float32) {
s.SetGaugeWithLabels(key, val, nil)
} | [
"func",
"(",
"s",
"*",
"DogStatsdSink",
")",
"SetGauge",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
")",
"{",
"s",
".",
"SetGaugeWithLabels",
"(",
"key",
",",
"val",
",",
"nil",
")",
"\n",
"}"
] | // Implementation of methods in the MetricSink interface | [
"Implementation",
"of",
"methods",
"in",
"the",
"MetricSink",
"interface"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/datadog/dogstatsd.go#L86-L88 | train |
armon/go-metrics | inmem_signal.go | NewInmemSignal | func NewInmemSignal(inmem *InmemSink, sig syscall.Signal, w io.Writer) *InmemSignal {
i := &InmemSignal{
signal: sig,
inm: inmem,
w: w,
sigCh: make(chan os.Signal, 1),
stopCh: make(chan struct{}),
}
signal.Notify(i.sigCh, sig)
go i.run()
return i
} | go | func NewInmemSignal(inmem *InmemSink, sig syscall.Signal, w io.Writer) *InmemSignal {
i := &InmemSignal{
signal: sig,
inm: inmem,
w: w,
sigCh: make(chan os.Signal, 1),
stopCh: make(chan struct{}),
}
signal.Notify(i.sigCh, sig)
go i.run()
return i
} | [
"func",
"NewInmemSignal",
"(",
"inmem",
"*",
"InmemSink",
",",
"sig",
"syscall",
".",
"Signal",
",",
"w",
"io",
".",
"Writer",
")",
"*",
"InmemSignal",
"{",
"i",
":=",
"&",
"InmemSignal",
"{",
"signal",
":",
"sig",
",",
"inm",
":",
"inmem",
",",
"w",... | // NewInmemSignal creates a new InmemSignal which listens for a given signal,
// and dumps the current metrics out to a writer | [
"NewInmemSignal",
"creates",
"a",
"new",
"InmemSignal",
"which",
"listens",
"for",
"a",
"given",
"signal",
"and",
"dumps",
"the",
"current",
"metrics",
"out",
"to",
"a",
"writer"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem_signal.go#L29-L40 | train |
armon/go-metrics | inmem_signal.go | Stop | func (i *InmemSignal) Stop() {
i.stopLock.Lock()
defer i.stopLock.Unlock()
if i.stop {
return
}
i.stop = true
close(i.stopCh)
signal.Stop(i.sigCh)
} | go | func (i *InmemSignal) Stop() {
i.stopLock.Lock()
defer i.stopLock.Unlock()
if i.stop {
return
}
i.stop = true
close(i.stopCh)
signal.Stop(i.sigCh)
} | [
"func",
"(",
"i",
"*",
"InmemSignal",
")",
"Stop",
"(",
")",
"{",
"i",
".",
"stopLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"i",
".",
"stopLock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"i",
".",
"stop",
"{",
"return",
"\n",
"}",
"\n",
"i",
... | // Stop is used to stop the InmemSignal from listening | [
"Stop",
"is",
"used",
"to",
"stop",
"the",
"InmemSignal",
"from",
"listening"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem_signal.go#L49-L59 | train |
armon/go-metrics | inmem_signal.go | dumpStats | func (i *InmemSignal) dumpStats() {
buf := bytes.NewBuffer(nil)
data := i.inm.Data()
// Skip the last period which is still being aggregated
for j := 0; j < len(data)-1; j++ {
intv := data[j]
intv.RLock()
for _, val := range intv.Gauges {
name := i.flattenLabels(val.Name, val.Labels)
fmt.Fprintf(buf, "[%v][G] '%s': %0.3f\n", intv.Interval, name, val.Value)
}
for name, vals := range intv.Points {
for _, val := range vals {
fmt.Fprintf(buf, "[%v][P] '%s': %0.3f\n", intv.Interval, name, val)
}
}
for _, agg := range intv.Counters {
name := i.flattenLabels(agg.Name, agg.Labels)
fmt.Fprintf(buf, "[%v][C] '%s': %s\n", intv.Interval, name, agg.AggregateSample)
}
for _, agg := range intv.Samples {
name := i.flattenLabels(agg.Name, agg.Labels)
fmt.Fprintf(buf, "[%v][S] '%s': %s\n", intv.Interval, name, agg.AggregateSample)
}
intv.RUnlock()
}
// Write out the bytes
i.w.Write(buf.Bytes())
} | go | func (i *InmemSignal) dumpStats() {
buf := bytes.NewBuffer(nil)
data := i.inm.Data()
// Skip the last period which is still being aggregated
for j := 0; j < len(data)-1; j++ {
intv := data[j]
intv.RLock()
for _, val := range intv.Gauges {
name := i.flattenLabels(val.Name, val.Labels)
fmt.Fprintf(buf, "[%v][G] '%s': %0.3f\n", intv.Interval, name, val.Value)
}
for name, vals := range intv.Points {
for _, val := range vals {
fmt.Fprintf(buf, "[%v][P] '%s': %0.3f\n", intv.Interval, name, val)
}
}
for _, agg := range intv.Counters {
name := i.flattenLabels(agg.Name, agg.Labels)
fmt.Fprintf(buf, "[%v][C] '%s': %s\n", intv.Interval, name, agg.AggregateSample)
}
for _, agg := range intv.Samples {
name := i.flattenLabels(agg.Name, agg.Labels)
fmt.Fprintf(buf, "[%v][S] '%s': %s\n", intv.Interval, name, agg.AggregateSample)
}
intv.RUnlock()
}
// Write out the bytes
i.w.Write(buf.Bytes())
} | [
"func",
"(",
"i",
"*",
"InmemSignal",
")",
"dumpStats",
"(",
")",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n\n",
"data",
":=",
"i",
".",
"inm",
".",
"Data",
"(",
")",
"\n",
"// Skip the last period which is still being aggregated",
"... | // dumpStats is used to dump the data to output writer | [
"dumpStats",
"is",
"used",
"to",
"dump",
"the",
"data",
"to",
"output",
"writer"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem_signal.go#L74-L104 | train |
armon/go-metrics | metrics.go | UpdateFilter | func (m *Metrics) UpdateFilter(allow, block []string) {
m.UpdateFilterAndLabels(allow, block, m.AllowedLabels, m.BlockedLabels)
} | go | func (m *Metrics) UpdateFilter(allow, block []string) {
m.UpdateFilterAndLabels(allow, block, m.AllowedLabels, m.BlockedLabels)
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"UpdateFilter",
"(",
"allow",
",",
"block",
"[",
"]",
"string",
")",
"{",
"m",
".",
"UpdateFilterAndLabels",
"(",
"allow",
",",
"block",
",",
"m",
".",
"AllowedLabels",
",",
"m",
".",
"BlockedLabels",
")",
"\n",
... | // UpdateFilter overwrites the existing filter with the given rules. | [
"UpdateFilter",
"overwrites",
"the",
"existing",
"filter",
"with",
"the",
"given",
"rules",
"."
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/metrics.go#L138-L140 | train |
armon/go-metrics | metrics.go | UpdateFilterAndLabels | func (m *Metrics) UpdateFilterAndLabels(allow, block, allowedLabels, blockedLabels []string) {
m.filterLock.Lock()
defer m.filterLock.Unlock()
m.AllowedPrefixes = allow
m.BlockedPrefixes = block
if allowedLabels == nil {
// Having a white list means we take only elements from it
m.allowedLabels = nil
} else {
m.allowedLabels = make(map[string]bool)
for _, v := range allowedLabels {
m.allowedLabels[v] = true
}
}
m.blockedLabels = make(map[string]bool)
for _, v := range blockedLabels {
m.blockedLabels[v] = true
}
m.AllowedLabels = allowedLabels
m.BlockedLabels = blockedLabels
m.filter = iradix.New()
for _, prefix := range m.AllowedPrefixes {
m.filter, _, _ = m.filter.Insert([]byte(prefix), true)
}
for _, prefix := range m.BlockedPrefixes {
m.filter, _, _ = m.filter.Insert([]byte(prefix), false)
}
} | go | func (m *Metrics) UpdateFilterAndLabels(allow, block, allowedLabels, blockedLabels []string) {
m.filterLock.Lock()
defer m.filterLock.Unlock()
m.AllowedPrefixes = allow
m.BlockedPrefixes = block
if allowedLabels == nil {
// Having a white list means we take only elements from it
m.allowedLabels = nil
} else {
m.allowedLabels = make(map[string]bool)
for _, v := range allowedLabels {
m.allowedLabels[v] = true
}
}
m.blockedLabels = make(map[string]bool)
for _, v := range blockedLabels {
m.blockedLabels[v] = true
}
m.AllowedLabels = allowedLabels
m.BlockedLabels = blockedLabels
m.filter = iradix.New()
for _, prefix := range m.AllowedPrefixes {
m.filter, _, _ = m.filter.Insert([]byte(prefix), true)
}
for _, prefix := range m.BlockedPrefixes {
m.filter, _, _ = m.filter.Insert([]byte(prefix), false)
}
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"UpdateFilterAndLabels",
"(",
"allow",
",",
"block",
",",
"allowedLabels",
",",
"blockedLabels",
"[",
"]",
"string",
")",
"{",
"m",
".",
"filterLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"filterLock",
... | // UpdateFilterAndLabels overwrites the existing filter with the given rules. | [
"UpdateFilterAndLabels",
"overwrites",
"the",
"existing",
"filter",
"with",
"the",
"given",
"rules",
"."
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/metrics.go#L143-L173 | train |
armon/go-metrics | metrics.go | labelIsAllowed | func (m *Metrics) labelIsAllowed(label *Label) bool {
labelName := (*label).Name
if m.blockedLabels != nil {
_, ok := m.blockedLabels[labelName]
if ok {
// If present, let's remove this label
return false
}
}
if m.allowedLabels != nil {
_, ok := m.allowedLabels[labelName]
return ok
}
// Allow by default
return true
} | go | func (m *Metrics) labelIsAllowed(label *Label) bool {
labelName := (*label).Name
if m.blockedLabels != nil {
_, ok := m.blockedLabels[labelName]
if ok {
// If present, let's remove this label
return false
}
}
if m.allowedLabels != nil {
_, ok := m.allowedLabels[labelName]
return ok
}
// Allow by default
return true
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"labelIsAllowed",
"(",
"label",
"*",
"Label",
")",
"bool",
"{",
"labelName",
":=",
"(",
"*",
"label",
")",
".",
"Name",
"\n",
"if",
"m",
".",
"blockedLabels",
"!=",
"nil",
"{",
"_",
",",
"ok",
":=",
"m",
"."... | // labelIsAllowed return true if a should be included in metric
// the caller should lock m.filterLock while calling this method | [
"labelIsAllowed",
"return",
"true",
"if",
"a",
"should",
"be",
"included",
"in",
"metric",
"the",
"caller",
"should",
"lock",
"m",
".",
"filterLock",
"while",
"calling",
"this",
"method"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/metrics.go#L177-L192 | train |
armon/go-metrics | metrics.go | filterLabels | func (m *Metrics) filterLabels(labels []Label) []Label {
if labels == nil {
return nil
}
toReturn := []Label{}
for _, label := range labels {
if m.labelIsAllowed(&label) {
toReturn = append(toReturn, label)
}
}
return toReturn
} | go | func (m *Metrics) filterLabels(labels []Label) []Label {
if labels == nil {
return nil
}
toReturn := []Label{}
for _, label := range labels {
if m.labelIsAllowed(&label) {
toReturn = append(toReturn, label)
}
}
return toReturn
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"filterLabels",
"(",
"labels",
"[",
"]",
"Label",
")",
"[",
"]",
"Label",
"{",
"if",
"labels",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"toReturn",
":=",
"[",
"]",
"Label",
"{",
"}",
"\n",
"for",
... | // filterLabels return only allowed labels
// the caller should lock m.filterLock while calling this method | [
"filterLabels",
"return",
"only",
"allowed",
"labels",
"the",
"caller",
"should",
"lock",
"m",
".",
"filterLock",
"while",
"calling",
"this",
"method"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/metrics.go#L196-L207 | train |
armon/go-metrics | metrics.go | allowMetric | func (m *Metrics) allowMetric(key []string, labels []Label) (bool, []Label) {
m.filterLock.RLock()
defer m.filterLock.RUnlock()
if m.filter == nil || m.filter.Len() == 0 {
return m.Config.FilterDefault, m.filterLabels(labels)
}
_, allowed, ok := m.filter.Root().LongestPrefix([]byte(strings.Join(key, ".")))
if !ok {
return m.Config.FilterDefault, m.filterLabels(labels)
}
return allowed.(bool), m.filterLabels(labels)
} | go | func (m *Metrics) allowMetric(key []string, labels []Label) (bool, []Label) {
m.filterLock.RLock()
defer m.filterLock.RUnlock()
if m.filter == nil || m.filter.Len() == 0 {
return m.Config.FilterDefault, m.filterLabels(labels)
}
_, allowed, ok := m.filter.Root().LongestPrefix([]byte(strings.Join(key, ".")))
if !ok {
return m.Config.FilterDefault, m.filterLabels(labels)
}
return allowed.(bool), m.filterLabels(labels)
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"allowMetric",
"(",
"key",
"[",
"]",
"string",
",",
"labels",
"[",
"]",
"Label",
")",
"(",
"bool",
",",
"[",
"]",
"Label",
")",
"{",
"m",
".",
"filterLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",... | // Returns whether the metric should be allowed based on configured prefix filters
// Also return the applicable labels | [
"Returns",
"whether",
"the",
"metric",
"should",
"be",
"allowed",
"based",
"on",
"configured",
"prefix",
"filters",
"Also",
"return",
"the",
"applicable",
"labels"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/metrics.go#L211-L225 | train |
armon/go-metrics | metrics.go | emitRuntimeStats | func (m *Metrics) emitRuntimeStats() {
// Export number of Goroutines
numRoutines := runtime.NumGoroutine()
m.SetGauge([]string{"runtime", "num_goroutines"}, float32(numRoutines))
// Export memory stats
var stats runtime.MemStats
runtime.ReadMemStats(&stats)
m.SetGauge([]string{"runtime", "alloc_bytes"}, float32(stats.Alloc))
m.SetGauge([]string{"runtime", "sys_bytes"}, float32(stats.Sys))
m.SetGauge([]string{"runtime", "malloc_count"}, float32(stats.Mallocs))
m.SetGauge([]string{"runtime", "free_count"}, float32(stats.Frees))
m.SetGauge([]string{"runtime", "heap_objects"}, float32(stats.HeapObjects))
m.SetGauge([]string{"runtime", "total_gc_pause_ns"}, float32(stats.PauseTotalNs))
m.SetGauge([]string{"runtime", "total_gc_runs"}, float32(stats.NumGC))
// Export info about the last few GC runs
num := stats.NumGC
// Handle wrap around
if num < m.lastNumGC {
m.lastNumGC = 0
}
// Ensure we don't scan more than 256
if num-m.lastNumGC >= 256 {
m.lastNumGC = num - 255
}
for i := m.lastNumGC; i < num; i++ {
pause := stats.PauseNs[i%256]
m.AddSample([]string{"runtime", "gc_pause_ns"}, float32(pause))
}
m.lastNumGC = num
} | go | func (m *Metrics) emitRuntimeStats() {
// Export number of Goroutines
numRoutines := runtime.NumGoroutine()
m.SetGauge([]string{"runtime", "num_goroutines"}, float32(numRoutines))
// Export memory stats
var stats runtime.MemStats
runtime.ReadMemStats(&stats)
m.SetGauge([]string{"runtime", "alloc_bytes"}, float32(stats.Alloc))
m.SetGauge([]string{"runtime", "sys_bytes"}, float32(stats.Sys))
m.SetGauge([]string{"runtime", "malloc_count"}, float32(stats.Mallocs))
m.SetGauge([]string{"runtime", "free_count"}, float32(stats.Frees))
m.SetGauge([]string{"runtime", "heap_objects"}, float32(stats.HeapObjects))
m.SetGauge([]string{"runtime", "total_gc_pause_ns"}, float32(stats.PauseTotalNs))
m.SetGauge([]string{"runtime", "total_gc_runs"}, float32(stats.NumGC))
// Export info about the last few GC runs
num := stats.NumGC
// Handle wrap around
if num < m.lastNumGC {
m.lastNumGC = 0
}
// Ensure we don't scan more than 256
if num-m.lastNumGC >= 256 {
m.lastNumGC = num - 255
}
for i := m.lastNumGC; i < num; i++ {
pause := stats.PauseNs[i%256]
m.AddSample([]string{"runtime", "gc_pause_ns"}, float32(pause))
}
m.lastNumGC = num
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"emitRuntimeStats",
"(",
")",
"{",
"// Export number of Goroutines",
"numRoutines",
":=",
"runtime",
".",
"NumGoroutine",
"(",
")",
"\n",
"m",
".",
"SetGauge",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\... | // Emits various runtime statsitics | [
"Emits",
"various",
"runtime",
"statsitics"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/metrics.go#L236-L270 | train |
armon/go-metrics | metrics.go | insert | func insert(i int, v string, s []string) []string {
s = append(s, "")
copy(s[i+1:], s[i:])
s[i] = v
return s
} | go | func insert(i int, v string, s []string) []string {
s = append(s, "")
copy(s[i+1:], s[i:])
s[i] = v
return s
} | [
"func",
"insert",
"(",
"i",
"int",
",",
"v",
"string",
",",
"s",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"s",
"=",
"append",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"copy",
"(",
"s",
"[",
"i",
"+",
"1",
":",
"]",
",",
"s",
"[",
... | // Inserts a string value at an index into the slice | [
"Inserts",
"a",
"string",
"value",
"at",
"an",
"index",
"into",
"the",
"slice"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/metrics.go#L273-L278 | train |
armon/go-metrics | start.go | DefaultConfig | func DefaultConfig(serviceName string) *Config {
c := &Config{
ServiceName: serviceName, // Use client provided service
HostName: "",
EnableHostname: true, // Enable hostname prefix
EnableRuntimeMetrics: true, // Enable runtime profiling
EnableTypePrefix: false, // Disable type prefix
TimerGranularity: time.Millisecond, // Timers are in milliseconds
ProfileInterval: time.Second, // Poll runtime every second
FilterDefault: true, // Don't filter metrics by default
}
// Try to get the hostname
name, _ := os.Hostname()
c.HostName = name
return c
} | go | func DefaultConfig(serviceName string) *Config {
c := &Config{
ServiceName: serviceName, // Use client provided service
HostName: "",
EnableHostname: true, // Enable hostname prefix
EnableRuntimeMetrics: true, // Enable runtime profiling
EnableTypePrefix: false, // Disable type prefix
TimerGranularity: time.Millisecond, // Timers are in milliseconds
ProfileInterval: time.Second, // Poll runtime every second
FilterDefault: true, // Don't filter metrics by default
}
// Try to get the hostname
name, _ := os.Hostname()
c.HostName = name
return c
} | [
"func",
"DefaultConfig",
"(",
"serviceName",
"string",
")",
"*",
"Config",
"{",
"c",
":=",
"&",
"Config",
"{",
"ServiceName",
":",
"serviceName",
",",
"// Use client provided service",
"HostName",
":",
"\"",
"\"",
",",
"EnableHostname",
":",
"true",
",",
"// E... | // DefaultConfig provides a sane default configuration | [
"DefaultConfig",
"provides",
"a",
"sane",
"default",
"configuration"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/start.go#L52-L68 | train |
armon/go-metrics | start.go | New | func New(conf *Config, sink MetricSink) (*Metrics, error) {
met := &Metrics{}
met.Config = *conf
met.sink = sink
met.UpdateFilterAndLabels(conf.AllowedPrefixes, conf.BlockedPrefixes, conf.AllowedLabels, conf.BlockedLabels)
// Start the runtime collector
if conf.EnableRuntimeMetrics {
go met.collectStats()
}
return met, nil
} | go | func New(conf *Config, sink MetricSink) (*Metrics, error) {
met := &Metrics{}
met.Config = *conf
met.sink = sink
met.UpdateFilterAndLabels(conf.AllowedPrefixes, conf.BlockedPrefixes, conf.AllowedLabels, conf.BlockedLabels)
// Start the runtime collector
if conf.EnableRuntimeMetrics {
go met.collectStats()
}
return met, nil
} | [
"func",
"New",
"(",
"conf",
"*",
"Config",
",",
"sink",
"MetricSink",
")",
"(",
"*",
"Metrics",
",",
"error",
")",
"{",
"met",
":=",
"&",
"Metrics",
"{",
"}",
"\n",
"met",
".",
"Config",
"=",
"*",
"conf",
"\n",
"met",
".",
"sink",
"=",
"sink",
... | // New is used to create a new instance of Metrics | [
"New",
"is",
"used",
"to",
"create",
"a",
"new",
"instance",
"of",
"Metrics"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/start.go#L71-L82 | train |
armon/go-metrics | start.go | NewGlobal | func NewGlobal(conf *Config, sink MetricSink) (*Metrics, error) {
metrics, err := New(conf, sink)
if err == nil {
globalMetrics.Store(metrics)
}
return metrics, err
} | go | func NewGlobal(conf *Config, sink MetricSink) (*Metrics, error) {
metrics, err := New(conf, sink)
if err == nil {
globalMetrics.Store(metrics)
}
return metrics, err
} | [
"func",
"NewGlobal",
"(",
"conf",
"*",
"Config",
",",
"sink",
"MetricSink",
")",
"(",
"*",
"Metrics",
",",
"error",
")",
"{",
"metrics",
",",
"err",
":=",
"New",
"(",
"conf",
",",
"sink",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"globalMetrics",
"... | // NewGlobal is the same as New, but it assigns the metrics object to be
// used globally as well as returning it. | [
"NewGlobal",
"is",
"the",
"same",
"as",
"New",
"but",
"it",
"assigns",
"the",
"metrics",
"object",
"to",
"be",
"used",
"globally",
"as",
"well",
"as",
"returning",
"it",
"."
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/start.go#L86-L92 | train |
armon/go-metrics | start.go | SetGauge | func SetGauge(key []string, val float32) {
globalMetrics.Load().(*Metrics).SetGauge(key, val)
} | go | func SetGauge(key []string, val float32) {
globalMetrics.Load().(*Metrics).SetGauge(key, val)
} | [
"func",
"SetGauge",
"(",
"key",
"[",
"]",
"string",
",",
"val",
"float32",
")",
"{",
"globalMetrics",
".",
"Load",
"(",
")",
".",
"(",
"*",
"Metrics",
")",
".",
"SetGauge",
"(",
"key",
",",
"val",
")",
"\n",
"}"
] | // Proxy all the methods to the globalMetrics instance | [
"Proxy",
"all",
"the",
"methods",
"to",
"the",
"globalMetrics",
"instance"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/start.go#L95-L97 | train |
armon/go-metrics | statsd.go | NewStatsdSink | func NewStatsdSink(addr string) (*StatsdSink, error) {
s := &StatsdSink{
addr: addr,
metricQueue: make(chan string, 4096),
}
go s.flushMetrics()
return s, nil
} | go | func NewStatsdSink(addr string) (*StatsdSink, error) {
s := &StatsdSink{
addr: addr,
metricQueue: make(chan string, 4096),
}
go s.flushMetrics()
return s, nil
} | [
"func",
"NewStatsdSink",
"(",
"addr",
"string",
")",
"(",
"*",
"StatsdSink",
",",
"error",
")",
"{",
"s",
":=",
"&",
"StatsdSink",
"{",
"addr",
":",
"addr",
",",
"metricQueue",
":",
"make",
"(",
"chan",
"string",
",",
"4096",
")",
",",
"}",
"\n",
"... | // NewStatsdSink is used to create a new StatsdSink | [
"NewStatsdSink",
"is",
"used",
"to",
"create",
"a",
"new",
"StatsdSink"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/statsd.go#L34-L41 | train |
armon/go-metrics | prometheus/prometheus.go | NewPrometheusSinkFrom | func NewPrometheusSinkFrom(opts PrometheusOpts) (*PrometheusSink, error) {
sink := &PrometheusSink{
gauges: make(map[string]prometheus.Gauge),
summaries: make(map[string]prometheus.Summary),
counters: make(map[string]prometheus.Counter),
updates: make(map[string]time.Time),
expiration: opts.Expiration,
}
return sink, prometheus.Register(sink)
} | go | func NewPrometheusSinkFrom(opts PrometheusOpts) (*PrometheusSink, error) {
sink := &PrometheusSink{
gauges: make(map[string]prometheus.Gauge),
summaries: make(map[string]prometheus.Summary),
counters: make(map[string]prometheus.Counter),
updates: make(map[string]time.Time),
expiration: opts.Expiration,
}
return sink, prometheus.Register(sink)
} | [
"func",
"NewPrometheusSinkFrom",
"(",
"opts",
"PrometheusOpts",
")",
"(",
"*",
"PrometheusSink",
",",
"error",
")",
"{",
"sink",
":=",
"&",
"PrometheusSink",
"{",
"gauges",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"prometheus",
".",
"Gauge",
")",
",",
... | // NewPrometheusSinkFrom creates a new PrometheusSink using the passed options. | [
"NewPrometheusSinkFrom",
"creates",
"a",
"new",
"PrometheusSink",
"using",
"the",
"passed",
"options",
"."
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/prometheus/prometheus.go#L47-L57 | train |
armon/go-metrics | prometheus/prometheus.go | Describe | func (p *PrometheusSink) Describe(c chan<- *prometheus.Desc) {
// We must emit some description otherwise an error is returned. This
// description isn't shown to the user!
prometheus.NewGauge(prometheus.GaugeOpts{Name: "Dummy", Help: "Dummy"}).Describe(c)
} | go | func (p *PrometheusSink) Describe(c chan<- *prometheus.Desc) {
// We must emit some description otherwise an error is returned. This
// description isn't shown to the user!
prometheus.NewGauge(prometheus.GaugeOpts{Name: "Dummy", Help: "Dummy"}).Describe(c)
} | [
"func",
"(",
"p",
"*",
"PrometheusSink",
")",
"Describe",
"(",
"c",
"chan",
"<-",
"*",
"prometheus",
".",
"Desc",
")",
"{",
"// We must emit some description otherwise an error is returned. This",
"// description isn't shown to the user!",
"prometheus",
".",
"NewGauge",
"... | // Describe is needed to meet the Collector interface. | [
"Describe",
"is",
"needed",
"to",
"meet",
"the",
"Collector",
"interface",
"."
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/prometheus/prometheus.go#L60-L64 | train |
armon/go-metrics | prometheus/prometheus.go | Collect | func (p *PrometheusSink) Collect(c chan<- prometheus.Metric) {
p.mu.Lock()
defer p.mu.Unlock()
expire := p.expiration != 0
now := time.Now()
for k, v := range p.gauges {
last := p.updates[k]
if expire && last.Add(p.expiration).Before(now) {
delete(p.updates, k)
delete(p.gauges, k)
} else {
v.Collect(c)
}
}
for k, v := range p.summaries {
last := p.updates[k]
if expire && last.Add(p.expiration).Before(now) {
delete(p.updates, k)
delete(p.summaries, k)
} else {
v.Collect(c)
}
}
for k, v := range p.counters {
last := p.updates[k]
if expire && last.Add(p.expiration).Before(now) {
delete(p.updates, k)
delete(p.counters, k)
} else {
v.Collect(c)
}
}
} | go | func (p *PrometheusSink) Collect(c chan<- prometheus.Metric) {
p.mu.Lock()
defer p.mu.Unlock()
expire := p.expiration != 0
now := time.Now()
for k, v := range p.gauges {
last := p.updates[k]
if expire && last.Add(p.expiration).Before(now) {
delete(p.updates, k)
delete(p.gauges, k)
} else {
v.Collect(c)
}
}
for k, v := range p.summaries {
last := p.updates[k]
if expire && last.Add(p.expiration).Before(now) {
delete(p.updates, k)
delete(p.summaries, k)
} else {
v.Collect(c)
}
}
for k, v := range p.counters {
last := p.updates[k]
if expire && last.Add(p.expiration).Before(now) {
delete(p.updates, k)
delete(p.counters, k)
} else {
v.Collect(c)
}
}
} | [
"func",
"(",
"p",
"*",
"PrometheusSink",
")",
"Collect",
"(",
"c",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"{",
"p",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"expire",
":=",
"p",
... | // Collect meets the collection interface and allows us to enforce our expiration
// logic to clean up ephemeral metrics if their value haven't been set for a
// duration exceeding our allowed expiration time. | [
"Collect",
"meets",
"the",
"collection",
"interface",
"and",
"allows",
"us",
"to",
"enforce",
"our",
"expiration",
"logic",
"to",
"clean",
"up",
"ephemeral",
"metrics",
"if",
"their",
"value",
"haven",
"t",
"been",
"set",
"for",
"a",
"duration",
"exceeding",
... | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/prometheus/prometheus.go#L69-L102 | train |
armon/go-metrics | inmem.go | NewIntervalMetrics | func NewIntervalMetrics(intv time.Time) *IntervalMetrics {
return &IntervalMetrics{
Interval: intv,
Gauges: make(map[string]GaugeValue),
Points: make(map[string][]float32),
Counters: make(map[string]SampledValue),
Samples: make(map[string]SampledValue),
}
} | go | func NewIntervalMetrics(intv time.Time) *IntervalMetrics {
return &IntervalMetrics{
Interval: intv,
Gauges: make(map[string]GaugeValue),
Points: make(map[string][]float32),
Counters: make(map[string]SampledValue),
Samples: make(map[string]SampledValue),
}
} | [
"func",
"NewIntervalMetrics",
"(",
"intv",
"time",
".",
"Time",
")",
"*",
"IntervalMetrics",
"{",
"return",
"&",
"IntervalMetrics",
"{",
"Interval",
":",
"intv",
",",
"Gauges",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"GaugeValue",
")",
",",
"Points",
... | // NewIntervalMetrics creates a new IntervalMetrics for a given interval | [
"NewIntervalMetrics",
"creates",
"a",
"new",
"IntervalMetrics",
"for",
"a",
"given",
"interval"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L59-L67 | train |
armon/go-metrics | inmem.go | Stddev | func (a *AggregateSample) Stddev() float64 {
num := (float64(a.Count) * a.SumSq) - math.Pow(a.Sum, 2)
div := float64(a.Count * (a.Count - 1))
if div == 0 {
return 0
}
return math.Sqrt(num / div)
} | go | func (a *AggregateSample) Stddev() float64 {
num := (float64(a.Count) * a.SumSq) - math.Pow(a.Sum, 2)
div := float64(a.Count * (a.Count - 1))
if div == 0 {
return 0
}
return math.Sqrt(num / div)
} | [
"func",
"(",
"a",
"*",
"AggregateSample",
")",
"Stddev",
"(",
")",
"float64",
"{",
"num",
":=",
"(",
"float64",
"(",
"a",
".",
"Count",
")",
"*",
"a",
".",
"SumSq",
")",
"-",
"math",
".",
"Pow",
"(",
"a",
".",
"Sum",
",",
"2",
")",
"\n",
"div... | // Computes a Stddev of the values | [
"Computes",
"a",
"Stddev",
"of",
"the",
"values"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L82-L89 | train |
armon/go-metrics | inmem.go | Mean | func (a *AggregateSample) Mean() float64 {
if a.Count == 0 {
return 0
}
return a.Sum / float64(a.Count)
} | go | func (a *AggregateSample) Mean() float64 {
if a.Count == 0 {
return 0
}
return a.Sum / float64(a.Count)
} | [
"func",
"(",
"a",
"*",
"AggregateSample",
")",
"Mean",
"(",
")",
"float64",
"{",
"if",
"a",
".",
"Count",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"a",
".",
"Sum",
"/",
"float64",
"(",
"a",
".",
"Count",
")",
"\n",
"}"
] | // Computes a mean of the values | [
"Computes",
"a",
"mean",
"of",
"the",
"values"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L92-L97 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.