id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
150,800 | godbus/dbus | prop/prop.go | SetMust | func (p *Properties) SetMust(iface, property string, v interface{}) {
p.mut.Lock()
defer p.mut.Unlock() // unlock in case of panic
if err := p.set(iface, property, v); err != nil {
panic(err)
}
} | go | func (p *Properties) SetMust(iface, property string, v interface{}) {
p.mut.Lock()
defer p.mut.Unlock() // unlock in case of panic
if err := p.set(iface, property, v); err != nil {
panic(err)
}
} | [
"func",
"(",
"p",
"*",
"Properties",
")",
"SetMust",
"(",
"iface",
",",
"property",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"{",
"p",
".",
"mut",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"mut",
".",
"Unlock",
"(",
")",
"// unlock in case of panic",
"\n",
"if",
"err",
":=",
"p",
".",
"set",
"(",
"iface",
",",
"property",
",",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // SetMust sets the value of the given property and panics if the interface or
// the property name are invalid. | [
"SetMust",
"sets",
"the",
"value",
"of",
"the",
"given",
"property",
"and",
"panics",
"if",
"the",
"interface",
"or",
"the",
"property",
"name",
"are",
"invalid",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L279-L285 |
150,801 | godbus/dbus | introspect/call.go | Call | func Call(o dbus.BusObject) (*Node, error) {
var xmldata string
var node Node
err := o.Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xmldata)
if err != nil {
return nil, err
}
err = xml.NewDecoder(strings.NewReader(xmldata)).Decode(&node)
if err != nil {
return nil, err
}
if node.Name == "" {
node.Name = string(o.Path())
}
return &node, nil
} | go | func Call(o dbus.BusObject) (*Node, error) {
var xmldata string
var node Node
err := o.Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xmldata)
if err != nil {
return nil, err
}
err = xml.NewDecoder(strings.NewReader(xmldata)).Decode(&node)
if err != nil {
return nil, err
}
if node.Name == "" {
node.Name = string(o.Path())
}
return &node, nil
} | [
"func",
"Call",
"(",
"o",
"dbus",
".",
"BusObject",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"var",
"xmldata",
"string",
"\n",
"var",
"node",
"Node",
"\n\n",
"err",
":=",
"o",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
")",
".",
"Store",
"(",
"&",
"xmldata",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"xml",
".",
"NewDecoder",
"(",
"strings",
".",
"NewReader",
"(",
"xmldata",
")",
")",
".",
"Decode",
"(",
"&",
"node",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"node",
".",
"Name",
"==",
"\"",
"\"",
"{",
"node",
".",
"Name",
"=",
"string",
"(",
"o",
".",
"Path",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"&",
"node",
",",
"nil",
"\n",
"}"
] | // Call calls org.freedesktop.Introspectable.Introspect on a remote object
// and returns the introspection data. | [
"Call",
"calls",
"org",
".",
"freedesktop",
".",
"Introspectable",
".",
"Introspect",
"on",
"a",
"remote",
"object",
"and",
"returns",
"the",
"introspection",
"data",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/introspect/call.go#L11-L27 |
150,802 | godbus/dbus | encoder.go | newEncoder | func newEncoder(out io.Writer, order binary.ByteOrder) *encoder {
return newEncoderAtOffset(out, 0, order)
} | go | func newEncoder(out io.Writer, order binary.ByteOrder) *encoder {
return newEncoderAtOffset(out, 0, order)
} | [
"func",
"newEncoder",
"(",
"out",
"io",
".",
"Writer",
",",
"order",
"binary",
".",
"ByteOrder",
")",
"*",
"encoder",
"{",
"return",
"newEncoderAtOffset",
"(",
"out",
",",
"0",
",",
"order",
")",
"\n",
"}"
] | // NewEncoder returns a new encoder that writes to out in the given byte order. | [
"NewEncoder",
"returns",
"a",
"new",
"encoder",
"that",
"writes",
"to",
"out",
"in",
"the",
"given",
"byte",
"order",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/encoder.go#L18-L20 |
150,803 | godbus/dbus | encoder.go | newEncoderAtOffset | func newEncoderAtOffset(out io.Writer, offset int, order binary.ByteOrder) *encoder {
enc := new(encoder)
enc.out = out
enc.order = order
enc.pos = offset
return enc
} | go | func newEncoderAtOffset(out io.Writer, offset int, order binary.ByteOrder) *encoder {
enc := new(encoder)
enc.out = out
enc.order = order
enc.pos = offset
return enc
} | [
"func",
"newEncoderAtOffset",
"(",
"out",
"io",
".",
"Writer",
",",
"offset",
"int",
",",
"order",
"binary",
".",
"ByteOrder",
")",
"*",
"encoder",
"{",
"enc",
":=",
"new",
"(",
"encoder",
")",
"\n",
"enc",
".",
"out",
"=",
"out",
"\n",
"enc",
".",
"order",
"=",
"order",
"\n",
"enc",
".",
"pos",
"=",
"offset",
"\n",
"return",
"enc",
"\n",
"}"
] | // newEncoderAtOffset returns a new encoder that writes to out in the given
// byte order. Specify the offset to initialize pos for proper alignment
// computation. | [
"newEncoderAtOffset",
"returns",
"a",
"new",
"encoder",
"that",
"writes",
"to",
"out",
"in",
"the",
"given",
"byte",
"order",
".",
"Specify",
"the",
"offset",
"to",
"initialize",
"pos",
"for",
"proper",
"alignment",
"computation",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/encoder.go#L25-L31 |
150,804 | godbus/dbus | encoder.go | align | func (enc *encoder) align(n int) {
pad := enc.padding(0, n)
if pad > 0 {
empty := make([]byte, pad)
if _, err := enc.out.Write(empty); err != nil {
panic(err)
}
enc.pos += pad
}
} | go | func (enc *encoder) align(n int) {
pad := enc.padding(0, n)
if pad > 0 {
empty := make([]byte, pad)
if _, err := enc.out.Write(empty); err != nil {
panic(err)
}
enc.pos += pad
}
} | [
"func",
"(",
"enc",
"*",
"encoder",
")",
"align",
"(",
"n",
"int",
")",
"{",
"pad",
":=",
"enc",
".",
"padding",
"(",
"0",
",",
"n",
")",
"\n",
"if",
"pad",
">",
"0",
"{",
"empty",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"pad",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"enc",
".",
"out",
".",
"Write",
"(",
"empty",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"enc",
".",
"pos",
"+=",
"pad",
"\n",
"}",
"\n",
"}"
] | // Aligns the next output to be on a multiple of n. Panics on write errors. | [
"Aligns",
"the",
"next",
"output",
"to",
"be",
"on",
"a",
"multiple",
"of",
"n",
".",
"Panics",
"on",
"write",
"errors",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/encoder.go#L34-L43 |
150,805 | godbus/dbus | encoder.go | padding | func (enc *encoder) padding(offset, algn int) int {
abs := enc.pos + offset
if abs%algn != 0 {
newabs := (abs + algn - 1) & ^(algn - 1)
return newabs - abs
}
return 0
} | go | func (enc *encoder) padding(offset, algn int) int {
abs := enc.pos + offset
if abs%algn != 0 {
newabs := (abs + algn - 1) & ^(algn - 1)
return newabs - abs
}
return 0
} | [
"func",
"(",
"enc",
"*",
"encoder",
")",
"padding",
"(",
"offset",
",",
"algn",
"int",
")",
"int",
"{",
"abs",
":=",
"enc",
".",
"pos",
"+",
"offset",
"\n",
"if",
"abs",
"%",
"algn",
"!=",
"0",
"{",
"newabs",
":=",
"(",
"abs",
"+",
"algn",
"-",
"1",
")",
"&",
"^",
"(",
"algn",
"-",
"1",
")",
"\n",
"return",
"newabs",
"-",
"abs",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}"
] | // pad returns the number of bytes of padding, based on current position and additional offset.
// and alignment. | [
"pad",
"returns",
"the",
"number",
"of",
"bytes",
"of",
"padding",
"based",
"on",
"current",
"position",
"and",
"additional",
"offset",
".",
"and",
"alignment",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/encoder.go#L47-L54 |
150,806 | godbus/dbus | encoder.go | Encode | func (enc *encoder) Encode(vs ...interface{}) (err error) {
defer func() {
err, _ = recover().(error)
}()
for _, v := range vs {
enc.encode(reflect.ValueOf(v), 0)
}
return nil
} | go | func (enc *encoder) Encode(vs ...interface{}) (err error) {
defer func() {
err, _ = recover().(error)
}()
for _, v := range vs {
enc.encode(reflect.ValueOf(v), 0)
}
return nil
} | [
"func",
"(",
"enc",
"*",
"encoder",
")",
"Encode",
"(",
"vs",
"...",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"err",
",",
"_",
"=",
"recover",
"(",
")",
".",
"(",
"error",
")",
"\n",
"}",
"(",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vs",
"{",
"enc",
".",
"encode",
"(",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
",",
"0",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Encode encodes the given values to the underyling reader. All written values
// are aligned properly as required by the D-Bus spec. | [
"Encode",
"encodes",
"the",
"given",
"values",
"to",
"the",
"underyling",
"reader",
".",
"All",
"written",
"values",
"are",
"aligned",
"properly",
"as",
"required",
"by",
"the",
"D",
"-",
"Bus",
"spec",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/encoder.go#L65-L73 |
150,807 | godbus/dbus | export.go | ExportMethodTable | func (conn *Conn) ExportMethodTable(methods map[string]interface{}, path ObjectPath, iface string) error {
return conn.exportMethodTable(methods, path, iface, false)
} | go | func (conn *Conn) ExportMethodTable(methods map[string]interface{}, path ObjectPath, iface string) error {
return conn.exportMethodTable(methods, path, iface, false)
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"ExportMethodTable",
"(",
"methods",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"path",
"ObjectPath",
",",
"iface",
"string",
")",
"error",
"{",
"return",
"conn",
".",
"exportMethodTable",
"(",
"methods",
",",
"path",
",",
"iface",
",",
"false",
")",
"\n",
"}"
] | // ExportMethodTable like Export registers the given methods as an object
// on the message bus. Unlike Export the it uses a method table to define
// the object instead of a native go object.
//
// The method table is a map from method name to function closure
// representing the method. This allows an object exported on the bus to not
// necessarily be a native go object. It can be useful for generating exposed
// methods on the fly.
//
// Any non-function objects in the method table are ignored. | [
"ExportMethodTable",
"like",
"Export",
"registers",
"the",
"given",
"methods",
"as",
"an",
"object",
"on",
"the",
"message",
"bus",
".",
"Unlike",
"Export",
"the",
"it",
"uses",
"a",
"method",
"table",
"to",
"define",
"the",
"object",
"instead",
"of",
"a",
"native",
"go",
"object",
".",
"The",
"method",
"table",
"is",
"a",
"map",
"from",
"method",
"name",
"to",
"function",
"closure",
"representing",
"the",
"method",
".",
"This",
"allows",
"an",
"object",
"exported",
"on",
"the",
"bus",
"to",
"not",
"necessarily",
"be",
"a",
"native",
"go",
"object",
".",
"It",
"can",
"be",
"useful",
"for",
"generating",
"exposed",
"methods",
"on",
"the",
"fly",
".",
"Any",
"non",
"-",
"function",
"objects",
"in",
"the",
"method",
"table",
"are",
"ignored",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/export.go#L292-L294 |
150,808 | godbus/dbus | export.go | ExportSubtreeMethodTable | func (conn *Conn) ExportSubtreeMethodTable(methods map[string]interface{}, path ObjectPath, iface string) error {
return conn.exportMethodTable(methods, path, iface, true)
} | go | func (conn *Conn) ExportSubtreeMethodTable(methods map[string]interface{}, path ObjectPath, iface string) error {
return conn.exportMethodTable(methods, path, iface, true)
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"ExportSubtreeMethodTable",
"(",
"methods",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"path",
"ObjectPath",
",",
"iface",
"string",
")",
"error",
"{",
"return",
"conn",
".",
"exportMethodTable",
"(",
"methods",
",",
"path",
",",
"iface",
",",
"true",
")",
"\n",
"}"
] | // Like ExportSubtree, but with the same caveats as ExportMethodTable. | [
"Like",
"ExportSubtree",
"but",
"with",
"the",
"same",
"caveats",
"as",
"ExportMethodTable",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/export.go#L297-L299 |
150,809 | godbus/dbus | export.go | ReleaseName | func (conn *Conn) ReleaseName(name string) (ReleaseNameReply, error) {
var r uint32
err := conn.busObj.Call("org.freedesktop.DBus.ReleaseName", 0, name).Store(&r)
if err != nil {
return 0, err
}
return ReleaseNameReply(r), nil
} | go | func (conn *Conn) ReleaseName(name string) (ReleaseNameReply, error) {
var r uint32
err := conn.busObj.Call("org.freedesktop.DBus.ReleaseName", 0, name).Store(&r)
if err != nil {
return 0, err
}
return ReleaseNameReply(r), nil
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"ReleaseName",
"(",
"name",
"string",
")",
"(",
"ReleaseNameReply",
",",
"error",
")",
"{",
"var",
"r",
"uint32",
"\n",
"err",
":=",
"conn",
".",
"busObj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"name",
")",
".",
"Store",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"ReleaseNameReply",
"(",
"r",
")",
",",
"nil",
"\n",
"}"
] | // ReleaseName calls org.freedesktop.DBus.ReleaseName and awaits a response. | [
"ReleaseName",
"calls",
"org",
".",
"freedesktop",
".",
"DBus",
".",
"ReleaseName",
"and",
"awaits",
"a",
"response",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/export.go#L367-L374 |
150,810 | godbus/dbus | export.go | RequestName | func (conn *Conn) RequestName(name string, flags RequestNameFlags) (RequestNameReply, error) {
var r uint32
err := conn.busObj.Call("org.freedesktop.DBus.RequestName", 0, name, flags).Store(&r)
if err != nil {
return 0, err
}
return RequestNameReply(r), nil
} | go | func (conn *Conn) RequestName(name string, flags RequestNameFlags) (RequestNameReply, error) {
var r uint32
err := conn.busObj.Call("org.freedesktop.DBus.RequestName", 0, name, flags).Store(&r)
if err != nil {
return 0, err
}
return RequestNameReply(r), nil
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"RequestName",
"(",
"name",
"string",
",",
"flags",
"RequestNameFlags",
")",
"(",
"RequestNameReply",
",",
"error",
")",
"{",
"var",
"r",
"uint32",
"\n",
"err",
":=",
"conn",
".",
"busObj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"name",
",",
"flags",
")",
".",
"Store",
"(",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"RequestNameReply",
"(",
"r",
")",
",",
"nil",
"\n",
"}"
] | // RequestName calls org.freedesktop.DBus.RequestName and awaits a response. | [
"RequestName",
"calls",
"org",
".",
"freedesktop",
".",
"DBus",
".",
"RequestName",
"and",
"awaits",
"a",
"response",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/export.go#L377-L384 |
150,811 | godbus/dbus | introspect/introspectable.go | NewIntrospectable | func NewIntrospectable(n *Node) Introspectable {
found := false
for _, v := range n.Interfaces {
if v.Name == "org.freedesktop.DBus.Introspectable" {
found = true
break
}
}
if !found {
n.Interfaces = append(n.Interfaces, IntrospectData)
}
b, err := xml.Marshal(n)
if err != nil {
panic(err)
}
return Introspectable(strings.TrimSpace(IntrospectDeclarationString) + string(b))
} | go | func NewIntrospectable(n *Node) Introspectable {
found := false
for _, v := range n.Interfaces {
if v.Name == "org.freedesktop.DBus.Introspectable" {
found = true
break
}
}
if !found {
n.Interfaces = append(n.Interfaces, IntrospectData)
}
b, err := xml.Marshal(n)
if err != nil {
panic(err)
}
return Introspectable(strings.TrimSpace(IntrospectDeclarationString) + string(b))
} | [
"func",
"NewIntrospectable",
"(",
"n",
"*",
"Node",
")",
"Introspectable",
"{",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"n",
".",
"Interfaces",
"{",
"if",
"v",
".",
"Name",
"==",
"\"",
"\"",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"n",
".",
"Interfaces",
"=",
"append",
"(",
"n",
".",
"Interfaces",
",",
"IntrospectData",
")",
"\n",
"}",
"\n",
"b",
",",
"err",
":=",
"xml",
".",
"Marshal",
"(",
"n",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"Introspectable",
"(",
"strings",
".",
"TrimSpace",
"(",
"IntrospectDeclarationString",
")",
"+",
"string",
"(",
"b",
")",
")",
"\n",
"}"
] | // NewIntrospectable returns an Introspectable that returns the introspection
// data that corresponds to the given Node. If n.Interfaces doesn't contain the
// data for org.freedesktop.DBus.Introspectable, it is added automatically. | [
"NewIntrospectable",
"returns",
"an",
"Introspectable",
"that",
"returns",
"the",
"introspection",
"data",
"that",
"corresponds",
"to",
"the",
"given",
"Node",
".",
"If",
"n",
".",
"Interfaces",
"doesn",
"t",
"contain",
"the",
"data",
"for",
"org",
".",
"freedesktop",
".",
"DBus",
".",
"Introspectable",
"it",
"is",
"added",
"automatically",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/introspect/introspectable.go#L20-L36 |
150,812 | godbus/dbus | introspect/introspectable.go | Methods | func Methods(v interface{}) []Method {
t := reflect.TypeOf(v)
ms := make([]Method, 0, t.NumMethod())
for i := 0; i < t.NumMethod(); i++ {
if t.Method(i).PkgPath != "" {
continue
}
mt := t.Method(i).Type
if mt.NumOut() == 0 ||
mt.Out(mt.NumOut()-1) != reflect.TypeOf(&dbus.Error{}) {
continue
}
var m Method
m.Name = t.Method(i).Name
m.Args = make([]Arg, 0, mt.NumIn()+mt.NumOut()-2)
for j := 1; j < mt.NumIn(); j++ {
if mt.In(j) != reflect.TypeOf((*dbus.Sender)(nil)).Elem() &&
mt.In(j) != reflect.TypeOf((*dbus.Message)(nil)).Elem() {
arg := Arg{"", dbus.SignatureOfType(mt.In(j)).String(), "in"}
m.Args = append(m.Args, arg)
}
}
for j := 0; j < mt.NumOut()-1; j++ {
arg := Arg{"", dbus.SignatureOfType(mt.Out(j)).String(), "out"}
m.Args = append(m.Args, arg)
}
m.Annotations = make([]Annotation, 0)
ms = append(ms, m)
}
return ms
} | go | func Methods(v interface{}) []Method {
t := reflect.TypeOf(v)
ms := make([]Method, 0, t.NumMethod())
for i := 0; i < t.NumMethod(); i++ {
if t.Method(i).PkgPath != "" {
continue
}
mt := t.Method(i).Type
if mt.NumOut() == 0 ||
mt.Out(mt.NumOut()-1) != reflect.TypeOf(&dbus.Error{}) {
continue
}
var m Method
m.Name = t.Method(i).Name
m.Args = make([]Arg, 0, mt.NumIn()+mt.NumOut()-2)
for j := 1; j < mt.NumIn(); j++ {
if mt.In(j) != reflect.TypeOf((*dbus.Sender)(nil)).Elem() &&
mt.In(j) != reflect.TypeOf((*dbus.Message)(nil)).Elem() {
arg := Arg{"", dbus.SignatureOfType(mt.In(j)).String(), "in"}
m.Args = append(m.Args, arg)
}
}
for j := 0; j < mt.NumOut()-1; j++ {
arg := Arg{"", dbus.SignatureOfType(mt.Out(j)).String(), "out"}
m.Args = append(m.Args, arg)
}
m.Annotations = make([]Annotation, 0)
ms = append(ms, m)
}
return ms
} | [
"func",
"Methods",
"(",
"v",
"interface",
"{",
"}",
")",
"[",
"]",
"Method",
"{",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"v",
")",
"\n",
"ms",
":=",
"make",
"(",
"[",
"]",
"Method",
",",
"0",
",",
"t",
".",
"NumMethod",
"(",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"t",
".",
"NumMethod",
"(",
")",
";",
"i",
"++",
"{",
"if",
"t",
".",
"Method",
"(",
"i",
")",
".",
"PkgPath",
"!=",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"mt",
":=",
"t",
".",
"Method",
"(",
"i",
")",
".",
"Type",
"\n",
"if",
"mt",
".",
"NumOut",
"(",
")",
"==",
"0",
"||",
"mt",
".",
"Out",
"(",
"mt",
".",
"NumOut",
"(",
")",
"-",
"1",
")",
"!=",
"reflect",
".",
"TypeOf",
"(",
"&",
"dbus",
".",
"Error",
"{",
"}",
")",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"m",
"Method",
"\n",
"m",
".",
"Name",
"=",
"t",
".",
"Method",
"(",
"i",
")",
".",
"Name",
"\n",
"m",
".",
"Args",
"=",
"make",
"(",
"[",
"]",
"Arg",
",",
"0",
",",
"mt",
".",
"NumIn",
"(",
")",
"+",
"mt",
".",
"NumOut",
"(",
")",
"-",
"2",
")",
"\n",
"for",
"j",
":=",
"1",
";",
"j",
"<",
"mt",
".",
"NumIn",
"(",
")",
";",
"j",
"++",
"{",
"if",
"mt",
".",
"In",
"(",
"j",
")",
"!=",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"dbus",
".",
"Sender",
")",
"(",
"nil",
")",
")",
".",
"Elem",
"(",
")",
"&&",
"mt",
".",
"In",
"(",
"j",
")",
"!=",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"dbus",
".",
"Message",
")",
"(",
"nil",
")",
")",
".",
"Elem",
"(",
")",
"{",
"arg",
":=",
"Arg",
"{",
"\"",
"\"",
",",
"dbus",
".",
"SignatureOfType",
"(",
"mt",
".",
"In",
"(",
"j",
")",
")",
".",
"String",
"(",
")",
",",
"\"",
"\"",
"}",
"\n",
"m",
".",
"Args",
"=",
"append",
"(",
"m",
".",
"Args",
",",
"arg",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"j",
":=",
"0",
";",
"j",
"<",
"mt",
".",
"NumOut",
"(",
")",
"-",
"1",
";",
"j",
"++",
"{",
"arg",
":=",
"Arg",
"{",
"\"",
"\"",
",",
"dbus",
".",
"SignatureOfType",
"(",
"mt",
".",
"Out",
"(",
"j",
")",
")",
".",
"String",
"(",
")",
",",
"\"",
"\"",
"}",
"\n",
"m",
".",
"Args",
"=",
"append",
"(",
"m",
".",
"Args",
",",
"arg",
")",
"\n",
"}",
"\n",
"m",
".",
"Annotations",
"=",
"make",
"(",
"[",
"]",
"Annotation",
",",
"0",
")",
"\n",
"ms",
"=",
"append",
"(",
"ms",
",",
"m",
")",
"\n",
"}",
"\n",
"return",
"ms",
"\n",
"}"
] | // Methods returns the description of the methods of v. This can be used to
// create a Node which can be passed to NewIntrospectable. | [
"Methods",
"returns",
"the",
"description",
"of",
"the",
"methods",
"of",
"v",
".",
"This",
"can",
"be",
"used",
"to",
"create",
"a",
"Node",
"which",
"can",
"be",
"passed",
"to",
"NewIntrospectable",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/introspect/introspectable.go#L45-L76 |
150,813 | godbus/dbus | message.go | EncodeTo | func (msg *Message) EncodeTo(out io.Writer, order binary.ByteOrder) error {
if err := msg.IsValid(); err != nil {
return err
}
var vs [7]interface{}
switch order {
case binary.LittleEndian:
vs[0] = byte('l')
case binary.BigEndian:
vs[0] = byte('B')
default:
return errors.New("dbus: invalid byte order")
}
body := new(bytes.Buffer)
enc := newEncoder(body, order)
if len(msg.Body) != 0 {
enc.Encode(msg.Body...)
}
vs[1] = msg.Type
vs[2] = msg.Flags
vs[3] = protoVersion
vs[4] = uint32(len(body.Bytes()))
vs[5] = msg.serial
headers := make([]header, 0, len(msg.Headers))
for k, v := range msg.Headers {
headers = append(headers, header{byte(k), v})
}
vs[6] = headers
var buf bytes.Buffer
enc = newEncoder(&buf, order)
enc.Encode(vs[:]...)
enc.align(8)
body.WriteTo(&buf)
if buf.Len() > 1<<27 {
return InvalidMessageError("message is too long")
}
if _, err := buf.WriteTo(out); err != nil {
return err
}
return nil
} | go | func (msg *Message) EncodeTo(out io.Writer, order binary.ByteOrder) error {
if err := msg.IsValid(); err != nil {
return err
}
var vs [7]interface{}
switch order {
case binary.LittleEndian:
vs[0] = byte('l')
case binary.BigEndian:
vs[0] = byte('B')
default:
return errors.New("dbus: invalid byte order")
}
body := new(bytes.Buffer)
enc := newEncoder(body, order)
if len(msg.Body) != 0 {
enc.Encode(msg.Body...)
}
vs[1] = msg.Type
vs[2] = msg.Flags
vs[3] = protoVersion
vs[4] = uint32(len(body.Bytes()))
vs[5] = msg.serial
headers := make([]header, 0, len(msg.Headers))
for k, v := range msg.Headers {
headers = append(headers, header{byte(k), v})
}
vs[6] = headers
var buf bytes.Buffer
enc = newEncoder(&buf, order)
enc.Encode(vs[:]...)
enc.align(8)
body.WriteTo(&buf)
if buf.Len() > 1<<27 {
return InvalidMessageError("message is too long")
}
if _, err := buf.WriteTo(out); err != nil {
return err
}
return nil
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"EncodeTo",
"(",
"out",
"io",
".",
"Writer",
",",
"order",
"binary",
".",
"ByteOrder",
")",
"error",
"{",
"if",
"err",
":=",
"msg",
".",
"IsValid",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"vs",
"[",
"7",
"]",
"interface",
"{",
"}",
"\n",
"switch",
"order",
"{",
"case",
"binary",
".",
"LittleEndian",
":",
"vs",
"[",
"0",
"]",
"=",
"byte",
"(",
"'l'",
")",
"\n",
"case",
"binary",
".",
"BigEndian",
":",
"vs",
"[",
"0",
"]",
"=",
"byte",
"(",
"'B'",
")",
"\n",
"default",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"body",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"enc",
":=",
"newEncoder",
"(",
"body",
",",
"order",
")",
"\n",
"if",
"len",
"(",
"msg",
".",
"Body",
")",
"!=",
"0",
"{",
"enc",
".",
"Encode",
"(",
"msg",
".",
"Body",
"...",
")",
"\n",
"}",
"\n",
"vs",
"[",
"1",
"]",
"=",
"msg",
".",
"Type",
"\n",
"vs",
"[",
"2",
"]",
"=",
"msg",
".",
"Flags",
"\n",
"vs",
"[",
"3",
"]",
"=",
"protoVersion",
"\n",
"vs",
"[",
"4",
"]",
"=",
"uint32",
"(",
"len",
"(",
"body",
".",
"Bytes",
"(",
")",
")",
")",
"\n",
"vs",
"[",
"5",
"]",
"=",
"msg",
".",
"serial",
"\n",
"headers",
":=",
"make",
"(",
"[",
"]",
"header",
",",
"0",
",",
"len",
"(",
"msg",
".",
"Headers",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"msg",
".",
"Headers",
"{",
"headers",
"=",
"append",
"(",
"headers",
",",
"header",
"{",
"byte",
"(",
"k",
")",
",",
"v",
"}",
")",
"\n",
"}",
"\n",
"vs",
"[",
"6",
"]",
"=",
"headers",
"\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"enc",
"=",
"newEncoder",
"(",
"&",
"buf",
",",
"order",
")",
"\n",
"enc",
".",
"Encode",
"(",
"vs",
"[",
":",
"]",
"...",
")",
"\n",
"enc",
".",
"align",
"(",
"8",
")",
"\n",
"body",
".",
"WriteTo",
"(",
"&",
"buf",
")",
"\n",
"if",
"buf",
".",
"Len",
"(",
")",
">",
"1",
"<<",
"27",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"buf",
".",
"WriteTo",
"(",
"out",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // EncodeTo encodes and sends a message to the given writer. The byte order must
// be either binary.LittleEndian or binary.BigEndian. If the message is not
// valid or an error occurs when writing, an error is returned. | [
"EncodeTo",
"encodes",
"and",
"sends",
"a",
"message",
"to",
"the",
"given",
"writer",
".",
"The",
"byte",
"order",
"must",
"be",
"either",
"binary",
".",
"LittleEndian",
"or",
"binary",
".",
"BigEndian",
".",
"If",
"the",
"message",
"is",
"not",
"valid",
"or",
"an",
"error",
"occurs",
"when",
"writing",
"an",
"error",
"is",
"returned",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/message.go#L213-L253 |
150,814 | godbus/dbus | message.go | IsValid | func (msg *Message) IsValid() error {
if msg.Flags & ^(FlagNoAutoStart|FlagNoReplyExpected|FlagAllowInteractiveAuthorization) != 0 {
return InvalidMessageError("invalid flags")
}
if msg.Type == 0 || msg.Type >= typeMax {
return InvalidMessageError("invalid message type")
}
for k, v := range msg.Headers {
if k == 0 || k >= fieldMax {
return InvalidMessageError("invalid header")
}
if reflect.TypeOf(v.value) != fieldTypes[k] {
return InvalidMessageError("invalid type of header field")
}
}
for _, v := range requiredFields[msg.Type] {
if _, ok := msg.Headers[v]; !ok {
return InvalidMessageError("missing required header")
}
}
if path, ok := msg.Headers[FieldPath]; ok {
if !path.value.(ObjectPath).IsValid() {
return InvalidMessageError("invalid path name")
}
}
if iface, ok := msg.Headers[FieldInterface]; ok {
if !isValidInterface(iface.value.(string)) {
return InvalidMessageError("invalid interface name")
}
}
if member, ok := msg.Headers[FieldMember]; ok {
if !isValidMember(member.value.(string)) {
return InvalidMessageError("invalid member name")
}
}
if errname, ok := msg.Headers[FieldErrorName]; ok {
if !isValidInterface(errname.value.(string)) {
return InvalidMessageError("invalid error name")
}
}
if len(msg.Body) != 0 {
if _, ok := msg.Headers[FieldSignature]; !ok {
return InvalidMessageError("missing signature")
}
}
return nil
} | go | func (msg *Message) IsValid() error {
if msg.Flags & ^(FlagNoAutoStart|FlagNoReplyExpected|FlagAllowInteractiveAuthorization) != 0 {
return InvalidMessageError("invalid flags")
}
if msg.Type == 0 || msg.Type >= typeMax {
return InvalidMessageError("invalid message type")
}
for k, v := range msg.Headers {
if k == 0 || k >= fieldMax {
return InvalidMessageError("invalid header")
}
if reflect.TypeOf(v.value) != fieldTypes[k] {
return InvalidMessageError("invalid type of header field")
}
}
for _, v := range requiredFields[msg.Type] {
if _, ok := msg.Headers[v]; !ok {
return InvalidMessageError("missing required header")
}
}
if path, ok := msg.Headers[FieldPath]; ok {
if !path.value.(ObjectPath).IsValid() {
return InvalidMessageError("invalid path name")
}
}
if iface, ok := msg.Headers[FieldInterface]; ok {
if !isValidInterface(iface.value.(string)) {
return InvalidMessageError("invalid interface name")
}
}
if member, ok := msg.Headers[FieldMember]; ok {
if !isValidMember(member.value.(string)) {
return InvalidMessageError("invalid member name")
}
}
if errname, ok := msg.Headers[FieldErrorName]; ok {
if !isValidInterface(errname.value.(string)) {
return InvalidMessageError("invalid error name")
}
}
if len(msg.Body) != 0 {
if _, ok := msg.Headers[FieldSignature]; !ok {
return InvalidMessageError("missing signature")
}
}
return nil
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"IsValid",
"(",
")",
"error",
"{",
"if",
"msg",
".",
"Flags",
"&",
"^",
"(",
"FlagNoAutoStart",
"|",
"FlagNoReplyExpected",
"|",
"FlagAllowInteractiveAuthorization",
")",
"!=",
"0",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"msg",
".",
"Type",
"==",
"0",
"||",
"msg",
".",
"Type",
">=",
"typeMax",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"msg",
".",
"Headers",
"{",
"if",
"k",
"==",
"0",
"||",
"k",
">=",
"fieldMax",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"reflect",
".",
"TypeOf",
"(",
"v",
".",
"value",
")",
"!=",
"fieldTypes",
"[",
"k",
"]",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"requiredFields",
"[",
"msg",
".",
"Type",
"]",
"{",
"if",
"_",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"v",
"]",
";",
"!",
"ok",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"path",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldPath",
"]",
";",
"ok",
"{",
"if",
"!",
"path",
".",
"value",
".",
"(",
"ObjectPath",
")",
".",
"IsValid",
"(",
")",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"iface",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldInterface",
"]",
";",
"ok",
"{",
"if",
"!",
"isValidInterface",
"(",
"iface",
".",
"value",
".",
"(",
"string",
")",
")",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"member",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldMember",
"]",
";",
"ok",
"{",
"if",
"!",
"isValidMember",
"(",
"member",
".",
"value",
".",
"(",
"string",
")",
")",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"errname",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldErrorName",
"]",
";",
"ok",
"{",
"if",
"!",
"isValidInterface",
"(",
"errname",
".",
"value",
".",
"(",
"string",
")",
")",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"msg",
".",
"Body",
")",
"!=",
"0",
"{",
"if",
"_",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldSignature",
"]",
";",
"!",
"ok",
"{",
"return",
"InvalidMessageError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // IsValid checks whether msg is a valid message and returns an
// InvalidMessageError if it is not. | [
"IsValid",
"checks",
"whether",
"msg",
"is",
"a",
"valid",
"message",
"and",
"returns",
"an",
"InvalidMessageError",
"if",
"it",
"is",
"not",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/message.go#L257-L303 |
150,815 | godbus/dbus | message.go | String | func (msg *Message) String() string {
if err := msg.IsValid(); err != nil {
return "<invalid>"
}
s := msg.Type.String()
if v, ok := msg.Headers[FieldSender]; ok {
s += " from " + v.value.(string)
}
if v, ok := msg.Headers[FieldDestination]; ok {
s += " to " + v.value.(string)
}
s += " serial " + strconv.FormatUint(uint64(msg.serial), 10)
if v, ok := msg.Headers[FieldReplySerial]; ok {
s += " reply_serial " + strconv.FormatUint(uint64(v.value.(uint32)), 10)
}
if v, ok := msg.Headers[FieldUnixFDs]; ok {
s += " unixfds " + strconv.FormatUint(uint64(v.value.(uint32)), 10)
}
if v, ok := msg.Headers[FieldPath]; ok {
s += " path " + string(v.value.(ObjectPath))
}
if v, ok := msg.Headers[FieldInterface]; ok {
s += " interface " + v.value.(string)
}
if v, ok := msg.Headers[FieldErrorName]; ok {
s += " error " + v.value.(string)
}
if v, ok := msg.Headers[FieldMember]; ok {
s += " member " + v.value.(string)
}
if len(msg.Body) != 0 {
s += "\n"
}
for i, v := range msg.Body {
s += " " + MakeVariant(v).String()
if i != len(msg.Body)-1 {
s += "\n"
}
}
return s
} | go | func (msg *Message) String() string {
if err := msg.IsValid(); err != nil {
return "<invalid>"
}
s := msg.Type.String()
if v, ok := msg.Headers[FieldSender]; ok {
s += " from " + v.value.(string)
}
if v, ok := msg.Headers[FieldDestination]; ok {
s += " to " + v.value.(string)
}
s += " serial " + strconv.FormatUint(uint64(msg.serial), 10)
if v, ok := msg.Headers[FieldReplySerial]; ok {
s += " reply_serial " + strconv.FormatUint(uint64(v.value.(uint32)), 10)
}
if v, ok := msg.Headers[FieldUnixFDs]; ok {
s += " unixfds " + strconv.FormatUint(uint64(v.value.(uint32)), 10)
}
if v, ok := msg.Headers[FieldPath]; ok {
s += " path " + string(v.value.(ObjectPath))
}
if v, ok := msg.Headers[FieldInterface]; ok {
s += " interface " + v.value.(string)
}
if v, ok := msg.Headers[FieldErrorName]; ok {
s += " error " + v.value.(string)
}
if v, ok := msg.Headers[FieldMember]; ok {
s += " member " + v.value.(string)
}
if len(msg.Body) != 0 {
s += "\n"
}
for i, v := range msg.Body {
s += " " + MakeVariant(v).String()
if i != len(msg.Body)-1 {
s += "\n"
}
}
return s
} | [
"func",
"(",
"msg",
"*",
"Message",
")",
"String",
"(",
")",
"string",
"{",
"if",
"err",
":=",
"msg",
".",
"IsValid",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"s",
":=",
"msg",
".",
"Type",
".",
"String",
"(",
")",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldSender",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"v",
".",
"value",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldDestination",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"v",
".",
"value",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"s",
"+=",
"\"",
"\"",
"+",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"msg",
".",
"serial",
")",
",",
"10",
")",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldReplySerial",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"v",
".",
"value",
".",
"(",
"uint32",
")",
")",
",",
"10",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldUnixFDs",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"v",
".",
"value",
".",
"(",
"uint32",
")",
")",
",",
"10",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldPath",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"string",
"(",
"v",
".",
"value",
".",
"(",
"ObjectPath",
")",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldInterface",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"v",
".",
"value",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldErrorName",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"v",
".",
"value",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"ok",
":=",
"msg",
".",
"Headers",
"[",
"FieldMember",
"]",
";",
"ok",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"v",
".",
"value",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"msg",
".",
"Body",
")",
"!=",
"0",
"{",
"s",
"+=",
"\"",
"\\n",
"\"",
"\n",
"}",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"msg",
".",
"Body",
"{",
"s",
"+=",
"\"",
"\"",
"+",
"MakeVariant",
"(",
"v",
")",
".",
"String",
"(",
")",
"\n",
"if",
"i",
"!=",
"len",
"(",
"msg",
".",
"Body",
")",
"-",
"1",
"{",
"s",
"+=",
"\"",
"\\n",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // String returns a string representation of a message similar to the format of
// dbus-monitor. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"a",
"message",
"similar",
"to",
"the",
"format",
"of",
"dbus",
"-",
"monitor",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/message.go#L313-L353 |
150,816 | godbus/dbus | call.go | Store | func (c *Call) Store(retvalues ...interface{}) error {
if c.Err != nil {
return c.Err
}
return Store(c.Body, retvalues...)
} | go | func (c *Call) Store(retvalues ...interface{}) error {
if c.Err != nil {
return c.Err
}
return Store(c.Body, retvalues...)
} | [
"func",
"(",
"c",
"*",
"Call",
")",
"Store",
"(",
"retvalues",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"c",
".",
"Err",
"!=",
"nil",
"{",
"return",
"c",
".",
"Err",
"\n",
"}",
"\n\n",
"return",
"Store",
"(",
"c",
".",
"Body",
",",
"retvalues",
"...",
")",
"\n",
"}"
] | // Store stores the body of the reply into the provided pointers. It returns
// an error if the signatures of the body and retvalues don't match, or if
// the error status is not nil. | [
"Store",
"stores",
"the",
"body",
"of",
"the",
"reply",
"into",
"the",
"provided",
"pointers",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"signatures",
"of",
"the",
"body",
"and",
"retvalues",
"don",
"t",
"match",
"or",
"if",
"the",
"error",
"status",
"is",
"not",
"nil",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/call.go#L49-L55 |
150,817 | godbus/dbus | dbus.go | Store | func Store(src []interface{}, dest ...interface{}) error {
if len(src) != len(dest) {
return errors.New("dbus.Store: length mismatch")
}
for i := range src {
if err := storeInterfaces(src[i], dest[i]); err != nil {
return err
}
}
return nil
} | go | func Store(src []interface{}, dest ...interface{}) error {
if len(src) != len(dest) {
return errors.New("dbus.Store: length mismatch")
}
for i := range src {
if err := storeInterfaces(src[i], dest[i]); err != nil {
return err
}
}
return nil
} | [
"func",
"Store",
"(",
"src",
"[",
"]",
"interface",
"{",
"}",
",",
"dest",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"len",
"(",
"src",
")",
"!=",
"len",
"(",
"dest",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"src",
"{",
"if",
"err",
":=",
"storeInterfaces",
"(",
"src",
"[",
"i",
"]",
",",
"dest",
"[",
"i",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Store copies the values contained in src to dest, which must be a slice of
// pointers. It converts slices of interfaces from src to corresponding structs
// in dest. An error is returned if the lengths of src and dest or the types of
// their elements don't match. | [
"Store",
"copies",
"the",
"values",
"contained",
"in",
"src",
"to",
"dest",
"which",
"must",
"be",
"a",
"slice",
"of",
"pointers",
".",
"It",
"converts",
"slices",
"of",
"interfaces",
"from",
"src",
"to",
"corresponding",
"structs",
"in",
"dest",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"lengths",
"of",
"src",
"and",
"dest",
"or",
"the",
"types",
"of",
"their",
"elements",
"don",
"t",
"match",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/dbus.go#L47-L58 |
150,818 | godbus/dbus | dbus.go | IsValid | func (o ObjectPath) IsValid() bool {
s := string(o)
if len(s) == 0 {
return false
}
if s[0] != '/' {
return false
}
if s[len(s)-1] == '/' && len(s) != 1 {
return false
}
// probably not used, but technically possible
if s == "/" {
return true
}
split := strings.Split(s[1:], "/")
for _, v := range split {
if len(v) == 0 {
return false
}
for _, c := range v {
if !isMemberChar(c) {
return false
}
}
}
return true
} | go | func (o ObjectPath) IsValid() bool {
s := string(o)
if len(s) == 0 {
return false
}
if s[0] != '/' {
return false
}
if s[len(s)-1] == '/' && len(s) != 1 {
return false
}
// probably not used, but technically possible
if s == "/" {
return true
}
split := strings.Split(s[1:], "/")
for _, v := range split {
if len(v) == 0 {
return false
}
for _, c := range v {
if !isMemberChar(c) {
return false
}
}
}
return true
} | [
"func",
"(",
"o",
"ObjectPath",
")",
"IsValid",
"(",
")",
"bool",
"{",
"s",
":=",
"string",
"(",
"o",
")",
"\n",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"s",
"[",
"0",
"]",
"!=",
"'/'",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"s",
"[",
"len",
"(",
"s",
")",
"-",
"1",
"]",
"==",
"'/'",
"&&",
"len",
"(",
"s",
")",
"!=",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// probably not used, but technically possible",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"split",
":=",
"strings",
".",
"Split",
"(",
"s",
"[",
"1",
":",
"]",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"split",
"{",
"if",
"len",
"(",
"v",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"v",
"{",
"if",
"!",
"isMemberChar",
"(",
"c",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // IsValid returns whether the object path is valid. | [
"IsValid",
"returns",
"whether",
"the",
"object",
"path",
"is",
"valid",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/dbus.go#L304-L331 |
150,819 | godbus/dbus | dbus.go | alignment | func alignment(t reflect.Type) int {
switch t {
case variantType:
return 1
case objectPathType:
return 4
case signatureType:
return 1
case interfacesType:
return 4
}
switch t.Kind() {
case reflect.Uint8:
return 1
case reflect.Uint16, reflect.Int16:
return 2
case reflect.Uint, reflect.Int, reflect.Uint32, reflect.Int32, reflect.String, reflect.Array, reflect.Slice, reflect.Map:
return 4
case reflect.Uint64, reflect.Int64, reflect.Float64, reflect.Struct:
return 8
case reflect.Ptr:
return alignment(t.Elem())
}
return 1
} | go | func alignment(t reflect.Type) int {
switch t {
case variantType:
return 1
case objectPathType:
return 4
case signatureType:
return 1
case interfacesType:
return 4
}
switch t.Kind() {
case reflect.Uint8:
return 1
case reflect.Uint16, reflect.Int16:
return 2
case reflect.Uint, reflect.Int, reflect.Uint32, reflect.Int32, reflect.String, reflect.Array, reflect.Slice, reflect.Map:
return 4
case reflect.Uint64, reflect.Int64, reflect.Float64, reflect.Struct:
return 8
case reflect.Ptr:
return alignment(t.Elem())
}
return 1
} | [
"func",
"alignment",
"(",
"t",
"reflect",
".",
"Type",
")",
"int",
"{",
"switch",
"t",
"{",
"case",
"variantType",
":",
"return",
"1",
"\n",
"case",
"objectPathType",
":",
"return",
"4",
"\n",
"case",
"signatureType",
":",
"return",
"1",
"\n",
"case",
"interfacesType",
":",
"return",
"4",
"\n",
"}",
"\n",
"switch",
"t",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Uint8",
":",
"return",
"1",
"\n",
"case",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Int16",
":",
"return",
"2",
"\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"String",
",",
"reflect",
".",
"Array",
",",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Map",
":",
"return",
"4",
"\n",
"case",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Int64",
",",
"reflect",
".",
"Float64",
",",
"reflect",
".",
"Struct",
":",
"return",
"8",
"\n",
"case",
"reflect",
".",
"Ptr",
":",
"return",
"alignment",
"(",
"t",
".",
"Elem",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}"
] | // alignment returns the alignment of values of type t. | [
"alignment",
"returns",
"the",
"alignment",
"of",
"values",
"of",
"type",
"t",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/dbus.go#L341-L365 |
150,820 | godbus/dbus | dbus.go | isKeyType | func isKeyType(t reflect.Type) bool {
switch t.Kind() {
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Int16, reflect.Int32, reflect.Int64, reflect.Float64,
reflect.String, reflect.Uint, reflect.Int:
return true
}
return false
} | go | func isKeyType(t reflect.Type) bool {
switch t.Kind() {
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Int16, reflect.Int32, reflect.Int64, reflect.Float64,
reflect.String, reflect.Uint, reflect.Int:
return true
}
return false
} | [
"func",
"isKeyType",
"(",
"t",
"reflect",
".",
"Type",
")",
"bool",
"{",
"switch",
"t",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
",",
"reflect",
".",
"Float64",
",",
"reflect",
".",
"String",
",",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Int",
":",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // isKeyType returns whether t is a valid type for a D-Bus dict. | [
"isKeyType",
"returns",
"whether",
"t",
"is",
"a",
"valid",
"type",
"for",
"a",
"D",
"-",
"Bus",
"dict",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/dbus.go#L368-L377 |
150,821 | godbus/dbus | dbus.go | isValidInterface | func isValidInterface(s string) bool {
if len(s) == 0 || len(s) > 255 || s[0] == '.' {
return false
}
elem := strings.Split(s, ".")
if len(elem) < 2 {
return false
}
for _, v := range elem {
if len(v) == 0 {
return false
}
if v[0] >= '0' && v[0] <= '9' {
return false
}
for _, c := range v {
if !isMemberChar(c) {
return false
}
}
}
return true
} | go | func isValidInterface(s string) bool {
if len(s) == 0 || len(s) > 255 || s[0] == '.' {
return false
}
elem := strings.Split(s, ".")
if len(elem) < 2 {
return false
}
for _, v := range elem {
if len(v) == 0 {
return false
}
if v[0] >= '0' && v[0] <= '9' {
return false
}
for _, c := range v {
if !isMemberChar(c) {
return false
}
}
}
return true
} | [
"func",
"isValidInterface",
"(",
"s",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"||",
"len",
"(",
"s",
")",
">",
"255",
"||",
"s",
"[",
"0",
"]",
"==",
"'.'",
"{",
"return",
"false",
"\n",
"}",
"\n",
"elem",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"elem",
")",
"<",
"2",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"elem",
"{",
"if",
"len",
"(",
"v",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"v",
"[",
"0",
"]",
">=",
"'0'",
"&&",
"v",
"[",
"0",
"]",
"<=",
"'9'",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"v",
"{",
"if",
"!",
"isMemberChar",
"(",
"c",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // isValidInterface returns whether s is a valid name for an interface. | [
"isValidInterface",
"returns",
"whether",
"s",
"is",
"a",
"valid",
"name",
"for",
"an",
"interface",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/dbus.go#L380-L402 |
150,822 | godbus/dbus | dbus.go | isValidMember | func isValidMember(s string) bool {
if len(s) == 0 || len(s) > 255 {
return false
}
i := strings.Index(s, ".")
if i != -1 {
return false
}
if s[0] >= '0' && s[0] <= '9' {
return false
}
for _, c := range s {
if !isMemberChar(c) {
return false
}
}
return true
} | go | func isValidMember(s string) bool {
if len(s) == 0 || len(s) > 255 {
return false
}
i := strings.Index(s, ".")
if i != -1 {
return false
}
if s[0] >= '0' && s[0] <= '9' {
return false
}
for _, c := range s {
if !isMemberChar(c) {
return false
}
}
return true
} | [
"func",
"isValidMember",
"(",
"s",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"0",
"||",
"len",
"(",
"s",
")",
">",
"255",
"{",
"return",
"false",
"\n",
"}",
"\n",
"i",
":=",
"strings",
".",
"Index",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"if",
"i",
"!=",
"-",
"1",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"s",
"[",
"0",
"]",
">=",
"'0'",
"&&",
"s",
"[",
"0",
"]",
"<=",
"'9'",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"s",
"{",
"if",
"!",
"isMemberChar",
"(",
"c",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // isValidMember returns whether s is a valid name for a member. | [
"isValidMember",
"returns",
"whether",
"s",
"is",
"a",
"valid",
"name",
"for",
"a",
"member",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/dbus.go#L405-L422 |
150,823 | godbus/dbus | conn.go | SessionBus | func SessionBus() (conn *Conn, err error) {
sessionBusLck.Lock()
defer sessionBusLck.Unlock()
if sessionBus != nil {
return sessionBus, nil
}
defer func() {
if conn != nil {
sessionBus = conn
}
}()
conn, err = SessionBusPrivate()
if err != nil {
return
}
if err = conn.Auth(nil); err != nil {
conn.Close()
conn = nil
return
}
if err = conn.Hello(); err != nil {
conn.Close()
conn = nil
}
return
} | go | func SessionBus() (conn *Conn, err error) {
sessionBusLck.Lock()
defer sessionBusLck.Unlock()
if sessionBus != nil {
return sessionBus, nil
}
defer func() {
if conn != nil {
sessionBus = conn
}
}()
conn, err = SessionBusPrivate()
if err != nil {
return
}
if err = conn.Auth(nil); err != nil {
conn.Close()
conn = nil
return
}
if err = conn.Hello(); err != nil {
conn.Close()
conn = nil
}
return
} | [
"func",
"SessionBus",
"(",
")",
"(",
"conn",
"*",
"Conn",
",",
"err",
"error",
")",
"{",
"sessionBusLck",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sessionBusLck",
".",
"Unlock",
"(",
")",
"\n",
"if",
"sessionBus",
"!=",
"nil",
"{",
"return",
"sessionBus",
",",
"nil",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"conn",
"!=",
"nil",
"{",
"sessionBus",
"=",
"conn",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"conn",
",",
"err",
"=",
"SessionBusPrivate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"conn",
".",
"Auth",
"(",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"conn",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"conn",
".",
"Hello",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"conn",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // SessionBus returns a shared connection to the session bus, connecting to it
// if not already done. | [
"SessionBus",
"returns",
"a",
"shared",
"connection",
"to",
"the",
"session",
"bus",
"connecting",
"to",
"it",
"if",
"not",
"already",
"done",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L52-L77 |
150,824 | godbus/dbus | conn.go | SystemBus | func SystemBus() (conn *Conn, err error) {
systemBusLck.Lock()
defer systemBusLck.Unlock()
if systemBus != nil {
return systemBus, nil
}
defer func() {
if conn != nil {
systemBus = conn
}
}()
conn, err = SystemBusPrivate()
if err != nil {
return
}
if err = conn.Auth(nil); err != nil {
conn.Close()
conn = nil
return
}
if err = conn.Hello(); err != nil {
conn.Close()
conn = nil
}
return
} | go | func SystemBus() (conn *Conn, err error) {
systemBusLck.Lock()
defer systemBusLck.Unlock()
if systemBus != nil {
return systemBus, nil
}
defer func() {
if conn != nil {
systemBus = conn
}
}()
conn, err = SystemBusPrivate()
if err != nil {
return
}
if err = conn.Auth(nil); err != nil {
conn.Close()
conn = nil
return
}
if err = conn.Hello(); err != nil {
conn.Close()
conn = nil
}
return
} | [
"func",
"SystemBus",
"(",
")",
"(",
"conn",
"*",
"Conn",
",",
"err",
"error",
")",
"{",
"systemBusLck",
".",
"Lock",
"(",
")",
"\n",
"defer",
"systemBusLck",
".",
"Unlock",
"(",
")",
"\n",
"if",
"systemBus",
"!=",
"nil",
"{",
"return",
"systemBus",
",",
"nil",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"conn",
"!=",
"nil",
"{",
"systemBus",
"=",
"conn",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"conn",
",",
"err",
"=",
"SystemBusPrivate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"conn",
".",
"Auth",
"(",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"conn",
"=",
"nil",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"conn",
".",
"Hello",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"conn",
".",
"Close",
"(",
")",
"\n",
"conn",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // SystemBus returns a shared connection to the system bus, connecting to it if
// not already done. | [
"SystemBus",
"returns",
"a",
"shared",
"connection",
"to",
"the",
"system",
"bus",
"connecting",
"to",
"it",
"if",
"not",
"already",
"done",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L109-L134 |
150,825 | godbus/dbus | conn.go | WithHandler | func WithHandler(handler Handler) ConnOption {
return func(conn *Conn) error {
conn.handler = handler
return nil
}
} | go | func WithHandler(handler Handler) ConnOption {
return func(conn *Conn) error {
conn.handler = handler
return nil
}
} | [
"func",
"WithHandler",
"(",
"handler",
"Handler",
")",
"ConnOption",
"{",
"return",
"func",
"(",
"conn",
"*",
"Conn",
")",
"error",
"{",
"conn",
".",
"handler",
"=",
"handler",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithHandler overrides the default handler. | [
"WithHandler",
"overrides",
"the",
"default",
"handler",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L170-L175 |
150,826 | godbus/dbus | conn.go | WithSignalHandler | func WithSignalHandler(handler SignalHandler) ConnOption {
return func(conn *Conn) error {
conn.signalHandler = handler
return nil
}
} | go | func WithSignalHandler(handler SignalHandler) ConnOption {
return func(conn *Conn) error {
conn.signalHandler = handler
return nil
}
} | [
"func",
"WithSignalHandler",
"(",
"handler",
"SignalHandler",
")",
"ConnOption",
"{",
"return",
"func",
"(",
"conn",
"*",
"Conn",
")",
"error",
"{",
"conn",
".",
"signalHandler",
"=",
"handler",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithSignalHandler overrides the default signal handler. | [
"WithSignalHandler",
"overrides",
"the",
"default",
"signal",
"handler",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L178-L183 |
150,827 | godbus/dbus | conn.go | WithSerialGenerator | func WithSerialGenerator(gen SerialGenerator) ConnOption {
return func(conn *Conn) error {
conn.serialGen = gen
return nil
}
} | go | func WithSerialGenerator(gen SerialGenerator) ConnOption {
return func(conn *Conn) error {
conn.serialGen = gen
return nil
}
} | [
"func",
"WithSerialGenerator",
"(",
"gen",
"SerialGenerator",
")",
"ConnOption",
"{",
"return",
"func",
"(",
"conn",
"*",
"Conn",
")",
"error",
"{",
"conn",
".",
"serialGen",
"=",
"gen",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithSerialGenerator overrides the default signals generator. | [
"WithSerialGenerator",
"overrides",
"the",
"default",
"signals",
"generator",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L186-L191 |
150,828 | godbus/dbus | conn.go | Eavesdrop | func (conn *Conn) Eavesdrop(ch chan<- *Message) {
conn.eavesdroppedLck.Lock()
conn.eavesdropped = ch
conn.eavesdroppedLck.Unlock()
} | go | func (conn *Conn) Eavesdrop(ch chan<- *Message) {
conn.eavesdroppedLck.Lock()
conn.eavesdropped = ch
conn.eavesdroppedLck.Unlock()
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"Eavesdrop",
"(",
"ch",
"chan",
"<-",
"*",
"Message",
")",
"{",
"conn",
".",
"eavesdroppedLck",
".",
"Lock",
"(",
")",
"\n",
"conn",
".",
"eavesdropped",
"=",
"ch",
"\n",
"conn",
".",
"eavesdroppedLck",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // Eavesdrop causes conn to send all incoming messages to the given channel
// without further processing. Method replies, errors and signals will not be
// sent to the appropiate channels and method calls will not be handled. If nil
// is passed, the normal behaviour is restored.
//
// The caller has to make sure that ch is sufficiently buffered;
// if a message arrives when a write to ch is not possible, the message is
// discarded. | [
"Eavesdrop",
"causes",
"conn",
"to",
"send",
"all",
"incoming",
"messages",
"to",
"the",
"given",
"channel",
"without",
"further",
"processing",
".",
"Method",
"replies",
"errors",
"and",
"signals",
"will",
"not",
"be",
"sent",
"to",
"the",
"appropiate",
"channels",
"and",
"method",
"calls",
"will",
"not",
"be",
"handled",
".",
"If",
"nil",
"is",
"passed",
"the",
"normal",
"behaviour",
"is",
"restored",
".",
"The",
"caller",
"has",
"to",
"make",
"sure",
"that",
"ch",
"is",
"sufficiently",
"buffered",
";",
"if",
"a",
"message",
"arrives",
"when",
"a",
"write",
"to",
"ch",
"is",
"not",
"possible",
"the",
"message",
"is",
"discarded",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L266-L270 |
150,829 | godbus/dbus | conn.go | SendWithContext | func (conn *Conn) SendWithContext(ctx context.Context, msg *Message, ch chan *Call) *Call {
return conn.send(ctx, msg, ch)
} | go | func (conn *Conn) SendWithContext(ctx context.Context, msg *Message, ch chan *Call) *Call {
return conn.send(ctx, msg, ch)
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"SendWithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"*",
"Message",
",",
"ch",
"chan",
"*",
"Call",
")",
"*",
"Call",
"{",
"return",
"conn",
".",
"send",
"(",
"ctx",
",",
"msg",
",",
"ch",
")",
"\n",
"}"
] | // SendWithContext acts like Send but takes a context | [
"SendWithContext",
"acts",
"like",
"Send",
"but",
"takes",
"a",
"context"
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L411-L413 |
150,830 | godbus/dbus | conn.go | sendReply | func (conn *Conn) sendReply(dest string, serial uint32, values ...interface{}) {
msg := new(Message)
msg.Type = TypeMethodReply
msg.serial = conn.getSerial()
msg.Headers = make(map[HeaderField]Variant)
if dest != "" {
msg.Headers[FieldDestination] = MakeVariant(dest)
}
msg.Headers[FieldReplySerial] = MakeVariant(serial)
msg.Body = values
if len(values) > 0 {
msg.Headers[FieldSignature] = MakeVariant(SignatureOf(values...))
}
conn.sendMessage(msg)
} | go | func (conn *Conn) sendReply(dest string, serial uint32, values ...interface{}) {
msg := new(Message)
msg.Type = TypeMethodReply
msg.serial = conn.getSerial()
msg.Headers = make(map[HeaderField]Variant)
if dest != "" {
msg.Headers[FieldDestination] = MakeVariant(dest)
}
msg.Headers[FieldReplySerial] = MakeVariant(serial)
msg.Body = values
if len(values) > 0 {
msg.Headers[FieldSignature] = MakeVariant(SignatureOf(values...))
}
conn.sendMessage(msg)
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"sendReply",
"(",
"dest",
"string",
",",
"serial",
"uint32",
",",
"values",
"...",
"interface",
"{",
"}",
")",
"{",
"msg",
":=",
"new",
"(",
"Message",
")",
"\n",
"msg",
".",
"Type",
"=",
"TypeMethodReply",
"\n",
"msg",
".",
"serial",
"=",
"conn",
".",
"getSerial",
"(",
")",
"\n",
"msg",
".",
"Headers",
"=",
"make",
"(",
"map",
"[",
"HeaderField",
"]",
"Variant",
")",
"\n",
"if",
"dest",
"!=",
"\"",
"\"",
"{",
"msg",
".",
"Headers",
"[",
"FieldDestination",
"]",
"=",
"MakeVariant",
"(",
"dest",
")",
"\n",
"}",
"\n",
"msg",
".",
"Headers",
"[",
"FieldReplySerial",
"]",
"=",
"MakeVariant",
"(",
"serial",
")",
"\n",
"msg",
".",
"Body",
"=",
"values",
"\n",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"msg",
".",
"Headers",
"[",
"FieldSignature",
"]",
"=",
"MakeVariant",
"(",
"SignatureOf",
"(",
"values",
"...",
")",
")",
"\n",
"}",
"\n",
"conn",
".",
"sendMessage",
"(",
"msg",
")",
"\n",
"}"
] | // sendReply creates a method reply message corresponding to the parameters and
// sends it to conn.out. | [
"sendReply",
"creates",
"a",
"method",
"reply",
"message",
"corresponding",
"to",
"the",
"parameters",
"and",
"sends",
"it",
"to",
"conn",
".",
"out",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L491-L505 |
150,831 | godbus/dbus | conn.go | Signal | func (conn *Conn) Signal(ch chan<- *Signal) {
conn.defaultSignalAction((*defaultSignalHandler).addSignal, ch)
} | go | func (conn *Conn) Signal(ch chan<- *Signal) {
conn.defaultSignalAction((*defaultSignalHandler).addSignal, ch)
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"Signal",
"(",
"ch",
"chan",
"<-",
"*",
"Signal",
")",
"{",
"conn",
".",
"defaultSignalAction",
"(",
"(",
"*",
"defaultSignalHandler",
")",
".",
"addSignal",
",",
"ch",
")",
"\n",
"}"
] | // Signal registers the given channel to be passed all received signal messages.
// The caller has to make sure that ch is sufficiently buffered; if a message
// arrives when a write to c is not possible, it is discarded.
//
// Multiple of these channels can be registered at the same time.
//
// These channels are "overwritten" by Eavesdrop; i.e., if there currently is a
// channel for eavesdropped messages, this channel receives all signals, and
// none of the channels passed to Signal will receive any signals. | [
"Signal",
"registers",
"the",
"given",
"channel",
"to",
"be",
"passed",
"all",
"received",
"signal",
"messages",
".",
"The",
"caller",
"has",
"to",
"make",
"sure",
"that",
"ch",
"is",
"sufficiently",
"buffered",
";",
"if",
"a",
"message",
"arrives",
"when",
"a",
"write",
"to",
"c",
"is",
"not",
"possible",
"it",
"is",
"discarded",
".",
"Multiple",
"of",
"these",
"channels",
"can",
"be",
"registered",
"at",
"the",
"same",
"time",
".",
"These",
"channels",
"are",
"overwritten",
"by",
"Eavesdrop",
";",
"i",
".",
"e",
".",
"if",
"there",
"currently",
"is",
"a",
"channel",
"for",
"eavesdropped",
"messages",
"this",
"channel",
"receives",
"all",
"signals",
"and",
"none",
"of",
"the",
"channels",
"passed",
"to",
"Signal",
"will",
"receive",
"any",
"signals",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L524-L526 |
150,832 | godbus/dbus | conn.go | RemoveSignal | func (conn *Conn) RemoveSignal(ch chan<- *Signal) {
conn.defaultSignalAction((*defaultSignalHandler).removeSignal, ch)
} | go | func (conn *Conn) RemoveSignal(ch chan<- *Signal) {
conn.defaultSignalAction((*defaultSignalHandler).removeSignal, ch)
} | [
"func",
"(",
"conn",
"*",
"Conn",
")",
"RemoveSignal",
"(",
"ch",
"chan",
"<-",
"*",
"Signal",
")",
"{",
"conn",
".",
"defaultSignalAction",
"(",
"(",
"*",
"defaultSignalHandler",
")",
".",
"removeSignal",
",",
"ch",
")",
"\n",
"}"
] | // RemoveSignal removes the given channel from the list of the registered channels. | [
"RemoveSignal",
"removes",
"the",
"given",
"channel",
"from",
"the",
"list",
"of",
"the",
"registered",
"channels",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L529-L531 |
150,833 | godbus/dbus | conn.go | dereferenceAll | func dereferenceAll(vs []interface{}) []interface{} {
for i := range vs {
v := reflect.ValueOf(vs[i])
v = v.Elem()
vs[i] = v.Interface()
}
return vs
} | go | func dereferenceAll(vs []interface{}) []interface{} {
for i := range vs {
v := reflect.ValueOf(vs[i])
v = v.Elem()
vs[i] = v.Interface()
}
return vs
} | [
"func",
"dereferenceAll",
"(",
"vs",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"for",
"i",
":=",
"range",
"vs",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"vs",
"[",
"i",
"]",
")",
"\n",
"v",
"=",
"v",
".",
"Elem",
"(",
")",
"\n",
"vs",
"[",
"i",
"]",
"=",
"v",
".",
"Interface",
"(",
")",
"\n",
"}",
"\n",
"return",
"vs",
"\n",
"}"
] | // dereferenceAll returns a slice that, assuming that vs is a slice of pointers
// of arbitrary types, containes the values that are obtained from dereferencing
// all elements in vs. | [
"dereferenceAll",
"returns",
"a",
"slice",
"that",
"assuming",
"that",
"vs",
"is",
"a",
"slice",
"of",
"pointers",
"of",
"arbitrary",
"types",
"containes",
"the",
"values",
"that",
"are",
"obtained",
"from",
"dereferencing",
"all",
"elements",
"in",
"vs",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L620-L627 |
150,834 | godbus/dbus | conn.go | finalize | func (tracker *callTracker) finalize(sn uint32) {
tracker.lck.Lock()
defer tracker.lck.Unlock()
c, ok := tracker.calls[sn]
if ok {
delete(tracker.calls, sn)
c.ContextCancel()
}
return
} | go | func (tracker *callTracker) finalize(sn uint32) {
tracker.lck.Lock()
defer tracker.lck.Unlock()
c, ok := tracker.calls[sn]
if ok {
delete(tracker.calls, sn)
c.ContextCancel()
}
return
} | [
"func",
"(",
"tracker",
"*",
"callTracker",
")",
"finalize",
"(",
"sn",
"uint32",
")",
"{",
"tracker",
".",
"lck",
".",
"Lock",
"(",
")",
"\n",
"defer",
"tracker",
".",
"lck",
".",
"Unlock",
"(",
")",
"\n",
"c",
",",
"ok",
":=",
"tracker",
".",
"calls",
"[",
"sn",
"]",
"\n",
"if",
"ok",
"{",
"delete",
"(",
"tracker",
".",
"calls",
",",
"sn",
")",
"\n",
"c",
".",
"ContextCancel",
"(",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // finalize was the only func that did not strobe Done | [
"finalize",
"was",
"the",
"only",
"func",
"that",
"did",
"not",
"strobe",
"Done"
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L796-L805 |
150,835 | godbus/dbus | object.go | CallWithContext | func (o *Object) CallWithContext(ctx context.Context, method string, flags Flags, args ...interface{}) *Call {
return <-o.createCall(ctx, method, flags, make(chan *Call, 1), args...).Done
} | go | func (o *Object) CallWithContext(ctx context.Context, method string, flags Flags, args ...interface{}) *Call {
return <-o.createCall(ctx, method, flags, make(chan *Call, 1), args...).Done
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"CallWithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"method",
"string",
",",
"flags",
"Flags",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Call",
"{",
"return",
"<-",
"o",
".",
"createCall",
"(",
"ctx",
",",
"method",
",",
"flags",
",",
"make",
"(",
"chan",
"*",
"Call",
",",
"1",
")",
",",
"args",
"...",
")",
".",
"Done",
"\n",
"}"
] | // CallWithContext acts like Call but takes a context | [
"CallWithContext",
"acts",
"like",
"Call",
"but",
"takes",
"a",
"context"
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/object.go#L37-L39 |
150,836 | godbus/dbus | object.go | GoWithContext | func (o *Object) GoWithContext(ctx context.Context, method string, flags Flags, ch chan *Call, args ...interface{}) *Call {
return o.createCall(ctx, method, flags, ch, args...)
} | go | func (o *Object) GoWithContext(ctx context.Context, method string, flags Flags, ch chan *Call, args ...interface{}) *Call {
return o.createCall(ctx, method, flags, ch, args...)
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"GoWithContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"method",
"string",
",",
"flags",
"Flags",
",",
"ch",
"chan",
"*",
"Call",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Call",
"{",
"return",
"o",
".",
"createCall",
"(",
"ctx",
",",
"method",
",",
"flags",
",",
"ch",
",",
"args",
"...",
")",
"\n",
"}"
] | // GoWithContext acts like Go but takes a context | [
"GoWithContext",
"acts",
"like",
"Go",
"but",
"takes",
"a",
"context"
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/object.go#L119-L121 |
150,837 | godbus/dbus | object.go | GetProperty | func (o *Object) GetProperty(p string) (Variant, error) {
idx := strings.LastIndex(p, ".")
if idx == -1 || idx+1 == len(p) {
return Variant{}, errors.New("dbus: invalid property " + p)
}
iface := p[:idx]
prop := p[idx+1:]
result := Variant{}
err := o.Call("org.freedesktop.DBus.Properties.Get", 0, iface, prop).Store(&result)
if err != nil {
return Variant{}, err
}
return result, nil
} | go | func (o *Object) GetProperty(p string) (Variant, error) {
idx := strings.LastIndex(p, ".")
if idx == -1 || idx+1 == len(p) {
return Variant{}, errors.New("dbus: invalid property " + p)
}
iface := p[:idx]
prop := p[idx+1:]
result := Variant{}
err := o.Call("org.freedesktop.DBus.Properties.Get", 0, iface, prop).Store(&result)
if err != nil {
return Variant{}, err
}
return result, nil
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"GetProperty",
"(",
"p",
"string",
")",
"(",
"Variant",
",",
"error",
")",
"{",
"idx",
":=",
"strings",
".",
"LastIndex",
"(",
"p",
",",
"\"",
"\"",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"||",
"idx",
"+",
"1",
"==",
"len",
"(",
"p",
")",
"{",
"return",
"Variant",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"p",
")",
"\n",
"}",
"\n\n",
"iface",
":=",
"p",
"[",
":",
"idx",
"]",
"\n",
"prop",
":=",
"p",
"[",
"idx",
"+",
"1",
":",
"]",
"\n\n",
"result",
":=",
"Variant",
"{",
"}",
"\n",
"err",
":=",
"o",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"iface",
",",
"prop",
")",
".",
"Store",
"(",
"&",
"result",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Variant",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // GetProperty calls org.freedesktop.DBus.Properties.Get on the given
// object. The property name must be given in interface.member notation. | [
"GetProperty",
"calls",
"org",
".",
"freedesktop",
".",
"DBus",
".",
"Properties",
".",
"Get",
"on",
"the",
"given",
"object",
".",
"The",
"property",
"name",
"must",
"be",
"given",
"in",
"interface",
".",
"member",
"notation",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/object.go#L193-L210 |
150,838 | godbus/dbus | object.go | SetProperty | func (o *Object) SetProperty(p string, v interface{}) error {
idx := strings.LastIndex(p, ".")
if idx == -1 || idx+1 == len(p) {
return errors.New("dbus: invalid property " + p)
}
iface := p[:idx]
prop := p[idx+1:]
return o.Call("org.freedesktop.DBus.Properties.Set", 0, iface, prop, v).Err
} | go | func (o *Object) SetProperty(p string, v interface{}) error {
idx := strings.LastIndex(p, ".")
if idx == -1 || idx+1 == len(p) {
return errors.New("dbus: invalid property " + p)
}
iface := p[:idx]
prop := p[idx+1:]
return o.Call("org.freedesktop.DBus.Properties.Set", 0, iface, prop, v).Err
} | [
"func",
"(",
"o",
"*",
"Object",
")",
"SetProperty",
"(",
"p",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"idx",
":=",
"strings",
".",
"LastIndex",
"(",
"p",
",",
"\"",
"\"",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"||",
"idx",
"+",
"1",
"==",
"len",
"(",
"p",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"p",
")",
"\n",
"}",
"\n\n",
"iface",
":=",
"p",
"[",
":",
"idx",
"]",
"\n",
"prop",
":=",
"p",
"[",
"idx",
"+",
"1",
":",
"]",
"\n\n",
"return",
"o",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"iface",
",",
"prop",
",",
"v",
")",
".",
"Err",
"\n",
"}"
] | // SetProperty calls org.freedesktop.DBus.Properties.Set on the given
// object. The property name must be given in interface.member notation. | [
"SetProperty",
"calls",
"org",
".",
"freedesktop",
".",
"DBus",
".",
"Properties",
".",
"Set",
"on",
"the",
"given",
"object",
".",
"The",
"property",
"name",
"must",
"be",
"given",
"in",
"interface",
".",
"member",
"notation",
"."
] | ade71ed3457e1a2d0edc32a59e718cc523e73b21 | https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/object.go#L214-L224 |
150,839 | hashicorp/go-hclog | hclogvet/buildtag.go | checkBuildTag | func checkBuildTag(name string, data []byte) {
if !vet("buildtags") {
return
}
lines := bytes.SplitAfter(data, nl)
// Determine cutpoint where +build comments are no longer valid.
// They are valid in leading // comments in the file followed by
// a blank line.
var cutoff int
for i, line := range lines {
line = bytes.TrimSpace(line)
if len(line) == 0 {
cutoff = i
continue
}
if bytes.HasPrefix(line, slashSlash) {
continue
}
break
}
for i, line := range lines {
line = bytes.TrimSpace(line)
if !bytes.HasPrefix(line, slashSlash) {
continue
}
text := bytes.TrimSpace(line[2:])
if bytes.HasPrefix(text, plusBuild) {
fields := bytes.Fields(text)
if !bytes.Equal(fields[0], plusBuild) {
// Comment is something like +buildasdf not +build.
fmt.Fprintf(os.Stderr, "%s:%d: possible malformed +build comment\n", name, i+1)
setExit(1)
continue
}
if i >= cutoff {
fmt.Fprintf(os.Stderr, "%s:%d: +build comment must appear before package clause and be followed by a blank line\n", name, i+1)
setExit(1)
continue
}
// Check arguments.
Args:
for _, arg := range fields[1:] {
for _, elem := range strings.Split(string(arg), ",") {
if strings.HasPrefix(elem, "!!") {
fmt.Fprintf(os.Stderr, "%s:%d: invalid double negative in build constraint: %s\n", name, i+1, arg)
setExit(1)
break Args
}
elem = strings.TrimPrefix(elem, "!")
for _, c := range elem {
if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' && c != '.' {
fmt.Fprintf(os.Stderr, "%s:%d: invalid non-alphanumeric build constraint: %s\n", name, i+1, arg)
setExit(1)
break Args
}
}
}
}
continue
}
// Comment with +build but not at beginning.
if bytes.Contains(line, plusBuild) && i < cutoff {
fmt.Fprintf(os.Stderr, "%s:%d: possible malformed +build comment\n", name, i+1)
setExit(1)
continue
}
}
} | go | func checkBuildTag(name string, data []byte) {
if !vet("buildtags") {
return
}
lines := bytes.SplitAfter(data, nl)
// Determine cutpoint where +build comments are no longer valid.
// They are valid in leading // comments in the file followed by
// a blank line.
var cutoff int
for i, line := range lines {
line = bytes.TrimSpace(line)
if len(line) == 0 {
cutoff = i
continue
}
if bytes.HasPrefix(line, slashSlash) {
continue
}
break
}
for i, line := range lines {
line = bytes.TrimSpace(line)
if !bytes.HasPrefix(line, slashSlash) {
continue
}
text := bytes.TrimSpace(line[2:])
if bytes.HasPrefix(text, plusBuild) {
fields := bytes.Fields(text)
if !bytes.Equal(fields[0], plusBuild) {
// Comment is something like +buildasdf not +build.
fmt.Fprintf(os.Stderr, "%s:%d: possible malformed +build comment\n", name, i+1)
setExit(1)
continue
}
if i >= cutoff {
fmt.Fprintf(os.Stderr, "%s:%d: +build comment must appear before package clause and be followed by a blank line\n", name, i+1)
setExit(1)
continue
}
// Check arguments.
Args:
for _, arg := range fields[1:] {
for _, elem := range strings.Split(string(arg), ",") {
if strings.HasPrefix(elem, "!!") {
fmt.Fprintf(os.Stderr, "%s:%d: invalid double negative in build constraint: %s\n", name, i+1, arg)
setExit(1)
break Args
}
elem = strings.TrimPrefix(elem, "!")
for _, c := range elem {
if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' && c != '.' {
fmt.Fprintf(os.Stderr, "%s:%d: invalid non-alphanumeric build constraint: %s\n", name, i+1, arg)
setExit(1)
break Args
}
}
}
}
continue
}
// Comment with +build but not at beginning.
if bytes.Contains(line, plusBuild) && i < cutoff {
fmt.Fprintf(os.Stderr, "%s:%d: possible malformed +build comment\n", name, i+1)
setExit(1)
continue
}
}
} | [
"func",
"checkBuildTag",
"(",
"name",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"{",
"if",
"!",
"vet",
"(",
"\"",
"\"",
")",
"{",
"return",
"\n",
"}",
"\n",
"lines",
":=",
"bytes",
".",
"SplitAfter",
"(",
"data",
",",
"nl",
")",
"\n\n",
"// Determine cutpoint where +build comments are no longer valid.",
"// They are valid in leading // comments in the file followed by",
"// a blank line.",
"var",
"cutoff",
"int",
"\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"line",
"=",
"bytes",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"if",
"len",
"(",
"line",
")",
"==",
"0",
"{",
"cutoff",
"=",
"i",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"bytes",
".",
"HasPrefix",
"(",
"line",
",",
"slashSlash",
")",
"{",
"continue",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"line",
":=",
"range",
"lines",
"{",
"line",
"=",
"bytes",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"if",
"!",
"bytes",
".",
"HasPrefix",
"(",
"line",
",",
"slashSlash",
")",
"{",
"continue",
"\n",
"}",
"\n",
"text",
":=",
"bytes",
".",
"TrimSpace",
"(",
"line",
"[",
"2",
":",
"]",
")",
"\n",
"if",
"bytes",
".",
"HasPrefix",
"(",
"text",
",",
"plusBuild",
")",
"{",
"fields",
":=",
"bytes",
".",
"Fields",
"(",
"text",
")",
"\n",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"fields",
"[",
"0",
"]",
",",
"plusBuild",
")",
"{",
"// Comment is something like +buildasdf not +build.",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"name",
",",
"i",
"+",
"1",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"i",
">=",
"cutoff",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"name",
",",
"i",
"+",
"1",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"// Check arguments.",
"Args",
":",
"for",
"_",
",",
"arg",
":=",
"range",
"fields",
"[",
"1",
":",
"]",
"{",
"for",
"_",
",",
"elem",
":=",
"range",
"strings",
".",
"Split",
"(",
"string",
"(",
"arg",
")",
",",
"\"",
"\"",
")",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"elem",
",",
"\"",
"\"",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"name",
",",
"i",
"+",
"1",
",",
"arg",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"break",
"Args",
"\n",
"}",
"\n",
"elem",
"=",
"strings",
".",
"TrimPrefix",
"(",
"elem",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"elem",
"{",
"if",
"!",
"unicode",
".",
"IsLetter",
"(",
"c",
")",
"&&",
"!",
"unicode",
".",
"IsDigit",
"(",
"c",
")",
"&&",
"c",
"!=",
"'_'",
"&&",
"c",
"!=",
"'.'",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"name",
",",
"i",
"+",
"1",
",",
"arg",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"break",
"Args",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"// Comment with +build but not at beginning.",
"if",
"bytes",
".",
"Contains",
"(",
"line",
",",
"plusBuild",
")",
"&&",
"i",
"<",
"cutoff",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"name",
",",
"i",
"+",
"1",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // checkBuildTag checks that build tags are in the correct location and well-formed. | [
"checkBuildTag",
"checks",
"that",
"build",
"tags",
"are",
"in",
"the",
"correct",
"location",
"and",
"well",
"-",
"formed",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/buildtag.go#L22-L91 |
150,840 | hashicorp/go-hclog | writer.go | NewLeveledWriter | func NewLeveledWriter(standard io.Writer, overrides map[Level]io.Writer) *LeveledWriter {
return &LeveledWriter{
standard: standard,
overrides: overrides,
}
} | go | func NewLeveledWriter(standard io.Writer, overrides map[Level]io.Writer) *LeveledWriter {
return &LeveledWriter{
standard: standard,
overrides: overrides,
}
} | [
"func",
"NewLeveledWriter",
"(",
"standard",
"io",
".",
"Writer",
",",
"overrides",
"map",
"[",
"Level",
"]",
"io",
".",
"Writer",
")",
"*",
"LeveledWriter",
"{",
"return",
"&",
"LeveledWriter",
"{",
"standard",
":",
"standard",
",",
"overrides",
":",
"overrides",
",",
"}",
"\n",
"}"
] | // NewLeveledWriter returns an initialized LeveledWriter.
//
// standard will be used as the default writer for all log levels,
// except for log levels that are defined in the overrides map. | [
"NewLeveledWriter",
"returns",
"an",
"initialized",
"LeveledWriter",
".",
"standard",
"will",
"be",
"used",
"as",
"the",
"default",
"writer",
"for",
"all",
"log",
"levels",
"except",
"for",
"log",
"levels",
"that",
"are",
"defined",
"in",
"the",
"overrides",
"map",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/writer.go#L55-L60 |
150,841 | hashicorp/go-hclog | writer.go | LevelWrite | func (lw *LeveledWriter) LevelWrite(level Level, p []byte) (int, error) {
w, ok := lw.overrides[level]
if !ok {
w = lw.standard
}
return w.Write(p)
} | go | func (lw *LeveledWriter) LevelWrite(level Level, p []byte) (int, error) {
w, ok := lw.overrides[level]
if !ok {
w = lw.standard
}
return w.Write(p)
} | [
"func",
"(",
"lw",
"*",
"LeveledWriter",
")",
"LevelWrite",
"(",
"level",
"Level",
",",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"w",
",",
"ok",
":=",
"lw",
".",
"overrides",
"[",
"level",
"]",
"\n",
"if",
"!",
"ok",
"{",
"w",
"=",
"lw",
".",
"standard",
"\n",
"}",
"\n",
"return",
"w",
".",
"Write",
"(",
"p",
")",
"\n",
"}"
] | // LevelWrite implements LevelWriter. | [
"LevelWrite",
"implements",
"LevelWriter",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/writer.go#L68-L74 |
150,842 | hashicorp/go-hclog | hclogvet/dead.go | updateDead | func (f *File) updateDead(node ast.Node) {
if f.dead[node] {
// The node is already marked as dead.
return
}
switch stmt := node.(type) {
case *ast.IfStmt:
// "if" branch is dead if its condition evaluates
// to constant false.
v := f.pkg.types[stmt.Cond].Value
if v == nil {
return
}
if !constant.BoolVal(v) {
f.setDead(stmt.Body)
return
}
f.setDead(stmt.Else)
case *ast.SwitchStmt:
// Case clause with empty switch tag is dead if it evaluates
// to constant false.
if stmt.Tag == nil {
BodyLoopBool:
for _, stmt := range stmt.Body.List {
cc := stmt.(*ast.CaseClause)
if cc.List == nil {
// Skip default case.
continue
}
for _, expr := range cc.List {
v := f.pkg.types[expr].Value
if v == nil || constant.BoolVal(v) {
continue BodyLoopBool
}
}
f.setDead(cc)
}
return
}
// Case clause is dead if its constant value doesn't match
// the constant value from the switch tag.
// TODO: This handles integer comparisons only.
v := f.pkg.types[stmt.Tag].Value
if v == nil || v.Kind() != constant.Int {
return
}
tagN, ok := constant.Uint64Val(v)
if !ok {
return
}
BodyLoopInt:
for _, x := range stmt.Body.List {
cc := x.(*ast.CaseClause)
if cc.List == nil {
// Skip default case.
continue
}
for _, expr := range cc.List {
v := f.pkg.types[expr].Value
if v == nil {
continue BodyLoopInt
}
n, ok := constant.Uint64Val(v)
if !ok || tagN == n {
continue BodyLoopInt
}
}
f.setDead(cc)
}
}
} | go | func (f *File) updateDead(node ast.Node) {
if f.dead[node] {
// The node is already marked as dead.
return
}
switch stmt := node.(type) {
case *ast.IfStmt:
// "if" branch is dead if its condition evaluates
// to constant false.
v := f.pkg.types[stmt.Cond].Value
if v == nil {
return
}
if !constant.BoolVal(v) {
f.setDead(stmt.Body)
return
}
f.setDead(stmt.Else)
case *ast.SwitchStmt:
// Case clause with empty switch tag is dead if it evaluates
// to constant false.
if stmt.Tag == nil {
BodyLoopBool:
for _, stmt := range stmt.Body.List {
cc := stmt.(*ast.CaseClause)
if cc.List == nil {
// Skip default case.
continue
}
for _, expr := range cc.List {
v := f.pkg.types[expr].Value
if v == nil || constant.BoolVal(v) {
continue BodyLoopBool
}
}
f.setDead(cc)
}
return
}
// Case clause is dead if its constant value doesn't match
// the constant value from the switch tag.
// TODO: This handles integer comparisons only.
v := f.pkg.types[stmt.Tag].Value
if v == nil || v.Kind() != constant.Int {
return
}
tagN, ok := constant.Uint64Val(v)
if !ok {
return
}
BodyLoopInt:
for _, x := range stmt.Body.List {
cc := x.(*ast.CaseClause)
if cc.List == nil {
// Skip default case.
continue
}
for _, expr := range cc.List {
v := f.pkg.types[expr].Value
if v == nil {
continue BodyLoopInt
}
n, ok := constant.Uint64Val(v)
if !ok || tagN == n {
continue BodyLoopInt
}
}
f.setDead(cc)
}
}
} | [
"func",
"(",
"f",
"*",
"File",
")",
"updateDead",
"(",
"node",
"ast",
".",
"Node",
")",
"{",
"if",
"f",
".",
"dead",
"[",
"node",
"]",
"{",
"// The node is already marked as dead.",
"return",
"\n",
"}",
"\n\n",
"switch",
"stmt",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"IfStmt",
":",
"// \"if\" branch is dead if its condition evaluates",
"// to constant false.",
"v",
":=",
"f",
".",
"pkg",
".",
"types",
"[",
"stmt",
".",
"Cond",
"]",
".",
"Value",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"!",
"constant",
".",
"BoolVal",
"(",
"v",
")",
"{",
"f",
".",
"setDead",
"(",
"stmt",
".",
"Body",
")",
"\n",
"return",
"\n",
"}",
"\n",
"f",
".",
"setDead",
"(",
"stmt",
".",
"Else",
")",
"\n",
"case",
"*",
"ast",
".",
"SwitchStmt",
":",
"// Case clause with empty switch tag is dead if it evaluates",
"// to constant false.",
"if",
"stmt",
".",
"Tag",
"==",
"nil",
"{",
"BodyLoopBool",
":",
"for",
"_",
",",
"stmt",
":=",
"range",
"stmt",
".",
"Body",
".",
"List",
"{",
"cc",
":=",
"stmt",
".",
"(",
"*",
"ast",
".",
"CaseClause",
")",
"\n",
"if",
"cc",
".",
"List",
"==",
"nil",
"{",
"// Skip default case.",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"expr",
":=",
"range",
"cc",
".",
"List",
"{",
"v",
":=",
"f",
".",
"pkg",
".",
"types",
"[",
"expr",
"]",
".",
"Value",
"\n",
"if",
"v",
"==",
"nil",
"||",
"constant",
".",
"BoolVal",
"(",
"v",
")",
"{",
"continue",
"BodyLoopBool",
"\n",
"}",
"\n",
"}",
"\n",
"f",
".",
"setDead",
"(",
"cc",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Case clause is dead if its constant value doesn't match",
"// the constant value from the switch tag.",
"// TODO: This handles integer comparisons only.",
"v",
":=",
"f",
".",
"pkg",
".",
"types",
"[",
"stmt",
".",
"Tag",
"]",
".",
"Value",
"\n",
"if",
"v",
"==",
"nil",
"||",
"v",
".",
"Kind",
"(",
")",
"!=",
"constant",
".",
"Int",
"{",
"return",
"\n",
"}",
"\n",
"tagN",
",",
"ok",
":=",
"constant",
".",
"Uint64Val",
"(",
"v",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"BodyLoopInt",
":",
"for",
"_",
",",
"x",
":=",
"range",
"stmt",
".",
"Body",
".",
"List",
"{",
"cc",
":=",
"x",
".",
"(",
"*",
"ast",
".",
"CaseClause",
")",
"\n",
"if",
"cc",
".",
"List",
"==",
"nil",
"{",
"// Skip default case.",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"expr",
":=",
"range",
"cc",
".",
"List",
"{",
"v",
":=",
"f",
".",
"pkg",
".",
"types",
"[",
"expr",
"]",
".",
"Value",
"\n",
"if",
"v",
"==",
"nil",
"{",
"continue",
"BodyLoopInt",
"\n",
"}",
"\n",
"n",
",",
"ok",
":=",
"constant",
".",
"Uint64Val",
"(",
"v",
")",
"\n",
"if",
"!",
"ok",
"||",
"tagN",
"==",
"n",
"{",
"continue",
"BodyLoopInt",
"\n",
"}",
"\n",
"}",
"\n",
"f",
".",
"setDead",
"(",
"cc",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // updateDead puts unreachable "if" and "case" nodes into f.dead. | [
"updateDead",
"puts",
"unreachable",
"if",
"and",
"case",
"nodes",
"into",
"f",
".",
"dead",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/dead.go#L16-L88 |
150,843 | hashicorp/go-hclog | hclogvet/dead.go | setDead | func (f *File) setDead(node ast.Node) {
dv := deadVisitor{
f: f,
}
ast.Walk(dv, node)
} | go | func (f *File) setDead(node ast.Node) {
dv := deadVisitor{
f: f,
}
ast.Walk(dv, node)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"setDead",
"(",
"node",
"ast",
".",
"Node",
")",
"{",
"dv",
":=",
"deadVisitor",
"{",
"f",
":",
"f",
",",
"}",
"\n",
"ast",
".",
"Walk",
"(",
"dv",
",",
"node",
")",
"\n",
"}"
] | // setDead marks the node and all the children as dead. | [
"setDead",
"marks",
"the",
"node",
"and",
"all",
"the",
"children",
"as",
"dead",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/dead.go#L91-L96 |
150,844 | hashicorp/go-hclog | hclogvet/main.go | Usage | func Usage() {
fmt.Fprintf(os.Stderr, "Usage of vet:\n")
fmt.Fprintf(os.Stderr, "\tvet [flags] directory...\n")
fmt.Fprintf(os.Stderr, "\tvet [flags] files... # Must be a single package\n")
fmt.Fprintf(os.Stderr, "By default, -all is set and all non-experimental checks are run.\n")
fmt.Fprintf(os.Stderr, "For more information run\n")
fmt.Fprintf(os.Stderr, "\tgo doc cmd/vet\n\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults()
os.Exit(2)
} | go | func Usage() {
fmt.Fprintf(os.Stderr, "Usage of vet:\n")
fmt.Fprintf(os.Stderr, "\tvet [flags] directory...\n")
fmt.Fprintf(os.Stderr, "\tvet [flags] files... # Must be a single package\n")
fmt.Fprintf(os.Stderr, "By default, -all is set and all non-experimental checks are run.\n")
fmt.Fprintf(os.Stderr, "For more information run\n")
fmt.Fprintf(os.Stderr, "\tgo doc cmd/vet\n\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
flag.PrintDefaults()
os.Exit(2)
} | [
"func",
"Usage",
"(",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\t",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\t",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\t",
"\\n",
"\\n",
"\"",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"flag",
".",
"PrintDefaults",
"(",
")",
"\n",
"os",
".",
"Exit",
"(",
"2",
")",
"\n",
"}"
] | // Usage is a replacement usage function for the flags package. | [
"Usage",
"is",
"a",
"replacement",
"usage",
"function",
"for",
"the",
"flags",
"package",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L173-L183 |
150,845 | hashicorp/go-hclog | hclogvet/main.go | prefixDirectory | func prefixDirectory(directory string, names []string) {
if directory != "." {
for i, name := range names {
names[i] = filepath.Join(directory, name)
}
}
} | go | func prefixDirectory(directory string, names []string) {
if directory != "." {
for i, name := range names {
names[i] = filepath.Join(directory, name)
}
}
} | [
"func",
"prefixDirectory",
"(",
"directory",
"string",
",",
"names",
"[",
"]",
"string",
")",
"{",
"if",
"directory",
"!=",
"\"",
"\"",
"{",
"for",
"i",
",",
"name",
":=",
"range",
"names",
"{",
"names",
"[",
"i",
"]",
"=",
"filepath",
".",
"Join",
"(",
"directory",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // prefixDirectory places the directory name on the beginning of each name in the list. | [
"prefixDirectory",
"places",
"the",
"directory",
"name",
"on",
"the",
"beginning",
"of",
"each",
"name",
"in",
"the",
"list",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L278-L284 |
150,846 | hashicorp/go-hclog | hclogvet/main.go | doPackageCfg | func doPackageCfg(cfgFile string) {
js, err := ioutil.ReadFile(cfgFile)
if err != nil {
errorf("%v", err)
}
if err := json.Unmarshal(js, &vcfg); err != nil {
errorf("parsing vet config %s: %v", cfgFile, err)
}
stdImporter = &vcfg
inittypes()
mustTypecheck = true
doPackage(vcfg.GoFiles, nil)
} | go | func doPackageCfg(cfgFile string) {
js, err := ioutil.ReadFile(cfgFile)
if err != nil {
errorf("%v", err)
}
if err := json.Unmarshal(js, &vcfg); err != nil {
errorf("parsing vet config %s: %v", cfgFile, err)
}
stdImporter = &vcfg
inittypes()
mustTypecheck = true
doPackage(vcfg.GoFiles, nil)
} | [
"func",
"doPackageCfg",
"(",
"cfgFile",
"string",
")",
"{",
"js",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"cfgFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"js",
",",
"&",
"vcfg",
")",
";",
"err",
"!=",
"nil",
"{",
"errorf",
"(",
"\"",
"\"",
",",
"cfgFile",
",",
"err",
")",
"\n",
"}",
"\n",
"stdImporter",
"=",
"&",
"vcfg",
"\n",
"inittypes",
"(",
")",
"\n",
"mustTypecheck",
"=",
"true",
"\n",
"doPackage",
"(",
"vcfg",
".",
"GoFiles",
",",
"nil",
")",
"\n",
"}"
] | // doPackageCfg analyzes a single package described in a config file. | [
"doPackageCfg",
"analyzes",
"a",
"single",
"package",
"described",
"in",
"a",
"config",
"file",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L333-L345 |
150,847 | hashicorp/go-hclog | hclogvet/main.go | doPackageDir | func doPackageDir(directory string) {
context := build.Default
if len(context.BuildTags) != 0 {
warnf("build tags %s previously set", context.BuildTags)
}
context.BuildTags = append(tagList, context.BuildTags...)
pkg, err := context.ImportDir(directory, 0)
if err != nil {
// If it's just that there are no go source files, that's fine.
if _, nogo := err.(*build.NoGoError); nogo {
return
}
// Non-fatal: we are doing a recursive walk and there may be other directories.
warnf("cannot process directory %s: %s", directory, err)
return
}
var names []string
names = append(names, pkg.GoFiles...)
names = append(names, pkg.CgoFiles...)
names = append(names, pkg.TestGoFiles...) // These are also in the "foo" package.
names = append(names, pkg.SFiles...)
prefixDirectory(directory, names)
basePkg := doPackage(names, nil)
// Is there also a "foo_test" package? If so, do that one as well.
if len(pkg.XTestGoFiles) > 0 {
names = pkg.XTestGoFiles
prefixDirectory(directory, names)
doPackage(names, basePkg)
}
} | go | func doPackageDir(directory string) {
context := build.Default
if len(context.BuildTags) != 0 {
warnf("build tags %s previously set", context.BuildTags)
}
context.BuildTags = append(tagList, context.BuildTags...)
pkg, err := context.ImportDir(directory, 0)
if err != nil {
// If it's just that there are no go source files, that's fine.
if _, nogo := err.(*build.NoGoError); nogo {
return
}
// Non-fatal: we are doing a recursive walk and there may be other directories.
warnf("cannot process directory %s: %s", directory, err)
return
}
var names []string
names = append(names, pkg.GoFiles...)
names = append(names, pkg.CgoFiles...)
names = append(names, pkg.TestGoFiles...) // These are also in the "foo" package.
names = append(names, pkg.SFiles...)
prefixDirectory(directory, names)
basePkg := doPackage(names, nil)
// Is there also a "foo_test" package? If so, do that one as well.
if len(pkg.XTestGoFiles) > 0 {
names = pkg.XTestGoFiles
prefixDirectory(directory, names)
doPackage(names, basePkg)
}
} | [
"func",
"doPackageDir",
"(",
"directory",
"string",
")",
"{",
"context",
":=",
"build",
".",
"Default",
"\n",
"if",
"len",
"(",
"context",
".",
"BuildTags",
")",
"!=",
"0",
"{",
"warnf",
"(",
"\"",
"\"",
",",
"context",
".",
"BuildTags",
")",
"\n",
"}",
"\n",
"context",
".",
"BuildTags",
"=",
"append",
"(",
"tagList",
",",
"context",
".",
"BuildTags",
"...",
")",
"\n\n",
"pkg",
",",
"err",
":=",
"context",
".",
"ImportDir",
"(",
"directory",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// If it's just that there are no go source files, that's fine.",
"if",
"_",
",",
"nogo",
":=",
"err",
".",
"(",
"*",
"build",
".",
"NoGoError",
")",
";",
"nogo",
"{",
"return",
"\n",
"}",
"\n",
"// Non-fatal: we are doing a recursive walk and there may be other directories.",
"warnf",
"(",
"\"",
"\"",
",",
"directory",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"var",
"names",
"[",
"]",
"string",
"\n",
"names",
"=",
"append",
"(",
"names",
",",
"pkg",
".",
"GoFiles",
"...",
")",
"\n",
"names",
"=",
"append",
"(",
"names",
",",
"pkg",
".",
"CgoFiles",
"...",
")",
"\n",
"names",
"=",
"append",
"(",
"names",
",",
"pkg",
".",
"TestGoFiles",
"...",
")",
"// These are also in the \"foo\" package.",
"\n",
"names",
"=",
"append",
"(",
"names",
",",
"pkg",
".",
"SFiles",
"...",
")",
"\n",
"prefixDirectory",
"(",
"directory",
",",
"names",
")",
"\n",
"basePkg",
":=",
"doPackage",
"(",
"names",
",",
"nil",
")",
"\n",
"// Is there also a \"foo_test\" package? If so, do that one as well.",
"if",
"len",
"(",
"pkg",
".",
"XTestGoFiles",
")",
">",
"0",
"{",
"names",
"=",
"pkg",
".",
"XTestGoFiles",
"\n",
"prefixDirectory",
"(",
"directory",
",",
"names",
")",
"\n",
"doPackage",
"(",
"names",
",",
"basePkg",
")",
"\n",
"}",
"\n",
"}"
] | // doPackageDir analyzes the single package found in the directory, if there is one,
// plus a test package, if there is one. | [
"doPackageDir",
"analyzes",
"the",
"single",
"package",
"found",
"in",
"the",
"directory",
"if",
"there",
"is",
"one",
"plus",
"a",
"test",
"package",
"if",
"there",
"is",
"one",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L349-L379 |
150,848 | hashicorp/go-hclog | hclogvet/main.go | doPackage | func doPackage(names []string, basePkg *Package) *Package {
var files []*File
var astFiles []*ast.File
fs := token.NewFileSet()
for _, name := range names {
data, err := ioutil.ReadFile(name)
if err != nil {
// Warn but continue to next package.
warnf("%s: %s", name, err)
return nil
}
checkBuildTag(name, data)
var parsedFile *ast.File
if strings.HasSuffix(name, ".go") {
parsedFile, err = parser.ParseFile(fs, name, data, 0)
if err != nil {
warnf("%s: %s", name, err)
return nil
}
astFiles = append(astFiles, parsedFile)
}
files = append(files, &File{
fset: fs,
content: data,
name: name,
file: parsedFile,
dead: make(map[ast.Node]bool),
})
}
if len(astFiles) == 0 {
return nil
}
pkg := new(Package)
pkg.path = astFiles[0].Name.Name
pkg.files = files
// Type check the package.
errs := pkg.check(fs, astFiles)
if errs != nil {
if vcfg.SucceedOnTypecheckFailure {
os.Exit(0)
}
if *verbose || mustTypecheck {
for _, err := range errs {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
if mustTypecheck {
// This message could be silenced, and we could just exit,
// but it might be helpful at least at first to make clear that the
// above errors are coming from vet and not the compiler
// (they often look like compiler errors, such as "declared but not used").
errorf("typecheck failures")
}
}
}
// Check.
chk := make(map[ast.Node][]func(*File, ast.Node))
for typ, set := range checkers {
for name, fn := range set {
if vet(name) {
chk[typ] = append(chk[typ], fn)
}
}
}
for _, file := range files {
file.pkg = pkg
file.basePkg = basePkg
file.checkers = chk
if file.file != nil {
file.walkFile(file.name, file.file)
}
}
return pkg
} | go | func doPackage(names []string, basePkg *Package) *Package {
var files []*File
var astFiles []*ast.File
fs := token.NewFileSet()
for _, name := range names {
data, err := ioutil.ReadFile(name)
if err != nil {
// Warn but continue to next package.
warnf("%s: %s", name, err)
return nil
}
checkBuildTag(name, data)
var parsedFile *ast.File
if strings.HasSuffix(name, ".go") {
parsedFile, err = parser.ParseFile(fs, name, data, 0)
if err != nil {
warnf("%s: %s", name, err)
return nil
}
astFiles = append(astFiles, parsedFile)
}
files = append(files, &File{
fset: fs,
content: data,
name: name,
file: parsedFile,
dead: make(map[ast.Node]bool),
})
}
if len(astFiles) == 0 {
return nil
}
pkg := new(Package)
pkg.path = astFiles[0].Name.Name
pkg.files = files
// Type check the package.
errs := pkg.check(fs, astFiles)
if errs != nil {
if vcfg.SucceedOnTypecheckFailure {
os.Exit(0)
}
if *verbose || mustTypecheck {
for _, err := range errs {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
if mustTypecheck {
// This message could be silenced, and we could just exit,
// but it might be helpful at least at first to make clear that the
// above errors are coming from vet and not the compiler
// (they often look like compiler errors, such as "declared but not used").
errorf("typecheck failures")
}
}
}
// Check.
chk := make(map[ast.Node][]func(*File, ast.Node))
for typ, set := range checkers {
for name, fn := range set {
if vet(name) {
chk[typ] = append(chk[typ], fn)
}
}
}
for _, file := range files {
file.pkg = pkg
file.basePkg = basePkg
file.checkers = chk
if file.file != nil {
file.walkFile(file.name, file.file)
}
}
return pkg
} | [
"func",
"doPackage",
"(",
"names",
"[",
"]",
"string",
",",
"basePkg",
"*",
"Package",
")",
"*",
"Package",
"{",
"var",
"files",
"[",
"]",
"*",
"File",
"\n",
"var",
"astFiles",
"[",
"]",
"*",
"ast",
".",
"File",
"\n",
"fs",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Warn but continue to next package.",
"warnf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"checkBuildTag",
"(",
"name",
",",
"data",
")",
"\n",
"var",
"parsedFile",
"*",
"ast",
".",
"File",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"name",
",",
"\"",
"\"",
")",
"{",
"parsedFile",
",",
"err",
"=",
"parser",
".",
"ParseFile",
"(",
"fs",
",",
"name",
",",
"data",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"warnf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"astFiles",
"=",
"append",
"(",
"astFiles",
",",
"parsedFile",
")",
"\n",
"}",
"\n",
"files",
"=",
"append",
"(",
"files",
",",
"&",
"File",
"{",
"fset",
":",
"fs",
",",
"content",
":",
"data",
",",
"name",
":",
"name",
",",
"file",
":",
"parsedFile",
",",
"dead",
":",
"make",
"(",
"map",
"[",
"ast",
".",
"Node",
"]",
"bool",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"astFiles",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"pkg",
":=",
"new",
"(",
"Package",
")",
"\n",
"pkg",
".",
"path",
"=",
"astFiles",
"[",
"0",
"]",
".",
"Name",
".",
"Name",
"\n",
"pkg",
".",
"files",
"=",
"files",
"\n",
"// Type check the package.",
"errs",
":=",
"pkg",
".",
"check",
"(",
"fs",
",",
"astFiles",
")",
"\n",
"if",
"errs",
"!=",
"nil",
"{",
"if",
"vcfg",
".",
"SucceedOnTypecheckFailure",
"{",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n",
"if",
"*",
"verbose",
"||",
"mustTypecheck",
"{",
"for",
"_",
",",
"err",
":=",
"range",
"errs",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"mustTypecheck",
"{",
"// This message could be silenced, and we could just exit,",
"// but it might be helpful at least at first to make clear that the",
"// above errors are coming from vet and not the compiler",
"// (they often look like compiler errors, such as \"declared but not used\").",
"errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Check.",
"chk",
":=",
"make",
"(",
"map",
"[",
"ast",
".",
"Node",
"]",
"[",
"]",
"func",
"(",
"*",
"File",
",",
"ast",
".",
"Node",
")",
")",
"\n",
"for",
"typ",
",",
"set",
":=",
"range",
"checkers",
"{",
"for",
"name",
",",
"fn",
":=",
"range",
"set",
"{",
"if",
"vet",
"(",
"name",
")",
"{",
"chk",
"[",
"typ",
"]",
"=",
"append",
"(",
"chk",
"[",
"typ",
"]",
",",
"fn",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"file",
":=",
"range",
"files",
"{",
"file",
".",
"pkg",
"=",
"pkg",
"\n",
"file",
".",
"basePkg",
"=",
"basePkg",
"\n",
"file",
".",
"checkers",
"=",
"chk",
"\n",
"if",
"file",
".",
"file",
"!=",
"nil",
"{",
"file",
".",
"walkFile",
"(",
"file",
".",
"name",
",",
"file",
".",
"file",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"pkg",
"\n",
"}"
] | // doPackage analyzes the single package constructed from the named files.
// It returns the parsed Package or nil if none of the files have been checked. | [
"doPackage",
"analyzes",
"the",
"single",
"package",
"constructed",
"from",
"the",
"named",
"files",
".",
"It",
"returns",
"the",
"parsed",
"Package",
"or",
"nil",
"if",
"none",
"of",
"the",
"files",
"have",
"been",
"checked",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L394-L467 |
150,849 | hashicorp/go-hclog | hclogvet/main.go | warnf | func warnf(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "vet: "+format+"\n", args...)
setExit(1)
} | go | func warnf(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "vet: "+format+"\n", args...)
setExit(1)
} | [
"func",
"warnf",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
"+",
"format",
"+",
"\"",
"\\n",
"\"",
",",
"args",
"...",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"}"
] | // warnf formats the error to standard error, adding program
// identification and a newline, but does not exit. | [
"warnf",
"formats",
"the",
"error",
"to",
"standard",
"error",
"adding",
"program",
"identification",
"and",
"a",
"newline",
"but",
"does",
"not",
"exit",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L505-L508 |
150,850 | hashicorp/go-hclog | hclogvet/main.go | Bad | func (f *File) Bad(pos token.Pos, args ...interface{}) {
f.Warn(pos, args...)
setExit(1)
} | go | func (f *File) Bad(pos token.Pos, args ...interface{}) {
f.Warn(pos, args...)
setExit(1)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Bad",
"(",
"pos",
"token",
".",
"Pos",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
".",
"Warn",
"(",
"pos",
",",
"args",
"...",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"}"
] | // Bad reports an error and sets the exit code.. | [
"Bad",
"reports",
"an",
"error",
"and",
"sets",
"the",
"exit",
"code",
".."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L527-L530 |
150,851 | hashicorp/go-hclog | hclogvet/main.go | Badf | func (f *File) Badf(pos token.Pos, format string, args ...interface{}) {
f.Warnf(pos, format, args...)
setExit(1)
} | go | func (f *File) Badf(pos token.Pos, format string, args ...interface{}) {
f.Warnf(pos, format, args...)
setExit(1)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Badf",
"(",
"pos",
"token",
".",
"Pos",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"f",
".",
"Warnf",
"(",
"pos",
",",
"format",
",",
"args",
"...",
")",
"\n",
"setExit",
"(",
"1",
")",
"\n",
"}"
] | // Badf reports a formatted error and sets the exit code. | [
"Badf",
"reports",
"a",
"formatted",
"error",
"and",
"sets",
"the",
"exit",
"code",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L533-L536 |
150,852 | hashicorp/go-hclog | hclogvet/main.go | loc | func (f *File) loc(pos token.Pos) string {
if pos == token.NoPos {
return ""
}
// Do not print columns. Because the pos often points to the start of an
// expression instead of the inner part with the actual error, the
// precision can mislead.
posn := f.fset.Position(pos)
return fmt.Sprintf("%s:%d", posn.Filename, posn.Line)
} | go | func (f *File) loc(pos token.Pos) string {
if pos == token.NoPos {
return ""
}
// Do not print columns. Because the pos often points to the start of an
// expression instead of the inner part with the actual error, the
// precision can mislead.
posn := f.fset.Position(pos)
return fmt.Sprintf("%s:%d", posn.Filename, posn.Line)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"loc",
"(",
"pos",
"token",
".",
"Pos",
")",
"string",
"{",
"if",
"pos",
"==",
"token",
".",
"NoPos",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"// Do not print columns. Because the pos often points to the start of an",
"// expression instead of the inner part with the actual error, the",
"// precision can mislead.",
"posn",
":=",
"f",
".",
"fset",
".",
"Position",
"(",
"pos",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"posn",
".",
"Filename",
",",
"posn",
".",
"Line",
")",
"\n",
"}"
] | // loc returns a formatted representation of the position. | [
"loc",
"returns",
"a",
"formatted",
"representation",
"of",
"the",
"position",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L539-L548 |
150,853 | hashicorp/go-hclog | hclogvet/main.go | locPrefix | func (f *File) locPrefix(pos token.Pos) string {
if pos == token.NoPos {
return ""
}
return fmt.Sprintf("%s: ", f.loc(pos))
} | go | func (f *File) locPrefix(pos token.Pos) string {
if pos == token.NoPos {
return ""
}
return fmt.Sprintf("%s: ", f.loc(pos))
} | [
"func",
"(",
"f",
"*",
"File",
")",
"locPrefix",
"(",
"pos",
"token",
".",
"Pos",
")",
"string",
"{",
"if",
"pos",
"==",
"token",
".",
"NoPos",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f",
".",
"loc",
"(",
"pos",
")",
")",
"\n",
"}"
] | // locPrefix returns a formatted representation of the position for use as a line prefix. | [
"locPrefix",
"returns",
"a",
"formatted",
"representation",
"of",
"the",
"position",
"for",
"use",
"as",
"a",
"line",
"prefix",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L551-L556 |
150,854 | hashicorp/go-hclog | hclogvet/main.go | Warn | func (f *File) Warn(pos token.Pos, args ...interface{}) {
fmt.Fprintf(os.Stderr, "%s%s", f.locPrefix(pos), fmt.Sprintln(args...))
} | go | func (f *File) Warn(pos token.Pos, args ...interface{}) {
fmt.Fprintf(os.Stderr, "%s%s", f.locPrefix(pos), fmt.Sprintln(args...))
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Warn",
"(",
"pos",
"token",
".",
"Pos",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"f",
".",
"locPrefix",
"(",
"pos",
")",
",",
"fmt",
".",
"Sprintln",
"(",
"args",
"...",
")",
")",
"\n",
"}"
] | // Warn reports an error but does not set the exit code. | [
"Warn",
"reports",
"an",
"error",
"but",
"does",
"not",
"set",
"the",
"exit",
"code",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L559-L561 |
150,855 | hashicorp/go-hclog | hclogvet/main.go | Warnf | func (f *File) Warnf(pos token.Pos, format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "%s%s\n", f.locPrefix(pos), fmt.Sprintf(format, args...))
} | go | func (f *File) Warnf(pos token.Pos, format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "%s%s\n", f.locPrefix(pos), fmt.Sprintf(format, args...))
} | [
"func",
"(",
"f",
"*",
"File",
")",
"Warnf",
"(",
"pos",
"token",
".",
"Pos",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"f",
".",
"locPrefix",
"(",
"pos",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
")",
"\n",
"}"
] | // Warnf reports a formatted error but does not set the exit code. | [
"Warnf",
"reports",
"a",
"formatted",
"error",
"but",
"does",
"not",
"set",
"the",
"exit",
"code",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L564-L566 |
150,856 | hashicorp/go-hclog | hclogvet/main.go | walkFile | func (f *File) walkFile(name string, file *ast.File) {
Println("Checking file", name)
ast.Walk(f, file)
} | go | func (f *File) walkFile(name string, file *ast.File) {
Println("Checking file", name)
ast.Walk(f, file)
} | [
"func",
"(",
"f",
"*",
"File",
")",
"walkFile",
"(",
"name",
"string",
",",
"file",
"*",
"ast",
".",
"File",
")",
"{",
"Println",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"ast",
".",
"Walk",
"(",
"f",
",",
"file",
")",
"\n",
"}"
] | // walkFile walks the file's tree. | [
"walkFile",
"walks",
"the",
"file",
"s",
"tree",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L569-L572 |
150,857 | hashicorp/go-hclog | hclogvet/main.go | gofmt | func (f *File) gofmt(x ast.Expr) string {
f.b.Reset()
printer.Fprint(&f.b, f.fset, x)
return f.b.String()
} | go | func (f *File) gofmt(x ast.Expr) string {
f.b.Reset()
printer.Fprint(&f.b, f.fset, x)
return f.b.String()
} | [
"func",
"(",
"f",
"*",
"File",
")",
"gofmt",
"(",
"x",
"ast",
".",
"Expr",
")",
"string",
"{",
"f",
".",
"b",
".",
"Reset",
"(",
")",
"\n",
"printer",
".",
"Fprint",
"(",
"&",
"f",
".",
"b",
",",
"f",
".",
"fset",
",",
"x",
")",
"\n",
"return",
"f",
".",
"b",
".",
"String",
"(",
")",
"\n",
"}"
] | // gofmt returns a string representation of the expression. | [
"gofmt",
"returns",
"a",
"string",
"representation",
"of",
"the",
"expression",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/main.go#L613-L617 |
150,858 | hashicorp/go-hclog | intlogger.go | New | func New(opts *LoggerOptions) Logger {
if opts == nil {
opts = &LoggerOptions{}
}
output := opts.Output
if output == nil {
output = DefaultOutput
}
level := opts.Level
if level == NoLevel {
level = DefaultLevel
}
mutex := opts.Mutex
if mutex == nil {
mutex = new(sync.Mutex)
}
l := &intLogger{
json: opts.JSONFormat,
caller: opts.IncludeLocation,
name: opts.Name,
timeFormat: TimeFormat,
mutex: mutex,
writer: newWriter(output),
level: new(int32),
}
if opts.TimeFormat != "" {
l.timeFormat = opts.TimeFormat
}
atomic.StoreInt32(l.level, int32(level))
return l
} | go | func New(opts *LoggerOptions) Logger {
if opts == nil {
opts = &LoggerOptions{}
}
output := opts.Output
if output == nil {
output = DefaultOutput
}
level := opts.Level
if level == NoLevel {
level = DefaultLevel
}
mutex := opts.Mutex
if mutex == nil {
mutex = new(sync.Mutex)
}
l := &intLogger{
json: opts.JSONFormat,
caller: opts.IncludeLocation,
name: opts.Name,
timeFormat: TimeFormat,
mutex: mutex,
writer: newWriter(output),
level: new(int32),
}
if opts.TimeFormat != "" {
l.timeFormat = opts.TimeFormat
}
atomic.StoreInt32(l.level, int32(level))
return l
} | [
"func",
"New",
"(",
"opts",
"*",
"LoggerOptions",
")",
"Logger",
"{",
"if",
"opts",
"==",
"nil",
"{",
"opts",
"=",
"&",
"LoggerOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"output",
":=",
"opts",
".",
"Output",
"\n",
"if",
"output",
"==",
"nil",
"{",
"output",
"=",
"DefaultOutput",
"\n",
"}",
"\n\n",
"level",
":=",
"opts",
".",
"Level",
"\n",
"if",
"level",
"==",
"NoLevel",
"{",
"level",
"=",
"DefaultLevel",
"\n",
"}",
"\n\n",
"mutex",
":=",
"opts",
".",
"Mutex",
"\n",
"if",
"mutex",
"==",
"nil",
"{",
"mutex",
"=",
"new",
"(",
"sync",
".",
"Mutex",
")",
"\n",
"}",
"\n\n",
"l",
":=",
"&",
"intLogger",
"{",
"json",
":",
"opts",
".",
"JSONFormat",
",",
"caller",
":",
"opts",
".",
"IncludeLocation",
",",
"name",
":",
"opts",
".",
"Name",
",",
"timeFormat",
":",
"TimeFormat",
",",
"mutex",
":",
"mutex",
",",
"writer",
":",
"newWriter",
"(",
"output",
")",
",",
"level",
":",
"new",
"(",
"int32",
")",
",",
"}",
"\n\n",
"if",
"opts",
".",
"TimeFormat",
"!=",
"\"",
"\"",
"{",
"l",
".",
"timeFormat",
"=",
"opts",
".",
"TimeFormat",
"\n",
"}",
"\n\n",
"atomic",
".",
"StoreInt32",
"(",
"l",
".",
"level",
",",
"int32",
"(",
"level",
")",
")",
"\n\n",
"return",
"l",
"\n",
"}"
] | // New returns a configured logger. | [
"New",
"returns",
"a",
"configured",
"logger",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L58-L95 |
150,859 | hashicorp/go-hclog | intlogger.go | trimCallerPath | func trimCallerPath(path string) string {
// lovely borrowed from zap
// nb. To make sure we trim the path correctly on Windows too, we
// counter-intuitively need to use '/' and *not* os.PathSeparator here,
// because the path given originates from Go stdlib, specifically
// runtime.Caller() which (as of Mar/17) returns forward slashes even on
// Windows.
//
// See https://github.com/golang/go/issues/3335
// and https://github.com/golang/go/issues/18151
//
// for discussion on the issue on Go side.
// Find the last separator.
idx := strings.LastIndexByte(path, '/')
if idx == -1 {
return path
}
// Find the penultimate separator.
idx = strings.LastIndexByte(path[:idx], '/')
if idx == -1 {
return path
}
return path[idx+1:]
} | go | func trimCallerPath(path string) string {
// lovely borrowed from zap
// nb. To make sure we trim the path correctly on Windows too, we
// counter-intuitively need to use '/' and *not* os.PathSeparator here,
// because the path given originates from Go stdlib, specifically
// runtime.Caller() which (as of Mar/17) returns forward slashes even on
// Windows.
//
// See https://github.com/golang/go/issues/3335
// and https://github.com/golang/go/issues/18151
//
// for discussion on the issue on Go side.
// Find the last separator.
idx := strings.LastIndexByte(path, '/')
if idx == -1 {
return path
}
// Find the penultimate separator.
idx = strings.LastIndexByte(path[:idx], '/')
if idx == -1 {
return path
}
return path[idx+1:]
} | [
"func",
"trimCallerPath",
"(",
"path",
"string",
")",
"string",
"{",
"// lovely borrowed from zap",
"// nb. To make sure we trim the path correctly on Windows too, we",
"// counter-intuitively need to use '/' and *not* os.PathSeparator here,",
"// because the path given originates from Go stdlib, specifically",
"// runtime.Caller() which (as of Mar/17) returns forward slashes even on",
"// Windows.",
"//",
"// See https://github.com/golang/go/issues/3335",
"// and https://github.com/golang/go/issues/18151",
"//",
"// for discussion on the issue on Go side.",
"// Find the last separator.",
"idx",
":=",
"strings",
".",
"LastIndexByte",
"(",
"path",
",",
"'/'",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"{",
"return",
"path",
"\n",
"}",
"\n\n",
"// Find the penultimate separator.",
"idx",
"=",
"strings",
".",
"LastIndexByte",
"(",
"path",
"[",
":",
"idx",
"]",
",",
"'/'",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"{",
"return",
"path",
"\n",
"}",
"\n\n",
"return",
"path",
"[",
"idx",
"+",
"1",
":",
"]",
"\n",
"}"
] | // Cleanup a path by returning the last 2 segments of the path only. | [
"Cleanup",
"a",
"path",
"by",
"returning",
"the",
"last",
"2",
"segments",
"of",
"the",
"path",
"only",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L119-L145 |
150,860 | hashicorp/go-hclog | intlogger.go | logJSON | func (l *intLogger) logJSON(t time.Time, level Level, msg string, args ...interface{}) {
vals := l.jsonMapEntry(t, level, msg)
args = append(l.implied, args...)
if args != nil && len(args) > 0 {
if len(args)%2 != 0 {
cs, ok := args[len(args)-1].(CapturedStacktrace)
if ok {
args = args[:len(args)-1]
vals["stacktrace"] = cs
} else {
args = append(args, "<unknown>")
}
}
for i := 0; i < len(args); i = i + 2 {
if _, ok := args[i].(string); !ok {
// As this is the logging function not much we can do here
// without injecting into logs...
continue
}
val := args[i+1]
switch sv := val.(type) {
case error:
// Check if val is of type error. If error type doesn't
// implement json.Marshaler or encoding.TextMarshaler
// then set val to err.Error() so that it gets marshaled
switch sv.(type) {
case json.Marshaler, encoding.TextMarshaler:
default:
val = sv.Error()
}
case Format:
val = fmt.Sprintf(sv[0].(string), sv[1:]...)
}
vals[args[i].(string)] = val
}
}
err := json.NewEncoder(l.writer).Encode(vals)
if err != nil {
if _, ok := err.(*json.UnsupportedTypeError); ok {
plainVal := l.jsonMapEntry(t, level, msg)
plainVal["@warn"] = errJsonUnsupportedTypeMsg
json.NewEncoder(l.writer).Encode(plainVal)
}
}
} | go | func (l *intLogger) logJSON(t time.Time, level Level, msg string, args ...interface{}) {
vals := l.jsonMapEntry(t, level, msg)
args = append(l.implied, args...)
if args != nil && len(args) > 0 {
if len(args)%2 != 0 {
cs, ok := args[len(args)-1].(CapturedStacktrace)
if ok {
args = args[:len(args)-1]
vals["stacktrace"] = cs
} else {
args = append(args, "<unknown>")
}
}
for i := 0; i < len(args); i = i + 2 {
if _, ok := args[i].(string); !ok {
// As this is the logging function not much we can do here
// without injecting into logs...
continue
}
val := args[i+1]
switch sv := val.(type) {
case error:
// Check if val is of type error. If error type doesn't
// implement json.Marshaler or encoding.TextMarshaler
// then set val to err.Error() so that it gets marshaled
switch sv.(type) {
case json.Marshaler, encoding.TextMarshaler:
default:
val = sv.Error()
}
case Format:
val = fmt.Sprintf(sv[0].(string), sv[1:]...)
}
vals[args[i].(string)] = val
}
}
err := json.NewEncoder(l.writer).Encode(vals)
if err != nil {
if _, ok := err.(*json.UnsupportedTypeError); ok {
plainVal := l.jsonMapEntry(t, level, msg)
plainVal["@warn"] = errJsonUnsupportedTypeMsg
json.NewEncoder(l.writer).Encode(plainVal)
}
}
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"logJSON",
"(",
"t",
"time",
".",
"Time",
",",
"level",
"Level",
",",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"vals",
":=",
"l",
".",
"jsonMapEntry",
"(",
"t",
",",
"level",
",",
"msg",
")",
"\n",
"args",
"=",
"append",
"(",
"l",
".",
"implied",
",",
"args",
"...",
")",
"\n\n",
"if",
"args",
"!=",
"nil",
"&&",
"len",
"(",
"args",
")",
">",
"0",
"{",
"if",
"len",
"(",
"args",
")",
"%",
"2",
"!=",
"0",
"{",
"cs",
",",
"ok",
":=",
"args",
"[",
"len",
"(",
"args",
")",
"-",
"1",
"]",
".",
"(",
"CapturedStacktrace",
")",
"\n",
"if",
"ok",
"{",
"args",
"=",
"args",
"[",
":",
"len",
"(",
"args",
")",
"-",
"1",
"]",
"\n",
"vals",
"[",
"\"",
"\"",
"]",
"=",
"cs",
"\n",
"}",
"else",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"args",
")",
";",
"i",
"=",
"i",
"+",
"2",
"{",
"if",
"_",
",",
"ok",
":=",
"args",
"[",
"i",
"]",
".",
"(",
"string",
")",
";",
"!",
"ok",
"{",
"// As this is the logging function not much we can do here",
"// without injecting into logs...",
"continue",
"\n",
"}",
"\n",
"val",
":=",
"args",
"[",
"i",
"+",
"1",
"]",
"\n",
"switch",
"sv",
":=",
"val",
".",
"(",
"type",
")",
"{",
"case",
"error",
":",
"// Check if val is of type error. If error type doesn't",
"// implement json.Marshaler or encoding.TextMarshaler",
"// then set val to err.Error() so that it gets marshaled",
"switch",
"sv",
".",
"(",
"type",
")",
"{",
"case",
"json",
".",
"Marshaler",
",",
"encoding",
".",
"TextMarshaler",
":",
"default",
":",
"val",
"=",
"sv",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"case",
"Format",
":",
"val",
"=",
"fmt",
".",
"Sprintf",
"(",
"sv",
"[",
"0",
"]",
".",
"(",
"string",
")",
",",
"sv",
"[",
"1",
":",
"]",
"...",
")",
"\n",
"}",
"\n\n",
"vals",
"[",
"args",
"[",
"i",
"]",
".",
"(",
"string",
")",
"]",
"=",
"val",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
":=",
"json",
".",
"NewEncoder",
"(",
"l",
".",
"writer",
")",
".",
"Encode",
"(",
"vals",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"_",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"json",
".",
"UnsupportedTypeError",
")",
";",
"ok",
"{",
"plainVal",
":=",
"l",
".",
"jsonMapEntry",
"(",
"t",
",",
"level",
",",
"msg",
")",
"\n",
"plainVal",
"[",
"\"",
"\"",
"]",
"=",
"errJsonUnsupportedTypeMsg",
"\n\n",
"json",
".",
"NewEncoder",
"(",
"l",
".",
"writer",
")",
".",
"Encode",
"(",
"plainVal",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // JSON logging function | [
"JSON",
"logging",
"function"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L301-L350 |
150,861 | hashicorp/go-hclog | intlogger.go | Debug | func (l *intLogger) Debug(msg string, args ...interface{}) {
l.Log(Debug, msg, args...)
} | go | func (l *intLogger) Debug(msg string, args ...interface{}) {
l.Log(Debug, msg, args...)
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"Debug",
"(",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Log",
"(",
"Debug",
",",
"msg",
",",
"args",
"...",
")",
"\n",
"}"
] | // Emit the message and args at DEBUG level | [
"Emit",
"the",
"message",
"and",
"args",
"at",
"DEBUG",
"level"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L389-L391 |
150,862 | hashicorp/go-hclog | intlogger.go | Trace | func (l *intLogger) Trace(msg string, args ...interface{}) {
l.Log(Trace, msg, args...)
} | go | func (l *intLogger) Trace(msg string, args ...interface{}) {
l.Log(Trace, msg, args...)
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"Trace",
"(",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Log",
"(",
"Trace",
",",
"msg",
",",
"args",
"...",
")",
"\n",
"}"
] | // Emit the message and args at TRACE level | [
"Emit",
"the",
"message",
"and",
"args",
"at",
"TRACE",
"level"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L394-L396 |
150,863 | hashicorp/go-hclog | intlogger.go | Info | func (l *intLogger) Info(msg string, args ...interface{}) {
l.Log(Info, msg, args...)
} | go | func (l *intLogger) Info(msg string, args ...interface{}) {
l.Log(Info, msg, args...)
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"Info",
"(",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Log",
"(",
"Info",
",",
"msg",
",",
"args",
"...",
")",
"\n",
"}"
] | // Emit the message and args at INFO level | [
"Emit",
"the",
"message",
"and",
"args",
"at",
"INFO",
"level"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L399-L401 |
150,864 | hashicorp/go-hclog | intlogger.go | Warn | func (l *intLogger) Warn(msg string, args ...interface{}) {
l.Log(Warn, msg, args...)
} | go | func (l *intLogger) Warn(msg string, args ...interface{}) {
l.Log(Warn, msg, args...)
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"Warn",
"(",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Log",
"(",
"Warn",
",",
"msg",
",",
"args",
"...",
")",
"\n",
"}"
] | // Emit the message and args at WARN level | [
"Emit",
"the",
"message",
"and",
"args",
"at",
"WARN",
"level"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L404-L406 |
150,865 | hashicorp/go-hclog | intlogger.go | Error | func (l *intLogger) Error(msg string, args ...interface{}) {
l.Log(Error, msg, args...)
} | go | func (l *intLogger) Error(msg string, args ...interface{}) {
l.Log(Error, msg, args...)
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"Error",
"(",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"l",
".",
"Log",
"(",
"Error",
",",
"msg",
",",
"args",
"...",
")",
"\n",
"}"
] | // Emit the message and args at ERROR level | [
"Emit",
"the",
"message",
"and",
"args",
"at",
"ERROR",
"level"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L409-L411 |
150,866 | hashicorp/go-hclog | intlogger.go | IsTrace | func (l *intLogger) IsTrace() bool {
return Level(atomic.LoadInt32(l.level)) == Trace
} | go | func (l *intLogger) IsTrace() bool {
return Level(atomic.LoadInt32(l.level)) == Trace
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"IsTrace",
"(",
")",
"bool",
"{",
"return",
"Level",
"(",
"atomic",
".",
"LoadInt32",
"(",
"l",
".",
"level",
")",
")",
"==",
"Trace",
"\n",
"}"
] | // Indicate that the logger would emit TRACE level logs | [
"Indicate",
"that",
"the",
"logger",
"would",
"emit",
"TRACE",
"level",
"logs"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L414-L416 |
150,867 | hashicorp/go-hclog | intlogger.go | IsDebug | func (l *intLogger) IsDebug() bool {
return Level(atomic.LoadInt32(l.level)) <= Debug
} | go | func (l *intLogger) IsDebug() bool {
return Level(atomic.LoadInt32(l.level)) <= Debug
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"IsDebug",
"(",
")",
"bool",
"{",
"return",
"Level",
"(",
"atomic",
".",
"LoadInt32",
"(",
"l",
".",
"level",
")",
")",
"<=",
"Debug",
"\n",
"}"
] | // Indicate that the logger would emit DEBUG level logs | [
"Indicate",
"that",
"the",
"logger",
"would",
"emit",
"DEBUG",
"level",
"logs"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L419-L421 |
150,868 | hashicorp/go-hclog | intlogger.go | IsInfo | func (l *intLogger) IsInfo() bool {
return Level(atomic.LoadInt32(l.level)) <= Info
} | go | func (l *intLogger) IsInfo() bool {
return Level(atomic.LoadInt32(l.level)) <= Info
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"IsInfo",
"(",
")",
"bool",
"{",
"return",
"Level",
"(",
"atomic",
".",
"LoadInt32",
"(",
"l",
".",
"level",
")",
")",
"<=",
"Info",
"\n",
"}"
] | // Indicate that the logger would emit INFO level logs | [
"Indicate",
"that",
"the",
"logger",
"would",
"emit",
"INFO",
"level",
"logs"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L424-L426 |
150,869 | hashicorp/go-hclog | intlogger.go | IsWarn | func (l *intLogger) IsWarn() bool {
return Level(atomic.LoadInt32(l.level)) <= Warn
} | go | func (l *intLogger) IsWarn() bool {
return Level(atomic.LoadInt32(l.level)) <= Warn
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"IsWarn",
"(",
")",
"bool",
"{",
"return",
"Level",
"(",
"atomic",
".",
"LoadInt32",
"(",
"l",
".",
"level",
")",
")",
"<=",
"Warn",
"\n",
"}"
] | // Indicate that the logger would emit WARN level logs | [
"Indicate",
"that",
"the",
"logger",
"would",
"emit",
"WARN",
"level",
"logs"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L429-L431 |
150,870 | hashicorp/go-hclog | intlogger.go | IsError | func (l *intLogger) IsError() bool {
return Level(atomic.LoadInt32(l.level)) <= Error
} | go | func (l *intLogger) IsError() bool {
return Level(atomic.LoadInt32(l.level)) <= Error
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"IsError",
"(",
")",
"bool",
"{",
"return",
"Level",
"(",
"atomic",
".",
"LoadInt32",
"(",
"l",
".",
"level",
")",
")",
"<=",
"Error",
"\n",
"}"
] | // Indicate that the logger would emit ERROR level logs | [
"Indicate",
"that",
"the",
"logger",
"would",
"emit",
"ERROR",
"level",
"logs"
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L434-L436 |
150,871 | hashicorp/go-hclog | intlogger.go | Named | func (l *intLogger) Named(name string) Logger {
sl := *l
if sl.name != "" {
sl.name = sl.name + "." + name
} else {
sl.name = name
}
return &sl
} | go | func (l *intLogger) Named(name string) Logger {
sl := *l
if sl.name != "" {
sl.name = sl.name + "." + name
} else {
sl.name = name
}
return &sl
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"Named",
"(",
"name",
"string",
")",
"Logger",
"{",
"sl",
":=",
"*",
"l",
"\n\n",
"if",
"sl",
".",
"name",
"!=",
"\"",
"\"",
"{",
"sl",
".",
"name",
"=",
"sl",
".",
"name",
"+",
"\"",
"\"",
"+",
"name",
"\n",
"}",
"else",
"{",
"sl",
".",
"name",
"=",
"name",
"\n",
"}",
"\n\n",
"return",
"&",
"sl",
"\n",
"}"
] | // Create a new sub-Logger that a name decending from the current name.
// This is used to create a subsystem specific Logger. | [
"Create",
"a",
"new",
"sub",
"-",
"Logger",
"that",
"a",
"name",
"decending",
"from",
"the",
"current",
"name",
".",
"This",
"is",
"used",
"to",
"create",
"a",
"subsystem",
"specific",
"Logger",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L481-L491 |
150,872 | hashicorp/go-hclog | intlogger.go | ResetNamed | func (l *intLogger) ResetNamed(name string) Logger {
sl := *l
sl.name = name
return &sl
} | go | func (l *intLogger) ResetNamed(name string) Logger {
sl := *l
sl.name = name
return &sl
} | [
"func",
"(",
"l",
"*",
"intLogger",
")",
"ResetNamed",
"(",
"name",
"string",
")",
"Logger",
"{",
"sl",
":=",
"*",
"l",
"\n\n",
"sl",
".",
"name",
"=",
"name",
"\n\n",
"return",
"&",
"sl",
"\n",
"}"
] | // Create a new sub-Logger with an explicit name. This ignores the current
// name. This is used to create a standalone logger that doesn't fall
// within the normal hierarchy. | [
"Create",
"a",
"new",
"sub",
"-",
"Logger",
"with",
"an",
"explicit",
"name",
".",
"This",
"ignores",
"the",
"current",
"name",
".",
"This",
"is",
"used",
"to",
"create",
"a",
"standalone",
"logger",
"that",
"doesn",
"t",
"fall",
"within",
"the",
"normal",
"hierarchy",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L496-L502 |
150,873 | 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 |
150,874 | 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",
"if",
"s",
".",
"forceLevel",
"!=",
"NoLevel",
"{",
"// Use pickLevel to strip log levels included in the line since we are",
"// forcing the level",
"_",
",",
"str",
":=",
"s",
".",
"pickLevel",
"(",
"str",
")",
"\n\n",
"// Log at the forced level",
"switch",
"s",
".",
"forceLevel",
"{",
"case",
"Trace",
":",
"s",
".",
"log",
".",
"Trace",
"(",
"str",
")",
"\n",
"case",
"Debug",
":",
"s",
".",
"log",
".",
"Debug",
"(",
"str",
")",
"\n",
"case",
"Info",
":",
"s",
".",
"log",
".",
"Info",
"(",
"str",
")",
"\n",
"case",
"Warn",
":",
"s",
".",
"log",
".",
"Warn",
"(",
"str",
")",
"\n",
"case",
"Error",
":",
"s",
".",
"log",
".",
"Error",
"(",
"str",
")",
"\n",
"default",
":",
"s",
".",
"log",
".",
"Info",
"(",
"str",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"s",
".",
"inferLevels",
"{",
"level",
",",
"str",
":=",
"s",
".",
"pickLevel",
"(",
"str",
")",
"\n",
"switch",
"level",
"{",
"case",
"Trace",
":",
"s",
".",
"log",
".",
"Trace",
"(",
"str",
")",
"\n",
"case",
"Debug",
":",
"s",
".",
"log",
".",
"Debug",
"(",
"str",
")",
"\n",
"case",
"Info",
":",
"s",
".",
"log",
".",
"Info",
"(",
"str",
")",
"\n",
"case",
"Warn",
":",
"s",
".",
"log",
".",
"Warn",
"(",
"str",
")",
"\n",
"case",
"Error",
":",
"s",
".",
"log",
".",
"Error",
"(",
"str",
")",
"\n",
"default",
":",
"s",
".",
"log",
".",
"Info",
"(",
"str",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"s",
".",
"log",
".",
"Info",
"(",
"str",
")",
"\n",
"}",
"\n\n",
"return",
"len",
"(",
"data",
")",
",",
"nil",
"\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 |
150,875 | 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",
".",
"TrimSpace",
"(",
"str",
"[",
"7",
":",
"]",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"str",
",",
"\"",
"\"",
")",
":",
"return",
"Trace",
",",
"strings",
".",
"TrimSpace",
"(",
"str",
"[",
"7",
":",
"]",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"str",
",",
"\"",
"\"",
")",
":",
"return",
"Info",
",",
"strings",
".",
"TrimSpace",
"(",
"str",
"[",
"6",
":",
"]",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"str",
",",
"\"",
"\"",
")",
":",
"return",
"Warn",
",",
"strings",
".",
"TrimSpace",
"(",
"str",
"[",
"7",
":",
"]",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"str",
",",
"\"",
"\"",
")",
":",
"return",
"Error",
",",
"strings",
".",
"TrimSpace",
"(",
"str",
"[",
"7",
":",
"]",
")",
"\n",
"case",
"strings",
".",
"HasPrefix",
"(",
"str",
",",
"\"",
"\"",
")",
":",
"return",
"Error",
",",
"strings",
".",
"TrimSpace",
"(",
"str",
"[",
"5",
":",
"]",
")",
"\n",
"default",
":",
"return",
"Info",
",",
"str",
"\n",
"}",
"\n",
"}"
] | // 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 |
150,876 | 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",
"levelStr",
"{",
"case",
"\"",
"\"",
":",
"return",
"Trace",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Debug",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Info",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Warn",
"\n",
"case",
"\"",
"\"",
":",
"return",
"Error",
"\n",
"default",
":",
"return",
"NoLevel",
"\n",
"}",
"\n",
"}"
] | // 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",
"variable",
"by",
"name",
"in",
"a",
"predictable",
"way",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/logger.go#L59-L76 |
150,877 | 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 |
150,878 | 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",
"(",
")",
"\n",
"end",
":=",
"ident",
".",
"End",
"(",
")",
"\n",
"span",
",",
"ok",
":=",
"pkg",
".",
"spans",
"[",
"obj",
"]",
"\n",
"if",
"ok",
"{",
"if",
"span",
".",
"min",
">",
"pos",
"{",
"span",
".",
"min",
"=",
"pos",
"\n",
"}",
"\n",
"if",
"span",
".",
"max",
"<",
"end",
"{",
"span",
".",
"max",
"=",
"end",
"\n",
"}",
"\n",
"}",
"else",
"{",
"span",
"=",
"Span",
"{",
"pos",
",",
"end",
"}",
"\n",
"}",
"\n",
"pkg",
".",
"spans",
"[",
"obj",
"]",
"=",
"span",
"\n",
"}"
] | // 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 |
150,879 | 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",
")",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"expr",
":=",
"range",
"a",
".",
"Lhs",
"{",
"ident",
",",
"ok",
":=",
"expr",
".",
"(",
"*",
"ast",
".",
"Ident",
")",
"\n",
"if",
"!",
"ok",
"{",
"f",
".",
"Badf",
"(",
"expr",
".",
"Pos",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"checkShadowing",
"(",
"f",
",",
"ident",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
150,880 | 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",
"// for each iteration. Another example is",
"//\tswitch n := n.(type)",
"if",
"len",
"(",
"a",
".",
"Rhs",
")",
"!=",
"len",
"(",
"a",
".",
"Lhs",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// 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",
")",
"\n",
"if",
"!",
"ok",
"{",
"f",
".",
"Badf",
"(",
"expr",
".",
"Pos",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"return",
"true",
"// Don't do any more processing.",
"\n",
"}",
"\n",
"switch",
"rhs",
":=",
"a",
".",
"Rhs",
"[",
"i",
"]",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Ident",
":",
"if",
"lhs",
".",
"Name",
"!=",
"rhs",
".",
"Name",
"{",
"return",
"false",
"\n",
"}",
"\n",
"case",
"*",
"ast",
".",
"TypeAssertExpr",
":",
"if",
"id",
",",
"ok",
":=",
"rhs",
".",
"X",
".",
"(",
"*",
"ast",
".",
"Ident",
")",
";",
"ok",
"{",
"if",
"lhs",
".",
"Name",
"!=",
"id",
".",
"Name",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // 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 |
150,881 | 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",
"(",
"d",
".",
"Values",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"i",
",",
"lhs",
":=",
"range",
"d",
".",
"Names",
"{",
"if",
"rhs",
",",
"ok",
":=",
"d",
".",
"Values",
"[",
"i",
"]",
".",
"(",
"*",
"ast",
".",
"Ident",
")",
";",
"ok",
"{",
"if",
"lhs",
".",
"Name",
"!=",
"rhs",
".",
"Name",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // 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 |
150,882 | 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",
"{",
"valueSpec",
",",
"ok",
":=",
"spec",
".",
"(",
"*",
"ast",
".",
"ValueSpec",
")",
"\n",
"if",
"!",
"ok",
"{",
"f",
".",
"Badf",
"(",
"spec",
".",
"Pos",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"// Don't complain about deliberate redeclarations of the form",
"//\tvar i = i",
"if",
"f",
".",
"idiomaticRedecl",
"(",
"valueSpec",
")",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"ident",
":=",
"range",
"valueSpec",
".",
"Names",
"{",
"checkShadowing",
"(",
"f",
",",
"ident",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // 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 |
150,883 | 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",
".",
"defs",
"[",
"ident",
"]",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// 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",
"(",
")",
")",
"\n",
"if",
"shadowed",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// Don't complain if it's shadowing a universe-declared identifier; that's fine.",
"if",
"shadowed",
".",
"Parent",
"(",
")",
"==",
"types",
".",
"Universe",
"{",
"return",
"\n",
"}",
"\n",
"if",
"*",
"strictShadowing",
"{",
"// The shadowed identifier must appear before this one to be an instance of shadowing.",
"if",
"shadowed",
".",
"Pos",
"(",
")",
">",
"ident",
".",
"Pos",
"(",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"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",
"]",
"\n",
"if",
"!",
"ok",
"{",
"f",
".",
"Badf",
"(",
"ident",
".",
"Pos",
"(",
")",
",",
"\"",
"\"",
",",
"ident",
".",
"Name",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"!",
"span",
".",
"contains",
"(",
"ident",
".",
"Pos",
"(",
")",
")",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"// 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",
"(",
")",
",",
"\"",
"\"",
",",
"obj",
".",
"Name",
"(",
")",
",",
"f",
".",
"loc",
"(",
"shadowed",
".",
"Pos",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
150,884 | 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",
"obj",
":=",
"n",
".",
"Obj",
"(",
")",
"\n",
"return",
"obj",
".",
"Name",
"(",
")",
"==",
"name",
"&&",
"isPackage",
"(",
"obj",
".",
"Pkg",
"(",
")",
",",
"path",
")",
"\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 |
150,885 | 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",
".",
"HasSuffix",
"(",
"pkg",
".",
"Path",
"(",
")",
",",
"\"",
"\"",
"+",
"path",
")",
"\n",
"}"
] | // 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 |
150,886 | 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 compiled yet.",
"warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"obj",
",",
"ok",
":=",
"pkg",
".",
"Scope",
"(",
")",
".",
"Lookup",
"(",
"name",
")",
".",
"(",
"*",
"types",
".",
"TypeName",
")",
";",
"ok",
"{",
"return",
"obj",
".",
"Type",
"(",
")",
"\n",
"}",
"\n",
"warnf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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",
"importType",
"returns",
"nil",
"."
] | d2f17ae9f9297cad64f18f15d537397e8783627b | https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/hclogvet/types.go#L63-L75 |
150,887 | 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",
"{",
"t",
"=",
"t",
".",
"Underlying",
"(",
")",
"\n",
"}",
"\n",
"b",
",",
"ok",
":=",
"t",
".",
"(",
"*",
"types",
".",
"Basic",
")",
"\n",
"return",
"ok",
"&&",
"b",
".",
"Kind",
"(",
")",
"==",
"kind",
"\n",
"}"
] | // 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 |
150,888 | 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",
"\"",
"\"",
"\n",
"}"
] | // 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 |
150,889 | 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",
"handlers",
"clients",
"can",
"rely",
"on",
"this",
"package",
"s",
"middleware",
"to",
"populate",
"the",
"CSP",
"nonce",
"in",
"the",
"context",
"."
] | 4e32686ccfd4360eba208873a5c397fef3b50cc4 | https://github.com/unrolled/secure/blob/4e32686ccfd4360eba208873a5c397fef3b50cc4/csp.go#L28-L30 |
150,890 | 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",
"]",
"\n",
"}",
"\n\n",
"o",
".",
"ContentSecurityPolicy",
"=",
"strings",
".",
"Replace",
"(",
"o",
".",
"ContentSecurityPolicy",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n\n",
"o",
".",
"nonceEnabled",
"=",
"strings",
".",
"Contains",
"(",
"o",
".",
"ContentSecurityPolicy",
",",
"\"",
"\"",
")",
"\n\n",
"s",
":=",
"&",
"Secure",
"{",
"opt",
":",
"o",
",",
"badHostHandler",
":",
"http",
".",
"HandlerFunc",
"(",
"defaultBadHostHandler",
")",
",",
"}",
"\n\n",
"if",
"s",
".",
"opt",
".",
"AllowedHostsAreRegex",
"{",
"// Test for invalid regular expressions in AllowedHosts",
"for",
"_",
",",
"allowedHost",
":=",
"range",
"o",
".",
"AllowedHosts",
"{",
"regex",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"allowedHost",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"s",
".",
"cRegexAllowedHosts",
"=",
"append",
"(",
"s",
".",
"cRegexAllowedHosts",
",",
"regex",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
] | // 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 |
150,891 | 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 indicates the request should not continue.",
"responseHeader",
",",
"r",
",",
"err",
":=",
"s",
".",
"processRequest",
"(",
"w",
",",
"r",
")",
"\n",
"addResponseHeaders",
"(",
"responseHeader",
",",
"w",
")",
"\n\n",
"// If there was an error, do not call next.",
"if",
"err",
"==",
"nil",
"&&",
"next",
"!=",
"nil",
"{",
"next",
"(",
"w",
",",
"r",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
150,892 | 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,",
"// that indicates the request should not continue.",
"responseHeader",
",",
"r",
",",
"err",
":=",
"s",
".",
"processRequest",
"(",
"w",
",",
"r",
")",
"\n\n",
"// 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",
")",
"\n\n",
"// No headers will be written to the ResponseWriter.",
"next",
"(",
"w",
",",
"r",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"}",
"\n",
"}"
] | // 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 |
150,893 | 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",
"_",
",",
"value",
":=",
"range",
"values",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // 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 |
150,894 | 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",
")",
"\n",
"addResponseHeaders",
"(",
"responseHeader",
",",
"w",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // 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 |
150,895 | 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",
".",
"processRequest",
"(",
"w",
",",
"r",
")",
"\n",
"}"
] | // 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 |
150,896 | 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",
"\n",
"if",
"!",
"ssl",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"s",
".",
"opt",
".",
"SSLProxyHeaders",
"{",
"if",
"r",
".",
"Header",
".",
"Get",
"(",
"k",
")",
"==",
"v",
"{",
"ssl",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ssl",
"\n",
"}"
] | // 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 |
150,897 | 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",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"ctxSecureHeaderKey",
")",
"\n",
"if",
"responseHeader",
"!=",
"nil",
"{",
"for",
"header",
",",
"values",
":=",
"range",
"responseHeader",
".",
"(",
"http",
".",
"Header",
")",
"{",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"res",
".",
"Header",
".",
"Set",
"(",
"header",
",",
"strings",
".",
"Join",
"(",
"values",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // 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 |
150,898 | 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 |
150,899 | 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",
".",
"IsTerminal",
"(",
"w",
".",
"Fd",
"(",
")",
")",
"{",
"c",
".",
"disabled",
"=",
"true",
"\n",
"}",
"\n",
"}"
] | // SetOutput sets the output. | [
"SetOutput",
"sets",
"the",
"output",
"."
] | 82ef680aef5189b68682876cf70d09daa4ac0f51 | https://github.com/labstack/gommon/blob/82ef680aef5189b68682876cf70d09daa4ac0f51/color/color.go#L144-L149 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.