repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
Microsoft/go-winio
fileinfo.go
GetFileBasicInfo
func GetFileBasicInfo(f *os.File) (*FileBasicInfo, error) { bi := &FileBasicInfo{} if err := getFileInformationByHandleEx(syscall.Handle(f.Fd()), fileBasicInfo, (*byte)(unsafe.Pointer(bi)), uint32(unsafe.Sizeof(*bi))); err != nil { return nil, &os.PathError{Op: "GetFileInformationByHandleEx", Path: f.Name(), Err: err} } runtime.KeepAlive(f) return bi, nil }
go
func GetFileBasicInfo(f *os.File) (*FileBasicInfo, error) { bi := &FileBasicInfo{} if err := getFileInformationByHandleEx(syscall.Handle(f.Fd()), fileBasicInfo, (*byte)(unsafe.Pointer(bi)), uint32(unsafe.Sizeof(*bi))); err != nil { return nil, &os.PathError{Op: "GetFileInformationByHandleEx", Path: f.Name(), Err: err} } runtime.KeepAlive(f) return bi, nil }
[ "func", "GetFileBasicInfo", "(", "f", "*", "os", ".", "File", ")", "(", "*", "FileBasicInfo", ",", "error", ")", "{", "bi", ":=", "&", "FileBasicInfo", "{", "}", "\n", "if", "err", ":=", "getFileInformationByHandleEx", "(", "syscall", ".", "Handle", "(",...
// GetFileBasicInfo retrieves times and attributes for a file.
[ "GetFileBasicInfo", "retrieves", "times", "and", "attributes", "for", "a", "file", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/fileinfo.go#L28-L35
train
Microsoft/go-winio
pkg/etw/eventmetadata.go
bytes
func (em *eventMetadata) bytes() []byte { // Finalize the event metadata buffer by filling in the buffer length at the // beginning. binary.LittleEndian.PutUint16(em.buffer.Bytes(), uint16(em.buffer.Len())) return em.buffer.Bytes() }
go
func (em *eventMetadata) bytes() []byte { // Finalize the event metadata buffer by filling in the buffer length at the // beginning. binary.LittleEndian.PutUint16(em.buffer.Bytes(), uint16(em.buffer.Len())) return em.buffer.Bytes() }
[ "func", "(", "em", "*", "eventMetadata", ")", "bytes", "(", ")", "[", "]", "byte", "{", "// Finalize the event metadata buffer by filling in the buffer length at the", "// beginning.", "binary", ".", "LittleEndian", ".", "PutUint16", "(", "em", ".", "buffer", ".", "...
// bytes returns the raw binary data containing the event metadata. Before being // returned, the current size of the buffer is written to the start of the // buffer. The returned value is not copied from the internal buffer, so it can // be mutated by the eventMetadata object after it is returned.
[ "bytes", "returns", "the", "raw", "binary", "data", "containing", "the", "event", "metadata", ".", "Before", "being", "returned", "the", "current", "size", "of", "the", "buffer", "is", "written", "to", "the", "start", "of", "the", "buffer", ".", "The", "re...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L88-L93
train
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeEventHeader
func (em *eventMetadata) writeEventHeader(name string, tags uint32) { binary.Write(&em.buffer, binary.LittleEndian, uint16(0)) // Length placeholder em.writeTags(tags) em.buffer.WriteString(name) em.buffer.WriteByte(0) // Null terminator for name }
go
func (em *eventMetadata) writeEventHeader(name string, tags uint32) { binary.Write(&em.buffer, binary.LittleEndian, uint16(0)) // Length placeholder em.writeTags(tags) em.buffer.WriteString(name) em.buffer.WriteByte(0) // Null terminator for name }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeEventHeader", "(", "name", "string", ",", "tags", "uint32", ")", "{", "binary", ".", "Write", "(", "&", "em", ".", "buffer", ",", "binary", ".", "LittleEndian", ",", "uint16", "(", "0", ")", ")", "/...
// writeEventHeader writes the metadata for the start of an event to the buffer. // This specifies the event name and tags.
[ "writeEventHeader", "writes", "the", "metadata", "for", "the", "start", "of", "an", "event", "to", "the", "buffer", ".", "This", "specifies", "the", "event", "name", "and", "tags", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L97-L102
train
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeField
func (em *eventMetadata) writeField(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType, outType, tags, 0) }
go
func (em *eventMetadata) writeField(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType, outType, tags, 0) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeField", "(", "name", "string", ",", "inType", "inType", ",", "outType", "outType", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inType", ",", "outType", ",", "tags",...
// writeField writes the metadata for a simple field to the buffer.
[ "writeField", "writes", "the", "metadata", "for", "a", "simple", "field", "to", "the", "buffer", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L154-L156
train
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeArray
func (em *eventMetadata) writeArray(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeArray, outType, tags, 0) }
go
func (em *eventMetadata) writeArray(name string, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeArray, outType, tags, 0) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeArray", "(", "name", "string", ",", "inType", "inType", ",", "outType", "outType", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inType", "|", "inTypeArray", ",", "ou...
// writeArray writes the metadata for an array field to the buffer. The number // of elements in the array must be written as a uint16 in the event data, // immediately preceeding the event data.
[ "writeArray", "writes", "the", "metadata", "for", "an", "array", "field", "to", "the", "buffer", ".", "The", "number", "of", "elements", "in", "the", "array", "must", "be", "written", "as", "a", "uint16", "in", "the", "event", "data", "immediately", "prece...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L161-L163
train
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeCountedArray
func (em *eventMetadata) writeCountedArray(name string, count uint16, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeCountedArray, outType, tags, count) }
go
func (em *eventMetadata) writeCountedArray(name string, count uint16, inType inType, outType outType, tags uint32) { em.writeFieldInner(name, inType|inTypeCountedArray, outType, tags, count) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeCountedArray", "(", "name", "string", ",", "count", "uint16", ",", "inType", "inType", ",", "outType", "outType", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inType",...
// writeCountedArray writes the metadata for an array field to the buffer. The // size of a counted array is fixed, and the size is written into the metadata // directly.
[ "writeCountedArray", "writes", "the", "metadata", "for", "an", "array", "field", "to", "the", "buffer", ".", "The", "size", "of", "a", "counted", "array", "is", "fixed", "and", "the", "size", "is", "written", "into", "the", "metadata", "directly", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L168-L170
train
Microsoft/go-winio
pkg/etw/eventmetadata.go
writeStruct
func (em *eventMetadata) writeStruct(name string, fieldCount uint8, tags uint32) { em.writeFieldInner(name, inTypeStruct, outType(fieldCount), tags, 0) }
go
func (em *eventMetadata) writeStruct(name string, fieldCount uint8, tags uint32) { em.writeFieldInner(name, inTypeStruct, outType(fieldCount), tags, 0) }
[ "func", "(", "em", "*", "eventMetadata", ")", "writeStruct", "(", "name", "string", ",", "fieldCount", "uint8", ",", "tags", "uint32", ")", "{", "em", ".", "writeFieldInner", "(", "name", ",", "inTypeStruct", ",", "outType", "(", "fieldCount", ")", ",", ...
// writeStruct writes the metadata for a nested struct to the buffer. The struct // contains the next N fields in the metadata, where N is specified by the // fieldCount argument.
[ "writeStruct", "writes", "the", "metadata", "for", "a", "nested", "struct", "to", "the", "buffer", ".", "The", "struct", "contains", "the", "next", "N", "fields", "in", "the", "metadata", "where", "N", "is", "specified", "by", "the", "fieldCount", "argument"...
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/etw/eventmetadata.go#L175-L177
train
Microsoft/go-winio
pkg/security/mksyscall_windows.go
IsNotDuplicate
func (f *Fn) IsNotDuplicate() bool { funcName := f.DLLFuncName() if uniqDllFuncName[funcName] == false { uniqDllFuncName[funcName] = true return true } return false }
go
func (f *Fn) IsNotDuplicate() bool { funcName := f.DLLFuncName() if uniqDllFuncName[funcName] == false { uniqDllFuncName[funcName] = true return true } return false }
[ "func", "(", "f", "*", "Fn", ")", "IsNotDuplicate", "(", ")", "bool", "{", "funcName", ":=", "f", ".", "DLLFuncName", "(", ")", "\n", "if", "uniqDllFuncName", "[", "funcName", "]", "==", "false", "{", "uniqDllFuncName", "[", "funcName", "]", "=", "true...
// IsNotDuplicate is true if f is not a duplicated function
[ "IsNotDuplicate", "is", "true", "if", "f", "is", "not", "a", "duplicated", "function" ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/security/mksyscall_windows.go#L612-L619
train
Microsoft/go-winio
pkg/security/mksyscall_windows.go
Generate
func (src *Source) Generate(w io.Writer) error { const ( pkgStd = iota // any package in std library pkgXSysWindows // x/sys/windows package pkgOther ) isStdRepo, err := src.IsStdRepo() if err != nil { return err } var pkgtype int switch { case isStdRepo: pkgtype = pkgStd case packageName == "windows": // TODO: this needs better logic than just using package name pkgtype = pkgXSysWindows default: pkgtype = pkgOther } if *systemDLL { switch pkgtype { case pkgStd: src.Import("internal/syscall/windows/sysdll") case pkgXSysWindows: default: src.ExternalImport("golang.org/x/sys/windows") } } if *winio { src.ExternalImport("github.com/Microsoft/go-winio") } if packageName != "syscall" { src.Import("syscall") } funcMap := template.FuncMap{ "packagename": packagename, "syscalldot": syscalldot, "newlazydll": func(dll string) string { arg := "\"" + dll + ".dll\"" if !*systemDLL { return syscalldot() + "NewLazyDLL(" + arg + ")" } if strings.HasPrefix(dll, "api_") || strings.HasPrefix(dll, "ext_") { arg = strings.Replace(arg, "_", "-", -1) } switch pkgtype { case pkgStd: return syscalldot() + "NewLazyDLL(sysdll.Add(" + arg + "))" case pkgXSysWindows: return "NewLazySystemDLL(" + arg + ")" default: return "windows.NewLazySystemDLL(" + arg + ")" } }, } t := template.Must(template.New("main").Funcs(funcMap).Parse(srcTemplate)) err = t.Execute(w, src) if err != nil { return errors.New("Failed to execute template: " + err.Error()) } return nil }
go
func (src *Source) Generate(w io.Writer) error { const ( pkgStd = iota // any package in std library pkgXSysWindows // x/sys/windows package pkgOther ) isStdRepo, err := src.IsStdRepo() if err != nil { return err } var pkgtype int switch { case isStdRepo: pkgtype = pkgStd case packageName == "windows": // TODO: this needs better logic than just using package name pkgtype = pkgXSysWindows default: pkgtype = pkgOther } if *systemDLL { switch pkgtype { case pkgStd: src.Import("internal/syscall/windows/sysdll") case pkgXSysWindows: default: src.ExternalImport("golang.org/x/sys/windows") } } if *winio { src.ExternalImport("github.com/Microsoft/go-winio") } if packageName != "syscall" { src.Import("syscall") } funcMap := template.FuncMap{ "packagename": packagename, "syscalldot": syscalldot, "newlazydll": func(dll string) string { arg := "\"" + dll + ".dll\"" if !*systemDLL { return syscalldot() + "NewLazyDLL(" + arg + ")" } if strings.HasPrefix(dll, "api_") || strings.HasPrefix(dll, "ext_") { arg = strings.Replace(arg, "_", "-", -1) } switch pkgtype { case pkgStd: return syscalldot() + "NewLazyDLL(sysdll.Add(" + arg + "))" case pkgXSysWindows: return "NewLazySystemDLL(" + arg + ")" default: return "windows.NewLazySystemDLL(" + arg + ")" } }, } t := template.Must(template.New("main").Funcs(funcMap).Parse(srcTemplate)) err = t.Execute(w, src) if err != nil { return errors.New("Failed to execute template: " + err.Error()) } return nil }
[ "func", "(", "src", "*", "Source", ")", "Generate", "(", "w", "io", ".", "Writer", ")", "error", "{", "const", "(", "pkgStd", "=", "iota", "// any package in std library", "\n", "pkgXSysWindows", "// x/sys/windows package", "\n", "pkgOther", "\n", ")", "\n", ...
// Generate output source file from a source set src.
[ "Generate", "output", "source", "file", "from", "a", "source", "set", "src", "." ]
3fe4fa31662f6ede2353d913e93907b8e096e0b6
https://github.com/Microsoft/go-winio/blob/3fe4fa31662f6ede2353d913e93907b8e096e0b6/pkg/security/mksyscall_windows.go#L750-L812
train
godbus/dbus
decoder.go
newDecoder
func newDecoder(in io.Reader, order binary.ByteOrder) *decoder { dec := new(decoder) dec.in = in dec.order = order return dec }
go
func newDecoder(in io.Reader, order binary.ByteOrder) *decoder { dec := new(decoder) dec.in = in dec.order = order return dec }
[ "func", "newDecoder", "(", "in", "io", ".", "Reader", ",", "order", "binary", ".", "ByteOrder", ")", "*", "decoder", "{", "dec", ":=", "new", "(", "decoder", ")", "\n", "dec", ".", "in", "=", "in", "\n", "dec", ".", "order", "=", "order", "\n", "...
// newDecoder returns a new decoder that reads values from in. The input is // expected to be in the given byte order.
[ "newDecoder", "returns", "a", "new", "decoder", "that", "reads", "values", "from", "in", ".", "The", "input", "is", "expected", "to", "be", "in", "the", "given", "byte", "order", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/decoder.go#L17-L22
train
godbus/dbus
decoder.go
align
func (dec *decoder) align(n int) { if dec.pos%n != 0 { newpos := (dec.pos + n - 1) & ^(n - 1) empty := make([]byte, newpos-dec.pos) if _, err := io.ReadFull(dec.in, empty); err != nil { panic(err) } dec.pos = newpos } }
go
func (dec *decoder) align(n int) { if dec.pos%n != 0 { newpos := (dec.pos + n - 1) & ^(n - 1) empty := make([]byte, newpos-dec.pos) if _, err := io.ReadFull(dec.in, empty); err != nil { panic(err) } dec.pos = newpos } }
[ "func", "(", "dec", "*", "decoder", ")", "align", "(", "n", "int", ")", "{", "if", "dec", ".", "pos", "%", "n", "!=", "0", "{", "newpos", ":=", "(", "dec", ".", "pos", "+", "n", "-", "1", ")", "&", "^", "(", "n", "-", "1", ")", "\n", "e...
// align aligns the input to the given boundary and panics on error.
[ "align", "aligns", "the", "input", "to", "the", "given", "boundary", "and", "panics", "on", "error", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/decoder.go#L25-L34
train
godbus/dbus
decoder.go
sigByteSize
func sigByteSize(sig string) int { var total int for offset := 0; offset < len(sig); { switch sig[offset] { case 'y': total += 1 offset += 1 case 'n', 'q': total += 2 offset += 1 case 'b', 'i', 'u', 'h': total += 4 offset += 1 case 'x', 't', 'd': total += 8 offset += 1 case '(': i := 1 depth := 1 for i < len(sig[offset:]) && depth != 0 { if sig[offset+i] == '(' { depth++ } else if sig[offset+i] == ')' { depth-- } i++ } s := sigByteSize(sig[offset+1 : offset+i-1]) if s == 0 { return 0 } total += s offset += i default: return 0 } } return total }
go
func sigByteSize(sig string) int { var total int for offset := 0; offset < len(sig); { switch sig[offset] { case 'y': total += 1 offset += 1 case 'n', 'q': total += 2 offset += 1 case 'b', 'i', 'u', 'h': total += 4 offset += 1 case 'x', 't', 'd': total += 8 offset += 1 case '(': i := 1 depth := 1 for i < len(sig[offset:]) && depth != 0 { if sig[offset+i] == '(' { depth++ } else if sig[offset+i] == ')' { depth-- } i++ } s := sigByteSize(sig[offset+1 : offset+i-1]) if s == 0 { return 0 } total += s offset += i default: return 0 } } return total }
[ "func", "sigByteSize", "(", "sig", "string", ")", "int", "{", "var", "total", "int", "\n", "for", "offset", ":=", "0", ";", "offset", "<", "len", "(", "sig", ")", ";", "{", "switch", "sig", "[", "offset", "]", "{", "case", "'y'", ":", "total", "+...
// sigByteSize tries to calculates size of the given signature in bytes. // // It returns zero when it can't, for example when it contains non-fixed size // types such as strings, maps and arrays that require reading of the transmitted // data, for that we would need to implement the unread method for Decoder first.
[ "sigByteSize", "tries", "to", "calculates", "size", "of", "the", "given", "signature", "in", "bytes", ".", "It", "returns", "zero", "when", "it", "can", "t", "for", "example", "when", "it", "contains", "non", "-", "fixed", "size", "types", "such", "as", ...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/decoder.go#L241-L279
train
godbus/dbus
auth.go
authReadLine
func authReadLine(in *bufio.Reader) ([][]byte, error) { data, err := in.ReadBytes('\n') if err != nil { return nil, err } data = bytes.TrimSuffix(data, []byte("\r\n")) return bytes.Split(data, []byte{' '}), nil }
go
func authReadLine(in *bufio.Reader) ([][]byte, error) { data, err := in.ReadBytes('\n') if err != nil { return nil, err } data = bytes.TrimSuffix(data, []byte("\r\n")) return bytes.Split(data, []byte{' '}), nil }
[ "func", "authReadLine", "(", "in", "*", "bufio", ".", "Reader", ")", "(", "[", "]", "[", "]", "byte", ",", "error", ")", "{", "data", ",", "err", ":=", "in", ".", "ReadBytes", "(", "'\\n'", ")", "\n", "if", "err", "!=", "nil", "{", "return", "n...
// authReadLine reads a line and separates it into its fields.
[ "authReadLine", "reads", "a", "line", "and", "separates", "it", "into", "its", "fields", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/auth.go#L223-L230
train
godbus/dbus
sig.go
SignatureOf
func SignatureOf(vs ...interface{}) Signature { var s string for _, v := range vs { s += getSignature(reflect.TypeOf(v)) } return Signature{s} }
go
func SignatureOf(vs ...interface{}) Signature { var s string for _, v := range vs { s += getSignature(reflect.TypeOf(v)) } return Signature{s} }
[ "func", "SignatureOf", "(", "vs", "...", "interface", "{", "}", ")", "Signature", "{", "var", "s", "string", "\n", "for", "_", ",", "v", ":=", "range", "vs", "{", "s", "+=", "getSignature", "(", "reflect", ".", "TypeOf", "(", "v", ")", ")", "\n", ...
// SignatureOf returns the concatenation of all the signatures of the given // values. It panics if one of them is not representable in D-Bus.
[ "SignatureOf", "returns", "the", "concatenation", "of", "all", "the", "signatures", "of", "the", "given", "values", ".", "It", "panics", "if", "one", "of", "them", "is", "not", "representable", "in", "D", "-", "Bus", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L34-L40
train
godbus/dbus
sig.go
getSignature
func getSignature(t reflect.Type) string { // handle simple types first switch t.Kind() { case reflect.Uint8: return "y" case reflect.Bool: return "b" case reflect.Int16: return "n" case reflect.Uint16: return "q" case reflect.Int, reflect.Int32: if t == unixFDType { return "h" } return "i" case reflect.Uint, reflect.Uint32: if t == unixFDIndexType { return "h" } return "u" case reflect.Int64: return "x" case reflect.Uint64: return "t" case reflect.Float64: return "d" case reflect.Ptr: return getSignature(t.Elem()) case reflect.String: if t == objectPathType { return "o" } return "s" case reflect.Struct: if t == variantType { return "v" } else if t == signatureType { return "g" } var s string for i := 0; i < t.NumField(); i++ { field := t.Field(i) if field.PkgPath == "" && field.Tag.Get("dbus") != "-" { s += getSignature(t.Field(i).Type) } } return "(" + s + ")" case reflect.Array, reflect.Slice: return "a" + getSignature(t.Elem()) case reflect.Map: if !isKeyType(t.Key()) { panic(InvalidTypeError{t}) } return "a{" + getSignature(t.Key()) + getSignature(t.Elem()) + "}" case reflect.Interface: return "v" } panic(InvalidTypeError{t}) }
go
func getSignature(t reflect.Type) string { // handle simple types first switch t.Kind() { case reflect.Uint8: return "y" case reflect.Bool: return "b" case reflect.Int16: return "n" case reflect.Uint16: return "q" case reflect.Int, reflect.Int32: if t == unixFDType { return "h" } return "i" case reflect.Uint, reflect.Uint32: if t == unixFDIndexType { return "h" } return "u" case reflect.Int64: return "x" case reflect.Uint64: return "t" case reflect.Float64: return "d" case reflect.Ptr: return getSignature(t.Elem()) case reflect.String: if t == objectPathType { return "o" } return "s" case reflect.Struct: if t == variantType { return "v" } else if t == signatureType { return "g" } var s string for i := 0; i < t.NumField(); i++ { field := t.Field(i) if field.PkgPath == "" && field.Tag.Get("dbus") != "-" { s += getSignature(t.Field(i).Type) } } return "(" + s + ")" case reflect.Array, reflect.Slice: return "a" + getSignature(t.Elem()) case reflect.Map: if !isKeyType(t.Key()) { panic(InvalidTypeError{t}) } return "a{" + getSignature(t.Key()) + getSignature(t.Elem()) + "}" case reflect.Interface: return "v" } panic(InvalidTypeError{t}) }
[ "func", "getSignature", "(", "t", "reflect", ".", "Type", ")", "string", "{", "// handle simple types first", "switch", "t", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Uint8", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Bool", ":"...
// getSignature returns the signature of the given type and panics on unknown types.
[ "getSignature", "returns", "the", "signature", "of", "the", "given", "type", "and", "panics", "on", "unknown", "types", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L49-L108
train
godbus/dbus
sig.go
ParseSignature
func ParseSignature(s string) (sig Signature, err error) { if len(s) == 0 { return } if len(s) > 255 { return Signature{""}, SignatureError{s, "too long"} } sig.str = s for err == nil && len(s) != 0 { err, s = validSingle(s, 0) } if err != nil { sig = Signature{""} } return }
go
func ParseSignature(s string) (sig Signature, err error) { if len(s) == 0 { return } if len(s) > 255 { return Signature{""}, SignatureError{s, "too long"} } sig.str = s for err == nil && len(s) != 0 { err, s = validSingle(s, 0) } if err != nil { sig = Signature{""} } return }
[ "func", "ParseSignature", "(", "s", "string", ")", "(", "sig", "Signature", ",", "err", "error", ")", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "\n", "}", "\n", "if", "len", "(", "s", ")", ">", "255", "{", "return", "Signature", ...
// ParseSignature returns the signature represented by this string, or a // SignatureError if the string is not a valid signature.
[ "ParseSignature", "returns", "the", "signature", "represented", "by", "this", "string", "or", "a", "SignatureError", "if", "the", "string", "is", "not", "a", "valid", "signature", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L112-L128
train
godbus/dbus
sig.go
ParseSignatureMust
func ParseSignatureMust(s string) Signature { sig, err := ParseSignature(s) if err != nil { panic(err) } return sig }
go
func ParseSignatureMust(s string) Signature { sig, err := ParseSignature(s) if err != nil { panic(err) } return sig }
[ "func", "ParseSignatureMust", "(", "s", "string", ")", "Signature", "{", "sig", ",", "err", ":=", "ParseSignature", "(", "s", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "sig", "\n", "}" ]
// ParseSignatureMust behaves like ParseSignature, except that it panics if s // is not valid.
[ "ParseSignatureMust", "behaves", "like", "ParseSignature", "except", "that", "it", "panics", "if", "s", "is", "not", "valid", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L132-L138
train
godbus/dbus
sig.go
Single
func (s Signature) Single() bool { err, r := validSingle(s.str, 0) return err != nil && r == "" }
go
func (s Signature) Single() bool { err, r := validSingle(s.str, 0) return err != nil && r == "" }
[ "func", "(", "s", "Signature", ")", "Single", "(", ")", "bool", "{", "err", ",", "r", ":=", "validSingle", "(", "s", ".", "str", ",", "0", ")", "\n", "return", "err", "!=", "nil", "&&", "r", "==", "\"", "\"", "\n", "}" ]
// Single returns whether the signature represents a single, complete type.
[ "Single", "returns", "whether", "the", "signature", "represents", "a", "single", "complete", "type", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L146-L149
train
godbus/dbus
sig.go
validSingle
func validSingle(s string, depth int) (err error, rem string) { if s == "" { return SignatureError{Sig: s, Reason: "empty signature"}, "" } if depth > 64 { return SignatureError{Sig: s, Reason: "container nesting too deep"}, "" } switch s[0] { case 'y', 'b', 'n', 'q', 'i', 'u', 'x', 't', 'd', 's', 'g', 'o', 'v', 'h': return nil, s[1:] case 'a': if len(s) > 1 && s[1] == '{' { i := findMatching(s[1:], '{', '}') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched '{'"}, "" } i++ rem = s[i+1:] s = s[2:i] if err, _ = validSingle(s[:1], depth+1); err != nil { return err, "" } err, nr := validSingle(s[1:], depth+1) if err != nil { return err, "" } if nr != "" { return SignatureError{Sig: s, Reason: "too many types in dict"}, "" } return nil, rem } return validSingle(s[1:], depth+1) case '(': i := findMatching(s, '(', ')') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched ')'"}, "" } rem = s[i+1:] s = s[1:i] for err == nil && s != "" { err, s = validSingle(s, depth+1) } if err != nil { rem = "" } return } return SignatureError{Sig: s, Reason: "invalid type character"}, "" }
go
func validSingle(s string, depth int) (err error, rem string) { if s == "" { return SignatureError{Sig: s, Reason: "empty signature"}, "" } if depth > 64 { return SignatureError{Sig: s, Reason: "container nesting too deep"}, "" } switch s[0] { case 'y', 'b', 'n', 'q', 'i', 'u', 'x', 't', 'd', 's', 'g', 'o', 'v', 'h': return nil, s[1:] case 'a': if len(s) > 1 && s[1] == '{' { i := findMatching(s[1:], '{', '}') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched '{'"}, "" } i++ rem = s[i+1:] s = s[2:i] if err, _ = validSingle(s[:1], depth+1); err != nil { return err, "" } err, nr := validSingle(s[1:], depth+1) if err != nil { return err, "" } if nr != "" { return SignatureError{Sig: s, Reason: "too many types in dict"}, "" } return nil, rem } return validSingle(s[1:], depth+1) case '(': i := findMatching(s, '(', ')') if i == -1 { return SignatureError{Sig: s, Reason: "unmatched ')'"}, "" } rem = s[i+1:] s = s[1:i] for err == nil && s != "" { err, s = validSingle(s, depth+1) } if err != nil { rem = "" } return } return SignatureError{Sig: s, Reason: "invalid type character"}, "" }
[ "func", "validSingle", "(", "s", "string", ",", "depth", "int", ")", "(", "err", "error", ",", "rem", "string", ")", "{", "if", "s", "==", "\"", "\"", "{", "return", "SignatureError", "{", "Sig", ":", "s", ",", "Reason", ":", "\"", "\"", "}", ","...
// Try to read a single type from this string. If it was successful, err is nil // and rem is the remaining unparsed part. Otherwise, err is a non-nil // SignatureError and rem is "". depth is the current recursion depth which may // not be greater than 64 and should be given as 0 on the first call.
[ "Try", "to", "read", "a", "single", "type", "from", "this", "string", ".", "If", "it", "was", "successful", "err", "is", "nil", "and", "rem", "is", "the", "remaining", "unparsed", "part", ".", "Otherwise", "err", "is", "a", "non", "-", "nil", "Signatur...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L171-L219
train
godbus/dbus
sig.go
typeFor
func typeFor(s string) (t reflect.Type) { err, _ := validSingle(s, 0) if err != nil { panic(err) } if t, ok := sigToType[s[0]]; ok { return t } switch s[0] { case 'a': if s[1] == '{' { i := strings.LastIndex(s, "}") t = reflect.MapOf(sigToType[s[2]], typeFor(s[3:i])) } else { t = reflect.SliceOf(typeFor(s[1:])) } case '(': t = interfacesType } return }
go
func typeFor(s string) (t reflect.Type) { err, _ := validSingle(s, 0) if err != nil { panic(err) } if t, ok := sigToType[s[0]]; ok { return t } switch s[0] { case 'a': if s[1] == '{' { i := strings.LastIndex(s, "}") t = reflect.MapOf(sigToType[s[2]], typeFor(s[3:i])) } else { t = reflect.SliceOf(typeFor(s[1:])) } case '(': t = interfacesType } return }
[ "func", "typeFor", "(", "s", "string", ")", "(", "t", "reflect", ".", "Type", ")", "{", "err", ",", "_", ":=", "validSingle", "(", "s", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "if", "t"...
// typeFor returns the type of the given signature. It ignores any left over // characters and panics if s doesn't start with a valid type signature.
[ "typeFor", "returns", "the", "type", "of", "the", "given", "signature", ".", "It", "ignores", "any", "left", "over", "characters", "and", "panics", "if", "s", "doesn", "t", "start", "with", "a", "valid", "type", "signature", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/sig.go#L238-L259
train
godbus/dbus
prop/prop.go
Export
func Export( conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop, ) (*Properties, error) { p := &Properties{m: props, conn: conn, path: path} if err := conn.Export(p, path, "org.freedesktop.DBus.Properties"); err != nil { return nil, err } return p, nil }
go
func Export( conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop, ) (*Properties, error) { p := &Properties{m: props, conn: conn, path: path} if err := conn.Export(p, path, "org.freedesktop.DBus.Properties"); err != nil { return nil, err } return p, nil }
[ "func", "Export", "(", "conn", "*", "dbus", ".", "Conn", ",", "path", "dbus", ".", "ObjectPath", ",", "props", "map", "[", "string", "]", "map", "[", "string", "]", "*", "Prop", ",", ")", "(", "*", "Properties", ",", "error", ")", "{", "p", ":=",...
// Export returns a new Properties structure that manages the given properties. // The key for the first-level map of props is the name of the interface; the // second-level key is the name of the property. The returned structure will be // exported as org.freedesktop.DBus.Properties on path.
[ "Export", "returns", "a", "new", "Properties", "structure", "that", "manages", "the", "given", "properties", ".", "The", "key", "for", "the", "first", "-", "level", "map", "of", "props", "is", "the", "name", "of", "the", "interface", ";", "the", "second", ...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L160-L168
train
godbus/dbus
prop/prop.go
Get
func (p *Properties) Get(iface, property string) (dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return dbus.Variant{}, ErrIfaceNotFound } prop, ok := m[property] if !ok { return dbus.Variant{}, ErrPropNotFound } return dbus.MakeVariant(prop.Value), nil }
go
func (p *Properties) Get(iface, property string) (dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return dbus.Variant{}, ErrIfaceNotFound } prop, ok := m[property] if !ok { return dbus.Variant{}, ErrPropNotFound } return dbus.MakeVariant(prop.Value), nil }
[ "func", "(", "p", "*", "Properties", ")", "Get", "(", "iface", ",", "property", "string", ")", "(", "dbus", ".", "Variant", ",", "*", "dbus", ".", "Error", ")", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mut", ".", ...
// Get implements org.freedesktop.DBus.Properties.Get.
[ "Get", "implements", "org", ".", "freedesktop", ".", "DBus", ".", "Properties", ".", "Get", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L171-L183
train
godbus/dbus
prop/prop.go
GetAll
func (p *Properties) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return nil, ErrIfaceNotFound } rm := make(map[string]dbus.Variant, len(m)) for k, v := range m { rm[k] = dbus.MakeVariant(v.Value) } return rm, nil }
go
func (p *Properties) GetAll(iface string) (map[string]dbus.Variant, *dbus.Error) { p.mut.RLock() defer p.mut.RUnlock() m, ok := p.m[iface] if !ok { return nil, ErrIfaceNotFound } rm := make(map[string]dbus.Variant, len(m)) for k, v := range m { rm[k] = dbus.MakeVariant(v.Value) } return rm, nil }
[ "func", "(", "p", "*", "Properties", ")", "GetAll", "(", "iface", "string", ")", "(", "map", "[", "string", "]", "dbus", ".", "Variant", ",", "*", "dbus", ".", "Error", ")", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".",...
// GetAll implements org.freedesktop.DBus.Properties.GetAll.
[ "GetAll", "implements", "org", ".", "freedesktop", ".", "DBus", ".", "Properties", ".", "GetAll", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L186-L198
train
godbus/dbus
prop/prop.go
GetMust
func (p *Properties) GetMust(iface, property string) interface{} { p.mut.RLock() defer p.mut.RUnlock() return p.m[iface][property].Value }
go
func (p *Properties) GetMust(iface, property string) interface{} { p.mut.RLock() defer p.mut.RUnlock() return p.m[iface][property].Value }
[ "func", "(", "p", "*", "Properties", ")", "GetMust", "(", "iface", ",", "property", "string", ")", "interface", "{", "}", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "RUnlock", "(", ")", "\n", "return", "p",...
// GetMust returns the value of the given property and panics if either the // interface or the property name are invalid.
[ "GetMust", "returns", "the", "value", "of", "the", "given", "property", "and", "panics", "if", "either", "the", "interface", "or", "the", "property", "name", "are", "invalid", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L202-L206
train
godbus/dbus
prop/prop.go
Introspection
func (p *Properties) Introspection(iface string) []introspect.Property { p.mut.RLock() defer p.mut.RUnlock() m := p.m[iface] s := make([]introspect.Property, 0, len(m)) for k, v := range m { p := introspect.Property{Name: k, Type: dbus.SignatureOf(v.Value).String()} if v.Writable { p.Access = "readwrite" } else { p.Access = "read" } s = append(s, p) } return s }
go
func (p *Properties) Introspection(iface string) []introspect.Property { p.mut.RLock() defer p.mut.RUnlock() m := p.m[iface] s := make([]introspect.Property, 0, len(m)) for k, v := range m { p := introspect.Property{Name: k, Type: dbus.SignatureOf(v.Value).String()} if v.Writable { p.Access = "readwrite" } else { p.Access = "read" } s = append(s, p) } return s }
[ "func", "(", "p", "*", "Properties", ")", "Introspection", "(", "iface", "string", ")", "[", "]", "introspect", ".", "Property", "{", "p", ".", "mut", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "RUnlock", "(", ")", "\n", "m", ":...
// Introspection returns the introspection data that represents the properties // of iface.
[ "Introspection", "returns", "the", "introspection", "data", "that", "represents", "the", "properties", "of", "iface", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L210-L225
train
godbus/dbus
prop/prop.go
set
func (p *Properties) set(iface, property string, v interface{}) error { prop := p.m[iface][property] prop.Value = v switch prop.Emit { case EmitFalse: return nil // do nothing case EmitInvalidates: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{}, []string{property}) case EmitTrue: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{property: dbus.MakeVariant(v)}, []string{}) default: panic("invalid value for EmitType") } }
go
func (p *Properties) set(iface, property string, v interface{}) error { prop := p.m[iface][property] prop.Value = v switch prop.Emit { case EmitFalse: return nil // do nothing case EmitInvalidates: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{}, []string{property}) case EmitTrue: return p.conn.Emit(p.path, "org.freedesktop.DBus.Properties.PropertiesChanged", iface, map[string]dbus.Variant{property: dbus.MakeVariant(v)}, []string{}) default: panic("invalid value for EmitType") } }
[ "func", "(", "p", "*", "Properties", ")", "set", "(", "iface", ",", "property", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "prop", ":=", "p", ".", "m", "[", "iface", "]", "[", "property", "]", "\n", "prop", ".", "Value", "=", ...
// set sets the given property and emits PropertyChanged if appropiate. p.mut // must already be locked.
[ "set", "sets", "the", "given", "property", "and", "emits", "PropertyChanged", "if", "appropiate", ".", "p", ".", "mut", "must", "already", "be", "locked", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L229-L245
train
godbus/dbus
prop/prop.go
Set
func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error { p.mut.Lock() defer p.mut.Unlock() m, ok := p.m[iface] if !ok { return ErrIfaceNotFound } prop, ok := m[property] if !ok { return ErrPropNotFound } if !prop.Writable { return ErrReadOnly } if newv.Signature() != dbus.SignatureOf(prop.Value) { return ErrInvalidArg } if prop.Callback != nil { err := prop.Callback(&Change{p, iface, property, newv.Value()}) if err != nil { return err } } if err := p.set(iface, property, newv.Value()); err != nil { return dbus.MakeFailedError(err) } return nil }
go
func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error { p.mut.Lock() defer p.mut.Unlock() m, ok := p.m[iface] if !ok { return ErrIfaceNotFound } prop, ok := m[property] if !ok { return ErrPropNotFound } if !prop.Writable { return ErrReadOnly } if newv.Signature() != dbus.SignatureOf(prop.Value) { return ErrInvalidArg } if prop.Callback != nil { err := prop.Callback(&Change{p, iface, property, newv.Value()}) if err != nil { return err } } if err := p.set(iface, property, newv.Value()); err != nil { return dbus.MakeFailedError(err) } return nil }
[ "func", "(", "p", "*", "Properties", ")", "Set", "(", "iface", ",", "property", "string", ",", "newv", "dbus", ".", "Variant", ")", "*", "dbus", ".", "Error", "{", "p", ".", "mut", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mut", ".", "Un...
// Set implements org.freedesktop.Properties.Set.
[ "Set", "implements", "org", ".", "freedesktop", ".", "Properties", ".", "Set", "." ]
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/prop/prop.go#L248-L275
train
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 i...
// 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
train
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", "("...
// 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
train
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
train
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", ".", ...
// 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
train
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",...
// 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
train
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", "-",...
// 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
train
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", "}", "(",...
// 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
train
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", ...
// 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", ...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/export.go#L292-L294
train
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", "(", "met...
// 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
train
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", ...
// 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
train
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", "(", "\"",...
// 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
train
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...
// 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", ".", "freed...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/introspect/introspectable.go#L20-L36
train
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"...
// 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
train
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", ...
// 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", ...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/message.go#L213-L253
train
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",...
// 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
train
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", ...
// 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
train
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", ","...
// 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", "stat...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/call.go#L49-L55
train
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", "(", "\"", "\"", ")", ...
// 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"...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/dbus.go#L47-L58
train
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", "]", "!=", "'/'", "{", "re...
// 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
train
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", ...
// 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
train
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", ",", "...
// 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
train
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", ":=", "st...
// 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
train
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", ",", "\"", "\...
// 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
train
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"...
// 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
train
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", "...
// 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
train
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
train
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
train
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
train
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", ".", "Un...
// 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", "chan...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L266-L270
train
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", ...
// 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
train
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"...
// 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
train
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", ...
ade71ed3457e1a2d0edc32a59e718cc523e73b21
https://github.com/godbus/dbus/blob/ade71ed3457e1a2d0edc32a59e718cc523e73b21/conn.go#L524-L526
train
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
train
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", "...
// 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
train
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", ".", "...
// 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
train
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", ...
// 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
train
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", ...
// 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
train
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", "+",...
// 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
train
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...
// 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
train
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", "// D...
// 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
train
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", ":", "ove...
// 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", "...
d2f17ae9f9297cad64f18f15d537397e8783627b
https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/writer.go#L55-L60
train
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", "{",...
// LevelWrite implements LevelWriter.
[ "LevelWrite", "implements", "LevelWriter", "." ]
d2f17ae9f9297cad64f18f15d537397e8783627b
https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/writer.go#L68-L74
train
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", ".", "(",...
// 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
train
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
train
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", "...
// 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
train
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", ...
// 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
train
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", ":=...
// 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
train
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", "...
// 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
train
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", ".", "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
train
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", "(",...
// 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
train
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
train
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", "...
// 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
train
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", ...
// 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
train
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", "(", "\"", "\"", ",", "...
// 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
train
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", ")", "...
// 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
train
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", ".", ...
// 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
train
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
train
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", "re...
// 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
train
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", "{", "ou...
// New returns a configured logger.
[ "New", "returns", "a", "configured", "logger", "." ]
d2f17ae9f9297cad64f18f15d537397e8783627b
https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L58-L95
train
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 stdl...
// 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
train
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", "...
// JSON logging function
[ "JSON", "logging", "function" ]
d2f17ae9f9297cad64f18f15d537397e8783627b
https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L301-L350
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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"...
// 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
train
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...
d2f17ae9f9297cad64f18f15d537397e8783627b
https://github.com/hashicorp/go-hclog/blob/d2f17ae9f9297cad64f18f15d537397e8783627b/intlogger.go#L496-L502
train