id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
21,700
golang/lint
lint.go
lintPackageComment
func (f *file) lintPackageComment() { if f.isTest() { return } const ref = styleGuideBase + "#package-comments" prefix := "Package " + f.f.Name.Name + " " // Look for a detached package comment. // First, scan for the last comment that occurs before the "package" keyword. var lastCG *ast.CommentGroup for _,...
go
func (f *file) lintPackageComment() { if f.isTest() { return } const ref = styleGuideBase + "#package-comments" prefix := "Package " + f.f.Name.Name + " " // Look for a detached package comment. // First, scan for the last comment that occurs before the "package" keyword. var lastCG *ast.CommentGroup for _,...
[ "func", "(", "f", "*", "file", ")", "lintPackageComment", "(", ")", "{", "if", "f", ".", "isTest", "(", ")", "{", "return", "\n", "}", "\n\n", "const", "ref", "=", "styleGuideBase", "+", "\"", "\"", "\n", "prefix", ":=", "\"", "\"", "+", "f", "."...
// lintPackageComment checks package comments. It complains if // there is no package comment, or if it is not of the right form. // This has a notable false positive in that a package comment // could rightfully appear in a different file of the same package, // but that's not easy to fix since this linter is file-ori...
[ "lintPackageComment", "checks", "package", "comments", ".", "It", "complains", "if", "there", "is", "no", "package", "comment", "or", "if", "it", "is", "not", "of", "the", "right", "form", ".", "This", "has", "a", "notable", "false", "positive", "in", "tha...
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L380-L429
21,701
golang/lint
lint.go
lintBlankImports
func (f *file) lintBlankImports() { // In package main and in tests, we don't complain about blank imports. if f.pkg.main || f.isTest() { return } // The first element of each contiguous group of blank imports should have // an explanatory comment of some kind. for i, imp := range f.f.Imports { pos := f.fset...
go
func (f *file) lintBlankImports() { // In package main and in tests, we don't complain about blank imports. if f.pkg.main || f.isTest() { return } // The first element of each contiguous group of blank imports should have // an explanatory comment of some kind. for i, imp := range f.f.Imports { pos := f.fset...
[ "func", "(", "f", "*", "file", ")", "lintBlankImports", "(", ")", "{", "// In package main and in tests, we don't complain about blank imports.", "if", "f", ".", "pkg", ".", "main", "||", "f", ".", "isTest", "(", ")", "{", "return", "\n", "}", "\n\n", "// The ...
// lintBlankImports complains if a non-main package has blank imports that are // not documented.
[ "lintBlankImports", "complains", "if", "a", "non", "-", "main", "package", "has", "blank", "imports", "that", "are", "not", "documented", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L433-L461
21,702
golang/lint
lint.go
lintImports
func (f *file) lintImports() { for i, is := range f.f.Imports { _ = i if is.Name != nil && is.Name.Name == "." && !f.isTest() { f.errorf(is, 1, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports") } } }
go
func (f *file) lintImports() { for i, is := range f.f.Imports { _ = i if is.Name != nil && is.Name.Name == "." && !f.isTest() { f.errorf(is, 1, link(styleGuideBase+"#import-dot"), category("imports"), "should not use dot imports") } } }
[ "func", "(", "f", "*", "file", ")", "lintImports", "(", ")", "{", "for", "i", ",", "is", ":=", "range", "f", ".", "f", ".", "Imports", "{", "_", "=", "i", "\n", "if", "is", ".", "Name", "!=", "nil", "&&", "is", ".", "Name", ".", "Name", "==...
// lintImports examines import blocks.
[ "lintImports", "examines", "import", "blocks", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L464-L472
21,703
golang/lint
lint.go
lintExported
func (f *file) lintExported() { if f.isTest() { return } var lastGen *ast.GenDecl // last GenDecl entered. // Set of GenDecls that have already had missing comments flagged. genDeclMissingComments := make(map[*ast.GenDecl]bool) f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl...
go
func (f *file) lintExported() { if f.isTest() { return } var lastGen *ast.GenDecl // last GenDecl entered. // Set of GenDecls that have already had missing comments flagged. genDeclMissingComments := make(map[*ast.GenDecl]bool) f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl...
[ "func", "(", "f", "*", "file", ")", "lintExported", "(", ")", "{", "if", "f", ".", "isTest", "(", ")", "{", "return", "\n", "}", "\n\n", "var", "lastGen", "*", "ast", ".", "GenDecl", "// last GenDecl entered.", "\n\n", "// Set of GenDecls that have already h...
// lintExported examines the exported names. // It complains if any required doc comments are missing, // or if they are not of the right form. The exact rules are in // lintFuncDoc, lintTypeDoc and lintValueSpecDoc; this function // also tracks the GenDecl structure being traversed to permit // doc comments for consta...
[ "lintExported", "examines", "the", "exported", "names", ".", "It", "complains", "if", "any", "required", "doc", "comments", "are", "missing", "or", "if", "they", "are", "not", "of", "the", "right", "form", ".", "The", "exact", "rules", "are", "in", "lintFu...
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L484-L528
21,704
golang/lint
lint.go
lintTypeDoc
func (f *file) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { if !ast.IsExported(t.Name.Name) { return } if doc == nil { f.errorf(t, 1, link(docCommentsLink), category("comments"), "exported type %v should have comment or be unexported", t.Name) return } s := doc.Text() articles := [...]string{"A", ...
go
func (f *file) lintTypeDoc(t *ast.TypeSpec, doc *ast.CommentGroup) { if !ast.IsExported(t.Name.Name) { return } if doc == nil { f.errorf(t, 1, link(docCommentsLink), category("comments"), "exported type %v should have comment or be unexported", t.Name) return } s := doc.Text() articles := [...]string{"A", ...
[ "func", "(", "f", "*", "file", ")", "lintTypeDoc", "(", "t", "*", "ast", ".", "TypeSpec", ",", "doc", "*", "ast", ".", "CommentGroup", ")", "{", "if", "!", "ast", ".", "IsExported", "(", "t", ".", "Name", ".", "Name", ")", "{", "return", "\n", ...
// lintTypeDoc examines the doc comment on a type. // It complains if they are missing from an exported type, // or if they are not of the standard form.
[ "lintTypeDoc", "examines", "the", "doc", "comment", "on", "a", "type", ".", "It", "complains", "if", "they", "are", "missing", "from", "an", "exported", "type", "or", "if", "they", "are", "not", "of", "the", "standard", "form", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L815-L835
21,705
golang/lint
lint.go
lintVarDecls
func (f *file) lintVarDecls() { var lastGen *ast.GenDecl // last GenDecl entered. f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl: if v.Tok != token.CONST && v.Tok != token.VAR { return false } lastGen = v return true case *ast.ValueSpec: if lastGen.Tok == token...
go
func (f *file) lintVarDecls() { var lastGen *ast.GenDecl // last GenDecl entered. f.walk(func(node ast.Node) bool { switch v := node.(type) { case *ast.GenDecl: if v.Tok != token.CONST && v.Tok != token.VAR { return false } lastGen = v return true case *ast.ValueSpec: if lastGen.Tok == token...
[ "func", "(", "f", "*", "file", ")", "lintVarDecls", "(", ")", "{", "var", "lastGen", "*", "ast", ".", "GenDecl", "// last GenDecl entered.", "\n\n", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "switch", "v", ":="...
// lintVarDecls examines variable declarations. It complains about declarations with // redundant LHS types that can be inferred from the RHS.
[ "lintVarDecls", "examines", "variable", "declarations", ".", "It", "complains", "about", "declarations", "with", "redundant", "LHS", "types", "that", "can", "be", "inferred", "from", "the", "RHS", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L982-L1050
21,706
golang/lint
lint.go
lintElses
func (f *file) lintElses() { // We don't want to flag if { } else if { } else { } constructions. // They will appear as an IfStmt whose Else field is also an IfStmt. // Record such a node so we ignore it when we visit it. ignore := make(map[*ast.IfStmt]bool) f.walk(func(node ast.Node) bool { ifStmt, ok := node....
go
func (f *file) lintElses() { // We don't want to flag if { } else if { } else { } constructions. // They will appear as an IfStmt whose Else field is also an IfStmt. // Record such a node so we ignore it when we visit it. ignore := make(map[*ast.IfStmt]bool) f.walk(func(node ast.Node) bool { ifStmt, ok := node....
[ "func", "(", "f", "*", "file", ")", "lintElses", "(", ")", "{", "// We don't want to flag if { } else if { } else { } constructions.", "// They will appear as an IfStmt whose Else field is also an IfStmt.", "// Record such a node so we ignore it when we visit it.", "ignore", ":=", "mak...
// lintElses examines else blocks. It complains about any else block whose if block ends in a return.
[ "lintElses", "examines", "else", "blocks", ".", "It", "complains", "about", "any", "else", "block", "whose", "if", "block", "ends", "in", "a", "return", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1059-L1100
21,707
golang/lint
lint.go
lintRanges
func (f *file) lintRanges() { f.walk(func(node ast.Node) bool { rs, ok := node.(*ast.RangeStmt) if !ok { return true } if isIdent(rs.Key, "_") && (rs.Value == nil || isIdent(rs.Value, "_")) { p := f.errorf(rs.Key, 1, category("range-loop"), "should omit values from range; this loop is equivalent to `for...
go
func (f *file) lintRanges() { f.walk(func(node ast.Node) bool { rs, ok := node.(*ast.RangeStmt) if !ok { return true } if isIdent(rs.Key, "_") && (rs.Value == nil || isIdent(rs.Value, "_")) { p := f.errorf(rs.Key, 1, category("range-loop"), "should omit values from range; this loop is equivalent to `for...
[ "func", "(", "f", "*", "file", ")", "lintRanges", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "rs", ",", "ok", ":=", "node", ".", "(", "*", "ast", ".", "RangeStmt", ")", "\n", "if", "!", ...
// lintRanges examines range clauses. It complains about redundant constructions.
[ "lintRanges", "examines", "range", "clauses", ".", "It", "complains", "about", "redundant", "constructions", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1103-L1131
21,708
golang/lint
lint.go
lintErrorf
func (f *file) lintErrorf() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok || len(ce.Args) != 1 { return true } isErrorsNew := isPkgDot(ce.Fun, "errors", "New") var isTestingError bool se, ok := ce.Fun.(*ast.SelectorExpr) if ok && se.Sel.Name == "Error" { if typ := f.pkg....
go
func (f *file) lintErrorf() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok || len(ce.Args) != 1 { return true } isErrorsNew := isPkgDot(ce.Fun, "errors", "New") var isTestingError bool se, ok := ce.Fun.(*ast.SelectorExpr) if ok && se.Sel.Name == "Error" { if typ := f.pkg....
[ "func", "(", "f", "*", "file", ")", "lintErrorf", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "ce", ",", "ok", ":=", "node", ".", "(", "*", "ast", ".", "CallExpr", ")", "\n", "if", "!", "...
// lintErrorf examines errors.New and testing.Error calls. It complains if its only argument is an fmt.Sprintf invocation.
[ "lintErrorf", "examines", "errors", ".", "New", "and", "testing", ".", "Error", "calls", ".", "It", "complains", "if", "its", "only", "argument", "is", "an", "fmt", ".", "Sprintf", "invocation", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1134-L1172
21,709
golang/lint
lint.go
lintErrors
func (f *file) lintErrors() { for _, decl := range f.f.Decls { gd, ok := decl.(*ast.GenDecl) if !ok || gd.Tok != token.VAR { continue } for _, spec := range gd.Specs { spec := spec.(*ast.ValueSpec) if len(spec.Names) != 1 || len(spec.Values) != 1 { continue } ce, ok := spec.Values[0].(*ast.C...
go
func (f *file) lintErrors() { for _, decl := range f.f.Decls { gd, ok := decl.(*ast.GenDecl) if !ok || gd.Tok != token.VAR { continue } for _, spec := range gd.Specs { spec := spec.(*ast.ValueSpec) if len(spec.Names) != 1 || len(spec.Values) != 1 { continue } ce, ok := spec.Values[0].(*ast.C...
[ "func", "(", "f", "*", "file", ")", "lintErrors", "(", ")", "{", "for", "_", ",", "decl", ":=", "range", "f", ".", "f", ".", "Decls", "{", "gd", ",", "ok", ":=", "decl", ".", "(", "*", "ast", ".", "GenDecl", ")", "\n", "if", "!", "ok", "||"...
// lintErrors examines global error vars. It complains if they aren't named in the standard way.
[ "lintErrors", "examines", "global", "error", "vars", ".", "It", "complains", "if", "they", "aren", "t", "named", "in", "the", "standard", "way", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1175-L1204
21,710
golang/lint
lint.go
lintErrorStrings
func (f *file) lintErrorStrings() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok { return true } if !isPkgDot(ce.Fun, "errors", "New") && !isPkgDot(ce.Fun, "fmt", "Errorf") { return true } if len(ce.Args) < 1 { return true } str, ok := ce.Args[0].(*ast.BasicLit) if...
go
func (f *file) lintErrorStrings() { f.walk(func(node ast.Node) bool { ce, ok := node.(*ast.CallExpr) if !ok { return true } if !isPkgDot(ce.Fun, "errors", "New") && !isPkgDot(ce.Fun, "fmt", "Errorf") { return true } if len(ce.Args) < 1 { return true } str, ok := ce.Args[0].(*ast.BasicLit) if...
[ "func", "(", "f", "*", "file", ")", "lintErrorStrings", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "node", "ast", ".", "Node", ")", "bool", "{", "ce", ",", "ok", ":=", "node", ".", "(", "*", "ast", ".", "CallExpr", ")", "\n", "if", "!...
// lintErrorStrings examines error strings. // It complains if they are capitalized or end in punctuation or a newline.
[ "lintErrorStrings", "examines", "error", "strings", ".", "It", "complains", "if", "they", "are", "capitalized", "or", "end", "in", "punctuation", "or", "a", "newline", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1230-L1259
21,711
golang/lint
lint.go
lintReceiverNames
func (f *file) lintReceiverNames() { typeReceiver := map[string]string{} f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Recv == nil || len(fn.Recv.List) == 0 { return true } names := fn.Recv.List[0].Names if len(names) < 1 { return true } name := names[0].Name const ref ...
go
func (f *file) lintReceiverNames() { typeReceiver := map[string]string{} f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Recv == nil || len(fn.Recv.List) == 0 { return true } names := fn.Recv.List[0].Names if len(names) < 1 { return true } name := names[0].Name const ref ...
[ "func", "(", "f", "*", "file", ")", "lintReceiverNames", "(", ")", "{", "typeReceiver", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", "...
// lintReceiverNames examines receiver names. It complains about inconsistent // names used for the same type and names such as "this".
[ "lintReceiverNames", "examines", "receiver", "names", ".", "It", "complains", "about", "inconsistent", "names", "used", "for", "the", "same", "type", "and", "names", "such", "as", "this", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1263-L1292
21,712
golang/lint
lint.go
lintErrorReturn
func (f *file) lintErrorReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Type.Results == nil { return true } ret := fn.Type.Results.List if len(ret) <= 1 { return true } if isIdent(ret[len(ret)-1].Type, "error") { return true } // An error return parameter s...
go
func (f *file) lintErrorReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || fn.Type.Results == nil { return true } ret := fn.Type.Results.List if len(ret) <= 1 { return true } if isIdent(ret[len(ret)-1].Type, "error") { return true } // An error return parameter s...
[ "func", "(", "f", "*", "file", ")", "lintErrorReturn", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "FuncDecl", ")", "\n", "if", "!", "o...
// lintErrorReturn examines function declarations that return an error. // It complains if the error isn't the last parameter.
[ "lintErrorReturn", "examines", "function", "declarations", "that", "return", "an", "error", ".", "It", "complains", "if", "the", "error", "isn", "t", "the", "last", "parameter", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1324-L1347
21,713
golang/lint
lint.go
lintUnexportedReturn
func (f *file) lintUnexportedReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok { return true } if fn.Type.Results == nil { return false } if !fn.Name.IsExported() { return false } thing := "func" if fn.Recv != nil && len(fn.Recv.List) > 0 { thing = "method" i...
go
func (f *file) lintUnexportedReturn() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok { return true } if fn.Type.Results == nil { return false } if !fn.Name.IsExported() { return false } thing := "func" if fn.Recv != nil && len(fn.Recv.List) > 0 { thing = "method" i...
[ "func", "(", "f", "*", "file", ")", "lintUnexportedReturn", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "FuncDecl", ")", "\n", "if", "!",...
// lintUnexportedReturn examines exported function declarations. // It complains if any return an unexported type.
[ "lintUnexportedReturn", "examines", "exported", "function", "declarations", ".", "It", "complains", "if", "any", "return", "an", "unexported", "type", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1351-L1384
21,714
golang/lint
lint.go
exportedType
func exportedType(typ types.Type) bool { switch T := typ.(type) { case *types.Named: // Builtin types have no package. return T.Obj().Pkg() == nil || T.Obj().Exported() case *types.Map: return exportedType(T.Key()) && exportedType(T.Elem()) case interface { Elem() types.Type }: // array, slice, pointer, ch...
go
func exportedType(typ types.Type) bool { switch T := typ.(type) { case *types.Named: // Builtin types have no package. return T.Obj().Pkg() == nil || T.Obj().Exported() case *types.Map: return exportedType(T.Key()) && exportedType(T.Elem()) case interface { Elem() types.Type }: // array, slice, pointer, ch...
[ "func", "exportedType", "(", "typ", "types", ".", "Type", ")", "bool", "{", "switch", "T", ":=", "typ", ".", "(", "type", ")", "{", "case", "*", "types", ".", "Named", ":", "// Builtin types have no package.", "return", "T", ".", "Obj", "(", ")", ".", ...
// exportedType reports whether typ is an exported type. // It is imprecise, and will err on the side of returning true, // such as for composite types.
[ "exportedType", "reports", "whether", "typ", "is", "an", "exported", "type", ".", "It", "is", "imprecise", "and", "will", "err", "on", "the", "side", "of", "returning", "true", "such", "as", "for", "composite", "types", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1389-L1403
21,715
golang/lint
lint.go
checkContextKeyType
func (f *file) checkContextKeyType(x *ast.CallExpr) { sel, ok := x.Fun.(*ast.SelectorExpr) if !ok { return } pkg, ok := sel.X.(*ast.Ident) if !ok || pkg.Name != "context" { return } if sel.Sel.Name != "WithValue" { return } // key is second argument to context.WithValue if len(x.Args) != 3 { return ...
go
func (f *file) checkContextKeyType(x *ast.CallExpr) { sel, ok := x.Fun.(*ast.SelectorExpr) if !ok { return } pkg, ok := sel.X.(*ast.Ident) if !ok || pkg.Name != "context" { return } if sel.Sel.Name != "WithValue" { return } // key is second argument to context.WithValue if len(x.Args) != 3 { return ...
[ "func", "(", "f", "*", "file", ")", "checkContextKeyType", "(", "x", "*", "ast", ".", "CallExpr", ")", "{", "sel", ",", "ok", ":=", "x", ".", "Fun", ".", "(", "*", "ast", ".", "SelectorExpr", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}"...
// checkContextKeyType reports an error if the call expression calls // context.WithValue with a key argument of basic type.
[ "checkContextKeyType", "reports", "an", "error", "if", "the", "call", "expression", "calls", "context", ".", "WithValue", "with", "a", "key", "argument", "of", "basic", "type", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1464-L1486
21,716
golang/lint
lint.go
lintContextArgs
func (f *file) lintContextArgs() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || len(fn.Type.Params.List) <= 1 { return true } // A context.Context should be the first parameter of a function. // Flag any that show up after the first. for _, arg := range fn.Type.Params.List[1:] { ...
go
func (f *file) lintContextArgs() { f.walk(func(n ast.Node) bool { fn, ok := n.(*ast.FuncDecl) if !ok || len(fn.Type.Params.List) <= 1 { return true } // A context.Context should be the first parameter of a function. // Flag any that show up after the first. for _, arg := range fn.Type.Params.List[1:] { ...
[ "func", "(", "f", "*", "file", ")", "lintContextArgs", "(", ")", "{", "f", ".", "walk", "(", "func", "(", "n", "ast", ".", "Node", ")", "bool", "{", "fn", ",", "ok", ":=", "n", ".", "(", "*", "ast", ".", "FuncDecl", ")", "\n", "if", "!", "o...
// lintContextArgs examines function declarations that contain an // argument with a type of context.Context // It complains if that argument isn't the first parameter.
[ "lintContextArgs", "examines", "function", "declarations", "that", "contain", "an", "argument", "with", "a", "type", "of", "context", ".", "Context", "It", "complains", "if", "that", "argument", "isn", "t", "the", "first", "parameter", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1491-L1507
21,717
golang/lint
lint.go
isUntypedConst
func (f *file) isUntypedConst(expr ast.Expr) (defType string, ok bool) { // Re-evaluate expr outside of its context to see if it's untyped. // (An expr evaluated within, for example, an assignment context will get the type of the LHS.) exprStr := f.render(expr) tv, err := types.Eval(f.fset, f.pkg.typesPkg, expr.Pos...
go
func (f *file) isUntypedConst(expr ast.Expr) (defType string, ok bool) { // Re-evaluate expr outside of its context to see if it's untyped. // (An expr evaluated within, for example, an assignment context will get the type of the LHS.) exprStr := f.render(expr) tv, err := types.Eval(f.fset, f.pkg.typesPkg, expr.Pos...
[ "func", "(", "f", "*", "file", ")", "isUntypedConst", "(", "expr", "ast", ".", "Expr", ")", "(", "defType", "string", ",", "ok", "bool", ")", "{", "// Re-evaluate expr outside of its context to see if it's untyped.", "// (An expr evaluated within, for example, an assignme...
// isUntypedConst reports whether expr is an untyped constant, // and indicates what its default type is. // scope may be nil.
[ "isUntypedConst", "reports", "whether", "expr", "is", "an", "untyped", "constant", "and", "indicates", "what", "its", "default", "type", "is", ".", "scope", "may", "be", "nil", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1622-L1637
21,718
golang/lint
lint.go
firstLineOf
func (f *file) firstLineOf(node, match ast.Node) string { line := f.render(node) if i := strings.Index(line, "\n"); i >= 0 { line = line[:i] } return f.indentOf(match) + line }
go
func (f *file) firstLineOf(node, match ast.Node) string { line := f.render(node) if i := strings.Index(line, "\n"); i >= 0 { line = line[:i] } return f.indentOf(match) + line }
[ "func", "(", "f", "*", "file", ")", "firstLineOf", "(", "node", ",", "match", "ast", ".", "Node", ")", "string", "{", "line", ":=", "f", ".", "render", "(", "node", ")", "\n", "if", "i", ":=", "strings", ".", "Index", "(", "line", ",", "\"", "\...
// firstLineOf renders the given node and returns its first line. // It will also match the indentation of another node.
[ "firstLineOf", "renders", "the", "given", "node", "and", "returns", "its", "first", "line", ".", "It", "will", "also", "match", "the", "indentation", "of", "another", "node", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1641-L1647
21,719
golang/lint
lint.go
imports
func (f *file) imports(importPath string) bool { all := astutil.Imports(f.fset, f.f) for _, p := range all { for _, i := range p { uq, err := strconv.Unquote(i.Path.Value) if err == nil && importPath == uq { return true } } } return false }
go
func (f *file) imports(importPath string) bool { all := astutil.Imports(f.fset, f.f) for _, p := range all { for _, i := range p { uq, err := strconv.Unquote(i.Path.Value) if err == nil && importPath == uq { return true } } } return false }
[ "func", "(", "f", "*", "file", ")", "imports", "(", "importPath", "string", ")", "bool", "{", "all", ":=", "astutil", ".", "Imports", "(", "f", ".", "fset", ",", "f", ".", "f", ")", "\n", "for", "_", ",", "p", ":=", "range", "all", "{", "for", ...
// imports returns true if the current file imports the specified package path.
[ "imports", "returns", "true", "if", "the", "current", "file", "imports", "the", "specified", "package", "path", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1669-L1680
21,720
golang/lint
lint.go
srcLine
func srcLine(src []byte, p token.Position) string { // Run to end of line in both directions if not at line start/end. lo, hi := p.Offset, p.Offset+1 for lo > 0 && src[lo-1] != '\n' { lo-- } for hi < len(src) && src[hi-1] != '\n' { hi++ } return string(src[lo:hi]) }
go
func srcLine(src []byte, p token.Position) string { // Run to end of line in both directions if not at line start/end. lo, hi := p.Offset, p.Offset+1 for lo > 0 && src[lo-1] != '\n' { lo-- } for hi < len(src) && src[hi-1] != '\n' { hi++ } return string(src[lo:hi]) }
[ "func", "srcLine", "(", "src", "[", "]", "byte", ",", "p", "token", ".", "Position", ")", "string", "{", "// Run to end of line in both directions if not at line start/end.", "lo", ",", "hi", ":=", "p", ".", "Offset", ",", "p", ".", "Offset", "+", "1", "\n",...
// srcLine returns the complete line at p, including the terminating newline.
[ "srcLine", "returns", "the", "complete", "line", "at", "p", "including", "the", "terminating", "newline", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/lint.go#L1683-L1693
21,721
golang/lint
golint/import.go
importPaths
func importPaths(args []string) []string { args = importPathsNoDotExpansion(args) var out []string for _, a := range args { if strings.Contains(a, "...") { if build.IsLocalImport(a) { out = append(out, allPackagesInFS(a)...) } else { out = append(out, allPackages(a)...) } continue } out = a...
go
func importPaths(args []string) []string { args = importPathsNoDotExpansion(args) var out []string for _, a := range args { if strings.Contains(a, "...") { if build.IsLocalImport(a) { out = append(out, allPackagesInFS(a)...) } else { out = append(out, allPackages(a)...) } continue } out = a...
[ "func", "importPaths", "(", "args", "[", "]", "string", ")", "[", "]", "string", "{", "args", "=", "importPathsNoDotExpansion", "(", "args", ")", "\n", "var", "out", "[", "]", "string", "\n", "for", "_", ",", "a", ":=", "range", "args", "{", "if", ...
// importPaths returns the import paths to use for the given command line.
[ "importPaths", "returns", "the", "import", "paths", "to", "use", "for", "the", "given", "command", "line", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/golint/import.go#L65-L80
21,722
golang/lint
golint/import.go
hasPathPrefix
func hasPathPrefix(s, prefix string) bool { switch { default: return false case len(s) == len(prefix): return s == prefix case len(s) > len(prefix): if prefix != "" && prefix[len(prefix)-1] == '/' { return strings.HasPrefix(s, prefix) } return s[len(prefix)] == '/' && s[:len(prefix)] == prefix } }
go
func hasPathPrefix(s, prefix string) bool { switch { default: return false case len(s) == len(prefix): return s == prefix case len(s) > len(prefix): if prefix != "" && prefix[len(prefix)-1] == '/' { return strings.HasPrefix(s, prefix) } return s[len(prefix)] == '/' && s[:len(prefix)] == prefix } }
[ "func", "hasPathPrefix", "(", "s", ",", "prefix", "string", ")", "bool", "{", "switch", "{", "default", ":", "return", "false", "\n", "case", "len", "(", "s", ")", "==", "len", "(", "prefix", ")", ":", "return", "s", "==", "prefix", "\n", "case", "...
// hasPathPrefix reports whether the path s begins with the // elements in prefix.
[ "hasPathPrefix", "reports", "whether", "the", "path", "s", "begins", "with", "the", "elements", "in", "prefix", "." ]
959b441ac422379a43da2230f62be024250818b0
https://github.com/golang/lint/blob/959b441ac422379a43da2230f62be024250818b0/golint/import.go#L101-L113
21,723
hashicorp/go-plugin
grpc_client.go
newGRPCClient
func newGRPCClient(doneCtx context.Context, c *Client) (*GRPCClient, error) { conn, err := dialGRPCConn(c.config.TLSConfig, c.dialer) if err != nil { return nil, err } // Start the broker. brokerGRPCClient := newGRPCBrokerClient(conn) broker := newGRPCBroker(brokerGRPCClient, c.config.TLSConfig) go broker.Run...
go
func newGRPCClient(doneCtx context.Context, c *Client) (*GRPCClient, error) { conn, err := dialGRPCConn(c.config.TLSConfig, c.dialer) if err != nil { return nil, err } // Start the broker. brokerGRPCClient := newGRPCBrokerClient(conn) broker := newGRPCBroker(brokerGRPCClient, c.config.TLSConfig) go broker.Run...
[ "func", "newGRPCClient", "(", "doneCtx", "context", ".", "Context", ",", "c", "*", "Client", ")", "(", "*", "GRPCClient", ",", "error", ")", "{", "conn", ",", "err", ":=", "dialGRPCConn", "(", "c", ".", "config", ".", "TLSConfig", ",", "c", ".", "dia...
// newGRPCClient creates a new GRPCClient. The Client argument is expected // to be successfully started already with a lock held.
[ "newGRPCClient", "creates", "a", "new", "GRPCClient", ".", "The", "Client", "argument", "is", "expected", "to", "be", "successfully", "started", "already", "with", "a", "lock", "held", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_client.go#L47-L68
21,724
hashicorp/go-plugin
server_mux.go
ServeMux
func ServeMux(m ServeMuxMap) { if len(os.Args) != 2 { fmt.Fprintf(os.Stderr, "Invoked improperly. This is an internal command that shouldn't\n"+ "be manually invoked.\n") os.Exit(1) } opts, ok := m[os.Args[1]] if !ok { fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1]) os.Exit(1) } Serve(...
go
func ServeMux(m ServeMuxMap) { if len(os.Args) != 2 { fmt.Fprintf(os.Stderr, "Invoked improperly. This is an internal command that shouldn't\n"+ "be manually invoked.\n") os.Exit(1) } opts, ok := m[os.Args[1]] if !ok { fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1]) os.Exit(1) } Serve(...
[ "func", "ServeMux", "(", "m", "ServeMuxMap", ")", "{", "if", "len", "(", "os", ".", "Args", ")", "!=", "2", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\"", "+", "\"", "\\n", "\"", ")", "\n", "os", ".", "Exit", "(...
// ServeMux is like Serve, but serves multiple types of plugins determined // by the argument given on the command-line. // // This command doesn't return until the plugin is done being executed. Any // errors are logged or output to stderr.
[ "ServeMux", "is", "like", "Serve", "but", "serves", "multiple", "types", "of", "plugins", "determined", "by", "the", "argument", "given", "on", "the", "command", "-", "line", ".", "This", "command", "doesn", "t", "return", "until", "the", "plugin", "is", "...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/server_mux.go#L16-L31
21,725
hashicorp/go-plugin
grpc_broker.go
Recv
func (s *gRPCBrokerServer) Recv() (*plugin.ConnInfo, error) { select { case <-s.quit: return nil, errors.New("broker closed") case i := <-s.recv: return i, nil } }
go
func (s *gRPCBrokerServer) Recv() (*plugin.ConnInfo, error) { select { case <-s.quit: return nil, errors.New("broker closed") case i := <-s.recv: return i, nil } }
[ "func", "(", "s", "*", "gRPCBrokerServer", ")", "Recv", "(", ")", "(", "*", "plugin", ".", "ConnInfo", ",", "error", ")", "{", "select", "{", "case", "<-", "s", ".", "quit", ":", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", ...
// Recv is used by the GRPCBroker to pass connection information that has been // sent from the client from the stream to the broker.
[ "Recv", "is", "used", "by", "the", "GRPCBroker", "to", "pass", "connection", "information", "that", "has", "been", "sent", "from", "the", "client", "from", "the", "stream", "to", "the", "broker", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L120-L127
21,726
hashicorp/go-plugin
grpc_broker.go
Send
func (s *gRPCBrokerClientImpl) Send(i *plugin.ConnInfo) error { ch := make(chan error) defer close(ch) select { case <-s.quit: return errors.New("broker closed") case s.send <- &sendErr{ i: i, ch: ch, }: } return <-ch }
go
func (s *gRPCBrokerClientImpl) Send(i *plugin.ConnInfo) error { ch := make(chan error) defer close(ch) select { case <-s.quit: return errors.New("broker closed") case s.send <- &sendErr{ i: i, ch: ch, }: } return <-ch }
[ "func", "(", "s", "*", "gRPCBrokerClientImpl", ")", "Send", "(", "i", "*", "plugin", ".", "ConnInfo", ")", "error", "{", "ch", ":=", "make", "(", "chan", "error", ")", "\n", "defer", "close", "(", "ch", ")", "\n\n", "select", "{", "case", "<-", "s"...
// Send is used by the GRPCBroker to pass connection information into the stream // to the plugin.
[ "Send", "is", "used", "by", "the", "GRPCBroker", "to", "pass", "connection", "information", "into", "the", "stream", "to", "the", "plugin", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L212-L226
21,727
hashicorp/go-plugin
grpc_broker.go
AcceptAndServe
func (b *GRPCBroker) AcceptAndServe(id uint32, s func([]grpc.ServerOption) *grpc.Server) { listener, err := b.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } defer listener.Close() var opts []grpc.ServerOption if b.tls != nil { opts = []grpc.ServerOption...
go
func (b *GRPCBroker) AcceptAndServe(id uint32, s func([]grpc.ServerOption) *grpc.Server) { listener, err := b.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } defer listener.Close() var opts []grpc.ServerOption if b.tls != nil { opts = []grpc.ServerOption...
[ "func", "(", "b", "*", "GRPCBroker", ")", "AcceptAndServe", "(", "id", "uint32", ",", "s", "func", "(", "[", "]", "grpc", ".", "ServerOption", ")", "*", "grpc", ".", "Server", ")", "{", "listener", ",", "err", ":=", "b", ".", "Accept", "(", "id", ...
// AcceptAndServe is used to accept a specific stream ID and immediately // serve a gRPC server on that stream ID. This is used to easily serve // complex arguments. Each AcceptAndServe call opens a new listener socket and // sends the connection info down the stream to the dialer. Since a new // connection is opened e...
[ "AcceptAndServe", "is", "used", "to", "accept", "a", "specific", "stream", "ID", "and", "immediately", "serve", "a", "gRPC", "server", "on", "that", "stream", "ID", ".", "This", "is", "used", "to", "easily", "serve", "complex", "arguments", ".", "Each", "A...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L312-L355
21,728
hashicorp/go-plugin
grpc_broker.go
Close
func (b *GRPCBroker) Close() error { b.streamer.Close() b.o.Do(func() { close(b.doneCh) }) return nil }
go
func (b *GRPCBroker) Close() error { b.streamer.Close() b.o.Do(func() { close(b.doneCh) }) return nil }
[ "func", "(", "b", "*", "GRPCBroker", ")", "Close", "(", ")", "error", "{", "b", ".", "streamer", ".", "Close", "(", ")", "\n", "b", ".", "o", ".", "Do", "(", "func", "(", ")", "{", "close", "(", "b", ".", "doneCh", ")", "\n", "}", ")", "\n"...
// Close closes the stream and all servers.
[ "Close", "closes", "the", "stream", "and", "all", "servers", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_broker.go#L358-L364
21,729
hashicorp/go-plugin
log_entry.go
parseJSON
func parseJSON(input []byte) (*logEntry, error) { var raw map[string]interface{} entry := &logEntry{} err := json.Unmarshal(input, &raw) if err != nil { return nil, err } // Parse hclog-specific objects if v, ok := raw["@message"]; ok { entry.Message = v.(string) delete(raw, "@message") } if v, ok := ...
go
func parseJSON(input []byte) (*logEntry, error) { var raw map[string]interface{} entry := &logEntry{} err := json.Unmarshal(input, &raw) if err != nil { return nil, err } // Parse hclog-specific objects if v, ok := raw["@message"]; ok { entry.Message = v.(string) delete(raw, "@message") } if v, ok := ...
[ "func", "parseJSON", "(", "input", "[", "]", "byte", ")", "(", "*", "logEntry", ",", "error", ")", "{", "var", "raw", "map", "[", "string", "]", "interface", "{", "}", "\n", "entry", ":=", "&", "logEntry", "{", "}", "\n\n", "err", ":=", "json", "...
// parseJSON handles parsing JSON output
[ "parseJSON", "handles", "parsing", "JSON", "output" ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/log_entry.go#L35-L73
21,730
hashicorp/go-plugin
client.go
Check
func (s *SecureConfig) Check(filePath string) (bool, error) { if len(s.Checksum) == 0 { return false, ErrSecureConfigNoChecksum } if s.Hash == nil { return false, ErrSecureConfigNoHash } file, err := os.Open(filePath) if err != nil { return false, err } defer file.Close() _, err = io.Copy(s.Hash, file...
go
func (s *SecureConfig) Check(filePath string) (bool, error) { if len(s.Checksum) == 0 { return false, ErrSecureConfigNoChecksum } if s.Hash == nil { return false, ErrSecureConfigNoHash } file, err := os.Open(filePath) if err != nil { return false, err } defer file.Close() _, err = io.Copy(s.Hash, file...
[ "func", "(", "s", "*", "SecureConfig", ")", "Check", "(", "filePath", "string", ")", "(", "bool", ",", "error", ")", "{", "if", "len", "(", "s", ".", "Checksum", ")", "==", "0", "{", "return", "false", ",", "ErrSecureConfigNoChecksum", "\n", "}", "\n...
// Check takes the filepath to an executable and returns true if the checksum of // the file matches the checksum provided in the SecureConfig.
[ "Check", "takes", "the", "filepath", "to", "an", "executable", "and", "returns", "true", "if", "the", "checksum", "of", "the", "file", "matches", "the", "checksum", "provided", "in", "the", "SecureConfig", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L233-L256
21,731
hashicorp/go-plugin
client.go
Client
func (c *Client) Client() (ClientProtocol, error) { _, err := c.Start() if err != nil { return nil, err } c.l.Lock() defer c.l.Unlock() if c.client != nil { return c.client, nil } switch c.protocol { case ProtocolNetRPC: c.client, err = newRPCClient(c) case ProtocolGRPC: c.client, err = newGRPCCli...
go
func (c *Client) Client() (ClientProtocol, error) { _, err := c.Start() if err != nil { return nil, err } c.l.Lock() defer c.l.Unlock() if c.client != nil { return c.client, nil } switch c.protocol { case ProtocolNetRPC: c.client, err = newRPCClient(c) case ProtocolGRPC: c.client, err = newGRPCCli...
[ "func", "(", "c", "*", "Client", ")", "Client", "(", ")", "(", "ClientProtocol", ",", "error", ")", "{", "_", ",", "err", ":=", "c", ".", "Start", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", ...
// Client returns the protocol client for this connection. // // Subsequent calls to this will return the same client.
[ "Client", "returns", "the", "protocol", "client", "for", "this", "connection", ".", "Subsequent", "calls", "to", "this", "will", "return", "the", "same", "client", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L340-L370
21,732
hashicorp/go-plugin
client.go
killed
func (c *Client) killed() bool { c.l.Lock() defer c.l.Unlock() return c.processKilled }
go
func (c *Client) killed() bool { c.l.Lock() defer c.l.Unlock() return c.processKilled }
[ "func", "(", "c", "*", "Client", ")", "killed", "(", ")", "bool", "{", "c", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "l", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "processKilled", "\n", "}" ]
// killed is used in tests to check if a process failed to exit gracefully, and // needed to be killed.
[ "killed", "is", "used", "in", "tests", "to", "check", "if", "a", "process", "failed", "to", "exit", "gracefully", "and", "needed", "to", "be", "killed", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L381-L385
21,733
hashicorp/go-plugin
client.go
loadServerCert
func (c *Client) loadServerCert(cert string) error { certPool := x509.NewCertPool() asn1, err := base64.RawStdEncoding.DecodeString(cert) if err != nil { return err } x509Cert, err := x509.ParseCertificate([]byte(asn1)) if err != nil { return err } certPool.AddCert(x509Cert) c.config.TLSConfig.RootCAs ...
go
func (c *Client) loadServerCert(cert string) error { certPool := x509.NewCertPool() asn1, err := base64.RawStdEncoding.DecodeString(cert) if err != nil { return err } x509Cert, err := x509.ParseCertificate([]byte(asn1)) if err != nil { return err } certPool.AddCert(x509Cert) c.config.TLSConfig.RootCAs ...
[ "func", "(", "c", "*", "Client", ")", "loadServerCert", "(", "cert", "string", ")", "error", "{", "certPool", ":=", "x509", ".", "NewCertPool", "(", ")", "\n\n", "asn1", ",", "err", ":=", "base64", ".", "RawStdEncoding", ".", "DecodeString", "(", "cert",...
// loadServerCert is used by AutoMTLS to read an x.509 cert returned by the // server, and load it as the RootCA for the client TLSConfig.
[ "loadServerCert", "is", "used", "by", "AutoMTLS", "to", "read", "an", "x", ".", "509", "cert", "returned", "by", "the", "server", "and", "load", "it", "as", "the", "RootCA", "for", "the", "client", "TLSConfig", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L759-L776
21,734
hashicorp/go-plugin
client.go
checkProtoVersion
func (c *Client) checkProtoVersion(protoVersion string) (int, PluginSet, error) { serverVersion, err := strconv.Atoi(protoVersion) if err != nil { return 0, nil, fmt.Errorf("Error parsing protocol version %q: %s", protoVersion, err) } // record these for the error message var clientVersions []int // all versi...
go
func (c *Client) checkProtoVersion(protoVersion string) (int, PluginSet, error) { serverVersion, err := strconv.Atoi(protoVersion) if err != nil { return 0, nil, fmt.Errorf("Error parsing protocol version %q: %s", protoVersion, err) } // record these for the error message var clientVersions []int // all versi...
[ "func", "(", "c", "*", "Client", ")", "checkProtoVersion", "(", "protoVersion", "string", ")", "(", "int", ",", "PluginSet", ",", "error", ")", "{", "serverVersion", ",", "err", ":=", "strconv", ".", "Atoi", "(", "protoVersion", ")", "\n", "if", "err", ...
// checkProtoVersion returns the negotiated version and PluginSet. // This returns an error if the server returned an incompatible protocol // version, or an invalid handshake response.
[ "checkProtoVersion", "returns", "the", "negotiated", "version", "and", "PluginSet", ".", "This", "returns", "an", "error", "if", "the", "server", "returned", "an", "incompatible", "protocol", "version", "or", "an", "invalid", "handshake", "response", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L834-L856
21,735
hashicorp/go-plugin
client.go
ReattachConfig
func (c *Client) ReattachConfig() *ReattachConfig { c.l.Lock() defer c.l.Unlock() if c.address == nil { return nil } if c.config.Cmd != nil && c.config.Cmd.Process == nil { return nil } // If we connected via reattach, just return the information as-is if c.config.Reattach != nil { return c.config.Reat...
go
func (c *Client) ReattachConfig() *ReattachConfig { c.l.Lock() defer c.l.Unlock() if c.address == nil { return nil } if c.config.Cmd != nil && c.config.Cmd.Process == nil { return nil } // If we connected via reattach, just return the information as-is if c.config.Reattach != nil { return c.config.Reat...
[ "func", "(", "c", "*", "Client", ")", "ReattachConfig", "(", ")", "*", "ReattachConfig", "{", "c", ".", "l", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "l", ".", "Unlock", "(", ")", "\n\n", "if", "c", ".", "address", "==", "nil", "{", "ret...
// ReattachConfig returns the information that must be provided to NewClient // to reattach to the plugin process that this client started. This is // useful for plugins that detach from their parent process. // // If this returns nil then the process hasn't been started yet. Please // call Start or Client before calli...
[ "ReattachConfig", "returns", "the", "information", "that", "must", "be", "provided", "to", "NewClient", "to", "reattach", "to", "the", "plugin", "process", "that", "this", "client", "started", ".", "This", "is", "useful", "for", "plugins", "that", "detach", "f...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L864-L886
21,736
hashicorp/go-plugin
client.go
Protocol
func (c *Client) Protocol() Protocol { _, err := c.Start() if err != nil { return ProtocolInvalid } return c.protocol }
go
func (c *Client) Protocol() Protocol { _, err := c.Start() if err != nil { return ProtocolInvalid } return c.protocol }
[ "func", "(", "c", "*", "Client", ")", "Protocol", "(", ")", "Protocol", "{", "_", ",", "err", ":=", "c", ".", "Start", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ProtocolInvalid", "\n", "}", "\n\n", "return", "c", ".", "protocol", ...
// Protocol returns the protocol of server on the remote end. This will // start the plugin process if it isn't already started. Errors from // starting the plugin are surpressed and ProtocolInvalid is returned. It // is recommended you call Start explicitly before calling Protocol to ensure // no errors occur.
[ "Protocol", "returns", "the", "protocol", "of", "server", "on", "the", "remote", "end", ".", "This", "will", "start", "the", "plugin", "process", "if", "it", "isn", "t", "already", "started", ".", "Errors", "from", "starting", "the", "plugin", "are", "surp...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L893-L900
21,737
hashicorp/go-plugin
client.go
dialer
func (c *Client) dialer(_ string, timeout time.Duration) (net.Conn, error) { conn, err := netAddrDialer(c.address)("", timeout) if err != nil { return nil, err } // If we have a TLS config we wrap our connection. We only do this // for net/rpc since gRPC uses its own mechanism for TLS. if c.protocol == Protoco...
go
func (c *Client) dialer(_ string, timeout time.Duration) (net.Conn, error) { conn, err := netAddrDialer(c.address)("", timeout) if err != nil { return nil, err } // If we have a TLS config we wrap our connection. We only do this // for net/rpc since gRPC uses its own mechanism for TLS. if c.protocol == Protoco...
[ "func", "(", "c", "*", "Client", ")", "dialer", "(", "_", "string", ",", "timeout", "time", ".", "Duration", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "netAddrDialer", "(", "c", ".", "address", ")", "(", "\""...
// dialer is compatible with grpc.WithDialer and creates the connection // to the plugin.
[ "dialer", "is", "compatible", "with", "grpc", ".", "WithDialer", "and", "creates", "the", "connection", "to", "the", "plugin", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/client.go#L920-L933
21,738
hashicorp/go-plugin
mtls.go
generateCert
func generateCert() (cert []byte, privateKey []byte, err error) { key, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) if err != nil { return nil, nil, err } serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) sn, err := rand.Int(rand.Reader, serialNumberLimit) if err != nil { return nil, nil, e...
go
func generateCert() (cert []byte, privateKey []byte, err error) { key, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) if err != nil { return nil, nil, err } serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) sn, err := rand.Int(rand.Reader, serialNumberLimit) if err != nil { return nil, nil, e...
[ "func", "generateCert", "(", ")", "(", "cert", "[", "]", "byte", ",", "privateKey", "[", "]", "byte", ",", "err", "error", ")", "{", "key", ",", "err", ":=", "ecdsa", ".", "GenerateKey", "(", "elliptic", ".", "P521", "(", ")", ",", "rand", ".", "...
// generateCert generates a temporary certificate for plugin authentication. The // certificate and private key are returns in PEM format.
[ "generateCert", "generates", "a", "temporary", "certificate", "for", "plugin", "authentication", ".", "The", "certificate", "and", "private", "key", "are", "returns", "in", "PEM", "format", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/mtls.go#L17-L73
21,739
hashicorp/go-plugin
process_windows.go
_pidAlive
func _pidAlive(pid int) bool { h, err := syscall.OpenProcess(processDesiredAccess, false, uint32(pid)) if err != nil { return false } var ec uint32 if e := syscall.GetExitCodeProcess(h, &ec); e != nil { return false } return ec == exit_STILL_ACTIVE }
go
func _pidAlive(pid int) bool { h, err := syscall.OpenProcess(processDesiredAccess, false, uint32(pid)) if err != nil { return false } var ec uint32 if e := syscall.GetExitCodeProcess(h, &ec); e != nil { return false } return ec == exit_STILL_ACTIVE }
[ "func", "_pidAlive", "(", "pid", "int", ")", "bool", "{", "h", ",", "err", ":=", "syscall", ".", "OpenProcess", "(", "processDesiredAccess", ",", "false", ",", "uint32", "(", "pid", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\...
// _pidAlive tests whether a process is alive or not
[ "_pidAlive", "tests", "whether", "a", "process", "is", "alive", "or", "not" ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/process_windows.go#L17-L29
21,740
hashicorp/go-plugin
grpc_server.go
Config
func (s *GRPCServer) Config() string { // Create a buffer that will contain our final contents var buf bytes.Buffer // Wrap the base64 encoding with JSON encoding. if err := json.NewEncoder(&buf).Encode(s.config); err != nil { // We panic since ths shouldn't happen under any scenario. We // carefully control t...
go
func (s *GRPCServer) Config() string { // Create a buffer that will contain our final contents var buf bytes.Buffer // Wrap the base64 encoding with JSON encoding. if err := json.NewEncoder(&buf).Encode(s.config); err != nil { // We panic since ths shouldn't happen under any scenario. We // carefully control t...
[ "func", "(", "s", "*", "GRPCServer", ")", "Config", "(", ")", "string", "{", "// Create a buffer that will contain our final contents", "var", "buf", "bytes", ".", "Buffer", "\n\n", "// Wrap the base64 encoding with JSON encoding.", "if", "err", ":=", "json", ".", "Ne...
// Config is the GRPCServerConfig encoded as JSON then base64.
[ "Config", "is", "the", "GRPCServerConfig", "encoded", "as", "JSON", "then", "base64", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_server.go#L114-L127
21,741
hashicorp/go-plugin
rpc_client.go
newRPCClient
func newRPCClient(c *Client) (*RPCClient, error) { // Connect to the client conn, err := net.Dial(c.address.Network(), c.address.String()) if err != nil { return nil, err } if tcpConn, ok := conn.(*net.TCPConn); ok { // Make sure to set keep alive so that the connection doesn't die tcpConn.SetKeepAlive(true)...
go
func newRPCClient(c *Client) (*RPCClient, error) { // Connect to the client conn, err := net.Dial(c.address.Network(), c.address.String()) if err != nil { return nil, err } if tcpConn, ok := conn.(*net.TCPConn); ok { // Make sure to set keep alive so that the connection doesn't die tcpConn.SetKeepAlive(true)...
[ "func", "newRPCClient", "(", "c", "*", "Client", ")", "(", "*", "RPCClient", ",", "error", ")", "{", "// Connect to the client", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "c", ".", "address", ".", "Network", "(", ")", ",", "c", ".", "address...
// newRPCClient creates a new RPCClient. The Client argument is expected // to be successfully started already with a lock held.
[ "newRPCClient", "creates", "a", "new", "RPCClient", ".", "The", "Client", "argument", "is", "expected", "to", "be", "successfully", "started", "already", "with", "a", "lock", "held", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L25-L57
21,742
hashicorp/go-plugin
rpc_client.go
NewRPCClient
func NewRPCClient(conn io.ReadWriteCloser, plugins map[string]Plugin) (*RPCClient, error) { // Create the yamux client so we can multiplex mux, err := yamux.Client(conn, nil) if err != nil { conn.Close() return nil, err } // Connect to the control stream. control, err := mux.Open() if err != nil { mux.Clo...
go
func NewRPCClient(conn io.ReadWriteCloser, plugins map[string]Plugin) (*RPCClient, error) { // Create the yamux client so we can multiplex mux, err := yamux.Client(conn, nil) if err != nil { conn.Close() return nil, err } // Connect to the control stream. control, err := mux.Open() if err != nil { mux.Clo...
[ "func", "NewRPCClient", "(", "conn", "io", ".", "ReadWriteCloser", ",", "plugins", "map", "[", "string", "]", "Plugin", ")", "(", "*", "RPCClient", ",", "error", ")", "{", "// Create the yamux client so we can multiplex", "mux", ",", "err", ":=", "yamux", ".",...
// NewRPCClient creates a client from an already-open connection-like value. // Dial is typically used instead.
[ "NewRPCClient", "creates", "a", "client", "from", "an", "already", "-", "open", "connection", "-", "like", "value", ".", "Dial", "is", "typically", "used", "instead", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L61-L98
21,743
hashicorp/go-plugin
rpc_client.go
SyncStreams
func (c *RPCClient) SyncStreams(stdout io.Writer, stderr io.Writer) error { go copyStream("stdout", stdout, c.stdout) go copyStream("stderr", stderr, c.stderr) return nil }
go
func (c *RPCClient) SyncStreams(stdout io.Writer, stderr io.Writer) error { go copyStream("stdout", stdout, c.stdout) go copyStream("stderr", stderr, c.stderr) return nil }
[ "func", "(", "c", "*", "RPCClient", ")", "SyncStreams", "(", "stdout", "io", ".", "Writer", ",", "stderr", "io", ".", "Writer", ")", "error", "{", "go", "copyStream", "(", "\"", "\"", ",", "stdout", ",", "c", ".", "stdout", ")", "\n", "go", "copySt...
// SyncStreams should be called to enable syncing of stdout, // stderr with the plugin. // // This will return immediately and the syncing will continue to happen // in the background. You do not need to launch this in a goroutine itself. // // This should never be called multiple times.
[ "SyncStreams", "should", "be", "called", "to", "enable", "syncing", "of", "stdout", "stderr", "with", "the", "plugin", ".", "This", "will", "return", "immediately", "and", "the", "syncing", "will", "continue", "to", "happen", "in", "the", "background", ".", ...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L107-L111
21,744
hashicorp/go-plugin
rpc_client.go
Close
func (c *RPCClient) Close() error { // Call the control channel and ask it to gracefully exit. If this // errors, then we save it so that we always return an error but we // want to try to close the other channels anyways. var empty struct{} returnErr := c.control.Call("Control.Quit", true, &empty) // Close the ...
go
func (c *RPCClient) Close() error { // Call the control channel and ask it to gracefully exit. If this // errors, then we save it so that we always return an error but we // want to try to close the other channels anyways. var empty struct{} returnErr := c.control.Call("Control.Quit", true, &empty) // Close the ...
[ "func", "(", "c", "*", "RPCClient", ")", "Close", "(", ")", "error", "{", "// Call the control channel and ask it to gracefully exit. If this", "// errors, then we save it so that we always return an error but we", "// want to try to close the other channels anyways.", "var", "empty", ...
// Close closes the connection. The client is no longer usable after this // is called.
[ "Close", "closes", "the", "connection", ".", "The", "client", "is", "no", "longer", "usable", "after", "this", "is", "called", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L115-L140
21,745
hashicorp/go-plugin
rpc_client.go
Ping
func (c *RPCClient) Ping() error { var empty struct{} return c.control.Call("Control.Ping", true, &empty) }
go
func (c *RPCClient) Ping() error { var empty struct{} return c.control.Call("Control.Ping", true, &empty) }
[ "func", "(", "c", "*", "RPCClient", ")", "Ping", "(", ")", "error", "{", "var", "empty", "struct", "{", "}", "\n", "return", "c", ".", "control", ".", "Call", "(", "\"", "\"", ",", "true", ",", "&", "empty", ")", "\n", "}" ]
// Ping pings the connection to ensure it is still alive. // // The error from the RPC call is returned exactly if you want to inspect // it for further error analysis. Any error returned from here would indicate // that the connection to the plugin is not healthy.
[ "Ping", "pings", "the", "connection", "to", "ensure", "it", "is", "still", "alive", ".", "The", "error", "from", "the", "RPC", "call", "is", "returned", "exactly", "if", "you", "want", "to", "inspect", "it", "for", "further", "error", "analysis", ".", "A...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_client.go#L167-L170
21,746
hashicorp/go-plugin
rpc_server.go
ServeConn
func (s *RPCServer) ServeConn(conn io.ReadWriteCloser) { // First create the yamux server to wrap this connection mux, err := yamux.Server(conn, nil) if err != nil { conn.Close() log.Printf("[ERR] plugin: error creating yamux server: %s", err) return } // Accept the control connection control, err := mux.A...
go
func (s *RPCServer) ServeConn(conn io.ReadWriteCloser) { // First create the yamux server to wrap this connection mux, err := yamux.Server(conn, nil) if err != nil { conn.Close() log.Printf("[ERR] plugin: error creating yamux server: %s", err) return } // Accept the control connection control, err := mux.A...
[ "func", "(", "s", "*", "RPCServer", ")", "ServeConn", "(", "conn", "io", ".", "ReadWriteCloser", ")", "{", "// First create the yamux server to wrap this connection", "mux", ",", "err", ":=", "yamux", ".", "Server", "(", "conn", ",", "nil", ")", "\n", "if", ...
// ServeConn runs a single connection. // // ServeConn blocks, serving the connection until the client hangs up.
[ "ServeConn", "runs", "a", "single", "connection", ".", "ServeConn", "blocks", "serving", "the", "connection", "until", "the", "client", "hangs", "up", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_server.go#L59-L109
21,747
hashicorp/go-plugin
rpc_server.go
done
func (s *RPCServer) done() { s.lock.Lock() defer s.lock.Unlock() if s.DoneCh != nil { close(s.DoneCh) s.DoneCh = nil } }
go
func (s *RPCServer) done() { s.lock.Lock() defer s.lock.Unlock() if s.DoneCh != nil { close(s.DoneCh) s.DoneCh = nil } }
[ "func", "(", "s", "*", "RPCServer", ")", "done", "(", ")", "{", "s", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "DoneCh", "!=", "nil", "{", "close", "(", "s", ".", "...
// done is called internally by the control server to trigger the // doneCh to close which is listened to by the main process to cleanly // exit.
[ "done", "is", "called", "internally", "by", "the", "control", "server", "to", "trigger", "the", "doneCh", "to", "close", "which", "is", "listened", "to", "by", "the", "main", "process", "to", "cleanly", "exit", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/rpc_server.go#L114-L122
21,748
hashicorp/go-plugin
server.go
protocolVersion
func protocolVersion(opts *ServeConfig) (int, Protocol, PluginSet) { protoVersion := int(opts.ProtocolVersion) pluginSet := opts.Plugins protoType := ProtocolNetRPC // Check if the client sent a list of acceptable versions var clientVersions []int if vs := os.Getenv("PLUGIN_PROTOCOL_VERSIONS"); vs != "" { for _...
go
func protocolVersion(opts *ServeConfig) (int, Protocol, PluginSet) { protoVersion := int(opts.ProtocolVersion) pluginSet := opts.Plugins protoType := ProtocolNetRPC // Check if the client sent a list of acceptable versions var clientVersions []int if vs := os.Getenv("PLUGIN_PROTOCOL_VERSIONS"); vs != "" { for _...
[ "func", "protocolVersion", "(", "opts", "*", "ServeConfig", ")", "(", "int", ",", "Protocol", ",", "PluginSet", ")", "{", "protoVersion", ":=", "int", "(", "opts", ".", "ProtocolVersion", ")", "\n", "pluginSet", ":=", "opts", ".", "Plugins", "\n", "protoTy...
// protocolVersion determines the protocol version and plugin set to be used by // the server. In the event that there is no suitable version, the last version // in the config is returned leaving the client to report the incompatibility.
[ "protocolVersion", "determines", "the", "protocol", "version", "and", "plugin", "set", "to", "be", "used", "by", "the", "server", ".", "In", "the", "event", "that", "there", "is", "no", "suitable", "version", "the", "last", "version", "in", "the", "config", ...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/server.go#L93-L167
21,749
hashicorp/go-plugin
process_posix.go
_pidAlive
func _pidAlive(pid int) bool { proc, err := os.FindProcess(pid) if err == nil { err = proc.Signal(syscall.Signal(0)) } return err == nil }
go
func _pidAlive(pid int) bool { proc, err := os.FindProcess(pid) if err == nil { err = proc.Signal(syscall.Signal(0)) } return err == nil }
[ "func", "_pidAlive", "(", "pid", "int", ")", "bool", "{", "proc", ",", "err", ":=", "os", ".", "FindProcess", "(", "pid", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "proc", ".", "Signal", "(", "syscall", ".", "Signal", "(", "0", ")", ...
// _pidAlive tests whether a process is alive or not by sending it Signal 0, // since Go otherwise has no way to test this.
[ "_pidAlive", "tests", "whether", "a", "process", "is", "alive", "or", "not", "by", "sending", "it", "Signal", "0", "since", "Go", "otherwise", "has", "no", "way", "to", "test", "this", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/process_posix.go#L12-L19
21,750
hashicorp/go-plugin
mux_broker.go
AcceptAndServe
func (m *MuxBroker) AcceptAndServe(id uint32, v interface{}) { conn, err := m.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } serve(conn, "Plugin", v) }
go
func (m *MuxBroker) AcceptAndServe(id uint32, v interface{}) { conn, err := m.Accept(id) if err != nil { log.Printf("[ERR] plugin: plugin acceptAndServe error: %s", err) return } serve(conn, "Plugin", v) }
[ "func", "(", "m", "*", "MuxBroker", ")", "AcceptAndServe", "(", "id", "uint32", ",", "v", "interface", "{", "}", ")", "{", "conn", ",", "err", ":=", "m", ".", "Accept", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", ...
// AcceptAndServe is used to accept a specific stream ID and immediately // serve an RPC server on that stream ID. This is used to easily serve // complex arguments. // // The served interface is always registered to the "Plugin" name.
[ "AcceptAndServe", "is", "used", "to", "accept", "a", "specific", "stream", "ID", "and", "immediately", "serve", "an", "RPC", "server", "on", "that", "stream", "ID", ".", "This", "is", "used", "to", "easily", "serve", "complex", "arguments", ".", "The", "se...
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/mux_broker.go#L80-L88
21,751
hashicorp/go-plugin
process.go
pidWait
func pidWait(pid int) error { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() for range ticker.C { if !pidAlive(pid) { break } } return nil }
go
func pidWait(pid int) error { ticker := time.NewTicker(1 * time.Second) defer ticker.Stop() for range ticker.C { if !pidAlive(pid) { break } } return nil }
[ "func", "pidWait", "(", "pid", "int", ")", "error", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "1", "*", "time", ".", "Second", ")", "\n", "defer", "ticker", ".", "Stop", "(", ")", "\n\n", "for", "range", "ticker", ".", "C", "{", "if", "...
// pidWait blocks for a process to exit.
[ "pidWait", "blocks", "for", "a", "process", "to", "exit", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/process.go#L13-L24
21,752
hashicorp/go-plugin
grpc_controller.go
Shutdown
func (s *grpcControllerServer) Shutdown(ctx context.Context, _ *plugin.Empty) (*plugin.Empty, error) { resp := &plugin.Empty{} // TODO: figure out why GracefullStop doesn't work. s.server.Stop() return resp, nil }
go
func (s *grpcControllerServer) Shutdown(ctx context.Context, _ *plugin.Empty) (*plugin.Empty, error) { resp := &plugin.Empty{} // TODO: figure out why GracefullStop doesn't work. s.server.Stop() return resp, nil }
[ "func", "(", "s", "*", "grpcControllerServer", ")", "Shutdown", "(", "ctx", "context", ".", "Context", ",", "_", "*", "plugin", ".", "Empty", ")", "(", "*", "plugin", ".", "Empty", ",", "error", ")", "{", "resp", ":=", "&", "plugin", ".", "Empty", ...
// Shutdown stops the grpc server. It first will attempt a graceful stop, then a // full stop on the server.
[ "Shutdown", "stops", "the", "grpc", "server", ".", "It", "first", "will", "attempt", "a", "graceful", "stop", "then", "a", "full", "stop", "on", "the", "server", "." ]
5692942914bbdbc03558fde936b1f0bc2af365be
https://github.com/hashicorp/go-plugin/blob/5692942914bbdbc03558fde936b1f0bc2af365be/grpc_controller.go#L17-L23
21,753
nareix/joy4
av/av.go
IsPlanar
func (self SampleFormat) IsPlanar() bool { switch self { case S16P, S32P, FLTP, DBLP: return true default: return false } }
go
func (self SampleFormat) IsPlanar() bool { switch self { case S16P, S32P, FLTP, DBLP: return true default: return false } }
[ "func", "(", "self", "SampleFormat", ")", "IsPlanar", "(", ")", "bool", "{", "switch", "self", "{", "case", "S16P", ",", "S32P", ",", "FLTP", ",", "DBLP", ":", "return", "true", "\n", "default", ":", "return", "false", "\n", "}", "\n", "}" ]
// Check if this sample format is in planar.
[ "Check", "if", "this", "sample", "format", "is", "in", "planar", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L70-L77
21,754
nareix/joy4
av/av.go
MakeAudioCodecType
func MakeAudioCodecType(base uint32) (c CodecType) { c = CodecType(base)<<codecTypeOtherBits | CodecType(codecTypeAudioBit) return }
go
func MakeAudioCodecType(base uint32) (c CodecType) { c = CodecType(base)<<codecTypeOtherBits | CodecType(codecTypeAudioBit) return }
[ "func", "MakeAudioCodecType", "(", "base", "uint32", ")", "(", "c", "CodecType", ")", "{", "c", "=", "CodecType", "(", "base", ")", "<<", "codecTypeOtherBits", "|", "CodecType", "(", "codecTypeAudioBit", ")", "\n", "return", "\n", "}" ]
// Make a new audio codec type.
[ "Make", "a", "new", "audio", "codec", "type", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L157-L160
21,755
nareix/joy4
av/av.go
HasSameFormat
func (self AudioFrame) HasSameFormat(other AudioFrame) bool { if self.SampleRate != other.SampleRate { return false } if self.ChannelLayout != other.ChannelLayout { return false } if self.SampleFormat != other.SampleFormat { return false } return true }
go
func (self AudioFrame) HasSameFormat(other AudioFrame) bool { if self.SampleRate != other.SampleRate { return false } if self.ChannelLayout != other.ChannelLayout { return false } if self.SampleFormat != other.SampleFormat { return false } return true }
[ "func", "(", "self", "AudioFrame", ")", "HasSameFormat", "(", "other", "AudioFrame", ")", "bool", "{", "if", "self", ".", "SampleRate", "!=", "other", ".", "SampleRate", "{", "return", "false", "\n", "}", "\n", "if", "self", ".", "ChannelLayout", "!=", "...
// Check this audio frame has same format as other audio frame.
[ "Check", "this", "audio", "frame", "has", "same", "format", "as", "other", "audio", "frame", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L252-L263
21,756
nareix/joy4
av/av.go
Slice
func (self AudioFrame) Slice(start int, end int) (out AudioFrame) { if start > end { panic(fmt.Sprintf("av: AudioFrame split failed start=%d end=%d invalid", start, end)) } out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount = end - start size := self.SampleFormat.BytesPerSample() for i :=...
go
func (self AudioFrame) Slice(start int, end int) (out AudioFrame) { if start > end { panic(fmt.Sprintf("av: AudioFrame split failed start=%d end=%d invalid", start, end)) } out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount = end - start size := self.SampleFormat.BytesPerSample() for i :=...
[ "func", "(", "self", "AudioFrame", ")", "Slice", "(", "start", "int", ",", "end", "int", ")", "(", "out", "AudioFrame", ")", "{", "if", "start", ">", "end", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "start", ",", "end", ")",...
// Split sample audio sample from this frame.
[ "Split", "sample", "audio", "sample", "from", "this", "frame", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L266-L278
21,757
nareix/joy4
av/av.go
Concat
func (self AudioFrame) Concat(in AudioFrame) (out AudioFrame) { out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount += in.SampleCount for i := range out.Data { out.Data[i] = append(out.Data[i], in.Data[i]...) } return }
go
func (self AudioFrame) Concat(in AudioFrame) (out AudioFrame) { out = self out.Data = append([][]byte(nil), out.Data...) out.SampleCount += in.SampleCount for i := range out.Data { out.Data[i] = append(out.Data[i], in.Data[i]...) } return }
[ "func", "(", "self", "AudioFrame", ")", "Concat", "(", "in", "AudioFrame", ")", "(", "out", "AudioFrame", ")", "{", "out", "=", "self", "\n", "out", ".", "Data", "=", "append", "(", "[", "]", "[", "]", "byte", "(", "nil", ")", ",", "out", ".", ...
// Concat two audio frames.
[ "Concat", "two", "audio", "frames", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/av.go#L281-L289
21,758
nareix/joy4
av/transcode/transcode.go
Do
func (self *Transcoder) Do(pkt av.Packet) (out []av.Packet, err error) { stream := self.streams[pkt.Idx] if stream.aenc != nil && stream.adec != nil { if out, err = stream.audioDecodeAndEncode(pkt); err != nil { return } } else { out = append(out, pkt) } return }
go
func (self *Transcoder) Do(pkt av.Packet) (out []av.Packet, err error) { stream := self.streams[pkt.Idx] if stream.aenc != nil && stream.adec != nil { if out, err = stream.audioDecodeAndEncode(pkt); err != nil { return } } else { out = append(out, pkt) } return }
[ "func", "(", "self", "*", "Transcoder", ")", "Do", "(", "pkt", "av", ".", "Packet", ")", "(", "out", "[", "]", "av", ".", "Packet", ",", "err", "error", ")", "{", "stream", ":=", "self", ".", "streams", "[", "pkt", ".", "Idx", "]", "\n", "if", ...
// Do the transcode. // // In audio transcoding one Packet may transcode into many Packets // packet time will be adjusted automatically.
[ "Do", "the", "transcode", ".", "In", "audio", "transcoding", "one", "Packet", "may", "transcode", "into", "many", "Packets", "packet", "time", "will", "be", "adjusted", "automatically", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L114-L124
21,759
nareix/joy4
av/transcode/transcode.go
Streams
func (self *Transcoder) Streams() (streams []av.CodecData, err error) { for _, stream := range self.streams { streams = append(streams, stream.codec) } return }
go
func (self *Transcoder) Streams() (streams []av.CodecData, err error) { for _, stream := range self.streams { streams = append(streams, stream.codec) } return }
[ "func", "(", "self", "*", "Transcoder", ")", "Streams", "(", ")", "(", "streams", "[", "]", "av", ".", "CodecData", ",", "err", "error", ")", "{", "for", "_", ",", "stream", ":=", "range", "self", ".", "streams", "{", "streams", "=", "append", "(",...
// Get CodecDatas after transcoding.
[ "Get", "CodecDatas", "after", "transcoding", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L127-L132
21,760
nareix/joy4
av/transcode/transcode.go
Close
func (self *Transcoder) Close() (err error) { for _, stream := range self.streams { if stream.aenc != nil { stream.aenc.Close() stream.aenc = nil } if stream.adec != nil { stream.adec.Close() stream.adec = nil } } self.streams = nil return }
go
func (self *Transcoder) Close() (err error) { for _, stream := range self.streams { if stream.aenc != nil { stream.aenc.Close() stream.aenc = nil } if stream.adec != nil { stream.adec.Close() stream.adec = nil } } self.streams = nil return }
[ "func", "(", "self", "*", "Transcoder", ")", "Close", "(", ")", "(", "err", "error", ")", "{", "for", "_", ",", "stream", ":=", "range", "self", ".", "streams", "{", "if", "stream", ".", "aenc", "!=", "nil", "{", "stream", ".", "aenc", ".", "Clos...
// Close transcoder, close related encoder and decoders.
[ "Close", "transcoder", "close", "related", "encoder", "and", "decoders", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/transcode/transcode.go#L135-L148
21,761
nareix/joy4
av/pubsub/queue.go
WritePacket
func (self *Queue) WritePacket(pkt av.Packet) (err error) { self.lock.Lock() self.buf.Push(pkt) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount++ } for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 { pkt := self.buf.Pop() if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFra...
go
func (self *Queue) WritePacket(pkt av.Packet) (err error) { self.lock.Lock() self.buf.Push(pkt) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFrame { self.curgopcount++ } for self.curgopcount >= self.maxgopcount && self.buf.Count > 1 { pkt := self.buf.Pop() if pkt.Idx == int8(self.videoidx) && pkt.IsKeyFra...
[ "func", "(", "self", "*", "Queue", ")", "WritePacket", "(", "pkt", "av", ".", "Packet", ")", "(", "err", "error", ")", "{", "self", ".", "lock", ".", "Lock", "(", ")", "\n\n", "self", ".", "buf", ".", "Push", "(", "pkt", ")", "\n", "if", "pkt",...
// Put packet into buffer, old packets will be discared.
[ "Put", "packet", "into", "buffer", "old", "packets", "will", "be", "discared", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L83-L106
21,762
nareix/joy4
av/pubsub/queue.go
Oldest
func (self *Queue) Oldest() *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { return buf.Head } return cursor }
go
func (self *Queue) Oldest() *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { return buf.Head } return cursor }
[ "func", "(", "self", "*", "Queue", ")", "Oldest", "(", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", "Buf", ",", "videoidx", "int", ")", ...
// Create cursor position at oldest buffered packet.
[ "Create", "cursor", "position", "at", "oldest", "buffered", "packet", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L131-L137
21,763
nareix/joy4
av/pubsub/queue.go
DelayedTime
func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if buf.IsValidPos(i) { end := buf.Get(i) for buf.IsValidPos(i) { if end.Time-buf.Get(i).Time > dur { break } i-- ...
go
func (self *Queue) DelayedTime(dur time.Duration) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if buf.IsValidPos(i) { end := buf.Get(i) for buf.IsValidPos(i) { if end.Time-buf.Get(i).Time > dur { break } i-- ...
[ "func", "(", "self", "*", "Queue", ")", "DelayedTime", "(", "dur", "time", ".", "Duration", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", ...
// Create cursor position at specific time in buffered packets.
[ "Create", "cursor", "position", "at", "specific", "time", "in", "buffered", "packets", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L140-L156
21,764
nareix/joy4
av/pubsub/queue.go
DelayedGopCount
func (self *Queue) DelayedGopCount(n int) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if videoidx != -1 { for gop := 0; buf.IsValidPos(i) && gop < n; i-- { pkt := buf.Get(i) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyF...
go
func (self *Queue) DelayedGopCount(n int) *QueueCursor { cursor := self.newCursor() cursor.init = func(buf *pktque.Buf, videoidx int) pktque.BufPos { i := buf.Tail - 1 if videoidx != -1 { for gop := 0; buf.IsValidPos(i) && gop < n; i-- { pkt := buf.Get(i) if pkt.Idx == int8(self.videoidx) && pkt.IsKeyF...
[ "func", "(", "self", "*", "Queue", ")", "DelayedGopCount", "(", "n", "int", ")", "*", "QueueCursor", "{", "cursor", ":=", "self", ".", "newCursor", "(", ")", "\n", "cursor", ".", "init", "=", "func", "(", "buf", "*", "pktque", ".", "Buf", ",", "vid...
// Create cursor position at specific delayed GOP count in buffered packets.
[ "Create", "cursor", "position", "at", "specific", "delayed", "GOP", "count", "in", "buffered", "packets", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L159-L174
21,765
nareix/joy4
av/pubsub/queue.go
ReadPacket
func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) { self.que.cond.L.Lock() buf := self.que.buf if !self.gotpos { self.pos = self.init(buf, self.que.videoidx) self.gotpos = true } for { if self.pos.LT(buf.Head) { self.pos = buf.Head } else if self.pos.GT(buf.Tail) { self.pos = buf.Tail ...
go
func (self *QueueCursor) ReadPacket() (pkt av.Packet, err error) { self.que.cond.L.Lock() buf := self.que.buf if !self.gotpos { self.pos = self.init(buf, self.que.videoidx) self.gotpos = true } for { if self.pos.LT(buf.Head) { self.pos = buf.Head } else if self.pos.GT(buf.Tail) { self.pos = buf.Tail ...
[ "func", "(", "self", "*", "QueueCursor", ")", "ReadPacket", "(", ")", "(", "pkt", "av", ".", "Packet", ",", "err", "error", ")", "{", "self", ".", "que", ".", "cond", ".", "L", ".", "Lock", "(", ")", "\n", "buf", ":=", "self", ".", "que", ".", ...
// ReadPacket will not consume packets in Queue, it's just a cursor.
[ "ReadPacket", "will", "not", "consume", "packets", "in", "Queue", "it", "s", "just", "a", "cursor", "." ]
3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02
https://github.com/nareix/joy4/blob/3ddbc8f9d4316ab2bbec2bc9ee98127862e3af02/av/pubsub/queue.go#L191-L217
21,766
go-martini/martini
martini.go
New
func New() *Martini { m := &Martini{Injector: inject.New(), action: func() {}, logger: log.New(os.Stdout, "[martini] ", 0)} m.Map(m.logger) m.Map(defaultReturnHandler()) return m }
go
func New() *Martini { m := &Martini{Injector: inject.New(), action: func() {}, logger: log.New(os.Stdout, "[martini] ", 0)} m.Map(m.logger) m.Map(defaultReturnHandler()) return m }
[ "func", "New", "(", ")", "*", "Martini", "{", "m", ":=", "&", "Martini", "{", "Injector", ":", "inject", ".", "New", "(", ")", ",", "action", ":", "func", "(", ")", "{", "}", ",", "logger", ":", "log", ".", "New", "(", "os", ".", "Stdout", ",...
// New creates a bare bones Martini instance. Use this method if you want to have full control over the middleware that is used.
[ "New", "creates", "a", "bare", "bones", "Martini", "instance", ".", "Use", "this", "method", "if", "you", "want", "to", "have", "full", "control", "over", "the", "middleware", "that", "is", "used", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L38-L43
21,767
go-martini/martini
martini.go
Logger
func (m *Martini) Logger(logger *log.Logger) { m.logger = logger m.Map(m.logger) }
go
func (m *Martini) Logger(logger *log.Logger) { m.logger = logger m.Map(m.logger) }
[ "func", "(", "m", "*", "Martini", ")", "Logger", "(", "logger", "*", "log", ".", "Logger", ")", "{", "m", ".", "logger", "=", "logger", "\n", "m", ".", "Map", "(", "m", ".", "logger", ")", "\n", "}" ]
// Logger sets the logger
[ "Logger", "sets", "the", "logger" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L61-L64
21,768
go-martini/martini
martini.go
Use
func (m *Martini) Use(handler Handler) { validateHandler(handler) m.handlers = append(m.handlers, handler) }
go
func (m *Martini) Use(handler Handler) { validateHandler(handler) m.handlers = append(m.handlers, handler) }
[ "func", "(", "m", "*", "Martini", ")", "Use", "(", "handler", "Handler", ")", "{", "validateHandler", "(", "handler", ")", "\n\n", "m", ".", "handlers", "=", "append", "(", "m", ".", "handlers", ",", "handler", ")", "\n", "}" ]
// Use adds a middleware Handler to the stack. Will panic if the handler is not a callable func. Middleware Handlers are invoked in the order that they are added.
[ "Use", "adds", "a", "middleware", "Handler", "to", "the", "stack", ".", "Will", "panic", "if", "the", "handler", "is", "not", "a", "callable", "func", ".", "Middleware", "Handlers", "are", "invoked", "in", "the", "order", "that", "they", "are", "added", ...
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L67-L71
21,769
go-martini/martini
martini.go
ServeHTTP
func (m *Martini) ServeHTTP(res http.ResponseWriter, req *http.Request) { m.createContext(res, req).run() }
go
func (m *Martini) ServeHTTP(res http.ResponseWriter, req *http.Request) { m.createContext(res, req).run() }
[ "func", "(", "m", "*", "Martini", ")", "ServeHTTP", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "m", ".", "createContext", "(", "res", ",", "req", ")", ".", "run", "(", ")", "\n", "}" ]
// ServeHTTP is the HTTP Entry point for a Martini instance. Useful if you want to control your own HTTP server.
[ "ServeHTTP", "is", "the", "HTTP", "Entry", "point", "for", "a", "Martini", "instance", ".", "Useful", "if", "you", "want", "to", "control", "your", "own", "HTTP", "server", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L74-L76
21,770
go-martini/martini
martini.go
RunOnAddr
func (m *Martini) RunOnAddr(addr string) { // TODO: Should probably be implemented using a new instance of http.Server in place of // calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use. // This would also allow to improve testing when a custom host and port are pass...
go
func (m *Martini) RunOnAddr(addr string) { // TODO: Should probably be implemented using a new instance of http.Server in place of // calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use. // This would also allow to improve testing when a custom host and port are pass...
[ "func", "(", "m", "*", "Martini", ")", "RunOnAddr", "(", "addr", "string", ")", "{", "// TODO: Should probably be implemented using a new instance of http.Server in place of", "// calling http.ListenAndServer directly, so that it could be stored in the martini struct for later use.", "//...
// Run the http server on a given host and port.
[ "Run", "the", "http", "server", "on", "a", "given", "host", "and", "port", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L79-L87
21,771
go-martini/martini
martini.go
Classic
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("public")) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
go
func Classic() *ClassicMartini { r := NewRouter() m := New() m.Use(Logger()) m.Use(Recovery()) m.Use(Static("public")) m.MapTo(r, (*Routes)(nil)) m.Action(r.Handle) return &ClassicMartini{m, r} }
[ "func", "Classic", "(", ")", "*", "ClassicMartini", "{", "r", ":=", "NewRouter", "(", ")", "\n", "m", ":=", "New", "(", ")", "\n", "m", ".", "Use", "(", "Logger", "(", ")", ")", "\n", "m", ".", "Use", "(", "Recovery", "(", ")", ")", "\n", "m"...
// Classic creates a classic Martini with some basic default middleware - martini.Logger, martini.Recovery and martini.Static. // Classic also maps martini.Routes as a service.
[ "Classic", "creates", "a", "classic", "Martini", "with", "some", "basic", "default", "middleware", "-", "martini", ".", "Logger", "martini", ".", "Recovery", "and", "martini", ".", "Static", ".", "Classic", "also", "maps", "martini", ".", "Routes", "as", "a"...
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/martini.go#L118-L127
21,772
go-martini/martini
router.go
URLWith
func (r *route) URLWith(args []string) string { if len(args) > 0 { argCount := len(args) i := 0 url := urlReg.ReplaceAllStringFunc(r.pattern, func(m string) string { var val interface{} if i < argCount { val = args[i] } else { val = m } i += 1 return fmt.Sprintf(`%v`, val) }) retur...
go
func (r *route) URLWith(args []string) string { if len(args) > 0 { argCount := len(args) i := 0 url := urlReg.ReplaceAllStringFunc(r.pattern, func(m string) string { var val interface{} if i < argCount { val = args[i] } else { val = m } i += 1 return fmt.Sprintf(`%v`, val) }) retur...
[ "func", "(", "r", "*", "route", ")", "URLWith", "(", "args", "[", "]", "string", ")", "string", "{", "if", "len", "(", "args", ")", ">", "0", "{", "argCount", ":=", "len", "(", "args", ")", "\n", "i", ":=", "0", "\n", "url", ":=", "urlReg", "...
// URLWith returns the url pattern replacing the parameters for its values
[ "URLWith", "returns", "the", "url", "pattern", "replacing", "the", "parameters", "for", "its", "values" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L291-L309
21,773
go-martini/martini
router.go
URLFor
func (r *router) URLFor(name string, params ...interface{}) string { route := r.findRoute(name) if route == nil { panic("route not found") } var args []string for _, param := range params { switch v := param.(type) { case int: args = append(args, strconv.FormatInt(int64(v), 10)) case string: args =...
go
func (r *router) URLFor(name string, params ...interface{}) string { route := r.findRoute(name) if route == nil { panic("route not found") } var args []string for _, param := range params { switch v := param.(type) { case int: args = append(args, strconv.FormatInt(int64(v), 10)) case string: args =...
[ "func", "(", "r", "*", "router", ")", "URLFor", "(", "name", "string", ",", "params", "...", "interface", "{", "}", ")", "string", "{", "route", ":=", "r", ".", "findRoute", "(", "name", ")", "\n\n", "if", "route", "==", "nil", "{", "panic", "(", ...
// URLFor returns the url for the given route name.
[ "URLFor", "returns", "the", "url", "for", "the", "given", "route", "name", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L338-L360
21,774
go-martini/martini
router.go
MethodsFor
func (r *router) MethodsFor(path string) []string { methods := []string{} for _, route := range r.getRoutes() { matches := route.regex.FindStringSubmatch(path) if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) { methods = append(methods, route.method) } } return methods }
go
func (r *router) MethodsFor(path string) []string { methods := []string{} for _, route := range r.getRoutes() { matches := route.regex.FindStringSubmatch(path) if len(matches) > 0 && matches[0] == path && !hasMethod(methods, route.method) { methods = append(methods, route.method) } } return methods }
[ "func", "(", "r", "*", "router", ")", "MethodsFor", "(", "path", "string", ")", "[", "]", "string", "{", "methods", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "route", ":=", "range", "r", ".", "getRoutes", "(", ")", "{", "matches"...
// MethodsFor returns all methods available for path
[ "MethodsFor", "returns", "all", "methods", "available", "for", "path" ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/router.go#L383-L392
21,775
go-martini/martini
logger.go
Logger
func Logger() Handler { return func(res http.ResponseWriter, req *http.Request, c Context, log *log.Logger) { start := time.Now() addr := req.Header.Get("X-Real-IP") if addr == "" { addr = req.Header.Get("X-Forwarded-For") if addr == "" { addr = req.RemoteAddr } } log.Printf("Started %s %s for...
go
func Logger() Handler { return func(res http.ResponseWriter, req *http.Request, c Context, log *log.Logger) { start := time.Now() addr := req.Header.Get("X-Real-IP") if addr == "" { addr = req.Header.Get("X-Forwarded-For") if addr == "" { addr = req.RemoteAddr } } log.Printf("Started %s %s for...
[ "func", "Logger", "(", ")", "Handler", "{", "return", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", "c", "Context", ",", "log", "*", "log", ".", "Logger", ")", "{", "start", ":=", "time", ".", "Now...
// Logger returns a middleware handler that logs the request as it goes in and the response as it goes out.
[ "Logger", "returns", "a", "middleware", "handler", "that", "logs", "the", "request", "as", "it", "goes", "in", "and", "the", "response", "as", "it", "goes", "out", "." ]
22fa46961aabd2665cf3f1343b146d20028f5071
https://github.com/go-martini/martini/blob/22fa46961aabd2665cf3f1343b146d20028f5071/logger.go#L10-L29
21,776
buger/jsonparser
escape.go
decodeSingleUnicodeEscape
func decodeSingleUnicodeEscape(in []byte) (rune, bool) { // We need at least 6 characters total if len(in) < 6 { return utf8.RuneError, false } // Convert hex to decimal h1, h2, h3, h4 := h2I(in[2]), h2I(in[3]), h2I(in[4]), h2I(in[5]) if h1 == badHex || h2 == badHex || h3 == badHex || h4 == badHex { return u...
go
func decodeSingleUnicodeEscape(in []byte) (rune, bool) { // We need at least 6 characters total if len(in) < 6 { return utf8.RuneError, false } // Convert hex to decimal h1, h2, h3, h4 := h2I(in[2]), h2I(in[3]), h2I(in[4]), h2I(in[5]) if h1 == badHex || h2 == badHex || h3 == badHex || h4 == badHex { return u...
[ "func", "decodeSingleUnicodeEscape", "(", "in", "[", "]", "byte", ")", "(", "rune", ",", "bool", ")", "{", "// We need at least 6 characters total", "if", "len", "(", "in", ")", "<", "6", "{", "return", "utf8", ".", "RuneError", ",", "false", "\n", "}", ...
// decodeSingleUnicodeEscape decodes a single \uXXXX escape sequence. The prefix \u is assumed to be present and // is not checked. // In JSON, these escapes can either come alone or as part of "UTF16 surrogate pairs" that must be handled together. // This function only handles one; decodeUnicodeEscape handles this mor...
[ "decodeSingleUnicodeEscape", "decodes", "a", "single", "\\", "uXXXX", "escape", "sequence", ".", "The", "prefix", "\\", "u", "is", "assumed", "to", "be", "present", "and", "is", "not", "checked", ".", "In", "JSON", "these", "escapes", "can", "either", "come"...
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/escape.go#L39-L53
21,777
buger/jsonparser
bytes.go
parseInt
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) { if len(bytes) == 0 { return 0, false, false } var neg bool = false if bytes[0] == '-' { neg = true bytes = bytes[1:] } var b int64 = 0 for _, c := range bytes { if c >= '0' && c <= '9' { b = (10 * v) + int64(c-'0') } else { return ...
go
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) { if len(bytes) == 0 { return 0, false, false } var neg bool = false if bytes[0] == '-' { neg = true bytes = bytes[1:] } var b int64 = 0 for _, c := range bytes { if c >= '0' && c <= '9' { b = (10 * v) + int64(c-'0') } else { return ...
[ "func", "parseInt", "(", "bytes", "[", "]", "byte", ")", "(", "v", "int64", ",", "ok", "bool", ",", "overflow", "bool", ")", "{", "if", "len", "(", "bytes", ")", "==", "0", "{", "return", "0", ",", "false", ",", "false", "\n", "}", "\n\n", "var...
// About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON
[ "About", "2x", "faster", "then", "strconv", ".", "ParseInt", "because", "it", "only", "supports", "base", "10", "which", "is", "enough", "for", "JSON" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/bytes.go#L11-L47
21,778
buger/jsonparser
parser.go
lastToken
func lastToken(data []byte) int { for i := len(data) - 1; i >= 0; i-- { switch data[i] { case ' ', '\n', '\r', '\t': continue default: return i } } return -1 }
go
func lastToken(data []byte) int { for i := len(data) - 1; i >= 0; i-- { switch data[i] { case ' ', '\n', '\r', '\t': continue default: return i } } return -1 }
[ "func", "lastToken", "(", "data", "[", "]", "byte", ")", "int", "{", "for", "i", ":=", "len", "(", "data", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "switch", "data", "[", "i", "]", "{", "case", "' '", ",", "'\\n'", ",", "'\\...
// Find position of last character which is not whitespace
[ "Find", "position", "of", "last", "character", "which", "is", "not", "whitespace" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L137-L148
21,779
buger/jsonparser
parser.go
stringEnd
func stringEnd(data []byte) (int, bool) { escaped := false for i, c := range data { if c == '"' { if !escaped { return i + 1, false } else { j := i - 1 for { if j < 0 || data[j] != '\\' { return i + 1, true // even number of backslashes } j-- if j < 0 || data[j] != '\\' {...
go
func stringEnd(data []byte) (int, bool) { escaped := false for i, c := range data { if c == '"' { if !escaped { return i + 1, false } else { j := i - 1 for { if j < 0 || data[j] != '\\' { return i + 1, true // even number of backslashes } j-- if j < 0 || data[j] != '\\' {...
[ "func", "stringEnd", "(", "data", "[", "]", "byte", ")", "(", "int", ",", "bool", ")", "{", "escaped", ":=", "false", "\n", "for", "i", ",", "c", ":=", "range", "data", "{", "if", "c", "==", "'\"'", "{", "if", "!", "escaped", "{", "return", "i"...
// Tries to find the end of string // Support if string contains escaped quote symbols.
[ "Tries", "to", "find", "the", "end", "of", "string", "Support", "if", "string", "contains", "escaped", "quote", "symbols", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L152-L178
21,780
buger/jsonparser
parser.go
ArrayEach
func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int, err error), keys ...string) (offset int, err error) { if len(data) == 0 { return -1, MalformedObjectError } offset = 1 if len(keys) > 0 { if offset = searchKeys(data, keys...); offset == -1 { return offset, KeyPathNotFoundErr...
go
func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int, err error), keys ...string) (offset int, err error) { if len(data) == 0 { return -1, MalformedObjectError } offset = 1 if len(keys) > 0 { if offset = searchKeys(data, keys...); offset == -1 { return offset, KeyPathNotFoundErr...
[ "func", "ArrayEach", "(", "data", "[", "]", "byte", ",", "cb", "func", "(", "value", "[", "]", "byte", ",", "dataType", "ValueType", ",", "offset", "int", ",", "err", "error", ")", ",", "keys", "...", "string", ")", "(", "offset", "int", ",", "err"...
// ArrayEach is used when iterating arrays, accepts a callback function with the same return arguments as `Get`.
[ "ArrayEach", "is", "used", "when", "iterating", "arrays", "accepts", "a", "callback", "function", "with", "the", "same", "return", "arguments", "as", "Get", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L902-L979
21,781
buger/jsonparser
parser.go
ObjectEach
func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) { var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings offset := 0 // Descend to the desired key, if requested if len(k...
go
func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) { var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings offset := 0 // Descend to the desired key, if requested if len(k...
[ "func", "ObjectEach", "(", "data", "[", "]", "byte", ",", "callback", "func", "(", "key", "[", "]", "byte", ",", "value", "[", "]", "byte", ",", "dataType", "ValueType", ",", "offset", "int", ")", "error", ",", "keys", "...", "string", ")", "(", "e...
// ObjectEach iterates over the key-value pairs of a JSON object, invoking a given callback for each such entry
[ "ObjectEach", "iterates", "over", "the", "key", "-", "value", "pairs", "of", "a", "JSON", "object", "invoking", "a", "given", "callback", "for", "each", "such", "entry" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L982-L1086
21,782
buger/jsonparser
parser.go
GetUnsafeString
func GetUnsafeString(data []byte, keys ...string) (val string, err error) { v, _, _, e := Get(data, keys...) if e != nil { return "", e } return bytesToString(&v), nil }
go
func GetUnsafeString(data []byte, keys ...string) (val string, err error) { v, _, _, e := Get(data, keys...) if e != nil { return "", e } return bytesToString(&v), nil }
[ "func", "GetUnsafeString", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "string", ",", "err", "error", ")", "{", "v", ",", "_", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if"...
// GetUnsafeString returns the value retrieved by `Get`, use creates string without memory allocation by mapping string to slice memory. It does not handle escape symbols.
[ "GetUnsafeString", "returns", "the", "value", "retrieved", "by", "Get", "use", "creates", "string", "without", "memory", "allocation", "by", "mapping", "string", "to", "slice", "memory", ".", "It", "does", "not", "handle", "escape", "symbols", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1089-L1097
21,783
buger/jsonparser
parser.go
GetString
func GetString(data []byte, keys ...string) (val string, err error) { v, t, _, e := Get(data, keys...) if e != nil { return "", e } if t != String { return "", fmt.Errorf("Value is not a string: %s", string(v)) } // If no escapes return raw conten if bytes.IndexByte(v, '\\') == -1 { return string(v), ni...
go
func GetString(data []byte, keys ...string) (val string, err error) { v, t, _, e := Get(data, keys...) if e != nil { return "", e } if t != String { return "", fmt.Errorf("Value is not a string: %s", string(v)) } // If no escapes return raw conten if bytes.IndexByte(v, '\\') == -1 { return string(v), ni...
[ "func", "GetString", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "string", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e...
// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols // If key data type do not match, it will return an error.
[ "GetString", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "string", "if", "possible", "trying", "to", "properly", "handle", "escape", "and", "utf8", "symbols", "If", "key", "data", "type", "do", "not", "match", "it", "will", "ret...
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1101-L1118
21,784
buger/jsonparser
parser.go
GetFloat
func GetFloat(data []byte, keys ...string) (val float64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseFloat(v) }
go
func GetFloat(data []byte, keys ...string) (val float64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseFloat(v) }
[ "func", "GetFloat", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "float64", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e...
// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible. // The offset is the same as in `Get`. // If key data type do not match, it will return an error.
[ "GetFloat", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "float64", "if", "possible", ".", "The", "offset", "is", "the", "same", "as", "in", "Get", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return...
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1123-L1135
21,785
buger/jsonparser
parser.go
GetInt
func GetInt(data []byte, keys ...string) (val int64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseInt(v) }
go
func GetInt(data []byte, keys ...string) (val int64, err error) { v, t, _, e := Get(data, keys...) if e != nil { return 0, e } if t != Number { return 0, fmt.Errorf("Value is not a number: %s", string(v)) } return ParseInt(v) }
[ "func", "GetInt", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "int64", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e", ...
// GetInt returns the value retrieved by `Get`, cast to a int64 if possible. // If key data type do not match, it will return an error.
[ "GetInt", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "int64", "if", "possible", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return", "an", "error", "." ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1139-L1151
21,786
buger/jsonparser
parser.go
GetBoolean
func GetBoolean(data []byte, keys ...string) (val bool, err error) { v, t, _, e := Get(data, keys...) if e != nil { return false, e } if t != Boolean { return false, fmt.Errorf("Value is not a boolean: %s", string(v)) } return ParseBoolean(v) }
go
func GetBoolean(data []byte, keys ...string) (val bool, err error) { v, t, _, e := Get(data, keys...) if e != nil { return false, e } if t != Boolean { return false, fmt.Errorf("Value is not a boolean: %s", string(v)) } return ParseBoolean(v) }
[ "func", "GetBoolean", "(", "data", "[", "]", "byte", ",", "keys", "...", "string", ")", "(", "val", "bool", ",", "err", "error", ")", "{", "v", ",", "t", ",", "_", ",", "e", ":=", "Get", "(", "data", ",", "keys", "...", ")", "\n\n", "if", "e"...
// GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. // The offset is the same as in `Get`. // If key data type do not match, it will return error.
[ "GetBoolean", "returns", "the", "value", "retrieved", "by", "Get", "cast", "to", "a", "bool", "if", "possible", ".", "The", "offset", "is", "the", "same", "as", "in", "Get", ".", "If", "key", "data", "type", "do", "not", "match", "it", "will", "return"...
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1156-L1168
21,787
buger/jsonparser
parser.go
ParseFloat
func ParseFloat(b []byte) (float64, error) { if v, err := parseFloat(&b); err != nil { return 0, MalformedValueError } else { return v, nil } }
go
func ParseFloat(b []byte) (float64, error) { if v, err := parseFloat(&b); err != nil { return 0, MalformedValueError } else { return v, nil } }
[ "func", "ParseFloat", "(", "b", "[", "]", "byte", ")", "(", "float64", ",", "error", ")", "{", "if", "v", ",", "err", ":=", "parseFloat", "(", "&", "b", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "MalformedValueError", "\n", "}", "els...
// ParseNumber parses a Number ValueType into a Go float64
[ "ParseNumber", "parses", "a", "Number", "ValueType", "into", "a", "Go", "float64" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1193-L1199
21,788
buger/jsonparser
parser.go
ParseInt
func ParseInt(b []byte) (int64, error) { if v, ok, overflow := parseInt(b); !ok { if overflow { return 0, OverflowIntegerError } return 0, MalformedValueError } else { return v, nil } }
go
func ParseInt(b []byte) (int64, error) { if v, ok, overflow := parseInt(b); !ok { if overflow { return 0, OverflowIntegerError } return 0, MalformedValueError } else { return v, nil } }
[ "func", "ParseInt", "(", "b", "[", "]", "byte", ")", "(", "int64", ",", "error", ")", "{", "if", "v", ",", "ok", ",", "overflow", ":=", "parseInt", "(", "b", ")", ";", "!", "ok", "{", "if", "overflow", "{", "return", "0", ",", "OverflowIntegerErr...
// ParseInt parses a Number ValueType into a Go int64
[ "ParseInt", "parses", "a", "Number", "ValueType", "into", "a", "Go", "int64" ]
bf1c66bbce23153d89b23f8960071a680dbef54b
https://github.com/buger/jsonparser/blob/bf1c66bbce23153d89b23f8960071a680dbef54b/parser.go#L1202-L1211
21,789
jung-kurt/gofpdf
fpdf.go
SetErrorf
func (f *Fpdf) SetErrorf(fmtStr string, args ...interface{}) { if f.err == nil { f.err = fmt.Errorf(fmtStr, args...) } }
go
func (f *Fpdf) SetErrorf(fmtStr string, args ...interface{}) { if f.err == nil { f.err = fmt.Errorf(fmtStr, args...) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetErrorf", "(", "fmtStr", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "f", ".", "err", "==", "nil", "{", "f", ".", "err", "=", "fmt", ".", "Errorf", "(", "fmtStr", ",", "args", "......
// SetErrorf sets the internal Fpdf error with formatted text to halt PDF // generation; this may facilitate error handling by application. If an error // condition is already set, this call is ignored. // // See the documentation for printing in the standard fmt package for details // about fmtStr and args.
[ "SetErrorf", "sets", "the", "internal", "Fpdf", "error", "with", "formatted", "text", "to", "halt", "PDF", "generation", ";", "this", "may", "facilitate", "error", "handling", "by", "application", ".", "If", "an", "error", "condition", "is", "already", "set", ...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L259-L263
21,790
jung-kurt/gofpdf
fpdf.go
SetMargins
func (f *Fpdf) SetMargins(left, top, right float64) { f.lMargin = left f.tMargin = top if right < 0 { right = left } f.rMargin = right }
go
func (f *Fpdf) SetMargins(left, top, right float64) { f.lMargin = left f.tMargin = top if right < 0 { right = left } f.rMargin = right }
[ "func", "(", "f", "*", "Fpdf", ")", "SetMargins", "(", "left", ",", "top", ",", "right", "float64", ")", "{", "f", ".", "lMargin", "=", "left", "\n", "f", ".", "tMargin", "=", "top", "\n", "if", "right", "<", "0", "{", "right", "=", "left", "\n...
// SetMargins defines the left, top and right margins. By default, they equal 1 // cm. Call this method to change them. If the value of the right margin is // less than zero, it is set to the same as the left margin.
[ "SetMargins", "defines", "the", "left", "top", "and", "right", "margins", ".", "By", "default", "they", "equal", "1", "cm", ".", "Call", "this", "method", "to", "change", "them", ".", "If", "the", "value", "of", "the", "right", "margin", "is", "less", ...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L307-L314
21,791
jung-kurt/gofpdf
fpdf.go
SetLeftMargin
func (f *Fpdf) SetLeftMargin(margin float64) { f.lMargin = margin if f.page > 0 && f.x < margin { f.x = margin } }
go
func (f *Fpdf) SetLeftMargin(margin float64) { f.lMargin = margin if f.page > 0 && f.x < margin { f.x = margin } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLeftMargin", "(", "margin", "float64", ")", "{", "f", ".", "lMargin", "=", "margin", "\n", "if", "f", ".", "page", ">", "0", "&&", "f", ".", "x", "<", "margin", "{", "f", ".", "x", "=", "margin", "\n", ...
// SetLeftMargin defines the left margin. The method can be called before // creating the first page. If the current abscissa gets out of page, it is // brought back to the margin.
[ "SetLeftMargin", "defines", "the", "left", "margin", ".", "The", "method", "can", "be", "called", "before", "creating", "the", "first", "page", ".", "If", "the", "current", "abscissa", "gets", "out", "of", "page", "it", "is", "brought", "back", "to", "the"...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L319-L324
21,792
jung-kurt/gofpdf
fpdf.go
SetPageBox
func (f *Fpdf) SetPageBox(t string, x, y, wd, ht float64) { f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) }
go
func (f *Fpdf) SetPageBox(t string, x, y, wd, ht float64) { f.SetPageBoxRec(t, PageBox{SizeType{Wd: wd, Ht: ht}, PointType{X: x, Y: y}}) }
[ "func", "(", "f", "*", "Fpdf", ")", "SetPageBox", "(", "t", "string", ",", "x", ",", "y", ",", "wd", ",", "ht", "float64", ")", "{", "f", ".", "SetPageBoxRec", "(", "t", ",", "PageBox", "{", "SizeType", "{", "Wd", ":", "wd", ",", "Ht", ":", "...
// SetPageBox sets the page box for the current page, and any following pages. // Allowable types are trim, trimbox, crop, cropbox, bleed, bleedbox, art and // artbox box types are case insensitive.
[ "SetPageBox", "sets", "the", "page", "box", "for", "the", "current", "page", "and", "any", "following", "pages", ".", "Allowable", "types", "are", "trim", "trimbox", "crop", "cropbox", "bleed", "bleedbox", "art", "and", "artbox", "box", "types", "are", "case...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L383-L385
21,793
jung-kurt/gofpdf
fpdf.go
GetAutoPageBreak
func (f *Fpdf) GetAutoPageBreak() (auto bool, margin float64) { auto = f.autoPageBreak margin = f.bMargin return }
go
func (f *Fpdf) GetAutoPageBreak() (auto bool, margin float64) { auto = f.autoPageBreak margin = f.bMargin return }
[ "func", "(", "f", "*", "Fpdf", ")", "GetAutoPageBreak", "(", ")", "(", "auto", "bool", ",", "margin", "float64", ")", "{", "auto", "=", "f", ".", "autoPageBreak", "\n", "margin", "=", "f", ".", "bMargin", "\n", "return", "\n", "}" ]
// GetAutoPageBreak returns true if automatic pages breaks are enabled, false // otherwise. This is followed by the triggering limit from the bottom of the // page. This value applies only if automatic page breaks are enabled.
[ "GetAutoPageBreak", "returns", "true", "if", "automatic", "pages", "breaks", "are", "enabled", "false", "otherwise", ".", "This", "is", "followed", "by", "the", "triggering", "limit", "from", "the", "bottom", "of", "the", "page", ".", "This", "value", "applies...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L484-L488
21,794
jung-kurt/gofpdf
fpdf.go
SetAutoPageBreak
func (f *Fpdf) SetAutoPageBreak(auto bool, margin float64) { f.autoPageBreak = auto f.bMargin = margin f.pageBreakTrigger = f.h - margin }
go
func (f *Fpdf) SetAutoPageBreak(auto bool, margin float64) { f.autoPageBreak = auto f.bMargin = margin f.pageBreakTrigger = f.h - margin }
[ "func", "(", "f", "*", "Fpdf", ")", "SetAutoPageBreak", "(", "auto", "bool", ",", "margin", "float64", ")", "{", "f", ".", "autoPageBreak", "=", "auto", "\n", "f", ".", "bMargin", "=", "margin", "\n", "f", ".", "pageBreakTrigger", "=", "f", ".", "h",...
// SetAutoPageBreak enables or disables the automatic page breaking mode. When // enabling, the second parameter is the distance from the bottom of the page // that defines the triggering limit. By default, the mode is on and the margin // is 2 cm.
[ "SetAutoPageBreak", "enables", "or", "disables", "the", "automatic", "page", "breaking", "mode", ".", "When", "enabling", "the", "second", "parameter", "is", "the", "distance", "from", "the", "bottom", "of", "the", "page", "that", "defines", "the", "triggering",...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L494-L498
21,795
jung-kurt/gofpdf
fpdf.go
SetKeywords
func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) { if isUTF8 { keywordsStr = utf8toutf16(keywordsStr) } f.keywords = keywordsStr }
go
func (f *Fpdf) SetKeywords(keywordsStr string, isUTF8 bool) { if isUTF8 { keywordsStr = utf8toutf16(keywordsStr) } f.keywords = keywordsStr }
[ "func", "(", "f", "*", "Fpdf", ")", "SetKeywords", "(", "keywordsStr", "string", ",", "isUTF8", "bool", ")", "{", "if", "isUTF8", "{", "keywordsStr", "=", "utf8toutf16", "(", "keywordsStr", ")", "\n", "}", "\n", "f", ".", "keywords", "=", "keywordsStr", ...
// SetKeywords defines the keywords of the document. keywordStr is a // space-delimited string, for example "invoice August". isUTF8 indicates if // the string is encoded
[ "SetKeywords", "defines", "the", "keywords", "of", "the", "document", ".", "keywordStr", "is", "a", "space", "-", "delimited", "string", "for", "example", "invoice", "August", ".", "isUTF8", "indicates", "if", "the", "string", "is", "encoded" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L588-L593
21,796
jung-kurt/gofpdf
fpdf.go
GetStringWidth
func (f *Fpdf) GetStringWidth(s string) float64 { if f.err != nil { return 0 } w := 0 for _, ch := range []byte(s) { if ch == 0 { break } w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 }
go
func (f *Fpdf) GetStringWidth(s string) float64 { if f.err != nil { return 0 } w := 0 for _, ch := range []byte(s) { if ch == 0 { break } w += f.currentFont.Cw[ch] } return float64(w) * f.fontSize / 1000 }
[ "func", "(", "f", "*", "Fpdf", ")", "GetStringWidth", "(", "s", "string", ")", "float64", "{", "if", "f", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "w", ":=", "0", "\n", "for", "_", ",", "ch", ":=", "range", "[", "]", "byt...
// GetStringWidth returns the length of a string in user units. A font must be // currently selected.
[ "GetStringWidth", "returns", "the", "length", "of", "a", "string", "in", "user", "units", ".", "A", "font", "must", "be", "currently", "selected", "." ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L914-L926
21,797
jung-kurt/gofpdf
fpdf.go
SetLineCapStyle
func (f *Fpdf) SetLineCapStyle(styleStr string) { var capStyle int switch styleStr { case "round": capStyle = 1 case "square": capStyle = 2 default: capStyle = 0 } f.capStyle = capStyle if f.page > 0 { f.outf("%d J", f.capStyle) } }
go
func (f *Fpdf) SetLineCapStyle(styleStr string) { var capStyle int switch styleStr { case "round": capStyle = 1 case "square": capStyle = 2 default: capStyle = 0 } f.capStyle = capStyle if f.page > 0 { f.outf("%d J", f.capStyle) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLineCapStyle", "(", "styleStr", "string", ")", "{", "var", "capStyle", "int", "\n", "switch", "styleStr", "{", "case", "\"", "\"", ":", "capStyle", "=", "1", "\n", "case", "\"", "\"", ":", "capStyle", "=", "2",...
// SetLineCapStyle defines the line cap style. styleStr should be "butt", // "round" or "square". A square style projects from the end of the line. The // method can be called before the first page is created. The value is // retained from page to page.
[ "SetLineCapStyle", "defines", "the", "line", "cap", "style", ".", "styleStr", "should", "be", "butt", "round", "or", "square", ".", "A", "square", "style", "projects", "from", "the", "end", "of", "the", "line", ".", "The", "method", "can", "be", "called", ...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L951-L965
21,798
jung-kurt/gofpdf
fpdf.go
SetLineJoinStyle
func (f *Fpdf) SetLineJoinStyle(styleStr string) { var joinStyle int switch styleStr { case "round": joinStyle = 1 case "bevel": joinStyle = 2 default: joinStyle = 0 } f.joinStyle = joinStyle if f.page > 0 { f.outf("%d j", f.joinStyle) } }
go
func (f *Fpdf) SetLineJoinStyle(styleStr string) { var joinStyle int switch styleStr { case "round": joinStyle = 1 case "bevel": joinStyle = 2 default: joinStyle = 0 } f.joinStyle = joinStyle if f.page > 0 { f.outf("%d j", f.joinStyle) } }
[ "func", "(", "f", "*", "Fpdf", ")", "SetLineJoinStyle", "(", "styleStr", "string", ")", "{", "var", "joinStyle", "int", "\n", "switch", "styleStr", "{", "case", "\"", "\"", ":", "joinStyle", "=", "1", "\n", "case", "\"", "\"", ":", "joinStyle", "=", ...
// SetLineJoinStyle defines the line cap style. styleStr should be "miter", // "round" or "bevel". The method can be called before the first page // is created. The value is retained from page to page.
[ "SetLineJoinStyle", "defines", "the", "line", "cap", "style", ".", "styleStr", "should", "be", "miter", "round", "or", "bevel", ".", "The", "method", "can", "be", "called", "before", "the", "first", "page", "is", "created", ".", "The", "value", "is", "reta...
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L970-L984
21,799
jung-kurt/gofpdf
fpdf.go
fillDrawOp
func fillDrawOp(styleStr string) (opStr string) { switch strings.ToUpper(styleStr) { case "", "D": // Stroke the path. opStr = "S" case "F": // fill the path, using the nonzero winding number rule opStr = "f" case "F*": // fill the path, using the even-odd rule opStr = "f*" case "FD", "DF": // fill a...
go
func fillDrawOp(styleStr string) (opStr string) { switch strings.ToUpper(styleStr) { case "", "D": // Stroke the path. opStr = "S" case "F": // fill the path, using the nonzero winding number rule opStr = "f" case "F*": // fill the path, using the even-odd rule opStr = "f*" case "FD", "DF": // fill a...
[ "func", "fillDrawOp", "(", "styleStr", "string", ")", "(", "opStr", "string", ")", "{", "switch", "strings", ".", "ToUpper", "(", "styleStr", ")", "{", "case", "\"", "\"", ",", "\"", "\"", ":", "// Stroke the path.", "opStr", "=", "\"", "\"", "\n", "ca...
// fillDrawOp corrects path painting operators
[ "fillDrawOp", "corrects", "path", "painting", "operators" ]
8b09ffb30d9a8716107d250631b3c580aa54ba04
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L1031-L1052