repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
hashicorp/go-hclog | intlogger.go | SetLevel | func (l *intLogger) SetLevel(level Level) {
atomic.StoreInt32(l.level, int32(level))
} | go | func (l *intLogger) SetLevel(level Level) {
atomic.StoreInt32(l.level, int32(level))
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"SetLevel",
"(",
"level",
"Level",
")",
"{",
"atomic",
".",
"StoreInt32",
"(",
"l",
".",
"level",
",",
"int32",
"(",
"level",
")",
")",
"\n",
"}"
] | // Update the logging level on-the-fly. This will affect all subloggers as
// well. | [
"Update",
"the",
"logging",
"level",
"on",
"-",
"the",
"-",
"fly",
".",
"This",
"will",
"affect",
"all",
"subloggers",
"as",
"well",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L506-L508 | train |
hashicorp/go-hclog | stdlog.go | Write | func (s *stdlogAdapter) Write(data []byte) (int, error) {
str := string(bytes.TrimRight(data, " \t\n"))
if s.forceLevel != NoLevel {
// Use pickLevel to strip log levels included in the line since we are
// forcing the level
_, str := s.pickLevel(str)
// Log at the forced level
switch s.forceLevel {
case Trace:
s.log.Trace(str)
case Debug:
s.log.Debug(str)
case Info:
s.log.Info(str)
case Warn:
s.log.Warn(str)
case Error:
s.log.Error(str)
default:
s.log.Info(str)
}
} else if s.inferLevels {
level, str := s.pickLevel(str)
switch level {
case Trace:
s.log.Trace(str)
case Debug:
s.log.Debug(str)
case Info:
s.log.Info(str)
case Warn:
s.log.Warn(str)
case Error:
s.log.Error(str)
default:
s.log.Info(str)
}
} else {
s.log.Info(str)
}
return len(data), nil
} | go | func (s *stdlogAdapter) Write(data []byte) (int, error) {
str := string(bytes.TrimRight(data, " \t\n"))
if s.forceLevel != NoLevel {
// Use pickLevel to strip log levels included in the line since we are
// forcing the level
_, str := s.pickLevel(str)
// Log at the forced level
switch s.forceLevel {
case Trace:
s.log.Trace(str)
case Debug:
s.log.Debug(str)
case Info:
s.log.Info(str)
case Warn:
s.log.Warn(str)
case Error:
s.log.Error(str)
default:
s.log.Info(str)
}
} else if s.inferLevels {
level, str := s.pickLevel(str)
switch level {
case Trace:
s.log.Trace(str)
case Debug:
s.log.Debug(str)
case Info:
s.log.Info(str)
case Warn:
s.log.Warn(str)
case Error:
s.log.Error(str)
default:
s.log.Info(str)
}
} else {
s.log.Info(str)
}
return len(data), nil
} | [
"func",
"(",
"s",
"*",
"stdlogAdapter",
")",
"Write",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"str",
":=",
"string",
"(",
"bytes",
".",
"TrimRight",
"(",
"data",
",",
"\"",
"\\t",
"\\n",
"\"",
")",
")",
"\n\n",
"... | // Take the data, infer the levels if configured, and send it through
// a regular Logger. | [
"Take",
"the",
"data",
"infer",
"the",
"levels",
"if",
"configured",
"and",
"send",
"it",
"through",
"a",
"regular",
"Logger",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/stdlog.go#L19-L63 | train |
hashicorp/go-hclog | stdlog.go | pickLevel | func (s *stdlogAdapter) pickLevel(str string) (Level, string) {
switch {
case strings.HasPrefix(str, "[DEBUG]"):
return Debug, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[TRACE]"):
return Trace, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[INFO]"):
return Info, strings.TrimSpace(str[6:])
case strings.HasPrefix(str, "[WARN]"):
return Warn, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[ERROR]"):
return Error, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[ERR]"):
return Error, strings.TrimSpace(str[5:])
default:
return Info, str
}
} | go | func (s *stdlogAdapter) pickLevel(str string) (Level, string) {
switch {
case strings.HasPrefix(str, "[DEBUG]"):
return Debug, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[TRACE]"):
return Trace, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[INFO]"):
return Info, strings.TrimSpace(str[6:])
case strings.HasPrefix(str, "[WARN]"):
return Warn, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[ERROR]"):
return Error, strings.TrimSpace(str[7:])
case strings.HasPrefix(str, "[ERR]"):
return Error, strings.TrimSpace(str[5:])
default:
return Info, str
}
} | [
"func",
"(",
"s",
"*",
"stdlogAdapter",
")",
"pickLevel",
"(",
"str",
"string",
")",
"(",
"Level",
",",
"string",
")",
"{",
"switch",
"{",
"case",
"strings",
".",
"HasPrefix",
"(",
"str",
",",
"\"",
"\"",
")",
":",
"return",
"Debug",
",",
"strings",
... | // Detect, based on conventions, what log level this is. | [
"Detect",
"based",
"on",
"conventions",
"what",
"log",
"level",
"this",
"is",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/stdlog.go#L66-L83 | train |
hashicorp/go-hclog | logger.go | LevelFromString | func LevelFromString(levelStr string) Level {
// We don't care about case. Accept both "INFO" and "info".
levelStr = strings.ToLower(strings.TrimSpace(levelStr))
switch levelStr {
case "trace":
return Trace
case "debug":
return Debug
case "info":
return Info
case "warn":
return Warn
case "error":
return Error
default:
return NoLevel
}
} | go | func LevelFromString(levelStr string) Level {
// We don't care about case. Accept both "INFO" and "info".
levelStr = strings.ToLower(strings.TrimSpace(levelStr))
switch levelStr {
case "trace":
return Trace
case "debug":
return Debug
case "info":
return Info
case "warn":
return Warn
case "error":
return Error
default:
return NoLevel
}
} | [
"func",
"LevelFromString",
"(",
"levelStr",
"string",
")",
"Level",
"{",
"// We don't care about case. Accept both \"INFO\" and \"info\".",
"levelStr",
"=",
"strings",
".",
"ToLower",
"(",
"strings",
".",
"TrimSpace",
"(",
"levelStr",
")",
")",
"\n",
"switch",
"levelS... | // LevelFromString returns a Level type for the named log level, or "NoLevel" if
// the level string is invalid. This facilitates setting the log level via
// config or environment variable by name in a predictable way. | [
"LevelFromString",
"returns",
"a",
"Level",
"type",
"for",
"the",
"named",
"log",
"level",
"or",
"NoLevel",
"if",
"the",
"level",
"string",
"is",
"invalid",
".",
"This",
"facilitates",
"setting",
"the",
"log",
"level",
"via",
"config",
"or",
"environment",
"... | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/logger.go#L59-L76 | train |
hashicorp/go-hclog | hclogvet/shadow.go | contains | func (s Span) contains(pos token.Pos) bool {
return s.min <= pos && pos < s.max
} | go | func (s Span) contains(pos token.Pos) bool {
return s.min <= pos && pos < s.max
} | [
"func",
"(",
"s",
"Span",
")",
"contains",
"(",
"pos",
"token",
".",
"Pos",
")",
"bool",
"{",
"return",
"s",
".",
"min",
"<=",
"pos",
"&&",
"pos",
"<",
"s",
".",
"max",
"\n",
"}"
] | // contains reports whether the position is inside the span. | [
"contains",
"reports",
"whether",
"the",
"position",
"is",
"inside",
"the",
"span",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/shadow.go#L77-L79 | train |
hashicorp/go-hclog | hclogvet/shadow.go | growSpan | func (pkg *Package) growSpan(ident *ast.Ident, obj types.Object) {
if *strictShadowing {
return // No need
}
pos := ident.Pos()
end := ident.End()
span, ok := pkg.spans[obj]
if ok {
if span.min > pos {
span.min = pos
}
if span.max < end {
span.max = end
}
} else {
span = Span{pos, end}
}
pkg.spans[obj] = span
} | go | func (pkg *Package) growSpan(ident *ast.Ident, obj types.Object) {
if *strictShadowing {
return // No need
}
pos := ident.Pos()
end := ident.End()
span, ok := pkg.spans[obj]
if ok {
if span.min > pos {
span.min = pos
}
if span.max < end {
span.max = end
}
} else {
span = Span{pos, end}
}
pkg.spans[obj] = span
} | [
"func",
"(",
"pkg",
"*",
"Package",
")",
"growSpan",
"(",
"ident",
"*",
"ast",
".",
"Ident",
",",
"obj",
"types",
".",
"Object",
")",
"{",
"if",
"*",
"strictShadowing",
"{",
"return",
"// No need",
"\n",
"}",
"\n",
"pos",
":=",
"ident",
".",
"Pos",
... | // growSpan expands the span for the object to contain the instance represented
// by the identifier. | [
"growSpan",
"expands",
"the",
"span",
"for",
"the",
"object",
"to",
"contain",
"the",
"instance",
"represented",
"by",
"the",
"identifier",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/shadow.go#L83-L101 | train |
hashicorp/go-hclog | hclogvet/shadow.go | checkShadowAssignment | func checkShadowAssignment(f *File, a *ast.AssignStmt) {
if a.Tok != token.DEFINE {
return
}
if f.idiomaticShortRedecl(a) {
return
}
for _, expr := range a.Lhs {
ident, ok := expr.(*ast.Ident)
if !ok {
f.Badf(expr.Pos(), "invalid AST: short variable declaration of non-identifier")
return
}
checkShadowing(f, ident)
}
} | go | func checkShadowAssignment(f *File, a *ast.AssignStmt) {
if a.Tok != token.DEFINE {
return
}
if f.idiomaticShortRedecl(a) {
return
}
for _, expr := range a.Lhs {
ident, ok := expr.(*ast.Ident)
if !ok {
f.Badf(expr.Pos(), "invalid AST: short variable declaration of non-identifier")
return
}
checkShadowing(f, ident)
}
} | [
"func",
"checkShadowAssignment",
"(",
"f",
"*",
"File",
",",
"a",
"*",
"ast",
".",
"AssignStmt",
")",
"{",
"if",
"a",
".",
"Tok",
"!=",
"token",
".",
"DEFINE",
"{",
"return",
"\n",
"}",
"\n",
"if",
"f",
".",
"idiomaticShortRedecl",
"(",
"a",
")",
"... | // checkShadowAssignment checks for shadowing in a short variable declaration. | [
"checkShadowAssignment",
"checks",
"for",
"shadowing",
"in",
"a",
"short",
"variable",
"declaration",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/shadow.go#L104-L119 | train |
hashicorp/go-hclog | hclogvet/shadow.go | idiomaticShortRedecl | func (f *File) idiomaticShortRedecl(a *ast.AssignStmt) bool {
// Don't complain about deliberate redeclarations of the form
// i := i
// Such constructs are idiomatic in range loops to create a new variable
// for each iteration. Another example is
// switch n := n.(type)
if len(a.Rhs) != len(a.Lhs) {
return false
}
// We know it's an assignment, so the LHS must be all identifiers. (We check anyway.)
for i, expr := range a.Lhs {
lhs, ok := expr.(*ast.Ident)
if !ok {
f.Badf(expr.Pos(), "invalid AST: short variable declaration of non-identifier")
return true // Don't do any more processing.
}
switch rhs := a.Rhs[i].(type) {
case *ast.Ident:
if lhs.Name != rhs.Name {
return false
}
case *ast.TypeAssertExpr:
if id, ok := rhs.X.(*ast.Ident); ok {
if lhs.Name != id.Name {
return false
}
}
default:
return false
}
}
return true
} | go | func (f *File) idiomaticShortRedecl(a *ast.AssignStmt) bool {
// Don't complain about deliberate redeclarations of the form
// i := i
// Such constructs are idiomatic in range loops to create a new variable
// for each iteration. Another example is
// switch n := n.(type)
if len(a.Rhs) != len(a.Lhs) {
return false
}
// We know it's an assignment, so the LHS must be all identifiers. (We check anyway.)
for i, expr := range a.Lhs {
lhs, ok := expr.(*ast.Ident)
if !ok {
f.Badf(expr.Pos(), "invalid AST: short variable declaration of non-identifier")
return true // Don't do any more processing.
}
switch rhs := a.Rhs[i].(type) {
case *ast.Ident:
if lhs.Name != rhs.Name {
return false
}
case *ast.TypeAssertExpr:
if id, ok := rhs.X.(*ast.Ident); ok {
if lhs.Name != id.Name {
return false
}
}
default:
return false
}
}
return true
} | [
"func",
"(",
"f",
"*",
"File",
")",
"idiomaticShortRedecl",
"(",
"a",
"*",
"ast",
".",
"AssignStmt",
")",
"bool",
"{",
"// Don't complain about deliberate redeclarations of the form",
"//\ti := i",
"// Such constructs are idiomatic in range loops to create a new variable",
"// ... | // idiomaticShortRedecl reports whether this short declaration can be ignored for
// the purposes of shadowing, that is, that any redeclarations it contains are deliberate. | [
"idiomaticShortRedecl",
"reports",
"whether",
"this",
"short",
"declaration",
"can",
"be",
"ignored",
"for",
"the",
"purposes",
"of",
"shadowing",
"that",
"is",
"that",
"any",
"redeclarations",
"it",
"contains",
"are",
"deliberate",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/shadow.go#L123-L155 | train |
hashicorp/go-hclog | hclogvet/shadow.go | idiomaticRedecl | func (f *File) idiomaticRedecl(d *ast.ValueSpec) bool {
// Don't complain about deliberate redeclarations of the form
// var i, j = i, j
if len(d.Names) != len(d.Values) {
return false
}
for i, lhs := range d.Names {
if rhs, ok := d.Values[i].(*ast.Ident); ok {
if lhs.Name != rhs.Name {
return false
}
}
}
return true
} | go | func (f *File) idiomaticRedecl(d *ast.ValueSpec) bool {
// Don't complain about deliberate redeclarations of the form
// var i, j = i, j
if len(d.Names) != len(d.Values) {
return false
}
for i, lhs := range d.Names {
if rhs, ok := d.Values[i].(*ast.Ident); ok {
if lhs.Name != rhs.Name {
return false
}
}
}
return true
} | [
"func",
"(",
"f",
"*",
"File",
")",
"idiomaticRedecl",
"(",
"d",
"*",
"ast",
".",
"ValueSpec",
")",
"bool",
"{",
"// Don't complain about deliberate redeclarations of the form",
"//\tvar i, j = i, j",
"if",
"len",
"(",
"d",
".",
"Names",
")",
"!=",
"len",
"(",
... | // idiomaticRedecl reports whether this declaration spec can be ignored for
// the purposes of shadowing, that is, that any redeclarations it contains are deliberate. | [
"idiomaticRedecl",
"reports",
"whether",
"this",
"declaration",
"spec",
"can",
"be",
"ignored",
"for",
"the",
"purposes",
"of",
"shadowing",
"that",
"is",
"that",
"any",
"redeclarations",
"it",
"contains",
"are",
"deliberate",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/shadow.go#L159-L173 | train |
hashicorp/go-hclog | hclogvet/shadow.go | checkShadowDecl | func checkShadowDecl(f *File, d *ast.GenDecl) {
if d.Tok != token.VAR {
return
}
for _, spec := range d.Specs {
valueSpec, ok := spec.(*ast.ValueSpec)
if !ok {
f.Badf(spec.Pos(), "invalid AST: var GenDecl not ValueSpec")
return
}
// Don't complain about deliberate redeclarations of the form
// var i = i
if f.idiomaticRedecl(valueSpec) {
return
}
for _, ident := range valueSpec.Names {
checkShadowing(f, ident)
}
}
} | go | func checkShadowDecl(f *File, d *ast.GenDecl) {
if d.Tok != token.VAR {
return
}
for _, spec := range d.Specs {
valueSpec, ok := spec.(*ast.ValueSpec)
if !ok {
f.Badf(spec.Pos(), "invalid AST: var GenDecl not ValueSpec")
return
}
// Don't complain about deliberate redeclarations of the form
// var i = i
if f.idiomaticRedecl(valueSpec) {
return
}
for _, ident := range valueSpec.Names {
checkShadowing(f, ident)
}
}
} | [
"func",
"checkShadowDecl",
"(",
"f",
"*",
"File",
",",
"d",
"*",
"ast",
".",
"GenDecl",
")",
"{",
"if",
"d",
".",
"Tok",
"!=",
"token",
".",
"VAR",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"spec",
":=",
"range",
"d",
".",
"Specs",
"{",
... | // checkShadowDecl checks for shadowing in a general variable declaration. | [
"checkShadowDecl",
"checks",
"for",
"shadowing",
"in",
"a",
"general",
"variable",
"declaration",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/shadow.go#L176-L195 | train |
hashicorp/go-hclog | hclogvet/shadow.go | checkShadowing | func checkShadowing(f *File, ident *ast.Ident) {
if ident.Name == "_" {
// Can't shadow the blank identifier.
return
}
obj := f.pkg.defs[ident]
if obj == nil {
return
}
// obj.Parent.Parent is the surrounding scope. If we can find another declaration
// starting from there, we have a shadowed identifier.
_, shadowed := obj.Parent().Parent().LookupParent(obj.Name(), obj.Pos())
if shadowed == nil {
return
}
// Don't complain if it's shadowing a universe-declared identifier; that's fine.
if shadowed.Parent() == types.Universe {
return
}
if *strictShadowing {
// The shadowed identifier must appear before this one to be an instance of shadowing.
if shadowed.Pos() > ident.Pos() {
return
}
} else {
// Don't complain if the span of validity of the shadowed identifier doesn't include
// the shadowing identifier.
span, ok := f.pkg.spans[shadowed]
if !ok {
f.Badf(ident.Pos(), "internal error: no range for %q", ident.Name)
return
}
if !span.contains(ident.Pos()) {
return
}
}
// Don't complain if the types differ: that implies the programmer really wants two different things.
if types.Identical(obj.Type(), shadowed.Type()) {
f.Badf(ident.Pos(), "declaration of %q shadows declaration at %s", obj.Name(), f.loc(shadowed.Pos()))
}
} | go | func checkShadowing(f *File, ident *ast.Ident) {
if ident.Name == "_" {
// Can't shadow the blank identifier.
return
}
obj := f.pkg.defs[ident]
if obj == nil {
return
}
// obj.Parent.Parent is the surrounding scope. If we can find another declaration
// starting from there, we have a shadowed identifier.
_, shadowed := obj.Parent().Parent().LookupParent(obj.Name(), obj.Pos())
if shadowed == nil {
return
}
// Don't complain if it's shadowing a universe-declared identifier; that's fine.
if shadowed.Parent() == types.Universe {
return
}
if *strictShadowing {
// The shadowed identifier must appear before this one to be an instance of shadowing.
if shadowed.Pos() > ident.Pos() {
return
}
} else {
// Don't complain if the span of validity of the shadowed identifier doesn't include
// the shadowing identifier.
span, ok := f.pkg.spans[shadowed]
if !ok {
f.Badf(ident.Pos(), "internal error: no range for %q", ident.Name)
return
}
if !span.contains(ident.Pos()) {
return
}
}
// Don't complain if the types differ: that implies the programmer really wants two different things.
if types.Identical(obj.Type(), shadowed.Type()) {
f.Badf(ident.Pos(), "declaration of %q shadows declaration at %s", obj.Name(), f.loc(shadowed.Pos()))
}
} | [
"func",
"checkShadowing",
"(",
"f",
"*",
"File",
",",
"ident",
"*",
"ast",
".",
"Ident",
")",
"{",
"if",
"ident",
".",
"Name",
"==",
"\"",
"\"",
"{",
"// Can't shadow the blank identifier.",
"return",
"\n",
"}",
"\n",
"obj",
":=",
"f",
".",
"pkg",
".",... | // checkShadowing checks whether the identifier shadows an identifier in an outer scope. | [
"checkShadowing",
"checks",
"whether",
"the",
"identifier",
"shadows",
"an",
"identifier",
"in",
"an",
"outer",
"scope",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/shadow.go#L198-L238 | train |
hashicorp/go-hclog | hclogvet/types.go | isNamedType | func isNamedType(t types.Type, path, name string) bool {
n, ok := t.(*types.Named)
if !ok {
return false
}
obj := n.Obj()
return obj.Name() == name && isPackage(obj.Pkg(), path)
} | go | func isNamedType(t types.Type, path, name string) bool {
n, ok := t.(*types.Named)
if !ok {
return false
}
obj := n.Obj()
return obj.Name() == name && isPackage(obj.Pkg(), path)
} | [
"func",
"isNamedType",
"(",
"t",
"types",
".",
"Type",
",",
"path",
",",
"name",
"string",
")",
"bool",
"{",
"n",
",",
"ok",
":=",
"t",
".",
"(",
"*",
"types",
".",
"Named",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n",
"}",
"\n",
... | // isNamedType reports whether t is the named type path.name. | [
"isNamedType",
"reports",
"whether",
"t",
"is",
"the",
"named",
"type",
"path",
".",
"name",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/types.go#L40-L47 | train |
hashicorp/go-hclog | hclogvet/types.go | isPackage | func isPackage(pkg *types.Package, path string) bool {
if pkg == nil {
return false
}
return pkg.Path() == path ||
strings.HasSuffix(pkg.Path(), "/vendor/"+path)
} | go | func isPackage(pkg *types.Package, path string) bool {
if pkg == nil {
return false
}
return pkg.Path() == path ||
strings.HasSuffix(pkg.Path(), "/vendor/"+path)
} | [
"func",
"isPackage",
"(",
"pkg",
"*",
"types",
".",
"Package",
",",
"path",
"string",
")",
"bool",
"{",
"if",
"pkg",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"pkg",
".",
"Path",
"(",
")",
"==",
"path",
"||",
"strings",
".",... | // isPackage reports whether pkg has path as the canonical path,
// taking into account vendoring effects | [
"isPackage",
"reports",
"whether",
"pkg",
"has",
"path",
"as",
"the",
"canonical",
"path",
"taking",
"into",
"account",
"vendoring",
"effects"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/types.go#L51-L58 | train |
hashicorp/go-hclog | hclogvet/types.go | importType | func importType(path, name string) types.Type {
pkg, err := stdImporter.Import(path)
if err != nil {
// This can happen if the package at path hasn't been compiled yet.
warnf("import failed: %v", err)
return nil
}
if obj, ok := pkg.Scope().Lookup(name).(*types.TypeName); ok {
return obj.Type()
}
warnf("invalid type name %q", name)
return nil
} | go | func importType(path, name string) types.Type {
pkg, err := stdImporter.Import(path)
if err != nil {
// This can happen if the package at path hasn't been compiled yet.
warnf("import failed: %v", err)
return nil
}
if obj, ok := pkg.Scope().Lookup(name).(*types.TypeName); ok {
return obj.Type()
}
warnf("invalid type name %q", name)
return nil
} | [
"func",
"importType",
"(",
"path",
",",
"name",
"string",
")",
"types",
".",
"Type",
"{",
"pkg",
",",
"err",
":=",
"stdImporter",
".",
"Import",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// This can happen if the package at path hasn't been compi... | // importType returns the type denoted by the qualified identifier
// path.name, and adds the respective package to the imports map
// as a side effect. In case of an error, importType returns nil. | [
"importType",
"returns",
"the",
"type",
"denoted",
"by",
"the",
"qualified",
"identifier",
"path",
".",
"name",
"and",
"adds",
"the",
"respective",
"package",
"to",
"the",
"imports",
"map",
"as",
"a",
"side",
"effect",
".",
"In",
"case",
"of",
"an",
"error... | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/types.go#L63-L75 | train |
hashicorp/go-hclog | hclogvet/types.go | hasBasicType | func (f *File) hasBasicType(x ast.Expr, kind types.BasicKind) bool {
t := f.pkg.types[x].Type
if t != nil {
t = t.Underlying()
}
b, ok := t.(*types.Basic)
return ok && b.Kind() == kind
} | go | func (f *File) hasBasicType(x ast.Expr, kind types.BasicKind) bool {
t := f.pkg.types[x].Type
if t != nil {
t = t.Underlying()
}
b, ok := t.(*types.Basic)
return ok && b.Kind() == kind
} | [
"func",
"(",
"f",
"*",
"File",
")",
"hasBasicType",
"(",
"x",
"ast",
".",
"Expr",
",",
"kind",
"types",
".",
"BasicKind",
")",
"bool",
"{",
"t",
":=",
"f",
".",
"pkg",
".",
"types",
"[",
"x",
"]",
".",
"Type",
"\n",
"if",
"t",
"!=",
"nil",
"{... | // hasBasicType reports whether x's type is a types.Basic with the given kind. | [
"hasBasicType",
"reports",
"whether",
"x",
"s",
"type",
"is",
"a",
"types",
".",
"Basic",
"with",
"the",
"given",
"kind",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/types.go#L143-L150 | train |
unrolled/secure | csp.go | CSPNonce | func CSPNonce(c context.Context) string {
if val, ok := c.Value(cspNonceKey).(string); ok {
return val
}
return ""
} | go | func CSPNonce(c context.Context) string {
if val, ok := c.Value(cspNonceKey).(string); ok {
return val
}
return ""
} | [
"func",
"CSPNonce",
"(",
"c",
"context",
".",
"Context",
")",
"string",
"{",
"if",
"val",
",",
"ok",
":=",
"c",
".",
"Value",
"(",
"cspNonceKey",
")",
".",
"(",
"string",
")",
";",
"ok",
"{",
"return",
"val",
"\n",
"}",
"\n\n",
"return",
"\"",
"\... | // CSPNonce returns the nonce value associated with the present request. If no nonce has been generated it returns an empty string. | [
"CSPNonce",
"returns",
"the",
"nonce",
"value",
"associated",
"with",
"the",
"present",
"request",
".",
"If",
"no",
"nonce",
"has",
"been",
"generated",
"it",
"returns",
"an",
"empty",
"string",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/csp.go#L16-L22 | train |
unrolled/secure | csp.go | WithCSPNonce | func WithCSPNonce(ctx context.Context, nonce string) context.Context {
return context.WithValue(ctx, cspNonceKey, nonce)
} | go | func WithCSPNonce(ctx context.Context, nonce string) context.Context {
return context.WithValue(ctx, cspNonceKey, nonce)
} | [
"func",
"WithCSPNonce",
"(",
"ctx",
"context",
".",
"Context",
",",
"nonce",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"cspNonceKey",
",",
"nonce",
")",
"\n",
"}"
] | // WithCSPNonce returns a context derived from ctx containing the given nonce as a value.
//
// This is intended for testing or more advanced use-cases;
// For ordinary HTTP handlers, clients can rely on this package's middleware to populate the CSP nonce in the context. | [
"WithCSPNonce",
"returns",
"a",
"context",
"derived",
"from",
"ctx",
"containing",
"the",
"given",
"nonce",
"as",
"a",
"value",
".",
"This",
"is",
"intended",
"for",
"testing",
"or",
"more",
"advanced",
"use",
"-",
"cases",
";",
"For",
"ordinary",
"HTTP",
... | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/csp.go#L28-L30 | train |
unrolled/secure | secure.go | New | func New(options ...Options) *Secure {
var o Options
if len(options) == 0 {
o = Options{}
} else {
o = options[0]
}
o.ContentSecurityPolicy = strings.Replace(o.ContentSecurityPolicy, "$NONCE", "'nonce-%[1]s'", -1)
o.nonceEnabled = strings.Contains(o.ContentSecurityPolicy, "%[1]s")
s := &Secure{
opt: o,
badHostHandler: http.HandlerFunc(defaultBadHostHandler),
}
if s.opt.AllowedHostsAreRegex {
// Test for invalid regular expressions in AllowedHosts
for _, allowedHost := range o.AllowedHosts {
regex, err := regexp.Compile(fmt.Sprintf("^%s$", allowedHost))
if err != nil {
panic(fmt.Sprintf("Error parsing AllowedHost: %s", err))
}
s.cRegexAllowedHosts = append(s.cRegexAllowedHosts, regex)
}
}
return s
} | go | func New(options ...Options) *Secure {
var o Options
if len(options) == 0 {
o = Options{}
} else {
o = options[0]
}
o.ContentSecurityPolicy = strings.Replace(o.ContentSecurityPolicy, "$NONCE", "'nonce-%[1]s'", -1)
o.nonceEnabled = strings.Contains(o.ContentSecurityPolicy, "%[1]s")
s := &Secure{
opt: o,
badHostHandler: http.HandlerFunc(defaultBadHostHandler),
}
if s.opt.AllowedHostsAreRegex {
// Test for invalid regular expressions in AllowedHosts
for _, allowedHost := range o.AllowedHosts {
regex, err := regexp.Compile(fmt.Sprintf("^%s$", allowedHost))
if err != nil {
panic(fmt.Sprintf("Error parsing AllowedHost: %s", err))
}
s.cRegexAllowedHosts = append(s.cRegexAllowedHosts, regex)
}
}
return s
} | [
"func",
"New",
"(",
"options",
"...",
"Options",
")",
"*",
"Secure",
"{",
"var",
"o",
"Options",
"\n",
"if",
"len",
"(",
"options",
")",
"==",
"0",
"{",
"o",
"=",
"Options",
"{",
"}",
"\n",
"}",
"else",
"{",
"o",
"=",
"options",
"[",
"0",
"]",
... | // New constructs a new Secure instance with the supplied options. | [
"New",
"constructs",
"a",
"new",
"Secure",
"instance",
"with",
"the",
"supplied",
"options",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L117-L146 | train |
unrolled/secure | secure.go | HandlerFuncWithNext | func (s *Secure) HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
// Let secure process the request. If it returns an error,
// that indicates the request should not continue.
responseHeader, r, err := s.processRequest(w, r)
addResponseHeaders(responseHeader, w)
// If there was an error, do not call next.
if err == nil && next != nil {
next(w, r)
}
} | go | func (s *Secure) HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
// Let secure process the request. If it returns an error,
// that indicates the request should not continue.
responseHeader, r, err := s.processRequest(w, r)
addResponseHeaders(responseHeader, w)
// If there was an error, do not call next.
if err == nil && next != nil {
next(w, r)
}
} | [
"func",
"(",
"s",
"*",
"Secure",
")",
"HandlerFuncWithNext",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"next",
"http",
".",
"HandlerFunc",
")",
"{",
"// Let secure process the request. If it returns an error,",
"// that i... | // HandlerFuncWithNext is a special implementation for Negroni, but could be used elsewhere. | [
"HandlerFuncWithNext",
"is",
"a",
"special",
"implementation",
"for",
"Negroni",
"but",
"could",
"be",
"used",
"elsewhere",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L192-L202 | train |
unrolled/secure | secure.go | HandlerFuncWithNextForRequestOnly | func (s *Secure) HandlerFuncWithNextForRequestOnly(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
// Let secure process the request. If it returns an error,
// that indicates the request should not continue.
responseHeader, r, err := s.processRequest(w, r)
// If there was an error, do not call next.
if err == nil && next != nil {
// Save response headers in the request context
ctx := context.WithValue(r.Context(), ctxSecureHeaderKey, responseHeader)
// No headers will be written to the ResponseWriter.
next(w, r.WithContext(ctx))
}
} | go | func (s *Secure) HandlerFuncWithNextForRequestOnly(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
// Let secure process the request. If it returns an error,
// that indicates the request should not continue.
responseHeader, r, err := s.processRequest(w, r)
// If there was an error, do not call next.
if err == nil && next != nil {
// Save response headers in the request context
ctx := context.WithValue(r.Context(), ctxSecureHeaderKey, responseHeader)
// No headers will be written to the ResponseWriter.
next(w, r.WithContext(ctx))
}
} | [
"func",
"(",
"s",
"*",
"Secure",
")",
"HandlerFuncWithNextForRequestOnly",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"next",
"http",
".",
"HandlerFunc",
")",
"{",
"// Let secure process the request. If it returns an error,"... | // HandlerFuncWithNextForRequestOnly is a special implementation for Negroni, but could be used elsewhere.
// Note that this is for requests only and will not write any headers. | [
"HandlerFuncWithNextForRequestOnly",
"is",
"a",
"special",
"implementation",
"for",
"Negroni",
"but",
"could",
"be",
"used",
"elsewhere",
".",
"Note",
"that",
"this",
"is",
"for",
"requests",
"only",
"and",
"will",
"not",
"write",
"any",
"headers",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L206-L219 | train |
unrolled/secure | secure.go | addResponseHeaders | func addResponseHeaders(responseHeader http.Header, w http.ResponseWriter) {
if responseHeader != nil {
for key, values := range responseHeader {
for _, value := range values {
w.Header().Set(key, value)
}
}
}
} | go | func addResponseHeaders(responseHeader http.Header, w http.ResponseWriter) {
if responseHeader != nil {
for key, values := range responseHeader {
for _, value := range values {
w.Header().Set(key, value)
}
}
}
} | [
"func",
"addResponseHeaders",
"(",
"responseHeader",
"http",
".",
"Header",
",",
"w",
"http",
".",
"ResponseWriter",
")",
"{",
"if",
"responseHeader",
"!=",
"nil",
"{",
"for",
"key",
",",
"values",
":=",
"range",
"responseHeader",
"{",
"for",
"_",
",",
"va... | // addResponseHeaders Adds the headers from 'responseHeader' to the response. | [
"addResponseHeaders",
"Adds",
"the",
"headers",
"from",
"responseHeader",
"to",
"the",
"response",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L222-L230 | train |
unrolled/secure | secure.go | Process | func (s *Secure) Process(w http.ResponseWriter, r *http.Request) error {
responseHeader, _, err := s.processRequest(w, r)
addResponseHeaders(responseHeader, w)
return err
} | go | func (s *Secure) Process(w http.ResponseWriter, r *http.Request) error {
responseHeader, _, err := s.processRequest(w, r)
addResponseHeaders(responseHeader, w)
return err
} | [
"func",
"(",
"s",
"*",
"Secure",
")",
"Process",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"responseHeader",
",",
"_",
",",
"err",
":=",
"s",
".",
"processRequest",
"(",
"w",
",",
"r",
")",
... | // Process runs the actual checks and writes the headers in the ResponseWriter. | [
"Process",
"runs",
"the",
"actual",
"checks",
"and",
"writes",
"the",
"headers",
"in",
"the",
"ResponseWriter",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L233-L238 | train |
unrolled/secure | secure.go | ProcessNoModifyRequest | func (s *Secure) ProcessNoModifyRequest(w http.ResponseWriter, r *http.Request) (http.Header, *http.Request, error) {
return s.processRequest(w, r)
} | go | func (s *Secure) ProcessNoModifyRequest(w http.ResponseWriter, r *http.Request) (http.Header, *http.Request, error) {
return s.processRequest(w, r)
} | [
"func",
"(",
"s",
"*",
"Secure",
")",
"ProcessNoModifyRequest",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"http",
".",
"Header",
",",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"return",
"s",
... | // ProcessNoModifyRequest runs the actual checks but does not write the headers in the ResponseWriter. | [
"ProcessNoModifyRequest",
"runs",
"the",
"actual",
"checks",
"but",
"does",
"not",
"write",
"the",
"headers",
"in",
"the",
"ResponseWriter",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L241-L243 | train |
unrolled/secure | secure.go | isSSL | func (s *Secure) isSSL(r *http.Request) bool {
ssl := strings.EqualFold(r.URL.Scheme, "https") || r.TLS != nil
if !ssl {
for k, v := range s.opt.SSLProxyHeaders {
if r.Header.Get(k) == v {
ssl = true
break
}
}
}
return ssl
} | go | func (s *Secure) isSSL(r *http.Request) bool {
ssl := strings.EqualFold(r.URL.Scheme, "https") || r.TLS != nil
if !ssl {
for k, v := range s.opt.SSLProxyHeaders {
if r.Header.Get(k) == v {
ssl = true
break
}
}
}
return ssl
} | [
"func",
"(",
"s",
"*",
"Secure",
")",
"isSSL",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"ssl",
":=",
"strings",
".",
"EqualFold",
"(",
"r",
".",
"URL",
".",
"Scheme",
",",
"\"",
"\"",
")",
"||",
"r",
".",
"TLS",
"!=",
"nil",
"... | // isSSL determine if we are on HTTPS. | [
"isSSL",
"determine",
"if",
"we",
"are",
"on",
"HTTPS",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L415-L426 | train |
unrolled/secure | secure.go | ModifyResponseHeaders | func (s *Secure) ModifyResponseHeaders(res *http.Response) error {
if res != nil && res.Request != nil {
responseHeader := res.Request.Context().Value(ctxSecureHeaderKey)
if responseHeader != nil {
for header, values := range responseHeader.(http.Header) {
if len(values) > 0 {
res.Header.Set(header, strings.Join(values, ","))
}
}
}
}
return nil
} | go | func (s *Secure) ModifyResponseHeaders(res *http.Response) error {
if res != nil && res.Request != nil {
responseHeader := res.Request.Context().Value(ctxSecureHeaderKey)
if responseHeader != nil {
for header, values := range responseHeader.(http.Header) {
if len(values) > 0 {
res.Header.Set(header, strings.Join(values, ","))
}
}
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Secure",
")",
"ModifyResponseHeaders",
"(",
"res",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"if",
"res",
"!=",
"nil",
"&&",
"res",
".",
"Request",
"!=",
"nil",
"{",
"responseHeader",
":=",
"res",
".",
"Request",
".",
"... | // ModifyResponseHeaders modifies the Response.
// Used by http.ReverseProxy. | [
"ModifyResponseHeaders",
"modifies",
"the",
"Response",
".",
"Used",
"by",
"http",
".",
"ReverseProxy",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/secure.go#L430-L442 | train |
labstack/gommon | color/color.go | New | func New() (c *Color) {
c = new(Color)
c.SetOutput(colorable.NewColorableStdout())
return
} | go | func New() (c *Color) {
c = new(Color)
c.SetOutput(colorable.NewColorableStdout())
return
} | [
"func",
"New",
"(",
")",
"(",
"c",
"*",
"Color",
")",
"{",
"c",
"=",
"new",
"(",
"Color",
")",
"\n",
"c",
".",
"SetOutput",
"(",
"colorable",
".",
"NewColorableStdout",
"(",
")",
")",
"\n",
"return",
"\n",
"}"
] | // New creates a Color instance. | [
"New",
"creates",
"a",
"Color",
"instance",
"."
] | 82ef680aef5189b68682876cf70d09daa4ac0f51 | https://github.com/labstack/gommon/blob/82ef680aef5189b68682876cf70d09daa4ac0f51/color/color.go#L132-L136 | train |
labstack/gommon | color/color.go | SetOutput | func (c *Color) SetOutput(w io.Writer) {
c.output = w
if w, ok := w.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
c.disabled = true
}
} | go | func (c *Color) SetOutput(w io.Writer) {
c.output = w
if w, ok := w.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
c.disabled = true
}
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"SetOutput",
"(",
"w",
"io",
".",
"Writer",
")",
"{",
"c",
".",
"output",
"=",
"w",
"\n",
"if",
"w",
",",
"ok",
":=",
"w",
".",
"(",
"*",
"os",
".",
"File",
")",
";",
"!",
"ok",
"||",
"!",
"isatty",
".... | // SetOutput sets the output. | [
"SetOutput",
"sets",
"the",
"output",
"."
] | 82ef680aef5189b68682876cf70d09daa4ac0f51 | https://github.com/labstack/gommon/blob/82ef680aef5189b68682876cf70d09daa4ac0f51/color/color.go#L144-L149 | train |
labstack/gommon | color/color.go | Printf | func (c *Color) Printf(format string, args ...interface{}) {
fmt.Fprintf(c.output, format, args...)
} | go | func (c *Color) Printf(format string, args ...interface{}) {
fmt.Fprintf(c.output, format, args...)
} | [
"func",
"(",
"c",
"*",
"Color",
")",
"Printf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"c",
".",
"output",
",",
"format",
",",
"args",
"...",
")",
"\n",
"}"
] | // Printf is analogous to `fmt.Printf` with termial detection. | [
"Printf",
"is",
"analogous",
"to",
"fmt",
".",
"Printf",
"with",
"termial",
"detection",
"."
] | 82ef680aef5189b68682876cf70d09daa4ac0f51 | https://github.com/labstack/gommon/blob/82ef680aef5189b68682876cf70d09daa4ac0f51/color/color.go#L172-L174 | train |
caarlos0/env | env.go | ParseWithFuncs | func ParseWithFuncs(v interface{}, funcMap CustomParsers) error {
ptrRef := reflect.ValueOf(v)
if ptrRef.Kind() != reflect.Ptr {
return ErrNotAStructPtr
}
ref := ptrRef.Elem()
if ref.Kind() != reflect.Struct {
return ErrNotAStructPtr
}
var parsers = defaultCustomParsers()
for k, v := range funcMap {
parsers[k] = v
}
return doParse(ref, parsers)
} | go | func ParseWithFuncs(v interface{}, funcMap CustomParsers) error {
ptrRef := reflect.ValueOf(v)
if ptrRef.Kind() != reflect.Ptr {
return ErrNotAStructPtr
}
ref := ptrRef.Elem()
if ref.Kind() != reflect.Struct {
return ErrNotAStructPtr
}
var parsers = defaultCustomParsers()
for k, v := range funcMap {
parsers[k] = v
}
return doParse(ref, parsers)
} | [
"func",
"ParseWithFuncs",
"(",
"v",
"interface",
"{",
"}",
",",
"funcMap",
"CustomParsers",
")",
"error",
"{",
"ptrRef",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"ptrRef",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"r... | // ParseWithFuncs is the same as `Parse` except it also allows the user to pass
// in custom parsers. | [
"ParseWithFuncs",
"is",
"the",
"same",
"as",
"Parse",
"except",
"it",
"also",
"allows",
"the",
"user",
"to",
"pass",
"in",
"custom",
"parsers",
"."
] | 2ae6b6e118789b55aae151656169a4a07d4bff42 | https://github.com/caarlos0/env/blob/2ae6b6e118789b55aae151656169a4a07d4bff42/env.go#L98-L112 | train |
caarlos0/env | env.go | parseKeyForOption | func parseKeyForOption(key string) (string, []string) {
opts := strings.Split(key, ",")
return opts[0], opts[1:]
} | go | func parseKeyForOption(key string) (string, []string) {
opts := strings.Split(key, ",")
return opts[0], opts[1:]
} | [
"func",
"parseKeyForOption",
"(",
"key",
"string",
")",
"(",
"string",
",",
"[",
"]",
"string",
")",
"{",
"opts",
":=",
"strings",
".",
"Split",
"(",
"key",
",",
"\"",
"\"",
")",
"\n",
"return",
"opts",
"[",
"0",
"]",
",",
"opts",
"[",
"1",
":",
... | // split the env tag's key into the expected key and desired option, if any. | [
"split",
"the",
"env",
"tag",
"s",
"key",
"into",
"the",
"expected",
"key",
"and",
"desired",
"option",
"if",
"any",
"."
] | 2ae6b6e118789b55aae151656169a4a07d4bff42 | https://github.com/caarlos0/env/blob/2ae6b6e118789b55aae151656169a4a07d4bff42/env.go#L183-L186 | train |
go-gl/glfw | v3.2/glfw/native_windows.go | GetWin32Adapter | func (m *Monitor) GetWin32Adapter() string {
ret := C.glfwGetWin32Adapter(m.data)
panicError()
return C.GoString(ret)
} | go | func (m *Monitor) GetWin32Adapter() string {
ret := C.glfwGetWin32Adapter(m.data)
panicError()
return C.GoString(ret)
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetWin32Adapter",
"(",
")",
"string",
"{",
"ret",
":=",
"C",
".",
"glfwGetWin32Adapter",
"(",
"m",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"ret",
")",
"\n",
... | // GetWin32Adapter returns the adapter device name of the monitor. | [
"GetWin32Adapter",
"returns",
"the",
"adapter",
"device",
"name",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_windows.go#L11-L15 | train |
go-gl/glfw | v3.2/glfw/native_windows.go | GetWin32Monitor | func (m *Monitor) GetWin32Monitor() string {
ret := C.glfwGetWin32Monitor(m.data)
panicError()
return C.GoString(ret)
} | go | func (m *Monitor) GetWin32Monitor() string {
ret := C.glfwGetWin32Monitor(m.data)
panicError()
return C.GoString(ret)
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetWin32Monitor",
"(",
")",
"string",
"{",
"ret",
":=",
"C",
".",
"glfwGetWin32Monitor",
"(",
"m",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"C",
".",
"GoString",
"(",
"ret",
")",
"\n",
... | // GetWin32Monitor returns the display device name of the monitor. | [
"GetWin32Monitor",
"returns",
"the",
"display",
"device",
"name",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_windows.go#L18-L22 | train |
go-gl/glfw | v3.2/glfw/native_windows.go | GetWin32Window | func (w *Window) GetWin32Window() C.HWND {
ret := C.glfwGetWin32Window(w.data)
panicError()
return ret
} | go | func (w *Window) GetWin32Window() C.HWND {
ret := C.glfwGetWin32Window(w.data)
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetWin32Window",
"(",
")",
"C",
".",
"HWND",
"{",
"ret",
":=",
"C",
".",
"glfwGetWin32Window",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetWin32Window returns the HWND of the window. | [
"GetWin32Window",
"returns",
"the",
"HWND",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_windows.go#L25-L29 | train |
go-gl/glfw | v3.2/glfw/native_windows.go | GetWGLContext | func (w *Window) GetWGLContext() C.HGLRC {
ret := C.glfwGetWGLContext(w.data)
panicError()
return ret
} | go | func (w *Window) GetWGLContext() C.HGLRC {
ret := C.glfwGetWGLContext(w.data)
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetWGLContext",
"(",
")",
"C",
".",
"HGLRC",
"{",
"ret",
":=",
"C",
".",
"glfwGetWGLContext",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetWGLContext returns the HGLRC of the window. | [
"GetWGLContext",
"returns",
"the",
"HGLRC",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_windows.go#L32-L36 | train |
go-gl/glfw | v3.0/glfw/monitor.go | GetPosition | func (m *Monitor) GetPosition() (x, y int) {
var xpos, ypos C.int
C.glfwGetMonitorPos(m.data, &xpos, &ypos)
return int(xpos), int(ypos)
} | go | func (m *Monitor) GetPosition() (x, y int) {
var xpos, ypos C.int
C.glfwGetMonitorPos(m.data, &xpos, &ypos)
return int(xpos), int(ypos)
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetPosition",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"var",
"xpos",
",",
"ypos",
"C",
".",
"int",
"\n\n",
"C",
".",
"glfwGetMonitorPos",
"(",
"m",
".",
"data",
",",
"&",
"xpos",
",",
"&",
"ypos",
... | //GetPosition returns the position, in screen coordinates, of the upper-left
//corner of the monitor. | [
"GetPosition",
"returns",
"the",
"position",
"in",
"screen",
"coordinates",
"of",
"the",
"upper",
"-",
"left",
"corner",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/monitor.go#L86-L91 | train |
go-gl/glfw | v3.0/glfw/monitor.go | SetGamma | func (m *Monitor) SetGamma(gamma float32) {
C.glfwSetGamma(m.data, C.float(gamma))
} | go | func (m *Monitor) SetGamma(gamma float32) {
C.glfwSetGamma(m.data, C.float(gamma))
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"SetGamma",
"(",
"gamma",
"float32",
")",
"{",
"C",
".",
"glfwSetGamma",
"(",
"m",
".",
"data",
",",
"C",
".",
"float",
"(",
"gamma",
")",
")",
"\n",
"}"
] | //SetGamma generates a 256-element gamma ramp from the specified exponent and then calls
//SetGamma with it. | [
"SetGamma",
"generates",
"a",
"256",
"-",
"element",
"gamma",
"ramp",
"from",
"the",
"specified",
"exponent",
"and",
"then",
"calls",
"SetGamma",
"with",
"it",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/monitor.go#L164-L166 | train |
go-gl/glfw | v3.0/glfw/monitor.go | GetGammaRamp | func (m *Monitor) GetGammaRamp() (*GammaRamp, error) {
var ramp GammaRamp
rampC := C.glfwGetGammaRamp(m.data)
if rampC == nil {
return nil, errors.New("Can't get the gamma ramp.")
}
length := int(rampC.size)
ramp.Red = make([]uint16, length)
ramp.Green = make([]uint16, length)
ramp.Blue = make([]uint16, length)
for i := 0; i < length; i++ {
ramp.Red[i] = uint16(C.GetGammaAtIndex(rampC.red, C.int(i)))
ramp.Green[i] = uint16(C.GetGammaAtIndex(rampC.green, C.int(i)))
ramp.Blue[i] = uint16(C.GetGammaAtIndex(rampC.blue, C.int(i)))
}
return &ramp, nil
} | go | func (m *Monitor) GetGammaRamp() (*GammaRamp, error) {
var ramp GammaRamp
rampC := C.glfwGetGammaRamp(m.data)
if rampC == nil {
return nil, errors.New("Can't get the gamma ramp.")
}
length := int(rampC.size)
ramp.Red = make([]uint16, length)
ramp.Green = make([]uint16, length)
ramp.Blue = make([]uint16, length)
for i := 0; i < length; i++ {
ramp.Red[i] = uint16(C.GetGammaAtIndex(rampC.red, C.int(i)))
ramp.Green[i] = uint16(C.GetGammaAtIndex(rampC.green, C.int(i)))
ramp.Blue[i] = uint16(C.GetGammaAtIndex(rampC.blue, C.int(i)))
}
return &ramp, nil
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetGammaRamp",
"(",
")",
"(",
"*",
"GammaRamp",
",",
"error",
")",
"{",
"var",
"ramp",
"GammaRamp",
"\n\n",
"rampC",
":=",
"C",
".",
"glfwGetGammaRamp",
"(",
"m",
".",
"data",
")",
"\n",
"if",
"rampC",
"==",
... | //GetGammaRamp retrieves the current gamma ramp of the monitor. | [
"GetGammaRamp",
"retrieves",
"the",
"current",
"gamma",
"ramp",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/monitor.go#L169-L189 | train |
go-gl/glfw | v3.0/glfw/monitor.go | SetGammaRamp | func (m *Monitor) SetGammaRamp(ramp *GammaRamp) {
var rampC C.GLFWgammaramp
length := len(ramp.Red)
for i := 0; i < length; i++ {
C.SetGammaAtIndex(rampC.red, C.int(i), C.ushort(ramp.Red[i]))
C.SetGammaAtIndex(rampC.green, C.int(i), C.ushort(ramp.Green[i]))
C.SetGammaAtIndex(rampC.blue, C.int(i), C.ushort(ramp.Blue[i]))
}
C.glfwSetGammaRamp(m.data, &rampC)
} | go | func (m *Monitor) SetGammaRamp(ramp *GammaRamp) {
var rampC C.GLFWgammaramp
length := len(ramp.Red)
for i := 0; i < length; i++ {
C.SetGammaAtIndex(rampC.red, C.int(i), C.ushort(ramp.Red[i]))
C.SetGammaAtIndex(rampC.green, C.int(i), C.ushort(ramp.Green[i]))
C.SetGammaAtIndex(rampC.blue, C.int(i), C.ushort(ramp.Blue[i]))
}
C.glfwSetGammaRamp(m.data, &rampC)
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"SetGammaRamp",
"(",
"ramp",
"*",
"GammaRamp",
")",
"{",
"var",
"rampC",
"C",
".",
"GLFWgammaramp",
"\n\n",
"length",
":=",
"len",
"(",
"ramp",
".",
"Red",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
... | //SetGammaRamp sets the current gamma ramp for the monitor. | [
"SetGammaRamp",
"sets",
"the",
"current",
"gamma",
"ramp",
"for",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/monitor.go#L192-L204 | train |
go-gl/glfw | v3.2/glfw/input.go | GetInputMode | func (w *Window) GetInputMode(mode InputMode) int {
ret := int(C.glfwGetInputMode(w.data, C.int(mode)))
panicError()
return ret
} | go | func (w *Window) GetInputMode(mode InputMode) int {
ret := int(C.glfwGetInputMode(w.data, C.int(mode)))
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetInputMode",
"(",
"mode",
"InputMode",
")",
"int",
"{",
"ret",
":=",
"int",
"(",
"C",
".",
"glfwGetInputMode",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"mode",
")",
")",
")",
"\n",
"panicError",
"... | // GetInputMode returns the value of an input option of the window. | [
"GetInputMode",
"returns",
"the",
"value",
"of",
"an",
"input",
"option",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L317-L321 | train |
go-gl/glfw | v3.2/glfw/input.go | SetInputMode | func (w *Window) SetInputMode(mode InputMode, value int) {
C.glfwSetInputMode(w.data, C.int(mode), C.int(value))
panicError()
} | go | func (w *Window) SetInputMode(mode InputMode, value int) {
C.glfwSetInputMode(w.data, C.int(mode), C.int(value))
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetInputMode",
"(",
"mode",
"InputMode",
",",
"value",
"int",
")",
"{",
"C",
".",
"glfwSetInputMode",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"mode",
")",
",",
"C",
".",
"int",
"(",
"value",
")",
... | // SetInputMode sets an input option for the window. | [
"SetInputMode",
"sets",
"an",
"input",
"option",
"for",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L324-L327 | train |
go-gl/glfw | v3.2/glfw/input.go | GetKeyName | func GetKeyName(key Key, scancode int) string {
ret := C.glfwGetKeyName(C.int(key), C.int(scancode))
panicError()
return C.GoString(ret)
} | go | func GetKeyName(key Key, scancode int) string {
ret := C.glfwGetKeyName(C.int(key), C.int(scancode))
panicError()
return C.GoString(ret)
} | [
"func",
"GetKeyName",
"(",
"key",
"Key",
",",
"scancode",
"int",
")",
"string",
"{",
"ret",
":=",
"C",
".",
"glfwGetKeyName",
"(",
"C",
".",
"int",
"(",
"key",
")",
",",
"C",
".",
"int",
"(",
"scancode",
")",
")",
"\n",
"panicError",
"(",
")",
"\... | // GetKeyName returns the localized name of the specified printable key.
//
// If the key is glfw.KeyUnknown, the scancode is used, otherwise the scancode is ignored. | [
"GetKeyName",
"returns",
"the",
"localized",
"name",
"of",
"the",
"specified",
"printable",
"key",
".",
"If",
"the",
"key",
"is",
"glfw",
".",
"KeyUnknown",
"the",
"scancode",
"is",
"used",
"otherwise",
"the",
"scancode",
"is",
"ignored",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L349-L353 | train |
go-gl/glfw | v3.2/glfw/input.go | SetCursor | func (w *Window) SetCursor(c *Cursor) {
if c == nil {
C.glfwSetCursor(w.data, nil)
} else {
C.glfwSetCursor(w.data, c.data)
}
panicError()
} | go | func (w *Window) SetCursor(c *Cursor) {
if c == nil {
C.glfwSetCursor(w.data, nil)
} else {
C.glfwSetCursor(w.data, c.data)
}
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetCursor",
"(",
"c",
"*",
"Cursor",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"C",
".",
"glfwSetCursor",
"(",
"w",
".",
"data",
",",
"nil",
")",
"\n",
"}",
"else",
"{",
"C",
".",
"glfwSetCursor",
"(",
"w",
... | // SetCursor sets the cursor image to be used when the cursor is over the client area
// of the specified window. The set cursor will only be visible when the cursor mode of the
// window is CursorNormal.
//
// On some platforms, the set cursor may not be visible unless the window also has input focus. | [
"SetCursor",
"sets",
"the",
"cursor",
"image",
"to",
"be",
"used",
"when",
"the",
"cursor",
"is",
"over",
"the",
"client",
"area",
"of",
"the",
"specified",
"window",
".",
"The",
"set",
"cursor",
"will",
"only",
"be",
"visible",
"when",
"the",
"cursor",
... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L451-L458 | train |
go-gl/glfw | v3.2/glfw/input.go | SetJoystickCallback | func SetJoystickCallback(cbfun JoystickCallback) (previous JoystickCallback) {
previous = fJoystickHolder
fJoystickHolder = cbfun
if cbfun == nil {
C.glfwSetJoystickCallback(nil)
} else {
C.glfwSetJoystickCallbackCB()
}
panicError()
return previous
} | go | func SetJoystickCallback(cbfun JoystickCallback) (previous JoystickCallback) {
previous = fJoystickHolder
fJoystickHolder = cbfun
if cbfun == nil {
C.glfwSetJoystickCallback(nil)
} else {
C.glfwSetJoystickCallbackCB()
}
panicError()
return previous
} | [
"func",
"SetJoystickCallback",
"(",
"cbfun",
"JoystickCallback",
")",
"(",
"previous",
"JoystickCallback",
")",
"{",
"previous",
"=",
"fJoystickHolder",
"\n",
"fJoystickHolder",
"=",
"cbfun",
"\n",
"if",
"cbfun",
"==",
"nil",
"{",
"C",
".",
"glfwSetJoystickCallbac... | // SetJoystickCallback sets the joystick configuration callback, or removes the
// currently set callback. This is called when a joystick is connected to or
// disconnected from the system. | [
"SetJoystickCallback",
"sets",
"the",
"joystick",
"configuration",
"callback",
"or",
"removes",
"the",
"currently",
"set",
"callback",
".",
"This",
"is",
"called",
"when",
"a",
"joystick",
"is",
"connected",
"to",
"or",
"disconnected",
"from",
"the",
"system",
"... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L466-L476 | train |
go-gl/glfw | v3.2/glfw/input.go | SetCursorPosCallback | func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback) {
previous = w.fCursorPosHolder
w.fCursorPosHolder = cbfun
if cbfun == nil {
C.glfwSetCursorPosCallback(w.data, nil)
} else {
C.glfwSetCursorPosCallbackCB(w.data)
}
panicError()
return previous
} | go | func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback) {
previous = w.fCursorPosHolder
w.fCursorPosHolder = cbfun
if cbfun == nil {
C.glfwSetCursorPosCallback(w.data, nil)
} else {
C.glfwSetCursorPosCallbackCB(w.data)
}
panicError()
return previous
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetCursorPosCallback",
"(",
"cbfun",
"CursorPosCallback",
")",
"(",
"previous",
"CursorPosCallback",
")",
"{",
"previous",
"=",
"w",
".",
"fCursorPosHolder",
"\n",
"w",
".",
"fCursorPosHolder",
"=",
"cbfun",
"\n",
"if",
... | // SetCursorPosCallback sets the cursor position callback which is called
// when the cursor is moved. The callback is provided with the position relative
// to the upper-left corner of the client area of the window. | [
"SetCursorPosCallback",
"sets",
"the",
"cursor",
"position",
"callback",
"which",
"is",
"called",
"when",
"the",
"cursor",
"is",
"moved",
".",
"The",
"callback",
"is",
"provided",
"with",
"the",
"position",
"relative",
"to",
"the",
"upper",
"-",
"left",
"corne... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L588-L598 | train |
go-gl/glfw | v3.2/glfw/input.go | SetDropCallback | func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) {
previous = w.fDropHolder
w.fDropHolder = cbfun
if cbfun == nil {
C.glfwSetDropCallback(w.data, nil)
} else {
C.glfwSetDropCallbackCB(w.data)
}
panicError()
return previous
} | go | func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback) {
previous = w.fDropHolder
w.fDropHolder = cbfun
if cbfun == nil {
C.glfwSetDropCallback(w.data, nil)
} else {
C.glfwSetDropCallbackCB(w.data)
}
panicError()
return previous
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetDropCallback",
"(",
"cbfun",
"DropCallback",
")",
"(",
"previous",
"DropCallback",
")",
"{",
"previous",
"=",
"w",
".",
"fDropHolder",
"\n",
"w",
".",
"fDropHolder",
"=",
"cbfun",
"\n",
"if",
"cbfun",
"==",
"nil"... | // SetDropCallback sets the drop callback which is called when an object
// is dropped over the window. | [
"SetDropCallback",
"sets",
"the",
"drop",
"callback",
"which",
"is",
"called",
"when",
"an",
"object",
"is",
"dropped",
"over",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L639-L649 | train |
go-gl/glfw | v3.2/glfw/input.go | JoystickPresent | func JoystickPresent(joy Joystick) bool {
ret := glfwbool(C.glfwJoystickPresent(C.int(joy)))
panicError()
return ret
} | go | func JoystickPresent(joy Joystick) bool {
ret := glfwbool(C.glfwJoystickPresent(C.int(joy)))
panicError()
return ret
} | [
"func",
"JoystickPresent",
"(",
"joy",
"Joystick",
")",
"bool",
"{",
"ret",
":=",
"glfwbool",
"(",
"C",
".",
"glfwJoystickPresent",
"(",
"C",
".",
"int",
"(",
"joy",
")",
")",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // JoystickPresent reports whether the specified joystick is present. | [
"JoystickPresent",
"reports",
"whether",
"the",
"specified",
"joystick",
"is",
"present",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L652-L656 | train |
go-gl/glfw | v3.2/glfw/input.go | GetJoystickAxes | func GetJoystickAxes(joy Joystick) []float32 {
var length int
axis := C.glfwGetJoystickAxes(C.int(joy), (*C.int)(unsafe.Pointer(&length)))
panicError()
if axis == nil {
return nil
}
a := make([]float32, length)
for i := 0; i < length; i++ {
a[i] = float32(C.GetAxisAtIndex(axis, C.int(i)))
}
return a
} | go | func GetJoystickAxes(joy Joystick) []float32 {
var length int
axis := C.glfwGetJoystickAxes(C.int(joy), (*C.int)(unsafe.Pointer(&length)))
panicError()
if axis == nil {
return nil
}
a := make([]float32, length)
for i := 0; i < length; i++ {
a[i] = float32(C.GetAxisAtIndex(axis, C.int(i)))
}
return a
} | [
"func",
"GetJoystickAxes",
"(",
"joy",
"Joystick",
")",
"[",
"]",
"float32",
"{",
"var",
"length",
"int",
"\n\n",
"axis",
":=",
"C",
".",
"glfwGetJoystickAxes",
"(",
"C",
".",
"int",
"(",
"joy",
")",
",",
"(",
"*",
"C",
".",
"int",
")",
"(",
"unsaf... | // GetJoystickAxes returns a slice of axis values. | [
"GetJoystickAxes",
"returns",
"a",
"slice",
"of",
"axis",
"values",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/input.go#L659-L673 | train |
go-gl/glfw | v3.2/glfw/error.go | Error | func (e *Error) Error() string {
return fmt.Sprintf("%s: %s", e.Code.String(), e.Desc)
} | go | func (e *Error) Error() string {
return fmt.Sprintf("%s: %s", e.Code.String(), e.Desc)
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"Code",
".",
"String",
"(",
")",
",",
"e",
".",
"Desc",
")",
"\n",
"}"
] | // Error prints the error code and description in a readable format. | [
"Error",
"prints",
"the",
"error",
"code",
"and",
"description",
"in",
"a",
"readable",
"format",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/error.go#L104-L106 | train |
go-gl/glfw | v3.2/glfw/error.go | flushErrors | func flushErrors() {
err := fetchError()
if err != nil {
fmt.Println("GLFW: An uncaught error has occurred:", err)
fmt.Println("GLFW: Please report this bug in the Go package immediately.")
}
} | go | func flushErrors() {
err := fetchError()
if err != nil {
fmt.Println("GLFW: An uncaught error has occurred:", err)
fmt.Println("GLFW: Please report this bug in the Go package immediately.")
}
} | [
"func",
"flushErrors",
"(",
")",
"{",
"err",
":=",
"fetchError",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"fmt",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // flushErrors is called by Terminate before it actually calls C.glfwTerminate,
// this ensures that any uncaught errors buffered in lastError are printed
// before the program exits. | [
"flushErrors",
"is",
"called",
"by",
"Terminate",
"before",
"it",
"actually",
"calls",
"C",
".",
"glfwTerminate",
"this",
"ensures",
"that",
"any",
"uncaught",
"errors",
"buffered",
"in",
"lastError",
"are",
"printed",
"before",
"the",
"program",
"exits",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/error.go#L134-L140 | train |
go-gl/glfw | v3.0/glfw/glfw.go | GetVersion | func GetVersion() (major, minor, revision int) {
var (
maj C.int
min C.int
rev C.int
)
C.glfwGetVersion(&maj, &min, &rev)
return int(maj), int(min), int(rev)
} | go | func GetVersion() (major, minor, revision int) {
var (
maj C.int
min C.int
rev C.int
)
C.glfwGetVersion(&maj, &min, &rev)
return int(maj), int(min), int(rev)
} | [
"func",
"GetVersion",
"(",
")",
"(",
"major",
",",
"minor",
",",
"revision",
"int",
")",
"{",
"var",
"(",
"maj",
"C",
".",
"int",
"\n",
"min",
"C",
".",
"int",
"\n",
"rev",
"C",
".",
"int",
"\n",
")",
"\n\n",
"C",
".",
"glfwGetVersion",
"(",
"&... | //GetVersion retrieves the major, minor and revision numbers of the GLFW
//library. It is intended for when you are using GLFW as a shared library and
//want to ensure that you are using the minimum required version.
//
//This function may be called before Init. | [
"GetVersion",
"retrieves",
"the",
"major",
"minor",
"and",
"revision",
"numbers",
"of",
"the",
"GLFW",
"library",
".",
"It",
"is",
"intended",
"for",
"when",
"you",
"are",
"using",
"GLFW",
"as",
"a",
"shared",
"library",
"and",
"want",
"to",
"ensure",
"tha... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/glfw.go#L67-L76 | train |
go-gl/glfw | v3.0/glfw/input.go | GetKey | func (w *Window) GetKey(key Key) Action {
return Action(C.glfwGetKey(w.data, C.int(key)))
} | go | func (w *Window) GetKey(key Key) Action {
return Action(C.glfwGetKey(w.data, C.int(key)))
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetKey",
"(",
"key",
"Key",
")",
"Action",
"{",
"return",
"Action",
"(",
"C",
".",
"glfwGetKey",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"key",
")",
")",
")",
"\n",
"}"
] | //GetKey returns the last reported state of a keyboard key. The returned state
//is one of Press or Release. The higher-level state Repeat is only reported to
//the key callback.
//
//If the StickyKeys input mode is enabled, this function returns Press the first
//time you call this function after a key has been pressed, even if the key has
//already been released.
//
//The key functions deal with physical keys, with key tokens named after their
//use on the standard US keyboard layout. If you want to input text, use the
//Unicode character callback instead. | [
"GetKey",
"returns",
"the",
"last",
"reported",
"state",
"of",
"a",
"keyboard",
"key",
".",
"The",
"returned",
"state",
"is",
"one",
"of",
"Press",
"or",
"Release",
".",
"The",
"higher",
"-",
"level",
"state",
"Repeat",
"is",
"only",
"reported",
"to",
"t... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/input.go#L290-L292 | train |
go-gl/glfw | v3.0/glfw/input.go | GetMouseButton | func (w *Window) GetMouseButton(button MouseButton) Action {
return Action(C.glfwGetMouseButton(w.data, C.int(button)))
} | go | func (w *Window) GetMouseButton(button MouseButton) Action {
return Action(C.glfwGetMouseButton(w.data, C.int(button)))
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetMouseButton",
"(",
"button",
"MouseButton",
")",
"Action",
"{",
"return",
"Action",
"(",
"C",
".",
"glfwGetMouseButton",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"button",
")",
")",
")",
"\n",
"}"
] | //GetMouseButton returns the last state reported for the specified mouse button.
//
//If the StickyMouseButtons input mode is enabled, this function returns Press
//the first time you call this function after a mouse button has been pressed,
//even if the mouse button has already been released. | [
"GetMouseButton",
"returns",
"the",
"last",
"state",
"reported",
"for",
"the",
"specified",
"mouse",
"button",
".",
"If",
"the",
"StickyMouseButtons",
"input",
"mode",
"is",
"enabled",
"this",
"function",
"returns",
"Press",
"the",
"first",
"time",
"you",
"call"... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/input.go#L299-L301 | train |
go-gl/glfw | v3.0/glfw/input.go | SetCharacterCallback | func (w *Window) SetCharacterCallback(cbfun func(w *Window, char uint)) {
if cbfun == nil {
C.glfwSetCharCallback(w.data, nil)
} else {
w.fCharHolder = cbfun
C.glfwSetCharCallbackCB(w.data)
}
} | go | func (w *Window) SetCharacterCallback(cbfun func(w *Window, char uint)) {
if cbfun == nil {
C.glfwSetCharCallback(w.data, nil)
} else {
w.fCharHolder = cbfun
C.glfwSetCharCallbackCB(w.data)
}
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetCharacterCallback",
"(",
"cbfun",
"func",
"(",
"w",
"*",
"Window",
",",
"char",
"uint",
")",
")",
"{",
"if",
"cbfun",
"==",
"nil",
"{",
"C",
".",
"glfwSetCharCallback",
"(",
"w",
".",
"data",
",",
"nil",
")... | //SetCharacterCallback sets the character callback which is called when a
//Unicode character is input.
//
//The character callback is intended for text input. If you want to know whether
//a specific key was pressed or released, use the key callback instead. | [
"SetCharacterCallback",
"sets",
"the",
"character",
"callback",
"which",
"is",
"called",
"when",
"a",
"Unicode",
"character",
"is",
"input",
".",
"The",
"character",
"callback",
"is",
"intended",
"for",
"text",
"input",
".",
"If",
"you",
"want",
"to",
"know",
... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/input.go#L354-L361 | train |
go-gl/glfw | v3.0/glfw/input.go | SetCursorPositionCallback | func (w *Window) SetCursorPositionCallback(cbfun func(w *Window, xpos float64, ypos float64)) {
if cbfun == nil {
C.glfwSetCursorPosCallback(w.data, nil)
} else {
w.fCursorPosHolder = cbfun
C.glfwSetCursorPosCallbackCB(w.data)
}
} | go | func (w *Window) SetCursorPositionCallback(cbfun func(w *Window, xpos float64, ypos float64)) {
if cbfun == nil {
C.glfwSetCursorPosCallback(w.data, nil)
} else {
w.fCursorPosHolder = cbfun
C.glfwSetCursorPosCallbackCB(w.data)
}
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetCursorPositionCallback",
"(",
"cbfun",
"func",
"(",
"w",
"*",
"Window",
",",
"xpos",
"float64",
",",
"ypos",
"float64",
")",
")",
"{",
"if",
"cbfun",
"==",
"nil",
"{",
"C",
".",
"glfwSetCursorPosCallback",
"(",
... | //SetCursorPositionCallback sets the cursor position callback which is called
//when the cursor is moved. The callback is provided with the position relative
//to the upper-left corner of the client area of the window. | [
"SetCursorPositionCallback",
"sets",
"the",
"cursor",
"position",
"callback",
"which",
"is",
"called",
"when",
"the",
"cursor",
"is",
"moved",
".",
"The",
"callback",
"is",
"provided",
"with",
"the",
"position",
"relative",
"to",
"the",
"upper",
"-",
"left",
"... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/input.go#L383-L390 | train |
go-gl/glfw | v3.0/glfw/input.go | GetJoystickButtons | func GetJoystickButtons(joy Joystick) ([]byte, error) {
var length int
buttons := C.glfwGetJoystickButtons(C.int(joy), (*C.int)(unsafe.Pointer(&length)))
if buttons == nil {
return nil, errors.New("Joystick is not present.")
}
b := make([]byte, length)
for i := 0; i < length; i++ {
b[i] = byte(C.GetButtonsAtIndex(buttons, C.int(i)))
}
return b, nil
} | go | func GetJoystickButtons(joy Joystick) ([]byte, error) {
var length int
buttons := C.glfwGetJoystickButtons(C.int(joy), (*C.int)(unsafe.Pointer(&length)))
if buttons == nil {
return nil, errors.New("Joystick is not present.")
}
b := make([]byte, length)
for i := 0; i < length; i++ {
b[i] = byte(C.GetButtonsAtIndex(buttons, C.int(i)))
}
return b, nil
} | [
"func",
"GetJoystickButtons",
"(",
"joy",
"Joystick",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"length",
"int",
"\n\n",
"buttons",
":=",
"C",
".",
"glfwGetJoystickButtons",
"(",
"C",
".",
"int",
"(",
"joy",
")",
",",
"(",
"*",
"C",
... | //GetJoystickButtons returns a slice of button values. | [
"GetJoystickButtons",
"returns",
"a",
"slice",
"of",
"button",
"values",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/input.go#L437-L451 | train |
go-gl/glfw | v3.0/glfw/window.go | GetPosition | func (w *Window) GetPosition() (x, y int) {
var xpos, ypos C.int
C.glfwGetWindowPos(w.data, &xpos, &ypos)
return int(xpos), int(ypos)
} | go | func (w *Window) GetPosition() (x, y int) {
var xpos, ypos C.int
C.glfwGetWindowPos(w.data, &xpos, &ypos)
return int(xpos), int(ypos)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetPosition",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"var",
"xpos",
",",
"ypos",
"C",
".",
"int",
"\n\n",
"C",
".",
"glfwGetWindowPos",
"(",
"w",
".",
"data",
",",
"&",
"xpos",
",",
"&",
"ypos",
... | //GetPosition returns the position, in screen coordinates, of the upper-left
//corner of the client area of the window. | [
"GetPosition",
"returns",
"the",
"position",
"in",
"screen",
"coordinates",
"of",
"the",
"upper",
"-",
"left",
"corner",
"of",
"the",
"client",
"area",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/window.go#L300-L305 | train |
go-gl/glfw | v3.0/glfw/window.go | GetSize | func (w *Window) GetSize() (width, height int) {
var wi, h C.int
C.glfwGetWindowSize(w.data, &wi, &h)
return int(wi), int(h)
} | go | func (w *Window) GetSize() (width, height int) {
var wi, h C.int
C.glfwGetWindowSize(w.data, &wi, &h)
return int(wi), int(h)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetSize",
"(",
")",
"(",
"width",
",",
"height",
"int",
")",
"{",
"var",
"wi",
",",
"h",
"C",
".",
"int",
"\n",
"C",
".",
"glfwGetWindowSize",
"(",
"w",
".",
"data",
",",
"&",
"wi",
",",
"&",
"h",
")",
... | //GetSize returns the size, in screen coordinates, of the client area of the
//specified window. | [
"GetSize",
"returns",
"the",
"size",
"in",
"screen",
"coordinates",
"of",
"the",
"client",
"area",
"of",
"the",
"specified",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/window.go#L328-L332 | train |
go-gl/glfw | v3.0/glfw/window.go | GetFramebufferSize | func (w *Window) GetFramebufferSize() (width, height int) {
var wi, h C.int
C.glfwGetFramebufferSize(w.data, &wi, &h)
return int(wi), int(h)
} | go | func (w *Window) GetFramebufferSize() (width, height int) {
var wi, h C.int
C.glfwGetFramebufferSize(w.data, &wi, &h)
return int(wi), int(h)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetFramebufferSize",
"(",
")",
"(",
"width",
",",
"height",
"int",
")",
"{",
"var",
"wi",
",",
"h",
"C",
".",
"int",
"\n",
"C",
".",
"glfwGetFramebufferSize",
"(",
"w",
".",
"data",
",",
"&",
"wi",
",",
"&",... | //GetFramebufferSize retrieves the size, in pixels, of the framebuffer of the
//specified window. | [
"GetFramebufferSize",
"retrieves",
"the",
"size",
"in",
"pixels",
"of",
"the",
"framebuffer",
"of",
"the",
"specified",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/window.go#L351-L355 | train |
go-gl/glfw | v3.0/glfw/window.go | GetMonitor | func (w *Window) GetMonitor() (*Monitor, error) {
m := C.glfwGetWindowMonitor(w.data)
if m == nil {
return nil, errors.New("Can't get the monitor.")
}
return &Monitor{m}, nil
} | go | func (w *Window) GetMonitor() (*Monitor, error) {
m := C.glfwGetWindowMonitor(w.data)
if m == nil {
return nil, errors.New("Can't get the monitor.")
}
return &Monitor{m}, nil
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetMonitor",
"(",
")",
"(",
"*",
"Monitor",
",",
"error",
")",
"{",
"m",
":=",
"C",
".",
"glfwGetWindowMonitor",
"(",
"w",
".",
"data",
")",
"\n\n",
"if",
"m",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors... | //GetMonitor returns the handle of the monitor that the window is in
//fullscreen on. | [
"GetMonitor",
"returns",
"the",
"handle",
"of",
"the",
"monitor",
"that",
"the",
"window",
"is",
"in",
"fullscreen",
"on",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/window.go#L399-L406 | train |
go-gl/glfw | v3.0/glfw/window.go | GetAttribute | func (w *Window) GetAttribute(attrib Hint) int {
return int(C.glfwGetWindowAttrib(w.data, C.int(attrib)))
} | go | func (w *Window) GetAttribute(attrib Hint) int {
return int(C.glfwGetWindowAttrib(w.data, C.int(attrib)))
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetAttribute",
"(",
"attrib",
"Hint",
")",
"int",
"{",
"return",
"int",
"(",
"C",
".",
"glfwGetWindowAttrib",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"attrib",
")",
")",
")",
"\n",
"}"
] | //GetAttribute returns an attribute of the window. There are many attributes,
//some related to the window and others to its context. | [
"GetAttribute",
"returns",
"an",
"attribute",
"of",
"the",
"window",
".",
"There",
"are",
"many",
"attributes",
"some",
"related",
"to",
"the",
"window",
"and",
"others",
"to",
"its",
"context",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/window.go#L410-L412 | train |
go-gl/glfw | v3.0/glfw/window.go | SetPositionCallback | func (w *Window) SetPositionCallback(cbfun func(w *Window, xpos int, ypos int)) {
if cbfun == nil {
C.glfwSetWindowPosCallback(w.data, nil)
} else {
w.fPosHolder = cbfun
C.glfwSetWindowPosCallbackCB(w.data)
}
} | go | func (w *Window) SetPositionCallback(cbfun func(w *Window, xpos int, ypos int)) {
if cbfun == nil {
C.glfwSetWindowPosCallback(w.data, nil)
} else {
w.fPosHolder = cbfun
C.glfwSetWindowPosCallbackCB(w.data)
}
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetPositionCallback",
"(",
"cbfun",
"func",
"(",
"w",
"*",
"Window",
",",
"xpos",
"int",
",",
"ypos",
"int",
")",
")",
"{",
"if",
"cbfun",
"==",
"nil",
"{",
"C",
".",
"glfwSetWindowPosCallback",
"(",
"w",
".",
... | //SetPositionCallback sets the position callback of the window, which is called
//when the window is moved. The callback is provided with the screen position
//of the upper-left corner of the client area of the window. | [
"SetPositionCallback",
"sets",
"the",
"position",
"callback",
"of",
"the",
"window",
"which",
"is",
"called",
"when",
"the",
"window",
"is",
"moved",
".",
"The",
"callback",
"is",
"provided",
"with",
"the",
"screen",
"position",
"of",
"the",
"upper",
"-",
"l... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/window.go#L429-L436 | train |
go-gl/glfw | v3.2/glfw/window.go | WindowHint | func WindowHint(target Hint, hint int) {
C.glfwWindowHint(C.int(target), C.int(hint))
panicError()
} | go | func WindowHint(target Hint, hint int) {
C.glfwWindowHint(C.int(target), C.int(hint))
panicError()
} | [
"func",
"WindowHint",
"(",
"target",
"Hint",
",",
"hint",
"int",
")",
"{",
"C",
".",
"glfwWindowHint",
"(",
"C",
".",
"int",
"(",
"target",
")",
",",
"C",
".",
"int",
"(",
"hint",
")",
")",
"\n",
"panicError",
"(",
")",
"\n",
"}"
] | // WindowHint sets hints for the next call to CreateWindow. The hints,
// once set, retain their values until changed by a call to WindowHint or
// DefaultWindowHints, or until the library is terminated with Terminate.
//
// This function may only be called from the main thread. | [
"WindowHint",
"sets",
"hints",
"for",
"the",
"next",
"call",
"to",
"CreateWindow",
".",
"The",
"hints",
"once",
"set",
"retain",
"their",
"values",
"until",
"changed",
"by",
"a",
"call",
"to",
"WindowHint",
"or",
"DefaultWindowHints",
"or",
"until",
"the",
"... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L234-L237 | train |
go-gl/glfw | v3.2/glfw/window.go | Destroy | func (w *Window) Destroy() {
windows.remove(w.data)
C.glfwDestroyWindow(w.data)
panicError()
} | go | func (w *Window) Destroy() {
windows.remove(w.data)
C.glfwDestroyWindow(w.data)
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Destroy",
"(",
")",
"{",
"windows",
".",
"remove",
"(",
"w",
".",
"data",
")",
"\n",
"C",
".",
"glfwDestroyWindow",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"}"
] | // Destroy destroys the specified window and its context. On calling this
// function, no further callbacks will be called for that window.
//
// This function may only be called from the main thread. | [
"Destroy",
"destroys",
"the",
"specified",
"window",
"and",
"its",
"context",
".",
"On",
"calling",
"this",
"function",
"no",
"further",
"callbacks",
"will",
"be",
"called",
"for",
"that",
"window",
".",
"This",
"function",
"may",
"only",
"be",
"called",
"fr... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L301-L305 | train |
go-gl/glfw | v3.2/glfw/window.go | ShouldClose | func (w *Window) ShouldClose() bool {
ret := glfwbool(C.glfwWindowShouldClose(w.data))
panicError()
return ret
} | go | func (w *Window) ShouldClose() bool {
ret := glfwbool(C.glfwWindowShouldClose(w.data))
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"ShouldClose",
"(",
")",
"bool",
"{",
"ret",
":=",
"glfwbool",
"(",
"C",
".",
"glfwWindowShouldClose",
"(",
"w",
".",
"data",
")",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // ShouldClose reports the value of the close flag of the specified window. | [
"ShouldClose",
"reports",
"the",
"value",
"of",
"the",
"close",
"flag",
"of",
"the",
"specified",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L308-L312 | train |
go-gl/glfw | v3.2/glfw/window.go | SetShouldClose | func (w *Window) SetShouldClose(value bool) {
if !value {
C.glfwSetWindowShouldClose(w.data, C.int(False))
} else {
C.glfwSetWindowShouldClose(w.data, C.int(True))
}
panicError()
} | go | func (w *Window) SetShouldClose(value bool) {
if !value {
C.glfwSetWindowShouldClose(w.data, C.int(False))
} else {
C.glfwSetWindowShouldClose(w.data, C.int(True))
}
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetShouldClose",
"(",
"value",
"bool",
")",
"{",
"if",
"!",
"value",
"{",
"C",
".",
"glfwSetWindowShouldClose",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"False",
")",
")",
"\n",
"}",
"else",
"{",
"C... | // SetShouldClose sets the value of the close flag of the window. This can be
// used to override the user's attempt to close the window, or to signal that it
// should be closed. | [
"SetShouldClose",
"sets",
"the",
"value",
"of",
"the",
"close",
"flag",
"of",
"the",
"window",
".",
"This",
"can",
"be",
"used",
"to",
"override",
"the",
"user",
"s",
"attempt",
"to",
"close",
"the",
"window",
"or",
"to",
"signal",
"that",
"it",
"should"... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L317-L324 | train |
go-gl/glfw | v3.2/glfw/window.go | GetPos | func (w *Window) GetPos() (x, y int) {
var xpos, ypos C.int
C.glfwGetWindowPos(w.data, &xpos, &ypos)
panicError()
return int(xpos), int(ypos)
} | go | func (w *Window) GetPos() (x, y int) {
var xpos, ypos C.int
C.glfwGetWindowPos(w.data, &xpos, &ypos)
panicError()
return int(xpos), int(ypos)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetPos",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"var",
"xpos",
",",
"ypos",
"C",
".",
"int",
"\n",
"C",
".",
"glfwGetWindowPos",
"(",
"w",
".",
"data",
",",
"&",
"xpos",
",",
"&",
"ypos",
")",
... | // GetPos returns the position, in screen coordinates, of the upper-left
// corner of the client area of the window. | [
"GetPos",
"returns",
"the",
"position",
"in",
"screen",
"coordinates",
"of",
"the",
"upper",
"-",
"left",
"corner",
"of",
"the",
"client",
"area",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L389-L394 | train |
go-gl/glfw | v3.2/glfw/window.go | SetSizeLimits | func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
C.glfwSetWindowSizeLimits(w.data, C.int(minw), C.int(minh), C.int(maxw), C.int(maxh))
panicError()
} | go | func (w *Window) SetSizeLimits(minw, minh, maxw, maxh int) {
C.glfwSetWindowSizeLimits(w.data, C.int(minw), C.int(minh), C.int(maxw), C.int(maxh))
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetSizeLimits",
"(",
"minw",
",",
"minh",
",",
"maxw",
",",
"maxh",
"int",
")",
"{",
"C",
".",
"glfwSetWindowSizeLimits",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"minw",
")",
",",
"C",
".",
"int",
... | // SetSizeLimits sets the size limits of the client area of the specified window.
// If the window is full screen or not resizable, this function does nothing.
//
// The size limits are applied immediately and may cause the window to be resized. | [
"SetSizeLimits",
"sets",
"the",
"size",
"limits",
"of",
"the",
"client",
"area",
"of",
"the",
"specified",
"window",
".",
"If",
"the",
"window",
"is",
"full",
"screen",
"or",
"not",
"resizable",
"this",
"function",
"does",
"nothing",
".",
"The",
"size",
"l... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L443-L446 | train |
go-gl/glfw | v3.2/glfw/window.go | GetFrameSize | func (w *Window) GetFrameSize() (left, top, right, bottom int) {
var l, t, r, b C.int
C.glfwGetWindowFrameSize(w.data, &l, &t, &r, &b)
panicError()
return int(l), int(t), int(r), int(b)
} | go | func (w *Window) GetFrameSize() (left, top, right, bottom int) {
var l, t, r, b C.int
C.glfwGetWindowFrameSize(w.data, &l, &t, &r, &b)
panicError()
return int(l), int(t), int(r), int(b)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetFrameSize",
"(",
")",
"(",
"left",
",",
"top",
",",
"right",
",",
"bottom",
"int",
")",
"{",
"var",
"l",
",",
"t",
",",
"r",
",",
"b",
"C",
".",
"int",
"\n",
"C",
".",
"glfwGetWindowFrameSize",
"(",
"w"... | // GetFrameSize retrieves the size, in screen coordinates, of each edge of the frame
// of the specified window. This size includes the title bar, if the window has one.
// The size of the frame may vary depending on the window-related hints used to create it.
//
// Because this function retrieves the size of each window frame edge and not the offset
// along a particular coordinate axis, the retrieved values will always be zero or positive. | [
"GetFrameSize",
"retrieves",
"the",
"size",
"in",
"screen",
"coordinates",
"of",
"each",
"edge",
"of",
"the",
"frame",
"of",
"the",
"specified",
"window",
".",
"This",
"size",
"includes",
"the",
"title",
"bar",
"if",
"the",
"window",
"has",
"one",
".",
"Th... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L477-L482 | train |
go-gl/glfw | v3.2/glfw/window.go | Focus | func (w *Window) Focus() error {
C.glfwFocusWindow(w.data)
return acceptError(APIUnavailable)
} | go | func (w *Window) Focus() error {
C.glfwFocusWindow(w.data)
return acceptError(APIUnavailable)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Focus",
"(",
")",
"error",
"{",
"C",
".",
"glfwFocusWindow",
"(",
"w",
".",
"data",
")",
"\n",
"return",
"acceptError",
"(",
"APIUnavailable",
")",
"\n",
"}"
] | // Focus brings the specified window to front and sets input focus.
// The window should already be visible and not iconified.
//
// By default, both windowed and full screen mode windows are focused when initially created.
// Set the glfw.Focused to disable this behavior.
//
// Do not use this function to steal focus from other applications unless you are certain that
// is what the user wants. Focus stealing can be extremely disruptive. | [
"Focus",
"brings",
"the",
"specified",
"window",
"to",
"front",
"and",
"sets",
"input",
"focus",
".",
"The",
"window",
"should",
"already",
"be",
"visible",
"and",
"not",
"iconified",
".",
"By",
"default",
"both",
"windowed",
"and",
"full",
"screen",
"mode",... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L492-L495 | train |
go-gl/glfw | v3.2/glfw/window.go | Maximize | func (w *Window) Maximize() error {
C.glfwMaximizeWindow(w.data)
return acceptError(APIUnavailable)
} | go | func (w *Window) Maximize() error {
C.glfwMaximizeWindow(w.data)
return acceptError(APIUnavailable)
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"Maximize",
"(",
")",
"error",
"{",
"C",
".",
"glfwMaximizeWindow",
"(",
"w",
".",
"data",
")",
"\n",
"return",
"acceptError",
"(",
"APIUnavailable",
")",
"\n",
"}"
] | // Maximize maximizes the specified window if it was previously not maximized.
// If the window is already maximized, this function does nothing.
//
// If the specified window is a full screen window, this function does nothing. | [
"Maximize",
"maximizes",
"the",
"specified",
"window",
"if",
"it",
"was",
"previously",
"not",
"maximized",
".",
"If",
"the",
"window",
"is",
"already",
"maximized",
"this",
"function",
"does",
"nothing",
".",
"If",
"the",
"specified",
"window",
"is",
"a",
"... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L512-L515 | train |
go-gl/glfw | v3.2/glfw/window.go | GetMonitor | func (w *Window) GetMonitor() *Monitor {
m := C.glfwGetWindowMonitor(w.data)
panicError()
if m == nil {
return nil
}
return &Monitor{m}
} | go | func (w *Window) GetMonitor() *Monitor {
m := C.glfwGetWindowMonitor(w.data)
panicError()
if m == nil {
return nil
}
return &Monitor{m}
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetMonitor",
"(",
")",
"*",
"Monitor",
"{",
"m",
":=",
"C",
".",
"glfwGetWindowMonitor",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}... | // GetMonitor returns the handle of the monitor that the window is in
// fullscreen on.
//
// Returns nil if the window is in windowed mode. | [
"GetMonitor",
"returns",
"the",
"handle",
"of",
"the",
"monitor",
"that",
"the",
"window",
"is",
"in",
"fullscreen",
"on",
".",
"Returns",
"nil",
"if",
"the",
"window",
"is",
"in",
"windowed",
"mode",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L550-L557 | train |
go-gl/glfw | v3.2/glfw/window.go | SetMonitor | func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) {
var m *C.GLFWmonitor
if monitor == nil {
m = nil
} else {
m = monitor.data
}
C.glfwSetWindowMonitor(w.data, m, C.int(xpos), C.int(ypos), C.int(width), C.int(height), C.int(refreshRate))
panicError()
} | go | func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int) {
var m *C.GLFWmonitor
if monitor == nil {
m = nil
} else {
m = monitor.data
}
C.glfwSetWindowMonitor(w.data, m, C.int(xpos), C.int(ypos), C.int(width), C.int(height), C.int(refreshRate))
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetMonitor",
"(",
"monitor",
"*",
"Monitor",
",",
"xpos",
",",
"ypos",
",",
"width",
",",
"height",
",",
"refreshRate",
"int",
")",
"{",
"var",
"m",
"*",
"C",
".",
"GLFWmonitor",
"\n",
"if",
"monitor",
"==",
"... | // SetMonitor sets the monitor that the window uses for full screen mode or,
// if the monitor is NULL, makes it windowed mode.
//
// When setting a monitor, this function updates the width, height and refresh
// rate of the desired video mode and switches to the video mode closest to it.
// The window position is ignored when setting a monitor.
//
// When the monitor is NULL, the position, width and height are used to place
// the window client area. The refresh rate is ignored when no monitor is specified.
// If you only wish to update the resolution of a full screen window or the size of
// a windowed mode window, see window.SetSize.
//
// When a window transitions from full screen to windowed mode, this function
// restores any previous window settings such as whether it is decorated, floating,
// resizable, has size or aspect ratio limits, etc.. | [
"SetMonitor",
"sets",
"the",
"monitor",
"that",
"the",
"window",
"uses",
"for",
"full",
"screen",
"mode",
"or",
"if",
"the",
"monitor",
"is",
"NULL",
"makes",
"it",
"windowed",
"mode",
".",
"When",
"setting",
"a",
"monitor",
"this",
"function",
"updates",
... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L574-L583 | train |
go-gl/glfw | v3.2/glfw/window.go | GetAttrib | func (w *Window) GetAttrib(attrib Hint) int {
ret := int(C.glfwGetWindowAttrib(w.data, C.int(attrib)))
panicError()
return ret
} | go | func (w *Window) GetAttrib(attrib Hint) int {
ret := int(C.glfwGetWindowAttrib(w.data, C.int(attrib)))
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetAttrib",
"(",
"attrib",
"Hint",
")",
"int",
"{",
"ret",
":=",
"int",
"(",
"C",
".",
"glfwGetWindowAttrib",
"(",
"w",
".",
"data",
",",
"C",
".",
"int",
"(",
"attrib",
")",
")",
")",
"\n",
"panicError",
"(... | // GetAttrib returns an attribute of the window. There are many attributes,
// some related to the window and others to its context. | [
"GetAttrib",
"returns",
"an",
"attribute",
"of",
"the",
"window",
".",
"There",
"are",
"many",
"attributes",
"some",
"related",
"to",
"the",
"window",
"and",
"others",
"to",
"its",
"context",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L587-L591 | train |
go-gl/glfw | v3.2/glfw/window.go | SetUserPointer | func (w *Window) SetUserPointer(pointer unsafe.Pointer) {
C.glfwSetWindowUserPointer(w.data, pointer)
panicError()
} | go | func (w *Window) SetUserPointer(pointer unsafe.Pointer) {
C.glfwSetWindowUserPointer(w.data, pointer)
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetUserPointer",
"(",
"pointer",
"unsafe",
".",
"Pointer",
")",
"{",
"C",
".",
"glfwSetWindowUserPointer",
"(",
"w",
".",
"data",
",",
"pointer",
")",
"\n",
"panicError",
"(",
")",
"\n",
"}"
] | // SetUserPointer sets the user-defined pointer of the window. The current value
// is retained until the window is destroyed. The initial value is nil. | [
"SetUserPointer",
"sets",
"the",
"user",
"-",
"defined",
"pointer",
"of",
"the",
"window",
".",
"The",
"current",
"value",
"is",
"retained",
"until",
"the",
"window",
"is",
"destroyed",
".",
"The",
"initial",
"value",
"is",
"nil",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L595-L598 | train |
go-gl/glfw | v3.2/glfw/window.go | GetUserPointer | func (w *Window) GetUserPointer() unsafe.Pointer {
ret := C.glfwGetWindowUserPointer(w.data)
panicError()
return ret
} | go | func (w *Window) GetUserPointer() unsafe.Pointer {
ret := C.glfwGetWindowUserPointer(w.data)
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetUserPointer",
"(",
")",
"unsafe",
".",
"Pointer",
"{",
"ret",
":=",
"C",
".",
"glfwGetWindowUserPointer",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetUserPointer returns the current value of the user-defined pointer of the
// window. The initial value is nil. | [
"GetUserPointer",
"returns",
"the",
"current",
"value",
"of",
"the",
"user",
"-",
"defined",
"pointer",
"of",
"the",
"window",
".",
"The",
"initial",
"value",
"is",
"nil",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L602-L606 | train |
go-gl/glfw | v3.2/glfw/window.go | SetPosCallback | func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback) {
previous = w.fPosHolder
w.fPosHolder = cbfun
if cbfun == nil {
C.glfwSetWindowPosCallback(w.data, nil)
} else {
C.glfwSetWindowPosCallbackCB(w.data)
}
panicError()
return previous
} | go | func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback) {
previous = w.fPosHolder
w.fPosHolder = cbfun
if cbfun == nil {
C.glfwSetWindowPosCallback(w.data, nil)
} else {
C.glfwSetWindowPosCallbackCB(w.data)
}
panicError()
return previous
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetPosCallback",
"(",
"cbfun",
"PosCallback",
")",
"(",
"previous",
"PosCallback",
")",
"{",
"previous",
"=",
"w",
".",
"fPosHolder",
"\n",
"w",
".",
"fPosHolder",
"=",
"cbfun",
"\n",
"if",
"cbfun",
"==",
"nil",
"... | // SetPosCallback sets the position callback of the window, which is called
// when the window is moved. The callback is provided with the screen position
// of the upper-left corner of the client area of the window. | [
"SetPosCallback",
"sets",
"the",
"position",
"callback",
"of",
"the",
"window",
"which",
"is",
"called",
"when",
"the",
"window",
"is",
"moved",
".",
"The",
"callback",
"is",
"provided",
"with",
"the",
"screen",
"position",
"of",
"the",
"upper",
"-",
"left",... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L614-L624 | train |
go-gl/glfw | v3.2/glfw/window.go | SetClipboardString | func (w *Window) SetClipboardString(str string) {
cp := C.CString(str)
defer C.free(unsafe.Pointer(cp))
C.glfwSetClipboardString(w.data, cp)
panicError()
} | go | func (w *Window) SetClipboardString(str string) {
cp := C.CString(str)
defer C.free(unsafe.Pointer(cp))
C.glfwSetClipboardString(w.data, cp)
panicError()
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"SetClipboardString",
"(",
"str",
"string",
")",
"{",
"cp",
":=",
"C",
".",
"CString",
"(",
"str",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"cp",
")",
")",
"\n",
"C",
".",
"... | // SetClipboardString sets the system clipboard to the specified UTF-8 encoded
// string.
//
// This function may only be called from the main thread. | [
"SetClipboardString",
"sets",
"the",
"system",
"clipboard",
"to",
"the",
"specified",
"UTF",
"-",
"8",
"encoded",
"string",
".",
"This",
"function",
"may",
"only",
"be",
"called",
"from",
"the",
"main",
"thread",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L749-L754 | train |
go-gl/glfw | v3.2/glfw/window.go | GetClipboardString | func (w *Window) GetClipboardString() (string, error) {
cs := C.glfwGetClipboardString(w.data)
if cs == nil {
return "", acceptError(FormatUnavailable)
}
return C.GoString(cs), nil
} | go | func (w *Window) GetClipboardString() (string, error) {
cs := C.glfwGetClipboardString(w.data)
if cs == nil {
return "", acceptError(FormatUnavailable)
}
return C.GoString(cs), nil
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetClipboardString",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"cs",
":=",
"C",
".",
"glfwGetClipboardString",
"(",
"w",
".",
"data",
")",
"\n",
"if",
"cs",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
... | // GetClipboardString returns the contents of the system clipboard, if it
// contains or is convertible to a UTF-8 encoded string.
//
// This function may only be called from the main thread. | [
"GetClipboardString",
"returns",
"the",
"contents",
"of",
"the",
"system",
"clipboard",
"if",
"it",
"contains",
"or",
"is",
"convertible",
"to",
"a",
"UTF",
"-",
"8",
"encoded",
"string",
".",
"This",
"function",
"may",
"only",
"be",
"called",
"from",
"the",... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/window.go#L760-L766 | train |
go-gl/glfw | v3.2/glfw/native_darwin.go | GetCocoaMonitor | func (m *Monitor) GetCocoaMonitor() uintptr {
ret := uintptr(C.glfwGetCocoaMonitor(m.data))
panicError()
return ret
} | go | func (m *Monitor) GetCocoaMonitor() uintptr {
ret := uintptr(C.glfwGetCocoaMonitor(m.data))
panicError()
return ret
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetCocoaMonitor",
"(",
")",
"uintptr",
"{",
"ret",
":=",
"uintptr",
"(",
"C",
".",
"glfwGetCocoaMonitor",
"(",
"m",
".",
"data",
")",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetCocoaMonitor returns the CGDirectDisplayID of the monitor. | [
"GetCocoaMonitor",
"returns",
"the",
"CGDirectDisplayID",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_darwin.go#L21-L25 | train |
go-gl/glfw | v3.2/glfw/native_darwin.go | GetCocoaWindow | func (w *Window) GetCocoaWindow() uintptr {
ret := uintptr(C.workaround_glfwGetCocoaWindow(w.data))
panicError()
return ret
} | go | func (w *Window) GetCocoaWindow() uintptr {
ret := uintptr(C.workaround_glfwGetCocoaWindow(w.data))
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetCocoaWindow",
"(",
")",
"uintptr",
"{",
"ret",
":=",
"uintptr",
"(",
"C",
".",
"workaround_glfwGetCocoaWindow",
"(",
"w",
".",
"data",
")",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetCocoaWindow returns the NSWindow of the window. | [
"GetCocoaWindow",
"returns",
"the",
"NSWindow",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_darwin.go#L28-L32 | train |
go-gl/glfw | v3.2/glfw/native_darwin.go | GetNSGLContext | func (w *Window) GetNSGLContext() uintptr {
ret := uintptr(C.workaround_glfwGetNSGLContext(w.data))
panicError()
return ret
} | go | func (w *Window) GetNSGLContext() uintptr {
ret := uintptr(C.workaround_glfwGetNSGLContext(w.data))
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetNSGLContext",
"(",
")",
"uintptr",
"{",
"ret",
":=",
"uintptr",
"(",
"C",
".",
"workaround_glfwGetNSGLContext",
"(",
"w",
".",
"data",
")",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetNSGLContext returns the NSOpenGLContext of the window. | [
"GetNSGLContext",
"returns",
"the",
"NSOpenGLContext",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_darwin.go#L35-L39 | train |
go-gl/glfw | v3.2/glfw/native_linbsd.go | GetX11Adapter | func (m *Monitor) GetX11Adapter() C.RRCrtc {
ret := C.glfwGetX11Adapter(m.data)
panicError()
return ret
} | go | func (m *Monitor) GetX11Adapter() C.RRCrtc {
ret := C.glfwGetX11Adapter(m.data)
panicError()
return ret
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetX11Adapter",
"(",
")",
"C",
".",
"RRCrtc",
"{",
"ret",
":=",
"C",
".",
"glfwGetX11Adapter",
"(",
"m",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetX11Adapter returns the RRCrtc of the monitor. | [
"GetX11Adapter",
"returns",
"the",
"RRCrtc",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_linbsd.go#L19-L23 | train |
go-gl/glfw | v3.2/glfw/native_linbsd.go | GetX11Monitor | func (m *Monitor) GetX11Monitor() C.RROutput {
ret := C.glfwGetX11Monitor(m.data)
panicError()
return ret
} | go | func (m *Monitor) GetX11Monitor() C.RROutput {
ret := C.glfwGetX11Monitor(m.data)
panicError()
return ret
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetX11Monitor",
"(",
")",
"C",
".",
"RROutput",
"{",
"ret",
":=",
"C",
".",
"glfwGetX11Monitor",
"(",
"m",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetX11Monitor returns the RROutput of the monitor. | [
"GetX11Monitor",
"returns",
"the",
"RROutput",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_linbsd.go#L26-L30 | train |
go-gl/glfw | v3.2/glfw/native_linbsd.go | GetX11Window | func (w *Window) GetX11Window() C.Window {
ret := C.glfwGetX11Window(w.data)
panicError()
return ret
} | go | func (w *Window) GetX11Window() C.Window {
ret := C.glfwGetX11Window(w.data)
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetX11Window",
"(",
")",
"C",
".",
"Window",
"{",
"ret",
":=",
"C",
".",
"glfwGetX11Window",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetX11Window returns the Window of the window. | [
"GetX11Window",
"returns",
"the",
"Window",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_linbsd.go#L33-L37 | train |
go-gl/glfw | v3.2/glfw/native_linbsd.go | GetGLXContext | func (w *Window) GetGLXContext() C.GLXContext {
ret := C.glfwGetGLXContext(w.data)
panicError()
return ret
} | go | func (w *Window) GetGLXContext() C.GLXContext {
ret := C.glfwGetGLXContext(w.data)
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetGLXContext",
"(",
")",
"C",
".",
"GLXContext",
"{",
"ret",
":=",
"C",
".",
"glfwGetGLXContext",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetGLXContext returns the GLXContext of the window. | [
"GetGLXContext",
"returns",
"the",
"GLXContext",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_linbsd.go#L40-L44 | train |
go-gl/glfw | v3.2/glfw/native_linbsd.go | GetGLXWindow | func (w *Window) GetGLXWindow() C.GLXWindow {
ret := C.glfwGetGLXWindow(w.data)
panicError()
return ret
} | go | func (w *Window) GetGLXWindow() C.GLXWindow {
ret := C.glfwGetGLXWindow(w.data)
panicError()
return ret
} | [
"func",
"(",
"w",
"*",
"Window",
")",
"GetGLXWindow",
"(",
")",
"C",
".",
"GLXWindow",
"{",
"ret",
":=",
"C",
".",
"glfwGetGLXWindow",
"(",
"w",
".",
"data",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"ret",
"\n",
"}"
] | // GetGLXWindow returns the GLXWindow of the window. | [
"GetGLXWindow",
"returns",
"the",
"GLXWindow",
"of",
"the",
"window",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/native_linbsd.go#L47-L51 | train |
go-gl/glfw | v3.0/glfw/error.go | SetErrorCallback | func SetErrorCallback(cbfun func(code ErrorCode, desc string)) {
if cbfun == nil {
C.glfwSetErrorCallback(nil)
} else {
fErrorHolder = cbfun
C.glfwSetErrorCallbackCB()
}
} | go | func SetErrorCallback(cbfun func(code ErrorCode, desc string)) {
if cbfun == nil {
C.glfwSetErrorCallback(nil)
} else {
fErrorHolder = cbfun
C.glfwSetErrorCallbackCB()
}
} | [
"func",
"SetErrorCallback",
"(",
"cbfun",
"func",
"(",
"code",
"ErrorCode",
",",
"desc",
"string",
")",
")",
"{",
"if",
"cbfun",
"==",
"nil",
"{",
"C",
".",
"glfwSetErrorCallback",
"(",
"nil",
")",
"\n",
"}",
"else",
"{",
"fErrorHolder",
"=",
"cbfun",
... | //SetErrorCallback sets the error callback, which is called with an error code
//and a human-readable description each time a GLFW error occurs.
//
//This function may be called before Init. | [
"SetErrorCallback",
"sets",
"the",
"error",
"callback",
"which",
"is",
"called",
"with",
"an",
"error",
"code",
"and",
"a",
"human",
"-",
"readable",
"description",
"each",
"time",
"a",
"GLFW",
"error",
"occurs",
".",
"This",
"function",
"may",
"be",
"called... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.0/glfw/error.go#L35-L42 | train |
go-gl/glfw | v3.2/glfw/context.go | ExtensionSupported | func ExtensionSupported(extension string) bool {
e := C.CString(extension)
defer C.free(unsafe.Pointer(e))
ret := glfwbool(C.glfwExtensionSupported(e))
panicError()
return ret
} | go | func ExtensionSupported(extension string) bool {
e := C.CString(extension)
defer C.free(unsafe.Pointer(e))
ret := glfwbool(C.glfwExtensionSupported(e))
panicError()
return ret
} | [
"func",
"ExtensionSupported",
"(",
"extension",
"string",
")",
"bool",
"{",
"e",
":=",
"C",
".",
"CString",
"(",
"extension",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"e",
")",
")",
"\n",
"ret",
":=",
"glfwbool",
"(",... | // ExtensionSupported reports whether the specified OpenGL or context creation
// API extension is supported by the current context. For example, on Windows
// both the OpenGL and WGL extension strings are checked.
//
// As this functions searches one or more extension strings on each call, it is
// recommended that you cache its results if it's going to be used frequently.
// The extension strings will not change during the lifetime of a context, so
// there is no danger in doing this. | [
"ExtensionSupported",
"reports",
"whether",
"the",
"specified",
"OpenGL",
"or",
"context",
"creation",
"API",
"extension",
"is",
"supported",
"by",
"the",
"current",
"context",
".",
"For",
"example",
"on",
"Windows",
"both",
"the",
"OpenGL",
"and",
"WGL",
"exten... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/context.go#L72-L78 | train |
go-gl/glfw | v3.2/glfw/context.go | GetProcAddress | func GetProcAddress(procname string) unsafe.Pointer {
p := C.CString(procname)
defer C.free(unsafe.Pointer(p))
ret := unsafe.Pointer(C.glfwGetProcAddress(p))
panicError()
return ret
} | go | func GetProcAddress(procname string) unsafe.Pointer {
p := C.CString(procname)
defer C.free(unsafe.Pointer(p))
ret := unsafe.Pointer(C.glfwGetProcAddress(p))
panicError()
return ret
} | [
"func",
"GetProcAddress",
"(",
"procname",
"string",
")",
"unsafe",
".",
"Pointer",
"{",
"p",
":=",
"C",
".",
"CString",
"(",
"procname",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
"\n",
"ret",
":=",
"u... | // GetProcAddress returns the address of the specified OpenGL or OpenGL ES core
// or extension function, if it is supported by the current context.
//
// A context must be current on the calling thread. Calling this function
// without a current context will cause a GLFW_NO_CURRENT_CONTEXT error.
//
// This function is used to provide GL proc resolving capabilities to an
// external C library. | [
"GetProcAddress",
"returns",
"the",
"address",
"of",
"the",
"specified",
"OpenGL",
"or",
"OpenGL",
"ES",
"core",
"or",
"extension",
"function",
"if",
"it",
"is",
"supported",
"by",
"the",
"current",
"context",
".",
"A",
"context",
"must",
"be",
"current",
"o... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/context.go#L88-L94 | train |
go-gl/glfw | v3.1/glfw/input.go | CreateCursor | func CreateCursor(img image.Image, xhot, yhot int) *Cursor {
var img_c C.GLFWimage
var pixels []uint8
b := img.Bounds()
switch img := img.(type) {
case *image.RGBA:
pixels = img.Pix
default:
m := image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
draw.Draw(m, m.Bounds(), img, b.Min, draw.Src)
pixels = m.Pix
}
pix, free := bytes(pixels)
img_c.width = C.int(b.Dx())
img_c.height = C.int(b.Dy())
img_c.pixels = (*C.uchar)(pix)
c := C.glfwCreateCursor(&img_c, C.int(xhot), C.int(yhot))
free()
panicError()
return &Cursor{c}
} | go | func CreateCursor(img image.Image, xhot, yhot int) *Cursor {
var img_c C.GLFWimage
var pixels []uint8
b := img.Bounds()
switch img := img.(type) {
case *image.RGBA:
pixels = img.Pix
default:
m := image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
draw.Draw(m, m.Bounds(), img, b.Min, draw.Src)
pixels = m.Pix
}
pix, free := bytes(pixels)
img_c.width = C.int(b.Dx())
img_c.height = C.int(b.Dy())
img_c.pixels = (*C.uchar)(pix)
c := C.glfwCreateCursor(&img_c, C.int(xhot), C.int(yhot))
free()
panicError()
return &Cursor{c}
} | [
"func",
"CreateCursor",
"(",
"img",
"image",
".",
"Image",
",",
"xhot",
",",
"yhot",
"int",
")",
"*",
"Cursor",
"{",
"var",
"img_c",
"C",
".",
"GLFWimage",
"\n",
"var",
"pixels",
"[",
"]",
"uint8",
"\n",
"b",
":=",
"img",
".",
"Bounds",
"(",
")",
... | // Creates a new custom cursor image that can be set for a window with SetCursor.
// The cursor can be destroyed with Destroy. Any remaining cursors are destroyed by Terminate.
//
// The pixels are 32-bit little-endian RGBA, i.e. eight bits per channel. They are arranged
// canonically as packed sequential rows, starting from the top-left corner.
//
// All non-RGBA images will be converted to RGBA.
//
// The cursor hotspot is specified in pixels, relative to the upper-left corner of the cursor image.
// Like all other coordinate systems in GLFW, the X-axis points to the right and the Y-axis points down. | [
"Creates",
"a",
"new",
"custom",
"cursor",
"image",
"that",
"can",
"be",
"set",
"for",
"a",
"window",
"with",
"SetCursor",
".",
"The",
"cursor",
"can",
"be",
"destroyed",
"with",
"Destroy",
".",
"Any",
"remaining",
"cursors",
"are",
"destroyed",
"by",
"Ter... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.1/glfw/input.go#L383-L409 | train |
go-gl/glfw | v3.1/glfw/input.go | CreateStandardCursor | func CreateStandardCursor(shape int) *Cursor {
c := C.glfwCreateStandardCursor(C.int(shape))
panicError()
return &Cursor{c}
} | go | func CreateStandardCursor(shape int) *Cursor {
c := C.glfwCreateStandardCursor(C.int(shape))
panicError()
return &Cursor{c}
} | [
"func",
"CreateStandardCursor",
"(",
"shape",
"int",
")",
"*",
"Cursor",
"{",
"c",
":=",
"C",
".",
"glfwCreateStandardCursor",
"(",
"C",
".",
"int",
"(",
"shape",
")",
")",
"\n",
"panicError",
"(",
")",
"\n",
"return",
"&",
"Cursor",
"{",
"c",
"}",
"... | // Returns a cursor with a standard shape, that can be set for a window with SetCursor. | [
"Returns",
"a",
"cursor",
"with",
"a",
"standard",
"shape",
"that",
"can",
"be",
"set",
"for",
"a",
"window",
"with",
"SetCursor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.1/glfw/input.go#L412-L416 | train |
go-gl/glfw | v3.2/glfw/monitor.go | GetPos | func (m *Monitor) GetPos() (x, y int) {
var xpos, ypos C.int
C.glfwGetMonitorPos(m.data, &xpos, &ypos)
panicError()
return int(xpos), int(ypos)
} | go | func (m *Monitor) GetPos() (x, y int) {
var xpos, ypos C.int
C.glfwGetMonitorPos(m.data, &xpos, &ypos)
panicError()
return int(xpos), int(ypos)
} | [
"func",
"(",
"m",
"*",
"Monitor",
")",
"GetPos",
"(",
")",
"(",
"x",
",",
"y",
"int",
")",
"{",
"var",
"xpos",
",",
"ypos",
"C",
".",
"int",
"\n",
"C",
".",
"glfwGetMonitorPos",
"(",
"m",
".",
"data",
",",
"&",
"xpos",
",",
"&",
"ypos",
")",
... | // GetPos returns the position, in screen coordinates, of the upper-left
// corner of the monitor. | [
"GetPos",
"returns",
"the",
"position",
"in",
"screen",
"coordinates",
"of",
"the",
"upper",
"-",
"left",
"corner",
"of",
"the",
"monitor",
"."
] | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/monitor.go#L86-L91 | train |
go-gl/glfw | v3.2/glfw/monitor.go | SetMonitorCallback | func SetMonitorCallback(cbfun func(monitor *Monitor, event MonitorEvent)) {
if cbfun == nil {
C.glfwSetMonitorCallback(nil)
} else {
fMonitorHolder = cbfun
C.glfwSetMonitorCallbackCB()
}
panicError()
} | go | func SetMonitorCallback(cbfun func(monitor *Monitor, event MonitorEvent)) {
if cbfun == nil {
C.glfwSetMonitorCallback(nil)
} else {
fMonitorHolder = cbfun
C.glfwSetMonitorCallbackCB()
}
panicError()
} | [
"func",
"SetMonitorCallback",
"(",
"cbfun",
"func",
"(",
"monitor",
"*",
"Monitor",
",",
"event",
"MonitorEvent",
")",
")",
"{",
"if",
"cbfun",
"==",
"nil",
"{",
"C",
".",
"glfwSetMonitorCallback",
"(",
"nil",
")",
"\n",
"}",
"else",
"{",
"fMonitorHolder",... | // SetMonitorCallback sets the monitor configuration callback, or removes the
// currently set callback. This is called when a monitor is connected to or
// disconnected from the system. | [
"SetMonitorCallback",
"sets",
"the",
"monitor",
"configuration",
"callback",
"or",
"removes",
"the",
"currently",
"set",
"callback",
".",
"This",
"is",
"called",
"when",
"a",
"monitor",
"is",
"connected",
"to",
"or",
"disconnected",
"from",
"the",
"system",
"."
... | e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc | https://github.com/go-gl/glfw/blob/e6da0acd62b1b57ee2799d4d0a76a7d4514dc5bc/v3.2/glfw/monitor.go#L119-L127 | train |
karrick/godirwalk | dirent.go | NewDirent | func NewDirent(osPathname string) (*Dirent, error) {
fi, err := os.Lstat(osPathname)
if err != nil {
return nil, err
}
return &Dirent{
name: filepath.Base(osPathname),
modeType: fi.Mode() & os.ModeType,
}, nil
} | go | func NewDirent(osPathname string) (*Dirent, error) {
fi, err := os.Lstat(osPathname)
if err != nil {
return nil, err
}
return &Dirent{
name: filepath.Base(osPathname),
modeType: fi.Mode() & os.ModeType,
}, nil
} | [
"func",
"NewDirent",
"(",
"osPathname",
"string",
")",
"(",
"*",
"Dirent",
",",
"error",
")",
"{",
"fi",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"osPathname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\... | // NewDirent returns a newly initialized Dirent structure, or an error. This
// function does not follow symbolic links.
//
// This function is rarely used, as Dirent structures are provided by other
// functions in this library that read and walk directories. | [
"NewDirent",
"returns",
"a",
"newly",
"initialized",
"Dirent",
"structure",
"or",
"an",
"error",
".",
"This",
"function",
"does",
"not",
"follow",
"symbolic",
"links",
".",
"This",
"function",
"is",
"rarely",
"used",
"as",
"Dirent",
"structures",
"are",
"provi... | 808a2f88690f523a3fb074bc6626124660bc80eb | https://github.com/karrick/godirwalk/blob/808a2f88690f523a3fb074bc6626124660bc80eb/dirent.go#L20-L29 | train |
karrick/godirwalk | readdir_windows.go | readdirents | func readdirents(osDirname string, _ []byte) (Dirents, error) {
dh, err := os.Open(osDirname)
if err != nil {
return nil, err
}
fileinfos, err := dh.Readdir(0)
if er := dh.Close(); err == nil {
err = er
}
if err != nil {
return nil, err
}
entries := make(Dirents, len(fileinfos))
for i, info := range fileinfos {
entries[i] = &Dirent{name: info.Name(), modeType: info.Mode() & os.ModeType}
}
return entries, nil
} | go | func readdirents(osDirname string, _ []byte) (Dirents, error) {
dh, err := os.Open(osDirname)
if err != nil {
return nil, err
}
fileinfos, err := dh.Readdir(0)
if er := dh.Close(); err == nil {
err = er
}
if err != nil {
return nil, err
}
entries := make(Dirents, len(fileinfos))
for i, info := range fileinfos {
entries[i] = &Dirent{name: info.Name(), modeType: info.Mode() & os.ModeType}
}
return entries, nil
} | [
"func",
"readdirents",
"(",
"osDirname",
"string",
",",
"_",
"[",
"]",
"byte",
")",
"(",
"Dirents",
",",
"error",
")",
"{",
"dh",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"osDirname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",... | // The functions in this file are mere wrappers of what is already provided by
// standard library, in order to provide the same API as this library provides.
//
// The scratch buffer argument is ignored by this architecture.
//
// Please send PR or link to article if you know of a more performant way of
// enumerating directory contents and mode types on Windows. | [
"The",
"functions",
"in",
"this",
"file",
"are",
"mere",
"wrappers",
"of",
"what",
"is",
"already",
"provided",
"by",
"standard",
"library",
"in",
"order",
"to",
"provide",
"the",
"same",
"API",
"as",
"this",
"library",
"provides",
".",
"The",
"scratch",
"... | 808a2f88690f523a3fb074bc6626124660bc80eb | https://github.com/karrick/godirwalk/blob/808a2f88690f523a3fb074bc6626124660bc80eb/readdir_windows.go#L15-L35 | train |
karrick/godirwalk | walk.go | walk | func walk(osPathname string, dirent *Dirent, options *Options) error {
err := options.Callback(osPathname, dirent)
if err != nil {
if err == filepath.SkipDir {
return err
}
err = errCallback(err.Error()) // wrap potential errors returned by callback
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}
// On some platforms, an entry can have more than one mode type bit set.
// For instance, it could have both the symlink bit and the directory bit
// set indicating it's a symlink to a directory.
if dirent.IsSymlink() {
if !options.FollowSymbolicLinks {
return nil
}
skip, err := symlinkDirHelper(osPathname, dirent, options)
if err != nil || skip {
return err
}
}
if !dirent.IsDir() {
return nil
}
// If get here, then specified pathname refers to a directory.
deChildren, err := ReadDirents(osPathname, options.ScratchBuffer)
if err != nil {
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}
if !options.Unsorted {
sort.Sort(deChildren) // sort children entries unless upstream says to leave unsorted
}
for _, deChild := range deChildren {
osChildname := filepath.Join(osPathname, deChild.name)
err = walk(osChildname, deChild, options)
if err != nil {
if err != filepath.SkipDir {
return err
}
// If received skipdir on a directory, stop processing that
// directory, but continue to its siblings. If received skipdir on a
// non-directory, stop processing remaining siblings.
if deChild.IsSymlink() {
var skip bool
if skip, err = symlinkDirHelper(osChildname, deChild, options); err != nil {
return err
}
if skip {
continue
}
}
if !deChild.IsDir() {
// If not directory, return immediately, thus skipping remainder
// of siblings.
return nil
}
}
}
if options.PostChildrenCallback == nil {
return nil
}
err = options.PostChildrenCallback(osPathname, dirent)
if err == nil || err == filepath.SkipDir {
return err
}
err = errCallback(err.Error()) // wrap potential errors returned by callback
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
} | go | func walk(osPathname string, dirent *Dirent, options *Options) error {
err := options.Callback(osPathname, dirent)
if err != nil {
if err == filepath.SkipDir {
return err
}
err = errCallback(err.Error()) // wrap potential errors returned by callback
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}
// On some platforms, an entry can have more than one mode type bit set.
// For instance, it could have both the symlink bit and the directory bit
// set indicating it's a symlink to a directory.
if dirent.IsSymlink() {
if !options.FollowSymbolicLinks {
return nil
}
skip, err := symlinkDirHelper(osPathname, dirent, options)
if err != nil || skip {
return err
}
}
if !dirent.IsDir() {
return nil
}
// If get here, then specified pathname refers to a directory.
deChildren, err := ReadDirents(osPathname, options.ScratchBuffer)
if err != nil {
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
}
if !options.Unsorted {
sort.Sort(deChildren) // sort children entries unless upstream says to leave unsorted
}
for _, deChild := range deChildren {
osChildname := filepath.Join(osPathname, deChild.name)
err = walk(osChildname, deChild, options)
if err != nil {
if err != filepath.SkipDir {
return err
}
// If received skipdir on a directory, stop processing that
// directory, but continue to its siblings. If received skipdir on a
// non-directory, stop processing remaining siblings.
if deChild.IsSymlink() {
var skip bool
if skip, err = symlinkDirHelper(osChildname, deChild, options); err != nil {
return err
}
if skip {
continue
}
}
if !deChild.IsDir() {
// If not directory, return immediately, thus skipping remainder
// of siblings.
return nil
}
}
}
if options.PostChildrenCallback == nil {
return nil
}
err = options.PostChildrenCallback(osPathname, dirent)
if err == nil || err == filepath.SkipDir {
return err
}
err = errCallback(err.Error()) // wrap potential errors returned by callback
if action := options.ErrorCallback(osPathname, err); action == SkipNode {
return nil
}
return err
} | [
"func",
"walk",
"(",
"osPathname",
"string",
",",
"dirent",
"*",
"Dirent",
",",
"options",
"*",
"Options",
")",
"error",
"{",
"err",
":=",
"options",
".",
"Callback",
"(",
"osPathname",
",",
"dirent",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"... | // walk recursively traverses the file system node specified by pathname and the
// Dirent. | [
"walk",
"recursively",
"traverses",
"the",
"file",
"system",
"node",
"specified",
"by",
"pathname",
"and",
"the",
"Dirent",
"."
] | 808a2f88690f523a3fb074bc6626124660bc80eb | https://github.com/karrick/godirwalk/blob/808a2f88690f523a3fb074bc6626124660bc80eb/walk.go#L229-L313 | train |
paulmach/orb | clip/helpers.go | Geometry | func Geometry(b orb.Bound, g orb.Geometry) orb.Geometry {
if g == nil {
return nil
}
if !b.Intersects(g.Bound()) {
return nil
}
switch g := g.(type) {
case orb.Point:
return g // Intersect check above
case orb.MultiPoint:
mp := MultiPoint(b, g)
if len(mp) == 1 {
return mp[0]
}
if mp == nil {
return nil
}
return mp
case orb.LineString:
mls := LineString(b, g)
if len(mls) == 1 {
return mls[0]
}
if len(mls) == 0 {
return nil
}
return mls
case orb.MultiLineString:
mls := MultiLineString(b, g)
if len(mls) == 1 {
return mls[0]
}
if mls == nil {
return nil
}
return mls
case orb.Ring:
r := Ring(b, g)
if r == nil {
return nil
}
return r
case orb.Polygon:
p := Polygon(b, g)
if p == nil {
return nil
}
return p
case orb.MultiPolygon:
mp := MultiPolygon(b, g)
if len(mp) == 1 {
return mp[0]
}
if mp == nil {
return nil
}
return mp
case orb.Collection:
c := Collection(b, g)
if len(c) == 1 {
return c[0]
}
if c == nil {
return nil
}
return c
case orb.Bound:
b = Bound(b, g)
if b.IsEmpty() {
return nil
}
return b
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | go | func Geometry(b orb.Bound, g orb.Geometry) orb.Geometry {
if g == nil {
return nil
}
if !b.Intersects(g.Bound()) {
return nil
}
switch g := g.(type) {
case orb.Point:
return g // Intersect check above
case orb.MultiPoint:
mp := MultiPoint(b, g)
if len(mp) == 1 {
return mp[0]
}
if mp == nil {
return nil
}
return mp
case orb.LineString:
mls := LineString(b, g)
if len(mls) == 1 {
return mls[0]
}
if len(mls) == 0 {
return nil
}
return mls
case orb.MultiLineString:
mls := MultiLineString(b, g)
if len(mls) == 1 {
return mls[0]
}
if mls == nil {
return nil
}
return mls
case orb.Ring:
r := Ring(b, g)
if r == nil {
return nil
}
return r
case orb.Polygon:
p := Polygon(b, g)
if p == nil {
return nil
}
return p
case orb.MultiPolygon:
mp := MultiPolygon(b, g)
if len(mp) == 1 {
return mp[0]
}
if mp == nil {
return nil
}
return mp
case orb.Collection:
c := Collection(b, g)
if len(c) == 1 {
return c[0]
}
if c == nil {
return nil
}
return c
case orb.Bound:
b = Bound(b, g)
if b.IsEmpty() {
return nil
}
return b
}
panic(fmt.Sprintf("geometry type not supported: %T", g))
} | [
"func",
"Geometry",
"(",
"b",
"orb",
".",
"Bound",
",",
"g",
"orb",
".",
"Geometry",
")",
"orb",
".",
"Geometry",
"{",
"if",
"g",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"!",
"b",
".",
"Intersects",
"(",
"g",
".",
"Bound",
"... | // Geometry will clip the geometry to the bounding box using the
// correct functions for the type.
// This operation will modify the input of '1d or 2d geometry' by using as a
// scratch space so clone if necessary. | [
"Geometry",
"will",
"clip",
"the",
"geometry",
"to",
"the",
"bounding",
"box",
"using",
"the",
"correct",
"functions",
"for",
"the",
"type",
".",
"This",
"operation",
"will",
"modify",
"the",
"input",
"of",
"1d",
"or",
"2d",
"geometry",
"by",
"using",
"as"... | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L15-L105 | train |
paulmach/orb | clip/helpers.go | MultiPoint | func MultiPoint(b orb.Bound, mp orb.MultiPoint) orb.MultiPoint {
var result orb.MultiPoint
for _, p := range mp {
if b.Contains(p) {
result = append(result, p)
}
}
return result
} | go | func MultiPoint(b orb.Bound, mp orb.MultiPoint) orb.MultiPoint {
var result orb.MultiPoint
for _, p := range mp {
if b.Contains(p) {
result = append(result, p)
}
}
return result
} | [
"func",
"MultiPoint",
"(",
"b",
"orb",
".",
"Bound",
",",
"mp",
"orb",
".",
"MultiPoint",
")",
"orb",
".",
"MultiPoint",
"{",
"var",
"result",
"orb",
".",
"MultiPoint",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"mp",
"{",
"if",
"b",
".",
"Contains... | // MultiPoint returns a new set with the points outside the bound removed. | [
"MultiPoint",
"returns",
"a",
"new",
"set",
"with",
"the",
"points",
"outside",
"the",
"bound",
"removed",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L108-L117 | train |
paulmach/orb | clip/helpers.go | LineString | func LineString(b orb.Bound, ls orb.LineString, opts ...Option) orb.MultiLineString {
open := false
if len(opts) > 0 {
o := &options{}
for _, opt := range opts {
opt(o)
}
open = o.openBound
}
result := line(b, ls, open)
if len(result) == 0 {
return nil
}
return result
} | go | func LineString(b orb.Bound, ls orb.LineString, opts ...Option) orb.MultiLineString {
open := false
if len(opts) > 0 {
o := &options{}
for _, opt := range opts {
opt(o)
}
open = o.openBound
}
result := line(b, ls, open)
if len(result) == 0 {
return nil
}
return result
} | [
"func",
"LineString",
"(",
"b",
"orb",
".",
"Bound",
",",
"ls",
"orb",
".",
"LineString",
",",
"opts",
"...",
"Option",
")",
"orb",
".",
"MultiLineString",
"{",
"open",
":=",
"false",
"\n",
"if",
"len",
"(",
"opts",
")",
">",
"0",
"{",
"o",
":=",
... | // LineString clips the linestring to the bounding box. | [
"LineString",
"clips",
"the",
"linestring",
"to",
"the",
"bounding",
"box",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L120-L137 | train |
paulmach/orb | clip/helpers.go | MultiLineString | func MultiLineString(b orb.Bound, mls orb.MultiLineString, opts ...Option) orb.MultiLineString {
open := false
if len(opts) > 0 {
o := &options{}
for _, opt := range opts {
opt(o)
}
open = o.openBound
}
var result orb.MultiLineString
for _, ls := range mls {
r := line(b, ls, open)
if len(r) != 0 {
result = append(result, r...)
}
}
return result
} | go | func MultiLineString(b orb.Bound, mls orb.MultiLineString, opts ...Option) orb.MultiLineString {
open := false
if len(opts) > 0 {
o := &options{}
for _, opt := range opts {
opt(o)
}
open = o.openBound
}
var result orb.MultiLineString
for _, ls := range mls {
r := line(b, ls, open)
if len(r) != 0 {
result = append(result, r...)
}
}
return result
} | [
"func",
"MultiLineString",
"(",
"b",
"orb",
".",
"Bound",
",",
"mls",
"orb",
".",
"MultiLineString",
",",
"opts",
"...",
"Option",
")",
"orb",
".",
"MultiLineString",
"{",
"open",
":=",
"false",
"\n",
"if",
"len",
"(",
"opts",
")",
">",
"0",
"{",
"o"... | // MultiLineString clips the linestrings to the bounding box
// and returns a linestring union. | [
"MultiLineString",
"clips",
"the",
"linestrings",
"to",
"the",
"bounding",
"box",
"and",
"returns",
"a",
"linestring",
"union",
"."
] | c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29 | https://github.com/paulmach/orb/blob/c6e407b203494d3b1edb9fd5cae4cf34a4ae0f29/clip/helpers.go#L141-L160 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.