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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
15,300 | bitrise-io/go-utils | command/git/commands.go | Clone | func (g *Git) Clone(repo string) *command.Model {
return g.command("clone", repo, ".")
} | go | func (g *Git) Clone(repo string) *command.Model {
return g.command("clone", repo, ".")
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Clone",
"(",
"repo",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"repo",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Clone a repository into a new directory. | [
"Clone",
"a",
"repository",
"into",
"a",
"new",
"directory",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L13-L15 |
15,301 | bitrise-io/go-utils | command/git/commands.go | CloneTagOrBranch | func (g *Git) CloneTagOrBranch(repo, tagOrBranch string) *command.Model {
return g.command("clone", "--recursive", "--branch", tagOrBranch, repo, ".")
} | go | func (g *Git) CloneTagOrBranch(repo, tagOrBranch string) *command.Model {
return g.command("clone", "--recursive", "--branch", tagOrBranch, repo, ".")
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"CloneTagOrBranch",
"(",
"repo",
",",
"tagOrBranch",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"tagOrBranch",
",",
"repo",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // CloneTagOrBranch is recursively clones a tag or branch. | [
"CloneTagOrBranch",
"is",
"recursively",
"clones",
"a",
"tag",
"or",
"branch",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L18-L20 |
15,302 | bitrise-io/go-utils | command/git/commands.go | Fetch | func (g *Git) Fetch(opts ...string) *command.Model {
args := []string{"fetch"}
args = append(args, opts...)
return g.command(args...)
} | go | func (g *Git) Fetch(opts ...string) *command.Model {
args := []string{"fetch"}
args = append(args, opts...)
return g.command(args...)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Fetch",
"(",
"opts",
"...",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"opts",
"...",
")",
"\n",
"return",
"g",
".",
"command",
"(",
"args",
"...",
")",
"\n",
"}"
] | // Fetch downloads objects and refs from another repository. | [
"Fetch",
"downloads",
"objects",
"and",
"refs",
"from",
"another",
"repository",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L33-L37 |
15,303 | bitrise-io/go-utils | command/git/commands.go | Checkout | func (g *Git) Checkout(arg string) *command.Model {
return g.command("checkout", arg)
} | go | func (g *Git) Checkout(arg string) *command.Model {
return g.command("checkout", arg)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Checkout",
"(",
"arg",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"arg",
")",
"\n",
"}"
] | // Checkout switchs branches or restore working tree files.
// Arg can be a commit hash, a branch or a tag. | [
"Checkout",
"switchs",
"branches",
"or",
"restore",
"working",
"tree",
"files",
".",
"Arg",
"can",
"be",
"a",
"commit",
"hash",
"a",
"branch",
"or",
"a",
"tag",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L41-L43 |
15,304 | bitrise-io/go-utils | command/git/commands.go | Merge | func (g *Git) Merge(arg string) *command.Model {
return g.command("merge", arg)
} | go | func (g *Git) Merge(arg string) *command.Model {
return g.command("merge", arg)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Merge",
"(",
"arg",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"arg",
")",
"\n",
"}"
] | // Merge joins two or more development histories together.
// Arg can be a commit hash, branch or tag. | [
"Merge",
"joins",
"two",
"or",
"more",
"development",
"histories",
"together",
".",
"Arg",
"can",
"be",
"a",
"commit",
"hash",
"branch",
"or",
"tag",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L47-L49 |
15,305 | bitrise-io/go-utils | command/git/commands.go | Clean | func (g *Git) Clean(options ...string) *command.Model {
args := []string{"clean"}
args = append(args, options...)
return g.command(args...)
} | go | func (g *Git) Clean(options ...string) *command.Model {
args := []string{"clean"}
args = append(args, options...)
return g.command(args...)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Clean",
"(",
"options",
"...",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"options",
"...",
")",
"\n",
"return",
"g",
".",
"command",
"(",
"args",
"...",
")",
"\n",
"}"
] | // Clean removes untracked files from the working tree. | [
"Clean",
"removes",
"untracked",
"files",
"from",
"the",
"working",
"tree",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L58-L62 |
15,306 | bitrise-io/go-utils | command/git/commands.go | SubmoduleForeach | func (g *Git) SubmoduleForeach(command *command.Model) *command.Model {
args := []string{"submodule", "foreach"}
args = append(args, command.GetCmd().Args...)
return g.command(args...)
} | go | func (g *Git) SubmoduleForeach(command *command.Model) *command.Model {
args := []string{"submodule", "foreach"}
args = append(args, command.GetCmd().Args...)
return g.command(args...)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"SubmoduleForeach",
"(",
"command",
"*",
"command",
".",
"Model",
")",
"*",
"command",
".",
"Model",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"command",
".",
"GetCmd",
"(",
")",
".",
"Args",
"...",
")",
"\n",
"return",
"g",
".",
"command",
"(",
"args",
"...",
")",
"\n",
"}"
] | // SubmoduleForeach evaluates an arbitrary git command in each checked out
// submodule. | [
"SubmoduleForeach",
"evaluates",
"an",
"arbitrary",
"git",
"command",
"in",
"each",
"checked",
"out",
"submodule",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L71-L75 |
15,307 | bitrise-io/go-utils | command/git/commands.go | NewBranch | func (g *Git) NewBranch(branch string) *command.Model {
return g.command("checkout", "-b", branch)
} | go | func (g *Git) NewBranch(branch string) *command.Model {
return g.command("checkout", "-b", branch)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"NewBranch",
"(",
"branch",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"branch",
")",
"\n",
"}"
] | // NewBranch creates a new branch as if git-branch were called and then check it out. | [
"NewBranch",
"creates",
"a",
"new",
"branch",
"as",
"if",
"git",
"-",
"branch",
"were",
"called",
"and",
"then",
"check",
"it",
"out",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L94-L96 |
15,308 | bitrise-io/go-utils | command/git/commands.go | Log | func (g *Git) Log(format string) *command.Model {
return g.command("log", "-1", "--format="+format)
} | go | func (g *Git) Log(format string) *command.Model {
return g.command("log", "-1", "--format="+format)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Log",
"(",
"format",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"format",
")",
"\n",
"}"
] | // Log shows the commit logs. The format parameter controls what is shown and how. | [
"Log",
"shows",
"the",
"commit",
"logs",
".",
"The",
"format",
"parameter",
"controls",
"what",
"is",
"shown",
"and",
"how",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L104-L106 |
15,309 | bitrise-io/go-utils | command/git/commands.go | RevList | func (g *Git) RevList(commit string, opts ...string) *command.Model {
args := []string{"rev-list", commit}
args = append(args, opts...)
return g.command(args...)
} | go | func (g *Git) RevList(commit string, opts ...string) *command.Model {
args := []string{"rev-list", commit}
args = append(args, opts...)
return g.command(args...)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"RevList",
"(",
"commit",
"string",
",",
"opts",
"...",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"commit",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"opts",
"...",
")",
"\n",
"return",
"g",
".",
"command",
"(",
"args",
"...",
")",
"\n",
"}"
] | // RevList lists commit objects in reverse chronological order. | [
"RevList",
"lists",
"commit",
"objects",
"in",
"reverse",
"chronological",
"order",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L109-L113 |
15,310 | bitrise-io/go-utils | command/git/commands.go | Push | func (g *Git) Push(branch string) *command.Model {
return g.command("push", "-u", "origin", branch)
} | go | func (g *Git) Push(branch string) *command.Model {
return g.command("push", "-u", "origin", branch)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Push",
"(",
"branch",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"branch",
")",
"\n",
"}"
] | // Push updates remote refs along with associated objects. | [
"Push",
"updates",
"remote",
"refs",
"along",
"with",
"associated",
"objects",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L116-L118 |
15,311 | bitrise-io/go-utils | command/git/commands.go | Commit | func (g *Git) Commit(message string) *command.Model {
return g.command("commit", "-m", message)
} | go | func (g *Git) Commit(message string) *command.Model {
return g.command("commit", "-m", message)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"Commit",
"(",
"message",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"message",
")",
"\n",
"}"
] | // Commit Stores the current contents of the index in a new commit along with a log message from the user describing the changes. | [
"Commit",
"Stores",
"the",
"current",
"contents",
"of",
"the",
"index",
"in",
"a",
"new",
"commit",
"along",
"with",
"a",
"log",
"message",
"from",
"the",
"user",
"describing",
"the",
"changes",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L121-L123 |
15,312 | bitrise-io/go-utils | command/git/commands.go | RevParse | func (g *Git) RevParse(arg string) *command.Model {
return g.command("rev-parse", arg)
} | go | func (g *Git) RevParse(arg string) *command.Model {
return g.command("rev-parse", arg)
} | [
"func",
"(",
"g",
"*",
"Git",
")",
"RevParse",
"(",
"arg",
"string",
")",
"*",
"command",
".",
"Model",
"{",
"return",
"g",
".",
"command",
"(",
"\"",
"\"",
",",
"arg",
")",
"\n",
"}"
] | // RevParse picks out and massage parameters. | [
"RevParse",
"picks",
"out",
"and",
"massage",
"parameters",
"."
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/command/git/commands.go#L126-L128 |
15,313 | bitrise-io/go-utils | envutil/envutil.go | StringFlagOrEnv | func StringFlagOrEnv(flagValue *string, envKey string) string {
if flagValue != nil && *flagValue != "" {
return *flagValue
}
return os.Getenv(envKey)
} | go | func StringFlagOrEnv(flagValue *string, envKey string) string {
if flagValue != nil && *flagValue != "" {
return *flagValue
}
return os.Getenv(envKey)
} | [
"func",
"StringFlagOrEnv",
"(",
"flagValue",
"*",
"string",
",",
"envKey",
"string",
")",
"string",
"{",
"if",
"flagValue",
"!=",
"nil",
"&&",
"*",
"flagValue",
"!=",
"\"",
"\"",
"{",
"return",
"*",
"flagValue",
"\n",
"}",
"\n",
"return",
"os",
".",
"Getenv",
"(",
"envKey",
")",
"\n",
"}"
] | // StringFlagOrEnv - returns the value of the flag if specified, otherwise the env's value.
// Empty string counts as not specified! | [
"StringFlagOrEnv",
"-",
"returns",
"the",
"value",
"of",
"the",
"flag",
"if",
"specified",
"otherwise",
"the",
"env",
"s",
"value",
".",
"Empty",
"string",
"counts",
"as",
"not",
"specified!"
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/envutil/envutil.go#L29-L34 |
15,314 | bitrise-io/go-utils | envutil/envutil.go | GetenvWithDefault | func GetenvWithDefault(envKey, defValue string) string {
retVal := os.Getenv(envKey)
if retVal == "" {
return defValue
}
return retVal
} | go | func GetenvWithDefault(envKey, defValue string) string {
retVal := os.Getenv(envKey)
if retVal == "" {
return defValue
}
return retVal
} | [
"func",
"GetenvWithDefault",
"(",
"envKey",
",",
"defValue",
"string",
")",
"string",
"{",
"retVal",
":=",
"os",
".",
"Getenv",
"(",
"envKey",
")",
"\n",
"if",
"retVal",
"==",
"\"",
"\"",
"{",
"return",
"defValue",
"\n",
"}",
"\n",
"return",
"retVal",
"\n",
"}"
] | // GetenvWithDefault - returns the env if specified, default value otherwise | [
"GetenvWithDefault",
"-",
"returns",
"the",
"env",
"if",
"specified",
"default",
"value",
"otherwise"
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/envutil/envutil.go#L37-L43 |
15,315 | bitrise-io/go-utils | maputil/maputil.go | MergeStringStringMap | func MergeStringStringMap(m1, m2 map[string]string) map[string]string {
mergedMap := CloneStringStringMap(m1)
for k, v := range m2 {
mergedMap[k] = v
}
return mergedMap
} | go | func MergeStringStringMap(m1, m2 map[string]string) map[string]string {
mergedMap := CloneStringStringMap(m1)
for k, v := range m2 {
mergedMap[k] = v
}
return mergedMap
} | [
"func",
"MergeStringStringMap",
"(",
"m1",
",",
"m2",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"mergedMap",
":=",
"CloneStringStringMap",
"(",
"m1",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"m2",
"{",
"mergedMap",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"mergedMap",
"\n",
"}"
] | // MergeStringStringMap - returns a new map object,
// DOES NOT modify either input map | [
"MergeStringStringMap",
"-",
"returns",
"a",
"new",
"map",
"object",
"DOES",
"NOT",
"modify",
"either",
"input",
"map"
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/maputil/maputil.go#L40-L46 |
15,316 | bitrise-io/go-utils | versions/versions.go | IsVersionBetween | func IsVersionBetween(verBase, verLower, verUpper string) (bool, error) {
r1, err := CompareVersions(verBase, verLower)
if err != nil {
return false, err
}
if r1 == 1 {
return false, nil
}
r2, err := CompareVersions(verBase, verUpper)
if err != nil {
return false, err
}
if r2 == -1 {
return false, nil
}
return true, nil
} | go | func IsVersionBetween(verBase, verLower, verUpper string) (bool, error) {
r1, err := CompareVersions(verBase, verLower)
if err != nil {
return false, err
}
if r1 == 1 {
return false, nil
}
r2, err := CompareVersions(verBase, verUpper)
if err != nil {
return false, err
}
if r2 == -1 {
return false, nil
}
return true, nil
} | [
"func",
"IsVersionBetween",
"(",
"verBase",
",",
"verLower",
",",
"verUpper",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"r1",
",",
"err",
":=",
"CompareVersions",
"(",
"verBase",
",",
"verLower",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"r1",
"==",
"1",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"r2",
",",
"err",
":=",
"CompareVersions",
"(",
"verBase",
",",
"verUpper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"r2",
"==",
"-",
"1",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // IsVersionBetween ...
// returns true if it's between the lower and upper limit
// or in case it matches the lower or the upper limit | [
"IsVersionBetween",
"...",
"returns",
"true",
"if",
"it",
"s",
"between",
"the",
"lower",
"and",
"upper",
"limit",
"or",
"in",
"case",
"it",
"matches",
"the",
"lower",
"or",
"the",
"upper",
"limit"
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/versions/versions.go#L68-L86 |
15,317 | bitrise-io/go-utils | versions/versions.go | IsVersionGreaterOrEqual | func IsVersionGreaterOrEqual(verBase, verLower string) (bool, error) {
r1, err := CompareVersions(verBase, verLower)
if err != nil {
return false, err
}
if r1 == 1 {
return false, nil
}
return true, nil
} | go | func IsVersionGreaterOrEqual(verBase, verLower string) (bool, error) {
r1, err := CompareVersions(verBase, verLower)
if err != nil {
return false, err
}
if r1 == 1 {
return false, nil
}
return true, nil
} | [
"func",
"IsVersionGreaterOrEqual",
"(",
"verBase",
",",
"verLower",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"r1",
",",
"err",
":=",
"CompareVersions",
"(",
"verBase",
",",
"verLower",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"r1",
"==",
"1",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // IsVersionGreaterOrEqual ...
// returns true if verBase is greater or equal to verLower | [
"IsVersionGreaterOrEqual",
"...",
"returns",
"true",
"if",
"verBase",
"is",
"greater",
"or",
"equal",
"to",
"verLower"
] | 2a09aab8380d7842750328aebd5671bcccea89c8 | https://github.com/bitrise-io/go-utils/blob/2a09aab8380d7842750328aebd5671bcccea89c8/versions/versions.go#L90-L100 |
15,318 | danieljoos/wincred | conversion.go | utf16PtrToString | func utf16PtrToString(wstr *uint16) string {
if wstr != nil {
for len := 0; ; len++ {
ptr := unsafe.Pointer(uintptr(unsafe.Pointer(wstr)) + uintptr(len)*unsafe.Sizeof(*wstr)) // see https://golang.org/pkg/unsafe/#Pointer (3)
if *(*uint16)(ptr) == 0 {
return string(utf16.Decode(*(*[]uint16)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(wstr)),
Len: len,
Cap: len,
}))))
}
}
}
return ""
} | go | func utf16PtrToString(wstr *uint16) string {
if wstr != nil {
for len := 0; ; len++ {
ptr := unsafe.Pointer(uintptr(unsafe.Pointer(wstr)) + uintptr(len)*unsafe.Sizeof(*wstr)) // see https://golang.org/pkg/unsafe/#Pointer (3)
if *(*uint16)(ptr) == 0 {
return string(utf16.Decode(*(*[]uint16)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(wstr)),
Len: len,
Cap: len,
}))))
}
}
}
return ""
} | [
"func",
"utf16PtrToString",
"(",
"wstr",
"*",
"uint16",
")",
"string",
"{",
"if",
"wstr",
"!=",
"nil",
"{",
"for",
"len",
":=",
"0",
";",
";",
"len",
"++",
"{",
"ptr",
":=",
"unsafe",
".",
"Pointer",
"(",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"wstr",
")",
")",
"+",
"uintptr",
"(",
"len",
")",
"*",
"unsafe",
".",
"Sizeof",
"(",
"*",
"wstr",
")",
")",
"// see https://golang.org/pkg/unsafe/#Pointer (3)",
"\n",
"if",
"*",
"(",
"*",
"uint16",
")",
"(",
"ptr",
")",
"==",
"0",
"{",
"return",
"string",
"(",
"utf16",
".",
"Decode",
"(",
"*",
"(",
"*",
"[",
"]",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"wstr",
")",
")",
",",
"Len",
":",
"len",
",",
"Cap",
":",
"len",
",",
"}",
")",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // uf16PtrToString creates a Go string from a pointer to a UTF16 encoded zero-terminated string.
// Such pointers are returned from the Windows API calls.
// The function creates a copy of the string. | [
"uf16PtrToString",
"creates",
"a",
"Go",
"string",
"from",
"a",
"pointer",
"to",
"a",
"UTF16",
"encoded",
"zero",
"-",
"terminated",
"string",
".",
"Such",
"pointers",
"are",
"returned",
"from",
"the",
"Windows",
"API",
"calls",
".",
"The",
"function",
"creates",
"a",
"copy",
"of",
"the",
"string",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/conversion.go#L17-L31 |
15,319 | danieljoos/wincred | conversion.go | utf16ToByte | func utf16ToByte(wstr []uint16) (result []byte) {
result = make([]byte, len(wstr)*2)
for i := range wstr {
binary.LittleEndian.PutUint16(result[(i*2):(i*2)+2], wstr[i])
}
return
} | go | func utf16ToByte(wstr []uint16) (result []byte) {
result = make([]byte, len(wstr)*2)
for i := range wstr {
binary.LittleEndian.PutUint16(result[(i*2):(i*2)+2], wstr[i])
}
return
} | [
"func",
"utf16ToByte",
"(",
"wstr",
"[",
"]",
"uint16",
")",
"(",
"result",
"[",
"]",
"byte",
")",
"{",
"result",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"wstr",
")",
"*",
"2",
")",
"\n",
"for",
"i",
":=",
"range",
"wstr",
"{",
"binary",
".",
"LittleEndian",
".",
"PutUint16",
"(",
"result",
"[",
"(",
"i",
"*",
"2",
")",
":",
"(",
"i",
"*",
"2",
")",
"+",
"2",
"]",
",",
"wstr",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // utf16ToByte creates a byte array from a given UTF 16 char array. | [
"utf16ToByte",
"creates",
"a",
"byte",
"array",
"from",
"a",
"given",
"UTF",
"16",
"char",
"array",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/conversion.go#L34-L40 |
15,320 | danieljoos/wincred | conversion.go | sysToCredential | func sysToCredential(cred *sysCREDENTIAL) (result *Credential) {
if cred == nil {
return nil
}
result = new(Credential)
result.Comment = utf16PtrToString(cred.Comment)
result.TargetName = utf16PtrToString(cred.TargetName)
result.TargetAlias = utf16PtrToString(cred.TargetAlias)
result.UserName = utf16PtrToString(cred.UserName)
result.LastWritten = time.Unix(0, cred.LastWritten.Nanoseconds())
result.Persist = CredentialPersistence(cred.Persist)
result.CredentialBlob = goBytes(cred.CredentialBlob, cred.CredentialBlobSize)
result.Attributes = make([]CredentialAttribute, cred.AttributeCount)
attrSlice := *(*[]sysCREDENTIAL_ATTRIBUTE)(unsafe.Pointer(&reflect.SliceHeader{
Data: cred.Attributes,
Len: int(cred.AttributeCount),
Cap: int(cred.AttributeCount),
}))
for i, attr := range attrSlice {
resultAttr := &result.Attributes[i]
resultAttr.Keyword = utf16PtrToString(attr.Keyword)
resultAttr.Value = goBytes(attr.Value, attr.ValueSize)
}
return result
} | go | func sysToCredential(cred *sysCREDENTIAL) (result *Credential) {
if cred == nil {
return nil
}
result = new(Credential)
result.Comment = utf16PtrToString(cred.Comment)
result.TargetName = utf16PtrToString(cred.TargetName)
result.TargetAlias = utf16PtrToString(cred.TargetAlias)
result.UserName = utf16PtrToString(cred.UserName)
result.LastWritten = time.Unix(0, cred.LastWritten.Nanoseconds())
result.Persist = CredentialPersistence(cred.Persist)
result.CredentialBlob = goBytes(cred.CredentialBlob, cred.CredentialBlobSize)
result.Attributes = make([]CredentialAttribute, cred.AttributeCount)
attrSlice := *(*[]sysCREDENTIAL_ATTRIBUTE)(unsafe.Pointer(&reflect.SliceHeader{
Data: cred.Attributes,
Len: int(cred.AttributeCount),
Cap: int(cred.AttributeCount),
}))
for i, attr := range attrSlice {
resultAttr := &result.Attributes[i]
resultAttr.Keyword = utf16PtrToString(attr.Keyword)
resultAttr.Value = goBytes(attr.Value, attr.ValueSize)
}
return result
} | [
"func",
"sysToCredential",
"(",
"cred",
"*",
"sysCREDENTIAL",
")",
"(",
"result",
"*",
"Credential",
")",
"{",
"if",
"cred",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"result",
"=",
"new",
"(",
"Credential",
")",
"\n",
"result",
".",
"Comment",
"=",
"utf16PtrToString",
"(",
"cred",
".",
"Comment",
")",
"\n",
"result",
".",
"TargetName",
"=",
"utf16PtrToString",
"(",
"cred",
".",
"TargetName",
")",
"\n",
"result",
".",
"TargetAlias",
"=",
"utf16PtrToString",
"(",
"cred",
".",
"TargetAlias",
")",
"\n",
"result",
".",
"UserName",
"=",
"utf16PtrToString",
"(",
"cred",
".",
"UserName",
")",
"\n",
"result",
".",
"LastWritten",
"=",
"time",
".",
"Unix",
"(",
"0",
",",
"cred",
".",
"LastWritten",
".",
"Nanoseconds",
"(",
")",
")",
"\n",
"result",
".",
"Persist",
"=",
"CredentialPersistence",
"(",
"cred",
".",
"Persist",
")",
"\n",
"result",
".",
"CredentialBlob",
"=",
"goBytes",
"(",
"cred",
".",
"CredentialBlob",
",",
"cred",
".",
"CredentialBlobSize",
")",
"\n",
"result",
".",
"Attributes",
"=",
"make",
"(",
"[",
"]",
"CredentialAttribute",
",",
"cred",
".",
"AttributeCount",
")",
"\n",
"attrSlice",
":=",
"*",
"(",
"*",
"[",
"]",
"sysCREDENTIAL_ATTRIBUTE",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"reflect",
".",
"SliceHeader",
"{",
"Data",
":",
"cred",
".",
"Attributes",
",",
"Len",
":",
"int",
"(",
"cred",
".",
"AttributeCount",
")",
",",
"Cap",
":",
"int",
"(",
"cred",
".",
"AttributeCount",
")",
",",
"}",
")",
")",
"\n",
"for",
"i",
",",
"attr",
":=",
"range",
"attrSlice",
"{",
"resultAttr",
":=",
"&",
"result",
".",
"Attributes",
"[",
"i",
"]",
"\n",
"resultAttr",
".",
"Keyword",
"=",
"utf16PtrToString",
"(",
"attr",
".",
"Keyword",
")",
"\n",
"resultAttr",
".",
"Value",
"=",
"goBytes",
"(",
"attr",
".",
"Value",
",",
"attr",
".",
"ValueSize",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // Convert the given CREDENTIAL struct to a more usable structure | [
"Convert",
"the",
"given",
"CREDENTIAL",
"struct",
"to",
"a",
"more",
"usable",
"structure"
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/conversion.go#L63-L87 |
15,321 | danieljoos/wincred | conversion.go | sysFromCredential | func sysFromCredential(cred *Credential) (result *sysCREDENTIAL) {
if cred == nil {
return nil
}
result = new(sysCREDENTIAL)
result.Flags = 0
result.Type = 0
result.TargetName, _ = syscall.UTF16PtrFromString(cred.TargetName)
result.Comment, _ = syscall.UTF16PtrFromString(cred.Comment)
result.LastWritten = syscall.NsecToFiletime(cred.LastWritten.UnixNano())
result.CredentialBlobSize = uint32(len(cred.CredentialBlob))
if len(cred.CredentialBlob) > 0 {
result.CredentialBlob = uintptr(unsafe.Pointer(&cred.CredentialBlob[0]))
} else {
result.CredentialBlob = 0
}
result.Persist = uint32(cred.Persist)
result.AttributeCount = uint32(len(cred.Attributes))
attributes := make([]sysCREDENTIAL_ATTRIBUTE, len(cred.Attributes))
if len(attributes) > 0 {
result.Attributes = uintptr(unsafe.Pointer(&attributes[0]))
} else {
result.Attributes = 0
}
for i := range cred.Attributes {
inAttr := &cred.Attributes[i]
outAttr := &attributes[i]
outAttr.Keyword, _ = syscall.UTF16PtrFromString(inAttr.Keyword)
outAttr.Flags = 0
outAttr.ValueSize = uint32(len(inAttr.Value))
if len(inAttr.Value) > 0 {
outAttr.Value = uintptr(unsafe.Pointer(&inAttr.Value[0]))
} else {
outAttr.Value = 0
}
}
result.TargetAlias, _ = syscall.UTF16PtrFromString(cred.TargetAlias)
result.UserName, _ = syscall.UTF16PtrFromString(cred.UserName)
return
} | go | func sysFromCredential(cred *Credential) (result *sysCREDENTIAL) {
if cred == nil {
return nil
}
result = new(sysCREDENTIAL)
result.Flags = 0
result.Type = 0
result.TargetName, _ = syscall.UTF16PtrFromString(cred.TargetName)
result.Comment, _ = syscall.UTF16PtrFromString(cred.Comment)
result.LastWritten = syscall.NsecToFiletime(cred.LastWritten.UnixNano())
result.CredentialBlobSize = uint32(len(cred.CredentialBlob))
if len(cred.CredentialBlob) > 0 {
result.CredentialBlob = uintptr(unsafe.Pointer(&cred.CredentialBlob[0]))
} else {
result.CredentialBlob = 0
}
result.Persist = uint32(cred.Persist)
result.AttributeCount = uint32(len(cred.Attributes))
attributes := make([]sysCREDENTIAL_ATTRIBUTE, len(cred.Attributes))
if len(attributes) > 0 {
result.Attributes = uintptr(unsafe.Pointer(&attributes[0]))
} else {
result.Attributes = 0
}
for i := range cred.Attributes {
inAttr := &cred.Attributes[i]
outAttr := &attributes[i]
outAttr.Keyword, _ = syscall.UTF16PtrFromString(inAttr.Keyword)
outAttr.Flags = 0
outAttr.ValueSize = uint32(len(inAttr.Value))
if len(inAttr.Value) > 0 {
outAttr.Value = uintptr(unsafe.Pointer(&inAttr.Value[0]))
} else {
outAttr.Value = 0
}
}
result.TargetAlias, _ = syscall.UTF16PtrFromString(cred.TargetAlias)
result.UserName, _ = syscall.UTF16PtrFromString(cred.UserName)
return
} | [
"func",
"sysFromCredential",
"(",
"cred",
"*",
"Credential",
")",
"(",
"result",
"*",
"sysCREDENTIAL",
")",
"{",
"if",
"cred",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"result",
"=",
"new",
"(",
"sysCREDENTIAL",
")",
"\n",
"result",
".",
"Flags",
"=",
"0",
"\n",
"result",
".",
"Type",
"=",
"0",
"\n",
"result",
".",
"TargetName",
",",
"_",
"=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"cred",
".",
"TargetName",
")",
"\n",
"result",
".",
"Comment",
",",
"_",
"=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"cred",
".",
"Comment",
")",
"\n",
"result",
".",
"LastWritten",
"=",
"syscall",
".",
"NsecToFiletime",
"(",
"cred",
".",
"LastWritten",
".",
"UnixNano",
"(",
")",
")",
"\n",
"result",
".",
"CredentialBlobSize",
"=",
"uint32",
"(",
"len",
"(",
"cred",
".",
"CredentialBlob",
")",
")",
"\n",
"if",
"len",
"(",
"cred",
".",
"CredentialBlob",
")",
">",
"0",
"{",
"result",
".",
"CredentialBlob",
"=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"cred",
".",
"CredentialBlob",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"else",
"{",
"result",
".",
"CredentialBlob",
"=",
"0",
"\n",
"}",
"\n",
"result",
".",
"Persist",
"=",
"uint32",
"(",
"cred",
".",
"Persist",
")",
"\n",
"result",
".",
"AttributeCount",
"=",
"uint32",
"(",
"len",
"(",
"cred",
".",
"Attributes",
")",
")",
"\n",
"attributes",
":=",
"make",
"(",
"[",
"]",
"sysCREDENTIAL_ATTRIBUTE",
",",
"len",
"(",
"cred",
".",
"Attributes",
")",
")",
"\n",
"if",
"len",
"(",
"attributes",
")",
">",
"0",
"{",
"result",
".",
"Attributes",
"=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"attributes",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"else",
"{",
"result",
".",
"Attributes",
"=",
"0",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"cred",
".",
"Attributes",
"{",
"inAttr",
":=",
"&",
"cred",
".",
"Attributes",
"[",
"i",
"]",
"\n",
"outAttr",
":=",
"&",
"attributes",
"[",
"i",
"]",
"\n",
"outAttr",
".",
"Keyword",
",",
"_",
"=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"inAttr",
".",
"Keyword",
")",
"\n",
"outAttr",
".",
"Flags",
"=",
"0",
"\n",
"outAttr",
".",
"ValueSize",
"=",
"uint32",
"(",
"len",
"(",
"inAttr",
".",
"Value",
")",
")",
"\n",
"if",
"len",
"(",
"inAttr",
".",
"Value",
")",
">",
"0",
"{",
"outAttr",
".",
"Value",
"=",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"inAttr",
".",
"Value",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"else",
"{",
"outAttr",
".",
"Value",
"=",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"result",
".",
"TargetAlias",
",",
"_",
"=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"cred",
".",
"TargetAlias",
")",
"\n",
"result",
".",
"UserName",
",",
"_",
"=",
"syscall",
".",
"UTF16PtrFromString",
"(",
"cred",
".",
"UserName",
")",
"\n\n",
"return",
"\n",
"}"
] | // Convert the given Credential object back to a CREDENTIAL struct, which can be used for calling the
// Windows APIs | [
"Convert",
"the",
"given",
"Credential",
"object",
"back",
"to",
"a",
"CREDENTIAL",
"struct",
"which",
"can",
"be",
"used",
"for",
"calling",
"the",
"Windows",
"APIs"
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/conversion.go#L91-L131 |
15,322 | danieljoos/wincred | wincred.go | GetGenericCredential | func GetGenericCredential(targetName string) (*GenericCredential, error) {
cred, err := sysCredRead(targetName, sysCRED_TYPE_GENERIC)
if cred != nil {
return &GenericCredential{*cred}, err
}
return nil, err
} | go | func GetGenericCredential(targetName string) (*GenericCredential, error) {
cred, err := sysCredRead(targetName, sysCRED_TYPE_GENERIC)
if cred != nil {
return &GenericCredential{*cred}, err
}
return nil, err
} | [
"func",
"GetGenericCredential",
"(",
"targetName",
"string",
")",
"(",
"*",
"GenericCredential",
",",
"error",
")",
"{",
"cred",
",",
"err",
":=",
"sysCredRead",
"(",
"targetName",
",",
"sysCRED_TYPE_GENERIC",
")",
"\n",
"if",
"cred",
"!=",
"nil",
"{",
"return",
"&",
"GenericCredential",
"{",
"*",
"cred",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}"
] | // GetGenericCredential fetches the generic credential with the given name from Windows credential manager.
// It returns nil and an error if the credential could not be found or an error occurred. | [
"GetGenericCredential",
"fetches",
"the",
"generic",
"credential",
"with",
"the",
"given",
"name",
"from",
"Windows",
"credential",
"manager",
".",
"It",
"returns",
"nil",
"and",
"an",
"error",
"if",
"the",
"credential",
"could",
"not",
"be",
"found",
"or",
"an",
"error",
"occurred",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L10-L16 |
15,323 | danieljoos/wincred | wincred.go | NewGenericCredential | func NewGenericCredential(targetName string) (result *GenericCredential) {
result = new(GenericCredential)
result.TargetName = targetName
result.Persist = PersistLocalMachine
return
} | go | func NewGenericCredential(targetName string) (result *GenericCredential) {
result = new(GenericCredential)
result.TargetName = targetName
result.Persist = PersistLocalMachine
return
} | [
"func",
"NewGenericCredential",
"(",
"targetName",
"string",
")",
"(",
"result",
"*",
"GenericCredential",
")",
"{",
"result",
"=",
"new",
"(",
"GenericCredential",
")",
"\n",
"result",
".",
"TargetName",
"=",
"targetName",
"\n",
"result",
".",
"Persist",
"=",
"PersistLocalMachine",
"\n",
"return",
"\n",
"}"
] | // NewGenericCredential creates a new generic credential object with the given name.
// The persist mode of the newly created object is set to a default value that indicates local-machine-wide storage.
// The credential object is NOT yet persisted to the Windows credential vault. | [
"NewGenericCredential",
"creates",
"a",
"new",
"generic",
"credential",
"object",
"with",
"the",
"given",
"name",
".",
"The",
"persist",
"mode",
"of",
"the",
"newly",
"created",
"object",
"is",
"set",
"to",
"a",
"default",
"value",
"that",
"indicates",
"local",
"-",
"machine",
"-",
"wide",
"storage",
".",
"The",
"credential",
"object",
"is",
"NOT",
"yet",
"persisted",
"to",
"the",
"Windows",
"credential",
"vault",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L21-L26 |
15,324 | danieljoos/wincred | wincred.go | Write | func (t *GenericCredential) Write() (err error) {
err = sysCredWrite(&t.Credential, sysCRED_TYPE_GENERIC)
return
} | go | func (t *GenericCredential) Write() (err error) {
err = sysCredWrite(&t.Credential, sysCRED_TYPE_GENERIC)
return
} | [
"func",
"(",
"t",
"*",
"GenericCredential",
")",
"Write",
"(",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"sysCredWrite",
"(",
"&",
"t",
".",
"Credential",
",",
"sysCRED_TYPE_GENERIC",
")",
"\n",
"return",
"\n",
"}"
] | // Write persists the generic credential object to Windows credential manager. | [
"Write",
"persists",
"the",
"generic",
"credential",
"object",
"to",
"Windows",
"credential",
"manager",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L29-L32 |
15,325 | danieljoos/wincred | wincred.go | Delete | func (t *GenericCredential) Delete() (err error) {
err = sysCredDelete(&t.Credential, sysCRED_TYPE_GENERIC)
return
} | go | func (t *GenericCredential) Delete() (err error) {
err = sysCredDelete(&t.Credential, sysCRED_TYPE_GENERIC)
return
} | [
"func",
"(",
"t",
"*",
"GenericCredential",
")",
"Delete",
"(",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"sysCredDelete",
"(",
"&",
"t",
".",
"Credential",
",",
"sysCRED_TYPE_GENERIC",
")",
"\n",
"return",
"\n",
"}"
] | // Delete removes the credential object from Windows credential manager. | [
"Delete",
"removes",
"the",
"credential",
"object",
"from",
"Windows",
"credential",
"manager",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L35-L38 |
15,326 | danieljoos/wincred | wincred.go | GetDomainPassword | func GetDomainPassword(targetName string) (*DomainPassword, error) {
cred, err := sysCredRead(targetName, sysCRED_TYPE_DOMAIN_PASSWORD)
if cred != nil {
return &DomainPassword{*cred}, err
}
return nil, err
} | go | func GetDomainPassword(targetName string) (*DomainPassword, error) {
cred, err := sysCredRead(targetName, sysCRED_TYPE_DOMAIN_PASSWORD)
if cred != nil {
return &DomainPassword{*cred}, err
}
return nil, err
} | [
"func",
"GetDomainPassword",
"(",
"targetName",
"string",
")",
"(",
"*",
"DomainPassword",
",",
"error",
")",
"{",
"cred",
",",
"err",
":=",
"sysCredRead",
"(",
"targetName",
",",
"sysCRED_TYPE_DOMAIN_PASSWORD",
")",
"\n",
"if",
"cred",
"!=",
"nil",
"{",
"return",
"&",
"DomainPassword",
"{",
"*",
"cred",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}"
] | // GetDomainPassword fetches the domain-password credential with the given target host name from Windows credential manager.
// It returns nil and an error if the credential could not be found or an error occurred. | [
"GetDomainPassword",
"fetches",
"the",
"domain",
"-",
"password",
"credential",
"with",
"the",
"given",
"target",
"host",
"name",
"from",
"Windows",
"credential",
"manager",
".",
"It",
"returns",
"nil",
"and",
"an",
"error",
"if",
"the",
"credential",
"could",
"not",
"be",
"found",
"or",
"an",
"error",
"occurred",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L42-L48 |
15,327 | danieljoos/wincred | wincred.go | NewDomainPassword | func NewDomainPassword(targetName string) (result *DomainPassword) {
result = new(DomainPassword)
result.TargetName = targetName
result.Persist = PersistLocalMachine
return
} | go | func NewDomainPassword(targetName string) (result *DomainPassword) {
result = new(DomainPassword)
result.TargetName = targetName
result.Persist = PersistLocalMachine
return
} | [
"func",
"NewDomainPassword",
"(",
"targetName",
"string",
")",
"(",
"result",
"*",
"DomainPassword",
")",
"{",
"result",
"=",
"new",
"(",
"DomainPassword",
")",
"\n",
"result",
".",
"TargetName",
"=",
"targetName",
"\n",
"result",
".",
"Persist",
"=",
"PersistLocalMachine",
"\n",
"return",
"\n",
"}"
] | // NewDomainPassword creates a new domain-password credential used for login to the given target host name.
// The persist mode of the newly created object is set to a default value that indicates local-machine-wide storage.
// The credential object is NOT yet persisted to the Windows credential vault. | [
"NewDomainPassword",
"creates",
"a",
"new",
"domain",
"-",
"password",
"credential",
"used",
"for",
"login",
"to",
"the",
"given",
"target",
"host",
"name",
".",
"The",
"persist",
"mode",
"of",
"the",
"newly",
"created",
"object",
"is",
"set",
"to",
"a",
"default",
"value",
"that",
"indicates",
"local",
"-",
"machine",
"-",
"wide",
"storage",
".",
"The",
"credential",
"object",
"is",
"NOT",
"yet",
"persisted",
"to",
"the",
"Windows",
"credential",
"vault",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L53-L58 |
15,328 | danieljoos/wincred | wincred.go | Write | func (t *DomainPassword) Write() (err error) {
err = sysCredWrite(&t.Credential, sysCRED_TYPE_DOMAIN_PASSWORD)
return
} | go | func (t *DomainPassword) Write() (err error) {
err = sysCredWrite(&t.Credential, sysCRED_TYPE_DOMAIN_PASSWORD)
return
} | [
"func",
"(",
"t",
"*",
"DomainPassword",
")",
"Write",
"(",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"sysCredWrite",
"(",
"&",
"t",
".",
"Credential",
",",
"sysCRED_TYPE_DOMAIN_PASSWORD",
")",
"\n",
"return",
"\n",
"}"
] | // Write persists the domain-password credential to Windows credential manager. | [
"Write",
"persists",
"the",
"domain",
"-",
"password",
"credential",
"to",
"Windows",
"credential",
"manager",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L61-L64 |
15,329 | danieljoos/wincred | wincred.go | Delete | func (t *DomainPassword) Delete() (err error) {
err = sysCredDelete(&t.Credential, sysCRED_TYPE_DOMAIN_PASSWORD)
return
} | go | func (t *DomainPassword) Delete() (err error) {
err = sysCredDelete(&t.Credential, sysCRED_TYPE_DOMAIN_PASSWORD)
return
} | [
"func",
"(",
"t",
"*",
"DomainPassword",
")",
"Delete",
"(",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"sysCredDelete",
"(",
"&",
"t",
".",
"Credential",
",",
"sysCRED_TYPE_DOMAIN_PASSWORD",
")",
"\n",
"return",
"\n",
"}"
] | // Delete removes the domain-password credential from Windows credential manager. | [
"Delete",
"removes",
"the",
"domain",
"-",
"password",
"credential",
"from",
"Windows",
"credential",
"manager",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L67-L70 |
15,330 | danieljoos/wincred | wincred.go | SetPassword | func (t *DomainPassword) SetPassword(pw string) {
t.CredentialBlob = utf16ToByte(utf16FromString(pw))
} | go | func (t *DomainPassword) SetPassword(pw string) {
t.CredentialBlob = utf16ToByte(utf16FromString(pw))
} | [
"func",
"(",
"t",
"*",
"DomainPassword",
")",
"SetPassword",
"(",
"pw",
"string",
")",
"{",
"t",
".",
"CredentialBlob",
"=",
"utf16ToByte",
"(",
"utf16FromString",
"(",
"pw",
")",
")",
"\n",
"}"
] | // SetPassword sets the CredentialBlob field of a domain password credential to the given string. | [
"SetPassword",
"sets",
"the",
"CredentialBlob",
"field",
"of",
"a",
"domain",
"password",
"credential",
"to",
"the",
"given",
"string",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L73-L75 |
15,331 | danieljoos/wincred | wincred.go | List | func List() ([]*Credential, error) {
creds, err := sysCredEnumerate("", true)
if err != nil && err.Error() == sysERROR_NOT_FOUND {
// Ignore ERROR_NOT_FOUND and return an empty list instead
creds = []*Credential{}
err = nil
}
return creds, err
} | go | func List() ([]*Credential, error) {
creds, err := sysCredEnumerate("", true)
if err != nil && err.Error() == sysERROR_NOT_FOUND {
// Ignore ERROR_NOT_FOUND and return an empty list instead
creds = []*Credential{}
err = nil
}
return creds, err
} | [
"func",
"List",
"(",
")",
"(",
"[",
"]",
"*",
"Credential",
",",
"error",
")",
"{",
"creds",
",",
"err",
":=",
"sysCredEnumerate",
"(",
"\"",
"\"",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
".",
"Error",
"(",
")",
"==",
"sysERROR_NOT_FOUND",
"{",
"// Ignore ERROR_NOT_FOUND and return an empty list instead",
"creds",
"=",
"[",
"]",
"*",
"Credential",
"{",
"}",
"\n",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"creds",
",",
"err",
"\n",
"}"
] | // List retrieves all credentials of the Credentials store. | [
"List",
"retrieves",
"all",
"credentials",
"of",
"the",
"Credentials",
"store",
"."
] | b892d337201d1400370ebf4fa919941c9ea222ee | https://github.com/danieljoos/wincred/blob/b892d337201d1400370ebf4fa919941c9ea222ee/wincred.go#L78-L86 |
15,332 | NebulousLabs/fastrand | fastrand.go | init | func init() {
r := &randReader{}
n, err := rand.Read(r.entropy[:])
if err != nil || n != len(r.entropy) {
panic("not enough entropy to fill fastrand reader at startup")
}
Reader = r
} | go | func init() {
r := &randReader{}
n, err := rand.Read(r.entropy[:])
if err != nil || n != len(r.entropy) {
panic("not enough entropy to fill fastrand reader at startup")
}
Reader = r
} | [
"func",
"init",
"(",
")",
"{",
"r",
":=",
"&",
"randReader",
"{",
"}",
"\n",
"n",
",",
"err",
":=",
"rand",
".",
"Read",
"(",
"r",
".",
"entropy",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"n",
"!=",
"len",
"(",
"r",
".",
"entropy",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"Reader",
"=",
"r",
"\n",
"}"
] | // init provides the initial entropy for the reader that will seed all numbers
// coming out of fastrand. | [
"init",
"provides",
"the",
"initial",
"entropy",
"for",
"the",
"reader",
"that",
"will",
"seed",
"all",
"numbers",
"coming",
"out",
"of",
"fastrand",
"."
] | 6fb6489aac4eae79e3f8112c21708191a7a90dd7 | https://github.com/NebulousLabs/fastrand/blob/6fb6489aac4eae79e3f8112c21708191a7a90dd7/fastrand.go#L42-L49 |
15,333 | NebulousLabs/fastrand | fastrand.go | Bytes | func Bytes(n int) []byte {
b := make([]byte, n)
Read(b)
return b
} | go | func Bytes(n int) []byte {
b := make([]byte, n)
Read(b)
return b
} | [
"func",
"Bytes",
"(",
"n",
"int",
")",
"[",
"]",
"byte",
"{",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"Read",
"(",
"b",
")",
"\n",
"return",
"b",
"\n",
"}"
] | // Bytes is a helper function that returns n bytes of random data. | [
"Bytes",
"is",
"a",
"helper",
"function",
"that",
"returns",
"n",
"bytes",
"of",
"random",
"data",
"."
] | 6fb6489aac4eae79e3f8112c21708191a7a90dd7 | https://github.com/NebulousLabs/fastrand/blob/6fb6489aac4eae79e3f8112c21708191a7a90dd7/fastrand.go#L122-L126 |
15,334 | NebulousLabs/fastrand | fastrand.go | Uint64n | func Uint64n(n uint64) uint64 {
if n == 0 {
panic("fastrand: argument to Uint64n is 0")
}
// To eliminate modulo bias, keep selecting at random until we fall within
// a range that is evenly divisible by n.
// NOTE: since n is at most math.MaxUint64, max is minimized when:
// n = math.MaxUint64/2 + 1 -> max = math.MaxUint64 - math.MaxUint64/2
// This gives an expected 2 tries before choosing a value < max.
max := math.MaxUint64 - math.MaxUint64%n
b := Bytes(8)
r := *(*uint64)(unsafe.Pointer(&b[0]))
for r >= max {
Read(b)
r = *(*uint64)(unsafe.Pointer(&b[0]))
}
return r % n
} | go | func Uint64n(n uint64) uint64 {
if n == 0 {
panic("fastrand: argument to Uint64n is 0")
}
// To eliminate modulo bias, keep selecting at random until we fall within
// a range that is evenly divisible by n.
// NOTE: since n is at most math.MaxUint64, max is minimized when:
// n = math.MaxUint64/2 + 1 -> max = math.MaxUint64 - math.MaxUint64/2
// This gives an expected 2 tries before choosing a value < max.
max := math.MaxUint64 - math.MaxUint64%n
b := Bytes(8)
r := *(*uint64)(unsafe.Pointer(&b[0]))
for r >= max {
Read(b)
r = *(*uint64)(unsafe.Pointer(&b[0]))
}
return r % n
} | [
"func",
"Uint64n",
"(",
"n",
"uint64",
")",
"uint64",
"{",
"if",
"n",
"==",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// To eliminate modulo bias, keep selecting at random until we fall within",
"// a range that is evenly divisible by n.",
"// NOTE: since n is at most math.MaxUint64, max is minimized when:",
"// n = math.MaxUint64/2 + 1 -> max = math.MaxUint64 - math.MaxUint64/2",
"// This gives an expected 2 tries before choosing a value < max.",
"max",
":=",
"math",
".",
"MaxUint64",
"-",
"math",
".",
"MaxUint64",
"%",
"n",
"\n",
"b",
":=",
"Bytes",
"(",
"8",
")",
"\n",
"r",
":=",
"*",
"(",
"*",
"uint64",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"b",
"[",
"0",
"]",
")",
")",
"\n",
"for",
"r",
">=",
"max",
"{",
"Read",
"(",
"b",
")",
"\n",
"r",
"=",
"*",
"(",
"*",
"uint64",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"b",
"[",
"0",
"]",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"%",
"n",
"\n",
"}"
] | // Uint64n returns a uniform random uint64 in [0,n). It panics if n == 0. | [
"Uint64n",
"returns",
"a",
"uniform",
"random",
"uint64",
"in",
"[",
"0",
"n",
")",
".",
"It",
"panics",
"if",
"n",
"==",
"0",
"."
] | 6fb6489aac4eae79e3f8112c21708191a7a90dd7 | https://github.com/NebulousLabs/fastrand/blob/6fb6489aac4eae79e3f8112c21708191a7a90dd7/fastrand.go#L129-L146 |
15,335 | NebulousLabs/fastrand | fastrand.go | Intn | func Intn(n int) int {
if n <= 0 {
panic("fastrand: argument to Intn is <= 0: " + strconv.Itoa(n))
}
// NOTE: since n is at most math.MaxUint64/2, max is minimized when:
// n = math.MaxUint64/4 + 1 -> max = math.MaxUint64 - math.MaxUint64/4
// This gives an expected 1.333 tries before choosing a value < max.
return int(Uint64n(uint64(n)))
} | go | func Intn(n int) int {
if n <= 0 {
panic("fastrand: argument to Intn is <= 0: " + strconv.Itoa(n))
}
// NOTE: since n is at most math.MaxUint64/2, max is minimized when:
// n = math.MaxUint64/4 + 1 -> max = math.MaxUint64 - math.MaxUint64/4
// This gives an expected 1.333 tries before choosing a value < max.
return int(Uint64n(uint64(n)))
} | [
"func",
"Intn",
"(",
"n",
"int",
")",
"int",
"{",
"if",
"n",
"<=",
"0",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"n",
")",
")",
"\n",
"}",
"\n",
"// NOTE: since n is at most math.MaxUint64/2, max is minimized when:",
"// n = math.MaxUint64/4 + 1 -> max = math.MaxUint64 - math.MaxUint64/4",
"// This gives an expected 1.333 tries before choosing a value < max.",
"return",
"int",
"(",
"Uint64n",
"(",
"uint64",
"(",
"n",
")",
")",
")",
"\n",
"}"
] | // Intn returns a uniform random int in [0,n). It panics if n <= 0. | [
"Intn",
"returns",
"a",
"uniform",
"random",
"int",
"in",
"[",
"0",
"n",
")",
".",
"It",
"panics",
"if",
"n",
"<",
"=",
"0",
"."
] | 6fb6489aac4eae79e3f8112c21708191a7a90dd7 | https://github.com/NebulousLabs/fastrand/blob/6fb6489aac4eae79e3f8112c21708191a7a90dd7/fastrand.go#L149-L157 |
15,336 | Lazin/go-ngram | ngram.go | SetPad | func SetPad(c rune) Option {
return func(ngram *NGramIndex) error {
ngram.pad = string(c)
return nil
}
} | go | func SetPad(c rune) Option {
return func(ngram *NGramIndex) error {
ngram.pad = string(c)
return nil
}
} | [
"func",
"SetPad",
"(",
"c",
"rune",
")",
"Option",
"{",
"return",
"func",
"(",
"ngram",
"*",
"NGramIndex",
")",
"error",
"{",
"ngram",
".",
"pad",
"=",
"string",
"(",
"c",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetPad must be used to pass padding character to NGramIndex c-tor | [
"SetPad",
"must",
"be",
"used",
"to",
"pass",
"padding",
"character",
"to",
"NGramIndex",
"c",
"-",
"tor"
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/ngram.go#L92-L97 |
15,337 | Lazin/go-ngram | ngram.go | SetWarp | func SetWarp(warp float64) Option {
return func(ngram *NGramIndex) error {
if warp < 0.0 || warp > 1.0 {
return errors.New("bad 'warp' value for n-gram index")
}
ngram.warp = warp
return nil
}
} | go | func SetWarp(warp float64) Option {
return func(ngram *NGramIndex) error {
if warp < 0.0 || warp > 1.0 {
return errors.New("bad 'warp' value for n-gram index")
}
ngram.warp = warp
return nil
}
} | [
"func",
"SetWarp",
"(",
"warp",
"float64",
")",
"Option",
"{",
"return",
"func",
"(",
"ngram",
"*",
"NGramIndex",
")",
"error",
"{",
"if",
"warp",
"<",
"0.0",
"||",
"warp",
">",
"1.0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ngram",
".",
"warp",
"=",
"warp",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetWarp must be used to pass warp to NGramIndex c-tor | [
"SetWarp",
"must",
"be",
"used",
"to",
"pass",
"warp",
"to",
"NGramIndex",
"c",
"-",
"tor"
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/ngram.go#L111-L119 |
15,338 | Lazin/go-ngram | ngram.go | NewNGramIndex | func NewNGramIndex(opts ...Option) (*NGramIndex, error) {
ngram := new(NGramIndex)
for _, opt := range opts {
if err := opt(ngram); err != nil {
return nil, err
}
}
ngram.init()
return ngram, nil
} | go | func NewNGramIndex(opts ...Option) (*NGramIndex, error) {
ngram := new(NGramIndex)
for _, opt := range opts {
if err := opt(ngram); err != nil {
return nil, err
}
}
ngram.init()
return ngram, nil
} | [
"func",
"NewNGramIndex",
"(",
"opts",
"...",
"Option",
")",
"(",
"*",
"NGramIndex",
",",
"error",
")",
"{",
"ngram",
":=",
"new",
"(",
"NGramIndex",
")",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"if",
"err",
":=",
"opt",
"(",
"ngram",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"ngram",
".",
"init",
"(",
")",
"\n",
"return",
"ngram",
",",
"nil",
"\n",
"}"
] | // NewNGramIndex is N-gram index c-tor. In most cases must be used withot parameters.
// You can pass parameters to c-tor using functions SetPad, SetWarp and SetN. | [
"NewNGramIndex",
"is",
"N",
"-",
"gram",
"index",
"c",
"-",
"tor",
".",
"In",
"most",
"cases",
"must",
"be",
"used",
"withot",
"parameters",
".",
"You",
"can",
"pass",
"parameters",
"to",
"c",
"-",
"tor",
"using",
"functions",
"SetPad",
"SetWarp",
"and",
"SetN",
"."
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/ngram.go#L123-L132 |
15,339 | Lazin/go-ngram | ngram.go | Add | func (ngram *NGramIndex) Add(input string) (TokenID, error) {
if ngram.index == nil {
ngram.init()
}
results, error := ngram.splitInput(input)
if error != nil {
return -1, error
}
ixstr, error := ngram.spool.Append(input)
if error != nil {
return -1, error
}
for _, hash := range results {
ngram.Lock()
if ngram.index[hash] == nil {
ngram.index[hash] = make(map[TokenID]int)
}
// insert string and counter
ngram.index[hash][ixstr]++
ngram.Unlock()
}
return ixstr, nil
} | go | func (ngram *NGramIndex) Add(input string) (TokenID, error) {
if ngram.index == nil {
ngram.init()
}
results, error := ngram.splitInput(input)
if error != nil {
return -1, error
}
ixstr, error := ngram.spool.Append(input)
if error != nil {
return -1, error
}
for _, hash := range results {
ngram.Lock()
if ngram.index[hash] == nil {
ngram.index[hash] = make(map[TokenID]int)
}
// insert string and counter
ngram.index[hash][ixstr]++
ngram.Unlock()
}
return ixstr, nil
} | [
"func",
"(",
"ngram",
"*",
"NGramIndex",
")",
"Add",
"(",
"input",
"string",
")",
"(",
"TokenID",
",",
"error",
")",
"{",
"if",
"ngram",
".",
"index",
"==",
"nil",
"{",
"ngram",
".",
"init",
"(",
")",
"\n",
"}",
"\n",
"results",
",",
"error",
":=",
"ngram",
".",
"splitInput",
"(",
"input",
")",
"\n",
"if",
"error",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"error",
"\n",
"}",
"\n",
"ixstr",
",",
"error",
":=",
"ngram",
".",
"spool",
".",
"Append",
"(",
"input",
")",
"\n",
"if",
"error",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"error",
"\n",
"}",
"\n",
"for",
"_",
",",
"hash",
":=",
"range",
"results",
"{",
"ngram",
".",
"Lock",
"(",
")",
"\n",
"if",
"ngram",
".",
"index",
"[",
"hash",
"]",
"==",
"nil",
"{",
"ngram",
".",
"index",
"[",
"hash",
"]",
"=",
"make",
"(",
"map",
"[",
"TokenID",
"]",
"int",
")",
"\n",
"}",
"\n",
"// insert string and counter",
"ngram",
".",
"index",
"[",
"hash",
"]",
"[",
"ixstr",
"]",
"++",
"\n",
"ngram",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"ixstr",
",",
"nil",
"\n",
"}"
] | // Add token to index. Function returns token id, this id can be converted
// to string with function "GetString". | [
"Add",
"token",
"to",
"index",
".",
"Function",
"returns",
"token",
"id",
"this",
"id",
"can",
"be",
"converted",
"to",
"string",
"with",
"function",
"GetString",
"."
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/ngram.go#L136-L158 |
15,340 | Lazin/go-ngram | ngram.go | GetString | func (ngram *NGramIndex) GetString(id TokenID) (string, error) {
return ngram.spool.ReadAt(id)
} | go | func (ngram *NGramIndex) GetString(id TokenID) (string, error) {
return ngram.spool.ReadAt(id)
} | [
"func",
"(",
"ngram",
"*",
"NGramIndex",
")",
"GetString",
"(",
"id",
"TokenID",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"ngram",
".",
"spool",
".",
"ReadAt",
"(",
"id",
")",
"\n",
"}"
] | // GetString converts token-id to string. | [
"GetString",
"converts",
"token",
"-",
"id",
"to",
"string",
"."
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/ngram.go#L161-L163 |
15,341 | Lazin/go-ngram | ngram.go | countNgrams | func (ngram *NGramIndex) countNgrams(inputNgrams []uint32) map[TokenID]int {
counters := make(map[TokenID]int)
for _, ngramHash := range inputNgrams {
ngram.RLock()
for tok := range ngram.index[ngramHash] {
counters[tok]++
}
ngram.RUnlock()
}
return counters
} | go | func (ngram *NGramIndex) countNgrams(inputNgrams []uint32) map[TokenID]int {
counters := make(map[TokenID]int)
for _, ngramHash := range inputNgrams {
ngram.RLock()
for tok := range ngram.index[ngramHash] {
counters[tok]++
}
ngram.RUnlock()
}
return counters
} | [
"func",
"(",
"ngram",
"*",
"NGramIndex",
")",
"countNgrams",
"(",
"inputNgrams",
"[",
"]",
"uint32",
")",
"map",
"[",
"TokenID",
"]",
"int",
"{",
"counters",
":=",
"make",
"(",
"map",
"[",
"TokenID",
"]",
"int",
")",
"\n",
"for",
"_",
",",
"ngramHash",
":=",
"range",
"inputNgrams",
"{",
"ngram",
".",
"RLock",
"(",
")",
"\n",
"for",
"tok",
":=",
"range",
"ngram",
".",
"index",
"[",
"ngramHash",
"]",
"{",
"counters",
"[",
"tok",
"]",
"++",
"\n",
"}",
"\n",
"ngram",
".",
"RUnlock",
"(",
")",
"\n",
"}",
"\n",
"return",
"counters",
"\n",
"}"
] | // countNgrams maps matched tokens to the number of ngrams, shared with input string | [
"countNgrams",
"maps",
"matched",
"tokens",
"to",
"the",
"number",
"of",
"ngrams",
"shared",
"with",
"input",
"string"
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/ngram.go#L166-L176 |
15,342 | Lazin/go-ngram | ngram.go | BestMatch | func (ngram *NGramIndex) BestMatch(input string, threshold ...float64) (*SearchResult, error) {
if ngram.index == nil {
ngram.init()
}
tval, error := validateThresholdValues(threshold)
if error != nil {
return nil, error
}
variants, error := ngram.match(input, tval)
if error != nil {
return nil, error
}
if len(variants) == 0 {
return nil, errors.New("no matches found")
}
var result SearchResult
maxsim := -1.0
for _, val := range variants {
if val.Similarity > maxsim {
maxsim = val.Similarity
result = val
}
}
return &result, nil
} | go | func (ngram *NGramIndex) BestMatch(input string, threshold ...float64) (*SearchResult, error) {
if ngram.index == nil {
ngram.init()
}
tval, error := validateThresholdValues(threshold)
if error != nil {
return nil, error
}
variants, error := ngram.match(input, tval)
if error != nil {
return nil, error
}
if len(variants) == 0 {
return nil, errors.New("no matches found")
}
var result SearchResult
maxsim := -1.0
for _, val := range variants {
if val.Similarity > maxsim {
maxsim = val.Similarity
result = val
}
}
return &result, nil
} | [
"func",
"(",
"ngram",
"*",
"NGramIndex",
")",
"BestMatch",
"(",
"input",
"string",
",",
"threshold",
"...",
"float64",
")",
"(",
"*",
"SearchResult",
",",
"error",
")",
"{",
"if",
"ngram",
".",
"index",
"==",
"nil",
"{",
"ngram",
".",
"init",
"(",
")",
"\n",
"}",
"\n",
"tval",
",",
"error",
":=",
"validateThresholdValues",
"(",
"threshold",
")",
"\n",
"if",
"error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"error",
"\n",
"}",
"\n",
"variants",
",",
"error",
":=",
"ngram",
".",
"match",
"(",
"input",
",",
"tval",
")",
"\n",
"if",
"error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"error",
"\n",
"}",
"\n",
"if",
"len",
"(",
"variants",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"result",
"SearchResult",
"\n",
"maxsim",
":=",
"-",
"1.0",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"variants",
"{",
"if",
"val",
".",
"Similarity",
">",
"maxsim",
"{",
"maxsim",
"=",
"val",
".",
"Similarity",
"\n",
"result",
"=",
"val",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"result",
",",
"nil",
"\n",
"}"
] | // BestMatch is the same as Search except that it's returning only one best result instead of all. | [
"BestMatch",
"is",
"the",
"same",
"as",
"Search",
"except",
"that",
"it",
"s",
"returning",
"only",
"one",
"best",
"result",
"instead",
"of",
"all",
"."
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/ngram.go#L234-L258 |
15,343 | Lazin/go-ngram | spool.go | Append | func (pool *stringPool) Append(s string) (TokenID, error) {
begin := pool.buffer.Len()
bstr := []byte(s)
bstr = smaz.Compress(bstr)
n, error := pool.buffer.Write(bstr)
if error != nil {
return 0, error
}
end := begin + n
pool.Lock()
ixitem := TokenID(len(pool.items))
pool.items = append(pool.items, region{begin: begin, end: end})
pool.Unlock()
return ixitem, nil
} | go | func (pool *stringPool) Append(s string) (TokenID, error) {
begin := pool.buffer.Len()
bstr := []byte(s)
bstr = smaz.Compress(bstr)
n, error := pool.buffer.Write(bstr)
if error != nil {
return 0, error
}
end := begin + n
pool.Lock()
ixitem := TokenID(len(pool.items))
pool.items = append(pool.items, region{begin: begin, end: end})
pool.Unlock()
return ixitem, nil
} | [
"func",
"(",
"pool",
"*",
"stringPool",
")",
"Append",
"(",
"s",
"string",
")",
"(",
"TokenID",
",",
"error",
")",
"{",
"begin",
":=",
"pool",
".",
"buffer",
".",
"Len",
"(",
")",
"\n",
"bstr",
":=",
"[",
"]",
"byte",
"(",
"s",
")",
"\n",
"bstr",
"=",
"smaz",
".",
"Compress",
"(",
"bstr",
")",
"\n",
"n",
",",
"error",
":=",
"pool",
".",
"buffer",
".",
"Write",
"(",
"bstr",
")",
"\n",
"if",
"error",
"!=",
"nil",
"{",
"return",
"0",
",",
"error",
"\n",
"}",
"\n",
"end",
":=",
"begin",
"+",
"n",
"\n",
"pool",
".",
"Lock",
"(",
")",
"\n",
"ixitem",
":=",
"TokenID",
"(",
"len",
"(",
"pool",
".",
"items",
")",
")",
"\n",
"pool",
".",
"items",
"=",
"append",
"(",
"pool",
".",
"items",
",",
"region",
"{",
"begin",
":",
"begin",
",",
"end",
":",
"end",
"}",
")",
"\n",
"pool",
".",
"Unlock",
"(",
")",
"\n",
"return",
"ixitem",
",",
"nil",
"\n",
"}"
] | // Append adds new string to string pool. Function returns token ID and error.
// Strings doesn't need to be unique | [
"Append",
"adds",
"new",
"string",
"to",
"string",
"pool",
".",
"Function",
"returns",
"token",
"ID",
"and",
"error",
".",
"Strings",
"doesn",
"t",
"need",
"to",
"be",
"unique"
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/spool.go#L26-L40 |
15,344 | Lazin/go-ngram | spool.go | ReadAt | func (pool *stringPool) ReadAt(index TokenID) (string, error) {
if index < TokenID(0) || index >= TokenID(len(pool.items)) {
return "", errors.New("index out of range")
}
pool.RLock()
item := pool.items[int(index)]
pool.RUnlock()
compressed := pool.buffer.Bytes()[item.begin:item.end]
decompressed, error := smaz.Decompress(compressed)
if error != nil {
return "", error
}
return string(decompressed), nil
} | go | func (pool *stringPool) ReadAt(index TokenID) (string, error) {
if index < TokenID(0) || index >= TokenID(len(pool.items)) {
return "", errors.New("index out of range")
}
pool.RLock()
item := pool.items[int(index)]
pool.RUnlock()
compressed := pool.buffer.Bytes()[item.begin:item.end]
decompressed, error := smaz.Decompress(compressed)
if error != nil {
return "", error
}
return string(decompressed), nil
} | [
"func",
"(",
"pool",
"*",
"stringPool",
")",
"ReadAt",
"(",
"index",
"TokenID",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"index",
"<",
"TokenID",
"(",
"0",
")",
"||",
"index",
">=",
"TokenID",
"(",
"len",
"(",
"pool",
".",
"items",
")",
")",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"pool",
".",
"RLock",
"(",
")",
"\n",
"item",
":=",
"pool",
".",
"items",
"[",
"int",
"(",
"index",
")",
"]",
"\n",
"pool",
".",
"RUnlock",
"(",
")",
"\n",
"compressed",
":=",
"pool",
".",
"buffer",
".",
"Bytes",
"(",
")",
"[",
"item",
".",
"begin",
":",
"item",
".",
"end",
"]",
"\n",
"decompressed",
",",
"error",
":=",
"smaz",
".",
"Decompress",
"(",
"compressed",
")",
"\n",
"if",
"error",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"error",
"\n",
"}",
"\n",
"return",
"string",
"(",
"decompressed",
")",
",",
"nil",
"\n",
"}"
] | // ReadAt converts token ID back to string. | [
"ReadAt",
"converts",
"token",
"ID",
"back",
"to",
"string",
"."
] | 80eaf16ac4ebcf4343074241ac31fc9e99824503 | https://github.com/Lazin/go-ngram/blob/80eaf16ac4ebcf4343074241ac31fc9e99824503/spool.go#L43-L56 |
15,345 | vmware/goipmi | asf.go | response | func (m *asfMessage) response(data interface{}) error {
return binary.Read(bytes.NewBuffer(m.Data), binary.BigEndian, data)
} | go | func (m *asfMessage) response(data interface{}) error {
return binary.Read(bytes.NewBuffer(m.Data), binary.BigEndian, data)
} | [
"func",
"(",
"m",
"*",
"asfMessage",
")",
"response",
"(",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"binary",
".",
"Read",
"(",
"bytes",
".",
"NewBuffer",
"(",
"m",
".",
"Data",
")",
",",
"binary",
".",
"BigEndian",
",",
"data",
")",
"\n",
"}"
] | // Response specific to the request ASF command | [
"Response",
"specific",
"to",
"the",
"request",
"ASF",
"command"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/asf.go#L102-L104 |
15,346 | vmware/goipmi | lan.go | authMD5 | func (l *lan) authMD5(data []uint8) []uint8 {
h := md5.New()
binaryWrite(h, l.authcode)
binaryWrite(h, l.SessionID)
binaryWrite(h, data)
binaryWrite(h, l.Sequence)
binaryWrite(h, l.authcode)
return h.Sum(nil)
} | go | func (l *lan) authMD5(data []uint8) []uint8 {
h := md5.New()
binaryWrite(h, l.authcode)
binaryWrite(h, l.SessionID)
binaryWrite(h, data)
binaryWrite(h, l.Sequence)
binaryWrite(h, l.authcode)
return h.Sum(nil)
} | [
"func",
"(",
"l",
"*",
"lan",
")",
"authMD5",
"(",
"data",
"[",
"]",
"uint8",
")",
"[",
"]",
"uint8",
"{",
"h",
":=",
"md5",
".",
"New",
"(",
")",
"\n\n",
"binaryWrite",
"(",
"h",
",",
"l",
".",
"authcode",
")",
"\n",
"binaryWrite",
"(",
"h",
",",
"l",
".",
"SessionID",
")",
"\n",
"binaryWrite",
"(",
"h",
",",
"data",
")",
"\n",
"binaryWrite",
"(",
"h",
",",
"l",
".",
"Sequence",
")",
"\n",
"binaryWrite",
"(",
"h",
",",
"l",
".",
"authcode",
")",
"\n\n",
"return",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n",
"}"
] | // per section 22.17.1 | [
"per",
"section",
"22",
".",
"17",
".",
"1"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/lan.go#L203-L213 |
15,347 | vmware/goipmi | message.go | Request | func (m *Message) Request(data interface{}) Response {
err := messageDataFromBytes(m.Data, data)
if err != nil {
if e, ok := err.(CompletionCode); ok {
return e
}
return ErrUnspecified
}
return nil
} | go | func (m *Message) Request(data interface{}) Response {
err := messageDataFromBytes(m.Data, data)
if err != nil {
if e, ok := err.(CompletionCode); ok {
return e
}
return ErrUnspecified
}
return nil
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"Request",
"(",
"data",
"interface",
"{",
"}",
")",
"Response",
"{",
"err",
":=",
"messageDataFromBytes",
"(",
"m",
".",
"Data",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"CompletionCode",
")",
";",
"ok",
"{",
"return",
"e",
"\n",
"}",
"\n",
"return",
"ErrUnspecified",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Request specific to the request IPMI command
// Unmarshal errors are returned as a Response such that they can be
// propagated to the client. | [
"Request",
"specific",
"to",
"the",
"request",
"IPMI",
"command",
"Unmarshal",
"errors",
"are",
"returned",
"as",
"a",
"Response",
"such",
"that",
"they",
"can",
"be",
"propagated",
"to",
"the",
"client",
"."
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/message.go#L81-L90 |
15,348 | vmware/goipmi | message.go | Response | func (m *Message) Response(data Response) error {
if m.CompletionCode() != CommandCompleted {
return m.CompletionCode()
}
return messageDataFromBytes(m.Data, data)
} | go | func (m *Message) Response(data Response) error {
if m.CompletionCode() != CommandCompleted {
return m.CompletionCode()
}
return messageDataFromBytes(m.Data, data)
} | [
"func",
"(",
"m",
"*",
"Message",
")",
"Response",
"(",
"data",
"Response",
")",
"error",
"{",
"if",
"m",
".",
"CompletionCode",
"(",
")",
"!=",
"CommandCompleted",
"{",
"return",
"m",
".",
"CompletionCode",
"(",
")",
"\n",
"}",
"\n",
"return",
"messageDataFromBytes",
"(",
"m",
".",
"Data",
",",
"data",
")",
"\n",
"}"
] | // Response specific to the request IPMI command | [
"Response",
"specific",
"to",
"the",
"request",
"IPMI",
"command"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/message.go#L93-L98 |
15,349 | vmware/goipmi | client.go | NewClient | func NewClient(c *Connection) (*Client, error) {
t, err := newTransport(c)
if err != nil {
return nil, err
}
return &Client{
Connection: c,
transport: t,
}, nil
} | go | func NewClient(c *Connection) (*Client, error) {
t, err := newTransport(c)
if err != nil {
return nil, err
}
return &Client{
Connection: c,
transport: t,
}, nil
} | [
"func",
"NewClient",
"(",
"c",
"*",
"Connection",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"t",
",",
"err",
":=",
"newTransport",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Client",
"{",
"Connection",
":",
"c",
",",
"transport",
":",
"t",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewClient creates a new Client with the given Connection properties | [
"NewClient",
"creates",
"a",
"new",
"Client",
"with",
"the",
"given",
"Connection",
"properties"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/client.go#L26-L35 |
15,350 | vmware/goipmi | client.go | Send | func (c *Client) Send(req *Request, res Response) error {
// TODO: handle retry, timeouts, etc.
return c.send(req, res)
} | go | func (c *Client) Send(req *Request, res Response) error {
// TODO: handle retry, timeouts, etc.
return c.send(req, res)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Send",
"(",
"req",
"*",
"Request",
",",
"res",
"Response",
")",
"error",
"{",
"// TODO: handle retry, timeouts, etc.",
"return",
"c",
".",
"send",
"(",
"req",
",",
"res",
")",
"\n",
"}"
] | // Send a Request and unmarshal to given Response type | [
"Send",
"a",
"Request",
"and",
"unmarshal",
"to",
"given",
"Response",
"type"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/client.go#L49-L52 |
15,351 | vmware/goipmi | client.go | DeviceID | func (c *Client) DeviceID() (*DeviceIDResponse, error) {
req := &Request{
NetworkFunctionApp,
CommandGetDeviceID,
&DeviceIDRequest{},
}
res := &DeviceIDResponse{}
return res, c.Send(req, res)
} | go | func (c *Client) DeviceID() (*DeviceIDResponse, error) {
req := &Request{
NetworkFunctionApp,
CommandGetDeviceID,
&DeviceIDRequest{},
}
res := &DeviceIDResponse{}
return res, c.Send(req, res)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeviceID",
"(",
")",
"(",
"*",
"DeviceIDResponse",
",",
"error",
")",
"{",
"req",
":=",
"&",
"Request",
"{",
"NetworkFunctionApp",
",",
"CommandGetDeviceID",
",",
"&",
"DeviceIDRequest",
"{",
"}",
",",
"}",
"\n",
"res",
":=",
"&",
"DeviceIDResponse",
"{",
"}",
"\n",
"return",
"res",
",",
"c",
".",
"Send",
"(",
"req",
",",
"res",
")",
"\n",
"}"
] | // DeviceID get the Device ID of the BMC | [
"DeviceID",
"get",
"the",
"Device",
"ID",
"of",
"the",
"BMC"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/client.go#L55-L63 |
15,352 | vmware/goipmi | client.go | SetBootDevice | func (c *Client) SetBootDevice(dev BootDevice) error {
useProgress := true
// set set-in-progress flag
err := c.setBootParam(BootParamSetInProgress, 0x01)
if err != nil {
useProgress = false
}
err = c.setBootParam(BootParamInfoAck, 0x01, 0x01)
if err != nil {
if useProgress {
// set-in-progress = set-complete
_ = c.setBootParam(BootParamSetInProgress, 0x00)
}
return err
}
err = c.setBootParam(BootParamBootFlags, 0x80, uint8(dev), 0x00, 0x00, 0x00)
if err == nil {
if useProgress {
// set-in-progress = commit-write
_ = c.setBootParam(BootParamSetInProgress, 0x02)
}
}
if useProgress {
// set-in-progress = set-complete
_ = c.setBootParam(BootParamSetInProgress, 0x00)
}
return err
} | go | func (c *Client) SetBootDevice(dev BootDevice) error {
useProgress := true
// set set-in-progress flag
err := c.setBootParam(BootParamSetInProgress, 0x01)
if err != nil {
useProgress = false
}
err = c.setBootParam(BootParamInfoAck, 0x01, 0x01)
if err != nil {
if useProgress {
// set-in-progress = set-complete
_ = c.setBootParam(BootParamSetInProgress, 0x00)
}
return err
}
err = c.setBootParam(BootParamBootFlags, 0x80, uint8(dev), 0x00, 0x00, 0x00)
if err == nil {
if useProgress {
// set-in-progress = commit-write
_ = c.setBootParam(BootParamSetInProgress, 0x02)
}
}
if useProgress {
// set-in-progress = set-complete
_ = c.setBootParam(BootParamSetInProgress, 0x00)
}
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetBootDevice",
"(",
"dev",
"BootDevice",
")",
"error",
"{",
"useProgress",
":=",
"true",
"\n",
"// set set-in-progress flag",
"err",
":=",
"c",
".",
"setBootParam",
"(",
"BootParamSetInProgress",
",",
"0x01",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"useProgress",
"=",
"false",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"setBootParam",
"(",
"BootParamInfoAck",
",",
"0x01",
",",
"0x01",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"useProgress",
"{",
"// set-in-progress = set-complete",
"_",
"=",
"c",
".",
"setBootParam",
"(",
"BootParamSetInProgress",
",",
"0x00",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"c",
".",
"setBootParam",
"(",
"BootParamBootFlags",
",",
"0x80",
",",
"uint8",
"(",
"dev",
")",
",",
"0x00",
",",
"0x00",
",",
"0x00",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"useProgress",
"{",
"// set-in-progress = commit-write",
"_",
"=",
"c",
".",
"setBootParam",
"(",
"BootParamSetInProgress",
",",
"0x02",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"useProgress",
"{",
"// set-in-progress = set-complete",
"_",
"=",
"c",
".",
"setBootParam",
"(",
"BootParamSetInProgress",
",",
"0x00",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // SetBootDevice is a wrapper around SetSystemBootOptionsRequest to configure the BootDevice
// per section 28.12 - table 28 | [
"SetBootDevice",
"is",
"a",
"wrapper",
"around",
"SetSystemBootOptionsRequest",
"to",
"configure",
"the",
"BootDevice",
"per",
"section",
"28",
".",
"12",
"-",
"table",
"28"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/client.go#L79-L110 |
15,353 | vmware/goipmi | client.go | Control | func (c *Client) Control(ctl ChassisControl) error {
r := &Request{
NetworkFunctionChassis,
CommandChassisControl,
&ChassisControlRequest{ctl},
}
return c.Send(r, &ChassisControlResponse{})
} | go | func (c *Client) Control(ctl ChassisControl) error {
r := &Request{
NetworkFunctionChassis,
CommandChassisControl,
&ChassisControlRequest{ctl},
}
return c.Send(r, &ChassisControlResponse{})
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Control",
"(",
"ctl",
"ChassisControl",
")",
"error",
"{",
"r",
":=",
"&",
"Request",
"{",
"NetworkFunctionChassis",
",",
"CommandChassisControl",
",",
"&",
"ChassisControlRequest",
"{",
"ctl",
"}",
",",
"}",
"\n",
"return",
"c",
".",
"Send",
"(",
"r",
",",
"&",
"ChassisControlResponse",
"{",
"}",
")",
"\n",
"}"
] | // Control sends a chassis power control command | [
"Control",
"sends",
"a",
"chassis",
"power",
"control",
"command"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/client.go#L113-L120 |
15,354 | vmware/goipmi | completion_code.go | Error | func (c CompletionCode) Error() string {
if s, ok := completionCodes[c]; ok {
return s
}
return fmt.Sprintf("Completion Code: %X", uint8(c))
} | go | func (c CompletionCode) Error() string {
if s, ok := completionCodes[c]; ok {
return s
}
return fmt.Sprintf("Completion Code: %X", uint8(c))
} | [
"func",
"(",
"c",
"CompletionCode",
")",
"Error",
"(",
")",
"string",
"{",
"if",
"s",
",",
"ok",
":=",
"completionCodes",
"[",
"c",
"]",
";",
"ok",
"{",
"return",
"s",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"uint8",
"(",
"c",
")",
")",
"\n",
"}"
] | // Error for CompletionCode | [
"Error",
"for",
"CompletionCode"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/completion_code.go#L85-L90 |
15,355 | vmware/goipmi | simulator.go | NewSimulator | func NewSimulator(addr net.UDPAddr) *Simulator {
s := &Simulator{
addr: addr,
ids: map[uint32]string{},
handlers: map[NetworkFunction]map[Command]Handler{},
}
// Built-in handlers for session management
s.handlers[NetworkFunctionApp] = map[Command]Handler{
CommandGetDeviceID: s.deviceID,
CommandGetAuthCapabilities: s.authCapabilities,
CommandGetSessionChallenge: s.sessionChallenge,
CommandActivateSession: s.sessionActivate,
CommandSetSessionPrivilegeLevel: s.sessionPrivilege,
CommandCloseSession: s.sessionClose,
CommandGetUserName: s.getUserName,
CommandSetUserName: s.setUserName,
}
// Built-in handlers for chassis commands
s.handlers[NetworkFunctionChassis] = map[Command]Handler{
CommandChassisStatus: s.chassisStatus,
CommandGetSystemBootOptions: s.getSystemBootOptions,
CommandSetSystemBootOptions: s.setSystemBootOptions,
}
return s
} | go | func NewSimulator(addr net.UDPAddr) *Simulator {
s := &Simulator{
addr: addr,
ids: map[uint32]string{},
handlers: map[NetworkFunction]map[Command]Handler{},
}
// Built-in handlers for session management
s.handlers[NetworkFunctionApp] = map[Command]Handler{
CommandGetDeviceID: s.deviceID,
CommandGetAuthCapabilities: s.authCapabilities,
CommandGetSessionChallenge: s.sessionChallenge,
CommandActivateSession: s.sessionActivate,
CommandSetSessionPrivilegeLevel: s.sessionPrivilege,
CommandCloseSession: s.sessionClose,
CommandGetUserName: s.getUserName,
CommandSetUserName: s.setUserName,
}
// Built-in handlers for chassis commands
s.handlers[NetworkFunctionChassis] = map[Command]Handler{
CommandChassisStatus: s.chassisStatus,
CommandGetSystemBootOptions: s.getSystemBootOptions,
CommandSetSystemBootOptions: s.setSystemBootOptions,
}
return s
} | [
"func",
"NewSimulator",
"(",
"addr",
"net",
".",
"UDPAddr",
")",
"*",
"Simulator",
"{",
"s",
":=",
"&",
"Simulator",
"{",
"addr",
":",
"addr",
",",
"ids",
":",
"map",
"[",
"uint32",
"]",
"string",
"{",
"}",
",",
"handlers",
":",
"map",
"[",
"NetworkFunction",
"]",
"map",
"[",
"Command",
"]",
"Handler",
"{",
"}",
",",
"}",
"\n\n",
"// Built-in handlers for session management",
"s",
".",
"handlers",
"[",
"NetworkFunctionApp",
"]",
"=",
"map",
"[",
"Command",
"]",
"Handler",
"{",
"CommandGetDeviceID",
":",
"s",
".",
"deviceID",
",",
"CommandGetAuthCapabilities",
":",
"s",
".",
"authCapabilities",
",",
"CommandGetSessionChallenge",
":",
"s",
".",
"sessionChallenge",
",",
"CommandActivateSession",
":",
"s",
".",
"sessionActivate",
",",
"CommandSetSessionPrivilegeLevel",
":",
"s",
".",
"sessionPrivilege",
",",
"CommandCloseSession",
":",
"s",
".",
"sessionClose",
",",
"CommandGetUserName",
":",
"s",
".",
"getUserName",
",",
"CommandSetUserName",
":",
"s",
".",
"setUserName",
",",
"}",
"\n\n",
"// Built-in handlers for chassis commands",
"s",
".",
"handlers",
"[",
"NetworkFunctionChassis",
"]",
"=",
"map",
"[",
"Command",
"]",
"Handler",
"{",
"CommandChassisStatus",
":",
"s",
".",
"chassisStatus",
",",
"CommandGetSystemBootOptions",
":",
"s",
".",
"getSystemBootOptions",
",",
"CommandSetSystemBootOptions",
":",
"s",
".",
"setSystemBootOptions",
",",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
] | // NewSimulator constructs a Simulator with the given addr | [
"NewSimulator",
"constructs",
"a",
"Simulator",
"with",
"the",
"given",
"addr"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/simulator.go#L44-L71 |
15,356 | vmware/goipmi | simulator.go | SetHandler | func (s *Simulator) SetHandler(netfn NetworkFunction, command Command, handler Handler) {
s.handlers[netfn][command] = handler
} | go | func (s *Simulator) SetHandler(netfn NetworkFunction, command Command, handler Handler) {
s.handlers[netfn][command] = handler
} | [
"func",
"(",
"s",
"*",
"Simulator",
")",
"SetHandler",
"(",
"netfn",
"NetworkFunction",
",",
"command",
"Command",
",",
"handler",
"Handler",
")",
"{",
"s",
".",
"handlers",
"[",
"netfn",
"]",
"[",
"command",
"]",
"=",
"handler",
"\n",
"}"
] | // SetHandler sets the command handler for the given netfn and command | [
"SetHandler",
"sets",
"the",
"command",
"handler",
"for",
"the",
"given",
"netfn",
"and",
"command"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/simulator.go#L74-L76 |
15,357 | vmware/goipmi | simulator.go | NewConnection | func (s *Simulator) NewConnection() *Connection {
addr := s.LocalAddr()
return &Connection{
Hostname: addr.IP.String(),
Port: addr.Port,
Interface: "lan",
}
} | go | func (s *Simulator) NewConnection() *Connection {
addr := s.LocalAddr()
return &Connection{
Hostname: addr.IP.String(),
Port: addr.Port,
Interface: "lan",
}
} | [
"func",
"(",
"s",
"*",
"Simulator",
")",
"NewConnection",
"(",
")",
"*",
"Connection",
"{",
"addr",
":=",
"s",
".",
"LocalAddr",
"(",
")",
"\n",
"return",
"&",
"Connection",
"{",
"Hostname",
":",
"addr",
".",
"IP",
".",
"String",
"(",
")",
",",
"Port",
":",
"addr",
".",
"Port",
",",
"Interface",
":",
"\"",
"\"",
",",
"}",
"\n",
"}"
] | // NewConnection to this Simulator instance | [
"NewConnection",
"to",
"this",
"Simulator",
"instance"
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/simulator.go#L79-L86 |
15,358 | vmware/goipmi | simulator.go | LocalAddr | func (s *Simulator) LocalAddr() *net.UDPAddr {
if s.conn != nil {
return s.conn.LocalAddr().(*net.UDPAddr)
}
return nil
} | go | func (s *Simulator) LocalAddr() *net.UDPAddr {
if s.conn != nil {
return s.conn.LocalAddr().(*net.UDPAddr)
}
return nil
} | [
"func",
"(",
"s",
"*",
"Simulator",
")",
"LocalAddr",
"(",
")",
"*",
"net",
".",
"UDPAddr",
"{",
"if",
"s",
".",
"conn",
"!=",
"nil",
"{",
"return",
"s",
".",
"conn",
".",
"LocalAddr",
"(",
")",
".",
"(",
"*",
"net",
".",
"UDPAddr",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // LocalAddr returns the address the server is bound to. | [
"LocalAddr",
"returns",
"the",
"address",
"the",
"server",
"is",
"bound",
"to",
"."
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/simulator.go#L89-L94 |
15,359 | vmware/goipmi | simulator.go | Run | func (s *Simulator) Run() error {
var err error
s.conn, err = net.ListenUDP("udp4", &s.addr)
if err != nil {
return err
}
s.wg.Add(1)
go func() {
_ = s.serve()
s.wg.Done()
}()
return nil
} | go | func (s *Simulator) Run() error {
var err error
s.conn, err = net.ListenUDP("udp4", &s.addr)
if err != nil {
return err
}
s.wg.Add(1)
go func() {
_ = s.serve()
s.wg.Done()
}()
return nil
} | [
"func",
"(",
"s",
"*",
"Simulator",
")",
"Run",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"s",
".",
"conn",
",",
"err",
"=",
"net",
".",
"ListenUDP",
"(",
"\"",
"\"",
",",
"&",
"s",
".",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"s",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"_",
"=",
"s",
".",
"serve",
"(",
")",
"\n",
"s",
".",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Run the Simulator. | [
"Run",
"the",
"Simulator",
"."
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/simulator.go#L97-L112 |
15,360 | vmware/goipmi | simulator.go | Stop | func (s *Simulator) Stop() {
_ = s.conn.Close()
s.wg.Wait()
} | go | func (s *Simulator) Stop() {
_ = s.conn.Close()
s.wg.Wait()
} | [
"func",
"(",
"s",
"*",
"Simulator",
")",
"Stop",
"(",
")",
"{",
"_",
"=",
"s",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"s",
".",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // Stop the Simulator. | [
"Stop",
"the",
"Simulator",
"."
] | 2333cd82d7020d1701c082e98870cb64a97988a2 | https://github.com/vmware/goipmi/blob/2333cd82d7020d1701c082e98870cb64a97988a2/simulator.go#L115-L118 |
15,361 | gdamore/encoding | charmap.go | NewDecoder | func (c *Charmap) NewDecoder() *encoding.Decoder {
c.Init()
return &encoding.Decoder{Transformer: &cmapDecoder{runes: c.runes}}
} | go | func (c *Charmap) NewDecoder() *encoding.Decoder {
c.Init()
return &encoding.Decoder{Transformer: &cmapDecoder{runes: c.runes}}
} | [
"func",
"(",
"c",
"*",
"Charmap",
")",
"NewDecoder",
"(",
")",
"*",
"encoding",
".",
"Decoder",
"{",
"c",
".",
"Init",
"(",
")",
"\n",
"return",
"&",
"encoding",
".",
"Decoder",
"{",
"Transformer",
":",
"&",
"cmapDecoder",
"{",
"runes",
":",
"c",
".",
"runes",
"}",
"}",
"\n",
"}"
] | // NewDecoder returns a Decoder the converts from the 8-bit
// character set to UTF-8. Unknown mappings, if any, are mapped
// to '\uFFFD'. | [
"NewDecoder",
"returns",
"a",
"Decoder",
"the",
"converts",
"from",
"the",
"8",
"-",
"bit",
"character",
"set",
"to",
"UTF",
"-",
"8",
".",
"Unknown",
"mappings",
"if",
"any",
"are",
"mapped",
"to",
"\\",
"uFFFD",
"."
] | 6289cdc94c00ac4aa177771c5fce7af2f96b626d | https://github.com/gdamore/encoding/blob/6289cdc94c00ac4aa177771c5fce7af2f96b626d/charmap.go#L129-L132 |
15,362 | gdamore/encoding | charmap.go | NewEncoder | func (c *Charmap) NewEncoder() *encoding.Encoder {
c.Init()
return &encoding.Encoder{
Transformer: &cmapEncoder{
bytes: c.bytes,
replace: c.ReplacementChar,
},
}
} | go | func (c *Charmap) NewEncoder() *encoding.Encoder {
c.Init()
return &encoding.Encoder{
Transformer: &cmapEncoder{
bytes: c.bytes,
replace: c.ReplacementChar,
},
}
} | [
"func",
"(",
"c",
"*",
"Charmap",
")",
"NewEncoder",
"(",
")",
"*",
"encoding",
".",
"Encoder",
"{",
"c",
".",
"Init",
"(",
")",
"\n",
"return",
"&",
"encoding",
".",
"Encoder",
"{",
"Transformer",
":",
"&",
"cmapEncoder",
"{",
"bytes",
":",
"c",
".",
"bytes",
",",
"replace",
":",
"c",
".",
"ReplacementChar",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewEncoder returns a Transformer that converts from UTF8 to the
// 8-bit character set. Unknown mappings are mapped to 0x1A. | [
"NewEncoder",
"returns",
"a",
"Transformer",
"that",
"converts",
"from",
"UTF8",
"to",
"the",
"8",
"-",
"bit",
"character",
"set",
".",
"Unknown",
"mappings",
"are",
"mapped",
"to",
"0x1A",
"."
] | 6289cdc94c00ac4aa177771c5fce7af2f96b626d | https://github.com/gdamore/encoding/blob/6289cdc94c00ac4aa177771c5fce7af2f96b626d/charmap.go#L136-L144 |
15,363 | vaughan0/go-ini | ini.go | Load | func (f File) Load(in io.Reader) (err error) {
bufin, ok := in.(*bufio.Reader)
if !ok {
bufin = bufio.NewReader(in)
}
return parseFile(bufin, f)
} | go | func (f File) Load(in io.Reader) (err error) {
bufin, ok := in.(*bufio.Reader)
if !ok {
bufin = bufio.NewReader(in)
}
return parseFile(bufin, f)
} | [
"func",
"(",
"f",
"File",
")",
"Load",
"(",
"in",
"io",
".",
"Reader",
")",
"(",
"err",
"error",
")",
"{",
"bufin",
",",
"ok",
":=",
"in",
".",
"(",
"*",
"bufio",
".",
"Reader",
")",
"\n",
"if",
"!",
"ok",
"{",
"bufin",
"=",
"bufio",
".",
"NewReader",
"(",
"in",
")",
"\n",
"}",
"\n",
"return",
"parseFile",
"(",
"bufin",
",",
"f",
")",
"\n",
"}"
] | // Loads INI data from a reader and stores the data in the File. | [
"Loads",
"INI",
"data",
"from",
"a",
"reader",
"and",
"stores",
"the",
"data",
"in",
"the",
"File",
"."
] | a98ad7ee00ec53921f08832bc06ecf7fd600e6a1 | https://github.com/vaughan0/go-ini/blob/a98ad7ee00ec53921f08832bc06ecf7fd600e6a1/ini.go#L53-L59 |
15,364 | sogko/slumber | domain/routes.go | Append | func (r *Routes) Append(routes ...*Routes) Routes {
res := Routes{}
// copy current route
for _, route := range *r {
res = append(res, route)
}
for _, _routes := range routes {
for _, route := range *_routes {
res = append(res, route)
}
}
return res
} | go | func (r *Routes) Append(routes ...*Routes) Routes {
res := Routes{}
// copy current route
for _, route := range *r {
res = append(res, route)
}
for _, _routes := range routes {
for _, route := range *_routes {
res = append(res, route)
}
}
return res
} | [
"func",
"(",
"r",
"*",
"Routes",
")",
"Append",
"(",
"routes",
"...",
"*",
"Routes",
")",
"Routes",
"{",
"res",
":=",
"Routes",
"{",
"}",
"\n",
"// copy current route",
"for",
"_",
",",
"route",
":=",
"range",
"*",
"r",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"route",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"_routes",
":=",
"range",
"routes",
"{",
"for",
"_",
",",
"route",
":=",
"range",
"*",
"_routes",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"route",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] | // Append Returns a new slice of Routes | [
"Append",
"Returns",
"a",
"new",
"slice",
"of",
"Routes"
] | a85dc47e9331ec5d7e88b30612c053a1462bfc3f | https://github.com/sogko/slumber/blob/a85dc47e9331ec5d7e88b30612c053a1462bfc3f/domain/routes.go#L27-L39 |
15,365 | sogko/slumber | server/server.go | NewServer | func NewServer(options *Config) *Server {
// set up server and middlewares
n := negroni.Classic()
s := &Server{n, options.Context, nil, nil, 0}
return s
} | go | func NewServer(options *Config) *Server {
// set up server and middlewares
n := negroni.Classic()
s := &Server{n, options.Context, nil, nil, 0}
return s
} | [
"func",
"NewServer",
"(",
"options",
"*",
"Config",
")",
"*",
"Server",
"{",
"// set up server and middlewares",
"n",
":=",
"negroni",
".",
"Classic",
"(",
")",
"\n\n",
"s",
":=",
"&",
"Server",
"{",
"n",
",",
"options",
".",
"Context",
",",
"nil",
",",
"nil",
",",
"0",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
] | // NewServer Returns a new Server object | [
"NewServer",
"Returns",
"a",
"new",
"Server",
"object"
] | a85dc47e9331ec5d7e88b30612c053a1462bfc3f | https://github.com/sogko/slumber/blob/a85dc47e9331ec5d7e88b30612c053a1462bfc3f/server/server.go#L36-L44 |
15,366 | sogko/slumber | middlewares/renderer/renderer.go | New | func New(options *Options, defaultRenderType string) *Renderer {
r := render.New(render.Options(*options))
return &Renderer{r, options, defaultRenderType}
} | go | func New(options *Options, defaultRenderType string) *Renderer {
r := render.New(render.Options(*options))
return &Renderer{r, options, defaultRenderType}
} | [
"func",
"New",
"(",
"options",
"*",
"Options",
",",
"defaultRenderType",
"string",
")",
"*",
"Renderer",
"{",
"r",
":=",
"render",
".",
"New",
"(",
"render",
".",
"Options",
"(",
"*",
"options",
")",
")",
"\n",
"return",
"&",
"Renderer",
"{",
"r",
",",
"options",
",",
"defaultRenderType",
"}",
"\n",
"}"
] | // New( Returns a new Renderer object | [
"New",
"(",
"Returns",
"a",
"new",
"Renderer",
"object"
] | a85dc47e9331ec5d7e88b30612c053a1462bfc3f | https://github.com/sogko/slumber/blob/a85dc47e9331ec5d7e88b30612c053a1462bfc3f/middlewares/renderer/renderer.go#L26-L29 |
15,367 | sogko/slumber | middlewares/renderer/renderer.go | Handler | func (renderer *Renderer) Handler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc, ctx domain.IContext) {
SetRendererCtx(ctx, req, renderer)
next(w, req)
} | go | func (renderer *Renderer) Handler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc, ctx domain.IContext) {
SetRendererCtx(ctx, req, renderer)
next(w, req)
} | [
"func",
"(",
"renderer",
"*",
"Renderer",
")",
"Handler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
",",
"next",
"http",
".",
"HandlerFunc",
",",
"ctx",
"domain",
".",
"IContext",
")",
"{",
"SetRendererCtx",
"(",
"ctx",
",",
"req",
",",
"renderer",
")",
"\n",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"}"
] | // HandlerWithNext Returns a middleware HandlerFunc that saves the Render object into request context | [
"HandlerWithNext",
"Returns",
"a",
"middleware",
"HandlerFunc",
"that",
"saves",
"the",
"Render",
"object",
"into",
"request",
"context"
] | a85dc47e9331ec5d7e88b30612c053a1462bfc3f | https://github.com/sogko/slumber/blob/a85dc47e9331ec5d7e88b30612c053a1462bfc3f/middlewares/renderer/renderer.go#L32-L35 |
15,368 | sogko/slumber | middlewares/mongodb/mongodb.go | Handler | func (session *MongoDBSession) Handler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc, ctx domain.IContext) {
s := session.Clone()
defer s.Close()
db := &MongoDB{
currentDb: s.DB(session.DatabaseName),
}
SetMongoDbCtx(ctx, req, db)
next(w, req)
} | go | func (session *MongoDBSession) Handler(w http.ResponseWriter, req *http.Request, next http.HandlerFunc, ctx domain.IContext) {
s := session.Clone()
defer s.Close()
db := &MongoDB{
currentDb: s.DB(session.DatabaseName),
}
SetMongoDbCtx(ctx, req, db)
next(w, req)
} | [
"func",
"(",
"session",
"*",
"MongoDBSession",
")",
"Handler",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
",",
"next",
"http",
".",
"HandlerFunc",
",",
"ctx",
"domain",
".",
"IContext",
")",
"{",
"s",
":=",
"session",
".",
"Clone",
"(",
")",
"\n",
"defer",
"s",
".",
"Close",
"(",
")",
"\n",
"db",
":=",
"&",
"MongoDB",
"{",
"currentDb",
":",
"s",
".",
"DB",
"(",
"session",
".",
"DatabaseName",
")",
",",
"}",
"\n",
"SetMongoDbCtx",
"(",
"ctx",
",",
"req",
",",
"db",
")",
"\n",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"}"
] | // Handler Returns a middleware HandlerFunc that creates and saves a database session into request context | [
"Handler",
"Returns",
"a",
"middleware",
"HandlerFunc",
"that",
"creates",
"and",
"saves",
"a",
"database",
"session",
"into",
"request",
"context"
] | a85dc47e9331ec5d7e88b30612c053a1462bfc3f | https://github.com/sogko/slumber/blob/a85dc47e9331ec5d7e88b30612c053a1462bfc3f/middlewares/mongodb/mongodb.go#L112-L120 |
15,369 | sogko/slumber | server/router.go | NewRouter | func NewRouter(ctx domain.IContext, ac domain.IAccessController) *Router {
router := mux.NewRouter().StrictSlash(true)
return &Router{router, ac, ctx}
} | go | func NewRouter(ctx domain.IContext, ac domain.IAccessController) *Router {
router := mux.NewRouter().StrictSlash(true)
return &Router{router, ac, ctx}
} | [
"func",
"NewRouter",
"(",
"ctx",
"domain",
".",
"IContext",
",",
"ac",
"domain",
".",
"IAccessController",
")",
"*",
"Router",
"{",
"router",
":=",
"mux",
".",
"NewRouter",
"(",
")",
".",
"StrictSlash",
"(",
"true",
")",
"\n\n",
"return",
"&",
"Router",
"{",
"router",
",",
"ac",
",",
"ctx",
"}",
"\n",
"}"
] | // NewRouter Returns a new Router object | [
"NewRouter",
"Returns",
"a",
"new",
"Router",
"object"
] | a85dc47e9331ec5d7e88b30612c053a1462bfc3f | https://github.com/sogko/slumber/blob/a85dc47e9331ec5d7e88b30612c053a1462bfc3f/server/router.go#L55-L59 |
15,370 | go-playground/lars | context_17.go | WithContext | func (c *Ctx) WithContext(ctx context.Context) {
c.request = c.request.WithContext(ctx)
} | go | func (c *Ctx) WithContext(ctx context.Context) {
c.request = c.request.WithContext(ctx)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"c",
".",
"request",
"=",
"c",
".",
"request",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"}"
] | // WithContext updates the underlying request's context with to ctx
// The provided ctx must be non-nil. | [
"WithContext",
"updates",
"the",
"underlying",
"request",
"s",
"context",
"with",
"to",
"ctx",
"The",
"provided",
"ctx",
"must",
"be",
"non",
"-",
"nil",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context_17.go#L110-L112 |
15,371 | go-playground/lars | context_17.go | WithCancel | func (c *Ctx) WithCancel() context.CancelFunc {
ctx, cf := context.WithCancel(c.request.Context())
c.request = c.request.WithContext(ctx)
return cf
} | go | func (c *Ctx) WithCancel() context.CancelFunc {
ctx, cf := context.WithCancel(c.request.Context())
c.request = c.request.WithContext(ctx)
return cf
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"WithCancel",
"(",
")",
"context",
".",
"CancelFunc",
"{",
"ctx",
",",
"cf",
":=",
"context",
".",
"WithCancel",
"(",
"c",
".",
"request",
".",
"Context",
"(",
")",
")",
"\n",
"c",
".",
"request",
"=",
"c",
".",
"request",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"return",
"cf",
"\n",
"}"
] | // WithCancel calls context.WithCancel and automatically
// updates context on the containing lars.Ctx object. | [
"WithCancel",
"calls",
"context",
".",
"WithCancel",
"and",
"automatically",
"updates",
"context",
"on",
"the",
"containing",
"lars",
".",
"Ctx",
"object",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context_17.go#L136-L140 |
15,372 | go-playground/lars | context_17.go | WithDeadline | func (c *Ctx) WithDeadline(deadline time.Time) context.CancelFunc {
ctx, cf := context.WithDeadline(c.request.Context(), deadline)
c.request = c.request.WithContext(ctx)
return cf
} | go | func (c *Ctx) WithDeadline(deadline time.Time) context.CancelFunc {
ctx, cf := context.WithDeadline(c.request.Context(), deadline)
c.request = c.request.WithContext(ctx)
return cf
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"WithDeadline",
"(",
"deadline",
"time",
".",
"Time",
")",
"context",
".",
"CancelFunc",
"{",
"ctx",
",",
"cf",
":=",
"context",
".",
"WithDeadline",
"(",
"c",
".",
"request",
".",
"Context",
"(",
")",
",",
"deadline",
")",
"\n",
"c",
".",
"request",
"=",
"c",
".",
"request",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"return",
"cf",
"\n",
"}"
] | // WithDeadline calls context.WithDeadline and automatically
// updates context on the containing lars.Ctx object. | [
"WithDeadline",
"calls",
"context",
".",
"WithDeadline",
"and",
"automatically",
"updates",
"context",
"on",
"the",
"containing",
"lars",
".",
"Ctx",
"object",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context_17.go#L144-L148 |
15,373 | go-playground/lars | context_17.go | WithTimeout | func (c *Ctx) WithTimeout(timeout time.Duration) context.CancelFunc {
ctx, cf := context.WithTimeout(c.request.Context(), timeout)
c.request = c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
return cf
} | go | func (c *Ctx) WithTimeout(timeout time.Duration) context.CancelFunc {
ctx, cf := context.WithTimeout(c.request.Context(), timeout)
c.request = c.request.WithContext(ctx) // temporarily shallow copying to avoid problems with external libraries
return cf
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"WithTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"context",
".",
"CancelFunc",
"{",
"ctx",
",",
"cf",
":=",
"context",
".",
"WithTimeout",
"(",
"c",
".",
"request",
".",
"Context",
"(",
")",
",",
"timeout",
")",
"\n",
"c",
".",
"request",
"=",
"c",
".",
"request",
".",
"WithContext",
"(",
"ctx",
")",
"// temporarily shallow copying to avoid problems with external libraries",
"\n",
"return",
"cf",
"\n",
"}"
] | // WithTimeout calls context.WithTimeout and automatically
// updates context on the containing lars.Ctx object. | [
"WithTimeout",
"calls",
"context",
".",
"WithTimeout",
"and",
"automatically",
"updates",
"context",
"on",
"the",
"containing",
"lars",
".",
"Ctx",
"object",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context_17.go#L152-L156 |
15,374 | go-playground/lars | context_16.go | RequestStart | func (c *Ctx) RequestStart(w http.ResponseWriter, r *http.Request) {
c.request = r
c.response.reset(w)
c.params = c.params[0:0]
c.queryParams = nil
c.netContext = context.Background() // in go 1.7 will call r.Context(), netContext will go away and be replaced with the Request objects Context
c.index = -1
c.handlers = nil
c.formParsed = false
c.multipartFormParsed = false
} | go | func (c *Ctx) RequestStart(w http.ResponseWriter, r *http.Request) {
c.request = r
c.response.reset(w)
c.params = c.params[0:0]
c.queryParams = nil
c.netContext = context.Background() // in go 1.7 will call r.Context(), netContext will go away and be replaced with the Request objects Context
c.index = -1
c.handlers = nil
c.formParsed = false
c.multipartFormParsed = false
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"RequestStart",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"c",
".",
"request",
"=",
"r",
"\n",
"c",
".",
"response",
".",
"reset",
"(",
"w",
")",
"\n",
"c",
".",
"params",
"=",
"c",
".",
"params",
"[",
"0",
":",
"0",
"]",
"\n",
"c",
".",
"queryParams",
"=",
"nil",
"\n",
"c",
".",
"netContext",
"=",
"context",
".",
"Background",
"(",
")",
"// in go 1.7 will call r.Context(), netContext will go away and be replaced with the Request objects Context",
"\n",
"c",
".",
"index",
"=",
"-",
"1",
"\n",
"c",
".",
"handlers",
"=",
"nil",
"\n",
"c",
".",
"formParsed",
"=",
"false",
"\n",
"c",
".",
"multipartFormParsed",
"=",
"false",
"\n",
"}"
] | // RequestStart resets the Context to it's default request state | [
"RequestStart",
"resets",
"the",
"Context",
"to",
"it",
"s",
"default",
"request",
"state"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context_16.go#L72-L82 |
15,375 | go-playground/lars | lars.go | New | func New() *LARS {
l := &LARS{
routeGroup: routeGroup{
middleware: make(HandlersChain, 0),
},
trees: make(map[string]*node),
contextFunc: func(l *LARS) Context {
return NewContext(l)
},
mostParams: 0,
http404: []HandlerFunc{default404Handler},
http405: []HandlerFunc{methodNotAllowedHandler},
redirectTrailingSlash: true,
handleMethodNotAllowed: false,
automaticallyHandleOPTIONS: false,
}
l.routeGroup.lars = l
l.pool.New = func() interface{} {
c := l.contextFunc(l)
b := c.BaseContext()
b.parent = c
return b
}
return l
} | go | func New() *LARS {
l := &LARS{
routeGroup: routeGroup{
middleware: make(HandlersChain, 0),
},
trees: make(map[string]*node),
contextFunc: func(l *LARS) Context {
return NewContext(l)
},
mostParams: 0,
http404: []HandlerFunc{default404Handler},
http405: []HandlerFunc{methodNotAllowedHandler},
redirectTrailingSlash: true,
handleMethodNotAllowed: false,
automaticallyHandleOPTIONS: false,
}
l.routeGroup.lars = l
l.pool.New = func() interface{} {
c := l.contextFunc(l)
b := c.BaseContext()
b.parent = c
return b
}
return l
} | [
"func",
"New",
"(",
")",
"*",
"LARS",
"{",
"l",
":=",
"&",
"LARS",
"{",
"routeGroup",
":",
"routeGroup",
"{",
"middleware",
":",
"make",
"(",
"HandlersChain",
",",
"0",
")",
",",
"}",
",",
"trees",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"node",
")",
",",
"contextFunc",
":",
"func",
"(",
"l",
"*",
"LARS",
")",
"Context",
"{",
"return",
"NewContext",
"(",
"l",
")",
"\n",
"}",
",",
"mostParams",
":",
"0",
",",
"http404",
":",
"[",
"]",
"HandlerFunc",
"{",
"default404Handler",
"}",
",",
"http405",
":",
"[",
"]",
"HandlerFunc",
"{",
"methodNotAllowedHandler",
"}",
",",
"redirectTrailingSlash",
":",
"true",
",",
"handleMethodNotAllowed",
":",
"false",
",",
"automaticallyHandleOPTIONS",
":",
"false",
",",
"}",
"\n\n",
"l",
".",
"routeGroup",
".",
"lars",
"=",
"l",
"\n",
"l",
".",
"pool",
".",
"New",
"=",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"c",
":=",
"l",
".",
"contextFunc",
"(",
"l",
")",
"\n",
"b",
":=",
"c",
".",
"BaseContext",
"(",
")",
"\n",
"b",
".",
"parent",
"=",
"c",
"\n\n",
"return",
"b",
"\n",
"}",
"\n\n",
"return",
"l",
"\n",
"}"
] | // New Creates and returns a new lars instance | [
"New",
"Creates",
"and",
"returns",
"a",
"new",
"lars",
"instance"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/lars.go#L184-L213 |
15,376 | go-playground/lars | lars.go | RegisterCustomHandler | func (l *LARS) RegisterCustomHandler(customType interface{}, fn CustomHandlerFunc) {
if l.customHandlersFuncs == nil {
l.customHandlersFuncs = make(customHandlers)
}
t := reflect.TypeOf(customType)
if _, ok := l.customHandlersFuncs[t]; ok {
panic(fmt.Sprint("Custom Type + CustomHandlerFunc already declared: ", t))
}
l.customHandlersFuncs[t] = fn
} | go | func (l *LARS) RegisterCustomHandler(customType interface{}, fn CustomHandlerFunc) {
if l.customHandlersFuncs == nil {
l.customHandlersFuncs = make(customHandlers)
}
t := reflect.TypeOf(customType)
if _, ok := l.customHandlersFuncs[t]; ok {
panic(fmt.Sprint("Custom Type + CustomHandlerFunc already declared: ", t))
}
l.customHandlersFuncs[t] = fn
} | [
"func",
"(",
"l",
"*",
"LARS",
")",
"RegisterCustomHandler",
"(",
"customType",
"interface",
"{",
"}",
",",
"fn",
"CustomHandlerFunc",
")",
"{",
"if",
"l",
".",
"customHandlersFuncs",
"==",
"nil",
"{",
"l",
".",
"customHandlersFuncs",
"=",
"make",
"(",
"customHandlers",
")",
"\n",
"}",
"\n\n",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"customType",
")",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"l",
".",
"customHandlersFuncs",
"[",
"t",
"]",
";",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprint",
"(",
"\"",
"\"",
",",
"t",
")",
")",
"\n",
"}",
"\n\n",
"l",
".",
"customHandlersFuncs",
"[",
"t",
"]",
"=",
"fn",
"\n",
"}"
] | // RegisterCustomHandler registers a custom handler that gets wrapped by HandlerFunc | [
"RegisterCustomHandler",
"registers",
"a",
"custom",
"handler",
"that",
"gets",
"wrapped",
"by",
"HandlerFunc"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/lars.go#L231-L244 |
15,377 | go-playground/lars | lars.go | Serve | func (l *LARS) Serve() http.Handler {
// reserved for any logic that needs to happen before serving starts.
// i.e. although this router does not use priority to determine route order
// could add sorting of tree nodes here....
l.notFound = make(HandlersChain, len(l.middleware)+len(l.http404))
copy(l.notFound, l.middleware)
copy(l.notFound[len(l.middleware):], l.http404)
if l.automaticallyHandleOPTIONS {
l.automaticOPTIONS = make(HandlersChain, len(l.middleware)+1)
copy(l.automaticOPTIONS, l.middleware)
copy(l.automaticOPTIONS[len(l.middleware):], []HandlerFunc{automaticOPTIONSHandler})
}
return http.HandlerFunc(l.serveHTTP)
} | go | func (l *LARS) Serve() http.Handler {
// reserved for any logic that needs to happen before serving starts.
// i.e. although this router does not use priority to determine route order
// could add sorting of tree nodes here....
l.notFound = make(HandlersChain, len(l.middleware)+len(l.http404))
copy(l.notFound, l.middleware)
copy(l.notFound[len(l.middleware):], l.http404)
if l.automaticallyHandleOPTIONS {
l.automaticOPTIONS = make(HandlersChain, len(l.middleware)+1)
copy(l.automaticOPTIONS, l.middleware)
copy(l.automaticOPTIONS[len(l.middleware):], []HandlerFunc{automaticOPTIONSHandler})
}
return http.HandlerFunc(l.serveHTTP)
} | [
"func",
"(",
"l",
"*",
"LARS",
")",
"Serve",
"(",
")",
"http",
".",
"Handler",
"{",
"// reserved for any logic that needs to happen before serving starts.",
"// i.e. although this router does not use priority to determine route order",
"// could add sorting of tree nodes here....",
"l",
".",
"notFound",
"=",
"make",
"(",
"HandlersChain",
",",
"len",
"(",
"l",
".",
"middleware",
")",
"+",
"len",
"(",
"l",
".",
"http404",
")",
")",
"\n",
"copy",
"(",
"l",
".",
"notFound",
",",
"l",
".",
"middleware",
")",
"\n",
"copy",
"(",
"l",
".",
"notFound",
"[",
"len",
"(",
"l",
".",
"middleware",
")",
":",
"]",
",",
"l",
".",
"http404",
")",
"\n\n",
"if",
"l",
".",
"automaticallyHandleOPTIONS",
"{",
"l",
".",
"automaticOPTIONS",
"=",
"make",
"(",
"HandlersChain",
",",
"len",
"(",
"l",
".",
"middleware",
")",
"+",
"1",
")",
"\n",
"copy",
"(",
"l",
".",
"automaticOPTIONS",
",",
"l",
".",
"middleware",
")",
"\n",
"copy",
"(",
"l",
".",
"automaticOPTIONS",
"[",
"len",
"(",
"l",
".",
"middleware",
")",
":",
"]",
",",
"[",
"]",
"HandlerFunc",
"{",
"automaticOPTIONSHandler",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"http",
".",
"HandlerFunc",
"(",
"l",
".",
"serveHTTP",
")",
"\n",
"}"
] | // Serve returns an http.Handler to be used. | [
"Serve",
"returns",
"an",
"http",
".",
"Handler",
"to",
"be",
"used",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/lars.go#L286-L303 |
15,378 | go-playground/lars | response.go | newResponse | func newResponse(w http.ResponseWriter, context Context) *Response {
return &Response{ResponseWriter: w, context: context}
} | go | func newResponse(w http.ResponseWriter, context Context) *Response {
return &Response{ResponseWriter: w, context: context}
} | [
"func",
"newResponse",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"context",
"Context",
")",
"*",
"Response",
"{",
"return",
"&",
"Response",
"{",
"ResponseWriter",
":",
"w",
",",
"context",
":",
"context",
"}",
"\n",
"}"
] | // newResponse creates a new Response for testing purposes | [
"newResponse",
"creates",
"a",
"new",
"Response",
"for",
"testing",
"purposes"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/response.go#L24-L26 |
15,379 | go-playground/lars | response.go | WriteString | func (r *Response) WriteString(s string) (n int, err error) {
n, err = io.WriteString(r.ResponseWriter, s)
r.size += int64(n)
return
} | go | func (r *Response) WriteString(s string) (n int, err error) {
n, err = io.WriteString(r.ResponseWriter, s)
r.size += int64(n)
return
} | [
"func",
"(",
"r",
"*",
"Response",
")",
"WriteString",
"(",
"s",
"string",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"n",
",",
"err",
"=",
"io",
".",
"WriteString",
"(",
"r",
".",
"ResponseWriter",
",",
"s",
")",
"\n",
"r",
".",
"size",
"+=",
"int64",
"(",
"n",
")",
"\n",
"return",
"\n",
"}"
] | // WriteString write string to ResponseWriter | [
"WriteString",
"write",
"string",
"to",
"ResponseWriter"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/response.go#L76-L80 |
15,380 | go-playground/lars | group.go | Any | func (g *routeGroup) Any(path string, h ...Handler) {
g.Connect(path, h...)
g.Delete(path, h...)
g.Get(path, h...)
g.Head(path, h...)
g.Options(path, h...)
g.Patch(path, h...)
g.Post(path, h...)
g.Put(path, h...)
g.Trace(path, h...)
} | go | func (g *routeGroup) Any(path string, h ...Handler) {
g.Connect(path, h...)
g.Delete(path, h...)
g.Get(path, h...)
g.Head(path, h...)
g.Options(path, h...)
g.Patch(path, h...)
g.Post(path, h...)
g.Put(path, h...)
g.Trace(path, h...)
} | [
"func",
"(",
"g",
"*",
"routeGroup",
")",
"Any",
"(",
"path",
"string",
",",
"h",
"...",
"Handler",
")",
"{",
"g",
".",
"Connect",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Delete",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Get",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Head",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Options",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Patch",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Post",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Put",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"g",
".",
"Trace",
"(",
"path",
",",
"h",
"...",
")",
"\n",
"}"
] | // Any adds a route & handler to the router for all HTTP methods. | [
"Any",
"adds",
"a",
"route",
"&",
"handler",
"to",
"the",
"router",
"for",
"all",
"HTTP",
"methods",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/group.go#L143-L153 |
15,381 | go-playground/lars | group.go | WebSocket | func (g *routeGroup) WebSocket(upgrader websocket.Upgrader, path string, h Handler) {
handler := g.lars.wrapHandler(h)
g.Get(path, func(c Context) {
ctx := c.BaseContext()
var err error
ctx.websocket, err = upgrader.Upgrade(ctx.response, ctx.request, nil)
if err != nil {
return
}
defer ctx.websocket.Close()
c.Next()
}, handler)
} | go | func (g *routeGroup) WebSocket(upgrader websocket.Upgrader, path string, h Handler) {
handler := g.lars.wrapHandler(h)
g.Get(path, func(c Context) {
ctx := c.BaseContext()
var err error
ctx.websocket, err = upgrader.Upgrade(ctx.response, ctx.request, nil)
if err != nil {
return
}
defer ctx.websocket.Close()
c.Next()
}, handler)
} | [
"func",
"(",
"g",
"*",
"routeGroup",
")",
"WebSocket",
"(",
"upgrader",
"websocket",
".",
"Upgrader",
",",
"path",
"string",
",",
"h",
"Handler",
")",
"{",
"handler",
":=",
"g",
".",
"lars",
".",
"wrapHandler",
"(",
"h",
")",
"\n",
"g",
".",
"Get",
"(",
"path",
",",
"func",
"(",
"c",
"Context",
")",
"{",
"ctx",
":=",
"c",
".",
"BaseContext",
"(",
")",
"\n",
"var",
"err",
"error",
"\n\n",
"ctx",
".",
"websocket",
",",
"err",
"=",
"upgrader",
".",
"Upgrade",
"(",
"ctx",
".",
"response",
",",
"ctx",
".",
"request",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"defer",
"ctx",
".",
"websocket",
".",
"Close",
"(",
")",
"\n",
"c",
".",
"Next",
"(",
")",
"\n",
"}",
",",
"handler",
")",
"\n",
"}"
] | // WebSocket adds a websocket route | [
"WebSocket",
"adds",
"a",
"websocket",
"route"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/group.go#L163-L179 |
15,382 | go-playground/lars | group.go | Group | func (g *routeGroup) Group(prefix string) IRouteGroup {
rg := &routeGroup{
prefix: g.prefix + prefix,
lars: g.lars,
middleware: make(HandlersChain, len(g.middleware)),
}
copy(rg.middleware, g.middleware)
return rg
} | go | func (g *routeGroup) Group(prefix string) IRouteGroup {
rg := &routeGroup{
prefix: g.prefix + prefix,
lars: g.lars,
middleware: make(HandlersChain, len(g.middleware)),
}
copy(rg.middleware, g.middleware)
return rg
} | [
"func",
"(",
"g",
"*",
"routeGroup",
")",
"Group",
"(",
"prefix",
"string",
")",
"IRouteGroup",
"{",
"rg",
":=",
"&",
"routeGroup",
"{",
"prefix",
":",
"g",
".",
"prefix",
"+",
"prefix",
",",
"lars",
":",
"g",
".",
"lars",
",",
"middleware",
":",
"make",
"(",
"HandlersChain",
",",
"len",
"(",
"g",
".",
"middleware",
")",
")",
",",
"}",
"\n",
"copy",
"(",
"rg",
".",
"middleware",
",",
"g",
".",
"middleware",
")",
"\n",
"return",
"rg",
"\n",
"}"
] | // Group creates a new sub router with specified prefix and retains existing middleware. | [
"Group",
"creates",
"a",
"new",
"sub",
"router",
"with",
"specified",
"prefix",
"and",
"retains",
"existing",
"middleware",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/group.go#L203-L211 |
15,383 | go-playground/lars | util.go | wrapHandler | func (l *LARS) wrapHandler(h Handler) HandlerFunc {
switch h := h.(type) {
case HandlerFunc:
return h
case func(Context):
return h
case http.Handler, http.HandlerFunc:
return func(c Context) {
ctx := c.BaseContext()
if h.(http.Handler).ServeHTTP(ctx.response, ctx.request); ctx.response.status != http.StatusOK || ctx.response.committed {
return
}
if ctx.index+1 < len(ctx.handlers) {
c.Next()
}
}
case func(http.ResponseWriter, *http.Request):
return func(c Context) {
ctx := c.BaseContext()
if h(ctx.response, ctx.request); ctx.response.status != http.StatusOK || ctx.response.committed {
return
}
if ctx.index+1 < len(ctx.handlers) {
c.Next()
}
}
case func(http.ResponseWriter, *http.Request, http.Handler):
return func(c Context) {
ctx := c.BaseContext()
h(ctx.response, ctx.request, NativeChainHandler)
}
case func(http.Handler) http.Handler:
hf := h(NativeChainHandler)
return func(c Context) {
ctx := c.BaseContext()
hf.ServeHTTP(ctx.response, ctx.request)
}
default:
if fn, ok := l.customHandlersFuncs[reflect.TypeOf(h)]; ok {
return func(c Context) {
fn(c, h)
}
}
panic("unknown handler")
}
} | go | func (l *LARS) wrapHandler(h Handler) HandlerFunc {
switch h := h.(type) {
case HandlerFunc:
return h
case func(Context):
return h
case http.Handler, http.HandlerFunc:
return func(c Context) {
ctx := c.BaseContext()
if h.(http.Handler).ServeHTTP(ctx.response, ctx.request); ctx.response.status != http.StatusOK || ctx.response.committed {
return
}
if ctx.index+1 < len(ctx.handlers) {
c.Next()
}
}
case func(http.ResponseWriter, *http.Request):
return func(c Context) {
ctx := c.BaseContext()
if h(ctx.response, ctx.request); ctx.response.status != http.StatusOK || ctx.response.committed {
return
}
if ctx.index+1 < len(ctx.handlers) {
c.Next()
}
}
case func(http.ResponseWriter, *http.Request, http.Handler):
return func(c Context) {
ctx := c.BaseContext()
h(ctx.response, ctx.request, NativeChainHandler)
}
case func(http.Handler) http.Handler:
hf := h(NativeChainHandler)
return func(c Context) {
ctx := c.BaseContext()
hf.ServeHTTP(ctx.response, ctx.request)
}
default:
if fn, ok := l.customHandlersFuncs[reflect.TypeOf(h)]; ok {
return func(c Context) {
fn(c, h)
}
}
panic("unknown handler")
}
} | [
"func",
"(",
"l",
"*",
"LARS",
")",
"wrapHandler",
"(",
"h",
"Handler",
")",
"HandlerFunc",
"{",
"switch",
"h",
":=",
"h",
".",
"(",
"type",
")",
"{",
"case",
"HandlerFunc",
":",
"return",
"h",
"\n\n",
"case",
"func",
"(",
"Context",
")",
":",
"return",
"h",
"\n\n",
"case",
"http",
".",
"Handler",
",",
"http",
".",
"HandlerFunc",
":",
"return",
"func",
"(",
"c",
"Context",
")",
"{",
"ctx",
":=",
"c",
".",
"BaseContext",
"(",
")",
"\n\n",
"if",
"h",
".",
"(",
"http",
".",
"Handler",
")",
".",
"ServeHTTP",
"(",
"ctx",
".",
"response",
",",
"ctx",
".",
"request",
")",
";",
"ctx",
".",
"response",
".",
"status",
"!=",
"http",
".",
"StatusOK",
"||",
"ctx",
".",
"response",
".",
"committed",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"ctx",
".",
"index",
"+",
"1",
"<",
"len",
"(",
"ctx",
".",
"handlers",
")",
"{",
"c",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"case",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
")",
":",
"return",
"func",
"(",
"c",
"Context",
")",
"{",
"ctx",
":=",
"c",
".",
"BaseContext",
"(",
")",
"\n\n",
"if",
"h",
"(",
"ctx",
".",
"response",
",",
"ctx",
".",
"request",
")",
";",
"ctx",
".",
"response",
".",
"status",
"!=",
"http",
".",
"StatusOK",
"||",
"ctx",
".",
"response",
".",
"committed",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"ctx",
".",
"index",
"+",
"1",
"<",
"len",
"(",
"ctx",
".",
"handlers",
")",
"{",
"c",
".",
"Next",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"case",
"func",
"(",
"http",
".",
"ResponseWriter",
",",
"*",
"http",
".",
"Request",
",",
"http",
".",
"Handler",
")",
":",
"return",
"func",
"(",
"c",
"Context",
")",
"{",
"ctx",
":=",
"c",
".",
"BaseContext",
"(",
")",
"\n\n",
"h",
"(",
"ctx",
".",
"response",
",",
"ctx",
".",
"request",
",",
"NativeChainHandler",
")",
"\n",
"}",
"\n\n",
"case",
"func",
"(",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
":",
"hf",
":=",
"h",
"(",
"NativeChainHandler",
")",
"\n\n",
"return",
"func",
"(",
"c",
"Context",
")",
"{",
"ctx",
":=",
"c",
".",
"BaseContext",
"(",
")",
"\n\n",
"hf",
".",
"ServeHTTP",
"(",
"ctx",
".",
"response",
",",
"ctx",
".",
"request",
")",
"\n",
"}",
"\n\n",
"default",
":",
"if",
"fn",
",",
"ok",
":=",
"l",
".",
"customHandlersFuncs",
"[",
"reflect",
".",
"TypeOf",
"(",
"h",
")",
"]",
";",
"ok",
"{",
"return",
"func",
"(",
"c",
"Context",
")",
"{",
"fn",
"(",
"c",
",",
"h",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // wrapHandler wraps Handler type | [
"wrapHandler",
"wraps",
"Handler",
"type"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/util.go#L41-L105 |
15,384 | go-playground/lars | util.go | wrapHandlerWithName | func (l *LARS) wrapHandlerWithName(h Handler) (chain HandlerFunc, handlerName string) {
chain = l.wrapHandler(h)
handlerName = runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
return
} | go | func (l *LARS) wrapHandlerWithName(h Handler) (chain HandlerFunc, handlerName string) {
chain = l.wrapHandler(h)
handlerName = runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
return
} | [
"func",
"(",
"l",
"*",
"LARS",
")",
"wrapHandlerWithName",
"(",
"h",
"Handler",
")",
"(",
"chain",
"HandlerFunc",
",",
"handlerName",
"string",
")",
"{",
"chain",
"=",
"l",
".",
"wrapHandler",
"(",
"h",
")",
"\n",
"handlerName",
"=",
"runtime",
".",
"FuncForPC",
"(",
"reflect",
".",
"ValueOf",
"(",
"h",
")",
".",
"Pointer",
"(",
")",
")",
".",
"Name",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // wrapHandlerWithName wraps Handler type and returns it including it's name before wrapping | [
"wrapHandlerWithName",
"wraps",
"Handler",
"type",
"and",
"returns",
"it",
"including",
"it",
"s",
"name",
"before",
"wrapping"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/util.go#L108-L113 |
15,385 | go-playground/lars | context.go | NewContext | func NewContext(l *LARS) *Ctx {
c := &Ctx{
params: make(Params, l.mostParams),
}
c.response = newResponse(nil, c)
return c
} | go | func NewContext(l *LARS) *Ctx {
c := &Ctx{
params: make(Params, l.mostParams),
}
c.response = newResponse(nil, c)
return c
} | [
"func",
"NewContext",
"(",
"l",
"*",
"LARS",
")",
"*",
"Ctx",
"{",
"c",
":=",
"&",
"Ctx",
"{",
"params",
":",
"make",
"(",
"Params",
",",
"l",
".",
"mostParams",
")",
",",
"}",
"\n\n",
"c",
".",
"response",
"=",
"newResponse",
"(",
"nil",
",",
"c",
")",
"\n\n",
"return",
"c",
"\n",
"}"
] | // NewContext returns a new default lars Context object. | [
"NewContext",
"returns",
"a",
"new",
"default",
"lars",
"Context",
"object",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L27-L36 |
15,386 | go-playground/lars | context.go | Param | func (c *Ctx) Param(name string) string {
for _, entry := range c.params {
if entry.Key == name {
return entry.Value
}
}
return blank
} | go | func (c *Ctx) Param(name string) string {
for _, entry := range c.params {
if entry.Key == name {
return entry.Value
}
}
return blank
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Param",
"(",
"name",
"string",
")",
"string",
"{",
"for",
"_",
",",
"entry",
":=",
"range",
"c",
".",
"params",
"{",
"if",
"entry",
".",
"Key",
"==",
"name",
"{",
"return",
"entry",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"blank",
"\n",
"}"
] | // Param returns the value of the first Param which key matches the given name.
// If no matching Param is found, an empty string is returned. | [
"Param",
"returns",
"the",
"value",
"of",
"the",
"first",
"Param",
"which",
"key",
"matches",
"the",
"given",
"name",
".",
"If",
"no",
"matching",
"Param",
"is",
"found",
"an",
"empty",
"string",
"is",
"returned",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L67-L76 |
15,387 | go-playground/lars | context.go | ParseMultipartForm | func (c *Ctx) ParseMultipartForm(maxMemory int64) error {
if c.multipartFormParsed {
return nil
}
if err := c.request.ParseMultipartForm(maxMemory); err != nil {
return err
}
for _, entry := range c.params {
c.request.Form.Add(entry.Key, entry.Value)
}
c.multipartFormParsed = true
return nil
} | go | func (c *Ctx) ParseMultipartForm(maxMemory int64) error {
if c.multipartFormParsed {
return nil
}
if err := c.request.ParseMultipartForm(maxMemory); err != nil {
return err
}
for _, entry := range c.params {
c.request.Form.Add(entry.Key, entry.Value)
}
c.multipartFormParsed = true
return nil
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"ParseMultipartForm",
"(",
"maxMemory",
"int64",
")",
"error",
"{",
"if",
"c",
".",
"multipartFormParsed",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"request",
".",
"ParseMultipartForm",
"(",
"maxMemory",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"entry",
":=",
"range",
"c",
".",
"params",
"{",
"c",
".",
"request",
".",
"Form",
".",
"Add",
"(",
"entry",
".",
"Key",
",",
"entry",
".",
"Value",
")",
"\n",
"}",
"\n\n",
"c",
".",
"multipartFormParsed",
"=",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // ParseMultipartForm calls the underlying http.Request ParseMultipartForm
// but also adds the URL params to the request Form as if they were defined
// as query params i.e. ?id=13&ok=true but does not add the params to the
// http.Request.URL.RawQuery for SEO purposes | [
"ParseMultipartForm",
"calls",
"the",
"underlying",
"http",
".",
"Request",
"ParseMultipartForm",
"but",
"also",
"adds",
"the",
"URL",
"params",
"to",
"the",
"request",
"Form",
"as",
"if",
"they",
"were",
"defined",
"as",
"query",
"params",
"i",
".",
"e",
".",
"?id",
"=",
"13&ok",
"=",
"true",
"but",
"does",
"not",
"add",
"the",
"params",
"to",
"the",
"http",
".",
"Request",
".",
"URL",
".",
"RawQuery",
"for",
"SEO",
"purposes"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L122-L139 |
15,388 | go-playground/lars | context.go | Next | func (c *Ctx) Next() {
c.index++
c.handlers[c.index](c.parent)
} | go | func (c *Ctx) Next() {
c.index++
c.handlers[c.index](c.parent)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Next",
"(",
")",
"{",
"c",
".",
"index",
"++",
"\n",
"c",
".",
"handlers",
"[",
"c",
".",
"index",
"]",
"(",
"c",
".",
"parent",
")",
"\n",
"}"
] | // Next should be used only inside middleware.
// It executes the pending handlers in the chain inside the calling handler.
// See example in github. | [
"Next",
"should",
"be",
"used",
"only",
"inside",
"middleware",
".",
"It",
"executes",
"the",
"pending",
"handlers",
"in",
"the",
"chain",
"inside",
"the",
"calling",
"handler",
".",
"See",
"example",
"in",
"github",
"."
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L144-L147 |
15,389 | go-playground/lars | context.go | JSON | func (c *Ctx) JSON(code int, i interface{}) (err error) {
b, err := json.Marshal(i)
if err != nil {
return err
}
return c.JSONBytes(code, b)
} | go | func (c *Ctx) JSON(code int, i interface{}) (err error) {
b, err := json.Marshal(i)
if err != nil {
return err
}
return c.JSONBytes(code, b)
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"JSON",
"(",
"code",
"int",
",",
"i",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"JSONBytes",
"(",
"code",
",",
"b",
")",
"\n",
"}"
] | // http response helpers
// JSON marshals provided interface + returns JSON + status code | [
"http",
"response",
"helpers",
"JSON",
"marshals",
"provided",
"interface",
"+",
"returns",
"JSON",
"+",
"status",
"code"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L152-L160 |
15,390 | go-playground/lars | context.go | Text | func (c *Ctx) Text(code int, s string) error {
return c.TextBytes(code, []byte(s))
} | go | func (c *Ctx) Text(code int, s string) error {
return c.TextBytes(code, []byte(s))
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Text",
"(",
"code",
"int",
",",
"s",
"string",
")",
"error",
"{",
"return",
"c",
".",
"TextBytes",
"(",
"code",
",",
"[",
"]",
"byte",
"(",
"s",
")",
")",
"\n",
"}"
] | // Text returns the provided string with status code | [
"Text",
"returns",
"the",
"provided",
"string",
"with",
"status",
"code"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L219-L221 |
15,391 | go-playground/lars | context.go | TextBytes | func (c *Ctx) TextBytes(code int, b []byte) (err error) {
c.response.Header().Set(ContentType, TextPlainCharsetUTF8)
c.response.WriteHeader(code)
_, err = c.response.Write(b)
return
} | go | func (c *Ctx) TextBytes(code int, b []byte) (err error) {
c.response.Header().Set(ContentType, TextPlainCharsetUTF8)
c.response.WriteHeader(code)
_, err = c.response.Write(b)
return
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"TextBytes",
"(",
"code",
"int",
",",
"b",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"c",
".",
"response",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"ContentType",
",",
"TextPlainCharsetUTF8",
")",
"\n",
"c",
".",
"response",
".",
"WriteHeader",
"(",
"code",
")",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"response",
".",
"Write",
"(",
"b",
")",
"\n",
"return",
"\n",
"}"
] | // TextBytes returns the provided response with status code | [
"TextBytes",
"returns",
"the",
"provided",
"response",
"with",
"status",
"code"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L224-L230 |
15,392 | go-playground/lars | context.go | Stream | func (c *Ctx) Stream(step func(w io.Writer) bool) {
w := c.response
clientGone := w.CloseNotify()
for {
select {
case <-clientGone:
return
default:
keepOpen := step(w)
w.Flush()
if !keepOpen {
return
}
}
}
} | go | func (c *Ctx) Stream(step func(w io.Writer) bool) {
w := c.response
clientGone := w.CloseNotify()
for {
select {
case <-clientGone:
return
default:
keepOpen := step(w)
w.Flush()
if !keepOpen {
return
}
}
}
} | [
"func",
"(",
"c",
"*",
"Ctx",
")",
"Stream",
"(",
"step",
"func",
"(",
"w",
"io",
".",
"Writer",
")",
"bool",
")",
"{",
"w",
":=",
"c",
".",
"response",
"\n",
"clientGone",
":=",
"w",
".",
"CloseNotify",
"(",
")",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"clientGone",
":",
"return",
"\n",
"default",
":",
"keepOpen",
":=",
"step",
"(",
"w",
")",
"\n",
"w",
".",
"Flush",
"(",
")",
"\n",
"if",
"!",
"keepOpen",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Stream provides HTTP Streaming | [
"Stream",
"provides",
"HTTP",
"Streaming"
] | 4dc376e72ef7f96a295a328f06e83e2b9ab85422 | https://github.com/go-playground/lars/blob/4dc376e72ef7f96a295a328f06e83e2b9ab85422/context.go#L305-L321 |
15,393 | yvasiyarov/gorelic | http_status_metrics.go | addHTTPStatusMetricsToComponent | func addHTTPStatusMetricsToComponent(component newrelic_platform_go.IComponent, statusCounters map[int]metrics.Counter) {
for statusCode, counter := range statusCounters {
component.AddMetrica(&counterByStatusMetrica{
counter: counter,
name: fmt.Sprintf("http/status/%d", statusCode),
units: "count",
})
}
} | go | func addHTTPStatusMetricsToComponent(component newrelic_platform_go.IComponent, statusCounters map[int]metrics.Counter) {
for statusCode, counter := range statusCounters {
component.AddMetrica(&counterByStatusMetrica{
counter: counter,
name: fmt.Sprintf("http/status/%d", statusCode),
units: "count",
})
}
} | [
"func",
"addHTTPStatusMetricsToComponent",
"(",
"component",
"newrelic_platform_go",
".",
"IComponent",
",",
"statusCounters",
"map",
"[",
"int",
"]",
"metrics",
".",
"Counter",
")",
"{",
"for",
"statusCode",
",",
"counter",
":=",
"range",
"statusCounters",
"{",
"component",
".",
"AddMetrica",
"(",
"&",
"counterByStatusMetrica",
"{",
"counter",
":",
"counter",
",",
"name",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"statusCode",
")",
",",
"units",
":",
"\"",
"\"",
",",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // addHTTPStatusMetricsToComponent initializes counter metrics for all http statuses and adds them to the component. | [
"addHTTPStatusMetricsToComponent",
"initializes",
"counter",
"metrics",
"for",
"all",
"http",
"statuses",
"and",
"adds",
"them",
"to",
"the",
"component",
"."
] | 635ca6035f2355e29fc558effa613d0d5867aac8 | https://github.com/yvasiyarov/gorelic/blob/635ca6035f2355e29fc558effa613d0d5867aac8/http_status_metrics.go#L25-L33 |
15,394 | yvasiyarov/gorelic | agent.go | NewAgent | func NewAgent() *Agent {
agent := &Agent{
NewrelicName: DefaultAgentName,
NewrelicPollInterval: DefaultNewRelicPollInterval,
Verbose: false,
CollectGcStat: true,
CollectMemoryStat: true,
GCPollInterval: DefaultGcPollIntervalInSeconds,
MemoryAllocatorPollInterval: DefaultMemoryAllocatorPollIntervalInSeconds,
AgentGUID: DefaultAgentGuid,
AgentVersion: CurrentAgentVersion,
Tracer: nil,
CustomMetrics: make([]newrelic_platform_go.IMetrica, 0),
}
return agent
} | go | func NewAgent() *Agent {
agent := &Agent{
NewrelicName: DefaultAgentName,
NewrelicPollInterval: DefaultNewRelicPollInterval,
Verbose: false,
CollectGcStat: true,
CollectMemoryStat: true,
GCPollInterval: DefaultGcPollIntervalInSeconds,
MemoryAllocatorPollInterval: DefaultMemoryAllocatorPollIntervalInSeconds,
AgentGUID: DefaultAgentGuid,
AgentVersion: CurrentAgentVersion,
Tracer: nil,
CustomMetrics: make([]newrelic_platform_go.IMetrica, 0),
}
return agent
} | [
"func",
"NewAgent",
"(",
")",
"*",
"Agent",
"{",
"agent",
":=",
"&",
"Agent",
"{",
"NewrelicName",
":",
"DefaultAgentName",
",",
"NewrelicPollInterval",
":",
"DefaultNewRelicPollInterval",
",",
"Verbose",
":",
"false",
",",
"CollectGcStat",
":",
"true",
",",
"CollectMemoryStat",
":",
"true",
",",
"GCPollInterval",
":",
"DefaultGcPollIntervalInSeconds",
",",
"MemoryAllocatorPollInterval",
":",
"DefaultMemoryAllocatorPollIntervalInSeconds",
",",
"AgentGUID",
":",
"DefaultAgentGuid",
",",
"AgentVersion",
":",
"CurrentAgentVersion",
",",
"Tracer",
":",
"nil",
",",
"CustomMetrics",
":",
"make",
"(",
"[",
"]",
"newrelic_platform_go",
".",
"IMetrica",
",",
"0",
")",
",",
"}",
"\n",
"return",
"agent",
"\n",
"}"
] | // NewAgent builds new Agent objects. | [
"NewAgent",
"builds",
"new",
"Agent",
"objects",
"."
] | 635ca6035f2355e29fc558effa613d0d5867aac8 | https://github.com/yvasiyarov/gorelic/blob/635ca6035f2355e29fc558effa613d0d5867aac8/agent.go#L66-L81 |
15,395 | yvasiyarov/gorelic | agent.go | ClearSentData | func (c resettableComponent) ClearSentData() {
c.IComponent.ClearSentData()
for _, counter := range c.counters {
counter.Clear()
}
} | go | func (c resettableComponent) ClearSentData() {
c.IComponent.ClearSentData()
for _, counter := range c.counters {
counter.Clear()
}
} | [
"func",
"(",
"c",
"resettableComponent",
")",
"ClearSentData",
"(",
")",
"{",
"c",
".",
"IComponent",
".",
"ClearSentData",
"(",
")",
"\n",
"for",
"_",
",",
"counter",
":=",
"range",
"c",
".",
"counters",
"{",
"counter",
".",
"Clear",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // newrelic_platform_go.IComponent interface implementation | [
"newrelic_platform_go",
".",
"IComponent",
"interface",
"implementation"
] | 635ca6035f2355e29fc558effa613d0d5867aac8 | https://github.com/yvasiyarov/gorelic/blob/635ca6035f2355e29fc558effa613d0d5867aac8/agent.go#L90-L95 |
15,396 | yvasiyarov/gorelic | agent.go | WrapHTTPHandlerFunc | func (agent *Agent) WrapHTTPHandlerFunc(h tHTTPHandlerFunc) tHTTPHandlerFunc {
agent.CollectHTTPStat = true
agent.initTimer()
return func(w http.ResponseWriter, req *http.Request) {
proxy := newHTTPHandlerFunc(h)
proxy.timer = agent.HTTPTimer
//set the http status counters before serving request.
proxy.httpStatusCounters = agent.HTTPStatusCounters
proxy.ServeHTTP(w, req)
}
} | go | func (agent *Agent) WrapHTTPHandlerFunc(h tHTTPHandlerFunc) tHTTPHandlerFunc {
agent.CollectHTTPStat = true
agent.initTimer()
return func(w http.ResponseWriter, req *http.Request) {
proxy := newHTTPHandlerFunc(h)
proxy.timer = agent.HTTPTimer
//set the http status counters before serving request.
proxy.httpStatusCounters = agent.HTTPStatusCounters
proxy.ServeHTTP(w, req)
}
} | [
"func",
"(",
"agent",
"*",
"Agent",
")",
"WrapHTTPHandlerFunc",
"(",
"h",
"tHTTPHandlerFunc",
")",
"tHTTPHandlerFunc",
"{",
"agent",
".",
"CollectHTTPStat",
"=",
"true",
"\n",
"agent",
".",
"initTimer",
"(",
")",
"\n",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"proxy",
":=",
"newHTTPHandlerFunc",
"(",
"h",
")",
"\n",
"proxy",
".",
"timer",
"=",
"agent",
".",
"HTTPTimer",
"\n",
"//set the http status counters before serving request.",
"proxy",
".",
"httpStatusCounters",
"=",
"agent",
".",
"HTTPStatusCounters",
"\n",
"proxy",
".",
"ServeHTTP",
"(",
"w",
",",
"req",
")",
"\n",
"}",
"\n",
"}"
] | //WrapHTTPHandlerFunc instrument HTTP handler functions to collect HTTP metrics | [
"WrapHTTPHandlerFunc",
"instrument",
"HTTP",
"handler",
"functions",
"to",
"collect",
"HTTP",
"metrics"
] | 635ca6035f2355e29fc558effa613d0d5867aac8 | https://github.com/yvasiyarov/gorelic/blob/635ca6035f2355e29fc558effa613d0d5867aac8/agent.go#L98-L108 |
15,397 | yvasiyarov/gorelic | agent.go | WrapHTTPHandler | func (agent *Agent) WrapHTTPHandler(h http.Handler) http.Handler {
agent.CollectHTTPStat = true
agent.initTimer()
proxy := newHTTPHandler(h)
proxy.timer = agent.HTTPTimer
return proxy
} | go | func (agent *Agent) WrapHTTPHandler(h http.Handler) http.Handler {
agent.CollectHTTPStat = true
agent.initTimer()
proxy := newHTTPHandler(h)
proxy.timer = agent.HTTPTimer
return proxy
} | [
"func",
"(",
"agent",
"*",
"Agent",
")",
"WrapHTTPHandler",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"agent",
".",
"CollectHTTPStat",
"=",
"true",
"\n",
"agent",
".",
"initTimer",
"(",
")",
"\n\n",
"proxy",
":=",
"newHTTPHandler",
"(",
"h",
")",
"\n",
"proxy",
".",
"timer",
"=",
"agent",
".",
"HTTPTimer",
"\n",
"return",
"proxy",
"\n",
"}"
] | //WrapHTTPHandler instrument HTTP handler object to collect HTTP metrics | [
"WrapHTTPHandler",
"instrument",
"HTTP",
"handler",
"object",
"to",
"collect",
"HTTP",
"metrics"
] | 635ca6035f2355e29fc558effa613d0d5867aac8 | https://github.com/yvasiyarov/gorelic/blob/635ca6035f2355e29fc558effa613d0d5867aac8/agent.go#L111-L118 |
15,398 | yvasiyarov/gorelic | agent.go | AddCustomMetric | func (agent *Agent) AddCustomMetric(metric newrelic_platform_go.IMetrica) {
agent.CustomMetrics = append(agent.CustomMetrics, metric)
} | go | func (agent *Agent) AddCustomMetric(metric newrelic_platform_go.IMetrica) {
agent.CustomMetrics = append(agent.CustomMetrics, metric)
} | [
"func",
"(",
"agent",
"*",
"Agent",
")",
"AddCustomMetric",
"(",
"metric",
"newrelic_platform_go",
".",
"IMetrica",
")",
"{",
"agent",
".",
"CustomMetrics",
"=",
"append",
"(",
"agent",
".",
"CustomMetrics",
",",
"metric",
")",
"\n",
"}"
] | //AddCustomMetric adds metric to be collected periodically with NewrelicPollInterval interval | [
"AddCustomMetric",
"adds",
"metric",
"to",
"be",
"collected",
"periodically",
"with",
"NewrelicPollInterval",
"interval"
] | 635ca6035f2355e29fc558effa613d0d5867aac8 | https://github.com/yvasiyarov/gorelic/blob/635ca6035f2355e29fc558effa613d0d5867aac8/agent.go#L121-L123 |
15,399 | yvasiyarov/gorelic | agent.go | Run | func (agent *Agent) Run() error {
if agent.NewrelicLicense == "" {
return errors.New("please, pass a valid newrelic license key")
}
var component newrelic_platform_go.IComponent
component = newrelic_platform_go.NewPluginComponent(agent.NewrelicName, agent.AgentGUID, agent.Verbose)
// Add default metrics and tracer.
addRuntimeMericsToComponent(component)
agent.Tracer = newTracer(component)
// Check agent flags and add relevant metrics.
if agent.CollectGcStat {
addGCMetricsToComponent(component, agent.GCPollInterval)
agent.debug(fmt.Sprintf("Init GC metrics collection. Poll interval %d seconds.", agent.GCPollInterval))
}
if agent.CollectMemoryStat {
addMemoryMericsToComponent(component, agent.MemoryAllocatorPollInterval)
agent.debug(fmt.Sprintf("Init memory allocator metrics collection. Poll interval %d seconds.", agent.MemoryAllocatorPollInterval))
}
if agent.CollectHTTPStat {
agent.initTimer()
addHTTPMericsToComponent(component, agent.HTTPTimer)
agent.debug(fmt.Sprintf("Init HTTP metrics collection."))
}
for _, metric := range agent.CustomMetrics {
component.AddMetrica(metric)
agent.debug(fmt.Sprintf("Init %s metric collection.", metric.GetName()))
}
if agent.CollectHTTPStatuses {
agent.initStatusCounters()
component = &resettableComponent{component, agent.HTTPStatusCounters}
addHTTPStatusMetricsToComponent(component, agent.HTTPStatusCounters)
agent.debug(fmt.Sprintf("Init HTTP status metrics collection."))
}
// Init newrelic reporting plugin.
agent.plugin = newrelic_platform_go.NewNewrelicPlugin(agent.AgentVersion, agent.NewrelicLicense, agent.NewrelicPollInterval)
agent.plugin.Client = agent.Client
agent.plugin.Verbose = agent.Verbose
// Add our metrics component to the plugin.
agent.plugin.AddComponent(component)
// Start reporting!
go agent.plugin.Run()
return nil
} | go | func (agent *Agent) Run() error {
if agent.NewrelicLicense == "" {
return errors.New("please, pass a valid newrelic license key")
}
var component newrelic_platform_go.IComponent
component = newrelic_platform_go.NewPluginComponent(agent.NewrelicName, agent.AgentGUID, agent.Verbose)
// Add default metrics and tracer.
addRuntimeMericsToComponent(component)
agent.Tracer = newTracer(component)
// Check agent flags and add relevant metrics.
if agent.CollectGcStat {
addGCMetricsToComponent(component, agent.GCPollInterval)
agent.debug(fmt.Sprintf("Init GC metrics collection. Poll interval %d seconds.", agent.GCPollInterval))
}
if agent.CollectMemoryStat {
addMemoryMericsToComponent(component, agent.MemoryAllocatorPollInterval)
agent.debug(fmt.Sprintf("Init memory allocator metrics collection. Poll interval %d seconds.", agent.MemoryAllocatorPollInterval))
}
if agent.CollectHTTPStat {
agent.initTimer()
addHTTPMericsToComponent(component, agent.HTTPTimer)
agent.debug(fmt.Sprintf("Init HTTP metrics collection."))
}
for _, metric := range agent.CustomMetrics {
component.AddMetrica(metric)
agent.debug(fmt.Sprintf("Init %s metric collection.", metric.GetName()))
}
if agent.CollectHTTPStatuses {
agent.initStatusCounters()
component = &resettableComponent{component, agent.HTTPStatusCounters}
addHTTPStatusMetricsToComponent(component, agent.HTTPStatusCounters)
agent.debug(fmt.Sprintf("Init HTTP status metrics collection."))
}
// Init newrelic reporting plugin.
agent.plugin = newrelic_platform_go.NewNewrelicPlugin(agent.AgentVersion, agent.NewrelicLicense, agent.NewrelicPollInterval)
agent.plugin.Client = agent.Client
agent.plugin.Verbose = agent.Verbose
// Add our metrics component to the plugin.
agent.plugin.AddComponent(component)
// Start reporting!
go agent.plugin.Run()
return nil
} | [
"func",
"(",
"agent",
"*",
"Agent",
")",
"Run",
"(",
")",
"error",
"{",
"if",
"agent",
".",
"NewrelicLicense",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"component",
"newrelic_platform_go",
".",
"IComponent",
"\n",
"component",
"=",
"newrelic_platform_go",
".",
"NewPluginComponent",
"(",
"agent",
".",
"NewrelicName",
",",
"agent",
".",
"AgentGUID",
",",
"agent",
".",
"Verbose",
")",
"\n\n",
"// Add default metrics and tracer.",
"addRuntimeMericsToComponent",
"(",
"component",
")",
"\n",
"agent",
".",
"Tracer",
"=",
"newTracer",
"(",
"component",
")",
"\n\n",
"// Check agent flags and add relevant metrics.",
"if",
"agent",
".",
"CollectGcStat",
"{",
"addGCMetricsToComponent",
"(",
"component",
",",
"agent",
".",
"GCPollInterval",
")",
"\n",
"agent",
".",
"debug",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"agent",
".",
"GCPollInterval",
")",
")",
"\n",
"}",
"\n\n",
"if",
"agent",
".",
"CollectMemoryStat",
"{",
"addMemoryMericsToComponent",
"(",
"component",
",",
"agent",
".",
"MemoryAllocatorPollInterval",
")",
"\n",
"agent",
".",
"debug",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"agent",
".",
"MemoryAllocatorPollInterval",
")",
")",
"\n",
"}",
"\n\n",
"if",
"agent",
".",
"CollectHTTPStat",
"{",
"agent",
".",
"initTimer",
"(",
")",
"\n",
"addHTTPMericsToComponent",
"(",
"component",
",",
"agent",
".",
"HTTPTimer",
")",
"\n",
"agent",
".",
"debug",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"metric",
":=",
"range",
"agent",
".",
"CustomMetrics",
"{",
"component",
".",
"AddMetrica",
"(",
"metric",
")",
"\n",
"agent",
".",
"debug",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"metric",
".",
"GetName",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"if",
"agent",
".",
"CollectHTTPStatuses",
"{",
"agent",
".",
"initStatusCounters",
"(",
")",
"\n",
"component",
"=",
"&",
"resettableComponent",
"{",
"component",
",",
"agent",
".",
"HTTPStatusCounters",
"}",
"\n",
"addHTTPStatusMetricsToComponent",
"(",
"component",
",",
"agent",
".",
"HTTPStatusCounters",
")",
"\n",
"agent",
".",
"debug",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"// Init newrelic reporting plugin.",
"agent",
".",
"plugin",
"=",
"newrelic_platform_go",
".",
"NewNewrelicPlugin",
"(",
"agent",
".",
"AgentVersion",
",",
"agent",
".",
"NewrelicLicense",
",",
"agent",
".",
"NewrelicPollInterval",
")",
"\n",
"agent",
".",
"plugin",
".",
"Client",
"=",
"agent",
".",
"Client",
"\n",
"agent",
".",
"plugin",
".",
"Verbose",
"=",
"agent",
".",
"Verbose",
"\n\n",
"// Add our metrics component to the plugin.",
"agent",
".",
"plugin",
".",
"AddComponent",
"(",
"component",
")",
"\n\n",
"// Start reporting!",
"go",
"agent",
".",
"plugin",
".",
"Run",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | //Run initialize Agent instance and start harvest go routine | [
"Run",
"initialize",
"Agent",
"instance",
"and",
"start",
"harvest",
"go",
"routine"
] | 635ca6035f2355e29fc558effa613d0d5867aac8 | https://github.com/yvasiyarov/gorelic/blob/635ca6035f2355e29fc558effa613d0d5867aac8/agent.go#L126-L178 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.