id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
29,200 | 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 |
29,201 | 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
... | [
"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 |
29,202 | 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 hoo... | [
"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 |
29,203 | 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 ... | 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 ... | [
"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 |
29,204 | 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 w... | 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 w... | [
"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 |
29,205 | 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 |
29,206 | 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 |
29,207 | 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 |
29,208 | 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 |
29,209 | 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 |
29,210 | 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 {
... | 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 {
... | [
"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 |
29,211 | 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 |
29,212 | 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 * ... | 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 * ... | [
"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 |
29,213 | 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 |
29,214 | 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 |
29,215 | 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 |
29,216 | 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 |
29,217 | 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 |
29,218 | 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 |
29,219 | 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 |
29,220 | 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 |
29,221 | 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 |
29,222 | 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 |
29,223 | 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 |
29,224 | 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 |
29,225 | 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 |
29,226 | 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 |
29,227 | 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 |
29,228 | 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 |
29,229 | 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 |
29,230 | 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 |
29,231 | 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 |
29,232 | 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 |
29,233 | 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 |
29,234 | 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 |
29,235 | 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 |
29,236 | 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 |
29,237 | 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 |
29,238 | 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, "... | 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, "... | [
"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 |
29,239 | 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 |
29,240 | 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... | 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... | [
"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 |
29,241 | 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 d... | 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 d... | [
"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 |
29,242 | 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 |
29,243 | 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... | 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... | [
"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 |
29,244 | 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"}, float3... | 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"}, float3... | [
"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 |
29,245 | 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 |
29,246 | 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: ... | 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: ... | [
"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 |
29,247 | 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()
}
... | 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()
}
... | [
"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 |
29,248 | 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 |
29,249 | 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 |
29,250 | 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 |
29,251 | 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.Expirat... | 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.Expirat... | [
"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 |
29,252 | 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 |
29,253 | 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.Collec... | 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.Collec... | [
"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 |
29,254 | 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 |
29,255 | 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 |
29,256 | 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 |
29,257 | armon/go-metrics | inmem.go | Ingest | func (a *AggregateSample) Ingest(v float64, rateDenom float64) {
a.Count++
a.Sum += v
a.SumSq += (v * v)
if v < a.Min || a.Count == 1 {
a.Min = v
}
if v > a.Max || a.Count == 1 {
a.Max = v
}
a.Rate = float64(a.Sum) / rateDenom
a.LastUpdated = time.Now()
} | go | func (a *AggregateSample) Ingest(v float64, rateDenom float64) {
a.Count++
a.Sum += v
a.SumSq += (v * v)
if v < a.Min || a.Count == 1 {
a.Min = v
}
if v > a.Max || a.Count == 1 {
a.Max = v
}
a.Rate = float64(a.Sum) / rateDenom
a.LastUpdated = time.Now()
} | [
"func",
"(",
"a",
"*",
"AggregateSample",
")",
"Ingest",
"(",
"v",
"float64",
",",
"rateDenom",
"float64",
")",
"{",
"a",
".",
"Count",
"++",
"\n",
"a",
".",
"Sum",
"+=",
"v",
"\n",
"a",
".",
"SumSq",
"+=",
"(",
"v",
"*",
"v",
")",
"\n",
"if",
... | // Ingest is used to update a sample | [
"Ingest",
"is",
"used",
"to",
"update",
"a",
"sample"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L100-L112 |
29,258 | armon/go-metrics | inmem.go | NewInmemSink | func NewInmemSink(interval, retain time.Duration) *InmemSink {
rateTimeUnit := time.Second
i := &InmemSink{
interval: interval,
retain: retain,
maxIntervals: int(retain / interval),
rateDenom: float64(interval.Nanoseconds()) / float64(rateTimeUnit.Nanoseconds()),
}
i.intervals = make([]*Interva... | go | func NewInmemSink(interval, retain time.Duration) *InmemSink {
rateTimeUnit := time.Second
i := &InmemSink{
interval: interval,
retain: retain,
maxIntervals: int(retain / interval),
rateDenom: float64(interval.Nanoseconds()) / float64(rateTimeUnit.Nanoseconds()),
}
i.intervals = make([]*Interva... | [
"func",
"NewInmemSink",
"(",
"interval",
",",
"retain",
"time",
".",
"Duration",
")",
"*",
"InmemSink",
"{",
"rateTimeUnit",
":=",
"time",
".",
"Second",
"\n",
"i",
":=",
"&",
"InmemSink",
"{",
"interval",
":",
"interval",
",",
"retain",
":",
"retain",
"... | // NewInmemSink is used to construct a new in-memory sink.
// Uses an aggregation interval and maximum retention period. | [
"NewInmemSink",
"is",
"used",
"to",
"construct",
"a",
"new",
"in",
"-",
"memory",
"sink",
".",
"Uses",
"an",
"aggregation",
"interval",
"and",
"maximum",
"retention",
"period",
"."
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L145-L155 |
29,259 | armon/go-metrics | inmem.go | Data | func (i *InmemSink) Data() []*IntervalMetrics {
// Get the current interval, forces creation
i.getInterval()
i.intervalLock.RLock()
defer i.intervalLock.RUnlock()
n := len(i.intervals)
intervals := make([]*IntervalMetrics, n)
copy(intervals[:n-1], i.intervals[:n-1])
current := i.intervals[n-1]
// make its ... | go | func (i *InmemSink) Data() []*IntervalMetrics {
// Get the current interval, forces creation
i.getInterval()
i.intervalLock.RLock()
defer i.intervalLock.RUnlock()
n := len(i.intervals)
intervals := make([]*IntervalMetrics, n)
copy(intervals[:n-1], i.intervals[:n-1])
current := i.intervals[n-1]
// make its ... | [
"func",
"(",
"i",
"*",
"InmemSink",
")",
"Data",
"(",
")",
"[",
"]",
"*",
"IntervalMetrics",
"{",
"// Get the current interval, forces creation",
"i",
".",
"getInterval",
"(",
")",
"\n\n",
"i",
".",
"intervalLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"i... | // Data is used to retrieve all the aggregated metrics
// Intervals may be in use, and a read lock should be acquired | [
"Data",
"is",
"used",
"to",
"retrieve",
"all",
"the",
"aggregated",
"metrics",
"Intervals",
"may",
"be",
"in",
"use",
"and",
"a",
"read",
"lock",
"should",
"be",
"acquired"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L228-L267 |
29,260 | armon/go-metrics | inmem.go | getInterval | func (i *InmemSink) getInterval() *IntervalMetrics {
intv := time.Now().Truncate(i.interval)
if m := i.getExistingInterval(intv); m != nil {
return m
}
return i.createInterval(intv)
} | go | func (i *InmemSink) getInterval() *IntervalMetrics {
intv := time.Now().Truncate(i.interval)
if m := i.getExistingInterval(intv); m != nil {
return m
}
return i.createInterval(intv)
} | [
"func",
"(",
"i",
"*",
"InmemSink",
")",
"getInterval",
"(",
")",
"*",
"IntervalMetrics",
"{",
"intv",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Truncate",
"(",
"i",
".",
"interval",
")",
"\n",
"if",
"m",
":=",
"i",
".",
"getExistingInterval",
"(",
... | // getInterval returns the current interval to write to | [
"getInterval",
"returns",
"the",
"current",
"interval",
"to",
"write",
"to"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L304-L310 |
29,261 | armon/go-metrics | inmem_endpoint.go | deepCopy | func (source *SampledValue) deepCopy() SampledValue {
dest := *source
if source.AggregateSample != nil {
dest.AggregateSample = &AggregateSample{}
*dest.AggregateSample = *source.AggregateSample
}
return dest
} | go | func (source *SampledValue) deepCopy() SampledValue {
dest := *source
if source.AggregateSample != nil {
dest.AggregateSample = &AggregateSample{}
*dest.AggregateSample = *source.AggregateSample
}
return dest
} | [
"func",
"(",
"source",
"*",
"SampledValue",
")",
"deepCopy",
"(",
")",
"SampledValue",
"{",
"dest",
":=",
"*",
"source",
"\n",
"if",
"source",
".",
"AggregateSample",
"!=",
"nil",
"{",
"dest",
".",
"AggregateSample",
"=",
"&",
"AggregateSample",
"{",
"}",
... | // deepCopy allocates a new instance of AggregateSample | [
"deepCopy",
"allocates",
"a",
"new",
"instance",
"of",
"AggregateSample"
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem_endpoint.go#L45-L52 |
29,262 | armon/go-metrics | inmem_endpoint.go | DisplayMetrics | func (i *InmemSink) DisplayMetrics(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
data := i.Data()
var interval *IntervalMetrics
n := len(data)
switch {
case n == 0:
return nil, fmt.Errorf("no metric intervals have been initialized yet")
case n == 1:
// Show the current interval if it's ... | go | func (i *InmemSink) DisplayMetrics(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
data := i.Data()
var interval *IntervalMetrics
n := len(data)
switch {
case n == 0:
return nil, fmt.Errorf("no metric intervals have been initialized yet")
case n == 1:
// Show the current interval if it's ... | [
"func",
"(",
"i",
"*",
"InmemSink",
")",
"DisplayMetrics",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"data",
":=",
"i",
".",
"Data",
"(",
")",
"\n\n... | // DisplayMetrics returns a summary of the metrics from the most recent finished interval. | [
"DisplayMetrics",
"returns",
"a",
"summary",
"of",
"the",
"metrics",
"from",
"the",
"most",
"recent",
"finished",
"interval",
"."
] | ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5 | https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem_endpoint.go#L55-L107 |
29,263 | levigross/grequests | session.go | NewSession | func NewSession(ro *RequestOptions) *Session {
if ro == nil {
ro = &RequestOptions{}
}
ro.UseCookieJar = true
return &Session{RequestOptions: ro, HTTPClient: BuildHTTPClient(*ro)}
} | go | func NewSession(ro *RequestOptions) *Session {
if ro == nil {
ro = &RequestOptions{}
}
ro.UseCookieJar = true
return &Session{RequestOptions: ro, HTTPClient: BuildHTTPClient(*ro)}
} | [
"func",
"NewSession",
"(",
"ro",
"*",
"RequestOptions",
")",
"*",
"Session",
"{",
"if",
"ro",
"==",
"nil",
"{",
"ro",
"=",
"&",
"RequestOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"ro",
".",
"UseCookieJar",
"=",
"true",
"\n\n",
"return",
"&",
"Session",
"... | // NewSession returns a session struct which enables can be used to maintain establish a persistent state with the
// server
// This function will set UseCookieJar to true as that is the purpose of using the session | [
"NewSession",
"returns",
"a",
"session",
"struct",
"which",
"enables",
"can",
"be",
"used",
"to",
"maintain",
"establish",
"a",
"persistent",
"state",
"with",
"the",
"server",
"This",
"function",
"will",
"set",
"UseCookieJar",
"to",
"true",
"as",
"that",
"is",... | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/session.go#L18-L26 |
29,264 | levigross/grequests | session.go | combineRequestOptions | func (s *Session) combineRequestOptions(ro *RequestOptions) *RequestOptions {
if ro == nil {
ro = &RequestOptions{}
}
if ro.UserAgent == "" && s.RequestOptions.UserAgent != "" {
ro.UserAgent = s.RequestOptions.UserAgent
}
if ro.Host == "" && s.RequestOptions.Host != "" {
ro.Host = s.RequestOptions.Host
}
... | go | func (s *Session) combineRequestOptions(ro *RequestOptions) *RequestOptions {
if ro == nil {
ro = &RequestOptions{}
}
if ro.UserAgent == "" && s.RequestOptions.UserAgent != "" {
ro.UserAgent = s.RequestOptions.UserAgent
}
if ro.Host == "" && s.RequestOptions.Host != "" {
ro.Host = s.RequestOptions.Host
}
... | [
"func",
"(",
"s",
"*",
"Session",
")",
"combineRequestOptions",
"(",
"ro",
"*",
"RequestOptions",
")",
"*",
"RequestOptions",
"{",
"if",
"ro",
"==",
"nil",
"{",
"ro",
"=",
"&",
"RequestOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"ro",
".",
"UserAgent"... | // Combine session options and request options
// 1. UserAgent
// 2. Host
// 3. Auth
// 4. Headers | [
"Combine",
"session",
"options",
"and",
"request",
"options",
"1",
".",
"UserAgent",
"2",
".",
"Host",
"3",
".",
"Auth",
"4",
".",
"Headers"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/session.go#L33-L61 |
29,265 | levigross/grequests | request.go | DoRegularRequest | func DoRegularRequest(requestVerb, url string, ro *RequestOptions) (*Response, error) {
return buildResponse(buildRequest(requestVerb, url, ro, nil))
} | go | func DoRegularRequest(requestVerb, url string, ro *RequestOptions) (*Response, error) {
return buildResponse(buildRequest(requestVerb, url, ro, nil))
} | [
"func",
"DoRegularRequest",
"(",
"requestVerb",
",",
"url",
"string",
",",
"ro",
"*",
"RequestOptions",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"return",
"buildResponse",
"(",
"buildRequest",
"(",
"requestVerb",
",",
"url",
",",
"ro",
",",
"nil"... | // DoRegularRequest adds generic test functionality | [
"DoRegularRequest",
"adds",
"generic",
"test",
"functionality"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/request.go#L144-L146 |
29,266 | levigross/grequests | request.go | buildRequest | func buildRequest(httpMethod, url string, ro *RequestOptions, httpClient *http.Client) (*http.Response, error) {
if ro == nil {
ro = &RequestOptions{}
}
if ro.CookieJar != nil {
ro.UseCookieJar = true
}
// Create our own HTTP client
if httpClient == nil {
httpClient = BuildHTTPClient(*ro)
}
var err er... | go | func buildRequest(httpMethod, url string, ro *RequestOptions, httpClient *http.Client) (*http.Response, error) {
if ro == nil {
ro = &RequestOptions{}
}
if ro.CookieJar != nil {
ro.UseCookieJar = true
}
// Create our own HTTP client
if httpClient == nil {
httpClient = BuildHTTPClient(*ro)
}
var err er... | [
"func",
"buildRequest",
"(",
"httpMethod",
",",
"url",
"string",
",",
"ro",
"*",
"RequestOptions",
",",
"httpClient",
"*",
"http",
".",
"Client",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"if",
"ro",
"==",
"nil",
"{",
"ro",
"=",... | // buildRequest is where most of the magic happens for request processing | [
"buildRequest",
"is",
"where",
"most",
"of",
"the",
"magic",
"happens",
"for",
"request",
"processing"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/request.go#L159-L210 |
29,267 | levigross/grequests | request.go | BuildHTTPClient | func BuildHTTPClient(ro RequestOptions) *http.Client {
if ro.HTTPClient != nil {
return ro.HTTPClient
}
// Does the user want to change the defaults?
if !ro.dontUseDefaultClient() {
return http.DefaultClient
}
// Using the user config for tls timeout or default
if ro.TLSHandshakeTimeout == 0 {
ro.TLSHan... | go | func BuildHTTPClient(ro RequestOptions) *http.Client {
if ro.HTTPClient != nil {
return ro.HTTPClient
}
// Does the user want to change the defaults?
if !ro.dontUseDefaultClient() {
return http.DefaultClient
}
// Using the user config for tls timeout or default
if ro.TLSHandshakeTimeout == 0 {
ro.TLSHan... | [
"func",
"BuildHTTPClient",
"(",
"ro",
"RequestOptions",
")",
"*",
"http",
".",
"Client",
"{",
"if",
"ro",
".",
"HTTPClient",
"!=",
"nil",
"{",
"return",
"ro",
".",
"HTTPClient",
"\n",
"}",
"\n\n",
"// Does the user want to change the defaults?",
"if",
"!",
"ro... | // BuildHTTPClient is a function that will return a custom HTTP client based on the request options provided
// the check is in UseDefaultClient | [
"BuildHTTPClient",
"is",
"a",
"function",
"that",
"will",
"return",
"a",
"custom",
"HTTP",
"client",
"based",
"on",
"the",
"request",
"options",
"provided",
"the",
"check",
"is",
"in",
"UseDefaultClient"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/request.go#L456-L502 |
29,268 | levigross/grequests | response.go | Read | func (r *Response) Read(p []byte) (n int, err error) {
if r.Error != nil {
return -1, r.Error
}
return r.RawResponse.Body.Read(p)
} | go | func (r *Response) Read(p []byte) (n int, err error) {
if r.Error != nil {
return -1, r.Error
}
return r.RawResponse.Body.Read(p)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"retu... | // Read is part of our ability to support io.ReadCloser if someone wants to make use of the raw body | [
"Read",
"is",
"part",
"of",
"our",
"ability",
"to",
"support",
"io",
".",
"ReadCloser",
"if",
"someone",
"wants",
"to",
"make",
"use",
"of",
"the",
"raw",
"body"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L55-L62 |
29,269 | levigross/grequests | response.go | Close | func (r *Response) Close() error {
if r.Error != nil {
return r.Error
}
io.Copy(ioutil.Discard, r)
return r.RawResponse.Body.Close()
} | go | func (r *Response) Close() error {
if r.Error != nil {
return r.Error
}
io.Copy(ioutil.Discard, r)
return r.RawResponse.Body.Close()
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"io",
".",
"Copy",
"(",
"ioutil",
".",
"Discard",
",",
"r",
")",
"\n\n",
"return... | // Close is part of our ability to support io.ReadCloser if someone wants to make use of the raw body | [
"Close",
"is",
"part",
"of",
"our",
"ability",
"to",
"support",
"io",
".",
"ReadCloser",
"if",
"someone",
"wants",
"to",
"make",
"use",
"of",
"the",
"raw",
"body"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L65-L74 |
29,270 | levigross/grequests | response.go | DownloadToFile | func (r *Response) DownloadToFile(fileName string) error {
if r.Error != nil {
return r.Error
}
fd, err := os.Create(fileName)
if err != nil {
return err
}
defer r.Close() // This is a noop if we use the internal ByteBuffer
defer fd.Close()
if _, err := io.Copy(fd, r.getInternalReader()); err != nil &&... | go | func (r *Response) DownloadToFile(fileName string) error {
if r.Error != nil {
return r.Error
}
fd, err := os.Create(fileName)
if err != nil {
return err
}
defer r.Close() // This is a noop if we use the internal ByteBuffer
defer fd.Close()
if _, err := io.Copy(fd, r.getInternalReader()); err != nil &&... | [
"func",
"(",
"r",
"*",
"Response",
")",
"DownloadToFile",
"(",
"fileName",
"string",
")",
"error",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"fd",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"... | // DownloadToFile allows you to download the contents of the response to a file | [
"DownloadToFile",
"allows",
"you",
"to",
"download",
"the",
"contents",
"of",
"the",
"response",
"to",
"a",
"file"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L77-L97 |
29,271 | levigross/grequests | response.go | JSON | func (r *Response) JSON(userStruct interface{}) error {
if r.Error != nil {
return r.Error
}
jsonDecoder := json.NewDecoder(r.getInternalReader())
defer r.Close()
return jsonDecoder.Decode(&userStruct)
} | go | func (r *Response) JSON(userStruct interface{}) error {
if r.Error != nil {
return r.Error
}
jsonDecoder := json.NewDecoder(r.getInternalReader())
defer r.Close()
return jsonDecoder.Decode(&userStruct)
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"JSON",
"(",
"userStruct",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"r",
".",
"Error",
"\n",
"}",
"\n\n",
"jsonDecoder",
":=",
"json",
".",
"NewDecoder",
... | // JSON is a method that will populate a struct that is provided `userStruct` with the JSON returned within the
// response body | [
"JSON",
"is",
"a",
"method",
"that",
"will",
"populate",
"a",
"struct",
"that",
"is",
"provided",
"userStruct",
"with",
"the",
"JSON",
"returned",
"within",
"the",
"response",
"body"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L130-L140 |
29,272 | levigross/grequests | response.go | String | func (r *Response) String() string {
if r.Error != nil {
return ""
}
r.populateResponseByteBuffer()
return r.internalByteBuffer.String()
} | go | func (r *Response) String() string {
if r.Error != nil {
return ""
}
r.populateResponseByteBuffer()
return r.internalByteBuffer.String()
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"String",
"(",
")",
"string",
"{",
"if",
"r",
".",
"Error",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"r",
".",
"populateResponseByteBuffer",
"(",
")",
"\n\n",
"return",
"r",
".",
"internalByte... | // String returns the response as a string | [
"String",
"returns",
"the",
"response",
"as",
"a",
"string"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L188-L196 |
29,273 | levigross/grequests | file_upload.go | FileUploadFromDisk | func FileUploadFromDisk(fileName string) ([]FileUpload, error) {
fd, err := os.Open(fileName)
if err != nil {
return nil, err
}
return []FileUpload{{FileContents: fd, FileName: fileName}}, nil
} | go | func FileUploadFromDisk(fileName string) ([]FileUpload, error) {
fd, err := os.Open(fileName)
if err != nil {
return nil, err
}
return []FileUpload{{FileContents: fd, FileName: fileName}}, nil
} | [
"func",
"FileUploadFromDisk",
"(",
"fileName",
"string",
")",
"(",
"[",
"]",
"FileUpload",
",",
"error",
")",
"{",
"fd",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"fileName",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
... | // FileUploadFromDisk allows you to create a FileUpload struct slice by just specifying a location on the disk | [
"FileUploadFromDisk",
"allows",
"you",
"to",
"create",
"a",
"FileUpload",
"struct",
"slice",
"by",
"just",
"specifying",
"a",
"location",
"on",
"the",
"disk"
] | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/file_upload.go#L28-L37 |
29,274 | levigross/grequests | file_upload.go | FileUploadFromGlob | func FileUploadFromGlob(fileSystemGlob string) ([]FileUpload, error) {
files, err := filepath.Glob(fileSystemGlob)
if err != nil {
return nil, err
}
if len(files) == 0 {
return nil, errors.New("grequests: No files have been returned in the glob")
}
filesToUpload := make([]FileUpload, 0, len(files))
for _... | go | func FileUploadFromGlob(fileSystemGlob string) ([]FileUpload, error) {
files, err := filepath.Glob(fileSystemGlob)
if err != nil {
return nil, err
}
if len(files) == 0 {
return nil, errors.New("grequests: No files have been returned in the glob")
}
filesToUpload := make([]FileUpload, 0, len(files))
for _... | [
"func",
"FileUploadFromGlob",
"(",
"fileSystemGlob",
"string",
")",
"(",
"[",
"]",
"FileUpload",
",",
"error",
")",
"{",
"files",
",",
"err",
":=",
"filepath",
".",
"Glob",
"(",
"fileSystemGlob",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil... | // FileUploadFromGlob allows you to create a FileUpload struct slice by just specifying a glob location on the disk
// this function will gloss over all errors in the files and only upload the files that don't return errors from the glob | [
"FileUploadFromGlob",
"allows",
"you",
"to",
"create",
"a",
"FileUpload",
"struct",
"slice",
"by",
"just",
"specifying",
"a",
"glob",
"location",
"on",
"the",
"disk",
"this",
"function",
"will",
"gloss",
"over",
"all",
"errors",
"in",
"the",
"files",
"and",
... | 37c80f76a0dae6ed656cbc830643ba53f45fc79c | https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/file_upload.go#L41-L68 |
29,275 | ahmetb/go-linq | orderby.go | OrderBy | func (q Query) OrderBy(selector func(interface{}) interface{}) OrderedQuery {
return OrderedQuery{
orders: []order{{selector: selector}},
original: q,
Query: Query{
Iterate: func() Iterator {
items := q.sort([]order{{selector: selector}})
len := len(items)
index := 0
return func() (item int... | go | func (q Query) OrderBy(selector func(interface{}) interface{}) OrderedQuery {
return OrderedQuery{
orders: []order{{selector: selector}},
original: q,
Query: Query{
Iterate: func() Iterator {
items := q.sort([]order{{selector: selector}})
len := len(items)
index := 0
return func() (item int... | [
"func",
"(",
"q",
"Query",
")",
"OrderBy",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"OrderedQuery",
"{",
"return",
"OrderedQuery",
"{",
"orders",
":",
"[",
"]",
"order",
"{",
"{",
"selector",
":",
"selector"... | // OrderBy sorts the elements of a collection in ascending order. Elements are
// sorted according to a key. | [
"OrderBy",
"sorts",
"the",
"elements",
"of",
"a",
"collection",
"in",
"ascending",
"order",
".",
"Elements",
"are",
"sorted",
"according",
"to",
"a",
"key",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/orderby.go#L21-L43 |
29,276 | ahmetb/go-linq | orderby.go | ThenByDescending | func (oq OrderedQuery) ThenByDescending(selector func(interface{}) interface{}) OrderedQuery {
return OrderedQuery{
orders: append(oq.orders, order{selector: selector, desc: true}),
original: oq.original,
Query: Query{
Iterate: func() Iterator {
items := oq.original.sort(append(oq.orders, order{selector... | go | func (oq OrderedQuery) ThenByDescending(selector func(interface{}) interface{}) OrderedQuery {
return OrderedQuery{
orders: append(oq.orders, order{selector: selector, desc: true}),
original: oq.original,
Query: Query{
Iterate: func() Iterator {
items := oq.original.sort(append(oq.orders, order{selector... | [
"func",
"(",
"oq",
"OrderedQuery",
")",
"ThenByDescending",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"OrderedQuery",
"{",
"return",
"OrderedQuery",
"{",
"orders",
":",
"append",
"(",
"oq",
".",
"orders",
",",
... | // ThenByDescending performs a subsequent ordering of the elements in a
// collection in descending order. This method enables you to specify multiple
// sort criteria by applying any number of ThenBy or ThenByDescending methods. | [
"ThenByDescending",
"performs",
"a",
"subsequent",
"ordering",
"of",
"the",
"elements",
"in",
"a",
"collection",
"in",
"descending",
"order",
".",
"This",
"method",
"enables",
"you",
"to",
"specify",
"multiple",
"sort",
"criteria",
"by",
"applying",
"any",
"numb... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/orderby.go#L161-L183 |
29,277 | ahmetb/go-linq | orderby.go | Sort | func (q Query) Sort(less func(i, j interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
items := q.lessSort(less)
len := len(items)
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = items[index]
index++
}
return
}
},
}
... | go | func (q Query) Sort(less func(i, j interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
items := q.lessSort(less)
len := len(items)
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = items[index]
index++
}
return
}
},
}
... | [
"func",
"(",
"q",
"Query",
")",
"Sort",
"(",
"less",
"func",
"(",
"i",
",",
"j",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"items",
":=",
"q",
".",
"lessSort"... | // Sort returns a new query by sorting elements with provided less function in
// ascending order. The comparer function should return true if the parameter i
// is less than j. While this method is uglier than chaining OrderBy,
// OrderByDescending, ThenBy and ThenByDescending methods, it's performance is
// much bett... | [
"Sort",
"returns",
"a",
"new",
"query",
"by",
"sorting",
"elements",
"with",
"provided",
"less",
"function",
"in",
"ascending",
"order",
".",
"The",
"comparer",
"function",
"should",
"return",
"true",
"if",
"the",
"parameter",
"i",
"is",
"less",
"than",
"j",... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/orderby.go#L211-L229 |
29,278 | ahmetb/go-linq | join.go | Join | func (q Query) Join(inner Query,
outerKeySelector func(interface{}) interface{},
innerKeySelector func(interface{}) interface{},
resultSelector func(outer interface{}, inner interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
innernext := inner.Iterate()
... | go | func (q Query) Join(inner Query,
outerKeySelector func(interface{}) interface{},
innerKeySelector func(interface{}) interface{},
resultSelector func(outer interface{}, inner interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
innernext := inner.Iterate()
... | [
"func",
"(",
"q",
"Query",
")",
"Join",
"(",
"inner",
"Query",
",",
"outerKeySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"innerKeySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"resul... | // Join correlates the elements of two collection based on matching keys.
//
// A join refers to the operation of correlating the elements of two sources of
// information based on a common key. Join brings the two information sources
// and the keys by which they are matched together in one method call. This
// differ... | [
"Join",
"correlates",
"the",
"elements",
"of",
"two",
"collection",
"based",
"on",
"matching",
"keys",
".",
"A",
"join",
"refers",
"to",
"the",
"operation",
"of",
"correlating",
"the",
"elements",
"of",
"two",
"sources",
"of",
"information",
"based",
"on",
"... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/join.go#L13-L54 |
29,279 | ahmetb/go-linq | skip.go | Skip | func (q Query) Skip(count int) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
n := count
return func() (item interface{}, ok bool) {
for ; n > 0; n-- {
item, ok = next()
if !ok {
return
}
}
return next()
}
},
}
} | go | func (q Query) Skip(count int) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
n := count
return func() (item interface{}, ok bool) {
for ; n > 0; n-- {
item, ok = next()
if !ok {
return
}
}
return next()
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Skip",
"(",
"count",
"int",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"n",
":=",
"count",
"\n\n",
"return",
"f... | // Skip bypasses a specified number of elements in a collection and then returns
// the remaining elements. | [
"Skip",
"bypasses",
"a",
"specified",
"number",
"of",
"elements",
"in",
"a",
"collection",
"and",
"then",
"returns",
"the",
"remaining",
"elements",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/skip.go#L5-L23 |
29,280 | ahmetb/go-linq | skip.go | SkipWhile | func (q Query) SkipWhile(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
ready := false
return func() (item interface{}, ok bool) {
for !ready {
item, ok = next()
if !ok {
return
}
ready = !predicate(item)
if ready {... | go | func (q Query) SkipWhile(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
ready := false
return func() (item interface{}, ok bool) {
for !ready {
item, ok = next()
if !ok {
return
}
ready = !predicate(item)
if ready {... | [
"func",
"(",
"q",
"Query",
")",
"SkipWhile",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")... | // SkipWhile bypasses elements in a collection as long as a specified condition
// is true and then returns the remaining elements.
//
// This method tests each element by using predicate and skips the element if
// the result is true. After the predicate function returns false for an
// element, that element and the r... | [
"SkipWhile",
"bypasses",
"elements",
"in",
"a",
"collection",
"as",
"long",
"as",
"a",
"specified",
"condition",
"is",
"true",
"and",
"then",
"returns",
"the",
"remaining",
"elements",
".",
"This",
"method",
"tests",
"each",
"element",
"by",
"using",
"predicat... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/skip.go#L32-L55 |
29,281 | ahmetb/go-linq | skip.go | SkipWhileIndexed | func (q Query) SkipWhileIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
ready := false
index := 0
return func() (item interface{}, ok bool) {
for !ready {
item, ok = next()
if !ok {
return
}
ready = !predi... | go | func (q Query) SkipWhileIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
ready := false
index := 0
return func() (item interface{}, ok bool) {
for !ready {
item, ok = next()
if !ok {
return
}
ready = !predi... | [
"func",
"(",
"q",
"Query",
")",
"SkipWhileIndexed",
"(",
"predicate",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
... | // SkipWhileIndexed bypasses elements in a collection as long as a specified
// condition is true and then returns the remaining elements. The element's
// index is used in the logic of the predicate function.
//
// This method tests each element by using predicate and skips the element if
// the result is true. After ... | [
"SkipWhileIndexed",
"bypasses",
"elements",
"in",
"a",
"collection",
"as",
"long",
"as",
"a",
"specified",
"condition",
"is",
"true",
"and",
"then",
"returns",
"the",
"remaining",
"elements",
".",
"The",
"element",
"s",
"index",
"is",
"used",
"in",
"the",
"l... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/skip.go#L87-L113 |
29,282 | ahmetb/go-linq | take.go | TakeWhile | func (q Query) TakeWhile(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
done := false
return func() (item interface{}, ok bool) {
if done {
return
}
item, ok = next()
if !ok {
done = true
return
}
if predicate(... | go | func (q Query) TakeWhile(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
done := false
return func() (item interface{}, ok bool) {
if done {
return
}
item, ok = next()
if !ok {
done = true
return
}
if predicate(... | [
"func",
"(",
"q",
"Query",
")",
"TakeWhile",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")... | // TakeWhile returns elements from a collection as long as a specified condition
// is true, and then skips the remaining elements. | [
"TakeWhile",
"returns",
"elements",
"from",
"a",
"collection",
"as",
"long",
"as",
"a",
"specified",
"condition",
"is",
"true",
"and",
"then",
"skips",
"the",
"remaining",
"elements",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/take.go#L25-L51 |
29,283 | ahmetb/go-linq | take.go | TakeWhileIndexed | func (q Query) TakeWhileIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
done := false
index := 0
return func() (item interface{}, ok bool) {
if done {
return
}
item, ok = next()
if !ok {
done = true
retur... | go | func (q Query) TakeWhileIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
done := false
index := 0
return func() (item interface{}, ok bool) {
if done {
return
}
item, ok = next()
if !ok {
done = true
retur... | [
"func",
"(",
"q",
"Query",
")",
"TakeWhileIndexed",
"(",
"predicate",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
... | // TakeWhileIndexed returns elements from a collection as long as a specified
// condition is true. The element's index is used in the logic of the predicate
// function. The first argument of predicate represents the zero-based index of
// the element within collection. The second argument represents the element to
//... | [
"TakeWhileIndexed",
"returns",
"elements",
"from",
"a",
"collection",
"as",
"long",
"as",
"a",
"specified",
"condition",
"is",
"true",
".",
"The",
"element",
"s",
"index",
"is",
"used",
"in",
"the",
"logic",
"of",
"the",
"predicate",
"function",
".",
"The",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/take.go#L80-L108 |
29,284 | ahmetb/go-linq | except.go | Except | func (q Query) Except(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
set := make(map[interface{}]bool)
for i, ok := next2(); ok; i, ok = next2() {
set[i] = true
}
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; i... | go | func (q Query) Except(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
set := make(map[interface{}]bool)
for i, ok := next2(); ok; i, ok = next2() {
set[i] = true
}
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; i... | [
"func",
"(",
"q",
"Query",
")",
"Except",
"(",
"q2",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"next2",
":=",
"q2",
".",
"Iterate",
... | // Except produces the set difference of two sequences. The set difference is
// the members of the first sequence that don't appear in the second sequence. | [
"Except",
"produces",
"the",
"set",
"difference",
"of",
"two",
"sequences",
".",
"The",
"set",
"difference",
"is",
"the",
"members",
"of",
"the",
"first",
"sequence",
"that",
"don",
"t",
"appear",
"in",
"the",
"second",
"sequence",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/except.go#L5-L27 |
29,285 | ahmetb/go-linq | selectmany.go | SelectMany | func (q Query) SelectMany(selector func(interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = outernext()
if !ok {... | go | func (q Query) SelectMany(selector func(interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = outernext()
if !ok {... | [
"func",
"(",
"q",
"Query",
")",
"SelectMany",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"outernext",
":=",
"q",
".",
"Iterate",
"("... | // SelectMany projects each element of a collection to a Query, iterates and
// flattens the resulting collection into one collection. | [
"SelectMany",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L5-L33 |
29,286 | ahmetb/go-linq | selectmany.go | SelectManyIndexed | func (q Query) SelectManyIndexed(selector func(int, interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = ... | go | func (q Query) SelectManyIndexed(selector func(int, interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = ... | [
"func",
"(",
"q",
"Query",
")",
"SelectManyIndexed",
"(",
"selector",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"outernext",
":=",
"q",
... | // SelectManyIndexed projects each element of a collection to a Query, iterates
// and flattens the resulting collection into one collection.
//
// The first argument to selector represents the zero-based index of that
// element in the source collection. This can be useful if the elements are in a
// known order and y... | [
"SelectManyIndexed",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
".",
"The",
"first",
"argument",
"to",
"selector",
"represents",
"the",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L66-L96 |
29,287 | ahmetb/go-linq | selectmany.go | SelectManyBy | func (q Query) SelectManyBy(selector func(interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
... | go | func (q Query) SelectManyBy(selector func(interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
... | [
"func",
"(",
"q",
"Query",
")",
"SelectManyBy",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"Query",
",",
"resultSelector",
"func",
"(",
"interface",
"{",
"}",
",",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"... | // SelectManyBy projects each element of a collection to a Query, iterates and
// flattens the resulting collection into one collection, and invokes a result
// selector function on each element therein. | [
"SelectManyBy",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
"and",
"invokes",
"a",
"result",
"selector",
"function",
"on",
"each",
"elem... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L123-L154 |
29,288 | ahmetb/go-linq | selectmany.go | SelectManyByIndexed | func (q Query) SelectManyByIndexed(selector func(int, interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok ... | go | func (q Query) SelectManyByIndexed(selector func(int, interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok ... | [
"func",
"(",
"q",
"Query",
")",
"SelectManyByIndexed",
"(",
"selector",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"Query",
",",
"resultSelector",
"func",
"(",
"interface",
"{",
"}",
",",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")"... | // SelectManyByIndexed projects each element of a collection to a Query,
// iterates and flattens the resulting collection into one collection, and
// invokes a result selector function on each element therein. The index of each
// source element is used in the intermediate projected form of that element. | [
"SelectManyByIndexed",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
"and",
"invokes",
"a",
"result",
"selector",
"function",
"on",
"each",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L196-L229 |
29,289 | ahmetb/go-linq | where.go | Where | func (q Query) Where(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(item) {
return
}
}
return
}
},
}
} | go | func (q Query) Where(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(item) {
return
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Where",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
... | // Where filters a collection of values based on a predicate. | [
"Where",
"filters",
"a",
"collection",
"of",
"values",
"based",
"on",
"a",
"predicate",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/where.go#L4-L20 |
29,290 | ahmetb/go-linq | where.go | WhereIndexed | func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
index := 0
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(index, item) {
return
}
index+... | go | func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
index := 0
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(index, item) {
return
}
index+... | [
"func",
"(",
"q",
"Query",
")",
"WhereIndexed",
"(",
"predicate",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"It... | // WhereIndexed filters a collection of values based on a predicate. Each
// element's index is used in the logic of the predicate function.
//
// The first argument represents the zero-based index of the element within
// collection. The second argument of predicate represents the element to test. | [
"WhereIndexed",
"filters",
"a",
"collection",
"of",
"values",
"based",
"on",
"a",
"predicate",
".",
"Each",
"element",
"s",
"index",
"is",
"used",
"in",
"the",
"logic",
"of",
"the",
"predicate",
"function",
".",
"The",
"first",
"argument",
"represents",
"the... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/where.go#L49-L68 |
29,291 | ahmetb/go-linq | groupjoin.go | GroupJoin | func (q Query) GroupJoin(inner Query,
outerKeySelector func(interface{}) interface{},
innerKeySelector func(interface{}) interface{},
resultSelector func(outer interface{}, inners []interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
innernext := inner.Iterat... | go | func (q Query) GroupJoin(inner Query,
outerKeySelector func(interface{}) interface{},
innerKeySelector func(interface{}) interface{},
resultSelector func(outer interface{}, inners []interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
innernext := inner.Iterat... | [
"func",
"(",
"q",
"Query",
")",
"GroupJoin",
"(",
"inner",
"Query",
",",
"outerKeySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"innerKeySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"... | // GroupJoin correlates the elements of two collections based on key equality,
// and groups the results.
//
// This method produces hierarchical results, which means that elements from
// outer query are paired with collections of matching elements from inner.
// GroupJoin enables you to base your results on a whole s... | [
"GroupJoin",
"correlates",
"the",
"elements",
"of",
"two",
"collections",
"based",
"on",
"key",
"equality",
"and",
"groups",
"the",
"results",
".",
"This",
"method",
"produces",
"hierarchical",
"results",
"which",
"means",
"that",
"elements",
"from",
"outer",
"q... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/groupjoin.go#L21-L52 |
29,292 | ahmetb/go-linq | distinct.go | Distinct | func (q Query) Distinct() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
... | go | func (q Query) Distinct() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
... | [
"func",
"(",
"q",
"Query",
")",
"Distinct",
"(",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"set",
":=",
"make",
"(",
"map",
"[",
"interface",
"... | // Distinct method returns distinct elements from a collection. The result is an
// unordered collection that contains no duplicate values. | [
"Distinct",
"method",
"returns",
"distinct",
"elements",
"from",
"a",
"collection",
".",
"The",
"result",
"is",
"an",
"unordered",
"collection",
"that",
"contains",
"no",
"duplicate",
"values",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/distinct.go#L5-L23 |
29,293 | ahmetb/go-linq | distinct.go | DistinctBy | func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
s := selector(item)
if _, has := ... | go | func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
s := selector(item)
if _, has := ... | [
"func",
"(",
"q",
"Query",
")",
"DistinctBy",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"It... | // DistinctBy method returns distinct elements from a collection. This method
// executes selector function for each element to determine a value to compare.
// The result is an unordered collection that contains no duplicate values. | [
"DistinctBy",
"method",
"returns",
"distinct",
"elements",
"from",
"a",
"collection",
".",
"This",
"method",
"executes",
"selector",
"function",
"for",
"each",
"element",
"to",
"determine",
"a",
"value",
"to",
"compare",
".",
"The",
"result",
"is",
"an",
"unor... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/distinct.go#L56-L75 |
29,294 | ahmetb/go-linq | groupby.go | GroupBy | func (q Query) GroupBy(keySelector func(interface{}) interface{},
elementSelector func(interface{}) interface{}) Query {
return Query{
func() Iterator {
next := q.Iterate()
set := make(map[interface{}][]interface{})
for item, ok := next(); ok; item, ok = next() {
key := keySelector(item)
set[key] ... | go | func (q Query) GroupBy(keySelector func(interface{}) interface{},
elementSelector func(interface{}) interface{}) Query {
return Query{
func() Iterator {
next := q.Iterate()
set := make(map[interface{}][]interface{})
for item, ok := next(); ok; item, ok = next() {
key := keySelector(item)
set[key] ... | [
"func",
"(",
"q",
"Query",
")",
"GroupBy",
"(",
"keySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"elementSelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",... | // GroupBy method groups the elements of a collection according to a specified
// key selector function and projects the elements for each group by using a
// specified function. | [
"GroupBy",
"method",
"groups",
"the",
"elements",
"of",
"a",
"collection",
"according",
"to",
"a",
"specified",
"key",
"selector",
"function",
"and",
"projects",
"the",
"elements",
"for",
"each",
"group",
"by",
"using",
"a",
"specified",
"function",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/groupby.go#L12-L45 |
29,295 | ahmetb/go-linq | result.go | All | func (q Query) All(predicate func(interface{}) bool) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if !predicate(item) {
return false
}
}
return true
} | go | func (q Query) All(predicate func(interface{}) bool) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if !predicate(item) {
return false
}
}
return true
} | [
"func",
"(",
"q",
"Query",
")",
"All",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"bool",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
... | // All determines whether all elements of a collection satisfy a condition. | [
"All",
"determines",
"whether",
"all",
"elements",
"of",
"a",
"collection",
"satisfy",
"a",
"condition",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L9-L19 |
29,296 | ahmetb/go-linq | result.go | Average | func (q Query) Average() (r float64) {
next := q.Iterate()
item, ok := next()
if !ok {
return math.NaN()
}
n := 1
switch item.(type) {
case int, int8, int16, int32, int64:
conv := getIntConverter(item)
sum := conv(item)
for item, ok = next(); ok; item, ok = next() {
sum += conv(item)
n++
}
r... | go | func (q Query) Average() (r float64) {
next := q.Iterate()
item, ok := next()
if !ok {
return math.NaN()
}
n := 1
switch item.(type) {
case int, int8, int16, int32, int64:
conv := getIntConverter(item)
sum := conv(item)
for item, ok = next(); ok; item, ok = next() {
sum += conv(item)
n++
}
r... | [
"func",
"(",
"q",
"Query",
")",
"Average",
"(",
")",
"(",
"r",
"float64",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"item",
",",
"ok",
":=",
"next",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"math",
".",
"NaN",
"(",
... | // Average computes the average of a collection of numeric values. | [
"Average",
"computes",
"the",
"average",
"of",
"a",
"collection",
"of",
"numeric",
"values",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L84-L124 |
29,297 | ahmetb/go-linq | result.go | Contains | func (q Query) Contains(value interface{}) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if item == value {
return true
}
}
return false
} | go | func (q Query) Contains(value interface{}) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if item == value {
return true
}
}
return false
} | [
"func",
"(",
"q",
"Query",
")",
"Contains",
"(",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"item",
",",
"ok",
"=",
... | // Contains determines whether a collection contains a specified element. | [
"Contains",
"determines",
"whether",
"a",
"collection",
"contains",
"a",
"specified",
"element",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L127-L137 |
29,298 | ahmetb/go-linq | result.go | Count | func (q Query) Count() (r int) {
next := q.Iterate()
for _, ok := next(); ok; _, ok = next() {
r++
}
return
} | go | func (q Query) Count() (r int) {
next := q.Iterate()
for _, ok := next(); ok; _, ok = next() {
r++
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"Count",
"(",
")",
"(",
"r",
"int",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"_",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"_",
",",
"ok",
"=",
"next",
"(",
")",
"{",
... | // Count returns the number of elements in a collection. | [
"Count",
"returns",
"the",
"number",
"of",
"elements",
"in",
"a",
"collection",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L140-L148 |
29,299 | ahmetb/go-linq | result.go | CountWith | func (q Query) CountWith(predicate func(interface{}) bool) (r int) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
r++
}
}
return
} | go | func (q Query) CountWith(predicate func(interface{}) bool) (r int) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
r++
}
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"CountWith",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"(",
"r",
"int",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")... | // CountWith returns a number that represents how many elements in the specified
// collection satisfy a condition. | [
"CountWith",
"returns",
"a",
"number",
"that",
"represents",
"how",
"many",
"elements",
"in",
"the",
"specified",
"collection",
"satisfy",
"a",
"condition",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L152-L162 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.