id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,800 |
rollbar/rollbar-go
|
client.go
|
ErrorWithLevel
|
func (c *Client) ErrorWithLevel(level string, err error) {
c.ErrorWithExtras(level, err, noExtras)
}
|
go
|
func (c *Client) ErrorWithLevel(level string, err error) {
c.ErrorWithExtras(level, err, noExtras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ErrorWithLevel",
"(",
"level",
"string",
",",
"err",
"error",
")",
"{",
"c",
".",
"ErrorWithExtras",
"(",
"level",
",",
"err",
",",
"noExtras",
")",
"\n",
"}"
] |
// ErrorWithLevel sends an error to Rollbar with the given severity level.
|
[
"ErrorWithLevel",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L267-L269
|
13,801 |
rollbar/rollbar-go
|
client.go
|
Errorf
|
func (c *Client) Errorf(level string, format string, args ...interface{}) {
c.ErrorWithStackSkipWithExtras(level, fmt.Errorf(format, args...), 1, noExtras)
}
|
go
|
func (c *Client) Errorf(level string, format string, args ...interface{}) {
c.ErrorWithStackSkipWithExtras(level, fmt.Errorf(format, args...), 1, noExtras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Errorf",
"(",
"level",
"string",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"ErrorWithStackSkipWithExtras",
"(",
"level",
",",
"fmt",
".",
"Errorf",
"(",
"format",
",",
"args",
"...",
")",
",",
"1",
",",
"noExtras",
")",
"\n",
"}"
] |
// Errorf sends an error to Rollbar with the given format string and arguments.
|
[
"Errorf",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"format",
"string",
"and",
"arguments",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L272-L274
|
13,802 |
rollbar/rollbar-go
|
client.go
|
ErrorWithExtras
|
func (c *Client) ErrorWithExtras(level string, err error, extras map[string]interface{}) {
c.ErrorWithStackSkipWithExtras(level, err, 1, extras)
}
|
go
|
func (c *Client) ErrorWithExtras(level string, err error, extras map[string]interface{}) {
c.ErrorWithStackSkipWithExtras(level, err, 1, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ErrorWithExtras",
"(",
"level",
"string",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"ErrorWithStackSkipWithExtras",
"(",
"level",
",",
"err",
",",
"1",
",",
"extras",
")",
"\n",
"}"
] |
// ErrorWithExtras sends an error to Rollbar with the given severity
// level with extra custom data.
|
[
"ErrorWithExtras",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L278-L280
|
13,803 |
rollbar/rollbar-go
|
client.go
|
ErrorWithExtrasAndContext
|
func (c *Client) ErrorWithExtrasAndContext(ctx context.Context, level string, err error, extras map[string]interface{}) {
c.ErrorWithStackSkipWithExtrasAndContext(ctx, level, err, 1, extras)
}
|
go
|
func (c *Client) ErrorWithExtrasAndContext(ctx context.Context, level string, err error, extras map[string]interface{}) {
c.ErrorWithStackSkipWithExtrasAndContext(ctx, level, err, 1, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ErrorWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"ErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"err",
",",
"1",
",",
"extras",
")",
"\n",
"}"
] |
// ErrorWithExtrasAndContext sends an error to Rollbar with the given severity
// level with extra custom data, within the given context.
|
[
"ErrorWithExtrasAndContext",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L284-L286
|
13,804 |
rollbar/rollbar-go
|
client.go
|
RequestError
|
func (c *Client) RequestError(level string, r *http.Request, err error) {
c.RequestErrorWithExtras(level, r, err, noExtras)
}
|
go
|
func (c *Client) RequestError(level string, r *http.Request, err error) {
c.RequestErrorWithExtras(level, r, err, noExtras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestError",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
")",
"{",
"c",
".",
"RequestErrorWithExtras",
"(",
"level",
",",
"r",
",",
"err",
",",
"noExtras",
")",
"\n",
"}"
] |
// RequestError sends an error to Rollbar with the given severity level
// and request-specific information.
|
[
"RequestError",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L290-L292
|
13,805 |
rollbar/rollbar-go
|
client.go
|
RequestErrorWithExtras
|
func (c *Client) RequestErrorWithExtras(level string, r *http.Request, err error, extras map[string]interface{}) {
c.RequestErrorWithStackSkipWithExtras(level, r, err, 1, extras)
}
|
go
|
func (c *Client) RequestErrorWithExtras(level string, r *http.Request, err error, extras map[string]interface{}) {
c.RequestErrorWithStackSkipWithExtras(level, r, err, 1, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestErrorWithExtras",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"RequestErrorWithStackSkipWithExtras",
"(",
"level",
",",
"r",
",",
"err",
",",
"1",
",",
"extras",
")",
"\n",
"}"
] |
// RequestErrorWithExtras sends an error to Rollbar with the given
// severity level and request-specific information with extra custom data.
|
[
"RequestErrorWithExtras",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"with",
"extra",
"custom",
"data",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L296-L298
|
13,806 |
rollbar/rollbar-go
|
client.go
|
RequestErrorWithExtrasAndContext
|
func (c *Client) RequestErrorWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, extras map[string]interface{}) {
c.RequestErrorWithStackSkipWithExtrasAndContext(ctx, level, r, err, 1, extras)
}
|
go
|
func (c *Client) RequestErrorWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, extras map[string]interface{}) {
c.RequestErrorWithStackSkipWithExtrasAndContext(ctx, level, r, err, 1, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestErrorWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"RequestErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
",",
"level",
",",
"r",
",",
"err",
",",
"1",
",",
"extras",
")",
"\n",
"}"
] |
// RequestErrorWithExtrasAndContext sends an error to Rollbar with the given
// severity level and request-specific information with extra custom data, within the given
// context.
|
[
"RequestErrorWithExtrasAndContext",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L303-L305
|
13,807 |
rollbar/rollbar-go
|
client.go
|
ErrorWithStackSkip
|
func (c *Client) ErrorWithStackSkip(level string, err error, skip int) {
c.ErrorWithStackSkipWithExtras(level, err, skip, noExtras)
}
|
go
|
func (c *Client) ErrorWithStackSkip(level string, err error, skip int) {
c.ErrorWithStackSkipWithExtras(level, err, skip, noExtras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ErrorWithStackSkip",
"(",
"level",
"string",
",",
"err",
"error",
",",
"skip",
"int",
")",
"{",
"c",
".",
"ErrorWithStackSkipWithExtras",
"(",
"level",
",",
"err",
",",
"skip",
",",
"noExtras",
")",
"\n",
"}"
] |
// ErrorWithStackSkip sends an error to Rollbar with the given severity
// level and a given number of stack trace frames skipped.
|
[
"ErrorWithStackSkip",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L309-L311
|
13,808 |
rollbar/rollbar-go
|
client.go
|
ErrorWithStackSkipWithExtras
|
func (c *Client) ErrorWithStackSkipWithExtras(level string, err error, skip int, extras map[string]interface{}) {
c.ErrorWithStackSkipWithExtrasAndContext(context.TODO(), level, err, skip, extras)
}
|
go
|
func (c *Client) ErrorWithStackSkipWithExtras(level string, err error, skip int, extras map[string]interface{}) {
c.ErrorWithStackSkipWithExtrasAndContext(context.TODO(), level, err, skip, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ErrorWithStackSkipWithExtras",
"(",
"level",
"string",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"ErrorWithStackSkipWithExtrasAndContext",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"level",
",",
"err",
",",
"skip",
",",
"extras",
")",
"\n",
"}"
] |
// ErrorWithStackSkipWithExtras sends an error to Rollbar with the given
// severity level and a given number of stack trace frames skipped with
// extra custom data.
|
[
"ErrorWithStackSkipWithExtras",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"with",
"extra",
"custom",
"data",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L316-L318
|
13,809 |
rollbar/rollbar-go
|
client.go
|
ErrorWithStackSkipWithExtrasAndContext
|
func (c *Client) ErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, err error, skip int, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, err.Error(), extras)
addErrorToBody(c.configuration, body, err, skip)
c.push(body)
}
|
go
|
func (c *Client) ErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, err error, skip int, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, err.Error(), extras)
addErrorToBody(c.configuration, body, err, skip)
c.push(body)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"c",
".",
"configuration",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n",
"body",
":=",
"c",
".",
"buildBody",
"(",
"ctx",
",",
"level",
",",
"err",
".",
"Error",
"(",
")",
",",
"extras",
")",
"\n",
"addErrorToBody",
"(",
"c",
".",
"configuration",
",",
"body",
",",
"err",
",",
"skip",
")",
"\n",
"c",
".",
"push",
"(",
"body",
")",
"\n",
"}"
] |
// ErrorWithStackSkipWithExtrasAndContext sends an error to Rollbar with the given
// severity level and a given number of stack trace frames skipped with
// extra custom data, within the given context.
|
[
"ErrorWithStackSkipWithExtrasAndContext",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L323-L330
|
13,810 |
rollbar/rollbar-go
|
client.go
|
RequestErrorWithStackSkip
|
func (c *Client) RequestErrorWithStackSkip(level string, r *http.Request, err error, skip int) {
c.RequestErrorWithStackSkipWithExtras(level, r, err, skip, noExtras)
}
|
go
|
func (c *Client) RequestErrorWithStackSkip(level string, r *http.Request, err error, skip int) {
c.RequestErrorWithStackSkipWithExtras(level, r, err, skip, noExtras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestErrorWithStackSkip",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"skip",
"int",
")",
"{",
"c",
".",
"RequestErrorWithStackSkipWithExtras",
"(",
"level",
",",
"r",
",",
"err",
",",
"skip",
",",
"noExtras",
")",
"\n",
"}"
] |
// RequestErrorWithStackSkip sends an error to Rollbar with the given
// severity level and a given number of stack trace frames skipped, in
// addition to extra request-specific information.
|
[
"RequestErrorWithStackSkip",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L335-L337
|
13,811 |
rollbar/rollbar-go
|
client.go
|
RequestErrorWithStackSkipWithExtras
|
func (c *Client) RequestErrorWithStackSkipWithExtras(level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
c.RequestErrorWithStackSkipWithExtrasAndContext(context.TODO(), level, r, err, skip, extras)
}
|
go
|
func (c *Client) RequestErrorWithStackSkipWithExtras(level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
c.RequestErrorWithStackSkipWithExtrasAndContext(context.TODO(), level, r, err, skip, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestErrorWithStackSkipWithExtras",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"RequestErrorWithStackSkipWithExtrasAndContext",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"level",
",",
"r",
",",
"err",
",",
"skip",
",",
"extras",
")",
"\n",
"}"
] |
// RequestErrorWithStackSkipWithExtras sends an error to Rollbar with
// the given severity level and a given number of stack trace frames
// skipped, in addition to extra request-specific information and extra
// custom data.
|
[
"RequestErrorWithStackSkipWithExtras",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
"and",
"extra",
"custom",
"data",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L343-L345
|
13,812 |
rollbar/rollbar-go
|
client.go
|
RequestErrorWithStackSkipWithExtrasAndContext
|
func (c *Client) RequestErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, err.Error(), extras)
data := addErrorToBody(c.configuration, body, err, skip)
data["request"] = c.requestDetails(r)
c.push(body)
}
|
go
|
func (c *Client) RequestErrorWithStackSkipWithExtrasAndContext(ctx context.Context, level string, r *http.Request, err error, skip int, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, err.Error(), extras)
data := addErrorToBody(c.configuration, body, err, skip)
data["request"] = c.requestDetails(r)
c.push(body)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestErrorWithStackSkipWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"err",
"error",
",",
"skip",
"int",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"c",
".",
"configuration",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n",
"body",
":=",
"c",
".",
"buildBody",
"(",
"ctx",
",",
"level",
",",
"err",
".",
"Error",
"(",
")",
",",
"extras",
")",
"\n",
"data",
":=",
"addErrorToBody",
"(",
"c",
".",
"configuration",
",",
"body",
",",
"err",
",",
"skip",
")",
"\n",
"data",
"[",
"\"",
"\"",
"]",
"=",
"c",
".",
"requestDetails",
"(",
"r",
")",
"\n",
"c",
".",
"push",
"(",
"body",
")",
"\n",
"}"
] |
// RequestErrorWithStackSkipWithExtrasAndContext sends an error to Rollbar with
// the given severity level and a given number of stack trace frames
// skipped, in addition to extra request-specific information and extra
// custom data, within the given context.
|
[
"RequestErrorWithStackSkipWithExtrasAndContext",
"sends",
"an",
"error",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"a",
"given",
"number",
"of",
"stack",
"trace",
"frames",
"skipped",
"in",
"addition",
"to",
"extra",
"request",
"-",
"specific",
"information",
"and",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L351-L359
|
13,813 |
rollbar/rollbar-go
|
client.go
|
MessageWithExtras
|
func (c *Client) MessageWithExtras(level string, msg string, extras map[string]interface{}) {
c.MessageWithExtrasAndContext(context.TODO(), level, msg, extras)
}
|
go
|
func (c *Client) MessageWithExtras(level string, msg string, extras map[string]interface{}) {
c.MessageWithExtrasAndContext(context.TODO(), level, msg, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"MessageWithExtras",
"(",
"level",
"string",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"MessageWithExtrasAndContext",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"level",
",",
"msg",
",",
"extras",
")",
"\n",
"}"
] |
// MessageWithExtras sends a message to Rollbar with the given severity
// level with extra custom data.
|
[
"MessageWithExtras",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L370-L372
|
13,814 |
rollbar/rollbar-go
|
client.go
|
MessageWithExtrasAndContext
|
func (c *Client) MessageWithExtrasAndContext(ctx context.Context, level string, msg string, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, msg, extras)
data := body["data"].(map[string]interface{})
data["body"] = messageBody(msg)
c.push(body)
}
|
go
|
func (c *Client) MessageWithExtrasAndContext(ctx context.Context, level string, msg string, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, msg, extras)
data := body["data"].(map[string]interface{})
data["body"] = messageBody(msg)
c.push(body)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"MessageWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"c",
".",
"configuration",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n",
"body",
":=",
"c",
".",
"buildBody",
"(",
"ctx",
",",
"level",
",",
"msg",
",",
"extras",
")",
"\n",
"data",
":=",
"body",
"[",
"\"",
"\"",
"]",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"data",
"[",
"\"",
"\"",
"]",
"=",
"messageBody",
"(",
"msg",
")",
"\n",
"c",
".",
"push",
"(",
"body",
")",
"\n",
"}"
] |
// MessageWithExtrasAndContext sends a message to Rollbar with the given severity
// level with extra custom data, within the given context.
|
[
"MessageWithExtrasAndContext",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L376-L384
|
13,815 |
rollbar/rollbar-go
|
client.go
|
RequestMessage
|
func (c *Client) RequestMessage(level string, r *http.Request, msg string) {
c.RequestMessageWithExtras(level, r, msg, noExtras)
}
|
go
|
func (c *Client) RequestMessage(level string, r *http.Request, msg string) {
c.RequestMessageWithExtras(level, r, msg, noExtras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestMessage",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"msg",
"string",
")",
"{",
"c",
".",
"RequestMessageWithExtras",
"(",
"level",
",",
"r",
",",
"msg",
",",
"noExtras",
")",
"\n",
"}"
] |
// RequestMessage sends a message to Rollbar with the given severity level
// and request-specific information.
|
[
"RequestMessage",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L388-L390
|
13,816 |
rollbar/rollbar-go
|
client.go
|
RequestMessageWithExtras
|
func (c *Client) RequestMessageWithExtras(level string, r *http.Request, msg string, extras map[string]interface{}) {
c.RequestMessageWithExtrasAndContext(context.TODO(), level, r, msg, extras)
}
|
go
|
func (c *Client) RequestMessageWithExtras(level string, r *http.Request, msg string, extras map[string]interface{}) {
c.RequestMessageWithExtrasAndContext(context.TODO(), level, r, msg, extras)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestMessageWithExtras",
"(",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"c",
".",
"RequestMessageWithExtrasAndContext",
"(",
"context",
".",
"TODO",
"(",
")",
",",
"level",
",",
"r",
",",
"msg",
",",
"extras",
")",
"\n",
"}"
] |
// RequestMessageWithExtras sends a message to Rollbar with the given
// severity level and request-specific information with extra custom data.
|
[
"RequestMessageWithExtras",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"with",
"extra",
"custom",
"data",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L394-L396
|
13,817 |
rollbar/rollbar-go
|
client.go
|
RequestMessageWithExtrasAndContext
|
func (c *Client) RequestMessageWithExtrasAndContext(ctx context.Context, level string, r *http.Request, msg string, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, msg, extras)
data := body["data"].(map[string]interface{})
data["body"] = messageBody(msg)
data["request"] = c.requestDetails(r)
c.push(body)
}
|
go
|
func (c *Client) RequestMessageWithExtrasAndContext(ctx context.Context, level string, r *http.Request, msg string, extras map[string]interface{}) {
if !c.configuration.enabled {
return
}
body := c.buildBody(ctx, level, msg, extras)
data := body["data"].(map[string]interface{})
data["body"] = messageBody(msg)
data["request"] = c.requestDetails(r)
c.push(body)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RequestMessageWithExtrasAndContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"level",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"msg",
"string",
",",
"extras",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"c",
".",
"configuration",
".",
"enabled",
"{",
"return",
"\n",
"}",
"\n",
"body",
":=",
"c",
".",
"buildBody",
"(",
"ctx",
",",
"level",
",",
"msg",
",",
"extras",
")",
"\n",
"data",
":=",
"body",
"[",
"\"",
"\"",
"]",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"data",
"[",
"\"",
"\"",
"]",
"=",
"messageBody",
"(",
"msg",
")",
"\n",
"data",
"[",
"\"",
"\"",
"]",
"=",
"c",
".",
"requestDetails",
"(",
"r",
")",
"\n",
"c",
".",
"push",
"(",
"body",
")",
"\n",
"}"
] |
// RequestMessageWithExtrasAndContext sends a message to Rollbar with the given
// severity level and request-specific information with extra custom data, within the given
// context.
|
[
"RequestMessageWithExtrasAndContext",
"sends",
"a",
"message",
"to",
"Rollbar",
"with",
"the",
"given",
"severity",
"level",
"and",
"request",
"-",
"specific",
"information",
"with",
"extra",
"custom",
"data",
"within",
"the",
"given",
"context",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L401-L410
|
13,818 |
rollbar/rollbar-go
|
client.go
|
NewPersonContext
|
func NewPersonContext(ctx context.Context, p *Person) context.Context {
return context.WithValue(ctx, personKey, p)
}
|
go
|
func NewPersonContext(ctx context.Context, p *Person) context.Context {
return context.WithValue(ctx, personKey, p)
}
|
[
"func",
"NewPersonContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"p",
"*",
"Person",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"personKey",
",",
"p",
")",
"\n",
"}"
] |
// NewPersonContext returns a new Context that carries the person as a value.
|
[
"NewPersonContext",
"returns",
"a",
"new",
"Context",
"that",
"carries",
"the",
"person",
"as",
"a",
"value",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L510-L512
|
13,819 |
rollbar/rollbar-go
|
client.go
|
PersonFromContext
|
func PersonFromContext(ctx context.Context) (*Person, bool) {
p, ok := ctx.Value(personKey).(*Person)
return p, ok
}
|
go
|
func PersonFromContext(ctx context.Context) (*Person, bool) {
p, ok := ctx.Value(personKey).(*Person)
return p, ok
}
|
[
"func",
"PersonFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"Person",
",",
"bool",
")",
"{",
"p",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"personKey",
")",
".",
"(",
"*",
"Person",
")",
"\n",
"return",
"p",
",",
"ok",
"\n",
"}"
] |
// PersonFromContext returns the Person value stored in ctx, if any.
|
[
"PersonFromContext",
"returns",
"the",
"Person",
"value",
"stored",
"in",
"ctx",
"if",
"any",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L515-L518
|
13,820 |
rollbar/rollbar-go
|
client.go
|
clientPost
|
func clientPost(token, endpoint string, body map[string]interface{}, logger ClientLogger) (error, bool) {
if len(token) == 0 {
rollbarError(logger, "empty token")
return nil, false
}
jsonBody, err := json.Marshal(body)
if err != nil {
rollbarError(logger, "failed to encode payload: %s", err.Error())
return err, false
}
resp, err := http.Post(endpoint, "application/json", bytes.NewReader(jsonBody))
if err != nil {
rollbarError(logger, "POST failed: %s", err.Error())
return err, isTemporary(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
rollbarError(logger, "received response: %s", resp.Status)
// http.StatusTooManyRequests is only defined in Go 1.6+ so we use 429 directly
isRateLimit := resp.StatusCode == 429
return ErrHTTPError(resp.StatusCode), isRateLimit
}
return nil, false
}
|
go
|
func clientPost(token, endpoint string, body map[string]interface{}, logger ClientLogger) (error, bool) {
if len(token) == 0 {
rollbarError(logger, "empty token")
return nil, false
}
jsonBody, err := json.Marshal(body)
if err != nil {
rollbarError(logger, "failed to encode payload: %s", err.Error())
return err, false
}
resp, err := http.Post(endpoint, "application/json", bytes.NewReader(jsonBody))
if err != nil {
rollbarError(logger, "POST failed: %s", err.Error())
return err, isTemporary(err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
rollbarError(logger, "received response: %s", resp.Status)
// http.StatusTooManyRequests is only defined in Go 1.6+ so we use 429 directly
isRateLimit := resp.StatusCode == 429
return ErrHTTPError(resp.StatusCode), isRateLimit
}
return nil, false
}
|
[
"func",
"clientPost",
"(",
"token",
",",
"endpoint",
"string",
",",
"body",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"logger",
"ClientLogger",
")",
"(",
"error",
",",
"bool",
")",
"{",
"if",
"len",
"(",
"token",
")",
"==",
"0",
"{",
"rollbarError",
"(",
"logger",
",",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"jsonBody",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"rollbarError",
"(",
"logger",
",",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"err",
",",
"false",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"http",
".",
"Post",
"(",
"endpoint",
",",
"\"",
"\"",
",",
"bytes",
".",
"NewReader",
"(",
"jsonBody",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"rollbarError",
"(",
"logger",
",",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"err",
",",
"isTemporary",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"200",
"{",
"rollbarError",
"(",
"logger",
",",
"\"",
"\"",
",",
"resp",
".",
"Status",
")",
"\n",
"// http.StatusTooManyRequests is only defined in Go 1.6+ so we use 429 directly",
"isRateLimit",
":=",
"resp",
".",
"StatusCode",
"==",
"429",
"\n",
"return",
"ErrHTTPError",
"(",
"resp",
".",
"StatusCode",
")",
",",
"isRateLimit",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] |
// clientPost returns an error which indicates the type of error that occured while attempting to
// send the body input to the endpoint given, or nil if no error occurred. If error is not nil, the
// boolean return parameter indicates whether the error is temporary or not. If this boolean return
// value is true then the caller could call this function again with the same input and possibly
// see a non-error response.
|
[
"clientPost",
"returns",
"an",
"error",
"which",
"indicates",
"the",
"type",
"of",
"error",
"that",
"occured",
"while",
"attempting",
"to",
"send",
"the",
"body",
"input",
"to",
"the",
"endpoint",
"given",
"or",
"nil",
"if",
"no",
"error",
"occurred",
".",
"If",
"error",
"is",
"not",
"nil",
"the",
"boolean",
"return",
"parameter",
"indicates",
"whether",
"the",
"error",
"is",
"temporary",
"or",
"not",
".",
"If",
"this",
"boolean",
"return",
"value",
"is",
"true",
"then",
"the",
"caller",
"could",
"call",
"this",
"function",
"again",
"with",
"the",
"same",
"input",
"and",
"possibly",
"see",
"a",
"non",
"-",
"error",
"response",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/client.go#L579-L606
|
13,821 |
rollbar/rollbar-go
|
async_transport.go
|
NewAsyncTransport
|
func NewAsyncTransport(token string, endpoint string, buffer int) *AsyncTransport {
transport := &AsyncTransport{
Token: token,
Endpoint: endpoint,
Buffer: buffer,
RetryAttempts: DefaultRetryAttempts,
PrintPayloadOnError: true,
bodyChannel: make(chan payload, buffer),
}
go func() {
for p := range transport.bodyChannel {
err, canRetry := transport.post(p)
if err != nil {
if canRetry && p.retriesLeft > 0 {
p.retriesLeft -= 1
select {
case transport.bodyChannel <- p:
default:
// This can happen if the bodyChannel had an item added to it from another
// thread while we are processing such that the channel is now full. If we try
// to send the payload back to the channel without this select statement we
// could deadlock. Instead we consider this a retry failure.
if transport.PrintPayloadOnError {
writePayloadToStderr(transport.Logger, p.body)
}
transport.waitGroup.Done()
}
} else {
if transport.PrintPayloadOnError {
writePayloadToStderr(transport.Logger, p.body)
}
transport.waitGroup.Done()
}
} else {
transport.waitGroup.Done()
}
}
}()
return transport
}
|
go
|
func NewAsyncTransport(token string, endpoint string, buffer int) *AsyncTransport {
transport := &AsyncTransport{
Token: token,
Endpoint: endpoint,
Buffer: buffer,
RetryAttempts: DefaultRetryAttempts,
PrintPayloadOnError: true,
bodyChannel: make(chan payload, buffer),
}
go func() {
for p := range transport.bodyChannel {
err, canRetry := transport.post(p)
if err != nil {
if canRetry && p.retriesLeft > 0 {
p.retriesLeft -= 1
select {
case transport.bodyChannel <- p:
default:
// This can happen if the bodyChannel had an item added to it from another
// thread while we are processing such that the channel is now full. If we try
// to send the payload back to the channel without this select statement we
// could deadlock. Instead we consider this a retry failure.
if transport.PrintPayloadOnError {
writePayloadToStderr(transport.Logger, p.body)
}
transport.waitGroup.Done()
}
} else {
if transport.PrintPayloadOnError {
writePayloadToStderr(transport.Logger, p.body)
}
transport.waitGroup.Done()
}
} else {
transport.waitGroup.Done()
}
}
}()
return transport
}
|
[
"func",
"NewAsyncTransport",
"(",
"token",
"string",
",",
"endpoint",
"string",
",",
"buffer",
"int",
")",
"*",
"AsyncTransport",
"{",
"transport",
":=",
"&",
"AsyncTransport",
"{",
"Token",
":",
"token",
",",
"Endpoint",
":",
"endpoint",
",",
"Buffer",
":",
"buffer",
",",
"RetryAttempts",
":",
"DefaultRetryAttempts",
",",
"PrintPayloadOnError",
":",
"true",
",",
"bodyChannel",
":",
"make",
"(",
"chan",
"payload",
",",
"buffer",
")",
",",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"p",
":=",
"range",
"transport",
".",
"bodyChannel",
"{",
"err",
",",
"canRetry",
":=",
"transport",
".",
"post",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"canRetry",
"&&",
"p",
".",
"retriesLeft",
">",
"0",
"{",
"p",
".",
"retriesLeft",
"-=",
"1",
"\n",
"select",
"{",
"case",
"transport",
".",
"bodyChannel",
"<-",
"p",
":",
"default",
":",
"// This can happen if the bodyChannel had an item added to it from another",
"// thread while we are processing such that the channel is now full. If we try",
"// to send the payload back to the channel without this select statement we",
"// could deadlock. Instead we consider this a retry failure.",
"if",
"transport",
".",
"PrintPayloadOnError",
"{",
"writePayloadToStderr",
"(",
"transport",
".",
"Logger",
",",
"p",
".",
"body",
")",
"\n",
"}",
"\n",
"transport",
".",
"waitGroup",
".",
"Done",
"(",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"transport",
".",
"PrintPayloadOnError",
"{",
"writePayloadToStderr",
"(",
"transport",
".",
"Logger",
",",
"p",
".",
"body",
")",
"\n",
"}",
"\n",
"transport",
".",
"waitGroup",
".",
"Done",
"(",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"transport",
".",
"waitGroup",
".",
"Done",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"transport",
"\n",
"}"
] |
// NewAsyncTransport builds an asynchronous transport which sends data to the Rollbar API at the
// specified endpoint using the given access token. The channel is limited to the size of the input
// buffer argument.
|
[
"NewAsyncTransport",
"builds",
"an",
"asynchronous",
"transport",
"which",
"sends",
"data",
"to",
"the",
"Rollbar",
"API",
"at",
"the",
"specified",
"endpoint",
"using",
"the",
"given",
"access",
"token",
".",
"The",
"channel",
"is",
"limited",
"to",
"the",
"size",
"of",
"the",
"input",
"buffer",
"argument",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/async_transport.go#L40-L80
|
13,822 |
rollbar/rollbar-go
|
async_transport.go
|
Send
|
func (t *AsyncTransport) Send(body map[string]interface{}) error {
if len(t.bodyChannel) < t.Buffer {
t.waitGroup.Add(1)
p := payload{
body: body,
retriesLeft: t.RetryAttempts,
}
t.bodyChannel <- p
} else {
err := ErrBufferFull{}
rollbarError(t.Logger, err.Error())
if t.PrintPayloadOnError {
writePayloadToStderr(t.Logger, body)
}
return err
}
return nil
}
|
go
|
func (t *AsyncTransport) Send(body map[string]interface{}) error {
if len(t.bodyChannel) < t.Buffer {
t.waitGroup.Add(1)
p := payload{
body: body,
retriesLeft: t.RetryAttempts,
}
t.bodyChannel <- p
} else {
err := ErrBufferFull{}
rollbarError(t.Logger, err.Error())
if t.PrintPayloadOnError {
writePayloadToStderr(t.Logger, body)
}
return err
}
return nil
}
|
[
"func",
"(",
"t",
"*",
"AsyncTransport",
")",
"Send",
"(",
"body",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"t",
".",
"bodyChannel",
")",
"<",
"t",
".",
"Buffer",
"{",
"t",
".",
"waitGroup",
".",
"Add",
"(",
"1",
")",
"\n",
"p",
":=",
"payload",
"{",
"body",
":",
"body",
",",
"retriesLeft",
":",
"t",
".",
"RetryAttempts",
",",
"}",
"\n",
"t",
".",
"bodyChannel",
"<-",
"p",
"\n",
"}",
"else",
"{",
"err",
":=",
"ErrBufferFull",
"{",
"}",
"\n",
"rollbarError",
"(",
"t",
".",
"Logger",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"if",
"t",
".",
"PrintPayloadOnError",
"{",
"writePayloadToStderr",
"(",
"t",
".",
"Logger",
",",
"body",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Send the body to Rollbar if the channel is not currently full.
// Returns ErrBufferFull if the underlying channel is full.
|
[
"Send",
"the",
"body",
"to",
"Rollbar",
"if",
"the",
"channel",
"is",
"not",
"currently",
"full",
".",
"Returns",
"ErrBufferFull",
"if",
"the",
"underlying",
"channel",
"is",
"full",
"."
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/async_transport.go#L84-L101
|
13,823 |
rollbar/rollbar-go
|
async_transport.go
|
Close
|
func (t *AsyncTransport) Close() error {
close(t.bodyChannel)
t.Wait()
return nil
}
|
go
|
func (t *AsyncTransport) Close() error {
close(t.bodyChannel)
t.Wait()
return nil
}
|
[
"func",
"(",
"t",
"*",
"AsyncTransport",
")",
"Close",
"(",
")",
"error",
"{",
"close",
"(",
"t",
".",
"bodyChannel",
")",
"\n",
"t",
".",
"Wait",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Close is an alias for Wait for the asynchronous transport
|
[
"Close",
"is",
"an",
"alias",
"for",
"Wait",
"for",
"the",
"asynchronous",
"transport"
] |
5729d3754c053614e806190ad972ddede06e741a
|
https://github.com/rollbar/rollbar-go/blob/5729d3754c053614e806190ad972ddede06e741a/async_transport.go#L109-L113
|
13,824 |
fishworks/gofish
|
pkg/rig/installer/vcs_installer.go
|
Install
|
func (i *VCSInstaller) Install() error {
repo, err := vcs.NewRepo(i.Source, i.Path())
if err != nil {
return err
}
if err := i.sync(repo); err != nil {
return err
}
ref, err := i.solveVersion(repo)
if err != nil {
return err
}
if ref != "" {
if err := i.setVersion(repo, ref); err != nil {
return err
}
}
if !isRig(repo.LocalPath()) {
return rig.ErrDoesNotExist
}
return nil
}
|
go
|
func (i *VCSInstaller) Install() error {
repo, err := vcs.NewRepo(i.Source, i.Path())
if err != nil {
return err
}
if err := i.sync(repo); err != nil {
return err
}
ref, err := i.solveVersion(repo)
if err != nil {
return err
}
if ref != "" {
if err := i.setVersion(repo, ref); err != nil {
return err
}
}
if !isRig(repo.LocalPath()) {
return rig.ErrDoesNotExist
}
return nil
}
|
[
"func",
"(",
"i",
"*",
"VCSInstaller",
")",
"Install",
"(",
")",
"error",
"{",
"repo",
",",
"err",
":=",
"vcs",
".",
"NewRepo",
"(",
"i",
".",
"Source",
",",
"i",
".",
"Path",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"i",
".",
"sync",
"(",
"repo",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ref",
",",
"err",
":=",
"i",
".",
"solveVersion",
"(",
"repo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"ref",
"!=",
"\"",
"\"",
"{",
"if",
"err",
":=",
"i",
".",
"setVersion",
"(",
"repo",
",",
"ref",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"isRig",
"(",
"repo",
".",
"LocalPath",
"(",
")",
")",
"{",
"return",
"rig",
".",
"ErrDoesNotExist",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Install clones a remote repository to the rig directory
//
// Implements Installer
|
[
"Install",
"clones",
"a",
"remote",
"repository",
"to",
"the",
"rig",
"directory",
"Implements",
"Installer"
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/vcs_installer.go#L47-L73
|
13,825 |
fishworks/gofish
|
pkg/rig/installer/vcs_installer.go
|
setVersion
|
func (i *VCSInstaller) setVersion(repo vcs.Repo, ref string) error {
return repo.UpdateVersion(ref)
}
|
go
|
func (i *VCSInstaller) setVersion(repo vcs.Repo, ref string) error {
return repo.UpdateVersion(ref)
}
|
[
"func",
"(",
"i",
"*",
"VCSInstaller",
")",
"setVersion",
"(",
"repo",
"vcs",
".",
"Repo",
",",
"ref",
"string",
")",
"error",
"{",
"return",
"repo",
".",
"UpdateVersion",
"(",
"ref",
")",
"\n",
"}"
] |
// setVersion attempts to checkout the version
|
[
"setVersion",
"attempts",
"to",
"checkout",
"the",
"version"
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/vcs_installer.go#L125-L127
|
13,826 |
fishworks/gofish
|
pkg/rig/installer/vcs_installer.go
|
sync
|
func (i *VCSInstaller) sync(repo vcs.Repo) error {
if _, err := os.Stat(repo.LocalPath()); os.IsNotExist(err) {
return repo.Get()
}
return repo.Update()
}
|
go
|
func (i *VCSInstaller) sync(repo vcs.Repo) error {
if _, err := os.Stat(repo.LocalPath()); os.IsNotExist(err) {
return repo.Get()
}
return repo.Update()
}
|
[
"func",
"(",
"i",
"*",
"VCSInstaller",
")",
"sync",
"(",
"repo",
"vcs",
".",
"Repo",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"repo",
".",
"LocalPath",
"(",
")",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"repo",
".",
"Get",
"(",
")",
"\n",
"}",
"\n",
"return",
"repo",
".",
"Update",
"(",
")",
"\n",
"}"
] |
// sync will clone or update a remote repo.
|
[
"sync",
"will",
"clone",
"or",
"update",
"a",
"remote",
"repo",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/vcs_installer.go#L168-L174
|
13,827 |
fishworks/gofish
|
version/version.go
|
String
|
func String() string {
ver := "dev"
if strings.Compare(Version, "") != 0 {
ver = fmt.Sprintf("%s", Version)
}
if strings.Compare(BuildMetadata, "") != 0 {
ver = fmt.Sprintf("%s+%s", ver, BuildMetadata)
}
return ver
}
|
go
|
func String() string {
ver := "dev"
if strings.Compare(Version, "") != 0 {
ver = fmt.Sprintf("%s", Version)
}
if strings.Compare(BuildMetadata, "") != 0 {
ver = fmt.Sprintf("%s+%s", ver, BuildMetadata)
}
return ver
}
|
[
"func",
"String",
"(",
")",
"string",
"{",
"ver",
":=",
"\"",
"\"",
"\n",
"if",
"strings",
".",
"Compare",
"(",
"Version",
",",
"\"",
"\"",
")",
"!=",
"0",
"{",
"ver",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"Version",
")",
"\n",
"}",
"\n",
"if",
"strings",
".",
"Compare",
"(",
"BuildMetadata",
",",
"\"",
"\"",
")",
"!=",
"0",
"{",
"ver",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ver",
",",
"BuildMetadata",
")",
"\n",
"}",
"\n",
"return",
"ver",
"\n",
"}"
] |
// String represents the version information as a well-formatted string.
|
[
"String",
"represents",
"the",
"version",
"information",
"as",
"a",
"well",
"-",
"formatted",
"string",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/version/version.go#L15-L24
|
13,828 |
fishworks/gofish
|
pkg/rig/installer/installer.go
|
Install
|
func Install(i Installer) error {
basePath := filepath.Dir(i.Path())
if _, pathErr := os.Stat(basePath); os.IsNotExist(pathErr) {
if err := os.MkdirAll(basePath, 0755); err != nil {
return err
}
}
if _, pathErr := os.Stat(i.Path()); !os.IsNotExist(pathErr) {
return i.Update()
}
return i.Install()
}
|
go
|
func Install(i Installer) error {
basePath := filepath.Dir(i.Path())
if _, pathErr := os.Stat(basePath); os.IsNotExist(pathErr) {
if err := os.MkdirAll(basePath, 0755); err != nil {
return err
}
}
if _, pathErr := os.Stat(i.Path()); !os.IsNotExist(pathErr) {
return i.Update()
}
return i.Install()
}
|
[
"func",
"Install",
"(",
"i",
"Installer",
")",
"error",
"{",
"basePath",
":=",
"filepath",
".",
"Dir",
"(",
"i",
".",
"Path",
"(",
")",
")",
"\n",
"if",
"_",
",",
"pathErr",
":=",
"os",
".",
"Stat",
"(",
"basePath",
")",
";",
"os",
".",
"IsNotExist",
"(",
"pathErr",
")",
"{",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"basePath",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"pathErr",
":=",
"os",
".",
"Stat",
"(",
"i",
".",
"Path",
"(",
")",
")",
";",
"!",
"os",
".",
"IsNotExist",
"(",
"pathErr",
")",
"{",
"return",
"i",
".",
"Update",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"i",
".",
"Install",
"(",
")",
"\n",
"}"
] |
// Install installs a rig.
|
[
"Install",
"installs",
"a",
"rig",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/installer.go#L22-L35
|
13,829 |
fishworks/gofish
|
pkg/rig/installer/installer.go
|
Update
|
func Update(i Installer) error {
if _, pathErr := os.Stat(i.Path()); os.IsNotExist(pathErr) {
return rig.ErrDoesNotExist
}
return i.Update()
}
|
go
|
func Update(i Installer) error {
if _, pathErr := os.Stat(i.Path()); os.IsNotExist(pathErr) {
return rig.ErrDoesNotExist
}
return i.Update()
}
|
[
"func",
"Update",
"(",
"i",
"Installer",
")",
"error",
"{",
"if",
"_",
",",
"pathErr",
":=",
"os",
".",
"Stat",
"(",
"i",
".",
"Path",
"(",
")",
")",
";",
"os",
".",
"IsNotExist",
"(",
"pathErr",
")",
"{",
"return",
"rig",
".",
"ErrDoesNotExist",
"\n",
"}",
"\n\n",
"return",
"i",
".",
"Update",
"(",
")",
"\n",
"}"
] |
// Update updates a rig.
|
[
"Update",
"updates",
"a",
"rig",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/installer.go#L38-L44
|
13,830 |
fishworks/gofish
|
pkg/rig/installer/installer.go
|
New
|
func New(source, name, version string, home home.Home) (Installer, error) {
if isLocalReference(source) {
return NewLocalInstaller(source, name, home)
}
return NewVCSInstaller(source, name, version, home)
}
|
go
|
func New(source, name, version string, home home.Home) (Installer, error) {
if isLocalReference(source) {
return NewLocalInstaller(source, name, home)
}
return NewVCSInstaller(source, name, version, home)
}
|
[
"func",
"New",
"(",
"source",
",",
"name",
",",
"version",
"string",
",",
"home",
"home",
".",
"Home",
")",
"(",
"Installer",
",",
"error",
")",
"{",
"if",
"isLocalReference",
"(",
"source",
")",
"{",
"return",
"NewLocalInstaller",
"(",
"source",
",",
"name",
",",
"home",
")",
"\n",
"}",
"\n\n",
"return",
"NewVCSInstaller",
"(",
"source",
",",
"name",
",",
"version",
",",
"home",
")",
"\n",
"}"
] |
// New determines and returns the correct Installer for the given source
|
[
"New",
"determines",
"and",
"returns",
"the",
"correct",
"Installer",
"for",
"the",
"given",
"source"
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/installer.go#L56-L62
|
13,831 |
fishworks/gofish
|
pkg/rig/installer/installer.go
|
isRig
|
func isRig(dirname string) bool {
_, err := os.Stat(filepath.Join(dirname, "Food"))
return err == nil
}
|
go
|
func isRig(dirname string) bool {
_, err := os.Stat(filepath.Join(dirname, "Food"))
return err == nil
}
|
[
"func",
"isRig",
"(",
"dirname",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filepath",
".",
"Join",
"(",
"dirname",
",",
"\"",
"\"",
")",
")",
"\n",
"return",
"err",
"==",
"nil",
"\n",
"}"
] |
// isRig checks if the directory contains a "Food" directory.
|
[
"isRig",
"checks",
"if",
"the",
"directory",
"contains",
"a",
"Food",
"directory",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/installer.go#L71-L74
|
13,832 |
fishworks/gofish
|
pkg/ohai/ohai.go
|
Ohaif
|
func Ohaif(format string, a ...interface{}) (int, error) {
return fmt.Printf(fmt.Sprintf("==> %s", format), a...)
}
|
go
|
func Ohaif(format string, a ...interface{}) (int, error) {
return fmt.Printf(fmt.Sprintf("==> %s", format), a...)
}
|
[
"func",
"Ohaif",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"fmt",
".",
"Printf",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"format",
")",
",",
"a",
"...",
")",
"\n",
"}"
] |
// Ohaif displays an informative message.
|
[
"Ohaif",
"displays",
"an",
"informative",
"message",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/ohai/ohai.go#L15-L17
|
13,833 |
fishworks/gofish
|
pkg/ohai/ohai.go
|
Warningf
|
func Warningf(format string, a ...interface{}) (int, error) {
return fmt.Printf(emoji.Sprintf("!!! %s", format), a...)
}
|
go
|
func Warningf(format string, a ...interface{}) (int, error) {
return fmt.Printf(emoji.Sprintf("!!! %s", format), a...)
}
|
[
"func",
"Warningf",
"(",
"format",
"string",
",",
"a",
"...",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"fmt",
".",
"Printf",
"(",
"emoji",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"format",
")",
",",
"a",
"...",
")",
"\n",
"}"
] |
// Warningf displays a warning message.
|
[
"Warningf",
"displays",
"a",
"warning",
"message",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/ohai/ohai.go#L45-L47
|
13,834 |
fishworks/gofish
|
receipt/install_receipt.go
|
NewFromReader
|
func NewFromReader(r io.Reader) (*InstallReceipt, error) {
var receipt InstallReceipt
err := json.NewDecoder(r).Decode(&receipt)
return &receipt, err
}
|
go
|
func NewFromReader(r io.Reader) (*InstallReceipt, error) {
var receipt InstallReceipt
err := json.NewDecoder(r).Decode(&receipt)
return &receipt, err
}
|
[
"func",
"NewFromReader",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"InstallReceipt",
",",
"error",
")",
"{",
"var",
"receipt",
"InstallReceipt",
"\n",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
")",
".",
"Decode",
"(",
"&",
"receipt",
")",
"\n",
"return",
"&",
"receipt",
",",
"err",
"\n",
"}"
] |
// NewFromReader reads in an install receipt from an io.Reader. Useful when reading from a file stream.
|
[
"NewFromReader",
"reads",
"in",
"an",
"install",
"receipt",
"from",
"an",
"io",
".",
"Reader",
".",
"Useful",
"when",
"reading",
"from",
"a",
"file",
"stream",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/receipt/install_receipt.go#L23-L27
|
13,835 |
fishworks/gofish
|
receipt/install_receipt.go
|
Save
|
func (i *InstallReceipt) Save(w io.Writer) error {
data, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err
}
_, err = w.Write(data)
w.Write([]byte("\n"))
return err
}
|
go
|
func (i *InstallReceipt) Save(w io.Writer) error {
data, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err
}
_, err = w.Write(data)
w.Write([]byte("\n"))
return err
}
|
[
"func",
"(",
"i",
"*",
"InstallReceipt",
")",
"Save",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"data",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"i",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"data",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\\n",
"\"",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Save writes the install receipt into the given io.Writer.
|
[
"Save",
"writes",
"the",
"install",
"receipt",
"into",
"the",
"given",
"io",
".",
"Writer",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/receipt/install_receipt.go#L30-L38
|
13,836 |
fishworks/gofish
|
cmd/gofish/ensure.go
|
ensureFood
|
func ensureFood() error {
ohai.Ohailn("Installing default fish food...")
addArgs := []string{
"https://github.com/fishworks/fish-food",
}
rigCmd, _, err := rootCmd.Find([]string{"rig", "add"})
if err != nil {
return err
}
return rigCmd.RunE(rigCmd, addArgs)
}
|
go
|
func ensureFood() error {
ohai.Ohailn("Installing default fish food...")
addArgs := []string{
"https://github.com/fishworks/fish-food",
}
rigCmd, _, err := rootCmd.Find([]string{"rig", "add"})
if err != nil {
return err
}
return rigCmd.RunE(rigCmd, addArgs)
}
|
[
"func",
"ensureFood",
"(",
")",
"error",
"{",
"ohai",
".",
"Ohailn",
"(",
"\"",
"\"",
")",
"\n\n",
"addArgs",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"}",
"\n\n",
"rigCmd",
",",
"_",
",",
"err",
":=",
"rootCmd",
".",
"Find",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"rigCmd",
".",
"RunE",
"(",
"rigCmd",
",",
"addArgs",
")",
"\n",
"}"
] |
// ensureFood checks to see if the default fish food exists.
//
// If the pack does not exist, this function will create it.
// If it does, it will update to the latest.
|
[
"ensureFood",
"checks",
"to",
"see",
"if",
"the",
"default",
"fish",
"food",
"exists",
".",
"If",
"the",
"pack",
"does",
"not",
"exist",
"this",
"function",
"will",
"create",
"it",
".",
"If",
"it",
"does",
"it",
"will",
"update",
"to",
"the",
"latest",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/cmd/gofish/ensure.go#L11-L23
|
13,837 |
fishworks/gofish
|
pkg/rig/installer/local_installer.go
|
NewLocalInstaller
|
func NewLocalInstaller(source string, name string, home home.Home) (*LocalInstaller, error) {
i := &LocalInstaller{
Source: source,
Home: home,
Name: name,
}
if i.Name == "" {
i.Name = filepath.Base(i.Source)
}
return i, nil
}
|
go
|
func NewLocalInstaller(source string, name string, home home.Home) (*LocalInstaller, error) {
i := &LocalInstaller{
Source: source,
Home: home,
Name: name,
}
if i.Name == "" {
i.Name = filepath.Base(i.Source)
}
return i, nil
}
|
[
"func",
"NewLocalInstaller",
"(",
"source",
"string",
",",
"name",
"string",
",",
"home",
"home",
".",
"Home",
")",
"(",
"*",
"LocalInstaller",
",",
"error",
")",
"{",
"i",
":=",
"&",
"LocalInstaller",
"{",
"Source",
":",
"source",
",",
"Home",
":",
"home",
",",
"Name",
":",
"name",
",",
"}",
"\n\n",
"if",
"i",
".",
"Name",
"==",
"\"",
"\"",
"{",
"i",
".",
"Name",
"=",
"filepath",
".",
"Base",
"(",
"i",
".",
"Source",
")",
"\n",
"}",
"\n\n",
"return",
"i",
",",
"nil",
"\n",
"}"
] |
// NewLocalInstaller creates a new LocalInstaller
|
[
"NewLocalInstaller",
"creates",
"a",
"new",
"LocalInstaller"
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/local_installer.go#L19-L31
|
13,838 |
fishworks/gofish
|
pkg/rig/installer/local_installer.go
|
Install
|
func (i *LocalInstaller) Install() error {
if !isRig(i.Source) {
return rig.ErrDoesNotExist
}
src, err := filepath.Abs(i.Source)
if err != nil {
return err
}
return i.link(src)
}
|
go
|
func (i *LocalInstaller) Install() error {
if !isRig(i.Source) {
return rig.ErrDoesNotExist
}
src, err := filepath.Abs(i.Source)
if err != nil {
return err
}
return i.link(src)
}
|
[
"func",
"(",
"i",
"*",
"LocalInstaller",
")",
"Install",
"(",
")",
"error",
"{",
"if",
"!",
"isRig",
"(",
"i",
".",
"Source",
")",
"{",
"return",
"rig",
".",
"ErrDoesNotExist",
"\n",
"}",
"\n\n",
"src",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"i",
".",
"Source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"i",
".",
"link",
"(",
"src",
")",
"\n",
"}"
] |
// Install creates a symlink to the rig directory
|
[
"Install",
"creates",
"a",
"symlink",
"to",
"the",
"rig",
"directory"
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/local_installer.go#L34-L45
|
13,839 |
fishworks/gofish
|
pkg/rig/installer/local_installer.go
|
link
|
func (i *LocalInstaller) link(from string) error {
origin, err := filepath.Abs(from)
if err != nil {
return err
}
dest, err := filepath.Abs(i.Path())
if err != nil {
return err
}
return os.Symlink(origin, dest)
}
|
go
|
func (i *LocalInstaller) link(from string) error {
origin, err := filepath.Abs(from)
if err != nil {
return err
}
dest, err := filepath.Abs(i.Path())
if err != nil {
return err
}
return os.Symlink(origin, dest)
}
|
[
"func",
"(",
"i",
"*",
"LocalInstaller",
")",
"link",
"(",
"from",
"string",
")",
"error",
"{",
"origin",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"from",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"dest",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"i",
".",
"Path",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"os",
".",
"Symlink",
"(",
"origin",
",",
"dest",
")",
"\n",
"}"
] |
// link creates a symlink from the rig source to the rig directory
|
[
"link",
"creates",
"a",
"symlink",
"from",
"the",
"rig",
"source",
"to",
"the",
"rig",
"directory"
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/pkg/rig/installer/local_installer.go#L61-L71
|
13,840 |
fishworks/gofish
|
food.go
|
Uninstall
|
func (f *Food) Uninstall() error {
pkg := f.GetPackage(runtime.GOOS, runtime.GOARCH)
if pkg == nil {
return nil
}
if f.Linked() {
if err := f.Unlink(pkg); err != nil {
return err
}
}
barrelDir := filepath.Join(home.Home(home.HomePath).Barrel(), f.Name, f.Version)
os.Remove(filepath.Join(home.Home(home.HomePath).Barrel(), f.Name, receipt.ReceiptFilename))
return os.RemoveAll(barrelDir)
}
|
go
|
func (f *Food) Uninstall() error {
pkg := f.GetPackage(runtime.GOOS, runtime.GOARCH)
if pkg == nil {
return nil
}
if f.Linked() {
if err := f.Unlink(pkg); err != nil {
return err
}
}
barrelDir := filepath.Join(home.Home(home.HomePath).Barrel(), f.Name, f.Version)
os.Remove(filepath.Join(home.Home(home.HomePath).Barrel(), f.Name, receipt.ReceiptFilename))
return os.RemoveAll(barrelDir)
}
|
[
"func",
"(",
"f",
"*",
"Food",
")",
"Uninstall",
"(",
")",
"error",
"{",
"pkg",
":=",
"f",
".",
"GetPackage",
"(",
"runtime",
".",
"GOOS",
",",
"runtime",
".",
"GOARCH",
")",
"\n",
"if",
"pkg",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"f",
".",
"Linked",
"(",
")",
"{",
"if",
"err",
":=",
"f",
".",
"Unlink",
"(",
"pkg",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"barrelDir",
":=",
"filepath",
".",
"Join",
"(",
"home",
".",
"Home",
"(",
"home",
".",
"HomePath",
")",
".",
"Barrel",
"(",
")",
",",
"f",
".",
"Name",
",",
"f",
".",
"Version",
")",
"\n",
"os",
".",
"Remove",
"(",
"filepath",
".",
"Join",
"(",
"home",
".",
"Home",
"(",
"home",
".",
"HomePath",
")",
".",
"Barrel",
"(",
")",
",",
"f",
".",
"Name",
",",
"receipt",
".",
"ReceiptFilename",
")",
")",
"\n",
"return",
"os",
".",
"RemoveAll",
"(",
"barrelDir",
")",
"\n",
"}"
] |
// Uninstall attempts to uninstall the package, returning errors if it fails.
|
[
"Uninstall",
"attempts",
"to",
"uninstall",
"the",
"package",
"returning",
"errors",
"if",
"it",
"fails",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/food.go#L145-L158
|
13,841 |
fishworks/gofish
|
food.go
|
Link
|
func (f *Food) Link(pkg *Package) error {
barrelDir := filepath.Join(home.Home(home.HomePath).Barrel(), f.Name, f.Version)
for _, r := range pkg.Resources {
// TODO: run this in parallel
destPath := filepath.Join(home.HomePrefix, r.InstallPath)
if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil && !os.IsExist(err) {
return err
}
if r.Executable {
if err := os.Chmod(filepath.Join(barrelDir, r.Path), 0755); err != nil {
return err
}
}
if err := os.Symlink(filepath.Join(barrelDir, r.Path), destPath); err != nil {
return err
}
}
return nil
}
|
go
|
func (f *Food) Link(pkg *Package) error {
barrelDir := filepath.Join(home.Home(home.HomePath).Barrel(), f.Name, f.Version)
for _, r := range pkg.Resources {
// TODO: run this in parallel
destPath := filepath.Join(home.HomePrefix, r.InstallPath)
if err := os.MkdirAll(filepath.Dir(destPath), 0755); err != nil && !os.IsExist(err) {
return err
}
if r.Executable {
if err := os.Chmod(filepath.Join(barrelDir, r.Path), 0755); err != nil {
return err
}
}
if err := os.Symlink(filepath.Join(barrelDir, r.Path), destPath); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Food",
")",
"Link",
"(",
"pkg",
"*",
"Package",
")",
"error",
"{",
"barrelDir",
":=",
"filepath",
".",
"Join",
"(",
"home",
".",
"Home",
"(",
"home",
".",
"HomePath",
")",
".",
"Barrel",
"(",
")",
",",
"f",
".",
"Name",
",",
"f",
".",
"Version",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"pkg",
".",
"Resources",
"{",
"// TODO: run this in parallel",
"destPath",
":=",
"filepath",
".",
"Join",
"(",
"home",
".",
"HomePrefix",
",",
"r",
".",
"InstallPath",
")",
"\n",
"if",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"filepath",
".",
"Dir",
"(",
"destPath",
")",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"&&",
"!",
"os",
".",
"IsExist",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"r",
".",
"Executable",
"{",
"if",
"err",
":=",
"os",
".",
"Chmod",
"(",
"filepath",
".",
"Join",
"(",
"barrelDir",
",",
"r",
".",
"Path",
")",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"os",
".",
"Symlink",
"(",
"filepath",
".",
"Join",
"(",
"barrelDir",
",",
"r",
".",
"Path",
")",
",",
"destPath",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Link creates links to any linked resources owned by the package.
|
[
"Link",
"creates",
"links",
"to",
"any",
"linked",
"resources",
"owned",
"by",
"the",
"package",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/food.go#L205-L223
|
13,842 |
fishworks/gofish
|
food.go
|
Unlink
|
func (f *Food) Unlink(pkg *Package) error {
for _, r := range pkg.Resources {
// TODO: check if the linked path we are about to remove is really owned by us
if err := os.RemoveAll(filepath.Join(home.HomePrefix, r.InstallPath)); err != nil {
return err
}
}
return nil
}
|
go
|
func (f *Food) Unlink(pkg *Package) error {
for _, r := range pkg.Resources {
// TODO: check if the linked path we are about to remove is really owned by us
if err := os.RemoveAll(filepath.Join(home.HomePrefix, r.InstallPath)); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Food",
")",
"Unlink",
"(",
"pkg",
"*",
"Package",
")",
"error",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"pkg",
".",
"Resources",
"{",
"// TODO: check if the linked path we are about to remove is really owned by us",
"if",
"err",
":=",
"os",
".",
"RemoveAll",
"(",
"filepath",
".",
"Join",
"(",
"home",
".",
"HomePrefix",
",",
"r",
".",
"InstallPath",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Unlink removes any linked resources owned by the package.
|
[
"Unlink",
"removes",
"any",
"linked",
"resources",
"owned",
"by",
"the",
"package",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/food.go#L226-L234
|
13,843 |
fishworks/gofish
|
food.go
|
Lint
|
func (f *Food) Lint() (errs []error) {
var wg sync.WaitGroup
for _, pkg := range f.Packages {
wg.Add(1)
go func(pkg *Package) {
defer wg.Done()
u, err := url.Parse(pkg.URL)
if err != nil {
errs = append(errs, fmt.Errorf("could not parse package URL '%s' as a URL: %v", pkg.URL, err))
}
cachedFilePath := filepath.Join(home.UserHome(home.UserHomePath).Cache(), fmt.Sprintf("%s-%s-%s-%s%s", f.Name, f.Version, pkg.OS, pkg.Arch, filepath.Ext(u.Path)))
if err := f.DownloadTo(pkg, cachedFilePath); err != nil {
errs = append(errs, err)
}
if err := checksumVerifyPath(cachedFilePath, pkg.SHA256); err != nil {
errs = append(errs, fmt.Errorf("shasum verify check failed: %v", err))
}
}(pkg)
}
wg.Wait()
return
}
|
go
|
func (f *Food) Lint() (errs []error) {
var wg sync.WaitGroup
for _, pkg := range f.Packages {
wg.Add(1)
go func(pkg *Package) {
defer wg.Done()
u, err := url.Parse(pkg.URL)
if err != nil {
errs = append(errs, fmt.Errorf("could not parse package URL '%s' as a URL: %v", pkg.URL, err))
}
cachedFilePath := filepath.Join(home.UserHome(home.UserHomePath).Cache(), fmt.Sprintf("%s-%s-%s-%s%s", f.Name, f.Version, pkg.OS, pkg.Arch, filepath.Ext(u.Path)))
if err := f.DownloadTo(pkg, cachedFilePath); err != nil {
errs = append(errs, err)
}
if err := checksumVerifyPath(cachedFilePath, pkg.SHA256); err != nil {
errs = append(errs, fmt.Errorf("shasum verify check failed: %v", err))
}
}(pkg)
}
wg.Wait()
return
}
|
[
"func",
"(",
"f",
"*",
"Food",
")",
"Lint",
"(",
")",
"(",
"errs",
"[",
"]",
"error",
")",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"for",
"_",
",",
"pkg",
":=",
"range",
"f",
".",
"Packages",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"pkg",
"*",
"Package",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"pkg",
".",
"URL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pkg",
".",
"URL",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"cachedFilePath",
":=",
"filepath",
".",
"Join",
"(",
"home",
".",
"UserHome",
"(",
"home",
".",
"UserHomePath",
")",
".",
"Cache",
"(",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
".",
"Name",
",",
"f",
".",
"Version",
",",
"pkg",
".",
"OS",
",",
"pkg",
".",
"Arch",
",",
"filepath",
".",
"Ext",
"(",
"u",
".",
"Path",
")",
")",
")",
"\n",
"if",
"err",
":=",
"f",
".",
"DownloadTo",
"(",
"pkg",
",",
"cachedFilePath",
")",
";",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"checksumVerifyPath",
"(",
"cachedFilePath",
",",
"pkg",
".",
"SHA256",
")",
";",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"}",
"(",
"pkg",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// Lint analyses a given fish food for potential errors, returning a list of errors.
|
[
"Lint",
"analyses",
"a",
"given",
"fish",
"food",
"for",
"potential",
"errors",
"returning",
"a",
"list",
"of",
"errors",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/food.go#L237-L258
|
13,844 |
fishworks/gofish
|
food.go
|
DownloadTo
|
func (f *Food) DownloadTo(pkg *Package, filePath string) error {
var success = true
if err := downloadCachedFileToPath(filePath, pkg.URL); err != nil {
success = false
log.Errorln(err)
// try using the mirrors
for i := range pkg.Mirrors {
if err := downloadCachedFileToPath(filePath, pkg.Mirrors[i]); err == nil {
success = true
break
} else {
log.Errorln(err)
}
}
}
if !success {
return fmt.Errorf("failed to download package for OS/arch %s/%s with URL %s to filepath %s", pkg.OS, pkg.Arch, pkg.URL, filePath)
}
return nil
}
|
go
|
func (f *Food) DownloadTo(pkg *Package, filePath string) error {
var success = true
if err := downloadCachedFileToPath(filePath, pkg.URL); err != nil {
success = false
log.Errorln(err)
// try using the mirrors
for i := range pkg.Mirrors {
if err := downloadCachedFileToPath(filePath, pkg.Mirrors[i]); err == nil {
success = true
break
} else {
log.Errorln(err)
}
}
}
if !success {
return fmt.Errorf("failed to download package for OS/arch %s/%s with URL %s to filepath %s", pkg.OS, pkg.Arch, pkg.URL, filePath)
}
return nil
}
|
[
"func",
"(",
"f",
"*",
"Food",
")",
"DownloadTo",
"(",
"pkg",
"*",
"Package",
",",
"filePath",
"string",
")",
"error",
"{",
"var",
"success",
"=",
"true",
"\n",
"if",
"err",
":=",
"downloadCachedFileToPath",
"(",
"filePath",
",",
"pkg",
".",
"URL",
")",
";",
"err",
"!=",
"nil",
"{",
"success",
"=",
"false",
"\n",
"log",
".",
"Errorln",
"(",
"err",
")",
"\n",
"// try using the mirrors",
"for",
"i",
":=",
"range",
"pkg",
".",
"Mirrors",
"{",
"if",
"err",
":=",
"downloadCachedFileToPath",
"(",
"filePath",
",",
"pkg",
".",
"Mirrors",
"[",
"i",
"]",
")",
";",
"err",
"==",
"nil",
"{",
"success",
"=",
"true",
"\n",
"break",
"\n",
"}",
"else",
"{",
"log",
".",
"Errorln",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"success",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"pkg",
".",
"OS",
",",
"pkg",
".",
"Arch",
",",
"pkg",
".",
"URL",
",",
"filePath",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// DownloadTo downloads a particular package to filePath, returning any errors if encountered.
|
[
"DownloadTo",
"downloads",
"a",
"particular",
"package",
"to",
"filePath",
"returning",
"any",
"errors",
"if",
"encountered",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/food.go#L261-L280
|
13,845 |
fishworks/gofish
|
food.go
|
downloadCachedFileToPath
|
func downloadCachedFileToPath(filePath string, url string) error {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
if _, err = os.Stat(filePath); err == nil {
return nil
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
out, err := os.Create(filePath)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
return err
}
|
go
|
func downloadCachedFileToPath(filePath string, url string) error {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}
if _, err = os.Stat(filePath); err == nil {
return nil
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
out, err := os.Create(filePath)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
return err
}
|
[
"func",
"downloadCachedFileToPath",
"(",
"filePath",
"string",
",",
"url",
"string",
")",
"error",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodGet",
",",
"url",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
"=",
"os",
".",
"Stat",
"(",
"filePath",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"http",
".",
"DefaultClient",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"out",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"out",
".",
"Close",
"(",
")",
"\n\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"out",
",",
"resp",
".",
"Body",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// downloadCachedFileToPath will download a file from the given url to a directory, returning the
// path to the cached file. If it already exists, it'll skip downloading the file and just return
// the path to the cached file.
|
[
"downloadCachedFileToPath",
"will",
"download",
"a",
"file",
"from",
"the",
"given",
"url",
"to",
"a",
"directory",
"returning",
"the",
"path",
"to",
"the",
"cached",
"file",
".",
"If",
"it",
"already",
"exists",
"it",
"ll",
"skip",
"downloading",
"the",
"file",
"and",
"just",
"return",
"the",
"path",
"to",
"the",
"cached",
"file",
"."
] |
91c7d15a7990d7abbe72fbebbee6de74970bc59d
|
https://github.com/fishworks/gofish/blob/91c7d15a7990d7abbe72fbebbee6de74970bc59d/food.go#L285-L309
|
13,846 |
jmoiron/jsonq
|
jsonq.go
|
Bool
|
func (j *JsonQuery) Bool(s ...string) (bool, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return false, err
}
return boolFromInterface(val)
}
|
go
|
func (j *JsonQuery) Bool(s ...string) (bool, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return false, err
}
return boolFromInterface(val)
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"Bool",
"(",
"s",
"...",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"val",
",",
"err",
":=",
"rquery",
"(",
"j",
".",
"blob",
",",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"return",
"boolFromInterface",
"(",
"val",
")",
"\n",
"}"
] |
// Bool extracts a bool the JsonQuery
|
[
"Bool",
"extracts",
"a",
"bool",
"the",
"JsonQuery"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L90-L96
|
13,847 |
jmoiron/jsonq
|
jsonq.go
|
Float
|
func (j *JsonQuery) Float(s ...string) (float64, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return 0.0, err
}
return floatFromInterface(val)
}
|
go
|
func (j *JsonQuery) Float(s ...string) (float64, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return 0.0, err
}
return floatFromInterface(val)
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"Float",
"(",
"s",
"...",
"string",
")",
"(",
"float64",
",",
"error",
")",
"{",
"val",
",",
"err",
":=",
"rquery",
"(",
"j",
".",
"blob",
",",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0.0",
",",
"err",
"\n",
"}",
"\n",
"return",
"floatFromInterface",
"(",
"val",
")",
"\n",
"}"
] |
// Float extracts a float from the JsonQuery
|
[
"Float",
"extracts",
"a",
"float",
"from",
"the",
"JsonQuery"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L99-L105
|
13,848 |
jmoiron/jsonq
|
jsonq.go
|
Int
|
func (j *JsonQuery) Int(s ...string) (int, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return 0, err
}
return intFromInterface(val)
}
|
go
|
func (j *JsonQuery) Int(s ...string) (int, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return 0, err
}
return intFromInterface(val)
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"Int",
"(",
"s",
"...",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"val",
",",
"err",
":=",
"rquery",
"(",
"j",
".",
"blob",
",",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"intFromInterface",
"(",
"val",
")",
"\n",
"}"
] |
// Int extracts an int from the JsonQuery
|
[
"Int",
"extracts",
"an",
"int",
"from",
"the",
"JsonQuery"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L108-L114
|
13,849 |
jmoiron/jsonq
|
jsonq.go
|
String
|
func (j *JsonQuery) String(s ...string) (string, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return "", err
}
return stringFromInterface(val)
}
|
go
|
func (j *JsonQuery) String(s ...string) (string, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return "", err
}
return stringFromInterface(val)
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"String",
"(",
"s",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"val",
",",
"err",
":=",
"rquery",
"(",
"j",
".",
"blob",
",",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"stringFromInterface",
"(",
"val",
")",
"\n",
"}"
] |
// String extracts a string from the JsonQuery
|
[
"String",
"extracts",
"a",
"string",
"from",
"the",
"JsonQuery"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L117-L123
|
13,850 |
jmoiron/jsonq
|
jsonq.go
|
Object
|
func (j *JsonQuery) Object(s ...string) (map[string]interface{}, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return map[string]interface{}{}, err
}
return objectFromInterface(val)
}
|
go
|
func (j *JsonQuery) Object(s ...string) (map[string]interface{}, error) {
val, err := rquery(j.blob, s...)
if err != nil {
return map[string]interface{}{}, err
}
return objectFromInterface(val)
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"Object",
"(",
"s",
"...",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"val",
",",
"err",
":=",
"rquery",
"(",
"j",
".",
"blob",
",",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"objectFromInterface",
"(",
"val",
")",
"\n",
"}"
] |
// Object extracts a json object from the JsonQuery
|
[
"Object",
"extracts",
"a",
"json",
"object",
"from",
"the",
"JsonQuery"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L126-L132
|
13,851 |
jmoiron/jsonq
|
jsonq.go
|
ArrayOfStrings
|
func (j *JsonQuery) ArrayOfStrings(s ...string) ([]string, error) {
array, err := j.Array(s...)
if err != nil {
return []string{}, err
}
toReturn := make([]string, len(array))
for index, val := range array {
toReturn[index], err = stringFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
go
|
func (j *JsonQuery) ArrayOfStrings(s ...string) ([]string, error) {
array, err := j.Array(s...)
if err != nil {
return []string{}, err
}
toReturn := make([]string, len(array))
for index, val := range array {
toReturn[index], err = stringFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"ArrayOfStrings",
"(",
"s",
"...",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"array",
",",
"err",
":=",
"j",
".",
"Array",
"(",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"toReturn",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"array",
")",
")",
"\n",
"for",
"index",
",",
"val",
":=",
"range",
"array",
"{",
"toReturn",
"[",
"index",
"]",
",",
"err",
"=",
"stringFromInterface",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"toReturn",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"toReturn",
",",
"nil",
"\n",
"}"
] |
// ArrayOfStrings extracts an array of strings from some json
|
[
"ArrayOfStrings",
"extracts",
"an",
"array",
"of",
"strings",
"from",
"some",
"json"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L153-L166
|
13,852 |
jmoiron/jsonq
|
jsonq.go
|
ArrayOfInts
|
func (j *JsonQuery) ArrayOfInts(s ...string) ([]int, error) {
array, err := j.Array(s...)
if err != nil {
return []int{}, err
}
toReturn := make([]int, len(array))
for index, val := range array {
toReturn[index], err = intFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
go
|
func (j *JsonQuery) ArrayOfInts(s ...string) ([]int, error) {
array, err := j.Array(s...)
if err != nil {
return []int{}, err
}
toReturn := make([]int, len(array))
for index, val := range array {
toReturn[index], err = intFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"ArrayOfInts",
"(",
"s",
"...",
"string",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"array",
",",
"err",
":=",
"j",
".",
"Array",
"(",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"int",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"toReturn",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"len",
"(",
"array",
")",
")",
"\n",
"for",
"index",
",",
"val",
":=",
"range",
"array",
"{",
"toReturn",
"[",
"index",
"]",
",",
"err",
"=",
"intFromInterface",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"toReturn",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"toReturn",
",",
"nil",
"\n",
"}"
] |
// ArrayOfInts extracts an array of ints from some json
|
[
"ArrayOfInts",
"extracts",
"an",
"array",
"of",
"ints",
"from",
"some",
"json"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L169-L182
|
13,853 |
jmoiron/jsonq
|
jsonq.go
|
ArrayOfFloats
|
func (j *JsonQuery) ArrayOfFloats(s ...string) ([]float64, error) {
array, err := j.Array(s...)
if err != nil {
return []float64{}, err
}
toReturn := make([]float64, len(array))
for index, val := range array {
toReturn[index], err = floatFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
go
|
func (j *JsonQuery) ArrayOfFloats(s ...string) ([]float64, error) {
array, err := j.Array(s...)
if err != nil {
return []float64{}, err
}
toReturn := make([]float64, len(array))
for index, val := range array {
toReturn[index], err = floatFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"ArrayOfFloats",
"(",
"s",
"...",
"string",
")",
"(",
"[",
"]",
"float64",
",",
"error",
")",
"{",
"array",
",",
"err",
":=",
"j",
".",
"Array",
"(",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"float64",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"toReturn",
":=",
"make",
"(",
"[",
"]",
"float64",
",",
"len",
"(",
"array",
")",
")",
"\n",
"for",
"index",
",",
"val",
":=",
"range",
"array",
"{",
"toReturn",
"[",
"index",
"]",
",",
"err",
"=",
"floatFromInterface",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"toReturn",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"toReturn",
",",
"nil",
"\n",
"}"
] |
// ArrayOfFloats extracts an array of float64s from some json
|
[
"ArrayOfFloats",
"extracts",
"an",
"array",
"of",
"float64s",
"from",
"some",
"json"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L185-L198
|
13,854 |
jmoiron/jsonq
|
jsonq.go
|
ArrayOfBools
|
func (j *JsonQuery) ArrayOfBools(s ...string) ([]bool, error) {
array, err := j.Array(s...)
if err != nil {
return []bool{}, err
}
toReturn := make([]bool, len(array))
for index, val := range array {
toReturn[index], err = boolFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
go
|
func (j *JsonQuery) ArrayOfBools(s ...string) ([]bool, error) {
array, err := j.Array(s...)
if err != nil {
return []bool{}, err
}
toReturn := make([]bool, len(array))
for index, val := range array {
toReturn[index], err = boolFromInterface(val)
if err != nil {
return toReturn, err
}
}
return toReturn, nil
}
|
[
"func",
"(",
"j",
"*",
"JsonQuery",
")",
"ArrayOfBools",
"(",
"s",
"...",
"string",
")",
"(",
"[",
"]",
"bool",
",",
"error",
")",
"{",
"array",
",",
"err",
":=",
"j",
".",
"Array",
"(",
"s",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"bool",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"toReturn",
":=",
"make",
"(",
"[",
"]",
"bool",
",",
"len",
"(",
"array",
")",
")",
"\n",
"for",
"index",
",",
"val",
":=",
"range",
"array",
"{",
"toReturn",
"[",
"index",
"]",
",",
"err",
"=",
"boolFromInterface",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"toReturn",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"toReturn",
",",
"nil",
"\n",
"}"
] |
// ArrayOfBools extracts an array of bools from some json
|
[
"ArrayOfBools",
"extracts",
"an",
"array",
"of",
"bools",
"from",
"some",
"json"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L201-L214
|
13,855 |
jmoiron/jsonq
|
jsonq.go
|
rquery
|
func rquery(blob interface{}, s ...string) (interface{}, error) {
var (
val interface{}
err error
)
val = blob
for _, q := range s {
val, err = query(val, q)
if err != nil {
return nil, err
}
}
switch val.(type) {
case nil:
return nil, fmt.Errorf("Nil value found at %s\n", s[len(s)-1])
}
return val, nil
}
|
go
|
func rquery(blob interface{}, s ...string) (interface{}, error) {
var (
val interface{}
err error
)
val = blob
for _, q := range s {
val, err = query(val, q)
if err != nil {
return nil, err
}
}
switch val.(type) {
case nil:
return nil, fmt.Errorf("Nil value found at %s\n", s[len(s)-1])
}
return val, nil
}
|
[
"func",
"rquery",
"(",
"blob",
"interface",
"{",
"}",
",",
"s",
"...",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"(",
"val",
"interface",
"{",
"}",
"\n",
"err",
"error",
"\n",
")",
"\n",
"val",
"=",
"blob",
"\n",
"for",
"_",
",",
"q",
":=",
"range",
"s",
"{",
"val",
",",
"err",
"=",
"query",
"(",
"val",
",",
"q",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"switch",
"val",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"s",
"[",
"len",
"(",
"s",
")",
"-",
"1",
"]",
")",
"\n",
"}",
"\n",
"return",
"val",
",",
"nil",
"\n",
"}"
] |
// Recursively query a decoded json blob
|
[
"Recursively",
"query",
"a",
"decoded",
"json",
"blob"
] |
e874b168d07ecc7808bc950a17998a8aa3141d82
|
https://github.com/jmoiron/jsonq/blob/e874b168d07ecc7808bc950a17998a8aa3141d82/jsonq.go#L254-L271
|
13,856 |
uber-go/atomic
|
error.go
|
NewError
|
func NewError(err error) *Error {
e := &Error{}
if err != nil {
e.Store(err)
}
return e
}
|
go
|
func NewError(err error) *Error {
e := &Error{}
if err != nil {
e.Store(err)
}
return e
}
|
[
"func",
"NewError",
"(",
"err",
"error",
")",
"*",
"Error",
"{",
"e",
":=",
"&",
"Error",
"{",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"e",
".",
"Store",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"e",
"\n",
"}"
] |
// NewError creates new atomic error object
|
[
"NewError",
"creates",
"new",
"atomic",
"error",
"object"
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/error.go#L32-L38
|
13,857 |
uber-go/atomic
|
error.go
|
Load
|
func (e *Error) Load() error {
v := e.v.Load()
if v == nil {
return nil
}
eh := v.(errorHolder)
return eh.err
}
|
go
|
func (e *Error) Load() error {
v := e.v.Load()
if v == nil {
return nil
}
eh := v.(errorHolder)
return eh.err
}
|
[
"func",
"(",
"e",
"*",
"Error",
")",
"Load",
"(",
")",
"error",
"{",
"v",
":=",
"e",
".",
"v",
".",
"Load",
"(",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"eh",
":=",
"v",
".",
"(",
"errorHolder",
")",
"\n",
"return",
"eh",
".",
"err",
"\n",
"}"
] |
// Load atomically loads the wrapped error
|
[
"Load",
"atomically",
"loads",
"the",
"wrapped",
"error"
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/error.go#L41-L49
|
13,858 |
uber-go/atomic
|
string.go
|
NewString
|
func NewString(str string) *String {
s := &String{}
if str != "" {
s.Store(str)
}
return s
}
|
go
|
func NewString(str string) *String {
s := &String{}
if str != "" {
s.Store(str)
}
return s
}
|
[
"func",
"NewString",
"(",
"str",
"string",
")",
"*",
"String",
"{",
"s",
":=",
"&",
"String",
"{",
"}",
"\n",
"if",
"str",
"!=",
"\"",
"\"",
"{",
"s",
".",
"Store",
"(",
"str",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// NewString creates a String.
|
[
"NewString",
"creates",
"a",
"String",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/string.go#L27-L33
|
13,859 |
uber-go/atomic
|
string.go
|
Load
|
func (s *String) Load() string {
v := s.v.Load()
if v == nil {
return ""
}
return v.(string)
}
|
go
|
func (s *String) Load() string {
v := s.v.Load()
if v == nil {
return ""
}
return v.(string)
}
|
[
"func",
"(",
"s",
"*",
"String",
")",
"Load",
"(",
")",
"string",
"{",
"v",
":=",
"s",
".",
"v",
".",
"Load",
"(",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"v",
".",
"(",
"string",
")",
"\n",
"}"
] |
// Load atomically loads the wrapped string.
|
[
"Load",
"atomically",
"loads",
"the",
"wrapped",
"string",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/string.go#L36-L42
|
13,860 |
uber-go/atomic
|
atomic.go
|
Add
|
func (i *Int32) Add(n int32) int32 {
return atomic.AddInt32(&i.v, n)
}
|
go
|
func (i *Int32) Add(n int32) int32 {
return atomic.AddInt32(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Int32",
")",
"Add",
"(",
"n",
"int32",
")",
"int32",
"{",
"return",
"atomic",
".",
"AddInt32",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Add atomically adds to the wrapped int32 and returns the new value.
|
[
"Add",
"atomically",
"adds",
"to",
"the",
"wrapped",
"int32",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L45-L47
|
13,861 |
uber-go/atomic
|
atomic.go
|
Sub
|
func (i *Int32) Sub(n int32) int32 {
return atomic.AddInt32(&i.v, -n)
}
|
go
|
func (i *Int32) Sub(n int32) int32 {
return atomic.AddInt32(&i.v, -n)
}
|
[
"func",
"(",
"i",
"*",
"Int32",
")",
"Sub",
"(",
"n",
"int32",
")",
"int32",
"{",
"return",
"atomic",
".",
"AddInt32",
"(",
"&",
"i",
".",
"v",
",",
"-",
"n",
")",
"\n",
"}"
] |
// Sub atomically subtracts from the wrapped int32 and returns the new value.
|
[
"Sub",
"atomically",
"subtracts",
"from",
"the",
"wrapped",
"int32",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L50-L52
|
13,862 |
uber-go/atomic
|
atomic.go
|
Swap
|
func (i *Int32) Swap(n int32) int32 {
return atomic.SwapInt32(&i.v, n)
}
|
go
|
func (i *Int32) Swap(n int32) int32 {
return atomic.SwapInt32(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Int32",
")",
"Swap",
"(",
"n",
"int32",
")",
"int32",
"{",
"return",
"atomic",
".",
"SwapInt32",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Swap atomically swaps the wrapped int32 and returns the old value.
|
[
"Swap",
"atomically",
"swaps",
"the",
"wrapped",
"int32",
"and",
"returns",
"the",
"old",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L75-L77
|
13,863 |
uber-go/atomic
|
atomic.go
|
Add
|
func (i *Int64) Add(n int64) int64 {
return atomic.AddInt64(&i.v, n)
}
|
go
|
func (i *Int64) Add(n int64) int64 {
return atomic.AddInt64(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Int64",
")",
"Add",
"(",
"n",
"int64",
")",
"int64",
"{",
"return",
"atomic",
".",
"AddInt64",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Add atomically adds to the wrapped int64 and returns the new value.
|
[
"Add",
"atomically",
"adds",
"to",
"the",
"wrapped",
"int64",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L93-L95
|
13,864 |
uber-go/atomic
|
atomic.go
|
Sub
|
func (i *Int64) Sub(n int64) int64 {
return atomic.AddInt64(&i.v, -n)
}
|
go
|
func (i *Int64) Sub(n int64) int64 {
return atomic.AddInt64(&i.v, -n)
}
|
[
"func",
"(",
"i",
"*",
"Int64",
")",
"Sub",
"(",
"n",
"int64",
")",
"int64",
"{",
"return",
"atomic",
".",
"AddInt64",
"(",
"&",
"i",
".",
"v",
",",
"-",
"n",
")",
"\n",
"}"
] |
// Sub atomically subtracts from the wrapped int64 and returns the new value.
|
[
"Sub",
"atomically",
"subtracts",
"from",
"the",
"wrapped",
"int64",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L98-L100
|
13,865 |
uber-go/atomic
|
atomic.go
|
Swap
|
func (i *Int64) Swap(n int64) int64 {
return atomic.SwapInt64(&i.v, n)
}
|
go
|
func (i *Int64) Swap(n int64) int64 {
return atomic.SwapInt64(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Int64",
")",
"Swap",
"(",
"n",
"int64",
")",
"int64",
"{",
"return",
"atomic",
".",
"SwapInt64",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Swap atomically swaps the wrapped int64 and returns the old value.
|
[
"Swap",
"atomically",
"swaps",
"the",
"wrapped",
"int64",
"and",
"returns",
"the",
"old",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L123-L125
|
13,866 |
uber-go/atomic
|
atomic.go
|
Add
|
func (i *Uint32) Add(n uint32) uint32 {
return atomic.AddUint32(&i.v, n)
}
|
go
|
func (i *Uint32) Add(n uint32) uint32 {
return atomic.AddUint32(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Uint32",
")",
"Add",
"(",
"n",
"uint32",
")",
"uint32",
"{",
"return",
"atomic",
".",
"AddUint32",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Add atomically adds to the wrapped uint32 and returns the new value.
|
[
"Add",
"atomically",
"adds",
"to",
"the",
"wrapped",
"uint32",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L141-L143
|
13,867 |
uber-go/atomic
|
atomic.go
|
Sub
|
func (i *Uint32) Sub(n uint32) uint32 {
return atomic.AddUint32(&i.v, ^(n - 1))
}
|
go
|
func (i *Uint32) Sub(n uint32) uint32 {
return atomic.AddUint32(&i.v, ^(n - 1))
}
|
[
"func",
"(",
"i",
"*",
"Uint32",
")",
"Sub",
"(",
"n",
"uint32",
")",
"uint32",
"{",
"return",
"atomic",
".",
"AddUint32",
"(",
"&",
"i",
".",
"v",
",",
"^",
"(",
"n",
"-",
"1",
")",
")",
"\n",
"}"
] |
// Sub atomically subtracts from the wrapped uint32 and returns the new value.
|
[
"Sub",
"atomically",
"subtracts",
"from",
"the",
"wrapped",
"uint32",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L146-L148
|
13,868 |
uber-go/atomic
|
atomic.go
|
Swap
|
func (i *Uint32) Swap(n uint32) uint32 {
return atomic.SwapUint32(&i.v, n)
}
|
go
|
func (i *Uint32) Swap(n uint32) uint32 {
return atomic.SwapUint32(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Uint32",
")",
"Swap",
"(",
"n",
"uint32",
")",
"uint32",
"{",
"return",
"atomic",
".",
"SwapUint32",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Swap atomically swaps the wrapped uint32 and returns the old value.
|
[
"Swap",
"atomically",
"swaps",
"the",
"wrapped",
"uint32",
"and",
"returns",
"the",
"old",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L171-L173
|
13,869 |
uber-go/atomic
|
atomic.go
|
Add
|
func (i *Uint64) Add(n uint64) uint64 {
return atomic.AddUint64(&i.v, n)
}
|
go
|
func (i *Uint64) Add(n uint64) uint64 {
return atomic.AddUint64(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Uint64",
")",
"Add",
"(",
"n",
"uint64",
")",
"uint64",
"{",
"return",
"atomic",
".",
"AddUint64",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Add atomically adds to the wrapped uint64 and returns the new value.
|
[
"Add",
"atomically",
"adds",
"to",
"the",
"wrapped",
"uint64",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L189-L191
|
13,870 |
uber-go/atomic
|
atomic.go
|
Sub
|
func (i *Uint64) Sub(n uint64) uint64 {
return atomic.AddUint64(&i.v, ^(n - 1))
}
|
go
|
func (i *Uint64) Sub(n uint64) uint64 {
return atomic.AddUint64(&i.v, ^(n - 1))
}
|
[
"func",
"(",
"i",
"*",
"Uint64",
")",
"Sub",
"(",
"n",
"uint64",
")",
"uint64",
"{",
"return",
"atomic",
".",
"AddUint64",
"(",
"&",
"i",
".",
"v",
",",
"^",
"(",
"n",
"-",
"1",
")",
")",
"\n",
"}"
] |
// Sub atomically subtracts from the wrapped uint64 and returns the new value.
|
[
"Sub",
"atomically",
"subtracts",
"from",
"the",
"wrapped",
"uint64",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L194-L196
|
13,871 |
uber-go/atomic
|
atomic.go
|
Swap
|
func (i *Uint64) Swap(n uint64) uint64 {
return atomic.SwapUint64(&i.v, n)
}
|
go
|
func (i *Uint64) Swap(n uint64) uint64 {
return atomic.SwapUint64(&i.v, n)
}
|
[
"func",
"(",
"i",
"*",
"Uint64",
")",
"Swap",
"(",
"n",
"uint64",
")",
"uint64",
"{",
"return",
"atomic",
".",
"SwapUint64",
"(",
"&",
"i",
".",
"v",
",",
"n",
")",
"\n",
"}"
] |
// Swap atomically swaps the wrapped uint64 and returns the old value.
|
[
"Swap",
"atomically",
"swaps",
"the",
"wrapped",
"uint64",
"and",
"returns",
"the",
"old",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L219-L221
|
13,872 |
uber-go/atomic
|
atomic.go
|
Swap
|
func (b *Bool) Swap(new bool) bool {
return truthy(atomic.SwapUint32(&b.v, boolToInt(new)))
}
|
go
|
func (b *Bool) Swap(new bool) bool {
return truthy(atomic.SwapUint32(&b.v, boolToInt(new)))
}
|
[
"func",
"(",
"b",
"*",
"Bool",
")",
"Swap",
"(",
"new",
"bool",
")",
"bool",
"{",
"return",
"truthy",
"(",
"atomic",
".",
"SwapUint32",
"(",
"&",
"b",
".",
"v",
",",
"boolToInt",
"(",
"new",
")",
")",
")",
"\n",
"}"
] |
// Swap sets the given value and returns the previous value.
|
[
"Swap",
"sets",
"the",
"given",
"value",
"and",
"returns",
"the",
"previous",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L247-L249
|
13,873 |
uber-go/atomic
|
atomic.go
|
Add
|
func (f *Float64) Add(s float64) float64 {
for {
old := f.Load()
new := old + s
if f.CAS(old, new) {
return new
}
}
}
|
go
|
func (f *Float64) Add(s float64) float64 {
for {
old := f.Load()
new := old + s
if f.CAS(old, new) {
return new
}
}
}
|
[
"func",
"(",
"f",
"*",
"Float64",
")",
"Add",
"(",
"s",
"float64",
")",
"float64",
"{",
"for",
"{",
"old",
":=",
"f",
".",
"Load",
"(",
")",
"\n",
"new",
":=",
"old",
"+",
"s",
"\n",
"if",
"f",
".",
"CAS",
"(",
"old",
",",
"new",
")",
"{",
"return",
"new",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Add atomically adds to the wrapped float64 and returns the new value.
|
[
"Add",
"atomically",
"adds",
"to",
"the",
"wrapped",
"float64",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L288-L296
|
13,874 |
uber-go/atomic
|
atomic.go
|
NewDuration
|
func NewDuration(d time.Duration) *Duration {
return &Duration{v: *NewInt64(int64(d))}
}
|
go
|
func NewDuration(d time.Duration) *Duration {
return &Duration{v: *NewInt64(int64(d))}
}
|
[
"func",
"NewDuration",
"(",
"d",
"time",
".",
"Duration",
")",
"*",
"Duration",
"{",
"return",
"&",
"Duration",
"{",
"v",
":",
"*",
"NewInt64",
"(",
"int64",
"(",
"d",
")",
")",
"}",
"\n",
"}"
] |
// NewDuration creates a Duration.
|
[
"NewDuration",
"creates",
"a",
"Duration",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L315-L317
|
13,875 |
uber-go/atomic
|
atomic.go
|
Add
|
func (d *Duration) Add(n time.Duration) time.Duration {
return time.Duration(d.v.Add(int64(n)))
}
|
go
|
func (d *Duration) Add(n time.Duration) time.Duration {
return time.Duration(d.v.Add(int64(n)))
}
|
[
"func",
"(",
"d",
"*",
"Duration",
")",
"Add",
"(",
"n",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"d",
".",
"v",
".",
"Add",
"(",
"int64",
"(",
"n",
")",
")",
")",
"\n",
"}"
] |
// Add atomically adds to the wrapped time.Duration and returns the new value.
|
[
"Add",
"atomically",
"adds",
"to",
"the",
"wrapped",
"time",
".",
"Duration",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L330-L332
|
13,876 |
uber-go/atomic
|
atomic.go
|
Sub
|
func (d *Duration) Sub(n time.Duration) time.Duration {
return time.Duration(d.v.Sub(int64(n)))
}
|
go
|
func (d *Duration) Sub(n time.Duration) time.Duration {
return time.Duration(d.v.Sub(int64(n)))
}
|
[
"func",
"(",
"d",
"*",
"Duration",
")",
"Sub",
"(",
"n",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"d",
".",
"v",
".",
"Sub",
"(",
"int64",
"(",
"n",
")",
")",
")",
"\n",
"}"
] |
// Sub atomically subtracts from the wrapped time.Duration and returns the new value.
|
[
"Sub",
"atomically",
"subtracts",
"from",
"the",
"wrapped",
"time",
".",
"Duration",
"and",
"returns",
"the",
"new",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L335-L337
|
13,877 |
uber-go/atomic
|
atomic.go
|
Swap
|
func (d *Duration) Swap(n time.Duration) time.Duration {
return time.Duration(d.v.Swap(int64(n)))
}
|
go
|
func (d *Duration) Swap(n time.Duration) time.Duration {
return time.Duration(d.v.Swap(int64(n)))
}
|
[
"func",
"(",
"d",
"*",
"Duration",
")",
"Swap",
"(",
"n",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"return",
"time",
".",
"Duration",
"(",
"d",
".",
"v",
".",
"Swap",
"(",
"int64",
"(",
"n",
")",
")",
")",
"\n",
"}"
] |
// Swap atomically swaps the wrapped time.Duration and returns the old value.
|
[
"Swap",
"atomically",
"swaps",
"the",
"wrapped",
"time",
".",
"Duration",
"and",
"returns",
"the",
"old",
"value",
"."
] |
df976f2515e274675050de7b3f42545de80594fd
|
https://github.com/uber-go/atomic/blob/df976f2515e274675050de7b3f42545de80594fd/atomic.go#L340-L342
|
13,878 |
mikespook/gearman-go
|
client/pool.go
|
NewPool
|
func NewPool() (pool *Pool) {
return &Pool{
Clients: make(map[string]*PoolClient, poolSize),
SelectionHandler: SelectWithRate,
}
}
|
go
|
func NewPool() (pool *Pool) {
return &Pool{
Clients: make(map[string]*PoolClient, poolSize),
SelectionHandler: SelectWithRate,
}
}
|
[
"func",
"NewPool",
"(",
")",
"(",
"pool",
"*",
"Pool",
")",
"{",
"return",
"&",
"Pool",
"{",
"Clients",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"PoolClient",
",",
"poolSize",
")",
",",
"SelectionHandler",
":",
"SelectWithRate",
",",
"}",
"\n",
"}"
] |
// NewPool returns a new pool.
|
[
"NewPool",
"returns",
"a",
"new",
"pool",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/pool.go#L61-L66
|
13,879 |
mikespook/gearman-go
|
client/pool.go
|
Add
|
func (pool *Pool) Add(net, addr string, rate int) (err error) {
pool.mutex.Lock()
defer pool.mutex.Unlock()
var item *PoolClient
var ok bool
if item, ok = pool.Clients[addr]; ok {
item.Rate = rate
} else {
var client *Client
client, err = New(net, addr)
if err == nil {
item = &PoolClient{Client: client, Rate: rate}
pool.Clients[addr] = item
}
}
return
}
|
go
|
func (pool *Pool) Add(net, addr string, rate int) (err error) {
pool.mutex.Lock()
defer pool.mutex.Unlock()
var item *PoolClient
var ok bool
if item, ok = pool.Clients[addr]; ok {
item.Rate = rate
} else {
var client *Client
client, err = New(net, addr)
if err == nil {
item = &PoolClient{Client: client, Rate: rate}
pool.Clients[addr] = item
}
}
return
}
|
[
"func",
"(",
"pool",
"*",
"Pool",
")",
"Add",
"(",
"net",
",",
"addr",
"string",
",",
"rate",
"int",
")",
"(",
"err",
"error",
")",
"{",
"pool",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pool",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"var",
"item",
"*",
"PoolClient",
"\n",
"var",
"ok",
"bool",
"\n",
"if",
"item",
",",
"ok",
"=",
"pool",
".",
"Clients",
"[",
"addr",
"]",
";",
"ok",
"{",
"item",
".",
"Rate",
"=",
"rate",
"\n",
"}",
"else",
"{",
"var",
"client",
"*",
"Client",
"\n",
"client",
",",
"err",
"=",
"New",
"(",
"net",
",",
"addr",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"item",
"=",
"&",
"PoolClient",
"{",
"Client",
":",
"client",
",",
"Rate",
":",
"rate",
"}",
"\n",
"pool",
".",
"Clients",
"[",
"addr",
"]",
"=",
"item",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Add a server with rate.
|
[
"Add",
"a",
"server",
"with",
"rate",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/pool.go#L69-L85
|
13,880 |
mikespook/gearman-go
|
client/pool.go
|
Remove
|
func (pool *Pool) Remove(addr string) {
pool.mutex.Lock()
defer pool.mutex.Unlock()
delete(pool.Clients, addr)
}
|
go
|
func (pool *Pool) Remove(addr string) {
pool.mutex.Lock()
defer pool.mutex.Unlock()
delete(pool.Clients, addr)
}
|
[
"func",
"(",
"pool",
"*",
"Pool",
")",
"Remove",
"(",
"addr",
"string",
")",
"{",
"pool",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"pool",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"pool",
".",
"Clients",
",",
"addr",
")",
"\n",
"}"
] |
// Remove a server.
|
[
"Remove",
"a",
"server",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/pool.go#L88-L92
|
13,881 |
mikespook/gearman-go
|
client/pool.go
|
Status
|
func (pool *Pool) Status(addr, handle string) (status *Status, err error) {
if client, ok := pool.Clients[addr]; ok {
client.Lock()
defer client.Unlock()
status, err = client.Status(handle)
} else {
err = ErrNotFound
}
return
}
|
go
|
func (pool *Pool) Status(addr, handle string) (status *Status, err error) {
if client, ok := pool.Clients[addr]; ok {
client.Lock()
defer client.Unlock()
status, err = client.Status(handle)
} else {
err = ErrNotFound
}
return
}
|
[
"func",
"(",
"pool",
"*",
"Pool",
")",
"Status",
"(",
"addr",
",",
"handle",
"string",
")",
"(",
"status",
"*",
"Status",
",",
"err",
"error",
")",
"{",
"if",
"client",
",",
"ok",
":=",
"pool",
".",
"Clients",
"[",
"addr",
"]",
";",
"ok",
"{",
"client",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"Unlock",
"(",
")",
"\n",
"status",
",",
"err",
"=",
"client",
".",
"Status",
"(",
"handle",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"ErrNotFound",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Status gets job status from job server.
// !!!Not fully tested.!!!
|
[
"Status",
"gets",
"job",
"status",
"from",
"job",
"server",
".",
"!!!Not",
"fully",
"tested",
".",
"!!!"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/pool.go#L116-L125
|
13,882 |
mikespook/gearman-go
|
client/pool.go
|
Echo
|
func (pool *Pool) Echo(addr string, data []byte) (echo []byte, err error) {
var client *PoolClient
if addr == "" {
client = pool.selectServer()
} else {
var ok bool
if client, ok = pool.Clients[addr]; !ok {
err = ErrNotFound
return
}
}
client.Lock()
defer client.Unlock()
echo, err = client.Echo(data)
return
}
|
go
|
func (pool *Pool) Echo(addr string, data []byte) (echo []byte, err error) {
var client *PoolClient
if addr == "" {
client = pool.selectServer()
} else {
var ok bool
if client, ok = pool.Clients[addr]; !ok {
err = ErrNotFound
return
}
}
client.Lock()
defer client.Unlock()
echo, err = client.Echo(data)
return
}
|
[
"func",
"(",
"pool",
"*",
"Pool",
")",
"Echo",
"(",
"addr",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"echo",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"var",
"client",
"*",
"PoolClient",
"\n",
"if",
"addr",
"==",
"\"",
"\"",
"{",
"client",
"=",
"pool",
".",
"selectServer",
"(",
")",
"\n",
"}",
"else",
"{",
"var",
"ok",
"bool",
"\n",
"if",
"client",
",",
"ok",
"=",
"pool",
".",
"Clients",
"[",
"addr",
"]",
";",
"!",
"ok",
"{",
"err",
"=",
"ErrNotFound",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"client",
".",
"Lock",
"(",
")",
"\n",
"defer",
"client",
".",
"Unlock",
"(",
")",
"\n",
"echo",
",",
"err",
"=",
"client",
".",
"Echo",
"(",
"data",
")",
"\n",
"return",
"\n",
"}"
] |
// Send a something out, get the samething back.
|
[
"Send",
"a",
"something",
"out",
"get",
"the",
"samething",
"back",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/pool.go#L128-L143
|
13,883 |
mikespook/gearman-go
|
client/request.go
|
Encode
|
func (req *request) Encode() (data []byte) {
l := len(req.Data) // length of data
tl := l + minPacketLength // add 12 bytes head
data = getBuffer(tl)
copy(data[:4], reqStr)
binary.BigEndian.PutUint32(data[4:8], req.DataType)
binary.BigEndian.PutUint32(data[8:12], uint32(l))
copy(data[minPacketLength:], req.Data)
return
}
|
go
|
func (req *request) Encode() (data []byte) {
l := len(req.Data) // length of data
tl := l + minPacketLength // add 12 bytes head
data = getBuffer(tl)
copy(data[:4], reqStr)
binary.BigEndian.PutUint32(data[4:8], req.DataType)
binary.BigEndian.PutUint32(data[8:12], uint32(l))
copy(data[minPacketLength:], req.Data)
return
}
|
[
"func",
"(",
"req",
"*",
"request",
")",
"Encode",
"(",
")",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"l",
":=",
"len",
"(",
"req",
".",
"Data",
")",
"// length of data",
"\n",
"tl",
":=",
"l",
"+",
"minPacketLength",
"// add 12 bytes head",
"\n",
"data",
"=",
"getBuffer",
"(",
"tl",
")",
"\n",
"copy",
"(",
"data",
"[",
":",
"4",
"]",
",",
"reqStr",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"data",
"[",
"4",
":",
"8",
"]",
",",
"req",
".",
"DataType",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"data",
"[",
"8",
":",
"12",
"]",
",",
"uint32",
"(",
"l",
")",
")",
"\n",
"copy",
"(",
"data",
"[",
"minPacketLength",
":",
"]",
",",
"req",
".",
"Data",
")",
"\n",
"return",
"\n",
"}"
] |
// Encode a Request to byte slice
|
[
"Encode",
"a",
"Request",
"to",
"byte",
"slice"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/request.go#L14-L23
|
13,884 |
mikespook/gearman-go
|
client/client.go
|
New
|
func New(network, addr string) (client *Client, err error) {
client = &Client{
net: network,
addr: addr,
respHandler: newResponseHandlerMap(),
innerHandler: newResponseHandlerMap(),
in: make(chan *Response, queueSize),
ResponseTimeout: DefaultTimeout,
}
client.conn, err = net.Dial(client.net, client.addr)
if err != nil {
return
}
client.rw = bufio.NewReadWriter(bufio.NewReader(client.conn),
bufio.NewWriter(client.conn))
go client.readLoop()
go client.processLoop()
return
}
|
go
|
func New(network, addr string) (client *Client, err error) {
client = &Client{
net: network,
addr: addr,
respHandler: newResponseHandlerMap(),
innerHandler: newResponseHandlerMap(),
in: make(chan *Response, queueSize),
ResponseTimeout: DefaultTimeout,
}
client.conn, err = net.Dial(client.net, client.addr)
if err != nil {
return
}
client.rw = bufio.NewReadWriter(bufio.NewReader(client.conn),
bufio.NewWriter(client.conn))
go client.readLoop()
go client.processLoop()
return
}
|
[
"func",
"New",
"(",
"network",
",",
"addr",
"string",
")",
"(",
"client",
"*",
"Client",
",",
"err",
"error",
")",
"{",
"client",
"=",
"&",
"Client",
"{",
"net",
":",
"network",
",",
"addr",
":",
"addr",
",",
"respHandler",
":",
"newResponseHandlerMap",
"(",
")",
",",
"innerHandler",
":",
"newResponseHandlerMap",
"(",
")",
",",
"in",
":",
"make",
"(",
"chan",
"*",
"Response",
",",
"queueSize",
")",
",",
"ResponseTimeout",
":",
"DefaultTimeout",
",",
"}",
"\n",
"client",
".",
"conn",
",",
"err",
"=",
"net",
".",
"Dial",
"(",
"client",
".",
"net",
",",
"client",
".",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"client",
".",
"rw",
"=",
"bufio",
".",
"NewReadWriter",
"(",
"bufio",
".",
"NewReader",
"(",
"client",
".",
"conn",
")",
",",
"bufio",
".",
"NewWriter",
"(",
"client",
".",
"conn",
")",
")",
"\n",
"go",
"client",
".",
"readLoop",
"(",
")",
"\n",
"go",
"client",
".",
"processLoop",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// New returns a client.
|
[
"New",
"returns",
"a",
"client",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/client.go#L66-L84
|
13,885 |
mikespook/gearman-go
|
client/client.go
|
Status
|
func (client *Client) Status(handle string) (status *Status, err error) {
if client.conn == nil {
return nil, ErrLostConn
}
var mutex sync.Mutex
mutex.Lock()
client.innerHandler.put("s"+handle, func(resp *Response) {
defer mutex.Unlock()
var err error
status, err = resp._status()
if err != nil {
client.err(err)
}
})
req := getRequest()
req.DataType = dtGetStatus
req.Data = []byte(handle)
client.write(req)
mutex.Lock()
return
}
|
go
|
func (client *Client) Status(handle string) (status *Status, err error) {
if client.conn == nil {
return nil, ErrLostConn
}
var mutex sync.Mutex
mutex.Lock()
client.innerHandler.put("s"+handle, func(resp *Response) {
defer mutex.Unlock()
var err error
status, err = resp._status()
if err != nil {
client.err(err)
}
})
req := getRequest()
req.DataType = dtGetStatus
req.Data = []byte(handle)
client.write(req)
mutex.Lock()
return
}
|
[
"func",
"(",
"client",
"*",
"Client",
")",
"Status",
"(",
"handle",
"string",
")",
"(",
"status",
"*",
"Status",
",",
"err",
"error",
")",
"{",
"if",
"client",
".",
"conn",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrLostConn",
"\n",
"}",
"\n",
"var",
"mutex",
"sync",
".",
"Mutex",
"\n",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"client",
".",
"innerHandler",
".",
"put",
"(",
"\"",
"\"",
"+",
"handle",
",",
"func",
"(",
"resp",
"*",
"Response",
")",
"{",
"defer",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"status",
",",
"err",
"=",
"resp",
".",
"_status",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"client",
".",
"err",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"req",
":=",
"getRequest",
"(",
")",
"\n",
"req",
".",
"DataType",
"=",
"dtGetStatus",
"\n",
"req",
".",
"Data",
"=",
"[",
"]",
"byte",
"(",
"handle",
")",
"\n",
"client",
".",
"write",
"(",
"req",
")",
"\n",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"return",
"\n",
"}"
] |
// Status gets job status from job server.
|
[
"Status",
"gets",
"job",
"status",
"from",
"job",
"server",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/client/client.go#L297-L317
|
13,886 |
mikespook/gearman-go
|
worker/agent.go
|
newAgent
|
func newAgent(net, addr string, worker *Worker) (a *agent, err error) {
a = &agent{
net: net,
addr: addr,
worker: worker,
in: make(chan []byte, queueSize),
}
return
}
|
go
|
func newAgent(net, addr string, worker *Worker) (a *agent, err error) {
a = &agent{
net: net,
addr: addr,
worker: worker,
in: make(chan []byte, queueSize),
}
return
}
|
[
"func",
"newAgent",
"(",
"net",
",",
"addr",
"string",
",",
"worker",
"*",
"Worker",
")",
"(",
"a",
"*",
"agent",
",",
"err",
"error",
")",
"{",
"a",
"=",
"&",
"agent",
"{",
"net",
":",
"net",
",",
"addr",
":",
"addr",
",",
"worker",
":",
"worker",
",",
"in",
":",
"make",
"(",
"chan",
"[",
"]",
"byte",
",",
"queueSize",
")",
",",
"}",
"\n",
"return",
"\n",
"}"
] |
// Create the agent of job server.
|
[
"Create",
"the",
"agent",
"of",
"job",
"server",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/agent.go#L23-L31
|
13,887 |
mikespook/gearman-go
|
worker/agent.go
|
read
|
func (a *agent) read() (data []byte, err error) {
n := 0
tmp := getBuffer(bufferSize)
var buf bytes.Buffer
// read the header so we can get the length of the data
if n, err = a.rw.Read(tmp); err != nil {
return
}
dl := int(binary.BigEndian.Uint32(tmp[8:12]))
// write what we read so far
buf.Write(tmp[:n])
// read until we receive all the data
for buf.Len() < dl+minPacketLength {
if n, err = a.rw.Read(tmp); err != nil {
return buf.Bytes(), err
}
buf.Write(tmp[:n])
}
return buf.Bytes(), err
}
|
go
|
func (a *agent) read() (data []byte, err error) {
n := 0
tmp := getBuffer(bufferSize)
var buf bytes.Buffer
// read the header so we can get the length of the data
if n, err = a.rw.Read(tmp); err != nil {
return
}
dl := int(binary.BigEndian.Uint32(tmp[8:12]))
// write what we read so far
buf.Write(tmp[:n])
// read until we receive all the data
for buf.Len() < dl+minPacketLength {
if n, err = a.rw.Read(tmp); err != nil {
return buf.Bytes(), err
}
buf.Write(tmp[:n])
}
return buf.Bytes(), err
}
|
[
"func",
"(",
"a",
"*",
"agent",
")",
"read",
"(",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"n",
":=",
"0",
"\n\n",
"tmp",
":=",
"getBuffer",
"(",
"bufferSize",
")",
"\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"// read the header so we can get the length of the data",
"if",
"n",
",",
"err",
"=",
"a",
".",
"rw",
".",
"Read",
"(",
"tmp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"dl",
":=",
"int",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"tmp",
"[",
"8",
":",
"12",
"]",
")",
")",
"\n\n",
"// write what we read so far",
"buf",
".",
"Write",
"(",
"tmp",
"[",
":",
"n",
"]",
")",
"\n\n",
"// read until we receive all the data",
"for",
"buf",
".",
"Len",
"(",
")",
"<",
"dl",
"+",
"minPacketLength",
"{",
"if",
"n",
",",
"err",
"=",
"a",
".",
"rw",
".",
"Read",
"(",
"tmp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}",
"\n\n",
"buf",
".",
"Write",
"(",
"tmp",
"[",
":",
"n",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"err",
"\n",
"}"
] |
// read length bytes from the socket
|
[
"read",
"length",
"bytes",
"from",
"the",
"socket"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/agent.go#L171-L196
|
13,888 |
mikespook/gearman-go
|
worker/agent.go
|
write
|
func (a *agent) write(outpack *outPack) (err error) {
var n int
buf := outpack.Encode()
for i := 0; i < len(buf); i += n {
n, err = a.rw.Write(buf[i:])
if err != nil {
return err
}
}
return a.rw.Flush()
}
|
go
|
func (a *agent) write(outpack *outPack) (err error) {
var n int
buf := outpack.Encode()
for i := 0; i < len(buf); i += n {
n, err = a.rw.Write(buf[i:])
if err != nil {
return err
}
}
return a.rw.Flush()
}
|
[
"func",
"(",
"a",
"*",
"agent",
")",
"write",
"(",
"outpack",
"*",
"outPack",
")",
"(",
"err",
"error",
")",
"{",
"var",
"n",
"int",
"\n",
"buf",
":=",
"outpack",
".",
"Encode",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"buf",
")",
";",
"i",
"+=",
"n",
"{",
"n",
",",
"err",
"=",
"a",
".",
"rw",
".",
"Write",
"(",
"buf",
"[",
"i",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"a",
".",
"rw",
".",
"Flush",
"(",
")",
"\n",
"}"
] |
// Internal write the encoded job.
|
[
"Internal",
"write",
"the",
"encoded",
"job",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/agent.go#L199-L209
|
13,889 |
mikespook/gearman-go
|
worker/agent.go
|
Write
|
func (a *agent) Write(outpack *outPack) (err error) {
a.Lock()
defer a.Unlock()
return a.write(outpack)
}
|
go
|
func (a *agent) Write(outpack *outPack) (err error) {
a.Lock()
defer a.Unlock()
return a.write(outpack)
}
|
[
"func",
"(",
"a",
"*",
"agent",
")",
"Write",
"(",
"outpack",
"*",
"outPack",
")",
"(",
"err",
"error",
")",
"{",
"a",
".",
"Lock",
"(",
")",
"\n",
"defer",
"a",
".",
"Unlock",
"(",
")",
"\n",
"return",
"a",
".",
"write",
"(",
"outpack",
")",
"\n",
"}"
] |
// Write with lock
|
[
"Write",
"with",
"lock"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/agent.go#L212-L216
|
13,890 |
mikespook/gearman-go
|
worker/outpack.go
|
Encode
|
func (outpack *outPack) Encode() (data []byte) {
var l int
if outpack.dataType == dtWorkFail {
l = len(outpack.handle)
} else {
l = len(outpack.data)
if outpack.handle != "" {
l += len(outpack.handle) + 1
}
}
data = getBuffer(l + minPacketLength)
binary.BigEndian.PutUint32(data[:4], req)
binary.BigEndian.PutUint32(data[4:8], outpack.dataType)
binary.BigEndian.PutUint32(data[8:minPacketLength], uint32(l))
i := minPacketLength
if outpack.handle != "" {
hi := len(outpack.handle) + i
copy(data[i:hi], []byte(outpack.handle))
if outpack.dataType != dtWorkFail {
data[hi] = '\x00'
}
i = hi + 1
}
if outpack.dataType != dtWorkFail {
copy(data[i:], outpack.data)
}
return
}
|
go
|
func (outpack *outPack) Encode() (data []byte) {
var l int
if outpack.dataType == dtWorkFail {
l = len(outpack.handle)
} else {
l = len(outpack.data)
if outpack.handle != "" {
l += len(outpack.handle) + 1
}
}
data = getBuffer(l + minPacketLength)
binary.BigEndian.PutUint32(data[:4], req)
binary.BigEndian.PutUint32(data[4:8], outpack.dataType)
binary.BigEndian.PutUint32(data[8:minPacketLength], uint32(l))
i := minPacketLength
if outpack.handle != "" {
hi := len(outpack.handle) + i
copy(data[i:hi], []byte(outpack.handle))
if outpack.dataType != dtWorkFail {
data[hi] = '\x00'
}
i = hi + 1
}
if outpack.dataType != dtWorkFail {
copy(data[i:], outpack.data)
}
return
}
|
[
"func",
"(",
"outpack",
"*",
"outPack",
")",
"Encode",
"(",
")",
"(",
"data",
"[",
"]",
"byte",
")",
"{",
"var",
"l",
"int",
"\n",
"if",
"outpack",
".",
"dataType",
"==",
"dtWorkFail",
"{",
"l",
"=",
"len",
"(",
"outpack",
".",
"handle",
")",
"\n",
"}",
"else",
"{",
"l",
"=",
"len",
"(",
"outpack",
".",
"data",
")",
"\n",
"if",
"outpack",
".",
"handle",
"!=",
"\"",
"\"",
"{",
"l",
"+=",
"len",
"(",
"outpack",
".",
"handle",
")",
"+",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"data",
"=",
"getBuffer",
"(",
"l",
"+",
"minPacketLength",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"data",
"[",
":",
"4",
"]",
",",
"req",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"data",
"[",
"4",
":",
"8",
"]",
",",
"outpack",
".",
"dataType",
")",
"\n",
"binary",
".",
"BigEndian",
".",
"PutUint32",
"(",
"data",
"[",
"8",
":",
"minPacketLength",
"]",
",",
"uint32",
"(",
"l",
")",
")",
"\n",
"i",
":=",
"minPacketLength",
"\n",
"if",
"outpack",
".",
"handle",
"!=",
"\"",
"\"",
"{",
"hi",
":=",
"len",
"(",
"outpack",
".",
"handle",
")",
"+",
"i",
"\n",
"copy",
"(",
"data",
"[",
"i",
":",
"hi",
"]",
",",
"[",
"]",
"byte",
"(",
"outpack",
".",
"handle",
")",
")",
"\n",
"if",
"outpack",
".",
"dataType",
"!=",
"dtWorkFail",
"{",
"data",
"[",
"hi",
"]",
"=",
"'\\x00'",
"\n",
"}",
"\n",
"i",
"=",
"hi",
"+",
"1",
"\n",
"}",
"\n",
"if",
"outpack",
".",
"dataType",
"!=",
"dtWorkFail",
"{",
"copy",
"(",
"data",
"[",
"i",
":",
"]",
",",
"outpack",
".",
"data",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// Encode a job to byte slice
|
[
"Encode",
"a",
"job",
"to",
"byte",
"slice"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/outpack.go#L20-L47
|
13,891 |
mikespook/gearman-go
|
worker/error.go
|
getError
|
func getError(data []byte) (err error) {
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
if len(rel) != 2 {
err = fmt.Errorf("Not a error data: %v", data)
return
}
err = fmt.Errorf("%s: %s", rel[0], rel[1])
return
}
|
go
|
func getError(data []byte) (err error) {
rel := bytes.SplitN(data, []byte{'\x00'}, 2)
if len(rel) != 2 {
err = fmt.Errorf("Not a error data: %v", data)
return
}
err = fmt.Errorf("%s: %s", rel[0], rel[1])
return
}
|
[
"func",
"getError",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"rel",
":=",
"bytes",
".",
"SplitN",
"(",
"data",
",",
"[",
"]",
"byte",
"{",
"'\\x00'",
"}",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"rel",
")",
"!=",
"2",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"data",
")",
"\n",
"return",
"\n",
"}",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rel",
"[",
"0",
"]",
",",
"rel",
"[",
"1",
"]",
")",
"\n",
"return",
"\n",
"}"
] |
// Extract the error message
|
[
"Extract",
"the",
"error",
"message"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/error.go#L17-L25
|
13,892 |
mikespook/gearman-go
|
worker/worker.go
|
err
|
func (worker *Worker) err(e error) {
if worker.ErrorHandler != nil {
worker.ErrorHandler(e)
}
}
|
go
|
func (worker *Worker) err(e error) {
if worker.ErrorHandler != nil {
worker.ErrorHandler(e)
}
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"err",
"(",
"e",
"error",
")",
"{",
"if",
"worker",
".",
"ErrorHandler",
"!=",
"nil",
"{",
"worker",
".",
"ErrorHandler",
"(",
"e",
")",
"\n",
"}",
"\n",
"}"
] |
// inner error handling
|
[
"inner",
"error",
"handling"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L53-L57
|
13,893 |
mikespook/gearman-go
|
worker/worker.go
|
broadcast
|
func (worker *Worker) broadcast(outpack *outPack) {
for _, v := range worker.agents {
v.write(outpack)
}
}
|
go
|
func (worker *Worker) broadcast(outpack *outPack) {
for _, v := range worker.agents {
v.write(outpack)
}
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"broadcast",
"(",
"outpack",
"*",
"outPack",
")",
"{",
"for",
"_",
",",
"v",
":=",
"range",
"worker",
".",
"agents",
"{",
"v",
".",
"write",
"(",
"outpack",
")",
"\n",
"}",
"\n",
"}"
] |
// Broadcast an outpack to all Gearman server.
|
[
"Broadcast",
"an",
"outpack",
"to",
"all",
"Gearman",
"server",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L73-L77
|
13,894 |
mikespook/gearman-go
|
worker/worker.go
|
RemoveFunc
|
func (worker *Worker) RemoveFunc(funcname string) (err error) {
worker.Lock()
defer worker.Unlock()
if _, ok := worker.funcs[funcname]; !ok {
return fmt.Errorf("The function does not exist: %s", funcname)
}
delete(worker.funcs, funcname)
if worker.running {
worker.removeFunc(funcname)
}
return
}
|
go
|
func (worker *Worker) RemoveFunc(funcname string) (err error) {
worker.Lock()
defer worker.Unlock()
if _, ok := worker.funcs[funcname]; !ok {
return fmt.Errorf("The function does not exist: %s", funcname)
}
delete(worker.funcs, funcname)
if worker.running {
worker.removeFunc(funcname)
}
return
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"RemoveFunc",
"(",
"funcname",
"string",
")",
"(",
"err",
"error",
")",
"{",
"worker",
".",
"Lock",
"(",
")",
"\n",
"defer",
"worker",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"worker",
".",
"funcs",
"[",
"funcname",
"]",
";",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"funcname",
")",
"\n",
"}",
"\n",
"delete",
"(",
"worker",
".",
"funcs",
",",
"funcname",
")",
"\n",
"if",
"worker",
".",
"running",
"{",
"worker",
".",
"removeFunc",
"(",
"funcname",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// RemoveFunc removes a function.
|
[
"RemoveFunc",
"removes",
"a",
"function",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L120-L131
|
13,895 |
mikespook/gearman-go
|
worker/worker.go
|
handleInPack
|
func (worker *Worker) handleInPack(inpack *inPack) {
switch inpack.dataType {
case dtNoJob:
inpack.a.PreSleep()
case dtNoop:
inpack.a.Grab()
case dtJobAssign, dtJobAssignUniq:
go func() {
if err := worker.exec(inpack); err != nil {
worker.err(err)
}
}()
if worker.limit != nil {
worker.limit <- true
}
inpack.a.Grab()
case dtError:
worker.err(inpack.Err())
fallthrough
case dtEchoRes:
fallthrough
default:
worker.customeHandler(inpack)
}
}
|
go
|
func (worker *Worker) handleInPack(inpack *inPack) {
switch inpack.dataType {
case dtNoJob:
inpack.a.PreSleep()
case dtNoop:
inpack.a.Grab()
case dtJobAssign, dtJobAssignUniq:
go func() {
if err := worker.exec(inpack); err != nil {
worker.err(err)
}
}()
if worker.limit != nil {
worker.limit <- true
}
inpack.a.Grab()
case dtError:
worker.err(inpack.Err())
fallthrough
case dtEchoRes:
fallthrough
default:
worker.customeHandler(inpack)
}
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"handleInPack",
"(",
"inpack",
"*",
"inPack",
")",
"{",
"switch",
"inpack",
".",
"dataType",
"{",
"case",
"dtNoJob",
":",
"inpack",
".",
"a",
".",
"PreSleep",
"(",
")",
"\n",
"case",
"dtNoop",
":",
"inpack",
".",
"a",
".",
"Grab",
"(",
")",
"\n",
"case",
"dtJobAssign",
",",
"dtJobAssignUniq",
":",
"go",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"worker",
".",
"exec",
"(",
"inpack",
")",
";",
"err",
"!=",
"nil",
"{",
"worker",
".",
"err",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"if",
"worker",
".",
"limit",
"!=",
"nil",
"{",
"worker",
".",
"limit",
"<-",
"true",
"\n",
"}",
"\n",
"inpack",
".",
"a",
".",
"Grab",
"(",
")",
"\n",
"case",
"dtError",
":",
"worker",
".",
"err",
"(",
"inpack",
".",
"Err",
"(",
")",
")",
"\n",
"fallthrough",
"\n",
"case",
"dtEchoRes",
":",
"fallthrough",
"\n",
"default",
":",
"worker",
".",
"customeHandler",
"(",
"inpack",
")",
"\n",
"}",
"\n",
"}"
] |
// inner package handling
|
[
"inner",
"package",
"handling"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L142-L166
|
13,896 |
mikespook/gearman-go
|
worker/worker.go
|
Ready
|
func (worker *Worker) Ready() (err error) {
if len(worker.agents) == 0 {
return ErrNoneAgents
}
if len(worker.funcs) == 0 {
return ErrNoneFuncs
}
for _, a := range worker.agents {
if err = a.Connect(); err != nil {
return
}
}
for funcname, f := range worker.funcs {
worker.addFunc(funcname, f.timeout)
}
worker.ready = true
return
}
|
go
|
func (worker *Worker) Ready() (err error) {
if len(worker.agents) == 0 {
return ErrNoneAgents
}
if len(worker.funcs) == 0 {
return ErrNoneFuncs
}
for _, a := range worker.agents {
if err = a.Connect(); err != nil {
return
}
}
for funcname, f := range worker.funcs {
worker.addFunc(funcname, f.timeout)
}
worker.ready = true
return
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"Ready",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"worker",
".",
"agents",
")",
"==",
"0",
"{",
"return",
"ErrNoneAgents",
"\n",
"}",
"\n",
"if",
"len",
"(",
"worker",
".",
"funcs",
")",
"==",
"0",
"{",
"return",
"ErrNoneFuncs",
"\n",
"}",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"worker",
".",
"agents",
"{",
"if",
"err",
"=",
"a",
".",
"Connect",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"funcname",
",",
"f",
":=",
"range",
"worker",
".",
"funcs",
"{",
"worker",
".",
"addFunc",
"(",
"funcname",
",",
"f",
".",
"timeout",
")",
"\n",
"}",
"\n",
"worker",
".",
"ready",
"=",
"true",
"\n",
"return",
"\n",
"}"
] |
// Connect to Gearman server and tell every server
// what can this worker do.
|
[
"Connect",
"to",
"Gearman",
"server",
"and",
"tell",
"every",
"server",
"what",
"can",
"this",
"worker",
"do",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L170-L187
|
13,897 |
mikespook/gearman-go
|
worker/worker.go
|
Work
|
func (worker *Worker) Work() {
if !worker.ready {
// didn't run Ready beforehand, so we'll have to do it:
err := worker.Ready()
if err != nil {
panic(err)
}
}
worker.running = true
for _, a := range worker.agents {
a.Grab()
}
var inpack *inPack
for inpack = range worker.in {
worker.handleInPack(inpack)
}
}
|
go
|
func (worker *Worker) Work() {
if !worker.ready {
// didn't run Ready beforehand, so we'll have to do it:
err := worker.Ready()
if err != nil {
panic(err)
}
}
worker.running = true
for _, a := range worker.agents {
a.Grab()
}
var inpack *inPack
for inpack = range worker.in {
worker.handleInPack(inpack)
}
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"Work",
"(",
")",
"{",
"if",
"!",
"worker",
".",
"ready",
"{",
"// didn't run Ready beforehand, so we'll have to do it:",
"err",
":=",
"worker",
".",
"Ready",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"worker",
".",
"running",
"=",
"true",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"worker",
".",
"agents",
"{",
"a",
".",
"Grab",
"(",
")",
"\n",
"}",
"\n",
"var",
"inpack",
"*",
"inPack",
"\n",
"for",
"inpack",
"=",
"range",
"worker",
".",
"in",
"{",
"worker",
".",
"handleInPack",
"(",
"inpack",
")",
"\n",
"}",
"\n",
"}"
] |
// Main loop, block here
// Most of time, this should be evaluated in goroutine.
|
[
"Main",
"loop",
"block",
"here",
"Most",
"of",
"time",
"this",
"should",
"be",
"evaluated",
"in",
"goroutine",
"."
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L191-L208
|
13,898 |
mikespook/gearman-go
|
worker/worker.go
|
customeHandler
|
func (worker *Worker) customeHandler(inpack *inPack) {
if worker.JobHandler != nil {
if err := worker.JobHandler(inpack); err != nil {
worker.err(err)
}
}
}
|
go
|
func (worker *Worker) customeHandler(inpack *inPack) {
if worker.JobHandler != nil {
if err := worker.JobHandler(inpack); err != nil {
worker.err(err)
}
}
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"customeHandler",
"(",
"inpack",
"*",
"inPack",
")",
"{",
"if",
"worker",
".",
"JobHandler",
"!=",
"nil",
"{",
"if",
"err",
":=",
"worker",
".",
"JobHandler",
"(",
"inpack",
")",
";",
"err",
"!=",
"nil",
"{",
"worker",
".",
"err",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// custome handling warper
|
[
"custome",
"handling",
"warper"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L211-L217
|
13,899 |
mikespook/gearman-go
|
worker/worker.go
|
Close
|
func (worker *Worker) Close() {
worker.Lock()
defer worker.Unlock()
if worker.running == true {
for _, a := range worker.agents {
a.Close()
}
worker.running = false
close(worker.in)
}
}
|
go
|
func (worker *Worker) Close() {
worker.Lock()
defer worker.Unlock()
if worker.running == true {
for _, a := range worker.agents {
a.Close()
}
worker.running = false
close(worker.in)
}
}
|
[
"func",
"(",
"worker",
"*",
"Worker",
")",
"Close",
"(",
")",
"{",
"worker",
".",
"Lock",
"(",
")",
"\n",
"defer",
"worker",
".",
"Unlock",
"(",
")",
"\n",
"if",
"worker",
".",
"running",
"==",
"true",
"{",
"for",
"_",
",",
"a",
":=",
"range",
"worker",
".",
"agents",
"{",
"a",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"worker",
".",
"running",
"=",
"false",
"\n",
"close",
"(",
"worker",
".",
"in",
")",
"\n",
"}",
"\n",
"}"
] |
// Close connection and exit main loop
|
[
"Close",
"connection",
"and",
"exit",
"main",
"loop"
] |
b902646ce8950409a10952e297dd63b4f459fa13
|
https://github.com/mikespook/gearman-go/blob/b902646ce8950409a10952e297dd63b4f459fa13/worker/worker.go#L220-L230
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.