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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
Jeffail/gabs | gabs.go | Index | func (g *Container) Index(index int) *Container {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}
}
return &Container{array[index]}
}
return &Container{nil}
} | go | func (g *Container) Index(index int) *Container {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}
}
return &Container{array[index]}
}
return &Container{nil}
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Index",
"(",
"index",
"int",
")",
"*",
"Container",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"if",
"index",
">=",
"len",
"(",
"array",
")",
"{",
"return",
"&",
"Container",
"{",
"nil",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Container",
"{",
"array",
"[",
"index",
"]",
"}",
"\n",
"}",
"\n",
"return",
"&",
"Container",
"{",
"nil",
"}",
"\n",
"}"
] | // Index - Attempt to find and return an object within a JSON array by index. | [
"Index",
"-",
"Attempt",
"to",
"find",
"and",
"return",
"an",
"object",
"within",
"a",
"JSON",
"array",
"by",
"index",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L139-L147 | train |
Jeffail/gabs | gabs.go | Children | func (g *Container) Children() ([]*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
children := make([]*Container, len(array))
for i := 0; i < len(array); i++ {
children[i] = &Container{array[i]}
}
return children, nil
}
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := []*Container{}
for _, obj := range mmap {
children = append(children, &Container{obj})
}
return children, nil
}
return nil, ErrNotObjOrArray
} | go | func (g *Container) Children() ([]*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
children := make([]*Container, len(array))
for i := 0; i < len(array); i++ {
children[i] = &Container{array[i]}
}
return children, nil
}
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := []*Container{}
for _, obj := range mmap {
children = append(children, &Container{obj})
}
return children, nil
}
return nil, ErrNotObjOrArray
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Children",
"(",
")",
"(",
"[",
"]",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"children",
":=",
"make",
"(",
"[",
"]",
"*",
"Container",
",",
"len",
"(",
"array",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"array",
")",
";",
"i",
"++",
"{",
"children",
"[",
"i",
"]",
"=",
"&",
"Container",
"{",
"array",
"[",
"i",
"]",
"}",
"\n",
"}",
"\n",
"return",
"children",
",",
"nil",
"\n",
"}",
"\n",
"if",
"mmap",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"children",
":=",
"[",
"]",
"*",
"Container",
"{",
"}",
"\n",
"for",
"_",
",",
"obj",
":=",
"range",
"mmap",
"{",
"children",
"=",
"append",
"(",
"children",
",",
"&",
"Container",
"{",
"obj",
"}",
")",
"\n",
"}",
"\n",
"return",
"children",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrNotObjOrArray",
"\n",
"}"
] | // Children - Return a slice of all the children of the array. This also works for objects, however,
// the children returned for an object will NOT be in order and you lose the names of the returned
// objects this way. | [
"Children",
"-",
"Return",
"a",
"slice",
"of",
"all",
"the",
"children",
"of",
"the",
"array",
".",
"This",
"also",
"works",
"for",
"objects",
"however",
"the",
"children",
"returned",
"for",
"an",
"object",
"will",
"NOT",
"be",
"in",
"order",
"and",
"you",
"lose",
"the",
"names",
"of",
"the",
"returned",
"objects",
"this",
"way",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L152-L168 | train |
Jeffail/gabs | gabs.go | ChildrenMap | func (g *Container) ChildrenMap() (map[string]*Container, error) {
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := map[string]*Container{}
for name, obj := range mmap {
children[name] = &Container{obj}
}
return children, nil
}
return nil, ErrNotObj
} | go | func (g *Container) ChildrenMap() (map[string]*Container, error) {
if mmap, ok := g.Data().(map[string]interface{}); ok {
children := map[string]*Container{}
for name, obj := range mmap {
children[name] = &Container{obj}
}
return children, nil
}
return nil, ErrNotObj
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ChildrenMap",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"mmap",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"children",
":=",
"map",
"[",
"string",
"]",
"*",
"Container",
"{",
"}",
"\n",
"for",
"name",
",",
"obj",
":=",
"range",
"mmap",
"{",
"children",
"[",
"name",
"]",
"=",
"&",
"Container",
"{",
"obj",
"}",
"\n",
"}",
"\n",
"return",
"children",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrNotObj",
"\n",
"}"
] | // ChildrenMap - Return a map of all the children of an object. | [
"ChildrenMap",
"-",
"Return",
"a",
"map",
"of",
"all",
"the",
"children",
"of",
"an",
"object",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L171-L180 | train |
Jeffail/gabs | gabs.go | SetP | func (g *Container) SetP(value interface{}, path string) (*Container, error) {
return g.Set(value, strings.Split(path, ".")...)
} | go | func (g *Container) SetP(value interface{}, path string) (*Container, error) {
return g.Set(value, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"SetP",
"(",
"value",
"interface",
"{",
"}",
",",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Set",
"(",
"value",
",",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // SetP - Does the same as Set, but using a dot notation JSON path. | [
"SetP",
"-",
"Does",
"the",
"same",
"as",
"Set",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L213-L215 | train |
Jeffail/gabs | gabs.go | SetIndex | func (g *Container) SetIndex(value interface{}, index int) (*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}, ErrOutOfBounds
}
array[index] = value
return &Container{array[index]}, nil
}
return &Container{nil}, ErrNotArray
} | go | func (g *Container) SetIndex(value interface{}, index int) (*Container, error) {
if array, ok := g.Data().([]interface{}); ok {
if index >= len(array) {
return &Container{nil}, ErrOutOfBounds
}
array[index] = value
return &Container{array[index]}, nil
}
return &Container{nil}, ErrNotArray
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"SetIndex",
"(",
"value",
"interface",
"{",
"}",
",",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"if",
"index",
">=",
"len",
"(",
"array",
")",
"{",
"return",
"&",
"Container",
"{",
"nil",
"}",
",",
"ErrOutOfBounds",
"\n",
"}",
"\n",
"array",
"[",
"index",
"]",
"=",
"value",
"\n",
"return",
"&",
"Container",
"{",
"array",
"[",
"index",
"]",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"Container",
"{",
"nil",
"}",
",",
"ErrNotArray",
"\n",
"}"
] | // SetIndex - Set a value of an array element based on the index. | [
"SetIndex",
"-",
"Set",
"a",
"value",
"of",
"an",
"array",
"element",
"based",
"on",
"the",
"index",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L218-L227 | train |
Jeffail/gabs | gabs.go | Object | func (g *Container) Object(path ...string) (*Container, error) {
return g.Set(map[string]interface{}{}, path...)
} | go | func (g *Container) Object(path ...string) (*Container, error) {
return g.Set(map[string]interface{}{}, path...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Object",
"(",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Set",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"path",
"...",
")",
"\n",
"}"
] | // Object - Create a new JSON object at a path. Returns an error if the path contains a collision
// with a non object type. | [
"Object",
"-",
"Create",
"a",
"new",
"JSON",
"object",
"at",
"a",
"path",
".",
"Returns",
"an",
"error",
"if",
"the",
"path",
"contains",
"a",
"collision",
"with",
"a",
"non",
"object",
"type",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L231-L233 | train |
Jeffail/gabs | gabs.go | ObjectP | func (g *Container) ObjectP(path string) (*Container, error) {
return g.Object(strings.Split(path, ".")...)
} | go | func (g *Container) ObjectP(path string) (*Container, error) {
return g.Object(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ObjectP",
"(",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Object",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ObjectP - Does the same as Object, but using a dot notation JSON path. | [
"ObjectP",
"-",
"Does",
"the",
"same",
"as",
"Object",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L236-L238 | train |
Jeffail/gabs | gabs.go | ObjectI | func (g *Container) ObjectI(index int) (*Container, error) {
return g.SetIndex(map[string]interface{}{}, index)
} | go | func (g *Container) ObjectI(index int) (*Container, error) {
return g.SetIndex(map[string]interface{}{}, index)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ObjectI",
"(",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"SetIndex",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"index",
")",
"\n",
"}"
] | // ObjectI - Create a new JSON object at an array index. Returns an error if the object is not an
// array or the index is out of bounds. | [
"ObjectI",
"-",
"Create",
"a",
"new",
"JSON",
"object",
"at",
"an",
"array",
"index",
".",
"Returns",
"an",
"error",
"if",
"the",
"object",
"is",
"not",
"an",
"array",
"or",
"the",
"index",
"is",
"out",
"of",
"bounds",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L242-L244 | train |
Jeffail/gabs | gabs.go | Array | func (g *Container) Array(path ...string) (*Container, error) {
return g.Set([]interface{}{}, path...)
} | go | func (g *Container) Array(path ...string) (*Container, error) {
return g.Set([]interface{}{}, path...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Array",
"(",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Set",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"path",
"...",
")",
"\n",
"}"
] | // Array - Create a new JSON array at a path. Returns an error if the path contains a collision with
// a non object type. | [
"Array",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"at",
"a",
"path",
".",
"Returns",
"an",
"error",
"if",
"the",
"path",
"contains",
"a",
"collision",
"with",
"a",
"non",
"object",
"type",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L248-L250 | train |
Jeffail/gabs | gabs.go | ArrayP | func (g *Container) ArrayP(path string) (*Container, error) {
return g.Array(strings.Split(path, ".")...)
} | go | func (g *Container) ArrayP(path string) (*Container, error) {
return g.Array(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayP",
"(",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"Array",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayP - Does the same as Array, but using a dot notation JSON path. | [
"ArrayP",
"-",
"Does",
"the",
"same",
"as",
"Array",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L253-L255 | train |
Jeffail/gabs | gabs.go | ArrayI | func (g *Container) ArrayI(index int) (*Container, error) {
return g.SetIndex([]interface{}{}, index)
} | go | func (g *Container) ArrayI(index int) (*Container, error) {
return g.SetIndex([]interface{}{}, index)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayI",
"(",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"SetIndex",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"index",
")",
"\n",
"}"
] | // ArrayI - Create a new JSON array at an array index. Returns an error if the object is not an
// array or the index is out of bounds. | [
"ArrayI",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"at",
"an",
"array",
"index",
".",
"Returns",
"an",
"error",
"if",
"the",
"object",
"is",
"not",
"an",
"array",
"or",
"the",
"index",
"is",
"out",
"of",
"bounds",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L259-L261 | train |
Jeffail/gabs | gabs.go | ArrayOfSize | func (g *Container) ArrayOfSize(size int, path ...string) (*Container, error) {
a := make([]interface{}, size)
return g.Set(a, path...)
} | go | func (g *Container) ArrayOfSize(size int, path ...string) (*Container, error) {
a := make([]interface{}, size)
return g.Set(a, path...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayOfSize",
"(",
"size",
"int",
",",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"size",
")",
"\n",
"return",
"g",
".",
"Set",
"(",
"a",
",",
"path",
"...",
")",
"\n",
"}"
] | // ArrayOfSize - Create a new JSON array of a particular size at a path. Returns an error if the
// path contains a collision with a non object type. | [
"ArrayOfSize",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"of",
"a",
"particular",
"size",
"at",
"a",
"path",
".",
"Returns",
"an",
"error",
"if",
"the",
"path",
"contains",
"a",
"collision",
"with",
"a",
"non",
"object",
"type",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L265-L268 | train |
Jeffail/gabs | gabs.go | ArrayOfSizeP | func (g *Container) ArrayOfSizeP(size int, path string) (*Container, error) {
return g.ArrayOfSize(size, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayOfSizeP(size int, path string) (*Container, error) {
return g.ArrayOfSize(size, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayOfSizeP",
"(",
"size",
"int",
",",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"ArrayOfSize",
"(",
"size",
",",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayOfSizeP - Does the same as ArrayOfSize, but using a dot notation JSON path. | [
"ArrayOfSizeP",
"-",
"Does",
"the",
"same",
"as",
"ArrayOfSize",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L271-L273 | train |
Jeffail/gabs | gabs.go | ArrayOfSizeI | func (g *Container) ArrayOfSizeI(size, index int) (*Container, error) {
a := make([]interface{}, size)
return g.SetIndex(a, index)
} | go | func (g *Container) ArrayOfSizeI(size, index int) (*Container, error) {
a := make([]interface{}, size)
return g.SetIndex(a, index)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayOfSizeI",
"(",
"size",
",",
"index",
"int",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"a",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"size",
")",
"\n",
"return",
"g",
".",
"SetIndex",
"(",
"a",
",",
"index",
")",
"\n",
"}"
] | // ArrayOfSizeI - Create a new JSON array of a particular size at an array index. Returns an error
// if the object is not an array or the index is out of bounds. | [
"ArrayOfSizeI",
"-",
"Create",
"a",
"new",
"JSON",
"array",
"of",
"a",
"particular",
"size",
"at",
"an",
"array",
"index",
".",
"Returns",
"an",
"error",
"if",
"the",
"object",
"is",
"not",
"an",
"array",
"or",
"the",
"index",
"is",
"out",
"of",
"bounds",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L277-L280 | train |
Jeffail/gabs | gabs.go | Delete | func (g *Container) Delete(path ...string) error {
var object interface{}
if g.object == nil {
return ErrNotObj
}
object = g.object
for target := 0; target < len(path); target++ {
if mmap, ok := object.(map[string]interface{}); ok {
if target == len(path)-1 {
if _, ok := mmap[path[target]]; ok {
delete(mmap, path[target])
} else {
return ErrNotObj
}
}
object = mmap[path[target]]
} else {
return ErrNotObj
}
}
return nil
} | go | func (g *Container) Delete(path ...string) error {
var object interface{}
if g.object == nil {
return ErrNotObj
}
object = g.object
for target := 0; target < len(path); target++ {
if mmap, ok := object.(map[string]interface{}); ok {
if target == len(path)-1 {
if _, ok := mmap[path[target]]; ok {
delete(mmap, path[target])
} else {
return ErrNotObj
}
}
object = mmap[path[target]]
} else {
return ErrNotObj
}
}
return nil
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"Delete",
"(",
"path",
"...",
"string",
")",
"error",
"{",
"var",
"object",
"interface",
"{",
"}",
"\n\n",
"if",
"g",
".",
"object",
"==",
"nil",
"{",
"return",
"ErrNotObj",
"\n",
"}",
"\n",
"object",
"=",
"g",
".",
"object",
"\n",
"for",
"target",
":=",
"0",
";",
"target",
"<",
"len",
"(",
"path",
")",
";",
"target",
"++",
"{",
"if",
"mmap",
",",
"ok",
":=",
"object",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"if",
"target",
"==",
"len",
"(",
"path",
")",
"-",
"1",
"{",
"if",
"_",
",",
"ok",
":=",
"mmap",
"[",
"path",
"[",
"target",
"]",
"]",
";",
"ok",
"{",
"delete",
"(",
"mmap",
",",
"path",
"[",
"target",
"]",
")",
"\n",
"}",
"else",
"{",
"return",
"ErrNotObj",
"\n",
"}",
"\n",
"}",
"\n",
"object",
"=",
"mmap",
"[",
"path",
"[",
"target",
"]",
"]",
"\n",
"}",
"else",
"{",
"return",
"ErrNotObj",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Delete - Delete an element at a JSON path, an error is returned if the element does not exist. | [
"Delete",
"-",
"Delete",
"an",
"element",
"at",
"a",
"JSON",
"path",
"an",
"error",
"is",
"returned",
"if",
"the",
"element",
"does",
"not",
"exist",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L283-L305 | train |
Jeffail/gabs | gabs.go | DeleteP | func (g *Container) DeleteP(path string) error {
return g.Delete(strings.Split(path, ".")...)
} | go | func (g *Container) DeleteP(path string) error {
return g.Delete(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"DeleteP",
"(",
"path",
"string",
")",
"error",
"{",
"return",
"g",
".",
"Delete",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // DeleteP - Does the same as Delete, but using a dot notation JSON path. | [
"DeleteP",
"-",
"Does",
"the",
"same",
"as",
"Delete",
"but",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L308-L310 | train |
Jeffail/gabs | gabs.go | ArrayAppendP | func (g *Container) ArrayAppendP(value interface{}, path string) error {
return g.ArrayAppend(value, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayAppendP(value interface{}, path string) error {
return g.ArrayAppend(value, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayAppendP",
"(",
"value",
"interface",
"{",
"}",
",",
"path",
"string",
")",
"error",
"{",
"return",
"g",
".",
"ArrayAppend",
"(",
"value",
",",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayAppendP - Append a value onto a JSON array using a dot notation JSON path. | [
"ArrayAppendP",
"-",
"Append",
"a",
"value",
"onto",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L409-L411 | train |
Jeffail/gabs | gabs.go | ArrayRemove | func (g *Container) ArrayRemove(index int, path ...string) error {
if index < 0 {
return ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return ErrNotArray
}
if index < len(array) {
array = append(array[:index], array[index+1:]...)
} else {
return ErrOutOfBounds
}
_, err := g.Set(array, path...)
return err
} | go | func (g *Container) ArrayRemove(index int, path ...string) error {
if index < 0 {
return ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return ErrNotArray
}
if index < len(array) {
array = append(array[:index], array[index+1:]...)
} else {
return ErrOutOfBounds
}
_, err := g.Set(array, path...)
return err
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayRemove",
"(",
"index",
"int",
",",
"path",
"...",
"string",
")",
"error",
"{",
"if",
"index",
"<",
"0",
"{",
"return",
"ErrOutOfBounds",
"\n",
"}",
"\n",
"array",
",",
"ok",
":=",
"g",
".",
"Search",
"(",
"path",
"...",
")",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"ErrNotArray",
"\n",
"}",
"\n",
"if",
"index",
"<",
"len",
"(",
"array",
")",
"{",
"array",
"=",
"append",
"(",
"array",
"[",
":",
"index",
"]",
",",
"array",
"[",
"index",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"}",
"else",
"{",
"return",
"ErrOutOfBounds",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"g",
".",
"Set",
"(",
"array",
",",
"path",
"...",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ArrayRemove - Remove an element from a JSON array. | [
"ArrayRemove",
"-",
"Remove",
"an",
"element",
"from",
"a",
"JSON",
"array",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L414-L429 | train |
Jeffail/gabs | gabs.go | ArrayRemoveP | func (g *Container) ArrayRemoveP(index int, path string) error {
return g.ArrayRemove(index, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayRemoveP(index int, path string) error {
return g.ArrayRemove(index, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayRemoveP",
"(",
"index",
"int",
",",
"path",
"string",
")",
"error",
"{",
"return",
"g",
".",
"ArrayRemove",
"(",
"index",
",",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayRemoveP - Remove an element from a JSON array using a dot notation JSON path. | [
"ArrayRemoveP",
"-",
"Remove",
"an",
"element",
"from",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L432-L434 | train |
Jeffail/gabs | gabs.go | ArrayElement | func (g *Container) ArrayElement(index int, path ...string) (*Container, error) {
if index < 0 {
return &Container{nil}, ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return &Container{nil}, ErrNotArray
}
if index < len(array) {
return &Container{array[index]}, nil
}
return &Container{nil}, ErrOutOfBounds
} | go | func (g *Container) ArrayElement(index int, path ...string) (*Container, error) {
if index < 0 {
return &Container{nil}, ErrOutOfBounds
}
array, ok := g.Search(path...).Data().([]interface{})
if !ok {
return &Container{nil}, ErrNotArray
}
if index < len(array) {
return &Container{array[index]}, nil
}
return &Container{nil}, ErrOutOfBounds
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayElement",
"(",
"index",
"int",
",",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"index",
"<",
"0",
"{",
"return",
"&",
"Container",
"{",
"nil",
"}",
",",
"ErrOutOfBounds",
"\n",
"}",
"\n",
"array",
",",
"ok",
":=",
"g",
".",
"Search",
"(",
"path",
"...",
")",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"&",
"Container",
"{",
"nil",
"}",
",",
"ErrNotArray",
"\n",
"}",
"\n",
"if",
"index",
"<",
"len",
"(",
"array",
")",
"{",
"return",
"&",
"Container",
"{",
"array",
"[",
"index",
"]",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"Container",
"{",
"nil",
"}",
",",
"ErrOutOfBounds",
"\n",
"}"
] | // ArrayElement - Access an element from a JSON array. | [
"ArrayElement",
"-",
"Access",
"an",
"element",
"from",
"a",
"JSON",
"array",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L437-L449 | train |
Jeffail/gabs | gabs.go | ArrayElementP | func (g *Container) ArrayElementP(index int, path string) (*Container, error) {
return g.ArrayElement(index, strings.Split(path, ".")...)
} | go | func (g *Container) ArrayElementP(index int, path string) (*Container, error) {
return g.ArrayElement(index, strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayElementP",
"(",
"index",
"int",
",",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"return",
"g",
".",
"ArrayElement",
"(",
"index",
",",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayElementP - Access an element from a JSON array using a dot notation JSON path. | [
"ArrayElementP",
"-",
"Access",
"an",
"element",
"from",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L452-L454 | train |
Jeffail/gabs | gabs.go | ArrayCount | func (g *Container) ArrayCount(path ...string) (int, error) {
if array, ok := g.Search(path...).Data().([]interface{}); ok {
return len(array), nil
}
return 0, ErrNotArray
} | go | func (g *Container) ArrayCount(path ...string) (int, error) {
if array, ok := g.Search(path...).Data().([]interface{}); ok {
return len(array), nil
}
return 0, ErrNotArray
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayCount",
"(",
"path",
"...",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Search",
"(",
"path",
"...",
")",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"{",
"return",
"len",
"(",
"array",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"ErrNotArray",
"\n",
"}"
] | // ArrayCount - Count the number of elements in a JSON array. | [
"ArrayCount",
"-",
"Count",
"the",
"number",
"of",
"elements",
"in",
"a",
"JSON",
"array",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L457-L462 | train |
Jeffail/gabs | gabs.go | ArrayCountP | func (g *Container) ArrayCountP(path string) (int, error) {
return g.ArrayCount(strings.Split(path, ".")...)
} | go | func (g *Container) ArrayCountP(path string) (int, error) {
return g.ArrayCount(strings.Split(path, ".")...)
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayCountP",
"(",
"path",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"g",
".",
"ArrayCount",
"(",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"}"
] | // ArrayCountP - Count the number of elements in a JSON array using a dot notation JSON path. | [
"ArrayCountP",
"-",
"Count",
"the",
"number",
"of",
"elements",
"in",
"a",
"JSON",
"array",
"using",
"a",
"dot",
"notation",
"JSON",
"path",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L465-L467 | train |
Jeffail/gabs | gabs.go | StringIndent | func (g *Container) StringIndent(prefix string, indent string) string {
return string(g.BytesIndent(prefix, indent))
} | go | func (g *Container) StringIndent(prefix string, indent string) string {
return string(g.BytesIndent(prefix, indent))
} | [
"func",
"(",
"g",
"*",
"Container",
")",
"StringIndent",
"(",
"prefix",
"string",
",",
"indent",
"string",
")",
"string",
"{",
"return",
"string",
"(",
"g",
".",
"BytesIndent",
"(",
"prefix",
",",
"indent",
")",
")",
"\n",
"}"
] | // StringIndent - Converts the contained object back to a JSON formatted string with prefix, indent. | [
"StringIndent",
"-",
"Converts",
"the",
"contained",
"object",
"back",
"to",
"a",
"JSON",
"formatted",
"string",
"with",
"prefix",
"indent",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L497-L499 | train |
Jeffail/gabs | gabs.go | EncodeOptHTMLEscape | func EncodeOptHTMLEscape(doEscape bool) EncodeOpt {
return func(e *json.Encoder) {
e.SetEscapeHTML(doEscape)
}
} | go | func EncodeOptHTMLEscape(doEscape bool) EncodeOpt {
return func(e *json.Encoder) {
e.SetEscapeHTML(doEscape)
}
} | [
"func",
"EncodeOptHTMLEscape",
"(",
"doEscape",
"bool",
")",
"EncodeOpt",
"{",
"return",
"func",
"(",
"e",
"*",
"json",
".",
"Encoder",
")",
"{",
"e",
".",
"SetEscapeHTML",
"(",
"doEscape",
")",
"\n",
"}",
"\n",
"}"
] | // EncodeOptHTMLEscape sets the encoder to escape the JSON for html. | [
"EncodeOptHTMLEscape",
"sets",
"the",
"encoder",
"to",
"escape",
"the",
"JSON",
"for",
"html",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L505-L509 | train |
Jeffail/gabs | gabs.go | EncodeOptIndent | func EncodeOptIndent(prefix string, indent string) EncodeOpt {
return func(e *json.Encoder) {
e.SetIndent(prefix, indent)
}
} | go | func EncodeOptIndent(prefix string, indent string) EncodeOpt {
return func(e *json.Encoder) {
e.SetIndent(prefix, indent)
}
} | [
"func",
"EncodeOptIndent",
"(",
"prefix",
"string",
",",
"indent",
"string",
")",
"EncodeOpt",
"{",
"return",
"func",
"(",
"e",
"*",
"json",
".",
"Encoder",
")",
"{",
"e",
".",
"SetIndent",
"(",
"prefix",
",",
"indent",
")",
"\n",
"}",
"\n",
"}"
] | // EncodeOptIndent sets the encoder to indent the JSON output. | [
"EncodeOptIndent",
"sets",
"the",
"encoder",
"to",
"indent",
"the",
"JSON",
"output",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L512-L516 | train |
Jeffail/gabs | gabs.go | ParseJSON | func ParseJSON(sample []byte) (*Container, error) {
var gabs Container
if err := json.Unmarshal(sample, &gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | go | func ParseJSON(sample []byte) (*Container, error) {
var gabs Container
if err := json.Unmarshal(sample, &gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | [
"func",
"ParseJSON",
"(",
"sample",
"[",
"]",
"byte",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"var",
"gabs",
"Container",
"\n\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"sample",
",",
"&",
"gabs",
".",
"object",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"gabs",
",",
"nil",
"\n",
"}"
] | // ParseJSON - Convert a string into a representation of the parsed JSON. | [
"ParseJSON",
"-",
"Convert",
"a",
"string",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L550-L558 | train |
Jeffail/gabs | gabs.go | ParseJSONDecoder | func ParseJSONDecoder(decoder *json.Decoder) (*Container, error) {
var gabs Container
if err := decoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | go | func ParseJSONDecoder(decoder *json.Decoder) (*Container, error) {
var gabs Container
if err := decoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | [
"func",
"ParseJSONDecoder",
"(",
"decoder",
"*",
"json",
".",
"Decoder",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"var",
"gabs",
"Container",
"\n\n",
"if",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"gabs",
".",
"object",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"gabs",
",",
"nil",
"\n",
"}"
] | // ParseJSONDecoder - Convert a json.Decoder into a representation of the parsed JSON. | [
"ParseJSONDecoder",
"-",
"Convert",
"a",
"json",
".",
"Decoder",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L561-L569 | train |
Jeffail/gabs | gabs.go | ParseJSONFile | func ParseJSONFile(path string) (*Container, error) {
if len(path) > 0 {
cBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
container, err := ParseJSON(cBytes)
if err != nil {
return nil, err
}
return container, nil
}
return nil, ErrInvalidPath
} | go | func ParseJSONFile(path string) (*Container, error) {
if len(path) > 0 {
cBytes, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
container, err := ParseJSON(cBytes)
if err != nil {
return nil, err
}
return container, nil
}
return nil, ErrInvalidPath
} | [
"func",
"ParseJSONFile",
"(",
"path",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"len",
"(",
"path",
")",
">",
"0",
"{",
"cBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"container",
",",
"err",
":=",
"ParseJSON",
"(",
"cBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"container",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"ErrInvalidPath",
"\n",
"}"
] | // ParseJSONFile - Read a file and convert into a representation of the parsed JSON. | [
"ParseJSONFile",
"-",
"Read",
"a",
"file",
"and",
"convert",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L572-L587 | train |
Jeffail/gabs | gabs.go | ParseJSONBuffer | func ParseJSONBuffer(buffer io.Reader) (*Container, error) {
var gabs Container
jsonDecoder := json.NewDecoder(buffer)
if err := jsonDecoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | go | func ParseJSONBuffer(buffer io.Reader) (*Container, error) {
var gabs Container
jsonDecoder := json.NewDecoder(buffer)
if err := jsonDecoder.Decode(&gabs.object); err != nil {
return nil, err
}
return &gabs, nil
} | [
"func",
"ParseJSONBuffer",
"(",
"buffer",
"io",
".",
"Reader",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"var",
"gabs",
"Container",
"\n",
"jsonDecoder",
":=",
"json",
".",
"NewDecoder",
"(",
"buffer",
")",
"\n",
"if",
"err",
":=",
"jsonDecoder",
".",
"Decode",
"(",
"&",
"gabs",
".",
"object",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"gabs",
",",
"nil",
"\n",
"}"
] | // ParseJSONBuffer - Read the contents of a buffer into a representation of the parsed JSON. | [
"ParseJSONBuffer",
"-",
"Read",
"the",
"contents",
"of",
"a",
"buffer",
"into",
"a",
"representation",
"of",
"the",
"parsed",
"JSON",
"."
] | 74ef14cf8f407ee3ca8ec01bb6f52d6104edea80 | https://github.com/Jeffail/gabs/blob/74ef14cf8f407ee3ca8ec01bb6f52d6104edea80/gabs.go#L590-L598 | train |
h2non/filetype | kind.go | Image | func Image(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Image)
} | go | func Image(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Image)
} | [
"func",
"Image",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Image",
")",
"\n",
"}"
] | // Image tries to match a file as image type | [
"Image",
"tries",
"to",
"match",
"a",
"file",
"as",
"image",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L9-L11 | train |
h2non/filetype | kind.go | IsImage | func IsImage(buf []byte) bool {
kind, _ := Image(buf)
return kind != types.Unknown
} | go | func IsImage(buf []byte) bool {
kind, _ := Image(buf)
return kind != types.Unknown
} | [
"func",
"IsImage",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Image",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsImage checks if the given buffer is an image type | [
"IsImage",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"image",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L14-L17 | train |
h2non/filetype | kind.go | Audio | func Audio(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Audio)
} | go | func Audio(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Audio)
} | [
"func",
"Audio",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Audio",
")",
"\n",
"}"
] | // Audio tries to match a file as audio type | [
"Audio",
"tries",
"to",
"match",
"a",
"file",
"as",
"audio",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L20-L22 | train |
h2non/filetype | kind.go | IsAudio | func IsAudio(buf []byte) bool {
kind, _ := Audio(buf)
return kind != types.Unknown
} | go | func IsAudio(buf []byte) bool {
kind, _ := Audio(buf)
return kind != types.Unknown
} | [
"func",
"IsAudio",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Audio",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsAudio checks if the given buffer is an audio type | [
"IsAudio",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"audio",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L25-L28 | train |
h2non/filetype | kind.go | Video | func Video(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Video)
} | go | func Video(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Video)
} | [
"func",
"Video",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Video",
")",
"\n",
"}"
] | // Video tries to match a file as video type | [
"Video",
"tries",
"to",
"match",
"a",
"file",
"as",
"video",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L31-L33 | train |
h2non/filetype | kind.go | IsVideo | func IsVideo(buf []byte) bool {
kind, _ := Video(buf)
return kind != types.Unknown
} | go | func IsVideo(buf []byte) bool {
kind, _ := Video(buf)
return kind != types.Unknown
} | [
"func",
"IsVideo",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Video",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsVideo checks if the given buffer is a video type | [
"IsVideo",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"a",
"video",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L36-L39 | train |
h2non/filetype | kind.go | Font | func Font(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Font)
} | go | func Font(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Font)
} | [
"func",
"Font",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Font",
")",
"\n",
"}"
] | // Font tries to match a file as text font type | [
"Font",
"tries",
"to",
"match",
"a",
"file",
"as",
"text",
"font",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L42-L44 | train |
h2non/filetype | kind.go | IsFont | func IsFont(buf []byte) bool {
kind, _ := Font(buf)
return kind != types.Unknown
} | go | func IsFont(buf []byte) bool {
kind, _ := Font(buf)
return kind != types.Unknown
} | [
"func",
"IsFont",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Font",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsFont checks if the given buffer is a font type | [
"IsFont",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"a",
"font",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L47-L50 | train |
h2non/filetype | kind.go | Archive | func Archive(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Archive)
} | go | func Archive(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Archive)
} | [
"func",
"Archive",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Archive",
")",
"\n",
"}"
] | // Archive tries to match a file as generic archive type | [
"Archive",
"tries",
"to",
"match",
"a",
"file",
"as",
"generic",
"archive",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L53-L55 | train |
h2non/filetype | kind.go | IsArchive | func IsArchive(buf []byte) bool {
kind, _ := Archive(buf)
return kind != types.Unknown
} | go | func IsArchive(buf []byte) bool {
kind, _ := Archive(buf)
return kind != types.Unknown
} | [
"func",
"IsArchive",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Archive",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsArchive checks if the given buffer is an archive type | [
"IsArchive",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"archive",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L58-L61 | train |
h2non/filetype | kind.go | Document | func Document(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Document)
} | go | func Document(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Document)
} | [
"func",
"Document",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"return",
"doMatchMap",
"(",
"buf",
",",
"matchers",
".",
"Document",
")",
"\n",
"}"
] | // Document tries to match a file as document type | [
"Document",
"tries",
"to",
"match",
"a",
"file",
"as",
"document",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L64-L66 | train |
h2non/filetype | kind.go | IsDocument | func IsDocument(buf []byte) bool {
kind, _ := Document(buf)
return kind != types.Unknown
} | go | func IsDocument(buf []byte) bool {
kind, _ := Document(buf)
return kind != types.Unknown
} | [
"func",
"IsDocument",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Document",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsDocument checks if the given buffer is an document type | [
"IsDocument",
"checks",
"if",
"the",
"given",
"buffer",
"is",
"an",
"document",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/kind.go#L69-L72 | train |
h2non/filetype | matchers/application.go | Wasm | func Wasm(buf []byte) bool {
// WASM has starts with `\0asm`, followed by the version.
// http://webassembly.github.io/spec/core/binary/modules.html#binary-magic
return len(buf) >= 8 &&
buf[0] == 0x00 && buf[1] == 0x61 &&
buf[2] == 0x73 && buf[3] == 0x6D &&
buf[4] == 0x01 && buf[5] == 0x00 &&
buf[6] == 0x00 && buf[7] == 0x00
} | go | func Wasm(buf []byte) bool {
// WASM has starts with `\0asm`, followed by the version.
// http://webassembly.github.io/spec/core/binary/modules.html#binary-magic
return len(buf) >= 8 &&
buf[0] == 0x00 && buf[1] == 0x61 &&
buf[2] == 0x73 && buf[3] == 0x6D &&
buf[4] == 0x01 && buf[5] == 0x00 &&
buf[6] == 0x00 && buf[7] == 0x00
} | [
"func",
"Wasm",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"// WASM has starts with `\\0asm`, followed by the version.",
"// http://webassembly.github.io/spec/core/binary/modules.html#binary-magic",
"return",
"len",
"(",
"buf",
")",
">=",
"8",
"&&",
"buf",
"[",
"0",
"]",
"==",
"0x00",
"&&",
"buf",
"[",
"1",
"]",
"==",
"0x61",
"&&",
"buf",
"[",
"2",
"]",
"==",
"0x73",
"&&",
"buf",
"[",
"3",
"]",
"==",
"0x6D",
"&&",
"buf",
"[",
"4",
"]",
"==",
"0x01",
"&&",
"buf",
"[",
"5",
"]",
"==",
"0x00",
"&&",
"buf",
"[",
"6",
"]",
"==",
"0x00",
"&&",
"buf",
"[",
"7",
"]",
"==",
"0x00",
"\n",
"}"
] | // Wasm detects a Web Assembly 1.0 filetype. | [
"Wasm",
"detects",
"a",
"Web",
"Assembly",
"1",
".",
"0",
"filetype",
"."
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/application.go#L12-L20 | train |
h2non/filetype | types/types.go | Get | func Get(ext string) Type {
kind := Types[ext]
if kind.Extension != "" {
return kind
}
return Unknown
} | go | func Get(ext string) Type {
kind := Types[ext]
if kind.Extension != "" {
return kind
}
return Unknown
} | [
"func",
"Get",
"(",
"ext",
"string",
")",
"Type",
"{",
"kind",
":=",
"Types",
"[",
"ext",
"]",
"\n",
"if",
"kind",
".",
"Extension",
"!=",
"\"",
"\"",
"{",
"return",
"kind",
"\n",
"}",
"\n",
"return",
"Unknown",
"\n",
"}"
] | // Get retrieves a Type by extension | [
"Get",
"retrieves",
"a",
"Type",
"by",
"extension"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/types/types.go#L12-L18 | train |
h2non/filetype | filetype.go | AddType | func AddType(ext, mime string) types.Type {
return types.NewType(ext, mime)
} | go | func AddType(ext, mime string) types.Type {
return types.NewType(ext, mime)
} | [
"func",
"AddType",
"(",
"ext",
",",
"mime",
"string",
")",
"types",
".",
"Type",
"{",
"return",
"types",
".",
"NewType",
"(",
"ext",
",",
"mime",
")",
"\n",
"}"
] | // AddType registers a new file type | [
"AddType",
"registers",
"a",
"new",
"file",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L26-L28 | train |
h2non/filetype | filetype.go | Is | func Is(buf []byte, ext string) bool {
kind, ok := types.Types[ext]
if ok {
return IsType(buf, kind)
}
return false
} | go | func Is(buf []byte, ext string) bool {
kind, ok := types.Types[ext]
if ok {
return IsType(buf, kind)
}
return false
} | [
"func",
"Is",
"(",
"buf",
"[",
"]",
"byte",
",",
"ext",
"string",
")",
"bool",
"{",
"kind",
",",
"ok",
":=",
"types",
".",
"Types",
"[",
"ext",
"]",
"\n",
"if",
"ok",
"{",
"return",
"IsType",
"(",
"buf",
",",
"kind",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Is checks if a given buffer matches with the given file type extension | [
"Is",
"checks",
"if",
"a",
"given",
"buffer",
"matches",
"with",
"the",
"given",
"file",
"type",
"extension"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L31-L37 | train |
h2non/filetype | filetype.go | IsType | func IsType(buf []byte, kind types.Type) bool {
matcher := matchers.Matchers[kind]
if matcher == nil {
return false
}
return matcher(buf) != types.Unknown
} | go | func IsType(buf []byte, kind types.Type) bool {
matcher := matchers.Matchers[kind]
if matcher == nil {
return false
}
return matcher(buf) != types.Unknown
} | [
"func",
"IsType",
"(",
"buf",
"[",
"]",
"byte",
",",
"kind",
"types",
".",
"Type",
")",
"bool",
"{",
"matcher",
":=",
"matchers",
".",
"Matchers",
"[",
"kind",
"]",
"\n",
"if",
"matcher",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"matcher",
"(",
"buf",
")",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // IsType checks if a given buffer matches with the given file type | [
"IsType",
"checks",
"if",
"a",
"given",
"buffer",
"matches",
"with",
"the",
"given",
"file",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L45-L51 | train |
h2non/filetype | filetype.go | IsMIME | func IsMIME(buf []byte, mime string) bool {
for _, kind := range types.Types {
if kind.MIME.Value == mime {
matcher := matchers.Matchers[kind]
return matcher(buf) != types.Unknown
}
}
return false
} | go | func IsMIME(buf []byte, mime string) bool {
for _, kind := range types.Types {
if kind.MIME.Value == mime {
matcher := matchers.Matchers[kind]
return matcher(buf) != types.Unknown
}
}
return false
} | [
"func",
"IsMIME",
"(",
"buf",
"[",
"]",
"byte",
",",
"mime",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"kind",
":=",
"range",
"types",
".",
"Types",
"{",
"if",
"kind",
".",
"MIME",
".",
"Value",
"==",
"mime",
"{",
"matcher",
":=",
"matchers",
".",
"Matchers",
"[",
"kind",
"]",
"\n",
"return",
"matcher",
"(",
"buf",
")",
"!=",
"types",
".",
"Unknown",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsMIME checks if a given buffer matches with the given MIME type | [
"IsMIME",
"checks",
"if",
"a",
"given",
"buffer",
"matches",
"with",
"the",
"given",
"MIME",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L54-L62 | train |
h2non/filetype | filetype.go | IsSupported | func IsSupported(ext string) bool {
for name := range Types {
if name == ext {
return true
}
}
return false
} | go | func IsSupported(ext string) bool {
for name := range Types {
if name == ext {
return true
}
}
return false
} | [
"func",
"IsSupported",
"(",
"ext",
"string",
")",
"bool",
"{",
"for",
"name",
":=",
"range",
"Types",
"{",
"if",
"name",
"==",
"ext",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsSupported checks if a given file extension is supported | [
"IsSupported",
"checks",
"if",
"a",
"given",
"file",
"extension",
"is",
"supported"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L65-L72 | train |
h2non/filetype | filetype.go | IsMIMESupported | func IsMIMESupported(mime string) bool {
for _, m := range Types {
if m.MIME.Value == mime {
return true
}
}
return false
} | go | func IsMIMESupported(mime string) bool {
for _, m := range Types {
if m.MIME.Value == mime {
return true
}
}
return false
} | [
"func",
"IsMIMESupported",
"(",
"mime",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"Types",
"{",
"if",
"m",
".",
"MIME",
".",
"Value",
"==",
"mime",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsMIMESupported checks if a given MIME type is supported | [
"IsMIMESupported",
"checks",
"if",
"a",
"given",
"MIME",
"type",
"is",
"supported"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/filetype.go#L75-L82 | train |
h2non/filetype | types/mime.go | NewMIME | func NewMIME(mime string) MIME {
kind, subtype := splitMime(mime)
return MIME{Type: kind, Subtype: subtype, Value: mime}
} | go | func NewMIME(mime string) MIME {
kind, subtype := splitMime(mime)
return MIME{Type: kind, Subtype: subtype, Value: mime}
} | [
"func",
"NewMIME",
"(",
"mime",
"string",
")",
"MIME",
"{",
"kind",
",",
"subtype",
":=",
"splitMime",
"(",
"mime",
")",
"\n",
"return",
"MIME",
"{",
"Type",
":",
"kind",
",",
"Subtype",
":",
"subtype",
",",
"Value",
":",
"mime",
"}",
"\n",
"}"
] | // Creates a new MIME type | [
"Creates",
"a",
"new",
"MIME",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/types/mime.go#L11-L14 | train |
h2non/filetype | matchers/matchers.go | NewMatcher | func NewMatcher(kind types.Type, fn Matcher) TypeMatcher {
matcher := func(buf []byte) types.Type {
if fn(buf) {
return kind
}
return types.Unknown
}
Matchers[kind] = matcher
// prepend here so any user defined matchers get added first
MatcherKeys = append([]types.Type{kind}, MatcherKeys...)
return matcher
} | go | func NewMatcher(kind types.Type, fn Matcher) TypeMatcher {
matcher := func(buf []byte) types.Type {
if fn(buf) {
return kind
}
return types.Unknown
}
Matchers[kind] = matcher
// prepend here so any user defined matchers get added first
MatcherKeys = append([]types.Type{kind}, MatcherKeys...)
return matcher
} | [
"func",
"NewMatcher",
"(",
"kind",
"types",
".",
"Type",
",",
"fn",
"Matcher",
")",
"TypeMatcher",
"{",
"matcher",
":=",
"func",
"(",
"buf",
"[",
"]",
"byte",
")",
"types",
".",
"Type",
"{",
"if",
"fn",
"(",
"buf",
")",
"{",
"return",
"kind",
"\n",
"}",
"\n",
"return",
"types",
".",
"Unknown",
"\n",
"}",
"\n\n",
"Matchers",
"[",
"kind",
"]",
"=",
"matcher",
"\n",
"// prepend here so any user defined matchers get added first",
"MatcherKeys",
"=",
"append",
"(",
"[",
"]",
"types",
".",
"Type",
"{",
"kind",
"}",
",",
"MatcherKeys",
"...",
")",
"\n",
"return",
"matcher",
"\n",
"}"
] | // Create and register a new type matcher function | [
"Create",
"and",
"register",
"a",
"new",
"type",
"matcher",
"function"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/matchers.go#L24-L36 | train |
h2non/filetype | types/type.go | NewType | func NewType(ext, mime string) Type {
t := Type{
MIME: NewMIME(mime),
Extension: ext,
}
return Add(t)
} | go | func NewType(ext, mime string) Type {
t := Type{
MIME: NewMIME(mime),
Extension: ext,
}
return Add(t)
} | [
"func",
"NewType",
"(",
"ext",
",",
"mime",
"string",
")",
"Type",
"{",
"t",
":=",
"Type",
"{",
"MIME",
":",
"NewMIME",
"(",
"mime",
")",
",",
"Extension",
":",
"ext",
",",
"}",
"\n",
"return",
"Add",
"(",
"t",
")",
"\n",
"}"
] | // NewType creates a new Type | [
"NewType",
"creates",
"a",
"new",
"Type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/types/type.go#L10-L16 | train |
h2non/filetype | matchers/isobmff/isobmff.go | IsISOBMFF | func IsISOBMFF(buf []byte) bool {
if len(buf) < 16 || string(buf[4:8]) != "ftyp" {
return false
}
if ftypLength := binary.BigEndian.Uint32(buf[0:4]); len(buf) < int(ftypLength) {
return false
}
return true
} | go | func IsISOBMFF(buf []byte) bool {
if len(buf) < 16 || string(buf[4:8]) != "ftyp" {
return false
}
if ftypLength := binary.BigEndian.Uint32(buf[0:4]); len(buf) < int(ftypLength) {
return false
}
return true
} | [
"func",
"IsISOBMFF",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"len",
"(",
"buf",
")",
"<",
"16",
"||",
"string",
"(",
"buf",
"[",
"4",
":",
"8",
"]",
")",
"!=",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"ftypLength",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"buf",
"[",
"0",
":",
"4",
"]",
")",
";",
"len",
"(",
"buf",
")",
"<",
"int",
"(",
"ftypLength",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // IsISOBMFF checks whether the given buffer represents ISO Base Media File Format data | [
"IsISOBMFF",
"checks",
"whether",
"the",
"given",
"buffer",
"represents",
"ISO",
"Base",
"Media",
"File",
"Format",
"data"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/isobmff/isobmff.go#L6-L16 | train |
h2non/filetype | matchers/isobmff/isobmff.go | GetFtyp | func GetFtyp(buf []byte) (string, string, []string) {
ftypLength := binary.BigEndian.Uint32(buf[0:4])
majorBrand := string(buf[8:12])
minorVersion := string(buf[12:16])
compatibleBrands := []string{}
for i := 16; i < int(ftypLength); i += 4 {
compatibleBrands = append(compatibleBrands, string(buf[i:i+4]))
}
return majorBrand, minorVersion, compatibleBrands
} | go | func GetFtyp(buf []byte) (string, string, []string) {
ftypLength := binary.BigEndian.Uint32(buf[0:4])
majorBrand := string(buf[8:12])
minorVersion := string(buf[12:16])
compatibleBrands := []string{}
for i := 16; i < int(ftypLength); i += 4 {
compatibleBrands = append(compatibleBrands, string(buf[i:i+4]))
}
return majorBrand, minorVersion, compatibleBrands
} | [
"func",
"GetFtyp",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"string",
",",
"string",
",",
"[",
"]",
"string",
")",
"{",
"ftypLength",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"buf",
"[",
"0",
":",
"4",
"]",
")",
"\n\n",
"majorBrand",
":=",
"string",
"(",
"buf",
"[",
"8",
":",
"12",
"]",
")",
"\n",
"minorVersion",
":=",
"string",
"(",
"buf",
"[",
"12",
":",
"16",
"]",
")",
"\n\n",
"compatibleBrands",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"i",
":=",
"16",
";",
"i",
"<",
"int",
"(",
"ftypLength",
")",
";",
"i",
"+=",
"4",
"{",
"compatibleBrands",
"=",
"append",
"(",
"compatibleBrands",
",",
"string",
"(",
"buf",
"[",
"i",
":",
"i",
"+",
"4",
"]",
")",
")",
"\n",
"}",
"\n\n",
"return",
"majorBrand",
",",
"minorVersion",
",",
"compatibleBrands",
"\n",
"}"
] | // GetFtyp returns the major brand, minor version and compatible brands of the ISO-BMFF data | [
"GetFtyp",
"returns",
"the",
"major",
"brand",
"minor",
"version",
"and",
"compatible",
"brands",
"of",
"the",
"ISO",
"-",
"BMFF",
"data"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/matchers/isobmff/isobmff.go#L19-L31 | train |
h2non/filetype | match.go | Match | func Match(buf []byte) (types.Type, error) {
length := len(buf)
if length == 0 {
return types.Unknown, ErrEmptyBuffer
}
for _, kind := range *MatcherKeys {
checker := Matchers[kind]
match := checker(buf)
if match != types.Unknown && match.Extension != "" {
return match, nil
}
}
return types.Unknown, nil
} | go | func Match(buf []byte) (types.Type, error) {
length := len(buf)
if length == 0 {
return types.Unknown, ErrEmptyBuffer
}
for _, kind := range *MatcherKeys {
checker := Matchers[kind]
match := checker(buf)
if match != types.Unknown && match.Extension != "" {
return match, nil
}
}
return types.Unknown, nil
} | [
"func",
"Match",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"length",
":=",
"len",
"(",
"buf",
")",
"\n",
"if",
"length",
"==",
"0",
"{",
"return",
"types",
".",
"Unknown",
",",
"ErrEmptyBuffer",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"kind",
":=",
"range",
"*",
"MatcherKeys",
"{",
"checker",
":=",
"Matchers",
"[",
"kind",
"]",
"\n",
"match",
":=",
"checker",
"(",
"buf",
")",
"\n",
"if",
"match",
"!=",
"types",
".",
"Unknown",
"&&",
"match",
".",
"Extension",
"!=",
"\"",
"\"",
"{",
"return",
"match",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"types",
".",
"Unknown",
",",
"nil",
"\n",
"}"
] | // Match infers the file type of a given buffer inspecting its magic numbers signature | [
"Match",
"infers",
"the",
"file",
"type",
"of",
"a",
"given",
"buffer",
"inspecting",
"its",
"magic",
"numbers",
"signature"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L21-L36 | train |
h2non/filetype | match.go | MatchFile | func MatchFile(filepath string) (types.Type, error) {
file, err := os.Open(filepath)
if err != nil {
return types.Unknown, err
}
defer file.Close()
return MatchReader(file)
} | go | func MatchFile(filepath string) (types.Type, error) {
file, err := os.Open(filepath)
if err != nil {
return types.Unknown, err
}
defer file.Close()
return MatchReader(file)
} | [
"func",
"MatchFile",
"(",
"filepath",
"string",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"types",
".",
"Unknown",
",",
"err",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"return",
"MatchReader",
"(",
"file",
")",
"\n",
"}"
] | // MatchFile infers a file type for a file | [
"MatchFile",
"infers",
"a",
"file",
"type",
"for",
"a",
"file"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L44-L52 | train |
h2non/filetype | match.go | AddMatcher | func AddMatcher(fileType types.Type, matcher matchers.Matcher) matchers.TypeMatcher {
return matchers.NewMatcher(fileType, matcher)
} | go | func AddMatcher(fileType types.Type, matcher matchers.Matcher) matchers.TypeMatcher {
return matchers.NewMatcher(fileType, matcher)
} | [
"func",
"AddMatcher",
"(",
"fileType",
"types",
".",
"Type",
",",
"matcher",
"matchers",
".",
"Matcher",
")",
"matchers",
".",
"TypeMatcher",
"{",
"return",
"matchers",
".",
"NewMatcher",
"(",
"fileType",
",",
"matcher",
")",
"\n",
"}"
] | // AddMatcher registers a new matcher type | [
"AddMatcher",
"registers",
"a",
"new",
"matcher",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L67-L69 | train |
h2non/filetype | match.go | Matches | func Matches(buf []byte) bool {
kind, _ := Match(buf)
return kind != types.Unknown
} | go | func Matches(buf []byte) bool {
kind, _ := Match(buf)
return kind != types.Unknown
} | [
"func",
"Matches",
"(",
"buf",
"[",
"]",
"byte",
")",
"bool",
"{",
"kind",
",",
"_",
":=",
"Match",
"(",
"buf",
")",
"\n",
"return",
"kind",
"!=",
"types",
".",
"Unknown",
"\n",
"}"
] | // Matches checks if the given buffer matches with some supported file type | [
"Matches",
"checks",
"if",
"the",
"given",
"buffer",
"matches",
"with",
"some",
"supported",
"file",
"type"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L72-L75 | train |
h2non/filetype | match.go | MatchMap | func MatchMap(buf []byte, matchers matchers.Map) types.Type {
for kind, matcher := range matchers {
if matcher(buf) {
return kind
}
}
return types.Unknown
} | go | func MatchMap(buf []byte, matchers matchers.Map) types.Type {
for kind, matcher := range matchers {
if matcher(buf) {
return kind
}
}
return types.Unknown
} | [
"func",
"MatchMap",
"(",
"buf",
"[",
"]",
"byte",
",",
"matchers",
"matchers",
".",
"Map",
")",
"types",
".",
"Type",
"{",
"for",
"kind",
",",
"matcher",
":=",
"range",
"matchers",
"{",
"if",
"matcher",
"(",
"buf",
")",
"{",
"return",
"kind",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"types",
".",
"Unknown",
"\n",
"}"
] | // MatchMap performs a file matching against a map of match functions | [
"MatchMap",
"performs",
"a",
"file",
"matching",
"against",
"a",
"map",
"of",
"match",
"functions"
] | 2248f2e2f77cd8cf9694216e3f9589d71005de37 | https://github.com/h2non/filetype/blob/2248f2e2f77cd8cf9694216e3f9589d71005de37/match.go#L78-L85 | train |
coreos/go-systemd | sdjournal/read.go | NewJournalReader | func NewJournalReader(config JournalReaderConfig) (*JournalReader, error) {
// use simpleMessageFormatter as default formatter.
if config.Formatter == nil {
config.Formatter = simpleMessageFormatter
}
r := &JournalReader{
formatter: config.Formatter,
}
// Open the journal
var err error
if config.Path != "" {
r.journal, err = NewJournalFromDir(config.Path)
} else {
r.journal, err = NewJournal()
}
if err != nil {
return nil, err
}
// Add any supplied matches
for _, m := range config.Matches {
if err = r.journal.AddMatch(m.String()); err != nil {
return nil, err
}
}
// Set the start position based on options
if config.Since != 0 {
// Start based on a relative time
start := time.Now().Add(config.Since)
if err := r.journal.SeekRealtimeUsec(uint64(start.UnixNano() / 1000)); err != nil {
return nil, err
}
} else if config.NumFromTail != 0 {
// Start based on a number of lines before the tail
if err := r.journal.SeekTail(); err != nil {
return nil, err
}
// Move the read pointer into position near the tail. Go one further than
// the option so that the initial cursor advancement positions us at the
// correct starting point.
skip, err := r.journal.PreviousSkip(config.NumFromTail + 1)
if err != nil {
return nil, err
}
// If we skipped fewer lines than expected, we have reached journal start.
// Thus, we seek to head so that next invocation can read the first line.
if skip != config.NumFromTail+1 {
if err := r.journal.SeekHead(); err != nil {
return nil, err
}
}
} else if config.Cursor != "" {
// Start based on a custom cursor
if err := r.journal.SeekCursor(config.Cursor); err != nil {
return nil, err
}
}
return r, nil
} | go | func NewJournalReader(config JournalReaderConfig) (*JournalReader, error) {
// use simpleMessageFormatter as default formatter.
if config.Formatter == nil {
config.Formatter = simpleMessageFormatter
}
r := &JournalReader{
formatter: config.Formatter,
}
// Open the journal
var err error
if config.Path != "" {
r.journal, err = NewJournalFromDir(config.Path)
} else {
r.journal, err = NewJournal()
}
if err != nil {
return nil, err
}
// Add any supplied matches
for _, m := range config.Matches {
if err = r.journal.AddMatch(m.String()); err != nil {
return nil, err
}
}
// Set the start position based on options
if config.Since != 0 {
// Start based on a relative time
start := time.Now().Add(config.Since)
if err := r.journal.SeekRealtimeUsec(uint64(start.UnixNano() / 1000)); err != nil {
return nil, err
}
} else if config.NumFromTail != 0 {
// Start based on a number of lines before the tail
if err := r.journal.SeekTail(); err != nil {
return nil, err
}
// Move the read pointer into position near the tail. Go one further than
// the option so that the initial cursor advancement positions us at the
// correct starting point.
skip, err := r.journal.PreviousSkip(config.NumFromTail + 1)
if err != nil {
return nil, err
}
// If we skipped fewer lines than expected, we have reached journal start.
// Thus, we seek to head so that next invocation can read the first line.
if skip != config.NumFromTail+1 {
if err := r.journal.SeekHead(); err != nil {
return nil, err
}
}
} else if config.Cursor != "" {
// Start based on a custom cursor
if err := r.journal.SeekCursor(config.Cursor); err != nil {
return nil, err
}
}
return r, nil
} | [
"func",
"NewJournalReader",
"(",
"config",
"JournalReaderConfig",
")",
"(",
"*",
"JournalReader",
",",
"error",
")",
"{",
"// use simpleMessageFormatter as default formatter.",
"if",
"config",
".",
"Formatter",
"==",
"nil",
"{",
"config",
".",
"Formatter",
"=",
"simpleMessageFormatter",
"\n",
"}",
"\n\n",
"r",
":=",
"&",
"JournalReader",
"{",
"formatter",
":",
"config",
".",
"Formatter",
",",
"}",
"\n\n",
"// Open the journal",
"var",
"err",
"error",
"\n",
"if",
"config",
".",
"Path",
"!=",
"\"",
"\"",
"{",
"r",
".",
"journal",
",",
"err",
"=",
"NewJournalFromDir",
"(",
"config",
".",
"Path",
")",
"\n",
"}",
"else",
"{",
"r",
".",
"journal",
",",
"err",
"=",
"NewJournal",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Add any supplied matches",
"for",
"_",
",",
"m",
":=",
"range",
"config",
".",
"Matches",
"{",
"if",
"err",
"=",
"r",
".",
"journal",
".",
"AddMatch",
"(",
"m",
".",
"String",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Set the start position based on options",
"if",
"config",
".",
"Since",
"!=",
"0",
"{",
"// Start based on a relative time",
"start",
":=",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"config",
".",
"Since",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"journal",
".",
"SeekRealtimeUsec",
"(",
"uint64",
"(",
"start",
".",
"UnixNano",
"(",
")",
"/",
"1000",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"config",
".",
"NumFromTail",
"!=",
"0",
"{",
"// Start based on a number of lines before the tail",
"if",
"err",
":=",
"r",
".",
"journal",
".",
"SeekTail",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Move the read pointer into position near the tail. Go one further than",
"// the option so that the initial cursor advancement positions us at the",
"// correct starting point.",
"skip",
",",
"err",
":=",
"r",
".",
"journal",
".",
"PreviousSkip",
"(",
"config",
".",
"NumFromTail",
"+",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// If we skipped fewer lines than expected, we have reached journal start.",
"// Thus, we seek to head so that next invocation can read the first line.",
"if",
"skip",
"!=",
"config",
".",
"NumFromTail",
"+",
"1",
"{",
"if",
"err",
":=",
"r",
".",
"journal",
".",
"SeekHead",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"config",
".",
"Cursor",
"!=",
"\"",
"\"",
"{",
"// Start based on a custom cursor",
"if",
"err",
":=",
"r",
".",
"journal",
".",
"SeekCursor",
"(",
"config",
".",
"Cursor",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] | // NewJournalReader creates a new JournalReader with configuration options that are similar to the
// systemd journalctl tool's iteration and filtering features. | [
"NewJournalReader",
"creates",
"a",
"new",
"JournalReader",
"with",
"configuration",
"options",
"that",
"are",
"similar",
"to",
"the",
"systemd",
"journalctl",
"tool",
"s",
"iteration",
"and",
"filtering",
"features",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L67-L130 | train |
coreos/go-systemd | sdjournal/read.go | Rewind | func (r *JournalReader) Rewind() error {
r.msgReader = nil
return r.journal.SeekHead()
} | go | func (r *JournalReader) Rewind() error {
r.msgReader = nil
return r.journal.SeekHead()
} | [
"func",
"(",
"r",
"*",
"JournalReader",
")",
"Rewind",
"(",
")",
"error",
"{",
"r",
".",
"msgReader",
"=",
"nil",
"\n",
"return",
"r",
".",
"journal",
".",
"SeekHead",
"(",
")",
"\n",
"}"
] | // Rewind attempts to rewind the JournalReader to the first entry. | [
"Rewind",
"attempts",
"to",
"rewind",
"the",
"JournalReader",
"to",
"the",
"first",
"entry",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L192-L195 | train |
coreos/go-systemd | sdjournal/read.go | Follow | func (r *JournalReader) Follow(until <-chan time.Time, writer io.Writer) error {
// Process journal entries and events. Entries are flushed until the tail or
// timeout is reached, and then we wait for new events or the timeout.
var msg = make([]byte, 64*1<<(10))
var waitCh = make(chan int, 1)
var waitGroup sync.WaitGroup
defer waitGroup.Wait()
process:
for {
c, err := r.Read(msg)
if err != nil && err != io.EOF {
return err
}
select {
case <-until:
return ErrExpired
default:
}
if c > 0 {
if _, err = writer.Write(msg[:c]); err != nil {
return err
}
continue process
}
// We're at the tail, so wait for new events or time out.
// Holds journal events to process. Tightly bounded for now unless there's a
// reason to unblock the journal watch routine more quickly.
for {
waitGroup.Add(1)
go func() {
status := r.journal.Wait(100 * time.Millisecond)
waitCh <- status
waitGroup.Done()
}()
select {
case <-until:
return ErrExpired
case e := <-waitCh:
switch e {
case SD_JOURNAL_NOP:
// the journal did not change since the last invocation
case SD_JOURNAL_APPEND, SD_JOURNAL_INVALIDATE:
continue process
default:
if e < 0 {
return fmt.Errorf("received error event: %d", e)
}
log.Printf("received unknown event: %d\n", e)
}
}
}
}
} | go | func (r *JournalReader) Follow(until <-chan time.Time, writer io.Writer) error {
// Process journal entries and events. Entries are flushed until the tail or
// timeout is reached, and then we wait for new events or the timeout.
var msg = make([]byte, 64*1<<(10))
var waitCh = make(chan int, 1)
var waitGroup sync.WaitGroup
defer waitGroup.Wait()
process:
for {
c, err := r.Read(msg)
if err != nil && err != io.EOF {
return err
}
select {
case <-until:
return ErrExpired
default:
}
if c > 0 {
if _, err = writer.Write(msg[:c]); err != nil {
return err
}
continue process
}
// We're at the tail, so wait for new events or time out.
// Holds journal events to process. Tightly bounded for now unless there's a
// reason to unblock the journal watch routine more quickly.
for {
waitGroup.Add(1)
go func() {
status := r.journal.Wait(100 * time.Millisecond)
waitCh <- status
waitGroup.Done()
}()
select {
case <-until:
return ErrExpired
case e := <-waitCh:
switch e {
case SD_JOURNAL_NOP:
// the journal did not change since the last invocation
case SD_JOURNAL_APPEND, SD_JOURNAL_INVALIDATE:
continue process
default:
if e < 0 {
return fmt.Errorf("received error event: %d", e)
}
log.Printf("received unknown event: %d\n", e)
}
}
}
}
} | [
"func",
"(",
"r",
"*",
"JournalReader",
")",
"Follow",
"(",
"until",
"<-",
"chan",
"time",
".",
"Time",
",",
"writer",
"io",
".",
"Writer",
")",
"error",
"{",
"// Process journal entries and events. Entries are flushed until the tail or",
"// timeout is reached, and then we wait for new events or the timeout.",
"var",
"msg",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"64",
"*",
"1",
"<<",
"(",
"10",
")",
")",
"\n",
"var",
"waitCh",
"=",
"make",
"(",
"chan",
"int",
",",
"1",
")",
"\n",
"var",
"waitGroup",
"sync",
".",
"WaitGroup",
"\n",
"defer",
"waitGroup",
".",
"Wait",
"(",
")",
"\n\n",
"process",
":",
"for",
"{",
"c",
",",
"err",
":=",
"r",
".",
"Read",
"(",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"io",
".",
"EOF",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"select",
"{",
"case",
"<-",
"until",
":",
"return",
"ErrExpired",
"\n",
"default",
":",
"}",
"\n",
"if",
"c",
">",
"0",
"{",
"if",
"_",
",",
"err",
"=",
"writer",
".",
"Write",
"(",
"msg",
"[",
":",
"c",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"continue",
"process",
"\n",
"}",
"\n\n",
"// We're at the tail, so wait for new events or time out.",
"// Holds journal events to process. Tightly bounded for now unless there's a",
"// reason to unblock the journal watch routine more quickly.",
"for",
"{",
"waitGroup",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"status",
":=",
"r",
".",
"journal",
".",
"Wait",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"waitCh",
"<-",
"status",
"\n",
"waitGroup",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"until",
":",
"return",
"ErrExpired",
"\n",
"case",
"e",
":=",
"<-",
"waitCh",
":",
"switch",
"e",
"{",
"case",
"SD_JOURNAL_NOP",
":",
"// the journal did not change since the last invocation",
"case",
"SD_JOURNAL_APPEND",
",",
"SD_JOURNAL_INVALIDATE",
":",
"continue",
"process",
"\n",
"default",
":",
"if",
"e",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"e",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"e",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Follow synchronously follows the JournalReader, writing each new journal entry to writer. The
// follow will continue until a single time.Time is received on the until channel. | [
"Follow",
"synchronously",
"follows",
"the",
"JournalReader",
"writing",
"each",
"new",
"journal",
"entry",
"to",
"writer",
".",
"The",
"follow",
"will",
"continue",
"until",
"a",
"single",
"time",
".",
"Time",
"is",
"received",
"on",
"the",
"until",
"channel",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L199-L257 | train |
coreos/go-systemd | sdjournal/read.go | simpleMessageFormatter | func simpleMessageFormatter(entry *JournalEntry) (string, error) {
msg, ok := entry.Fields["MESSAGE"]
if !ok {
return "", fmt.Errorf("no MESSAGE field present in journal entry")
}
usec := entry.RealtimeTimestamp
timestamp := time.Unix(0, int64(usec)*int64(time.Microsecond))
return fmt.Sprintf("%s %s\n", timestamp, msg), nil
} | go | func simpleMessageFormatter(entry *JournalEntry) (string, error) {
msg, ok := entry.Fields["MESSAGE"]
if !ok {
return "", fmt.Errorf("no MESSAGE field present in journal entry")
}
usec := entry.RealtimeTimestamp
timestamp := time.Unix(0, int64(usec)*int64(time.Microsecond))
return fmt.Sprintf("%s %s\n", timestamp, msg), nil
} | [
"func",
"simpleMessageFormatter",
"(",
"entry",
"*",
"JournalEntry",
")",
"(",
"string",
",",
"error",
")",
"{",
"msg",
",",
"ok",
":=",
"entry",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"usec",
":=",
"entry",
".",
"RealtimeTimestamp",
"\n",
"timestamp",
":=",
"time",
".",
"Unix",
"(",
"0",
",",
"int64",
"(",
"usec",
")",
"*",
"int64",
"(",
"time",
".",
"Microsecond",
")",
")",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"timestamp",
",",
"msg",
")",
",",
"nil",
"\n",
"}"
] | // simpleMessageFormatter is the default formatter.
// It returns a string representing the current journal entry in a simple format which
// includes the entry timestamp and MESSAGE field. | [
"simpleMessageFormatter",
"is",
"the",
"default",
"formatter",
".",
"It",
"returns",
"a",
"string",
"representing",
"the",
"current",
"journal",
"entry",
"in",
"a",
"simple",
"format",
"which",
"includes",
"the",
"entry",
"timestamp",
"and",
"MESSAGE",
"field",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/read.go#L262-L272 | train |
coreos/go-systemd | dbus/methods.go | KillUnit | func (c *Conn) KillUnit(name string, signal int32) {
c.sysobj.Call("org.freedesktop.systemd1.Manager.KillUnit", 0, name, "all", signal).Store()
} | go | func (c *Conn) KillUnit(name string, signal int32) {
c.sysobj.Call("org.freedesktop.systemd1.Manager.KillUnit", 0, name, "all", signal).Store()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"KillUnit",
"(",
"name",
"string",
",",
"signal",
"int32",
")",
"{",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"name",
",",
"\"",
"\"",
",",
"signal",
")",
".",
"Store",
"(",
")",
"\n",
"}"
] | // KillUnit takes the unit name and a UNIX signal number to send. All of the unit's
// processes are killed. | [
"KillUnit",
"takes",
"the",
"unit",
"name",
"and",
"a",
"UNIX",
"signal",
"number",
"to",
"send",
".",
"All",
"of",
"the",
"unit",
"s",
"processes",
"are",
"killed",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L143-L145 | train |
coreos/go-systemd | dbus/methods.go | ResetFailedUnit | func (c *Conn) ResetFailedUnit(name string) error {
return c.sysobj.Call("org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store()
} | go | func (c *Conn) ResetFailedUnit(name string) error {
return c.sysobj.Call("org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store()
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ResetFailedUnit",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"name",
")",
".",
"Store",
"(",
")",
"\n",
"}"
] | // ResetFailedUnit resets the "failed" state of a specific unit. | [
"ResetFailedUnit",
"resets",
"the",
"failed",
"state",
"of",
"a",
"specific",
"unit",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L148-L150 | train |
coreos/go-systemd | dbus/methods.go | SystemState | func (c *Conn) SystemState() (*Property, error) {
var err error
var prop dbus.Variant
obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop)
if err != nil {
return nil, err
}
return &Property{Name: "SystemState", Value: prop}, nil
} | go | func (c *Conn) SystemState() (*Property, error) {
var err error
var prop dbus.Variant
obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop)
if err != nil {
return nil, err
}
return &Property{Name: "SystemState", Value: prop}, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SystemState",
"(",
")",
"(",
"*",
"Property",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"prop",
"dbus",
".",
"Variant",
"\n\n",
"obj",
":=",
"c",
".",
"sysconn",
".",
"Object",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"err",
"=",
"obj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
".",
"Store",
"(",
"&",
"prop",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Property",
"{",
"Name",
":",
"\"",
"\"",
",",
"Value",
":",
"prop",
"}",
",",
"nil",
"\n",
"}"
] | // SystemState returns the systemd state. Equivalent to `systemctl is-system-running`. | [
"SystemState",
"returns",
"the",
"systemd",
"state",
".",
"Equivalent",
"to",
"systemctl",
"is",
"-",
"system",
"-",
"running",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L153-L164 | train |
coreos/go-systemd | dbus/methods.go | getProperties | func (c *Conn) getProperties(path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) {
var err error
var props map[string]dbus.Variant
if !path.IsValid() {
return nil, fmt.Errorf("invalid unit name: %v", path)
}
obj := c.sysconn.Object("org.freedesktop.systemd1", path)
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props)
if err != nil {
return nil, err
}
out := make(map[string]interface{}, len(props))
for k, v := range props {
out[k] = v.Value()
}
return out, nil
} | go | func (c *Conn) getProperties(path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) {
var err error
var props map[string]dbus.Variant
if !path.IsValid() {
return nil, fmt.Errorf("invalid unit name: %v", path)
}
obj := c.sysconn.Object("org.freedesktop.systemd1", path)
err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props)
if err != nil {
return nil, err
}
out := make(map[string]interface{}, len(props))
for k, v := range props {
out[k] = v.Value()
}
return out, nil
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"getProperties",
"(",
"path",
"dbus",
".",
"ObjectPath",
",",
"dbusInterface",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"props",
"map",
"[",
"string",
"]",
"dbus",
".",
"Variant",
"\n\n",
"if",
"!",
"path",
".",
"IsValid",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n\n",
"obj",
":=",
"c",
".",
"sysconn",
".",
"Object",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"err",
"=",
"obj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"dbusInterface",
")",
".",
"Store",
"(",
"&",
"props",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"out",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"props",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"props",
"{",
"out",
"[",
"k",
"]",
"=",
"v",
".",
"Value",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // getProperties takes the unit path and returns all of its dbus object properties, for the given dbus interface | [
"getProperties",
"takes",
"the",
"unit",
"path",
"and",
"returns",
"all",
"of",
"its",
"dbus",
"object",
"properties",
"for",
"the",
"given",
"dbus",
"interface"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L167-L187 | train |
coreos/go-systemd | dbus/methods.go | GetServiceProperty | func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error) {
return c.getProperty(service, "org.freedesktop.systemd1.Service", propertyName)
} | go | func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error) {
return c.getProperty(service, "org.freedesktop.systemd1.Service", propertyName)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"GetServiceProperty",
"(",
"service",
"string",
",",
"propertyName",
"string",
")",
"(",
"*",
"Property",
",",
"error",
")",
"{",
"return",
"c",
".",
"getProperty",
"(",
"service",
",",
"\"",
"\"",
",",
"propertyName",
")",
"\n",
"}"
] | // GetServiceProperty returns property for given service name and property name | [
"GetServiceProperty",
"returns",
"property",
"for",
"given",
"service",
"name",
"and",
"property",
"name"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L223-L225 | train |
coreos/go-systemd | dbus/methods.go | ListUnitsFiltered | func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store)
} | go | func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitsFiltered",
"(",
"states",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"UnitStatus",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitsInternal",
"(",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"states",
")",
".",
"Store",
")",
"\n",
"}"
] | // ListUnitsFiltered returns an array with units filtered by state.
// It takes a list of units' statuses to filter. | [
"ListUnitsFiltered",
"returns",
"an",
"array",
"with",
"units",
"filtered",
"by",
"state",
".",
"It",
"takes",
"a",
"list",
"of",
"units",
"statuses",
"to",
"filter",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L302-L304 | train |
coreos/go-systemd | dbus/methods.go | ListUnitsByPatterns | func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store)
} | go | func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) {
return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitsByPatterns",
"(",
"states",
"[",
"]",
"string",
",",
"patterns",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"UnitStatus",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitsInternal",
"(",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"states",
",",
"patterns",
")",
".",
"Store",
")",
"\n",
"}"
] | // ListUnitsByPatterns returns an array with units.
// It takes a list of units' statuses and names to filter.
// Note that units may be known by multiple names at the same time,
// and hence there might be more unit names loaded than actual units behind them. | [
"ListUnitsByPatterns",
"returns",
"an",
"array",
"with",
"units",
".",
"It",
"takes",
"a",
"list",
"of",
"units",
"statuses",
"and",
"names",
"to",
"filter",
".",
"Note",
"that",
"units",
"may",
"be",
"known",
"by",
"multiple",
"names",
"at",
"the",
"same",
"time",
"and",
"hence",
"there",
"might",
"be",
"more",
"unit",
"names",
"loaded",
"than",
"actual",
"units",
"behind",
"them",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L310-L312 | train |
coreos/go-systemd | dbus/methods.go | ListUnitFiles | func (c *Conn) ListUnitFiles() ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store)
} | go | func (c *Conn) ListUnitFiles() ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitFiles",
"(",
")",
"(",
"[",
"]",
"UnitFile",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitFilesInternal",
"(",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
")",
".",
"Store",
")",
"\n",
"}"
] | // ListUnitFiles returns an array of all available units on disk. | [
"ListUnitFiles",
"returns",
"an",
"array",
"of",
"all",
"available",
"units",
"on",
"disk",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L355-L357 | train |
coreos/go-systemd | dbus/methods.go | ListUnitFilesByPatterns | func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store)
} | go | func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error) {
return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"ListUnitFilesByPatterns",
"(",
"states",
"[",
"]",
"string",
",",
"patterns",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"UnitFile",
",",
"error",
")",
"{",
"return",
"c",
".",
"listUnitFilesInternal",
"(",
"c",
".",
"sysobj",
".",
"Call",
"(",
"\"",
"\"",
",",
"0",
",",
"states",
",",
"patterns",
")",
".",
"Store",
")",
"\n",
"}"
] | // ListUnitFilesByPatterns returns an array of all available units on disk matched the patterns. | [
"ListUnitFilesByPatterns",
"returns",
"an",
"array",
"of",
"all",
"available",
"units",
"on",
"disk",
"matched",
"the",
"patterns",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L360-L362 | train |
coreos/go-systemd | dbus/methods.go | unitName | func unitName(dpath dbus.ObjectPath) string {
return pathBusUnescape(path.Base(string(dpath)))
} | go | func unitName(dpath dbus.ObjectPath) string {
return pathBusUnescape(path.Base(string(dpath)))
} | [
"func",
"unitName",
"(",
"dpath",
"dbus",
".",
"ObjectPath",
")",
"string",
"{",
"return",
"pathBusUnescape",
"(",
"path",
".",
"Base",
"(",
"string",
"(",
"dpath",
")",
")",
")",
"\n",
"}"
] | // unitName returns the unescaped base element of the supplied escaped path | [
"unitName",
"returns",
"the",
"unescaped",
"base",
"element",
"of",
"the",
"supplied",
"escaped",
"path"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/methods.go#L592-L594 | train |
coreos/go-systemd | unit/option.go | NewUnitOption | func NewUnitOption(section, name, value string) *UnitOption {
return &UnitOption{Section: section, Name: name, Value: value}
} | go | func NewUnitOption(section, name, value string) *UnitOption {
return &UnitOption{Section: section, Name: name, Value: value}
} | [
"func",
"NewUnitOption",
"(",
"section",
",",
"name",
",",
"value",
"string",
")",
"*",
"UnitOption",
"{",
"return",
"&",
"UnitOption",
"{",
"Section",
":",
"section",
",",
"Name",
":",
"name",
",",
"Value",
":",
"value",
"}",
"\n",
"}"
] | // NewUnitOption returns a new UnitOption instance with pre-set values. | [
"NewUnitOption",
"returns",
"a",
"new",
"UnitOption",
"instance",
"with",
"pre",
"-",
"set",
"values",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/option.go#L29-L31 | train |
coreos/go-systemd | unit/option.go | Match | func (uo *UnitOption) Match(other *UnitOption) bool {
return uo.Section == other.Section &&
uo.Name == other.Name &&
uo.Value == other.Value
} | go | func (uo *UnitOption) Match(other *UnitOption) bool {
return uo.Section == other.Section &&
uo.Name == other.Name &&
uo.Value == other.Value
} | [
"func",
"(",
"uo",
"*",
"UnitOption",
")",
"Match",
"(",
"other",
"*",
"UnitOption",
")",
"bool",
"{",
"return",
"uo",
".",
"Section",
"==",
"other",
".",
"Section",
"&&",
"uo",
".",
"Name",
"==",
"other",
".",
"Name",
"&&",
"uo",
".",
"Value",
"==",
"other",
".",
"Value",
"\n",
"}"
] | // Match compares two UnitOptions and returns true if they are identical. | [
"Match",
"compares",
"two",
"UnitOptions",
"and",
"returns",
"true",
"if",
"they",
"are",
"identical",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/option.go#L38-L42 | train |
coreos/go-systemd | unit/option.go | AllMatch | func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool {
length := len(u1)
if length != len(u2) {
return false
}
for i := 0; i < length; i++ {
if !u1[i].Match(u2[i]) {
return false
}
}
return true
} | go | func AllMatch(u1 []*UnitOption, u2 []*UnitOption) bool {
length := len(u1)
if length != len(u2) {
return false
}
for i := 0; i < length; i++ {
if !u1[i].Match(u2[i]) {
return false
}
}
return true
} | [
"func",
"AllMatch",
"(",
"u1",
"[",
"]",
"*",
"UnitOption",
",",
"u2",
"[",
"]",
"*",
"UnitOption",
")",
"bool",
"{",
"length",
":=",
"len",
"(",
"u1",
")",
"\n",
"if",
"length",
"!=",
"len",
"(",
"u2",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
"{",
"if",
"!",
"u1",
"[",
"i",
"]",
".",
"Match",
"(",
"u2",
"[",
"i",
"]",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // AllMatch compares two slices of UnitOptions and returns true if they are
// identical. | [
"AllMatch",
"compares",
"two",
"slices",
"of",
"UnitOptions",
"and",
"returns",
"true",
"if",
"they",
"are",
"identical",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/option.go#L46-L59 | train |
coreos/go-systemd | dbus/dbus.go | needsEscape | func needsEscape(i int, b byte) bool {
// Escape everything that is not a-z-A-Z-0-9
// Also escape 0-9 if it's the first character
return strings.IndexByte(alphanum, b) == -1 ||
(i == 0 && strings.IndexByte(num, b) != -1)
} | go | func needsEscape(i int, b byte) bool {
// Escape everything that is not a-z-A-Z-0-9
// Also escape 0-9 if it's the first character
return strings.IndexByte(alphanum, b) == -1 ||
(i == 0 && strings.IndexByte(num, b) != -1)
} | [
"func",
"needsEscape",
"(",
"i",
"int",
",",
"b",
"byte",
")",
"bool",
"{",
"// Escape everything that is not a-z-A-Z-0-9",
"// Also escape 0-9 if it's the first character",
"return",
"strings",
".",
"IndexByte",
"(",
"alphanum",
",",
"b",
")",
"==",
"-",
"1",
"||",
"(",
"i",
"==",
"0",
"&&",
"strings",
".",
"IndexByte",
"(",
"num",
",",
"b",
")",
"!=",
"-",
"1",
")",
"\n",
"}"
] | // needsEscape checks whether a byte in a potential dbus ObjectPath needs to be escaped | [
"needsEscape",
"checks",
"whether",
"a",
"byte",
"in",
"a",
"potential",
"dbus",
"ObjectPath",
"needs",
"to",
"be",
"escaped"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/dbus.go#L37-L42 | train |
coreos/go-systemd | dbus/dbus.go | PathBusEscape | func PathBusEscape(path string) string {
// Special case the empty string
if len(path) == 0 {
return "_"
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if needsEscape(i, c) {
e := fmt.Sprintf("_%x", c)
n = append(n, []byte(e)...)
} else {
n = append(n, c)
}
}
return string(n)
} | go | func PathBusEscape(path string) string {
// Special case the empty string
if len(path) == 0 {
return "_"
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if needsEscape(i, c) {
e := fmt.Sprintf("_%x", c)
n = append(n, []byte(e)...)
} else {
n = append(n, c)
}
}
return string(n)
} | [
"func",
"PathBusEscape",
"(",
"path",
"string",
")",
"string",
"{",
"// Special case the empty string",
"if",
"len",
"(",
"path",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"n",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"path",
")",
";",
"i",
"++",
"{",
"c",
":=",
"path",
"[",
"i",
"]",
"\n",
"if",
"needsEscape",
"(",
"i",
",",
"c",
")",
"{",
"e",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
")",
"\n",
"n",
"=",
"append",
"(",
"n",
",",
"[",
"]",
"byte",
"(",
"e",
")",
"...",
")",
"\n",
"}",
"else",
"{",
"n",
"=",
"append",
"(",
"n",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"string",
"(",
"n",
")",
"\n",
"}"
] | // PathBusEscape sanitizes a constituent string of a dbus ObjectPath using the
// rules that systemd uses for serializing special characters. | [
"PathBusEscape",
"sanitizes",
"a",
"constituent",
"string",
"of",
"a",
"dbus",
"ObjectPath",
"using",
"the",
"rules",
"that",
"systemd",
"uses",
"for",
"serializing",
"special",
"characters",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/dbus.go#L46-L62 | train |
coreos/go-systemd | dbus/dbus.go | pathBusUnescape | func pathBusUnescape(path string) string {
if path == "_" {
return ""
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if c == '_' && i+2 < len(path) {
res, err := hex.DecodeString(path[i+1 : i+3])
if err == nil {
n = append(n, res...)
}
i += 2
} else {
n = append(n, c)
}
}
return string(n)
} | go | func pathBusUnescape(path string) string {
if path == "_" {
return ""
}
n := []byte{}
for i := 0; i < len(path); i++ {
c := path[i]
if c == '_' && i+2 < len(path) {
res, err := hex.DecodeString(path[i+1 : i+3])
if err == nil {
n = append(n, res...)
}
i += 2
} else {
n = append(n, c)
}
}
return string(n)
} | [
"func",
"pathBusUnescape",
"(",
"path",
"string",
")",
"string",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"n",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"path",
")",
";",
"i",
"++",
"{",
"c",
":=",
"path",
"[",
"i",
"]",
"\n",
"if",
"c",
"==",
"'_'",
"&&",
"i",
"+",
"2",
"<",
"len",
"(",
"path",
")",
"{",
"res",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"path",
"[",
"i",
"+",
"1",
":",
"i",
"+",
"3",
"]",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"n",
"=",
"append",
"(",
"n",
",",
"res",
"...",
")",
"\n",
"}",
"\n",
"i",
"+=",
"2",
"\n",
"}",
"else",
"{",
"n",
"=",
"append",
"(",
"n",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"string",
"(",
"n",
")",
"\n",
"}"
] | // pathBusUnescape is the inverse of PathBusEscape. | [
"pathBusUnescape",
"is",
"the",
"inverse",
"of",
"PathBusEscape",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/dbus.go#L65-L83 | train |
coreos/go-systemd | dbus/subscription.go | SubscribeUnits | func (c *Conn) SubscribeUnits(interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error) {
return c.SubscribeUnitsCustom(interval, 0, func(u1, u2 *UnitStatus) bool { return *u1 != *u2 }, nil)
} | go | func (c *Conn) SubscribeUnits(interval time.Duration) (<-chan map[string]*UnitStatus, <-chan error) {
return c.SubscribeUnitsCustom(interval, 0, func(u1, u2 *UnitStatus) bool { return *u1 != *u2 }, nil)
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SubscribeUnits",
"(",
"interval",
"time",
".",
"Duration",
")",
"(",
"<-",
"chan",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
",",
"<-",
"chan",
"error",
")",
"{",
"return",
"c",
".",
"SubscribeUnitsCustom",
"(",
"interval",
",",
"0",
",",
"func",
"(",
"u1",
",",
"u2",
"*",
"UnitStatus",
")",
"bool",
"{",
"return",
"*",
"u1",
"!=",
"*",
"u2",
"}",
",",
"nil",
")",
"\n",
"}"
] | // SubscribeUnits returns two unbuffered channels which will receive all changed units every
// interval. Deleted units are sent as nil. | [
"SubscribeUnits",
"returns",
"two",
"unbuffered",
"channels",
"which",
"will",
"receive",
"all",
"changed",
"units",
"every",
"interval",
".",
"Deleted",
"units",
"are",
"sent",
"as",
"nil",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription.go#L99-L101 | train |
coreos/go-systemd | dbus/subscription.go | SubscribeUnitsCustom | func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error) {
old := make(map[string]*UnitStatus)
statusChan := make(chan map[string]*UnitStatus, buffer)
errChan := make(chan error, buffer)
go func() {
for {
timerChan := time.After(interval)
units, err := c.ListUnits()
if err == nil {
cur := make(map[string]*UnitStatus)
for i := range units {
if filterUnit != nil && filterUnit(units[i].Name) {
continue
}
cur[units[i].Name] = &units[i]
}
// add all new or changed units
changed := make(map[string]*UnitStatus)
for n, u := range cur {
if oldU, ok := old[n]; !ok || isChanged(oldU, u) {
changed[n] = u
}
delete(old, n)
}
// add all deleted units
for oldN := range old {
changed[oldN] = nil
}
old = cur
if len(changed) != 0 {
statusChan <- changed
}
} else {
errChan <- err
}
<-timerChan
}
}()
return statusChan, errChan
} | go | func (c *Conn) SubscribeUnitsCustom(interval time.Duration, buffer int, isChanged func(*UnitStatus, *UnitStatus) bool, filterUnit func(string) bool) (<-chan map[string]*UnitStatus, <-chan error) {
old := make(map[string]*UnitStatus)
statusChan := make(chan map[string]*UnitStatus, buffer)
errChan := make(chan error, buffer)
go func() {
for {
timerChan := time.After(interval)
units, err := c.ListUnits()
if err == nil {
cur := make(map[string]*UnitStatus)
for i := range units {
if filterUnit != nil && filterUnit(units[i].Name) {
continue
}
cur[units[i].Name] = &units[i]
}
// add all new or changed units
changed := make(map[string]*UnitStatus)
for n, u := range cur {
if oldU, ok := old[n]; !ok || isChanged(oldU, u) {
changed[n] = u
}
delete(old, n)
}
// add all deleted units
for oldN := range old {
changed[oldN] = nil
}
old = cur
if len(changed) != 0 {
statusChan <- changed
}
} else {
errChan <- err
}
<-timerChan
}
}()
return statusChan, errChan
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SubscribeUnitsCustom",
"(",
"interval",
"time",
".",
"Duration",
",",
"buffer",
"int",
",",
"isChanged",
"func",
"(",
"*",
"UnitStatus",
",",
"*",
"UnitStatus",
")",
"bool",
",",
"filterUnit",
"func",
"(",
"string",
")",
"bool",
")",
"(",
"<-",
"chan",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
",",
"<-",
"chan",
"error",
")",
"{",
"old",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
")",
"\n",
"statusChan",
":=",
"make",
"(",
"chan",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
",",
"buffer",
")",
"\n",
"errChan",
":=",
"make",
"(",
"chan",
"error",
",",
"buffer",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"timerChan",
":=",
"time",
".",
"After",
"(",
"interval",
")",
"\n\n",
"units",
",",
"err",
":=",
"c",
".",
"ListUnits",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"cur",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
")",
"\n",
"for",
"i",
":=",
"range",
"units",
"{",
"if",
"filterUnit",
"!=",
"nil",
"&&",
"filterUnit",
"(",
"units",
"[",
"i",
"]",
".",
"Name",
")",
"{",
"continue",
"\n",
"}",
"\n",
"cur",
"[",
"units",
"[",
"i",
"]",
".",
"Name",
"]",
"=",
"&",
"units",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"// add all new or changed units",
"changed",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
")",
"\n",
"for",
"n",
",",
"u",
":=",
"range",
"cur",
"{",
"if",
"oldU",
",",
"ok",
":=",
"old",
"[",
"n",
"]",
";",
"!",
"ok",
"||",
"isChanged",
"(",
"oldU",
",",
"u",
")",
"{",
"changed",
"[",
"n",
"]",
"=",
"u",
"\n",
"}",
"\n",
"delete",
"(",
"old",
",",
"n",
")",
"\n",
"}",
"\n\n",
"// add all deleted units",
"for",
"oldN",
":=",
"range",
"old",
"{",
"changed",
"[",
"oldN",
"]",
"=",
"nil",
"\n",
"}",
"\n\n",
"old",
"=",
"cur",
"\n\n",
"if",
"len",
"(",
"changed",
")",
"!=",
"0",
"{",
"statusChan",
"<-",
"changed",
"\n",
"}",
"\n",
"}",
"else",
"{",
"errChan",
"<-",
"err",
"\n",
"}",
"\n\n",
"<-",
"timerChan",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"statusChan",
",",
"errChan",
"\n",
"}"
] | // SubscribeUnitsCustom is like SubscribeUnits but lets you specify the buffer
// size of the channels, the comparison function for detecting changes and a filter
// function for cutting down on the noise that your channel receives. | [
"SubscribeUnitsCustom",
"is",
"like",
"SubscribeUnits",
"but",
"lets",
"you",
"specify",
"the",
"buffer",
"size",
"of",
"the",
"channels",
"the",
"comparison",
"function",
"for",
"detecting",
"changes",
"and",
"a",
"filter",
"function",
"for",
"cutting",
"down",
"on",
"the",
"noise",
"that",
"your",
"channel",
"receives",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription.go#L106-L153 | train |
coreos/go-systemd | dbus/subscription.go | cleanIgnore | func (c *Conn) cleanIgnore() {
now := time.Now().UnixNano()
if c.subStateSubscriber.cleanIgnore < now {
c.subStateSubscriber.cleanIgnore = now + cleanIgnoreInterval
for p, t := range c.subStateSubscriber.ignore {
if t < now {
delete(c.subStateSubscriber.ignore, p)
}
}
}
} | go | func (c *Conn) cleanIgnore() {
now := time.Now().UnixNano()
if c.subStateSubscriber.cleanIgnore < now {
c.subStateSubscriber.cleanIgnore = now + cleanIgnoreInterval
for p, t := range c.subStateSubscriber.ignore {
if t < now {
delete(c.subStateSubscriber.ignore, p)
}
}
}
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"cleanIgnore",
"(",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"\n",
"if",
"c",
".",
"subStateSubscriber",
".",
"cleanIgnore",
"<",
"now",
"{",
"c",
".",
"subStateSubscriber",
".",
"cleanIgnore",
"=",
"now",
"+",
"cleanIgnoreInterval",
"\n\n",
"for",
"p",
",",
"t",
":=",
"range",
"c",
".",
"subStateSubscriber",
".",
"ignore",
"{",
"if",
"t",
"<",
"now",
"{",
"delete",
"(",
"c",
".",
"subStateSubscriber",
".",
"ignore",
",",
"p",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // without this, ignore would grow unboundedly over time | [
"without",
"this",
"ignore",
"would",
"grow",
"unboundedly",
"over",
"time"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription.go#L278-L289 | train |
coreos/go-systemd | dbus/subscription_set.go | Subscribe | func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error) {
// TODO: Make fully evented by using systemd 209 with properties changed values
return s.conn.SubscribeUnitsCustom(time.Second, 0,
mismatchUnitStatus,
func(unit string) bool { return s.filter(unit) },
)
} | go | func (s *SubscriptionSet) Subscribe() (<-chan map[string]*UnitStatus, <-chan error) {
// TODO: Make fully evented by using systemd 209 with properties changed values
return s.conn.SubscribeUnitsCustom(time.Second, 0,
mismatchUnitStatus,
func(unit string) bool { return s.filter(unit) },
)
} | [
"func",
"(",
"s",
"*",
"SubscriptionSet",
")",
"Subscribe",
"(",
")",
"(",
"<-",
"chan",
"map",
"[",
"string",
"]",
"*",
"UnitStatus",
",",
"<-",
"chan",
"error",
")",
"{",
"// TODO: Make fully evented by using systemd 209 with properties changed values",
"return",
"s",
".",
"conn",
".",
"SubscribeUnitsCustom",
"(",
"time",
".",
"Second",
",",
"0",
",",
"mismatchUnitStatus",
",",
"func",
"(",
"unit",
"string",
")",
"bool",
"{",
"return",
"s",
".",
"filter",
"(",
"unit",
")",
"}",
",",
")",
"\n",
"}"
] | // Subscribe starts listening for dbus events for all of the units in the set.
// Returns channels identical to conn.SubscribeUnits. | [
"Subscribe",
"starts",
"listening",
"for",
"dbus",
"events",
"for",
"all",
"of",
"the",
"units",
"in",
"the",
"set",
".",
"Returns",
"channels",
"identical",
"to",
"conn",
".",
"SubscribeUnits",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription_set.go#L34-L40 | train |
coreos/go-systemd | dbus/subscription_set.go | mismatchUnitStatus | func mismatchUnitStatus(u1, u2 *UnitStatus) bool {
return u1.Name != u2.Name ||
u1.Description != u2.Description ||
u1.LoadState != u2.LoadState ||
u1.ActiveState != u2.ActiveState ||
u1.SubState != u2.SubState
} | go | func mismatchUnitStatus(u1, u2 *UnitStatus) bool {
return u1.Name != u2.Name ||
u1.Description != u2.Description ||
u1.LoadState != u2.LoadState ||
u1.ActiveState != u2.ActiveState ||
u1.SubState != u2.SubState
} | [
"func",
"mismatchUnitStatus",
"(",
"u1",
",",
"u2",
"*",
"UnitStatus",
")",
"bool",
"{",
"return",
"u1",
".",
"Name",
"!=",
"u2",
".",
"Name",
"||",
"u1",
".",
"Description",
"!=",
"u2",
".",
"Description",
"||",
"u1",
".",
"LoadState",
"!=",
"u2",
".",
"LoadState",
"||",
"u1",
".",
"ActiveState",
"!=",
"u2",
".",
"ActiveState",
"||",
"u1",
".",
"SubState",
"!=",
"u2",
".",
"SubState",
"\n",
"}"
] | // mismatchUnitStatus returns true if the provided UnitStatus objects
// are not equivalent. false is returned if the objects are equivalent.
// Only the Name, Description and state-related fields are used in
// the comparison. | [
"mismatchUnitStatus",
"returns",
"true",
"if",
"the",
"provided",
"UnitStatus",
"objects",
"are",
"not",
"equivalent",
".",
"false",
"is",
"returned",
"if",
"the",
"objects",
"are",
"equivalent",
".",
"Only",
"the",
"Name",
"Description",
"and",
"state",
"-",
"related",
"fields",
"are",
"used",
"in",
"the",
"comparison",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/dbus/subscription_set.go#L51-L57 | train |
coreos/go-systemd | unit/serialize.go | Serialize | func Serialize(opts []*UnitOption) io.Reader {
var buf bytes.Buffer
if len(opts) == 0 {
return &buf
}
// Index of sections -> ordered options
idx := map[string][]*UnitOption{}
// Separately preserve order in which sections were seen
sections := []string{}
for _, opt := range opts {
sec := opt.Section
if _, ok := idx[sec]; !ok {
sections = append(sections, sec)
}
idx[sec] = append(idx[sec], opt)
}
for i, sect := range sections {
writeSectionHeader(&buf, sect)
writeNewline(&buf)
opts := idx[sect]
for _, opt := range opts {
writeOption(&buf, opt)
writeNewline(&buf)
}
if i < len(sections)-1 {
writeNewline(&buf)
}
}
return &buf
} | go | func Serialize(opts []*UnitOption) io.Reader {
var buf bytes.Buffer
if len(opts) == 0 {
return &buf
}
// Index of sections -> ordered options
idx := map[string][]*UnitOption{}
// Separately preserve order in which sections were seen
sections := []string{}
for _, opt := range opts {
sec := opt.Section
if _, ok := idx[sec]; !ok {
sections = append(sections, sec)
}
idx[sec] = append(idx[sec], opt)
}
for i, sect := range sections {
writeSectionHeader(&buf, sect)
writeNewline(&buf)
opts := idx[sect]
for _, opt := range opts {
writeOption(&buf, opt)
writeNewline(&buf)
}
if i < len(sections)-1 {
writeNewline(&buf)
}
}
return &buf
} | [
"func",
"Serialize",
"(",
"opts",
"[",
"]",
"*",
"UnitOption",
")",
"io",
".",
"Reader",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"if",
"len",
"(",
"opts",
")",
"==",
"0",
"{",
"return",
"&",
"buf",
"\n",
"}",
"\n\n",
"// Index of sections -> ordered options",
"idx",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"*",
"UnitOption",
"{",
"}",
"\n",
"// Separately preserve order in which sections were seen",
"sections",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"sec",
":=",
"opt",
".",
"Section",
"\n",
"if",
"_",
",",
"ok",
":=",
"idx",
"[",
"sec",
"]",
";",
"!",
"ok",
"{",
"sections",
"=",
"append",
"(",
"sections",
",",
"sec",
")",
"\n",
"}",
"\n",
"idx",
"[",
"sec",
"]",
"=",
"append",
"(",
"idx",
"[",
"sec",
"]",
",",
"opt",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"sect",
":=",
"range",
"sections",
"{",
"writeSectionHeader",
"(",
"&",
"buf",
",",
"sect",
")",
"\n",
"writeNewline",
"(",
"&",
"buf",
")",
"\n\n",
"opts",
":=",
"idx",
"[",
"sect",
"]",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"writeOption",
"(",
"&",
"buf",
",",
"opt",
")",
"\n",
"writeNewline",
"(",
"&",
"buf",
")",
"\n",
"}",
"\n",
"if",
"i",
"<",
"len",
"(",
"sections",
")",
"-",
"1",
"{",
"writeNewline",
"(",
"&",
"buf",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"buf",
"\n",
"}"
] | // Serialize encodes all of the given UnitOption objects into a
// unit file. When serialized the options are sorted in their
// supplied order but grouped by section. | [
"Serialize",
"encodes",
"all",
"of",
"the",
"given",
"UnitOption",
"objects",
"into",
"a",
"unit",
"file",
".",
"When",
"serialized",
"the",
"options",
"are",
"sorted",
"in",
"their",
"supplied",
"order",
"but",
"grouped",
"by",
"section",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/unit/serialize.go#L25-L59 | train |
coreos/go-systemd | sdjournal/journal.go | NewJournal | func NewJournal() (j *Journal, err error) {
j = &Journal{}
sd_journal_open, err := getFunction("sd_journal_open")
if err != nil {
return nil, err
}
r := C.my_sd_journal_open(sd_journal_open, &j.cjournal, C.SD_JOURNAL_LOCAL_ONLY)
if r < 0 {
return nil, fmt.Errorf("failed to open journal: %d", syscall.Errno(-r))
}
return j, nil
} | go | func NewJournal() (j *Journal, err error) {
j = &Journal{}
sd_journal_open, err := getFunction("sd_journal_open")
if err != nil {
return nil, err
}
r := C.my_sd_journal_open(sd_journal_open, &j.cjournal, C.SD_JOURNAL_LOCAL_ONLY)
if r < 0 {
return nil, fmt.Errorf("failed to open journal: %d", syscall.Errno(-r))
}
return j, nil
} | [
"func",
"NewJournal",
"(",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"r",
":=",
"C",
".",
"my_sd_journal_open",
"(",
"sd_journal_open",
",",
"&",
"j",
".",
"cjournal",
",",
"C",
".",
"SD_JOURNAL_LOCAL_ONLY",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"j",
",",
"nil",
"\n",
"}"
] | // NewJournal returns a new Journal instance pointing to the local journal | [
"NewJournal",
"returns",
"a",
"new",
"Journal",
"instance",
"pointing",
"to",
"the",
"local",
"journal"
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L406-L421 | train |
coreos/go-systemd | sdjournal/journal.go | NewJournalFromDir | func NewJournalFromDir(path string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_directory, err := getFunction("sd_journal_open_directory")
if err != nil {
return nil, err
}
p := C.CString(path)
defer C.free(unsafe.Pointer(p))
r := C.my_sd_journal_open_directory(sd_journal_open_directory, &j.cjournal, p, 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journal in directory %q: %d", path, syscall.Errno(-r))
}
return j, nil
} | go | func NewJournalFromDir(path string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_directory, err := getFunction("sd_journal_open_directory")
if err != nil {
return nil, err
}
p := C.CString(path)
defer C.free(unsafe.Pointer(p))
r := C.my_sd_journal_open_directory(sd_journal_open_directory, &j.cjournal, p, 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journal in directory %q: %d", path, syscall.Errno(-r))
}
return j, nil
} | [
"func",
"NewJournalFromDir",
"(",
"path",
"string",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open_directory",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"p",
":=",
"C",
".",
"CString",
"(",
"path",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
"\n\n",
"r",
":=",
"C",
".",
"my_sd_journal_open_directory",
"(",
"sd_journal_open_directory",
",",
"&",
"j",
".",
"cjournal",
",",
"p",
",",
"0",
")",
"\n",
"if",
"r",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"j",
",",
"nil",
"\n",
"}"
] | // NewJournalFromDir returns a new Journal instance pointing to a journal residing
// in a given directory. | [
"NewJournalFromDir",
"returns",
"a",
"new",
"Journal",
"instance",
"pointing",
"to",
"a",
"journal",
"residing",
"in",
"a",
"given",
"directory",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L425-L442 | train |
coreos/go-systemd | sdjournal/journal.go | NewJournalFromFiles | func NewJournalFromFiles(paths ...string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_files, err := getFunction("sd_journal_open_files")
if err != nil {
return nil, err
}
// by making the slice 1 elem too long, we guarantee it'll be null-terminated
cPaths := make([]*C.char, len(paths)+1)
for idx, path := range paths {
p := C.CString(path)
cPaths[idx] = p
defer C.free(unsafe.Pointer(p))
}
r := C.my_sd_journal_open_files(sd_journal_open_files, &j.cjournal, &cPaths[0], 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journals in paths %q: %d", paths, syscall.Errno(-r))
}
return j, nil
} | go | func NewJournalFromFiles(paths ...string) (j *Journal, err error) {
j = &Journal{}
sd_journal_open_files, err := getFunction("sd_journal_open_files")
if err != nil {
return nil, err
}
// by making the slice 1 elem too long, we guarantee it'll be null-terminated
cPaths := make([]*C.char, len(paths)+1)
for idx, path := range paths {
p := C.CString(path)
cPaths[idx] = p
defer C.free(unsafe.Pointer(p))
}
r := C.my_sd_journal_open_files(sd_journal_open_files, &j.cjournal, &cPaths[0], 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journals in paths %q: %d", paths, syscall.Errno(-r))
}
return j, nil
} | [
"func",
"NewJournalFromFiles",
"(",
"paths",
"...",
"string",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open_files",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// by making the slice 1 elem too long, we guarantee it'll be null-terminated",
"cPaths",
":=",
"make",
"(",
"[",
"]",
"*",
"C",
".",
"char",
",",
"len",
"(",
"paths",
")",
"+",
"1",
")",
"\n",
"for",
"idx",
",",
"path",
":=",
"range",
"paths",
"{",
"p",
":=",
"C",
".",
"CString",
"(",
"path",
")",
"\n",
"cPaths",
"[",
"idx",
"]",
"=",
"p",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"p",
")",
")",
"\n",
"}",
"\n\n",
"r",
":=",
"C",
".",
"my_sd_journal_open_files",
"(",
"sd_journal_open_files",
",",
"&",
"j",
".",
"cjournal",
",",
"&",
"cPaths",
"[",
"0",
"]",
",",
"0",
")",
"\n",
"if",
"r",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"paths",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"j",
",",
"nil",
"\n",
"}"
] | // NewJournalFromFiles returns a new Journal instance pointing to a journals residing
// in a given files. | [
"NewJournalFromFiles",
"returns",
"a",
"new",
"Journal",
"instance",
"pointing",
"to",
"a",
"journals",
"residing",
"in",
"a",
"given",
"files",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L446-L468 | train |
coreos/go-systemd | sdjournal/journal.go | Close | func (j *Journal) Close() error {
sd_journal_close, err := getFunction("sd_journal_close")
if err != nil {
return err
}
j.mu.Lock()
C.my_sd_journal_close(sd_journal_close, j.cjournal)
j.mu.Unlock()
return nil
} | go | func (j *Journal) Close() error {
sd_journal_close, err := getFunction("sd_journal_close")
if err != nil {
return err
}
j.mu.Lock()
C.my_sd_journal_close(sd_journal_close, j.cjournal)
j.mu.Unlock()
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Close",
"(",
")",
"error",
"{",
"sd_journal_close",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"C",
".",
"my_sd_journal_close",
"(",
"sd_journal_close",
",",
"j",
".",
"cjournal",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close closes a journal opened with NewJournal. | [
"Close",
"closes",
"a",
"journal",
"opened",
"with",
"NewJournal",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L471-L482 | train |
coreos/go-systemd | sdjournal/journal.go | AddMatch | func (j *Journal) AddMatch(match string) error {
sd_journal_add_match, err := getFunction("sd_journal_add_match")
if err != nil {
return err
}
m := C.CString(match)
defer C.free(unsafe.Pointer(m))
j.mu.Lock()
r := C.my_sd_journal_add_match(sd_journal_add_match, j.cjournal, unsafe.Pointer(m), C.size_t(len(match)))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add match: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) AddMatch(match string) error {
sd_journal_add_match, err := getFunction("sd_journal_add_match")
if err != nil {
return err
}
m := C.CString(match)
defer C.free(unsafe.Pointer(m))
j.mu.Lock()
r := C.my_sd_journal_add_match(sd_journal_add_match, j.cjournal, unsafe.Pointer(m), C.size_t(len(match)))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add match: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddMatch",
"(",
"match",
"string",
")",
"error",
"{",
"sd_journal_add_match",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"m",
":=",
"C",
".",
"CString",
"(",
"match",
")",
"\n",
"defer",
"C",
".",
"free",
"(",
"unsafe",
".",
"Pointer",
"(",
"m",
")",
")",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_add_match",
"(",
"sd_journal_add_match",
",",
"j",
".",
"cjournal",
",",
"unsafe",
".",
"Pointer",
"(",
"m",
")",
",",
"C",
".",
"size_t",
"(",
"len",
"(",
"match",
")",
")",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // AddMatch adds a match by which to filter the entries of the journal. | [
"AddMatch",
"adds",
"a",
"match",
"by",
"which",
"to",
"filter",
"the",
"entries",
"of",
"the",
"journal",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L485-L503 | train |
coreos/go-systemd | sdjournal/journal.go | AddDisjunction | func (j *Journal) AddDisjunction() error {
sd_journal_add_disjunction, err := getFunction("sd_journal_add_disjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_disjunction(sd_journal_add_disjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a disjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) AddDisjunction() error {
sd_journal_add_disjunction, err := getFunction("sd_journal_add_disjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_disjunction(sd_journal_add_disjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a disjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddDisjunction",
"(",
")",
"error",
"{",
"sd_journal_add_disjunction",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_add_disjunction",
"(",
"sd_journal_add_disjunction",
",",
"j",
".",
"cjournal",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // AddDisjunction inserts a logical OR in the match list. | [
"AddDisjunction",
"inserts",
"a",
"logical",
"OR",
"in",
"the",
"match",
"list",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L506-L521 | train |
coreos/go-systemd | sdjournal/journal.go | AddConjunction | func (j *Journal) AddConjunction() error {
sd_journal_add_conjunction, err := getFunction("sd_journal_add_conjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_conjunction(sd_journal_add_conjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a conjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) AddConjunction() error {
sd_journal_add_conjunction, err := getFunction("sd_journal_add_conjunction")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_add_conjunction(sd_journal_add_conjunction, j.cjournal)
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to add a conjunction in the match list: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddConjunction",
"(",
")",
"error",
"{",
"sd_journal_add_conjunction",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_add_conjunction",
"(",
"sd_journal_add_conjunction",
",",
"j",
".",
"cjournal",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // AddConjunction inserts a logical AND in the match list. | [
"AddConjunction",
"inserts",
"a",
"logical",
"AND",
"in",
"the",
"match",
"list",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L524-L539 | train |
coreos/go-systemd | sdjournal/journal.go | FlushMatches | func (j *Journal) FlushMatches() {
sd_journal_flush_matches, err := getFunction("sd_journal_flush_matches")
if err != nil {
return
}
j.mu.Lock()
C.my_sd_journal_flush_matches(sd_journal_flush_matches, j.cjournal)
j.mu.Unlock()
} | go | func (j *Journal) FlushMatches() {
sd_journal_flush_matches, err := getFunction("sd_journal_flush_matches")
if err != nil {
return
}
j.mu.Lock()
C.my_sd_journal_flush_matches(sd_journal_flush_matches, j.cjournal)
j.mu.Unlock()
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"FlushMatches",
"(",
")",
"{",
"sd_journal_flush_matches",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"C",
".",
"my_sd_journal_flush_matches",
"(",
"sd_journal_flush_matches",
",",
"j",
".",
"cjournal",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // FlushMatches flushes all matches, disjunctions and conjunctions. | [
"FlushMatches",
"flushes",
"all",
"matches",
"disjunctions",
"and",
"conjunctions",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L542-L551 | train |
coreos/go-systemd | sdjournal/journal.go | Next | func (j *Journal) Next() (uint64, error) {
sd_journal_next, err := getFunction("sd_journal_next")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next(sd_journal_next, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) Next() (uint64, error) {
sd_journal_next, err := getFunction("sd_journal_next")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next(sd_journal_next, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Next",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_next",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_next",
"(",
"sd_journal_next",
",",
"j",
".",
"cjournal",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"uint64",
"(",
"r",
")",
",",
"nil",
"\n",
"}"
] | // Next advances the read pointer into the journal by one entry. | [
"Next",
"advances",
"the",
"read",
"pointer",
"into",
"the",
"journal",
"by",
"one",
"entry",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L554-L569 | train |
coreos/go-systemd | sdjournal/journal.go | NextSkip | func (j *Journal) NextSkip(skip uint64) (uint64, error) {
sd_journal_next_skip, err := getFunction("sd_journal_next_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next_skip(sd_journal_next_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) NextSkip(skip uint64) (uint64, error) {
sd_journal_next_skip, err := getFunction("sd_journal_next_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_next_skip(sd_journal_next_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"NextSkip",
"(",
"skip",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_next_skip",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_next_skip",
"(",
"sd_journal_next_skip",
",",
"j",
".",
"cjournal",
",",
"C",
".",
"uint64_t",
"(",
"skip",
")",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"uint64",
"(",
"r",
")",
",",
"nil",
"\n",
"}"
] | // NextSkip advances the read pointer by multiple entries at once,
// as specified by the skip parameter. | [
"NextSkip",
"advances",
"the",
"read",
"pointer",
"by",
"multiple",
"entries",
"at",
"once",
"as",
"specified",
"by",
"the",
"skip",
"parameter",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L573-L588 | train |
coreos/go-systemd | sdjournal/journal.go | Previous | func (j *Journal) Previous() (uint64, error) {
sd_journal_previous, err := getFunction("sd_journal_previous")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous(sd_journal_previous, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) Previous() (uint64, error) {
sd_journal_previous, err := getFunction("sd_journal_previous")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous(sd_journal_previous, j.cjournal)
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Previous",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_previous",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_previous",
"(",
"sd_journal_previous",
",",
"j",
".",
"cjournal",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"uint64",
"(",
"r",
")",
",",
"nil",
"\n",
"}"
] | // Previous sets the read pointer into the journal back by one entry. | [
"Previous",
"sets",
"the",
"read",
"pointer",
"into",
"the",
"journal",
"back",
"by",
"one",
"entry",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L591-L606 | train |
coreos/go-systemd | sdjournal/journal.go | PreviousSkip | func (j *Journal) PreviousSkip(skip uint64) (uint64, error) {
sd_journal_previous_skip, err := getFunction("sd_journal_previous_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous_skip(sd_journal_previous_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | go | func (j *Journal) PreviousSkip(skip uint64) (uint64, error) {
sd_journal_previous_skip, err := getFunction("sd_journal_previous_skip")
if err != nil {
return 0, err
}
j.mu.Lock()
r := C.my_sd_journal_previous_skip(sd_journal_previous_skip, j.cjournal, C.uint64_t(skip))
j.mu.Unlock()
if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
}
return uint64(r), nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"PreviousSkip",
"(",
"skip",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_previous_skip",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_previous_skip",
"(",
"sd_journal_previous_skip",
",",
"j",
".",
"cjournal",
",",
"C",
".",
"uint64_t",
"(",
"skip",
")",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"uint64",
"(",
"r",
")",
",",
"nil",
"\n",
"}"
] | // PreviousSkip sets back the read pointer by multiple entries at once,
// as specified by the skip parameter. | [
"PreviousSkip",
"sets",
"back",
"the",
"read",
"pointer",
"by",
"multiple",
"entries",
"at",
"once",
"as",
"specified",
"by",
"the",
"skip",
"parameter",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L610-L625 | train |
coreos/go-systemd | sdjournal/journal.go | SetDataThreshold | func (j *Journal) SetDataThreshold(threshold uint64) error {
sd_journal_set_data_threshold, err := getFunction("sd_journal_set_data_threshold")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_set_data_threshold(sd_journal_set_data_threshold, j.cjournal, C.size_t(threshold))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to set data threshold: %d", syscall.Errno(-r))
}
return nil
} | go | func (j *Journal) SetDataThreshold(threshold uint64) error {
sd_journal_set_data_threshold, err := getFunction("sd_journal_set_data_threshold")
if err != nil {
return err
}
j.mu.Lock()
r := C.my_sd_journal_set_data_threshold(sd_journal_set_data_threshold, j.cjournal, C.size_t(threshold))
j.mu.Unlock()
if r < 0 {
return fmt.Errorf("failed to set data threshold: %d", syscall.Errno(-r))
}
return nil
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"SetDataThreshold",
"(",
"threshold",
"uint64",
")",
"error",
"{",
"sd_journal_set_data_threshold",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_set_data_threshold",
"(",
"sd_journal_set_data_threshold",
",",
"j",
".",
"cjournal",
",",
"C",
".",
"size_t",
"(",
"threshold",
")",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"syscall",
".",
"Errno",
"(",
"-",
"r",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SetDataThreshold sets the data field size threshold for data returned by
// GetData. To retrieve the complete data fields this threshold should be
// turned off by setting it to 0, so that the library always returns the
// complete data objects. | [
"SetDataThreshold",
"sets",
"the",
"data",
"field",
"size",
"threshold",
"for",
"data",
"returned",
"by",
"GetData",
".",
"To",
"retrieve",
"the",
"complete",
"data",
"fields",
"this",
"threshold",
"should",
"be",
"turned",
"off",
"by",
"setting",
"it",
"to",
"0",
"so",
"that",
"the",
"library",
"always",
"returns",
"the",
"complete",
"data",
"objects",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L795-L810 | train |
coreos/go-systemd | sdjournal/journal.go | Wait | func (j *Journal) Wait(timeout time.Duration) int {
var to uint64
sd_journal_wait, err := getFunction("sd_journal_wait")
if err != nil {
return -1
}
if timeout == IndefiniteWait {
// sd_journal_wait(3) calls for a (uint64_t) -1 to be passed to signify
// indefinite wait, but using a -1 overflows our C.uint64_t, so we use an
// equivalent hex value.
to = 0xffffffffffffffff
} else {
to = uint64(timeout / time.Microsecond)
}
j.mu.Lock()
r := C.my_sd_journal_wait(sd_journal_wait, j.cjournal, C.uint64_t(to))
j.mu.Unlock()
return int(r)
} | go | func (j *Journal) Wait(timeout time.Duration) int {
var to uint64
sd_journal_wait, err := getFunction("sd_journal_wait")
if err != nil {
return -1
}
if timeout == IndefiniteWait {
// sd_journal_wait(3) calls for a (uint64_t) -1 to be passed to signify
// indefinite wait, but using a -1 overflows our C.uint64_t, so we use an
// equivalent hex value.
to = 0xffffffffffffffff
} else {
to = uint64(timeout / time.Microsecond)
}
j.mu.Lock()
r := C.my_sd_journal_wait(sd_journal_wait, j.cjournal, C.uint64_t(to))
j.mu.Unlock()
return int(r)
} | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Wait",
"(",
"timeout",
"time",
".",
"Duration",
")",
"int",
"{",
"var",
"to",
"uint64",
"\n\n",
"sd_journal_wait",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n\n",
"if",
"timeout",
"==",
"IndefiniteWait",
"{",
"// sd_journal_wait(3) calls for a (uint64_t) -1 to be passed to signify",
"// indefinite wait, but using a -1 overflows our C.uint64_t, so we use an",
"// equivalent hex value.",
"to",
"=",
"0xffffffffffffffff",
"\n",
"}",
"else",
"{",
"to",
"=",
"uint64",
"(",
"timeout",
"/",
"time",
".",
"Microsecond",
")",
"\n",
"}",
"\n",
"j",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"r",
":=",
"C",
".",
"my_sd_journal_wait",
"(",
"sd_journal_wait",
",",
"j",
".",
"cjournal",
",",
"C",
".",
"uint64_t",
"(",
"to",
")",
")",
"\n",
"j",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"int",
"(",
"r",
")",
"\n",
"}"
] | // Wait will synchronously wait until the journal gets changed. The maximum time
// this call sleeps may be controlled with the timeout parameter. If
// sdjournal.IndefiniteWait is passed as the timeout parameter, Wait will
// wait indefinitely for a journal change. | [
"Wait",
"will",
"synchronously",
"wait",
"until",
"the",
"journal",
"gets",
"changed",
".",
"The",
"maximum",
"time",
"this",
"call",
"sleeps",
"may",
"be",
"controlled",
"with",
"the",
"timeout",
"parameter",
".",
"If",
"sdjournal",
".",
"IndefiniteWait",
"is",
"passed",
"as",
"the",
"timeout",
"parameter",
"Wait",
"will",
"wait",
"indefinitely",
"for",
"a",
"journal",
"change",
"."
] | 95778dfbb74eb7e4dbaf43bf7d71809650ef8076 | https://github.com/coreos/go-systemd/blob/95778dfbb74eb7e4dbaf43bf7d71809650ef8076/sdjournal/journal.go#L997-L1018 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.