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",
">="... | // 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 :... | 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 :... | [
"func",
"(",
"g",
"*",
"Container",
")",
"Children",
"(",
")",
"(",
"[",
"]",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"array",
",",
"ok",
":=",
"g",
".",
"Data",
"(",
")",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"... | // 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",
"yo... | 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",
"]",
"interfa... | // 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",
"... | // 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",
"(",
")",
".",
"(",
"[",
"]",
... | // 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",
"...",
... | // 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... | // 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",
",",
... | // 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",
".",
... | // 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",
"bound... | 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 {
d... | 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 {
d... | [
"func",
"(",
"g",
"*",
"Container",
")",
"Delete",
"(",
"path",
"...",
"string",
")",
"error",
"{",
"var",
"object",
"interface",
"{",
"}",
"\n\n",
"if",
"g",
".",
"object",
"==",
"nil",
"{",
"return",
"ErrNotObj",
"\n",
"}",
"\n",
"object",
"=",
"... | // 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",
",",
"\"",
"\"",
")",
... | // 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... | 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... | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayRemove",
"(",
"index",
"int",
",",
"path",
"...",
"string",
")",
"error",
"{",
"if",
"index",
"<",
"0",
"{",
"return",
"ErrOutOfBounds",
"\n",
"}",
"\n",
"array",
",",
"ok",
":=",
"g",
".",
"Search",
"... | // 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",
",",
"\"",
"\"",
")",
"...",
")",
"\... | // 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
}
retu... | 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
}
retu... | [
"func",
"(",
"g",
"*",
"Container",
")",
"ArrayElement",
"(",
"index",
"int",
",",
"path",
"...",
"string",
")",
"(",
"*",
"Container",
",",
"error",
")",
"{",
"if",
"index",
"<",
"0",
"{",
"return",
"&",
"Container",
"{",
"nil",
"}",
",",
"ErrOutO... | // 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",
","... | // 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",
"(",
")",
".",
"(",
"[",
"... | // 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",
")",
";",
"er... | // 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",
")",
";",
"... | // 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",
"!=",
"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... | // 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 ... | 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 ... | [
"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",
... | // 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",
"re... | // 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",
"retur... | // 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",
... | // 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 matc... | 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 matc... | [
"func",
"NewMatcher",
"(",
"kind",
"types",
".",
"Type",
",",
"fn",
"Matcher",
")",
"TypeMatcher",
"{",
"matcher",
":=",
"func",
"(",
"buf",
"[",
"]",
"byte",
")",
"types",
".",
"Type",
"{",
"if",
"fn",
"(",
"buf",
")",
"{",
"return",
"kind",
"\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",
"ftypLe... | // 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]))
}
... | 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]))
}
... | [
"func",
"GetFtyp",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"string",
",",
"string",
",",
"[",
"]",
"string",
")",
"{",
"ftypLength",
":=",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"buf",
"[",
"0",
":",
"4",
"]",
")",
"\n\n",
"majorBrand",
... | // 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... | 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... | [
"func",
"Match",
"(",
"buf",
"[",
"]",
"byte",
")",
"(",
"types",
".",
"Type",
",",
"error",
")",
"{",
"length",
":=",
"len",
"(",
"buf",
")",
"\n",
"if",
"length",
"==",
"0",
"{",
"return",
"types",
".",
"Unknown",
",",
"ErrEmptyBuffer",
"\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",
",",
... | // 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",
... | // 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 != "... | 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 != "... | [
"func",
"NewJournalReader",
"(",
"config",
"JournalReaderConfig",
")",
"(",
"*",
"JournalReader",
",",
"error",
")",
"{",
"// use simpleMessageFormatter as default formatter.",
"if",
"config",
".",
"Formatter",
"==",
"nil",
"{",
"config",
".",
"Formatter",
"=",
"sim... | // 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.... | 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.... | [
"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 the... | // 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", times... | 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", times... | [
"func",
"simpleMessageFormatter",
"(",
"entry",
"*",
"JournalEntry",
")",
"(",
"string",
",",
"error",
")",
"{",
"msg",
",",
"ok",
":=",
"entry",
".",
"Fields",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
",",
"fmt",
"."... | // 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 n... | 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 n... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SystemState",
"(",
")",
"(",
"*",
"Property",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"prop",
"dbus",
".",
"Variant",
"\n\n",
"obj",
":=",
"c",
".",
"sysconn",
".",
"Object",
"(",
"\"",
"\"... | // 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.... | 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.... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"getProperties",
"(",
"path",
"dbus",
".",
"ObjectPath",
",",
"dbusInterface",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"prop... | // 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",... | // 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",
"(",
"\"",
"\"",
",... | // 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",
".",
"syso... | // 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"... | 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",
")"... | // 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",
".",
... | // 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",
"==... | // 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",
"}",
"... | // 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",
"||",... | // 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",
":=... | // 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)
}
... | 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)
}
... | [
"func",
"pathBusUnescape",
"(",
"path",
"string",
")",
"string",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"n",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"... | // 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",
"(",... | // 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, ... | 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, ... | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SubscribeUnitsCustom",
"(",
"interval",
"time",
".",
"Duration",
",",
"buffer",
"int",
",",
"isChanged",
"func",
"(",
"*",
"UnitStatus",
",",
"*",
"UnitStatus",
")",
"bool",
",",
"filterUnit",
"func",
"(",
"string",
"... | // 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",
... | 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",
... | // 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",
... | // 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",
"... | // 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",
"-",
... | 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... | 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... | [
"func",
"Serialize",
"(",
"opts",
"[",
"]",
"*",
"UnitOption",
")",
"io",
".",
"Reader",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"if",
"len",
"(",
"opts",
")",
"==",
"0",
"{",
"return",
"&",
"buf",
"\n",
"}",
"\n\n",
"// Index of sections ... | // 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(... | 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(... | [
"func",
"NewJournal",
"(",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // 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.cjo... | 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.cjo... | [
"func",
"NewJournalFromDir",
"(",
"path",
"string",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open_directory",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if"... | // 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... | 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... | [
"func",
"NewJournalFromFiles",
"(",
"paths",
"...",
"string",
")",
"(",
"j",
"*",
"Journal",
",",
"err",
"error",
")",
"{",
"j",
"=",
"&",
"Journal",
"{",
"}",
"\n\n",
"sd_journal_open_files",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\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... | // 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(mat... | 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(mat... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddMatch",
"(",
"match",
"string",
")",
"error",
"{",
"sd_journal_add_match",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"m",... | // 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 disjuncti... | 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 disjuncti... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddDisjunction",
"(",
")",
"error",
"{",
"sd_journal_add_disjunction",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"... | // 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 conjuncti... | 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 conjuncti... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"AddConjunction",
"(",
")",
"error",
"{",
"sd_journal_add_conjunction",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"j",
".",
"... | // 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",
... | // 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 ... | 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 ... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Next",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_next",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\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 ... | 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 ... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"NextSkip",
"(",
"skip",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_next_skip",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
... | // 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.Err... | 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.Err... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Previous",
"(",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_previous",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\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, fm... | 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, fm... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"PreviousSkip",
"(",
"skip",
"uint64",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"sd_journal_previous_skip",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // 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 <... | 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 <... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"SetDataThreshold",
"(",
"threshold",
"uint64",
")",
"error",
"{",
"sd_journal_set_data_threshold",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\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",
... | 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.uint... | 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.uint... | [
"func",
"(",
"j",
"*",
"Journal",
")",
"Wait",
"(",
"timeout",
"time",
".",
"Duration",
")",
"int",
"{",
"var",
"to",
"uint64",
"\n\n",
"sd_journal_wait",
",",
"err",
":=",
"getFunction",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // 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... | 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.