repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
securego/gosec
rules/archive.go
NewArchive
func NewArchive(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { calls := gosec.NewCallList() calls.Add("path/filepath", "Join") return &archive{ calls: calls, argType: "*archive/zip.File", MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: ...
go
func NewArchive(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { calls := gosec.NewCallList() calls.Add("path/filepath", "Join") return &archive{ calls: calls, argType: "*archive/zip.File", MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medium, Confidence: gosec.High, What: ...
[ "func", "NewArchive", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "calls", ":=", "gosec", ".", "NewCallList", "(", ")", "\n", "calls", ".", "Add", "(", "\"...
// NewArchive creates a new rule which detects the file traversal when extracting zip archives
[ "NewArchive", "creates", "a", "new", "rule", "which", "detects", "the", "file", "traversal", "when", "extracting", "zip", "archives" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/archive.go#L47-L60
train
securego/gosec
call_list.go
AddAll
func (c CallList) AddAll(selector string, idents ...string) { for _, ident := range idents { c.Add(selector, ident) } }
go
func (c CallList) AddAll(selector string, idents ...string) { for _, ident := range idents { c.Add(selector, ident) } }
[ "func", "(", "c", "CallList", ")", "AddAll", "(", "selector", "string", ",", "idents", "...", "string", ")", "{", "for", "_", ",", "ident", ":=", "range", "idents", "{", "c", ".", "Add", "(", "selector", ",", "ident", ")", "\n", "}", "\n", "}" ]
// AddAll will add several calls to the call list at once
[ "AddAll", "will", "add", "several", "calls", "to", "the", "call", "list", "at", "once" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/call_list.go#L35-L39
train
securego/gosec
call_list.go
Add
func (c CallList) Add(selector, ident string) { if _, ok := c[selector]; !ok { c[selector] = make(set) } c[selector][ident] = true }
go
func (c CallList) Add(selector, ident string) { if _, ok := c[selector]; !ok { c[selector] = make(set) } c[selector][ident] = true }
[ "func", "(", "c", "CallList", ")", "Add", "(", "selector", ",", "ident", "string", ")", "{", "if", "_", ",", "ok", ":=", "c", "[", "selector", "]", ";", "!", "ok", "{", "c", "[", "selector", "]", "=", "make", "(", "set", ")", "\n", "}", "\n",...
// Add a selector and call to the call list
[ "Add", "a", "selector", "and", "call", "to", "the", "call", "list" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/call_list.go#L42-L47
train
securego/gosec
helpers.go
MatchCompLit
func MatchCompLit(n ast.Node, ctx *Context, required string) *ast.CompositeLit { if complit, ok := n.(*ast.CompositeLit); ok { typeOf := ctx.Info.TypeOf(complit) if typeOf.String() == required { return complit } } return nil }
go
func MatchCompLit(n ast.Node, ctx *Context, required string) *ast.CompositeLit { if complit, ok := n.(*ast.CompositeLit); ok { typeOf := ctx.Info.TypeOf(complit) if typeOf.String() == required { return complit } } return nil }
[ "func", "MatchCompLit", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ",", "required", "string", ")", "*", "ast", ".", "CompositeLit", "{", "if", "complit", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "CompositeLit", ")", ";", "ok"...
// MatchCompLit will match an ast.CompositeLit based on the supplied type
[ "MatchCompLit", "will", "match", "an", "ast", ".", "CompositeLit", "based", "on", "the", "supplied", "type" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L86-L94
train
securego/gosec
helpers.go
GetInt
func GetInt(n ast.Node) (int64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.INT { return strconv.ParseInt(node.Value, 0, 64) } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetInt(n ast.Node) (int64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.INT { return strconv.ParseInt(node.Value, 0, 64) } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetInt", "(", "n", "ast", ".", "Node", ")", "(", "int64", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "INT", "{", ...
// GetInt will read and return an integer value from an ast.BasicLit
[ "GetInt", "will", "read", "and", "return", "an", "integer", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L97-L102
train
securego/gosec
helpers.go
GetFloat
func GetFloat(n ast.Node) (float64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.FLOAT { return strconv.ParseFloat(node.Value, 64) } return 0.0, fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetFloat(n ast.Node) (float64, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.FLOAT { return strconv.ParseFloat(node.Value, 64) } return 0.0, fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetFloat", "(", "n", "ast", ".", "Node", ")", "(", "float64", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "FLOAT", ...
// GetFloat will read and return a float value from an ast.BasicLit
[ "GetFloat", "will", "read", "and", "return", "a", "float", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L105-L110
train
securego/gosec
helpers.go
GetChar
func GetChar(n ast.Node) (byte, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.CHAR { return node.Value[0], nil } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetChar(n ast.Node) (byte, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.CHAR { return node.Value[0], nil } return 0, fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetChar", "(", "n", "ast", ".", "Node", ")", "(", "byte", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "CHAR", "{", ...
// GetChar will read and return a char value from an ast.BasicLit
[ "GetChar", "will", "read", "and", "return", "a", "char", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L113-L118
train
securego/gosec
helpers.go
GetString
func GetString(n ast.Node) (string, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.STRING { return strconv.Unquote(node.Value) } return "", fmt.Errorf("Unexpected AST node type: %T", n) }
go
func GetString(n ast.Node) (string, error) { if node, ok := n.(*ast.BasicLit); ok && node.Kind == token.STRING { return strconv.Unquote(node.Value) } return "", fmt.Errorf("Unexpected AST node type: %T", n) }
[ "func", "GetString", "(", "n", "ast", ".", "Node", ")", "(", "string", ",", "error", ")", "{", "if", "node", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "BasicLit", ")", ";", "ok", "&&", "node", ".", "Kind", "==", "token", ".", "STRING", ...
// GetString will read and return a string value from an ast.BasicLit
[ "GetString", "will", "read", "and", "return", "a", "string", "value", "from", "an", "ast", ".", "BasicLit" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L121-L126
train
securego/gosec
helpers.go
GetCallObject
func GetCallObject(n ast.Node, ctx *Context) (*ast.CallExpr, types.Object) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.Ident: return node, ctx.Info.Uses[fn] case *ast.SelectorExpr: return node, ctx.Info.Uses[fn.Sel] } } return nil, nil }
go
func GetCallObject(n ast.Node, ctx *Context) (*ast.CallExpr, types.Object) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.Ident: return node, ctx.Info.Uses[fn] case *ast.SelectorExpr: return node, ctx.Info.Uses[fn.Sel] } } return nil, nil }
[ "func", "GetCallObject", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "(", "*", "ast", ".", "CallExpr", ",", "types", ".", "Object", ")", "{", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "...
// GetCallObject returns the object and call expression and associated // object for a given AST node. nil, nil will be returned if the // object cannot be resolved.
[ "GetCallObject", "returns", "the", "object", "and", "call", "expression", "and", "associated", "object", "for", "a", "given", "AST", "node", ".", "nil", "nil", "will", "be", "returned", "if", "the", "object", "cannot", "be", "resolved", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L131-L142
train
securego/gosec
helpers.go
GetCallInfo
func GetCallInfo(n ast.Node, ctx *Context) (string, string, error) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.SelectorExpr: switch expr := fn.X.(type) { case *ast.Ident: if expr.Obj != nil && expr.Obj.Kind == ast.Var { t := ctx.Info.TypeOf(expr) if...
go
func GetCallInfo(n ast.Node, ctx *Context) (string, string, error) { switch node := n.(type) { case *ast.CallExpr: switch fn := node.Fun.(type) { case *ast.SelectorExpr: switch expr := fn.X.(type) { case *ast.Ident: if expr.Obj != nil && expr.Obj.Kind == ast.Var { t := ctx.Info.TypeOf(expr) if...
[ "func", "GetCallInfo", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "(", "string", ",", "string", ",", "error", ")", "{", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "CallExpr", ":", "switch...
// GetCallInfo returns the package or type and name associated with a // call expression.
[ "GetCallInfo", "returns", "the", "package", "or", "type", "and", "name", "associated", "with", "a", "call", "expression", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L146-L167
train
securego/gosec
helpers.go
GetCallStringArgsValues
func GetCallStringArgsValues(n ast.Node, ctx *Context) []string { values := []string{} switch node := n.(type) { case *ast.CallExpr: for _, arg := range node.Args { switch param := arg.(type) { case *ast.BasicLit: value, err := GetString(param) if err == nil { values = append(values, value) ...
go
func GetCallStringArgsValues(n ast.Node, ctx *Context) []string { values := []string{} switch node := n.(type) { case *ast.CallExpr: for _, arg := range node.Args { switch param := arg.(type) { case *ast.BasicLit: value, err := GetString(param) if err == nil { values = append(values, value) ...
[ "func", "GetCallStringArgsValues", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "[", "]", "string", "{", "values", ":=", "[", "]", "string", "{", "}", "\n", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "...
// GetCallStringArgsValues returns the values of strings arguments if they can be resolved
[ "GetCallStringArgsValues", "returns", "the", "values", "of", "strings", "arguments", "if", "they", "can", "be", "resolved" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L170-L187
train
securego/gosec
helpers.go
GetIdentStringValues
func GetIdentStringValues(ident *ast.Ident) []string { values := []string{} obj := ident.Obj if obj != nil { switch decl := obj.Decl.(type) { case *ast.ValueSpec: for _, v := range decl.Values { value, err := GetString(v) if err == nil { values = append(values, value) } } case *ast.Assig...
go
func GetIdentStringValues(ident *ast.Ident) []string { values := []string{} obj := ident.Obj if obj != nil { switch decl := obj.Decl.(type) { case *ast.ValueSpec: for _, v := range decl.Values { value, err := GetString(v) if err == nil { values = append(values, value) } } case *ast.Assig...
[ "func", "GetIdentStringValues", "(", "ident", "*", "ast", ".", "Ident", ")", "[", "]", "string", "{", "values", ":=", "[", "]", "string", "{", "}", "\n", "obj", ":=", "ident", ".", "Obj", "\n", "if", "obj", "!=", "nil", "{", "switch", "decl", ":=",...
// GetIdentStringValues return the string values of an Ident if they can be resolved
[ "GetIdentStringValues", "return", "the", "string", "values", "of", "an", "Ident", "if", "they", "can", "be", "resolved" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L190-L213
train
securego/gosec
helpers.go
GetImportedName
func GetImportedName(path string, ctx *Context) (string, bool) { importName, imported := ctx.Imports.Imported[path] if !imported { return "", false } if _, initonly := ctx.Imports.InitOnly[path]; initonly { return "", false } if alias, ok := ctx.Imports.Aliased[path]; ok { importName = alias } return im...
go
func GetImportedName(path string, ctx *Context) (string, bool) { importName, imported := ctx.Imports.Imported[path] if !imported { return "", false } if _, initonly := ctx.Imports.InitOnly[path]; initonly { return "", false } if alias, ok := ctx.Imports.Aliased[path]; ok { importName = alias } return im...
[ "func", "GetImportedName", "(", "path", "string", ",", "ctx", "*", "Context", ")", "(", "string", ",", "bool", ")", "{", "importName", ",", "imported", ":=", "ctx", ".", "Imports", ".", "Imported", "[", "path", "]", "\n", "if", "!", "imported", "{", ...
// GetImportedName returns the name used for the package within the // code. It will resolve aliases and ignores initialization only imports.
[ "GetImportedName", "returns", "the", "name", "used", "for", "the", "package", "within", "the", "code", ".", "It", "will", "resolve", "aliases", "and", "ignores", "initialization", "only", "imports", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L217-L231
train
securego/gosec
helpers.go
GetImportPath
func GetImportPath(name string, ctx *Context) (string, bool) { for path := range ctx.Imports.Imported { if imported, ok := GetImportedName(path, ctx); ok && imported == name { return path, true } } return "", false }
go
func GetImportPath(name string, ctx *Context) (string, bool) { for path := range ctx.Imports.Imported { if imported, ok := GetImportedName(path, ctx); ok && imported == name { return path, true } } return "", false }
[ "func", "GetImportPath", "(", "name", "string", ",", "ctx", "*", "Context", ")", "(", "string", ",", "bool", ")", "{", "for", "path", ":=", "range", "ctx", ".", "Imports", ".", "Imported", "{", "if", "imported", ",", "ok", ":=", "GetImportedName", "(",...
// GetImportPath resolves the full import path of an identifier based on // the imports in the current context.
[ "GetImportPath", "resolves", "the", "full", "import", "path", "of", "an", "identifier", "based", "on", "the", "imports", "in", "the", "current", "context", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L235-L242
train
securego/gosec
helpers.go
GetLocation
func GetLocation(n ast.Node, ctx *Context) (string, int) { fobj := ctx.FileSet.File(n.Pos()) return fobj.Name(), fobj.Line(n.Pos()) }
go
func GetLocation(n ast.Node, ctx *Context) (string, int) { fobj := ctx.FileSet.File(n.Pos()) return fobj.Name(), fobj.Line(n.Pos()) }
[ "func", "GetLocation", "(", "n", "ast", ".", "Node", ",", "ctx", "*", "Context", ")", "(", "string", ",", "int", ")", "{", "fobj", ":=", "ctx", ".", "FileSet", ".", "File", "(", "n", ".", "Pos", "(", ")", ")", "\n", "return", "fobj", ".", "Name...
// GetLocation returns the filename and line number of an ast.Node
[ "GetLocation", "returns", "the", "filename", "and", "line", "number", "of", "an", "ast", ".", "Node" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L245-L248
train
securego/gosec
helpers.go
Gopath
func Gopath() []string { defaultGoPath := runtime.GOROOT() if u, err := user.Current(); err == nil { defaultGoPath = filepath.Join(u.HomeDir, "go") } path := Getenv("GOPATH", defaultGoPath) paths := strings.Split(path, string(os.PathListSeparator)) for idx, path := range paths { if abs, err := filepath.Abs(pa...
go
func Gopath() []string { defaultGoPath := runtime.GOROOT() if u, err := user.Current(); err == nil { defaultGoPath = filepath.Join(u.HomeDir, "go") } path := Getenv("GOPATH", defaultGoPath) paths := strings.Split(path, string(os.PathListSeparator)) for idx, path := range paths { if abs, err := filepath.Abs(pa...
[ "func", "Gopath", "(", ")", "[", "]", "string", "{", "defaultGoPath", ":=", "runtime", ".", "GOROOT", "(", ")", "\n", "if", "u", ",", "err", ":=", "user", ".", "Current", "(", ")", ";", "err", "==", "nil", "{", "defaultGoPath", "=", "filepath", "."...
// Gopath returns all GOPATHs
[ "Gopath", "returns", "all", "GOPATHs" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L251-L264
train
securego/gosec
helpers.go
Getenv
func Getenv(key, userDefault string) string { if val := os.Getenv(key); val != "" { return val } return userDefault }
go
func Getenv(key, userDefault string) string { if val := os.Getenv(key); val != "" { return val } return userDefault }
[ "func", "Getenv", "(", "key", ",", "userDefault", "string", ")", "string", "{", "if", "val", ":=", "os", ".", "Getenv", "(", "key", ")", ";", "val", "!=", "\"", "\"", "{", "return", "val", "\n", "}", "\n", "return", "userDefault", "\n", "}" ]
// Getenv returns the values of the environment variable, otherwise //returns the default if variable is not set
[ "Getenv", "returns", "the", "values", "of", "the", "environment", "variable", "otherwise", "returns", "the", "default", "if", "variable", "is", "not", "set" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L268-L273
train
securego/gosec
helpers.go
GetPkgRelativePath
func GetPkgRelativePath(path string) (string, error) { abspath, err := filepath.Abs(path) if err != nil { abspath = path } if strings.HasSuffix(abspath, ".go") { abspath = filepath.Dir(abspath) } for _, base := range Gopath() { projectRoot := filepath.FromSlash(fmt.Sprintf("%s/src/", base)) if strings.Has...
go
func GetPkgRelativePath(path string) (string, error) { abspath, err := filepath.Abs(path) if err != nil { abspath = path } if strings.HasSuffix(abspath, ".go") { abspath = filepath.Dir(abspath) } for _, base := range Gopath() { projectRoot := filepath.FromSlash(fmt.Sprintf("%s/src/", base)) if strings.Has...
[ "func", "GetPkgRelativePath", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "abspath", ",", "err", ":=", "filepath", ".", "Abs", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "abspath", "=", "path", "\n", "}", "\n", "i...
// GetPkgRelativePath returns the Go relative relative path derived // form the given path
[ "GetPkgRelativePath", "returns", "the", "Go", "relative", "relative", "path", "derived", "form", "the", "given", "path" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L277-L292
train
securego/gosec
helpers.go
GetPkgAbsPath
func GetPkgAbsPath(pkgPath string) (string, error) { absPath, err := filepath.Abs(pkgPath) if err != nil { return "", err } if _, err := os.Stat(absPath); os.IsNotExist(err) { return "", errors.New("no project absolute path found") } return absPath, nil }
go
func GetPkgAbsPath(pkgPath string) (string, error) { absPath, err := filepath.Abs(pkgPath) if err != nil { return "", err } if _, err := os.Stat(absPath); os.IsNotExist(err) { return "", errors.New("no project absolute path found") } return absPath, nil }
[ "func", "GetPkgAbsPath", "(", "pkgPath", "string", ")", "(", "string", ",", "error", ")", "{", "absPath", ",", "err", ":=", "filepath", ".", "Abs", "(", "pkgPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}...
// GetPkgAbsPath returns the Go package absolute path derived from // the given path
[ "GetPkgAbsPath", "returns", "the", "Go", "package", "absolute", "path", "derived", "from", "the", "given", "path" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L296-L305
train
securego/gosec
helpers.go
ConcatString
func ConcatString(n *ast.BinaryExpr) (string, bool) { var s string // sub expressions are found in X object, Y object is always last BasicLit if rightOperand, ok := n.Y.(*ast.BasicLit); ok { if str, err := GetString(rightOperand); err == nil { s = str + s } } else { return "", false } if leftOperand, ok ...
go
func ConcatString(n *ast.BinaryExpr) (string, bool) { var s string // sub expressions are found in X object, Y object is always last BasicLit if rightOperand, ok := n.Y.(*ast.BasicLit); ok { if str, err := GetString(rightOperand); err == nil { s = str + s } } else { return "", false } if leftOperand, ok ...
[ "func", "ConcatString", "(", "n", "*", "ast", ".", "BinaryExpr", ")", "(", "string", ",", "bool", ")", "{", "var", "s", "string", "\n", "// sub expressions are found in X object, Y object is always last BasicLit", "if", "rightOperand", ",", "ok", ":=", "n", ".", ...
// ConcatString recursively concatenates strings from a binary expression
[ "ConcatString", "recursively", "concatenates", "strings", "from", "a", "binary", "expression" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L308-L330
train
securego/gosec
helpers.go
FindVarIdentities
func FindVarIdentities(n *ast.BinaryExpr, c *Context) ([]*ast.Ident, bool) { identities := []*ast.Ident{} // sub expressions are found in X object, Y object is always the last term if rightOperand, ok := n.Y.(*ast.Ident); ok { obj := c.Info.ObjectOf(rightOperand) if _, ok := obj.(*types.Var); ok && !TryResolve(r...
go
func FindVarIdentities(n *ast.BinaryExpr, c *Context) ([]*ast.Ident, bool) { identities := []*ast.Ident{} // sub expressions are found in X object, Y object is always the last term if rightOperand, ok := n.Y.(*ast.Ident); ok { obj := c.Info.ObjectOf(rightOperand) if _, ok := obj.(*types.Var); ok && !TryResolve(r...
[ "func", "FindVarIdentities", "(", "n", "*", "ast", ".", "BinaryExpr", ",", "c", "*", "Context", ")", "(", "[", "]", "*", "ast", ".", "Ident", ",", "bool", ")", "{", "identities", ":=", "[", "]", "*", "ast", ".", "Ident", "{", "}", "\n", "// sub e...
// FindVarIdentities returns array of all variable identities in a given binary expression
[ "FindVarIdentities", "returns", "array", "of", "all", "variable", "identities", "in", "a", "given", "binary", "expression" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L333-L360
train
securego/gosec
helpers.go
PackagePaths
func PackagePaths(root string, exclude *regexp.Regexp) ([]string, error) { if strings.HasSuffix(root, "...") { root = root[0 : len(root)-3] } else { return []string{root}, nil } paths := map[string]bool{} err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error { if filepath.Ext(path) == ...
go
func PackagePaths(root string, exclude *regexp.Regexp) ([]string, error) { if strings.HasSuffix(root, "...") { root = root[0 : len(root)-3] } else { return []string{root}, nil } paths := map[string]bool{} err := filepath.Walk(root, func(path string, f os.FileInfo, err error) error { if filepath.Ext(path) == ...
[ "func", "PackagePaths", "(", "root", "string", ",", "exclude", "*", "regexp", ".", "Regexp", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "strings", ".", "HasSuffix", "(", "root", ",", "\"", "\"", ")", "{", "root", "=", "root", "[", ...
// PackagePaths returns a slice with all packages path at given root directory
[ "PackagePaths", "returns", "a", "slice", "with", "all", "packages", "path", "at", "given", "root", "directory" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/helpers.go#L363-L389
train
securego/gosec
rules/tls_config.go
NewModernTLSCheck
func NewModernTLSCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &insecureConfigTLS{ MetaData: gosec.MetaData{ID: id}, requiredType: "crypto/tls.Config", MinVersion: 0x0303, MaxVersion: 0x0303, goodCiphers: []string{ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RS...
go
func NewModernTLSCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &insecureConfigTLS{ MetaData: gosec.MetaData{ID: id}, requiredType: "crypto/tls.Config", MinVersion: 0x0303, MaxVersion: 0x0303, goodCiphers: []string{ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RS...
[ "func", "NewModernTLSCheck", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "return", "&", "insecureConfigTLS", "{", "MetaData", ":", "gosec", ".", "MetaData", "{",...
// NewModernTLSCheck creates a check for Modern TLS ciphers // DO NOT EDIT - generated by tlsconfig tool
[ "NewModernTLSCheck", "creates", "a", "check", "for", "Modern", "TLS", "ciphers", "DO", "NOT", "EDIT", "-", "generated", "by", "tlsconfig", "tool" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/tls_config.go#L11-L30
train
securego/gosec
rule.go
Register
func (r RuleSet) Register(rule Rule, nodes ...ast.Node) { for _, n := range nodes { t := reflect.TypeOf(n) if rules, ok := r[t]; ok { r[t] = append(rules, rule) } else { r[t] = []Rule{rule} } } }
go
func (r RuleSet) Register(rule Rule, nodes ...ast.Node) { for _, n := range nodes { t := reflect.TypeOf(n) if rules, ok := r[t]; ok { r[t] = append(rules, rule) } else { r[t] = []Rule{rule} } } }
[ "func", "(", "r", "RuleSet", ")", "Register", "(", "rule", "Rule", ",", "nodes", "...", "ast", ".", "Node", ")", "{", "for", "_", ",", "n", ":=", "range", "nodes", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "n", ")", "\n", "if", "rules", ",...
// Register adds a trigger for the supplied rule for the the // specified ast nodes.
[ "Register", "adds", "a", "trigger", "for", "the", "supplied", "rule", "for", "the", "the", "specified", "ast", "nodes", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rule.go#L41-L50
train
securego/gosec
rule.go
RegisteredFor
func (r RuleSet) RegisteredFor(n ast.Node) []Rule { if rules, found := r[reflect.TypeOf(n)]; found { return rules } return []Rule{} }
go
func (r RuleSet) RegisteredFor(n ast.Node) []Rule { if rules, found := r[reflect.TypeOf(n)]; found { return rules } return []Rule{} }
[ "func", "(", "r", "RuleSet", ")", "RegisteredFor", "(", "n", "ast", ".", "Node", ")", "[", "]", "Rule", "{", "if", "rules", ",", "found", ":=", "r", "[", "reflect", ".", "TypeOf", "(", "n", ")", "]", ";", "found", "{", "return", "rules", "\n", ...
// RegisteredFor will return all rules that are registered for a // specified ast node.
[ "RegisteredFor", "will", "return", "all", "rules", "that", "are", "registered", "for", "a", "specified", "ast", "node", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rule.go#L54-L59
train
securego/gosec
rules/sql.go
MatchPatterns
func (s *sqlStatement) MatchPatterns(str string) bool { for _, pattern := range s.patterns { if !pattern.MatchString(str) { return false } } return true }
go
func (s *sqlStatement) MatchPatterns(str string) bool { for _, pattern := range s.patterns { if !pattern.MatchString(str) { return false } } return true }
[ "func", "(", "s", "*", "sqlStatement", ")", "MatchPatterns", "(", "str", "string", ")", "bool", "{", "for", "_", ",", "pattern", ":=", "range", "s", ".", "patterns", "{", "if", "!", "pattern", ".", "MatchString", "(", "str", ")", "{", "return", "fals...
// See if the string matches the patterns for the statement.
[ "See", "if", "the", "string", "matches", "the", "patterns", "for", "the", "statement", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/sql.go#L36-L43
train
securego/gosec
rules/sql.go
checkObject
func (s *sqlStrConcat) checkObject(n *ast.Ident, c *gosec.Context) bool { if n.Obj != nil { return n.Obj.Kind != ast.Var && n.Obj.Kind != ast.Fun } // Try to resolve unresolved identifiers using other files in same package for _, file := range c.PkgFiles { if node, ok := file.Scope.Objects[n.String()]; ok { ...
go
func (s *sqlStrConcat) checkObject(n *ast.Ident, c *gosec.Context) bool { if n.Obj != nil { return n.Obj.Kind != ast.Var && n.Obj.Kind != ast.Fun } // Try to resolve unresolved identifiers using other files in same package for _, file := range c.PkgFiles { if node, ok := file.Scope.Objects[n.String()]; ok { ...
[ "func", "(", "s", "*", "sqlStrConcat", ")", "checkObject", "(", "n", "*", "ast", ".", "Ident", ",", "c", "*", "gosec", ".", "Context", ")", "bool", "{", "if", "n", ".", "Obj", "!=", "nil", "{", "return", "n", ".", "Obj", ".", "Kind", "!=", "ast...
// see if we can figure out what it is
[ "see", "if", "we", "can", "figure", "out", "what", "it", "is" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/sql.go#L54-L66
train
securego/gosec
rules/sql.go
NewSQLStrConcat
func NewSQLStrConcat(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &sqlStrConcat{ sqlStatement: sqlStatement{ patterns: []*regexp.Regexp{ regexp.MustCompile(`(?)(SELECT|DELETE|INSERT|UPDATE|INTO|FROM|WHERE) `), }, MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medi...
go
func NewSQLStrConcat(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &sqlStrConcat{ sqlStatement: sqlStatement{ patterns: []*regexp.Regexp{ regexp.MustCompile(`(?)(SELECT|DELETE|INSERT|UPDATE|INTO|FROM|WHERE) `), }, MetaData: gosec.MetaData{ ID: id, Severity: gosec.Medi...
[ "func", "NewSQLStrConcat", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "return", "&", "sqlStrConcat", "{", "sqlStatement", ":", "sqlStatement", "{", "patterns", ...
// NewSQLStrConcat looks for cases where we are building SQL strings via concatenation
[ "NewSQLStrConcat", "looks", "for", "cases", "where", "we", "are", "building", "SQL", "strings", "via", "concatenation" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/sql.go#L90-L104
train
securego/gosec
rules/sql.go
NewSQLStrFormat
func NewSQLStrFormat(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { rule := &sqlStrFormat{ calls: gosec.NewCallList(), noIssue: gosec.NewCallList(), noIssueQuoted: gosec.NewCallList(), sqlStatement: sqlStatement{ patterns: []*regexp.Regexp{ regexp.MustCompile("(?)(SELECT|DELETE|I...
go
func NewSQLStrFormat(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { rule := &sqlStrFormat{ calls: gosec.NewCallList(), noIssue: gosec.NewCallList(), noIssueQuoted: gosec.NewCallList(), sqlStatement: sqlStatement{ patterns: []*regexp.Regexp{ regexp.MustCompile("(?)(SELECT|DELETE|I...
[ "func", "NewSQLStrFormat", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "rule", ":=", "&", "sqlStrFormat", "{", "calls", ":", "gosec", ".", "NewCallList", "(", ...
// NewSQLStrFormat looks for cases where we're building SQL query strings using format strings
[ "NewSQLStrFormat", "looks", "for", "cases", "where", "we", "re", "building", "SQL", "query", "strings", "using", "format", "strings" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/sql.go#L177-L199
train
securego/gosec
config.go
ReadFrom
func (c Config) ReadFrom(r io.Reader) (int64, error) { data, err := ioutil.ReadAll(r) if err != nil { return int64(len(data)), err } if err = json.Unmarshal(data, &c); err != nil { return int64(len(data)), err } return int64(len(data)), nil }
go
func (c Config) ReadFrom(r io.Reader) (int64, error) { data, err := ioutil.ReadAll(r) if err != nil { return int64(len(data)), err } if err = json.Unmarshal(data, &c); err != nil { return int64(len(data)), err } return int64(len(data)), nil }
[ "func", "(", "c", "Config", ")", "ReadFrom", "(", "r", "io", ".", "Reader", ")", "(", "int64", ",", "error", ")", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "int64", "(...
// ReadFrom implements the io.ReaderFrom interface. This // should be used with io.Reader to load configuration from //file or from string etc.
[ "ReadFrom", "implements", "the", "io", ".", "ReaderFrom", "interface", ".", "This", "should", "be", "used", "with", "io", ".", "Reader", "to", "load", "configuration", "from", "file", "or", "from", "string", "etc", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/config.go#L42-L51
train
securego/gosec
config.go
WriteTo
func (c Config) WriteTo(w io.Writer) (int64, error) { data, err := json.Marshal(c) if err != nil { return int64(len(data)), err } return io.Copy(w, bytes.NewReader(data)) }
go
func (c Config) WriteTo(w io.Writer) (int64, error) { data, err := json.Marshal(c) if err != nil { return int64(len(data)), err } return io.Copy(w, bytes.NewReader(data)) }
[ "func", "(", "c", "Config", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "int64", ",", "error", ")", "{", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "c", ")", "\n", "if", "err", "!=", "nil", "{", "return", "int64", "(", ...
// WriteTo implements the io.WriteTo interface. This should // be used to save or print out the configuration information.
[ "WriteTo", "implements", "the", "io", ".", "WriteTo", "interface", ".", "This", "should", "be", "used", "to", "save", "or", "print", "out", "the", "configuration", "information", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/config.go#L55-L61
train
securego/gosec
config.go
Get
func (c Config) Get(section string) (interface{}, error) { settings, found := c[section] if !found { return nil, fmt.Errorf("Section %s not in configuration", section) } return settings, nil }
go
func (c Config) Get(section string) (interface{}, error) { settings, found := c[section] if !found { return nil, fmt.Errorf("Section %s not in configuration", section) } return settings, nil }
[ "func", "(", "c", "Config", ")", "Get", "(", "section", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "settings", ",", "found", ":=", "c", "[", "section", "]", "\n", "if", "!", "found", "{", "return", "nil", ",", "fmt", ".", ...
// Get returns the configuration section for the supplied key
[ "Get", "returns", "the", "configuration", "section", "for", "the", "supplied", "key" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/config.go#L64-L70
train
securego/gosec
config.go
GetGlobal
func (c Config) GetGlobal(option GlobalOption) (string, error) { if globals, ok := c[Globals]; ok { if settings, ok := globals.(map[GlobalOption]string); ok { if value, ok := settings[option]; ok { return value, nil } return "", fmt.Errorf("global setting for %s not found", option) } } return "", fm...
go
func (c Config) GetGlobal(option GlobalOption) (string, error) { if globals, ok := c[Globals]; ok { if settings, ok := globals.(map[GlobalOption]string); ok { if value, ok := settings[option]; ok { return value, nil } return "", fmt.Errorf("global setting for %s not found", option) } } return "", fm...
[ "func", "(", "c", "Config", ")", "GetGlobal", "(", "option", "GlobalOption", ")", "(", "string", ",", "error", ")", "{", "if", "globals", ",", "ok", ":=", "c", "[", "Globals", "]", ";", "ok", "{", "if", "settings", ",", "ok", ":=", "globals", ".", ...
// GetGlobal returns value associated with global configuration option
[ "GetGlobal", "returns", "value", "associated", "with", "global", "configuration", "option" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/config.go#L78-L89
train
securego/gosec
config.go
SetGlobal
func (c Config) SetGlobal(option GlobalOption, value string) { if globals, ok := c[Globals]; ok { if settings, ok := globals.(map[GlobalOption]string); ok { settings[option] = value } } }
go
func (c Config) SetGlobal(option GlobalOption, value string) { if globals, ok := c[Globals]; ok { if settings, ok := globals.(map[GlobalOption]string); ok { settings[option] = value } } }
[ "func", "(", "c", "Config", ")", "SetGlobal", "(", "option", "GlobalOption", ",", "value", "string", ")", "{", "if", "globals", ",", "ok", ":=", "c", "[", "Globals", "]", ";", "ok", "{", "if", "settings", ",", "ok", ":=", "globals", ".", "(", "map"...
// SetGlobal associates a value with a global configuration option
[ "SetGlobal", "associates", "a", "value", "with", "a", "global", "configuration", "option" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/config.go#L92-L98
train
securego/gosec
config.go
IsGlobalEnabled
func (c Config) IsGlobalEnabled(option GlobalOption) (bool, error) { value, err := c.GetGlobal(option) if err != nil { return false, err } return (value == "true" || value == "enabled"), nil }
go
func (c Config) IsGlobalEnabled(option GlobalOption) (bool, error) { value, err := c.GetGlobal(option) if err != nil { return false, err } return (value == "true" || value == "enabled"), nil }
[ "func", "(", "c", "Config", ")", "IsGlobalEnabled", "(", "option", "GlobalOption", ")", "(", "bool", ",", "error", ")", "{", "value", ",", "err", ":=", "c", ".", "GetGlobal", "(", "option", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false",...
// IsGlobalEnabled checks if a global option is enabled
[ "IsGlobalEnabled", "checks", "if", "a", "global", "option", "is", "enabled" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/config.go#L101-L107
train
securego/gosec
rules/rand.go
NewWeakRandCheck
func NewWeakRandCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &weakRand{ funcNames: []string{"Read", "Int"}, packagePath: "math/rand", MetaData: gosec.MetaData{ ID: id, Severity: gosec.High, Confidence: gosec.Medium, What: "Use of weak random number generator...
go
func NewWeakRandCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &weakRand{ funcNames: []string{"Read", "Int"}, packagePath: "math/rand", MetaData: gosec.MetaData{ ID: id, Severity: gosec.High, Confidence: gosec.Medium, What: "Use of weak random number generator...
[ "func", "NewWeakRandCheck", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "return", "&", "weakRand", "{", "funcNames", ":", "[", "]", "string", "{", "\"", "\""...
// NewWeakRandCheck detects the use of random number generator that isn't cryptographically secure
[ "NewWeakRandCheck", "detects", "the", "use", "of", "random", "number", "generator", "that", "isn", "t", "cryptographically", "secure" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/rand.go#L44-L55
train
securego/gosec
rules/ssh.go
NewSSHHostKey
func NewSSHHostKey(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &sshHostKey{ pkg: "golang.org/x/crypto/ssh", calls: []string{"InsecureIgnoreHostKey"}, MetaData: gosec.MetaData{ ID: id, What: "Use of ssh InsecureIgnoreHostKey should be audited", Severity: gosec.Medium...
go
func NewSSHHostKey(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &sshHostKey{ pkg: "golang.org/x/crypto/ssh", calls: []string{"InsecureIgnoreHostKey"}, MetaData: gosec.MetaData{ ID: id, What: "Use of ssh InsecureIgnoreHostKey should be audited", Severity: gosec.Medium...
[ "func", "NewSSHHostKey", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "return", "&", "sshHostKey", "{", "pkg", ":", "\"", "\"", ",", "calls", ":", "[", "]",...
// NewSSHHostKey rule detects the use of insecure ssh HostKeyCallback.
[ "NewSSHHostKey", "rule", "detects", "the", "use", "of", "insecure", "ssh", "HostKeyCallback", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/ssh.go#L27-L38
train
securego/gosec
rules/errors.go
NewNoErrorCheck
func NewNoErrorCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { // TODO(gm) Come up with sensible defaults here. Or flip it to use a // black list instead. whitelist := gosec.NewCallList() whitelist.AddAll("bytes.Buffer", "Write", "WriteByte", "WriteRune", "WriteString") whitelist.AddAll("fmt", "Prin...
go
func NewNoErrorCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { // TODO(gm) Come up with sensible defaults here. Or flip it to use a // black list instead. whitelist := gosec.NewCallList() whitelist.AddAll("bytes.Buffer", "Write", "WriteByte", "WriteRune", "WriteString") whitelist.AddAll("fmt", "Prin...
[ "func", "NewNoErrorCheck", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "// TODO(gm) Come up with sensible defaults here. Or flip it to use a", "// black list instead.", "white...
// NewNoErrorCheck detects if the returned error is unchecked
[ "NewNoErrorCheck", "detects", "if", "the", "returned", "error", "is", "unchecked" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/errors.go#L81-L106
train
securego/gosec
rules/big.go
NewUsingBigExp
func NewUsingBigExp(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &usingBigExp{ pkg: "*math/big.Int", calls: []string{"Exp"}, MetaData: gosec.MetaData{ ID: id, What: "Use of math/big.Int.Exp function should be audited for modulus == 0", Severity: gosec.Low, Confide...
go
func NewUsingBigExp(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { return &usingBigExp{ pkg: "*math/big.Int", calls: []string{"Exp"}, MetaData: gosec.MetaData{ ID: id, What: "Use of math/big.Int.Exp function should be audited for modulus == 0", Severity: gosec.Low, Confide...
[ "func", "NewUsingBigExp", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "return", "&", "usingBigExp", "{", "pkg", ":", "\"", "\"", ",", "calls", ":", "[", "]...
// NewUsingBigExp detects issues with modulus == 0 for Bignum
[ "NewUsingBigExp", "detects", "issues", "with", "modulus", "==", "0", "for", "Bignum" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/big.go#L41-L52
train
securego/gosec
rules/rulelist.go
Builders
func (rl RuleList) Builders() map[string]gosec.RuleBuilder { builders := make(map[string]gosec.RuleBuilder) for _, def := range rl { builders[def.ID] = def.Create } return builders }
go
func (rl RuleList) Builders() map[string]gosec.RuleBuilder { builders := make(map[string]gosec.RuleBuilder) for _, def := range rl { builders[def.ID] = def.Create } return builders }
[ "func", "(", "rl", "RuleList", ")", "Builders", "(", ")", "map", "[", "string", "]", "gosec", ".", "RuleBuilder", "{", "builders", ":=", "make", "(", "map", "[", "string", "]", "gosec", ".", "RuleBuilder", ")", "\n", "for", "_", ",", "def", ":=", "...
// Builders returns all the create methods for a given rule list
[ "Builders", "returns", "all", "the", "create", "methods", "for", "a", "given", "rule", "list" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/rulelist.go#L31-L37
train
securego/gosec
rules/rulelist.go
Generate
func Generate(filters ...RuleFilter) RuleList { rules := []RuleDefinition{ // misc {"G101", "Look for hardcoded credentials", NewHardcodedCredentials}, {"G102", "Bind to all interfaces", NewBindsToAllNetworkInterfaces}, {"G103", "Audit the use of unsafe block", NewUsingUnsafe}, {"G104", "Audit errors not che...
go
func Generate(filters ...RuleFilter) RuleList { rules := []RuleDefinition{ // misc {"G101", "Look for hardcoded credentials", NewHardcodedCredentials}, {"G102", "Bind to all interfaces", NewBindsToAllNetworkInterfaces}, {"G103", "Audit the use of unsafe block", NewUsingUnsafe}, {"G104", "Audit errors not che...
[ "func", "Generate", "(", "filters", "...", "RuleFilter", ")", "RuleList", "{", "rules", ":=", "[", "]", "RuleDefinition", "{", "// misc", "{", "\"", "\"", ",", "\"", "\"", ",", "NewHardcodedCredentials", "}", ",", "{", "\"", "\"", ",", "\"", "\"", ",",...
// Generate the list of rules to use
[ "Generate", "the", "list", "of", "rules", "to", "use" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/rulelist.go#L59-L109
train
securego/gosec
errors.go
NewError
func NewError(line, column int, err string) *Error { return &Error{ Line: line, Column: column, Err: err, } }
go
func NewError(line, column int, err string) *Error { return &Error{ Line: line, Column: column, Err: err, } }
[ "func", "NewError", "(", "line", ",", "column", "int", ",", "err", "string", ")", "*", "Error", "{", "return", "&", "Error", "{", "Line", ":", "line", ",", "Column", ":", "column", ",", "Err", ":", "err", ",", "}", "\n", "}" ]
// NewError creates Error object
[ "NewError", "creates", "Error", "object" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/errors.go#L15-L21
train
securego/gosec
errors.go
sortErrors
func sortErrors(allErrors map[string][]Error) { for _, errors := range allErrors { sort.Slice(errors, func(i, j int) bool { if errors[i].Line == errors[j].Line { return errors[i].Column <= errors[j].Column } return errors[i].Line < errors[j].Line }) } }
go
func sortErrors(allErrors map[string][]Error) { for _, errors := range allErrors { sort.Slice(errors, func(i, j int) bool { if errors[i].Line == errors[j].Line { return errors[i].Column <= errors[j].Column } return errors[i].Line < errors[j].Line }) } }
[ "func", "sortErrors", "(", "allErrors", "map", "[", "string", "]", "[", "]", "Error", ")", "{", "for", "_", ",", "errors", ":=", "range", "allErrors", "{", "sort", ".", "Slice", "(", "errors", ",", "func", "(", "i", ",", "j", "int", ")", "bool", ...
// sortErros sorts the golang erros by line
[ "sortErros", "sorts", "the", "golang", "erros", "by", "line" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/errors.go#L24-L33
train
securego/gosec
rules/tempfiles.go
NewBadTempFile
func NewBadTempFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { calls := gosec.NewCallList() calls.Add("io/ioutil", "WriteFile") calls.Add("os", "Create") return &badTempFile{ calls: calls, args: regexp.MustCompile(`^/tmp/.*$|^/var/tmp/.*$`), MetaData: gosec.MetaData{ ID: id, Sever...
go
func NewBadTempFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { calls := gosec.NewCallList() calls.Add("io/ioutil", "WriteFile") calls.Add("os", "Create") return &badTempFile{ calls: calls, args: regexp.MustCompile(`^/tmp/.*$|^/var/tmp/.*$`), MetaData: gosec.MetaData{ ID: id, Sever...
[ "func", "NewBadTempFile", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "calls", ":=", "gosec", ".", "NewCallList", "(", ")", "\n", "calls", ".", "Add", "(", ...
// NewBadTempFile detects direct writes to predictable path in temporary directory
[ "NewBadTempFile", "detects", "direct", "writes", "to", "predictable", "path", "in", "temporary", "directory" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/tempfiles.go#L44-L58
train
securego/gosec
import_tracker.go
NewImportTracker
func NewImportTracker() *ImportTracker { return &ImportTracker{ make(map[string]string), make(map[string]string), make(map[string]bool), } }
go
func NewImportTracker() *ImportTracker { return &ImportTracker{ make(map[string]string), make(map[string]string), make(map[string]bool), } }
[ "func", "NewImportTracker", "(", ")", "*", "ImportTracker", "{", "return", "&", "ImportTracker", "{", "make", "(", "map", "[", "string", "]", "string", ")", ",", "make", "(", "map", "[", "string", "]", "string", ")", ",", "make", "(", "map", "[", "st...
// NewImportTracker creates an empty Import tracker instance
[ "NewImportTracker", "creates", "an", "empty", "Import", "tracker", "instance" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/import_tracker.go#L31-L37
train
securego/gosec
import_tracker.go
TrackFile
func (t *ImportTracker) TrackFile(file *ast.File) { for _, imp := range file.Imports { path := strings.Trim(imp.Path.Value, `"`) parts := strings.Split(path, "/") if len(parts) > 0 { name := parts[len(parts)-1] t.Imported[path] = name } } }
go
func (t *ImportTracker) TrackFile(file *ast.File) { for _, imp := range file.Imports { path := strings.Trim(imp.Path.Value, `"`) parts := strings.Split(path, "/") if len(parts) > 0 { name := parts[len(parts)-1] t.Imported[path] = name } } }
[ "func", "(", "t", "*", "ImportTracker", ")", "TrackFile", "(", "file", "*", "ast", ".", "File", ")", "{", "for", "_", ",", "imp", ":=", "range", "file", ".", "Imports", "{", "path", ":=", "strings", ".", "Trim", "(", "imp", ".", "Path", ".", "Val...
// TrackFile track all the imports used by the supplied file
[ "TrackFile", "track", "all", "the", "imports", "used", "by", "the", "supplied", "file" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/import_tracker.go#L40-L49
train
securego/gosec
import_tracker.go
TrackPackages
func (t *ImportTracker) TrackPackages(pkgs ...*types.Package) { for _, pkg := range pkgs { t.Imported[pkg.Path()] = pkg.Name() } }
go
func (t *ImportTracker) TrackPackages(pkgs ...*types.Package) { for _, pkg := range pkgs { t.Imported[pkg.Path()] = pkg.Name() } }
[ "func", "(", "t", "*", "ImportTracker", ")", "TrackPackages", "(", "pkgs", "...", "*", "types", ".", "Package", ")", "{", "for", "_", ",", "pkg", ":=", "range", "pkgs", "{", "t", ".", "Imported", "[", "pkg", ".", "Path", "(", ")", "]", "=", "pkg"...
// TrackPackages tracks all the imports used by the supplied packages
[ "TrackPackages", "tracks", "all", "the", "imports", "used", "by", "the", "supplied", "packages" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/import_tracker.go#L52-L56
train
securego/gosec
import_tracker.go
TrackImport
func (t *ImportTracker) TrackImport(n ast.Node) { if imported, ok := n.(*ast.ImportSpec); ok { path := strings.Trim(imported.Path.Value, `"`) if imported.Name != nil { if imported.Name.Name == "_" { // Initialization only import t.InitOnly[path] = true } else { // Aliased import t.Aliased[pat...
go
func (t *ImportTracker) TrackImport(n ast.Node) { if imported, ok := n.(*ast.ImportSpec); ok { path := strings.Trim(imported.Path.Value, `"`) if imported.Name != nil { if imported.Name.Name == "_" { // Initialization only import t.InitOnly[path] = true } else { // Aliased import t.Aliased[pat...
[ "func", "(", "t", "*", "ImportTracker", ")", "TrackImport", "(", "n", "ast", ".", "Node", ")", "{", "if", "imported", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "ImportSpec", ")", ";", "ok", "{", "path", ":=", "strings", ".", "Trim", "(", ...
// TrackImport tracks imports and handles the 'unsafe' import
[ "TrackImport", "tracks", "imports", "and", "handles", "the", "unsafe", "import" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/import_tracker.go#L59-L75
train
securego/gosec
rules/readfile.go
isJoinFunc
func (r *readfile) isJoinFunc(n ast.Node, c *gosec.Context) bool { if call := r.pathJoin.ContainsCallExpr(n, c, false); call != nil { for _, arg := range call.Args { // edge case: check if one of the args is a BinaryExpr if binExp, ok := arg.(*ast.BinaryExpr); ok { // iterate and resolve all found identiti...
go
func (r *readfile) isJoinFunc(n ast.Node, c *gosec.Context) bool { if call := r.pathJoin.ContainsCallExpr(n, c, false); call != nil { for _, arg := range call.Args { // edge case: check if one of the args is a BinaryExpr if binExp, ok := arg.(*ast.BinaryExpr); ok { // iterate and resolve all found identiti...
[ "func", "(", "r", "*", "readfile", ")", "isJoinFunc", "(", "n", "ast", ".", "Node", ",", "c", "*", "gosec", ".", "Context", ")", "bool", "{", "if", "call", ":=", "r", ".", "pathJoin", ".", "ContainsCallExpr", "(", "n", ",", "c", ",", "false", ")"...
// isJoinFunc checks if there is a filepath.Join or other join function
[ "isJoinFunc", "checks", "if", "there", "is", "a", "filepath", ".", "Join", "or", "other", "join", "function" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/readfile.go#L36-L57
train
securego/gosec
rules/readfile.go
Match
func (r *readfile) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) { if node := r.ContainsCallExpr(n, c, false); node != nil { for _, arg := range node.Args { // handles path joining functions in Arg // eg. os.Open(filepath.Join("/tmp/", file)) if callExpr, ok := arg.(*ast.CallExpr); ok { if r...
go
func (r *readfile) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) { if node := r.ContainsCallExpr(n, c, false); node != nil { for _, arg := range node.Args { // handles path joining functions in Arg // eg. os.Open(filepath.Join("/tmp/", file)) if callExpr, ok := arg.(*ast.CallExpr); ok { if r...
[ "func", "(", "r", "*", "readfile", ")", "Match", "(", "n", "ast", ".", "Node", ",", "c", "*", "gosec", ".", "Context", ")", "(", "*", "gosec", ".", "Issue", ",", "error", ")", "{", "if", "node", ":=", "r", ".", "ContainsCallExpr", "(", "n", ","...
// Match inspects AST nodes to determine if the match the methods `os.Open` or `ioutil.ReadFile`
[ "Match", "inspects", "AST", "nodes", "to", "determine", "if", "the", "match", "the", "methods", "os", ".", "Open", "or", "ioutil", ".", "ReadFile" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/readfile.go#L60-L87
train
securego/gosec
rules/readfile.go
NewReadFile
func NewReadFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { rule := &readfile{ pathJoin: gosec.NewCallList(), CallList: gosec.NewCallList(), MetaData: gosec.MetaData{ ID: id, What: "Potential file inclusion via variable", Severity: gosec.Medium, Confidence: gosec.High, ...
go
func NewReadFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { rule := &readfile{ pathJoin: gosec.NewCallList(), CallList: gosec.NewCallList(), MetaData: gosec.MetaData{ ID: id, What: "Potential file inclusion via variable", Severity: gosec.Medium, Confidence: gosec.High, ...
[ "func", "NewReadFile", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "rule", ":=", "&", "readfile", "{", "pathJoin", ":", "gosec", ".", "NewCallList", "(", ")"...
// NewReadFile detects cases where we read files
[ "NewReadFile", "detects", "cases", "where", "we", "read", "files" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/readfile.go#L90-L106
train
securego/gosec
rules/ssrf.go
ResolveVar
func (r *ssrf) ResolveVar(n *ast.CallExpr, c *gosec.Context) bool { if len(n.Args) > 0 { arg := n.Args[0] if ident, ok := arg.(*ast.Ident); ok { obj := c.Info.ObjectOf(ident) if _, ok := obj.(*types.Var); ok && !gosec.TryResolve(ident, c) { return true } } } return false }
go
func (r *ssrf) ResolveVar(n *ast.CallExpr, c *gosec.Context) bool { if len(n.Args) > 0 { arg := n.Args[0] if ident, ok := arg.(*ast.Ident); ok { obj := c.Info.ObjectOf(ident) if _, ok := obj.(*types.Var); ok && !gosec.TryResolve(ident, c) { return true } } } return false }
[ "func", "(", "r", "*", "ssrf", ")", "ResolveVar", "(", "n", "*", "ast", ".", "CallExpr", ",", "c", "*", "gosec", ".", "Context", ")", "bool", "{", "if", "len", "(", "n", ".", "Args", ")", ">", "0", "{", "arg", ":=", "n", ".", "Args", "[", "...
// ResolveVar tries to resolve the first argument of a call expression // The first argument is the url
[ "ResolveVar", "tries", "to", "resolve", "the", "first", "argument", "of", "a", "call", "expression", "The", "first", "argument", "is", "the", "url" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/ssrf.go#L22-L33
train
securego/gosec
rules/ssrf.go
NewSSRFCheck
func NewSSRFCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { rule := &ssrf{ CallList: gosec.NewCallList(), MetaData: gosec.MetaData{ ID: id, What: "Potential HTTP request made with variable url", Severity: gosec.Medium, Confidence: gosec.Medium, }, } rule.AddAll("net/h...
go
func NewSSRFCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) { rule := &ssrf{ CallList: gosec.NewCallList(), MetaData: gosec.MetaData{ ID: id, What: "Potential HTTP request made with variable url", Severity: gosec.Medium, Confidence: gosec.Medium, }, } rule.AddAll("net/h...
[ "func", "NewSSRFCheck", "(", "id", "string", ",", "conf", "gosec", ".", "Config", ")", "(", "gosec", ".", "Rule", ",", "[", "]", "ast", ".", "Node", ")", "{", "rule", ":=", "&", "ssrf", "{", "CallList", ":", "gosec", ".", "NewCallList", "(", ")", ...
// NewSSRFCheck detects cases where HTTP requests are sent
[ "NewSSRFCheck", "detects", "cases", "where", "HTTP", "requests", "are", "sent" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/rules/ssrf.go#L47-L59
train
securego/gosec
resolve.go
TryResolve
func TryResolve(n ast.Node, c *Context) bool { switch node := n.(type) { case *ast.BasicLit: return true case *ast.CompositeLit: return resolveCompLit(node, c) case *ast.Ident: return resolveIdent(node, c) case *ast.AssignStmt: return resolveAssign(node, c) case *ast.CallExpr: return resolveCallExpr...
go
func TryResolve(n ast.Node, c *Context) bool { switch node := n.(type) { case *ast.BasicLit: return true case *ast.CompositeLit: return resolveCompLit(node, c) case *ast.Ident: return resolveIdent(node, c) case *ast.AssignStmt: return resolveAssign(node, c) case *ast.CallExpr: return resolveCallExpr...
[ "func", "TryResolve", "(", "n", "ast", ".", "Node", ",", "c", "*", "Context", ")", "bool", "{", "switch", "node", ":=", "n", ".", "(", "type", ")", "{", "case", "*", "ast", ".", "BasicLit", ":", "return", "true", "\n\n", "case", "*", "ast", ".", ...
// TryResolve will attempt, given a subtree starting at some ATS node, to resolve // all values contained within to a known constant. It is used to check for any // unknown values in compound expressions.
[ "TryResolve", "will", "attempt", "given", "a", "subtree", "starting", "at", "some", "ATS", "node", "to", "resolve", "all", "values", "contained", "within", "to", "a", "known", "constant", ".", "It", "is", "used", "to", "check", "for", "any", "unknown", "va...
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/resolve.go#L60-L82
train
securego/gosec
issue.go
NewIssue
func NewIssue(ctx *Context, node ast.Node, ruleID, desc string, severity Score, confidence Score) *Issue { var code string fobj := ctx.FileSet.File(node.Pos()) name := fobj.Name() start, end := fobj.Line(node.Pos()), fobj.Line(node.End()) line := strconv.Itoa(start) if start != end { line = fmt.Sprintf("%d-%d"...
go
func NewIssue(ctx *Context, node ast.Node, ruleID, desc string, severity Score, confidence Score) *Issue { var code string fobj := ctx.FileSet.File(node.Pos()) name := fobj.Name() start, end := fobj.Line(node.Pos()), fobj.Line(node.End()) line := strconv.Itoa(start) if start != end { line = fmt.Sprintf("%d-%d"...
[ "func", "NewIssue", "(", "ctx", "*", "Context", ",", "node", "ast", ".", "Node", ",", "ruleID", ",", "desc", "string", ",", "severity", "Score", ",", "confidence", "Score", ")", "*", "Issue", "{", "var", "code", "string", "\n", "fobj", ":=", "ctx", "...
// NewIssue creates a new Issue
[ "NewIssue", "creates", "a", "new", "Issue" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/issue.go#L94-L125
train
securego/gosec
analyzer.go
NewAnalyzer
func NewAnalyzer(conf Config, tests bool, logger *log.Logger) *Analyzer { ignoreNoSec := false if enabled, err := conf.IsGlobalEnabled(Nosec); err == nil { ignoreNoSec = enabled } if logger == nil { logger = log.New(os.Stderr, "[gosec]", log.LstdFlags) } return &Analyzer{ ignoreNosec: ignoreNoSec, ruleset...
go
func NewAnalyzer(conf Config, tests bool, logger *log.Logger) *Analyzer { ignoreNoSec := false if enabled, err := conf.IsGlobalEnabled(Nosec); err == nil { ignoreNoSec = enabled } if logger == nil { logger = log.New(os.Stderr, "[gosec]", log.LstdFlags) } return &Analyzer{ ignoreNosec: ignoreNoSec, ruleset...
[ "func", "NewAnalyzer", "(", "conf", "Config", ",", "tests", "bool", ",", "logger", "*", "log", ".", "Logger", ")", "*", "Analyzer", "{", "ignoreNoSec", ":=", "false", "\n", "if", "enabled", ",", "err", ":=", "conf", ".", "IsGlobalEnabled", "(", "Nosec", ...
// NewAnalyzer builds a new analyzer.
[ "NewAnalyzer", "builds", "a", "new", "analyzer", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L74-L93
train
securego/gosec
analyzer.go
LoadRules
func (gosec *Analyzer) LoadRules(ruleDefinitions map[string]RuleBuilder) { for id, def := range ruleDefinitions { r, nodes := def(id, gosec.config) gosec.ruleset.Register(r, nodes...) } }
go
func (gosec *Analyzer) LoadRules(ruleDefinitions map[string]RuleBuilder) { for id, def := range ruleDefinitions { r, nodes := def(id, gosec.config) gosec.ruleset.Register(r, nodes...) } }
[ "func", "(", "gosec", "*", "Analyzer", ")", "LoadRules", "(", "ruleDefinitions", "map", "[", "string", "]", "RuleBuilder", ")", "{", "for", "id", ",", "def", ":=", "range", "ruleDefinitions", "{", "r", ",", "nodes", ":=", "def", "(", "id", ",", "gosec"...
// LoadRules instantiates all the rules to be used when analyzing source // packages
[ "LoadRules", "instantiates", "all", "the", "rules", "to", "be", "used", "when", "analyzing", "source", "packages" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L97-L102
train
securego/gosec
analyzer.go
Process
func (gosec *Analyzer) Process(buildTags []string, packagePaths ...string) error { config := gosec.pkgConfig(buildTags) for _, pkgPath := range packagePaths { pkgs, err := gosec.load(pkgPath, config) if err != nil { gosec.AppendError(pkgPath, err) } for _, pkg := range pkgs { if pkg.Name != "" { err...
go
func (gosec *Analyzer) Process(buildTags []string, packagePaths ...string) error { config := gosec.pkgConfig(buildTags) for _, pkgPath := range packagePaths { pkgs, err := gosec.load(pkgPath, config) if err != nil { gosec.AppendError(pkgPath, err) } for _, pkg := range pkgs { if pkg.Name != "" { err...
[ "func", "(", "gosec", "*", "Analyzer", ")", "Process", "(", "buildTags", "[", "]", "string", ",", "packagePaths", "...", "string", ")", "error", "{", "config", ":=", "gosec", ".", "pkgConfig", "(", "buildTags", ")", "\n", "for", "_", ",", "pkgPath", ":...
// Process kicks off the analysis process for a given package
[ "Process", "kicks", "off", "the", "analysis", "process", "for", "a", "given", "package" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L105-L124
train
securego/gosec
analyzer.go
ParseErrors
func (gosec *Analyzer) ParseErrors(pkg *packages.Package) error { if len(pkg.Errors) == 0 { return nil } for _, pkgErr := range pkg.Errors { parts := strings.Split(pkgErr.Pos, ":") file := parts[0] var err error var line int if len(parts) > 1 { if line, err = strconv.Atoi(parts[1]); err != nil { r...
go
func (gosec *Analyzer) ParseErrors(pkg *packages.Package) error { if len(pkg.Errors) == 0 { return nil } for _, pkgErr := range pkg.Errors { parts := strings.Split(pkgErr.Pos, ":") file := parts[0] var err error var line int if len(parts) > 1 { if line, err = strconv.Atoi(parts[1]); err != nil { r...
[ "func", "(", "gosec", "*", "Analyzer", ")", "ParseErrors", "(", "pkg", "*", "packages", ".", "Package", ")", "error", "{", "if", "len", "(", "pkg", ".", "Errors", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "for", "_", ",", "pkgErr", "...
// ParseErrors parses the errors from given package
[ "ParseErrors", "parses", "the", "errors", "from", "given", "package" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L193-L223
train
securego/gosec
analyzer.go
AppendError
func (gosec *Analyzer) AppendError(file string, err error) { // Do not report the error for empty packages (e.g. files excluded from build with a tag) r := regexp.MustCompile(`no buildable Go source files in`) if r.MatchString(err.Error()) { return } errors := []Error{} if ferrs, ok := gosec.errors[file]; ok { ...
go
func (gosec *Analyzer) AppendError(file string, err error) { // Do not report the error for empty packages (e.g. files excluded from build with a tag) r := regexp.MustCompile(`no buildable Go source files in`) if r.MatchString(err.Error()) { return } errors := []Error{} if ferrs, ok := gosec.errors[file]; ok { ...
[ "func", "(", "gosec", "*", "Analyzer", ")", "AppendError", "(", "file", "string", ",", "err", "error", ")", "{", "// Do not report the error for empty packages (e.g. files excluded from build with a tag)", "r", ":=", "regexp", ".", "MustCompile", "(", "`no buildable Go so...
// AppendError appends an error to the file errors
[ "AppendError", "appends", "an", "error", "to", "the", "file", "errors" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L226-L239
train
securego/gosec
analyzer.go
Visit
func (gosec *Analyzer) Visit(n ast.Node) ast.Visitor { // If we've reached the end of this branch, pop off the ignores stack. if n == nil { if len(gosec.context.Ignores) > 0 { gosec.context.Ignores = gosec.context.Ignores[1:] } return gosec } // Get any new rule exclusions. ignoredRules, ignoreAll := gos...
go
func (gosec *Analyzer) Visit(n ast.Node) ast.Visitor { // If we've reached the end of this branch, pop off the ignores stack. if n == nil { if len(gosec.context.Ignores) > 0 { gosec.context.Ignores = gosec.context.Ignores[1:] } return gosec } // Get any new rule exclusions. ignoredRules, ignoreAll := gos...
[ "func", "(", "gosec", "*", "Analyzer", ")", "Visit", "(", "n", "ast", ".", "Node", ")", "ast", ".", "Visitor", "{", "// If we've reached the end of this branch, pop off the ignores stack.", "if", "n", "==", "nil", "{", "if", "len", "(", "gosec", ".", "context"...
// Visit runs the gosec visitor logic over an AST created by parsing go code. // Rule methods added with AddRule will be invoked as necessary.
[ "Visit", "runs", "the", "gosec", "visitor", "logic", "over", "an", "AST", "created", "by", "parsing", "go", "code", ".", "Rule", "methods", "added", "with", "AddRule", "will", "be", "invoked", "as", "necessary", "." ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L271-L320
train
securego/gosec
analyzer.go
Report
func (gosec *Analyzer) Report() ([]*Issue, *Metrics, map[string][]Error) { return gosec.issues, gosec.stats, gosec.errors }
go
func (gosec *Analyzer) Report() ([]*Issue, *Metrics, map[string][]Error) { return gosec.issues, gosec.stats, gosec.errors }
[ "func", "(", "gosec", "*", "Analyzer", ")", "Report", "(", ")", "(", "[", "]", "*", "Issue", ",", "*", "Metrics", ",", "map", "[", "string", "]", "[", "]", "Error", ")", "{", "return", "gosec", ".", "issues", ",", "gosec", ".", "stats", ",", "g...
// Report returns the current issues discovered and the metrics about the scan
[ "Report", "returns", "the", "current", "issues", "discovered", "and", "the", "metrics", "about", "the", "scan" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L323-L325
train
securego/gosec
analyzer.go
Reset
func (gosec *Analyzer) Reset() { gosec.context = &Context{} gosec.issues = make([]*Issue, 0, 16) gosec.stats = &Metrics{} }
go
func (gosec *Analyzer) Reset() { gosec.context = &Context{} gosec.issues = make([]*Issue, 0, 16) gosec.stats = &Metrics{} }
[ "func", "(", "gosec", "*", "Analyzer", ")", "Reset", "(", ")", "{", "gosec", ".", "context", "=", "&", "Context", "{", "}", "\n", "gosec", ".", "issues", "=", "make", "(", "[", "]", "*", "Issue", ",", "0", ",", "16", ")", "\n", "gosec", ".", ...
// Reset clears state such as context, issues and metrics from the configured analyzer
[ "Reset", "clears", "state", "such", "as", "context", "issues", "and", "metrics", "from", "the", "configured", "analyzer" ]
29cec138dcc94f347e6d41550a5223571dc7d6cf
https://github.com/securego/gosec/blob/29cec138dcc94f347e6d41550a5223571dc7d6cf/analyzer.go#L328-L332
train
Shopify/toxiproxy
client/client.go
Proxies
func (client *Client) Proxies() (map[string]*Proxy, error) { resp, err := http.Get(client.endpoint + "/proxies") if err != nil { return nil, err } err = checkError(resp, http.StatusOK, "Proxies") if err != nil { return nil, err } proxies := make(map[string]*Proxy) err = json.NewDecoder(resp.Body).Decode(&...
go
func (client *Client) Proxies() (map[string]*Proxy, error) { resp, err := http.Get(client.endpoint + "/proxies") if err != nil { return nil, err } err = checkError(resp, http.StatusOK, "Proxies") if err != nil { return nil, err } proxies := make(map[string]*Proxy) err = json.NewDecoder(resp.Body).Decode(&...
[ "func", "(", "client", "*", "Client", ")", "Proxies", "(", ")", "(", "map", "[", "string", "]", "*", "Proxy", ",", "error", ")", "{", "resp", ",", "err", ":=", "http", ".", "Get", "(", "client", ".", "endpoint", "+", "\"", "\"", ")", "\n", "if"...
// Proxies returns a map with all the proxies and their toxics.
[ "Proxies", "returns", "a", "map", "with", "all", "the", "proxies", "and", "their", "toxics", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/client/client.go#L60-L82
train
Shopify/toxiproxy
client/client.go
Proxy
func (client *Client) Proxy(name string) (*Proxy, error) { // TODO url encode resp, err := http.Get(client.endpoint + "/proxies/" + name) if err != nil { return nil, err } err = checkError(resp, http.StatusOK, "Proxy") if err != nil { return nil, err } proxy := new(Proxy) err = json.NewDecoder(resp.Body)...
go
func (client *Client) Proxy(name string) (*Proxy, error) { // TODO url encode resp, err := http.Get(client.endpoint + "/proxies/" + name) if err != nil { return nil, err } err = checkError(resp, http.StatusOK, "Proxy") if err != nil { return nil, err } proxy := new(Proxy) err = json.NewDecoder(resp.Body)...
[ "func", "(", "client", "*", "Client", ")", "Proxy", "(", "name", "string", ")", "(", "*", "Proxy", ",", "error", ")", "{", "// TODO url encode", "resp", ",", "err", ":=", "http", ".", "Get", "(", "client", ".", "endpoint", "+", "\"", "\"", "+", "na...
// Proxy returns a proxy by name.
[ "Proxy", "returns", "a", "proxy", "by", "name", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/client/client.go#L112-L133
train
Shopify/toxiproxy
client/client.go
Populate
func (client *Client) Populate(config []Proxy) ([]*Proxy, error) { proxies := struct { Proxies []*Proxy `json:"proxies"` }{} request, err := json.Marshal(config) if err != nil { return nil, err } resp, err := http.Post(client.endpoint+"/populate", "application/json", bytes.NewReader(request)) if err != nil ...
go
func (client *Client) Populate(config []Proxy) ([]*Proxy, error) { proxies := struct { Proxies []*Proxy `json:"proxies"` }{} request, err := json.Marshal(config) if err != nil { return nil, err } resp, err := http.Post(client.endpoint+"/populate", "application/json", bytes.NewReader(request)) if err != nil ...
[ "func", "(", "client", "*", "Client", ")", "Populate", "(", "config", "[", "]", "Proxy", ")", "(", "[", "]", "*", "Proxy", ",", "error", ")", "{", "proxies", ":=", "struct", "{", "Proxies", "[", "]", "*", "Proxy", "`json:\"proxies\"`", "\n", "}", "...
// Create a list of proxies using a configuration list. If a proxy already exists, it will be replaced // with the specified configuration. For large amounts of proxies, `config` can be loaded from a file. // Returns a list of the successfully created proxies.
[ "Create", "a", "list", "of", "proxies", "using", "a", "configuration", "list", ".", "If", "a", "proxy", "already", "exists", "it", "will", "be", "replaced", "with", "the", "specified", "configuration", ".", "For", "large", "amounts", "of", "proxies", "config...
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/client/client.go#L138-L163
train
Shopify/toxiproxy
client/client.go
Save
func (proxy *Proxy) Save() error { request, err := json.Marshal(proxy) if err != nil { return err } var resp *http.Response if proxy.created { resp, err = http.Post(proxy.client.endpoint+"/proxies/"+proxy.Name, "text/plain", bytes.NewReader(request)) } else { resp, err = http.Post(proxy.client.endpoint+"/p...
go
func (proxy *Proxy) Save() error { request, err := json.Marshal(proxy) if err != nil { return err } var resp *http.Response if proxy.created { resp, err = http.Post(proxy.client.endpoint+"/proxies/"+proxy.Name, "text/plain", bytes.NewReader(request)) } else { resp, err = http.Post(proxy.client.endpoint+"/p...
[ "func", "(", "proxy", "*", "Proxy", ")", "Save", "(", ")", "error", "{", "request", ",", "err", ":=", "json", ".", "Marshal", "(", "proxy", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "resp", "*", "http", ...
// Save saves changes to a proxy such as its enabled status or upstream port.
[ "Save", "saves", "changes", "to", "a", "proxy", "such", "as", "its", "enabled", "status", "or", "upstream", "port", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/client/client.go#L166-L198
train
Shopify/toxiproxy
client/client.go
Toxics
func (proxy *Proxy) Toxics() (Toxics, error) { resp, err := http.Get(proxy.client.endpoint + "/proxies/" + proxy.Name + "/toxics") if err != nil { return nil, err } err = checkError(resp, http.StatusOK, "Toxics") if err != nil { return nil, err } toxics := make(Toxics, 0) err = json.NewDecoder(resp.Body)....
go
func (proxy *Proxy) Toxics() (Toxics, error) { resp, err := http.Get(proxy.client.endpoint + "/proxies/" + proxy.Name + "/toxics") if err != nil { return nil, err } err = checkError(resp, http.StatusOK, "Toxics") if err != nil { return nil, err } toxics := make(Toxics, 0) err = json.NewDecoder(resp.Body)....
[ "func", "(", "proxy", "*", "Proxy", ")", "Toxics", "(", ")", "(", "Toxics", ",", "error", ")", "{", "resp", ",", "err", ":=", "http", ".", "Get", "(", "proxy", ".", "client", ".", "endpoint", "+", "\"", "\"", "+", "proxy", ".", "Name", "+", "\"...
// Toxics returns a map of all the active toxics and their attributes.
[ "Toxics", "returns", "a", "map", "of", "all", "the", "active", "toxics", "and", "their", "attributes", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/client/client.go#L232-L250
train
Shopify/toxiproxy
client/client.go
ResetState
func (client *Client) ResetState() error { resp, err := http.Post(client.endpoint+"/reset", "text/plain", bytes.NewReader([]byte{})) if err != nil { return err } return checkError(resp, http.StatusNoContent, "ResetState") }
go
func (client *Client) ResetState() error { resp, err := http.Post(client.endpoint+"/reset", "text/plain", bytes.NewReader([]byte{})) if err != nil { return err } return checkError(resp, http.StatusNoContent, "ResetState") }
[ "func", "(", "client", "*", "Client", ")", "ResetState", "(", ")", "error", "{", "resp", ",", "err", ":=", "http", ".", "Post", "(", "client", ".", "endpoint", "+", "\"", "\"", ",", "\"", "\"", ",", "bytes", ".", "NewReader", "(", "[", "]", "byte...
// ResetState resets the state of all proxies and toxics in Toxiproxy.
[ "ResetState", "resets", "the", "state", "of", "all", "proxies", "and", "toxics", "in", "Toxiproxy", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/client/client.go#L336-L343
train
Shopify/toxiproxy
link.go
Start
func (link *ToxicLink) Start(name string, source io.Reader, dest io.WriteCloser) { go func() { bytes, err := io.Copy(link.input, source) if err != nil { logrus.WithFields(logrus.Fields{ "name": link.proxy.Name, "bytes": bytes, "err": err, }).Warn("Source terminated") } link.input.Close() ...
go
func (link *ToxicLink) Start(name string, source io.Reader, dest io.WriteCloser) { go func() { bytes, err := io.Copy(link.input, source) if err != nil { logrus.WithFields(logrus.Fields{ "name": link.proxy.Name, "bytes": bytes, "err": err, }).Warn("Source terminated") } link.input.Close() ...
[ "func", "(", "link", "*", "ToxicLink", ")", "Start", "(", "name", "string", ",", "source", "io", ".", "Reader", ",", "dest", "io", ".", "WriteCloser", ")", "{", "go", "func", "(", ")", "{", "bytes", ",", "err", ":=", "io", ".", "Copy", "(", "link...
// Start the link with the specified toxics
[ "Start", "the", "link", "with", "the", "specified", "toxics" ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/link.go#L56-L88
train
Shopify/toxiproxy
link.go
AddToxic
func (link *ToxicLink) AddToxic(toxic *toxics.ToxicWrapper) { i := len(link.stubs) newin := make(chan *stream.StreamChunk, toxic.BufferSize) link.stubs = append(link.stubs, toxics.NewToxicStub(newin, link.stubs[i-1].Output)) // Interrupt the last toxic so that we don't have a race when moving channels if link.st...
go
func (link *ToxicLink) AddToxic(toxic *toxics.ToxicWrapper) { i := len(link.stubs) newin := make(chan *stream.StreamChunk, toxic.BufferSize) link.stubs = append(link.stubs, toxics.NewToxicStub(newin, link.stubs[i-1].Output)) // Interrupt the last toxic so that we don't have a race when moving channels if link.st...
[ "func", "(", "link", "*", "ToxicLink", ")", "AddToxic", "(", "toxic", "*", "toxics", ".", "ToxicWrapper", ")", "{", "i", ":=", "len", "(", "link", ".", "stubs", ")", "\n\n", "newin", ":=", "make", "(", "chan", "*", "stream", ".", "StreamChunk", ",", ...
// Add a toxic to the end of the chain.
[ "Add", "a", "toxic", "to", "the", "end", "of", "the", "chain", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/link.go#L91-L112
train
Shopify/toxiproxy
link.go
UpdateToxic
func (link *ToxicLink) UpdateToxic(toxic *toxics.ToxicWrapper) { if link.stubs[toxic.Index].InterruptToxic() { go link.stubs[toxic.Index].Run(toxic) } }
go
func (link *ToxicLink) UpdateToxic(toxic *toxics.ToxicWrapper) { if link.stubs[toxic.Index].InterruptToxic() { go link.stubs[toxic.Index].Run(toxic) } }
[ "func", "(", "link", "*", "ToxicLink", ")", "UpdateToxic", "(", "toxic", "*", "toxics", ".", "ToxicWrapper", ")", "{", "if", "link", ".", "stubs", "[", "toxic", ".", "Index", "]", ".", "InterruptToxic", "(", ")", "{", "go", "link", ".", "stubs", "[",...
// Update an existing toxic in the chain.
[ "Update", "an", "existing", "toxic", "in", "the", "chain", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/link.go#L115-L119
train
Shopify/toxiproxy
link.go
RemoveToxic
func (link *ToxicLink) RemoveToxic(toxic *toxics.ToxicWrapper) { i := toxic.Index if link.stubs[i].InterruptToxic() { cleanup, ok := toxic.Toxic.(toxics.CleanupToxic) if ok { cleanup.Cleanup(link.stubs[i]) // Cleanup could have closed the stub. if link.stubs[i].Closed() { return } } stop := ...
go
func (link *ToxicLink) RemoveToxic(toxic *toxics.ToxicWrapper) { i := toxic.Index if link.stubs[i].InterruptToxic() { cleanup, ok := toxic.Toxic.(toxics.CleanupToxic) if ok { cleanup.Cleanup(link.stubs[i]) // Cleanup could have closed the stub. if link.stubs[i].Closed() { return } } stop := ...
[ "func", "(", "link", "*", "ToxicLink", ")", "RemoveToxic", "(", "toxic", "*", "toxics", ".", "ToxicWrapper", ")", "{", "i", ":=", "toxic", ".", "Index", "\n\n", "if", "link", ".", "stubs", "[", "i", "]", ".", "InterruptToxic", "(", ")", "{", "cleanup...
// Remove an existing toxic from the chain.
[ "Remove", "an", "existing", "toxic", "from", "the", "chain", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/link.go#L122-L176
train
Shopify/toxiproxy
toxics/toxic.go
Run
func (s *ToxicStub) Run(toxic *ToxicWrapper) { s.running = make(chan struct{}) defer close(s.running) if rand.Float32() < toxic.Toxicity { toxic.Pipe(s) } else { new(NoopToxic).Pipe(s) } }
go
func (s *ToxicStub) Run(toxic *ToxicWrapper) { s.running = make(chan struct{}) defer close(s.running) if rand.Float32() < toxic.Toxicity { toxic.Pipe(s) } else { new(NoopToxic).Pipe(s) } }
[ "func", "(", "s", "*", "ToxicStub", ")", "Run", "(", "toxic", "*", "ToxicWrapper", ")", "{", "s", ".", "running", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "defer", "close", "(", "s", ".", "running", ")", "\n", "if", "rand", ".", ...
// Begin running a toxic on this stub, can be interrupted. // Runs a noop toxic randomly depending on toxicity
[ "Begin", "running", "a", "toxic", "on", "this", "stub", "can", "be", "interrupted", ".", "Runs", "a", "noop", "toxic", "randomly", "depending", "on", "toxicity" ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/toxics/toxic.go#L78-L86
train
Shopify/toxiproxy
toxics/toxic.go
InterruptToxic
func (s *ToxicStub) InterruptToxic() bool { select { case <-s.closed: return false case s.Interrupt <- struct{}{}: <-s.running // Wait for the running toxic to exit return true } }
go
func (s *ToxicStub) InterruptToxic() bool { select { case <-s.closed: return false case s.Interrupt <- struct{}{}: <-s.running // Wait for the running toxic to exit return true } }
[ "func", "(", "s", "*", "ToxicStub", ")", "InterruptToxic", "(", ")", "bool", "{", "select", "{", "case", "<-", "s", ".", "closed", ":", "return", "false", "\n", "case", "s", ".", "Interrupt", "<-", "struct", "{", "}", "{", "}", ":", "<-", "s", "....
// Interrupt the flow of data so that the toxic controlling the stub can be replaced. // Returns true if the stream was successfully interrupted, or false if the stream is closed.
[ "Interrupt", "the", "flow", "of", "data", "so", "that", "the", "toxic", "controlling", "the", "stub", "can", "be", "replaced", ".", "Returns", "true", "if", "the", "stream", "was", "successfully", "interrupted", "or", "false", "if", "the", "stream", "is", ...
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/toxics/toxic.go#L90-L98
train
Shopify/toxiproxy
toxic_collection.go
findToxicByName
func (c *ToxicCollection) findToxicByName(name string) *toxics.ToxicWrapper { for dir := range c.chain { for i, toxic := range c.chain[dir] { if i == 0 { // Skip the first noop toxic, it has no name continue } if toxic.Name == name { return toxic } } } return nil }
go
func (c *ToxicCollection) findToxicByName(name string) *toxics.ToxicWrapper { for dir := range c.chain { for i, toxic := range c.chain[dir] { if i == 0 { // Skip the first noop toxic, it has no name continue } if toxic.Name == name { return toxic } } } return nil }
[ "func", "(", "c", "*", "ToxicCollection", ")", "findToxicByName", "(", "name", "string", ")", "*", "toxics", ".", "ToxicWrapper", "{", "for", "dir", ":=", "range", "c", ".", "chain", "{", "for", "i", ",", "toxic", ":=", "range", "c", ".", "chain", "[...
// All following functions assume the lock is already grabbed
[ "All", "following", "functions", "assume", "the", "lock", "is", "already", "grabbed" ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/toxic_collection.go#L188-L201
train
Shopify/toxiproxy
proxy.go
server
func (proxy *Proxy) server() { ln, err := net.Listen("tcp", proxy.Listen) if err != nil { proxy.started <- err return } proxy.Listen = ln.Addr().String() proxy.started <- nil logrus.WithFields(logrus.Fields{ "name": proxy.Name, "proxy": proxy.Listen, "upstream": proxy.Upstream, }).Info("Starte...
go
func (proxy *Proxy) server() { ln, err := net.Listen("tcp", proxy.Listen) if err != nil { proxy.started <- err return } proxy.Listen = ln.Addr().String() proxy.started <- nil logrus.WithFields(logrus.Fields{ "name": proxy.Name, "proxy": proxy.Listen, "upstream": proxy.Upstream, }).Info("Starte...
[ "func", "(", "proxy", "*", "Proxy", ")", "server", "(", ")", "{", "ln", ",", "err", ":=", "net", ".", "Listen", "(", "\"", "\"", ",", "proxy", ".", "Listen", ")", "\n", "if", "err", "!=", "nil", "{", "proxy", ".", "started", "<-", "err", "\n", ...
// server runs the Proxy server, accepting new clients and creating Links to // connect them to upstreams.
[ "server", "runs", "the", "Proxy", "server", "accepting", "new", "clients", "and", "creating", "Links", "to", "connect", "them", "to", "upstreams", "." ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/proxy.go#L94-L182
train
Shopify/toxiproxy
proxy.go
start
func start(proxy *Proxy) error { if proxy.Enabled { return ErrProxyAlreadyStarted } proxy.tomb = tomb.Tomb{} // Reset tomb, from previous starts/stops go proxy.server() err := <-proxy.started // Only enable the proxy if it successfully started proxy.Enabled = err == nil return err }
go
func start(proxy *Proxy) error { if proxy.Enabled { return ErrProxyAlreadyStarted } proxy.tomb = tomb.Tomb{} // Reset tomb, from previous starts/stops go proxy.server() err := <-proxy.started // Only enable the proxy if it successfully started proxy.Enabled = err == nil return err }
[ "func", "start", "(", "proxy", "*", "Proxy", ")", "error", "{", "if", "proxy", ".", "Enabled", "{", "return", "ErrProxyAlreadyStarted", "\n", "}", "\n\n", "proxy", ".", "tomb", "=", "tomb", ".", "Tomb", "{", "}", "// Reset tomb, from previous starts/stops", ...
// Starts a proxy, assumes the lock has already been taken
[ "Starts", "a", "proxy", "assumes", "the", "lock", "has", "already", "been", "taken" ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/proxy.go#L191-L202
train
Shopify/toxiproxy
proxy.go
stop
func stop(proxy *Proxy) { if !proxy.Enabled { return } proxy.Enabled = false proxy.tomb.Killf("Shutting down from stop()") proxy.tomb.Wait() // Wait until we stop accepting new connections proxy.connections.Lock() defer proxy.connections.Unlock() for _, conn := range proxy.connections.list { conn.Close() ...
go
func stop(proxy *Proxy) { if !proxy.Enabled { return } proxy.Enabled = false proxy.tomb.Killf("Shutting down from stop()") proxy.tomb.Wait() // Wait until we stop accepting new connections proxy.connections.Lock() defer proxy.connections.Unlock() for _, conn := range proxy.connections.list { conn.Close() ...
[ "func", "stop", "(", "proxy", "*", "Proxy", ")", "{", "if", "!", "proxy", ".", "Enabled", "{", "return", "\n", "}", "\n", "proxy", ".", "Enabled", "=", "false", "\n\n", "proxy", ".", "tomb", ".", "Killf", "(", "\"", "\"", ")", "\n", "proxy", ".",...
// Stops a proxy, assumes the lock has already been taken
[ "Stops", "a", "proxy", "assumes", "the", "lock", "has", "already", "been", "taken" ]
07d7b6381cb3b059bdd3d66b1e844ccacc2f660e
https://github.com/Shopify/toxiproxy/blob/07d7b6381cb3b059bdd3d66b1e844ccacc2f660e/proxy.go#L205-L225
train
cweill/gotests
internal/goparser/goparser.go
Parse
func (p *Parser) Parse(srcPath string, files []models.Path) (*Result, error) { b, err := p.readFile(srcPath) if err != nil { return nil, err } fset := token.NewFileSet() f, err := p.parseFile(fset, srcPath) if err != nil { return nil, err } fs, err := p.parseFiles(fset, f, files) if err != nil { return n...
go
func (p *Parser) Parse(srcPath string, files []models.Path) (*Result, error) { b, err := p.readFile(srcPath) if err != nil { return nil, err } fset := token.NewFileSet() f, err := p.parseFile(fset, srcPath) if err != nil { return nil, err } fs, err := p.parseFiles(fset, f, files) if err != nil { return n...
[ "func", "(", "p", "*", "Parser", ")", "Parse", "(", "srcPath", "string", ",", "files", "[", "]", "models", ".", "Path", ")", "(", "*", "Result", ",", "error", ")", "{", "b", ",", "err", ":=", "p", ".", "readFile", "(", "srcPath", ")", "\n", "if...
// Parse parses a given Go file at srcPath, along any files that share the same // package, into a domain model for generating tests.
[ "Parse", "parses", "a", "given", "Go", "file", "at", "srcPath", "along", "any", "files", "that", "share", "the", "same", "package", "into", "a", "domain", "model", "for", "generating", "tests", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/goparser/goparser.go#L38-L61
train
cweill/gotests
internal/goparser/goparser.go
goCode
func goCode(b []byte, f *ast.File) []byte { furthestPos := f.Name.End() for _, node := range f.Imports { if pos := node.End(); pos > furthestPos { furthestPos = pos } } if furthestPos < token.Pos(len(b)) { furthestPos++ // Avoid wrong output on windows-encoded files if b[furthestPos-2] == '\r' && b[fu...
go
func goCode(b []byte, f *ast.File) []byte { furthestPos := f.Name.End() for _, node := range f.Imports { if pos := node.End(); pos > furthestPos { furthestPos = pos } } if furthestPos < token.Pos(len(b)) { furthestPos++ // Avoid wrong output on windows-encoded files if b[furthestPos-2] == '\r' && b[fu...
[ "func", "goCode", "(", "b", "[", "]", "byte", ",", "f", "*", "ast", ".", "File", ")", "[", "]", "byte", "{", "furthestPos", ":=", "f", ".", "Name", ".", "End", "(", ")", "\n", "for", "_", ",", "node", ":=", "range", "f", ".", "Imports", "{", ...
// Returns the Go code below the imports block.
[ "Returns", "the", "Go", "code", "below", "the", "imports", "block", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/goparser/goparser.go#L163-L179
train
cweill/gotests
internal/input/input.go
Files
func Files(srcPath string) ([]models.Path, error) { srcPath, err := filepath.Abs(srcPath) if err != nil { return nil, fmt.Errorf("filepath.Abs: %v\n", err) } var fi os.FileInfo if fi, err = os.Stat(srcPath); err != nil { return nil, fmt.Errorf("os.Stat: %v\n", err) } if fi.IsDir() { return dirFiles(srcPath...
go
func Files(srcPath string) ([]models.Path, error) { srcPath, err := filepath.Abs(srcPath) if err != nil { return nil, fmt.Errorf("filepath.Abs: %v\n", err) } var fi os.FileInfo if fi, err = os.Stat(srcPath); err != nil { return nil, fmt.Errorf("os.Stat: %v\n", err) } if fi.IsDir() { return dirFiles(srcPath...
[ "func", "Files", "(", "srcPath", "string", ")", "(", "[", "]", "models", ".", "Path", ",", "error", ")", "{", "srcPath", ",", "err", ":=", "filepath", ".", "Abs", "(", "srcPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fm...
// Files returns all the Golang files for the given path. Ignores hidden files.
[ "Files", "returns", "all", "the", "Golang", "files", "for", "the", "given", "path", ".", "Ignores", "hidden", "files", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/input/input.go#L13-L26
train
cweill/gotests
internal/render/render.go
LoadCustomTemplates
func LoadCustomTemplates(dir string) error { initEmptyTmpls() files, err := ioutil.ReadDir(dir) if err != nil { return fmt.Errorf("ioutil.ReadDir: %v", err) } templateFiles := []string{} for _, f := range files { templateFiles = append(templateFiles, path.Join(dir, f.Name())) } tmpls, err = tmpls.ParseFil...
go
func LoadCustomTemplates(dir string) error { initEmptyTmpls() files, err := ioutil.ReadDir(dir) if err != nil { return fmt.Errorf("ioutil.ReadDir: %v", err) } templateFiles := []string{} for _, f := range files { templateFiles = append(templateFiles, path.Join(dir, f.Name())) } tmpls, err = tmpls.ParseFil...
[ "func", "LoadCustomTemplates", "(", "dir", "string", ")", "error", "{", "initEmptyTmpls", "(", ")", "\n\n", "files", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "dir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", ...
// LoadCustomTemplates allows to load in custom templates from a specified path.
[ "LoadCustomTemplates", "allows", "to", "load", "in", "custom", "templates", "from", "a", "specified", "path", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/render/render.go#L30-L47
train
cweill/gotests
internal/render/bindata/esc.go
FSByte
func FSByte(useLocal bool, name string) ([]byte, error) { if useLocal { f, err := _escLocal.Open(name) if err != nil { return nil, err } b, err := ioutil.ReadAll(f) _ = f.Close() return b, err } f, err := _escStatic.prepare(name) if err != nil { return nil, err } return f.data, nil }
go
func FSByte(useLocal bool, name string) ([]byte, error) { if useLocal { f, err := _escLocal.Open(name) if err != nil { return nil, err } b, err := ioutil.ReadAll(f) _ = f.Close() return b, err } f, err := _escStatic.prepare(name) if err != nil { return nil, err } return f.data, nil }
[ "func", "FSByte", "(", "useLocal", "bool", ",", "name", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "useLocal", "{", "f", ",", "err", ":=", "_escLocal", ".", "Open", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", ...
// FSByte returns the named file from the embedded assets. If useLocal is // true, the filesystem's contents are instead used.
[ "FSByte", "returns", "the", "named", "file", "from", "the", "embedded", "assets", ".", "If", "useLocal", "is", "true", "the", "filesystem", "s", "contents", "are", "instead", "used", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/render/bindata/esc.go#L173-L188
train
cweill/gotests
internal/render/bindata/esc.go
FSMustByte
func FSMustByte(useLocal bool, name string) []byte { b, err := FSByte(useLocal, name) if err != nil { panic(err) } return b }
go
func FSMustByte(useLocal bool, name string) []byte { b, err := FSByte(useLocal, name) if err != nil { panic(err) } return b }
[ "func", "FSMustByte", "(", "useLocal", "bool", ",", "name", "string", ")", "[", "]", "byte", "{", "b", ",", "err", ":=", "FSByte", "(", "useLocal", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", ...
// FSMustByte is the same as FSByte, but panics if name is not present.
[ "FSMustByte", "is", "the", "same", "as", "FSByte", "but", "panics", "if", "name", "is", "not", "present", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/render/bindata/esc.go#L191-L197
train
cweill/gotests
internal/render/bindata/esc.go
FSString
func FSString(useLocal bool, name string) (string, error) { b, err := FSByte(useLocal, name) return string(b), err }
go
func FSString(useLocal bool, name string) (string, error) { b, err := FSByte(useLocal, name) return string(b), err }
[ "func", "FSString", "(", "useLocal", "bool", ",", "name", "string", ")", "(", "string", ",", "error", ")", "{", "b", ",", "err", ":=", "FSByte", "(", "useLocal", ",", "name", ")", "\n", "return", "string", "(", "b", ")", ",", "err", "\n", "}" ]
// FSString is the string version of FSByte.
[ "FSString", "is", "the", "string", "version", "of", "FSByte", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/render/bindata/esc.go#L200-L203
train
cweill/gotests
internal/render/bindata/esc.go
FSMustString
func FSMustString(useLocal bool, name string) string { return string(FSMustByte(useLocal, name)) }
go
func FSMustString(useLocal bool, name string) string { return string(FSMustByte(useLocal, name)) }
[ "func", "FSMustString", "(", "useLocal", "bool", ",", "name", "string", ")", "string", "{", "return", "string", "(", "FSMustByte", "(", "useLocal", ",", "name", ")", ")", "\n", "}" ]
// FSMustString is the string version of FSMustByte.
[ "FSMustString", "is", "the", "string", "version", "of", "FSMustByte", "." ]
afa0a378663a63a98287714c3f3359e22a4ab29e
https://github.com/cweill/gotests/blob/afa0a378663a63a98287714c3f3359e22a4ab29e/internal/render/bindata/esc.go#L206-L208
train
dropbox/godropbox
database/binlog/parsed_event_reader.go
NewParsedV4EventReader
func NewParsedV4EventReader( reader EventReader, parsers V4EventParserMap) EventReader { return &parsedV4EventReader{ reader: reader, eventParsers: parsers, } }
go
func NewParsedV4EventReader( reader EventReader, parsers V4EventParserMap) EventReader { return &parsedV4EventReader{ reader: reader, eventParsers: parsers, } }
[ "func", "NewParsedV4EventReader", "(", "reader", "EventReader", ",", "parsers", "V4EventParserMap", ")", "EventReader", "{", "return", "&", "parsedV4EventReader", "{", "reader", ":", "reader", ",", "eventParsers", ":", "parsers", ",", "}", "\n", "}" ]
// This returns an EventReader which applies the appropriate parser on each // raw v4 event in the stream. If no parser is available for the event, // or if an error occurs during parsing, then the reader will return the // original event along with the error.
[ "This", "returns", "an", "EventReader", "which", "applies", "the", "appropriate", "parser", "on", "each", "raw", "v4", "event", "in", "the", "stream", ".", "If", "no", "parser", "is", "available", "for", "the", "event", "or", "if", "an", "error", "occurs",...
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/database/binlog/parsed_event_reader.go#L16-L24
train
dropbox/godropbox
io2/writer_to_reader_adapter.go
NewWriterToReaderAdapter
func NewWriterToReaderAdapter(toBeAdapted func(io.Reader) (io.Reader, error), output io.Writer, shouldCloseDownstream bool) io.WriteCloser { retval := privateReaderAdapter{ Writer: WriterToReaderAdapter{ workChan: make(chan *[]byte), doneWorkChan: make(chan *[]byte), errChan: make(chan error, 3),...
go
func NewWriterToReaderAdapter(toBeAdapted func(io.Reader) (io.Reader, error), output io.Writer, shouldCloseDownstream bool) io.WriteCloser { retval := privateReaderAdapter{ Writer: WriterToReaderAdapter{ workChan: make(chan *[]byte), doneWorkChan: make(chan *[]byte), errChan: make(chan error, 3),...
[ "func", "NewWriterToReaderAdapter", "(", "toBeAdapted", "func", "(", "io", ".", "Reader", ")", "(", "io", ".", "Reader", ",", "error", ")", ",", "output", "io", ".", "Writer", ",", "shouldCloseDownstream", "bool", ")", "io", ".", "WriteCloser", "{", "retva...
// This makes a io.Writer from a io.Reader and begins reading and writing data // The returned class is not thread safe and public methods must be called from a single thread
[ "This", "makes", "a", "io", ".", "Writer", "from", "a", "io", ".", "Reader", "and", "begins", "reading", "and", "writing", "data", "The", "returned", "class", "is", "not", "thread", "safe", "and", "public", "methods", "must", "be", "called", "from", "a",...
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/writer_to_reader_adapter.go#L29-L41
train
dropbox/godropbox
io2/writer_to_reader_adapter.go
Read
func (rself *privateReaderAdapter) Read(data []byte) (int, error) { lenToCopy := len(rself.bufferToBeRead) if lenToCopy == 0 { rself.workReceipt = <-rself.Writer.workChan if rself.workReceipt == nil { // no more data to consume rself.closeReceived = true return 0, io.EOF } rself.bufferToBeRead = *rse...
go
func (rself *privateReaderAdapter) Read(data []byte) (int, error) { lenToCopy := len(rself.bufferToBeRead) if lenToCopy == 0 { rself.workReceipt = <-rself.Writer.workChan if rself.workReceipt == nil { // no more data to consume rself.closeReceived = true return 0, io.EOF } rself.bufferToBeRead = *rse...
[ "func", "(", "rself", "*", "privateReaderAdapter", ")", "Read", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "lenToCopy", ":=", "len", "(", "rself", ".", "bufferToBeRead", ")", "\n", "if", "lenToCopy", "==", "0", "{", "rsel...
// this is the private Read implementation, to be used with io.Copy // on the read thread
[ "this", "is", "the", "private", "Read", "implementation", "to", "be", "used", "with", "io", ".", "Copy", "on", "the", "read", "thread" ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/writer_to_reader_adapter.go#L45-L67
train
dropbox/godropbox
io2/writer_to_reader_adapter.go
copyDataToOutput
func copyDataToOutput(inputFactory func(io.Reader) (io.Reader, error), adaptedInput *privateReaderAdapter, output io.Writer, shouldCloseDownstream bool) { input, err := inputFactory(adaptedInput) if err != nil { adaptedInput.Writer.errChan <- err } else { _, err = io.Copy(output, input) if err != nil { ...
go
func copyDataToOutput(inputFactory func(io.Reader) (io.Reader, error), adaptedInput *privateReaderAdapter, output io.Writer, shouldCloseDownstream bool) { input, err := inputFactory(adaptedInput) if err != nil { adaptedInput.Writer.errChan <- err } else { _, err = io.Copy(output, input) if err != nil { ...
[ "func", "copyDataToOutput", "(", "inputFactory", "func", "(", "io", ".", "Reader", ")", "(", "io", ".", "Reader", ",", "error", ")", ",", "adaptedInput", "*", "privateReaderAdapter", ",", "output", "io", ".", "Writer", ",", "shouldCloseDownstream", "bool", "...
// This io.Copy's as much data as possible from the wrapped reader // to the corresponding writer output. // When finished it closes the downstream and drains the upstream // writer. Finally it sends any remaining errors to the errChan and // closes that channel
[ "This", "io", ".", "Copy", "s", "as", "much", "data", "as", "possible", "from", "the", "wrapped", "reader", "to", "the", "corresponding", "writer", "output", ".", "When", "finished", "it", "closes", "the", "downstream", "and", "drains", "the", "upstream", ...
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/io2/writer_to_reader_adapter.go#L158-L187
train
dropbox/godropbox
caching/generic_storage.go
NewGenericStorage
func NewGenericStorage(name string, options GenericStorageOptions) Storage { return &GenericStorage{ name: name, get: options.GetFunc, getMulti: options.GetMultiFunc, set: options.SetFunc, setMulti: options.SetMultiFunc, del: options.DelFunc, delMulti: optio...
go
func NewGenericStorage(name string, options GenericStorageOptions) Storage { return &GenericStorage{ name: name, get: options.GetFunc, getMulti: options.GetMultiFunc, set: options.SetFunc, setMulti: options.SetMultiFunc, del: options.DelFunc, delMulti: optio...
[ "func", "NewGenericStorage", "(", "name", "string", ",", "options", "GenericStorageOptions", ")", "Storage", "{", "return", "&", "GenericStorage", "{", "name", ":", "name", ",", "get", ":", "options", ".", "GetFunc", ",", "getMulti", ":", "options", ".", "Ge...
// This creates a GenericStorage. See GenericStorageOptions for additional // information.
[ "This", "creates", "a", "GenericStorage", ".", "See", "GenericStorageOptions", "for", "additional", "information", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/caching/generic_storage.go#L59-L71
train
dropbox/godropbox
container/set/set.go
Union
func Union(s1 Set, s2 Set) Set { if s1 == nil { if s2 == nil { return nil } return s2.Copy() } s3 := s1.Copy() s3.Union(s2) return s3 }
go
func Union(s1 Set, s2 Set) Set { if s1 == nil { if s2 == nil { return nil } return s2.Copy() } s3 := s1.Copy() s3.Union(s2) return s3 }
[ "func", "Union", "(", "s1", "Set", ",", "s2", "Set", ")", "Set", "{", "if", "s1", "==", "nil", "{", "if", "s2", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "s2", ".", "Copy", "(", ")", "\n", "}", "\n", "s3", ":=", "s1", ...
// Returns a new set which is the union of s1 and s2. s1 and s2 are unmodified.
[ "Returns", "a", "new", "set", "which", "is", "the", "union", "of", "s1", "and", "s2", ".", "s1", "and", "s2", "are", "unmodified", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L50-L61
train
dropbox/godropbox
container/set/set.go
Intersect
func Intersect(s1 Set, s2 Set) Set { if s1 == nil { if s2 == nil { return nil } return s2.New() } s3 := s1.Copy() s3.Intersect(s2) return s3 }
go
func Intersect(s1 Set, s2 Set) Set { if s1 == nil { if s2 == nil { return nil } return s2.New() } s3 := s1.Copy() s3.Intersect(s2) return s3 }
[ "func", "Intersect", "(", "s1", "Set", ",", "s2", "Set", ")", "Set", "{", "if", "s1", "==", "nil", "{", "if", "s2", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "s2", ".", "New", "(", ")", "\n", "}", "\n", "s3", ":=", "s1",...
// Returns a new set which is the intersect of s1 and s2. s1 and s2 are // unmodified.
[ "Returns", "a", "new", "set", "which", "is", "the", "intersect", "of", "s1", "and", "s2", ".", "s1", "and", "s2", "are", "unmodified", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L65-L76
train
dropbox/godropbox
container/set/set.go
Subtract
func Subtract(s1 Set, s2 Set) Set { if s1 == nil { if s2 == nil { return nil } return s2.New() } s3 := s1.Copy() s3.Subtract(s2) return s3 }
go
func Subtract(s1 Set, s2 Set) Set { if s1 == nil { if s2 == nil { return nil } return s2.New() } s3 := s1.Copy() s3.Subtract(s2) return s3 }
[ "func", "Subtract", "(", "s1", "Set", ",", "s2", "Set", ")", "Set", "{", "if", "s1", "==", "nil", "{", "if", "s2", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "return", "s2", ".", "New", "(", ")", "\n", "}", "\n", "s3", ":=", "s1", ...
// Returns a new set which is the difference between s1 and s2. s1 and s2 are // unmodified.
[ "Returns", "a", "new", "set", "which", "is", "the", "difference", "between", "s1", "and", "s2", ".", "s1", "and", "s2", "are", "unmodified", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L80-L91
train
dropbox/godropbox
container/set/set.go
equal
func equal(s Set, s2 Set) bool { if s.Len() != s2.Len() { return false } return s.IsSubset(s2) }
go
func equal(s Set, s2 Set) bool { if s.Len() != s2.Len() { return false } return s.IsSubset(s2) }
[ "func", "equal", "(", "s", "Set", ",", "s2", "Set", ")", "bool", "{", "if", "s", ".", "Len", "(", ")", "!=", "s2", ".", "Len", "(", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "s", ".", "IsSubset", "(", "s2", ")", "\n", "}" ]
// Common functions between the two implementations, since go // does not allow for any inheritance.
[ "Common", "functions", "between", "the", "two", "implementations", "since", "go", "does", "not", "allow", "for", "any", "inheritance", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/container/set/set.go#L340-L346
train
dropbox/godropbox
memcache/raw_binary_client.go
NewRawBinaryClient
func NewRawBinaryClient(shard int, channel io.ReadWriter) ClientShard { return &RawBinaryClient{ shard: shard, channel: channel, validState: true, maxValueLength: defaultMaxValueLength, } }
go
func NewRawBinaryClient(shard int, channel io.ReadWriter) ClientShard { return &RawBinaryClient{ shard: shard, channel: channel, validState: true, maxValueLength: defaultMaxValueLength, } }
[ "func", "NewRawBinaryClient", "(", "shard", "int", ",", "channel", "io", ".", "ReadWriter", ")", "ClientShard", "{", "return", "&", "RawBinaryClient", "{", "shard", ":", "shard", ",", "channel", ":", "channel", ",", "validState", ":", "true", ",", "maxValueL...
// This creates a new memcache RawBinaryClient.
[ "This", "creates", "a", "new", "memcache", "RawBinaryClient", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L103-L110
train
dropbox/godropbox
memcache/raw_binary_client.go
NewLargeRawBinaryClient
func NewLargeRawBinaryClient(shard int, channel io.ReadWriter) ClientShard { return &RawBinaryClient{ shard: shard, channel: channel, validState: true, maxValueLength: largeMaxValueLength, } }
go
func NewLargeRawBinaryClient(shard int, channel io.ReadWriter) ClientShard { return &RawBinaryClient{ shard: shard, channel: channel, validState: true, maxValueLength: largeMaxValueLength, } }
[ "func", "NewLargeRawBinaryClient", "(", "shard", "int", ",", "channel", "io", ".", "ReadWriter", ")", "ClientShard", "{", "return", "&", "RawBinaryClient", "{", "shard", ":", "shard", ",", "channel", ":", "channel", ",", "validState", ":", "true", ",", "maxV...
// This creates a new memcache RawBinaryClient for use with np-large cluster.
[ "This", "creates", "a", "new", "memcache", "RawBinaryClient", "for", "use", "with", "np", "-", "large", "cluster", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L113-L120
train
dropbox/godropbox
memcache/raw_binary_client.go
mutate
func (c *RawBinaryClient) mutate(code opCode, item *Item) MutateResponse { if item == nil { return NewMutateErrorResponse("", errors.New("item is nil")) } c.mutex.Lock() defer c.mutex.Unlock() if resp := c.sendMutateRequest(code, item, true); resp != nil { return resp } return c.receiveMutateResponse(code...
go
func (c *RawBinaryClient) mutate(code opCode, item *Item) MutateResponse { if item == nil { return NewMutateErrorResponse("", errors.New("item is nil")) } c.mutex.Lock() defer c.mutex.Unlock() if resp := c.sendMutateRequest(code, item, true); resp != nil { return resp } return c.receiveMutateResponse(code...
[ "func", "(", "c", "*", "RawBinaryClient", ")", "mutate", "(", "code", "opCode", ",", "item", "*", "Item", ")", "MutateResponse", "{", "if", "item", "==", "nil", "{", "return", "NewMutateErrorResponse", "(", "\"", "\"", ",", "errors", ".", "New", "(", "...
// Perform a mutation operation specified by the given code.
[ "Perform", "a", "mutation", "operation", "specified", "by", "the", "given", "code", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/memcache/raw_binary_client.go#L443-L456
train
dropbox/godropbox
rate_limiter/rate_limiter.go
MaxQuota
func (l *rateLimiterImpl) MaxQuota() float64 { l.mutex.Lock() defer l.mutex.Unlock() return l.maxQuota }
go
func (l *rateLimiterImpl) MaxQuota() float64 { l.mutex.Lock() defer l.mutex.Unlock() return l.maxQuota }
[ "func", "(", "l", "*", "rateLimiterImpl", ")", "MaxQuota", "(", ")", "float64", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "l", ".", "maxQuota", "\n", "}" ]
// This returns the leaky bucket's maximum capacity.
[ "This", "returns", "the", "leaky", "bucket", "s", "maximum", "capacity", "." ]
5749d3b71cbefd8eacc316df3f0a6fcb9991bb51
https://github.com/dropbox/godropbox/blob/5749d3b71cbefd8eacc316df3f0a6fcb9991bb51/rate_limiter/rate_limiter.go#L147-L151
train