id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
100 | aymerick/douceur | inliner/inliner.go | collectElementsAndRules | func (inliner *Inliner) collectElementsAndRules() {
for _, stylesheet := range inliner.stylesheets {
for _, rule := range stylesheet.Rules {
if rule.Kind == css.QualifiedRule {
// Let's go!
inliner.handleQualifiedRule(rule)
} else {
// Keep it 'as is'
inliner.rawRules = append(inliner.rawRules, rule)
}
}
}
} | go | func (inliner *Inliner) collectElementsAndRules() {
for _, stylesheet := range inliner.stylesheets {
for _, rule := range stylesheet.Rules {
if rule.Kind == css.QualifiedRule {
// Let's go!
inliner.handleQualifiedRule(rule)
} else {
// Keep it 'as is'
inliner.rawRules = append(inliner.rawRules, rule)
}
}
}
} | [
"func",
"(",
"inliner",
"*",
"Inliner",
")",
"collectElementsAndRules",
"(",
")",
"{",
"for",
"_",
",",
"stylesheet",
":=",
"range",
"inliner",
".",
"stylesheets",
"{",
"for",
"_",
",",
"rule",
":=",
"range",
"stylesheet",
".",
"Rules",
"{",
"if",
"rule",
".",
"Kind",
"==",
"css",
".",
"QualifiedRule",
"{",
"// Let's go!",
"inliner",
".",
"handleQualifiedRule",
"(",
"rule",
")",
"\n",
"}",
"else",
"{",
"// Keep it 'as is'",
"inliner",
".",
"rawRules",
"=",
"append",
"(",
"inliner",
".",
"rawRules",
",",
"rule",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Collects HTML elements matching parsed stylesheets, and thus collect used style rules | [
"Collects",
"HTML",
"elements",
"matching",
"parsed",
"stylesheets",
"and",
"thus",
"collect",
"used",
"style",
"rules"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/inliner.go#L127-L139 |
101 | aymerick/douceur | inliner/inliner.go | handleQualifiedRule | func (inliner *Inliner) handleQualifiedRule(rule *css.Rule) {
for _, selector := range rule.Selectors {
if Inlinable(selector) {
inliner.doc.Find(selector).Each(func(i int, s *goquery.Selection) {
// get marker
eltMarker, exists := s.Attr(eltMarkerAttr)
if !exists {
// mark element
eltMarker = strconv.Itoa(inliner.eltMarker)
s.SetAttr(eltMarkerAttr, eltMarker)
inliner.eltMarker++
// add new element
inliner.elements[eltMarker] = NewElement(s)
}
// add style rule for element
inliner.elements[eltMarker].addStyleRule(NewStyleRule(selector, rule.Declarations))
})
} else {
// Keep it 'as is'
inliner.rawRules = append(inliner.rawRules, NewStyleRule(selector, rule.Declarations))
}
}
} | go | func (inliner *Inliner) handleQualifiedRule(rule *css.Rule) {
for _, selector := range rule.Selectors {
if Inlinable(selector) {
inliner.doc.Find(selector).Each(func(i int, s *goquery.Selection) {
// get marker
eltMarker, exists := s.Attr(eltMarkerAttr)
if !exists {
// mark element
eltMarker = strconv.Itoa(inliner.eltMarker)
s.SetAttr(eltMarkerAttr, eltMarker)
inliner.eltMarker++
// add new element
inliner.elements[eltMarker] = NewElement(s)
}
// add style rule for element
inliner.elements[eltMarker].addStyleRule(NewStyleRule(selector, rule.Declarations))
})
} else {
// Keep it 'as is'
inliner.rawRules = append(inliner.rawRules, NewStyleRule(selector, rule.Declarations))
}
}
} | [
"func",
"(",
"inliner",
"*",
"Inliner",
")",
"handleQualifiedRule",
"(",
"rule",
"*",
"css",
".",
"Rule",
")",
"{",
"for",
"_",
",",
"selector",
":=",
"range",
"rule",
".",
"Selectors",
"{",
"if",
"Inlinable",
"(",
"selector",
")",
"{",
"inliner",
".",
"doc",
".",
"Find",
"(",
"selector",
")",
".",
"Each",
"(",
"func",
"(",
"i",
"int",
",",
"s",
"*",
"goquery",
".",
"Selection",
")",
"{",
"// get marker",
"eltMarker",
",",
"exists",
":=",
"s",
".",
"Attr",
"(",
"eltMarkerAttr",
")",
"\n",
"if",
"!",
"exists",
"{",
"// mark element",
"eltMarker",
"=",
"strconv",
".",
"Itoa",
"(",
"inliner",
".",
"eltMarker",
")",
"\n",
"s",
".",
"SetAttr",
"(",
"eltMarkerAttr",
",",
"eltMarker",
")",
"\n",
"inliner",
".",
"eltMarker",
"++",
"\n\n",
"// add new element",
"inliner",
".",
"elements",
"[",
"eltMarker",
"]",
"=",
"NewElement",
"(",
"s",
")",
"\n",
"}",
"\n\n",
"// add style rule for element",
"inliner",
".",
"elements",
"[",
"eltMarker",
"]",
".",
"addStyleRule",
"(",
"NewStyleRule",
"(",
"selector",
",",
"rule",
".",
"Declarations",
")",
")",
"\n",
"}",
")",
"\n",
"}",
"else",
"{",
"// Keep it 'as is'",
"inliner",
".",
"rawRules",
"=",
"append",
"(",
"inliner",
".",
"rawRules",
",",
"NewStyleRule",
"(",
"selector",
",",
"rule",
".",
"Declarations",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Handles parsed qualified rule | [
"Handles",
"parsed",
"qualified",
"rule"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/inliner.go#L142-L166 |
102 | aymerick/douceur | inliner/inliner.go | inlineStyleRules | func (inliner *Inliner) inlineStyleRules() error {
for _, element := range inliner.elements {
// remove marker
element.elt.RemoveAttr(eltMarkerAttr)
// inline element
err := element.inline()
if err != nil {
return err
}
}
return nil
} | go | func (inliner *Inliner) inlineStyleRules() error {
for _, element := range inliner.elements {
// remove marker
element.elt.RemoveAttr(eltMarkerAttr)
// inline element
err := element.inline()
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"inliner",
"*",
"Inliner",
")",
"inlineStyleRules",
"(",
")",
"error",
"{",
"for",
"_",
",",
"element",
":=",
"range",
"inliner",
".",
"elements",
"{",
"// remove marker",
"element",
".",
"elt",
".",
"RemoveAttr",
"(",
"eltMarkerAttr",
")",
"\n\n",
"// inline element",
"err",
":=",
"element",
".",
"inline",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Inline style rules in HTML document | [
"Inline",
"style",
"rules",
"in",
"HTML",
"document"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/inliner.go#L169-L182 |
103 | aymerick/douceur | inliner/inliner.go | computeRawCSS | func (inliner *Inliner) computeRawCSS() string {
result := ""
for _, rawRule := range inliner.rawRules {
result += rawRule.String()
result += "\n"
}
return result
} | go | func (inliner *Inliner) computeRawCSS() string {
result := ""
for _, rawRule := range inliner.rawRules {
result += rawRule.String()
result += "\n"
}
return result
} | [
"func",
"(",
"inliner",
"*",
"Inliner",
")",
"computeRawCSS",
"(",
")",
"string",
"{",
"result",
":=",
"\"",
"\"",
"\n\n",
"for",
"_",
",",
"rawRule",
":=",
"range",
"inliner",
".",
"rawRules",
"{",
"result",
"+=",
"rawRule",
".",
"String",
"(",
")",
"\n",
"result",
"+=",
"\"",
"\\n",
"\"",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // Computes raw CSS rules | [
"Computes",
"raw",
"CSS",
"rules"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/inliner.go#L185-L194 |
104 | aymerick/douceur | inliner/inliner.go | insertRawStylesheet | func (inliner *Inliner) insertRawStylesheet() {
rawCSS := inliner.computeRawCSS()
if rawCSS != "" {
// create <style> element
cssNode := &html.Node{
Type: html.TextNode,
Data: "\n" + rawCSS,
}
styleNode := &html.Node{
Type: html.ElementNode,
Data: "style",
Attr: []html.Attribute{{Key: "type", Val: "text/css"}},
}
styleNode.AppendChild(cssNode)
// append to <head> element
headNode := inliner.doc.Find("head")
if headNode == nil {
// @todo Create head node !
panic("NOT IMPLEMENTED: create missing <head> node")
}
headNode.AppendNodes(styleNode)
}
} | go | func (inliner *Inliner) insertRawStylesheet() {
rawCSS := inliner.computeRawCSS()
if rawCSS != "" {
// create <style> element
cssNode := &html.Node{
Type: html.TextNode,
Data: "\n" + rawCSS,
}
styleNode := &html.Node{
Type: html.ElementNode,
Data: "style",
Attr: []html.Attribute{{Key: "type", Val: "text/css"}},
}
styleNode.AppendChild(cssNode)
// append to <head> element
headNode := inliner.doc.Find("head")
if headNode == nil {
// @todo Create head node !
panic("NOT IMPLEMENTED: create missing <head> node")
}
headNode.AppendNodes(styleNode)
}
} | [
"func",
"(",
"inliner",
"*",
"Inliner",
")",
"insertRawStylesheet",
"(",
")",
"{",
"rawCSS",
":=",
"inliner",
".",
"computeRawCSS",
"(",
")",
"\n",
"if",
"rawCSS",
"!=",
"\"",
"\"",
"{",
"// create <style> element",
"cssNode",
":=",
"&",
"html",
".",
"Node",
"{",
"Type",
":",
"html",
".",
"TextNode",
",",
"Data",
":",
"\"",
"\\n",
"\"",
"+",
"rawCSS",
",",
"}",
"\n\n",
"styleNode",
":=",
"&",
"html",
".",
"Node",
"{",
"Type",
":",
"html",
".",
"ElementNode",
",",
"Data",
":",
"\"",
"\"",
",",
"Attr",
":",
"[",
"]",
"html",
".",
"Attribute",
"{",
"{",
"Key",
":",
"\"",
"\"",
",",
"Val",
":",
"\"",
"\"",
"}",
"}",
",",
"}",
"\n\n",
"styleNode",
".",
"AppendChild",
"(",
"cssNode",
")",
"\n\n",
"// append to <head> element",
"headNode",
":=",
"inliner",
".",
"doc",
".",
"Find",
"(",
"\"",
"\"",
")",
"\n",
"if",
"headNode",
"==",
"nil",
"{",
"// @todo Create head node !",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"headNode",
".",
"AppendNodes",
"(",
"styleNode",
")",
"\n",
"}",
"\n",
"}"
] | // Insert raw CSS rules into HTML document | [
"Insert",
"raw",
"CSS",
"rules",
"into",
"HTML",
"document"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/inliner.go#L197-L223 |
105 | aymerick/douceur | inliner/inliner.go | Inlinable | func Inlinable(selector string) bool {
if strings.Contains(selector, "::") {
return false
}
for _, badSel := range unsupportedSelectors {
if strings.Contains(selector, badSel) {
return false
}
}
return true
} | go | func Inlinable(selector string) bool {
if strings.Contains(selector, "::") {
return false
}
for _, badSel := range unsupportedSelectors {
if strings.Contains(selector, badSel) {
return false
}
}
return true
} | [
"func",
"Inlinable",
"(",
"selector",
"string",
")",
"bool",
"{",
"if",
"strings",
".",
"Contains",
"(",
"selector",
",",
"\"",
"\"",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"badSel",
":=",
"range",
"unsupportedSelectors",
"{",
"if",
"strings",
".",
"Contains",
"(",
"selector",
",",
"badSel",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // Inlinable returns true if given selector is inlinable | [
"Inlinable",
"returns",
"true",
"if",
"given",
"selector",
"is",
"inlinable"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/inliner.go#L231-L243 |
106 | aymerick/douceur | inliner/style_declaration.go | NewStyleDeclaration | func NewStyleDeclaration(styleRule *StyleRule, declaration *css.Declaration) *StyleDeclaration {
return &StyleDeclaration{
StyleRule: styleRule,
Declaration: declaration,
}
} | go | func NewStyleDeclaration(styleRule *StyleRule, declaration *css.Declaration) *StyleDeclaration {
return &StyleDeclaration{
StyleRule: styleRule,
Declaration: declaration,
}
} | [
"func",
"NewStyleDeclaration",
"(",
"styleRule",
"*",
"StyleRule",
",",
"declaration",
"*",
"css",
".",
"Declaration",
")",
"*",
"StyleDeclaration",
"{",
"return",
"&",
"StyleDeclaration",
"{",
"StyleRule",
":",
"styleRule",
",",
"Declaration",
":",
"declaration",
",",
"}",
"\n",
"}"
] | // NewStyleDeclaration instanciates a new StyleDeclaration | [
"NewStyleDeclaration",
"instanciates",
"a",
"new",
"StyleDeclaration"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/style_declaration.go#L12-L17 |
107 | aymerick/douceur | inliner/style_declaration.go | Specificity | func (styleDecl *StyleDeclaration) Specificity() int {
if styleDecl.Declaration.Important {
return 10000
}
return styleDecl.StyleRule.Specificity
} | go | func (styleDecl *StyleDeclaration) Specificity() int {
if styleDecl.Declaration.Important {
return 10000
}
return styleDecl.StyleRule.Specificity
} | [
"func",
"(",
"styleDecl",
"*",
"StyleDeclaration",
")",
"Specificity",
"(",
")",
"int",
"{",
"if",
"styleDecl",
".",
"Declaration",
".",
"Important",
"{",
"return",
"10000",
"\n",
"}",
"\n\n",
"return",
"styleDecl",
".",
"StyleRule",
".",
"Specificity",
"\n",
"}"
] | // Specificity computes style declaration specificity | [
"Specificity",
"computes",
"style",
"declaration",
"specificity"
] | f9e29746e1161076eae141dd235f5d98b546ec3e | https://github.com/aymerick/douceur/blob/f9e29746e1161076eae141dd235f5d98b546ec3e/inliner/style_declaration.go#L20-L26 |
108 | oleiade/reflections | reflections.go | HasField | func HasField(obj interface{}, name string) (bool, error) {
if !hasValidType(obj, []reflect.Kind{reflect.Struct, reflect.Ptr}) {
return false, errors.New("Cannot use GetField on a non-struct interface")
}
objValue := reflectValue(obj)
objType := objValue.Type()
field, ok := objType.FieldByName(name)
if !ok || !isExportableField(field) {
return false, nil
}
return true, nil
} | go | func HasField(obj interface{}, name string) (bool, error) {
if !hasValidType(obj, []reflect.Kind{reflect.Struct, reflect.Ptr}) {
return false, errors.New("Cannot use GetField on a non-struct interface")
}
objValue := reflectValue(obj)
objType := objValue.Type()
field, ok := objType.FieldByName(name)
if !ok || !isExportableField(field) {
return false, nil
}
return true, nil
} | [
"func",
"HasField",
"(",
"obj",
"interface",
"{",
"}",
",",
"name",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"!",
"hasValidType",
"(",
"obj",
",",
"[",
"]",
"reflect",
".",
"Kind",
"{",
"reflect",
".",
"Struct",
",",
"reflect",
".",
"Ptr",
"}",
")",
"{",
"return",
"false",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"objValue",
":=",
"reflectValue",
"(",
"obj",
")",
"\n",
"objType",
":=",
"objValue",
".",
"Type",
"(",
")",
"\n",
"field",
",",
"ok",
":=",
"objType",
".",
"FieldByName",
"(",
"name",
")",
"\n",
"if",
"!",
"ok",
"||",
"!",
"isExportableField",
"(",
"field",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // HasField checks if the provided field name is part of a struct. obj can whether
// be a structure or pointer to structure. | [
"HasField",
"checks",
"if",
"the",
"provided",
"field",
"name",
"is",
"part",
"of",
"a",
"struct",
".",
"obj",
"can",
"whether",
"be",
"a",
"structure",
"or",
"pointer",
"to",
"structure",
"."
] | 0e86b3c98b2ff33e30c85cfe97d9a63d439fe7eb | https://github.com/oleiade/reflections/blob/0e86b3c98b2ff33e30c85cfe97d9a63d439fe7eb/reflections.go#L124-L137 |
109 | oleiade/reflections | reflections.go | Tags | func Tags(obj interface{}, key string) (map[string]string, error) {
return tags(obj, key, false)
} | go | func Tags(obj interface{}, key string) (map[string]string, error) {
return tags(obj, key, false)
} | [
"func",
"Tags",
"(",
"obj",
"interface",
"{",
"}",
",",
"key",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"return",
"tags",
"(",
"obj",
",",
"key",
",",
"false",
")",
"\n",
"}"
] | // Tags lists the struct tag fields. obj can whether
// be a structure or pointer to structure. | [
"Tags",
"lists",
"the",
"struct",
"tag",
"fields",
".",
"obj",
"can",
"whether",
"be",
"a",
"structure",
"or",
"pointer",
"to",
"structure",
"."
] | 0e86b3c98b2ff33e30c85cfe97d9a63d439fe7eb | https://github.com/oleiade/reflections/blob/0e86b3c98b2ff33e30c85cfe97d9a63d439fe7eb/reflections.go#L226-L228 |
110 | timshannon/bolthold | index.go | indexAdd | func indexAdd(storer Storer, tx *bolt.Tx, key []byte, data interface{}) error {
indexes := storer.Indexes()
for name, index := range indexes {
err := indexUpdate(storer.Type(), name, index, tx, key, data, false)
if err != nil {
return err
}
}
return nil
} | go | func indexAdd(storer Storer, tx *bolt.Tx, key []byte, data interface{}) error {
indexes := storer.Indexes()
for name, index := range indexes {
err := indexUpdate(storer.Type(), name, index, tx, key, data, false)
if err != nil {
return err
}
}
return nil
} | [
"func",
"indexAdd",
"(",
"storer",
"Storer",
",",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"key",
"[",
"]",
"byte",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"indexes",
":=",
"storer",
".",
"Indexes",
"(",
")",
"\n",
"for",
"name",
",",
"index",
":=",
"range",
"indexes",
"{",
"err",
":=",
"indexUpdate",
"(",
"storer",
".",
"Type",
"(",
")",
",",
"name",
",",
"index",
",",
"tx",
",",
"key",
",",
"data",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // adds an item to the index | [
"adds",
"an",
"item",
"to",
"the",
"index"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/index.go#L27-L37 |
111 | timshannon/bolthold | index.go | indexDelete | func indexDelete(storer Storer, tx *bolt.Tx, key []byte, originalData interface{}) error {
indexes := storer.Indexes()
for name, index := range indexes {
err := indexUpdate(storer.Type(), name, index, tx, key, originalData, true)
if err != nil {
return err
}
}
return nil
} | go | func indexDelete(storer Storer, tx *bolt.Tx, key []byte, originalData interface{}) error {
indexes := storer.Indexes()
for name, index := range indexes {
err := indexUpdate(storer.Type(), name, index, tx, key, originalData, true)
if err != nil {
return err
}
}
return nil
} | [
"func",
"indexDelete",
"(",
"storer",
"Storer",
",",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"key",
"[",
"]",
"byte",
",",
"originalData",
"interface",
"{",
"}",
")",
"error",
"{",
"indexes",
":=",
"storer",
".",
"Indexes",
"(",
")",
"\n\n",
"for",
"name",
",",
"index",
":=",
"range",
"indexes",
"{",
"err",
":=",
"indexUpdate",
"(",
"storer",
".",
"Type",
"(",
")",
",",
"name",
",",
"index",
",",
"tx",
",",
"key",
",",
"originalData",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // removes an item from the index
// be sure to pass the data from the old record, not the new one | [
"removes",
"an",
"item",
"from",
"the",
"index",
"be",
"sure",
"to",
"pass",
"the",
"data",
"from",
"the",
"old",
"record",
"not",
"the",
"new",
"one"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/index.go#L41-L52 |
112 | timshannon/bolthold | index.go | indexUpdate | func indexUpdate(typeName, indexName string, index Index, tx *bolt.Tx, key []byte, value interface{}, delete bool) error {
indexKey, err := index(indexName, value)
if indexKey == nil {
return nil
}
indexValue := make(keyList, 0)
if err != nil {
return err
}
b, err := tx.CreateBucketIfNotExists(indexBucketName(typeName, indexName))
if err != nil {
return err
}
iVal := b.Get(indexKey)
if iVal != nil {
err = decode(iVal, &indexValue)
if err != nil {
return err
}
}
if delete {
indexValue.remove(key)
} else {
indexValue.add(key)
}
if len(indexValue) == 0 {
return b.Delete(indexKey)
}
iVal, err = encode(indexValue)
if err != nil {
return err
}
return b.Put(indexKey, iVal)
} | go | func indexUpdate(typeName, indexName string, index Index, tx *bolt.Tx, key []byte, value interface{}, delete bool) error {
indexKey, err := index(indexName, value)
if indexKey == nil {
return nil
}
indexValue := make(keyList, 0)
if err != nil {
return err
}
b, err := tx.CreateBucketIfNotExists(indexBucketName(typeName, indexName))
if err != nil {
return err
}
iVal := b.Get(indexKey)
if iVal != nil {
err = decode(iVal, &indexValue)
if err != nil {
return err
}
}
if delete {
indexValue.remove(key)
} else {
indexValue.add(key)
}
if len(indexValue) == 0 {
return b.Delete(indexKey)
}
iVal, err = encode(indexValue)
if err != nil {
return err
}
return b.Put(indexKey, iVal)
} | [
"func",
"indexUpdate",
"(",
"typeName",
",",
"indexName",
"string",
",",
"index",
"Index",
",",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"key",
"[",
"]",
"byte",
",",
"value",
"interface",
"{",
"}",
",",
"delete",
"bool",
")",
"error",
"{",
"indexKey",
",",
"err",
":=",
"index",
"(",
"indexName",
",",
"value",
")",
"\n",
"if",
"indexKey",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"indexValue",
":=",
"make",
"(",
"keyList",
",",
"0",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"b",
",",
"err",
":=",
"tx",
".",
"CreateBucketIfNotExists",
"(",
"indexBucketName",
"(",
"typeName",
",",
"indexName",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"iVal",
":=",
"b",
".",
"Get",
"(",
"indexKey",
")",
"\n",
"if",
"iVal",
"!=",
"nil",
"{",
"err",
"=",
"decode",
"(",
"iVal",
",",
"&",
"indexValue",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"delete",
"{",
"indexValue",
".",
"remove",
"(",
"key",
")",
"\n",
"}",
"else",
"{",
"indexValue",
".",
"add",
"(",
"key",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"indexValue",
")",
"==",
"0",
"{",
"return",
"b",
".",
"Delete",
"(",
"indexKey",
")",
"\n",
"}",
"\n\n",
"iVal",
",",
"err",
"=",
"encode",
"(",
"indexValue",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"b",
".",
"Put",
"(",
"indexKey",
",",
"iVal",
")",
"\n",
"}"
] | // adds or removes a specific index on an item | [
"adds",
"or",
"removes",
"a",
"specific",
"index",
"on",
"an",
"item"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/index.go#L55-L96 |
113 | timshannon/bolthold | index.go | IndexExists | func (s *Store) IndexExists(tx *bolt.Tx, typeName, indexName string) bool {
return (tx.Bucket(indexBucketName(typeName, indexName)) != nil)
} | go | func (s *Store) IndexExists(tx *bolt.Tx, typeName, indexName string) bool {
return (tx.Bucket(indexBucketName(typeName, indexName)) != nil)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"IndexExists",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"typeName",
",",
"indexName",
"string",
")",
"bool",
"{",
"return",
"(",
"tx",
".",
"Bucket",
"(",
"indexBucketName",
"(",
"typeName",
",",
"indexName",
")",
")",
"!=",
"nil",
")",
"\n",
"}"
] | // IndexExists tests if an index exists for the passed in field name | [
"IndexExists",
"tests",
"if",
"an",
"index",
"exists",
"for",
"the",
"passed",
"in",
"field",
"name"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/index.go#L99-L101 |
114 | timshannon/bolthold | delete.go | Delete | func (s *Store) Delete(key, dataType interface{}) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxDelete(tx, key, dataType)
})
} | go | func (s *Store) Delete(key, dataType interface{}) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxDelete(tx, key, dataType)
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Delete",
"(",
"key",
",",
"dataType",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"s",
".",
"TxDelete",
"(",
"tx",
",",
"key",
",",
"dataType",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Delete deletes a record from the bolthold, datatype just needs to be an example of the type stored so that
// the proper bucket and indexes are updated | [
"Delete",
"deletes",
"a",
"record",
"from",
"the",
"bolthold",
"datatype",
"just",
"needs",
"to",
"be",
"an",
"example",
"of",
"the",
"type",
"stored",
"so",
"that",
"the",
"proper",
"bucket",
"and",
"indexes",
"are",
"updated"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/delete.go#L15-L19 |
115 | timshannon/bolthold | delete.go | TxDelete | func (s *Store) TxDelete(tx *bolt.Tx, key, dataType interface{}) error {
if !tx.Writable() {
return bolt.ErrTxNotWritable
}
storer := newStorer(dataType)
gk, err := encode(key)
if err != nil {
return err
}
b := tx.Bucket([]byte(storer.Type()))
if b == nil {
return ErrNotFound
}
value := reflect.New(reflect.TypeOf(dataType)).Interface()
bVal := b.Get(gk)
err = decode(bVal, value)
if err != nil {
return err
}
// delete data
err = b.Delete(gk)
if err != nil {
return err
}
// remove any indexes
return indexDelete(storer, tx, gk, value)
} | go | func (s *Store) TxDelete(tx *bolt.Tx, key, dataType interface{}) error {
if !tx.Writable() {
return bolt.ErrTxNotWritable
}
storer := newStorer(dataType)
gk, err := encode(key)
if err != nil {
return err
}
b := tx.Bucket([]byte(storer.Type()))
if b == nil {
return ErrNotFound
}
value := reflect.New(reflect.TypeOf(dataType)).Interface()
bVal := b.Get(gk)
err = decode(bVal, value)
if err != nil {
return err
}
// delete data
err = b.Delete(gk)
if err != nil {
return err
}
// remove any indexes
return indexDelete(storer, tx, gk, value)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxDelete",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"key",
",",
"dataType",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"!",
"tx",
".",
"Writable",
"(",
")",
"{",
"return",
"bolt",
".",
"ErrTxNotWritable",
"\n",
"}",
"\n\n",
"storer",
":=",
"newStorer",
"(",
"dataType",
")",
"\n",
"gk",
",",
"err",
":=",
"encode",
"(",
"key",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"b",
":=",
"tx",
".",
"Bucket",
"(",
"[",
"]",
"byte",
"(",
"storer",
".",
"Type",
"(",
")",
")",
")",
"\n",
"if",
"b",
"==",
"nil",
"{",
"return",
"ErrNotFound",
"\n",
"}",
"\n\n",
"value",
":=",
"reflect",
".",
"New",
"(",
"reflect",
".",
"TypeOf",
"(",
"dataType",
")",
")",
".",
"Interface",
"(",
")",
"\n\n",
"bVal",
":=",
"b",
".",
"Get",
"(",
"gk",
")",
"\n\n",
"err",
"=",
"decode",
"(",
"bVal",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// delete data",
"err",
"=",
"b",
".",
"Delete",
"(",
"gk",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// remove any indexes",
"return",
"indexDelete",
"(",
"storer",
",",
"tx",
",",
"gk",
",",
"value",
")",
"\n",
"}"
] | // TxDelete is the same as Delete except it allows you specify your own transaction | [
"TxDelete",
"is",
"the",
"same",
"as",
"Delete",
"except",
"it",
"allows",
"you",
"specify",
"your",
"own",
"transaction"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/delete.go#L22-L57 |
116 | timshannon/bolthold | delete.go | DeleteMatching | func (s *Store) DeleteMatching(dataType interface{}, query *Query) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxDeleteMatching(tx, dataType, query)
})
} | go | func (s *Store) DeleteMatching(dataType interface{}, query *Query) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxDeleteMatching(tx, dataType, query)
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"DeleteMatching",
"(",
"dataType",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
")",
"error",
"{",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"s",
".",
"TxDeleteMatching",
"(",
"tx",
",",
"dataType",
",",
"query",
")",
"\n",
"}",
")",
"\n",
"}"
] | // DeleteMatching deletes all of the records that match the passed in query | [
"DeleteMatching",
"deletes",
"all",
"of",
"the",
"records",
"that",
"match",
"the",
"passed",
"in",
"query"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/delete.go#L60-L64 |
117 | timshannon/bolthold | delete.go | TxDeleteMatching | func (s *Store) TxDeleteMatching(tx *bolt.Tx, dataType interface{}, query *Query) error {
return deleteQuery(tx, dataType, query)
} | go | func (s *Store) TxDeleteMatching(tx *bolt.Tx, dataType interface{}, query *Query) error {
return deleteQuery(tx, dataType, query)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxDeleteMatching",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"dataType",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
")",
"error",
"{",
"return",
"deleteQuery",
"(",
"tx",
",",
"dataType",
",",
"query",
")",
"\n",
"}"
] | // TxDeleteMatching does the same as DeleteMatching, but allows you to specify your own transaction | [
"TxDeleteMatching",
"does",
"the",
"same",
"as",
"DeleteMatching",
"but",
"allows",
"you",
"to",
"specify",
"your",
"own",
"transaction"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/delete.go#L67-L69 |
118 | timshannon/bolthold | get.go | Get | func (s *Store) Get(key, result interface{}) error {
return s.Bolt().View(func(tx *bolt.Tx) error {
return s.TxGet(tx, key, result)
})
} | go | func (s *Store) Get(key, result interface{}) error {
return s.Bolt().View(func(tx *bolt.Tx) error {
return s.TxGet(tx, key, result)
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Get",
"(",
"key",
",",
"result",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"View",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"s",
".",
"TxGet",
"(",
"tx",
",",
"key",
",",
"result",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Get retrieves a value from bolthold and puts it into result. Result must be a pointer | [
"Get",
"retrieves",
"a",
"value",
"from",
"bolthold",
"and",
"puts",
"it",
"into",
"result",
".",
"Result",
"must",
"be",
"a",
"pointer"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/get.go#L17-L21 |
119 | timshannon/bolthold | get.go | TxGet | func (s *Store) TxGet(tx *bolt.Tx, key, result interface{}) error {
storer := newStorer(result)
gk, err := encode(key)
if err != nil {
return err
}
bkt := tx.Bucket([]byte(storer.Type()))
if bkt == nil {
return ErrNotFound
}
value := bkt.Get(gk)
if value == nil {
return ErrNotFound
}
return decode(value, result)
} | go | func (s *Store) TxGet(tx *bolt.Tx, key, result interface{}) error {
storer := newStorer(result)
gk, err := encode(key)
if err != nil {
return err
}
bkt := tx.Bucket([]byte(storer.Type()))
if bkt == nil {
return ErrNotFound
}
value := bkt.Get(gk)
if value == nil {
return ErrNotFound
}
return decode(value, result)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxGet",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"key",
",",
"result",
"interface",
"{",
"}",
")",
"error",
"{",
"storer",
":=",
"newStorer",
"(",
"result",
")",
"\n\n",
"gk",
",",
"err",
":=",
"encode",
"(",
"key",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"bkt",
":=",
"tx",
".",
"Bucket",
"(",
"[",
"]",
"byte",
"(",
"storer",
".",
"Type",
"(",
")",
")",
")",
"\n",
"if",
"bkt",
"==",
"nil",
"{",
"return",
"ErrNotFound",
"\n",
"}",
"\n\n",
"value",
":=",
"bkt",
".",
"Get",
"(",
"gk",
")",
"\n",
"if",
"value",
"==",
"nil",
"{",
"return",
"ErrNotFound",
"\n",
"}",
"\n\n",
"return",
"decode",
"(",
"value",
",",
"result",
")",
"\n",
"}"
] | // TxGet allows you to pass in your own bolt transaction to retrieve a value from the bolthold and puts it into result | [
"TxGet",
"allows",
"you",
"to",
"pass",
"in",
"your",
"own",
"bolt",
"transaction",
"to",
"retrieve",
"a",
"value",
"from",
"the",
"bolthold",
"and",
"puts",
"it",
"into",
"result"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/get.go#L24-L44 |
120 | timshannon/bolthold | get.go | Find | func (s *Store) Find(result interface{}, query *Query) error {
return s.Bolt().View(func(tx *bolt.Tx) error {
return s.TxFind(tx, result, query)
})
} | go | func (s *Store) Find(result interface{}, query *Query) error {
return s.Bolt().View(func(tx *bolt.Tx) error {
return s.TxFind(tx, result, query)
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Find",
"(",
"result",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
")",
"error",
"{",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"View",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"s",
".",
"TxFind",
"(",
"tx",
",",
"result",
",",
"query",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Find retrieves a set of values from the bolthold that matches the passed in query
// result must be a pointer to a slice.
// The result of the query will be appended to the passed in result slice, rather than the passed in slice being
// emptied. | [
"Find",
"retrieves",
"a",
"set",
"of",
"values",
"from",
"the",
"bolthold",
"that",
"matches",
"the",
"passed",
"in",
"query",
"result",
"must",
"be",
"a",
"pointer",
"to",
"a",
"slice",
".",
"The",
"result",
"of",
"the",
"query",
"will",
"be",
"appended",
"to",
"the",
"passed",
"in",
"result",
"slice",
"rather",
"than",
"the",
"passed",
"in",
"slice",
"being",
"emptied",
"."
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/get.go#L50-L54 |
121 | timshannon/bolthold | get.go | TxFind | func (s *Store) TxFind(tx *bolt.Tx, result interface{}, query *Query) error {
return findQuery(tx, result, query)
} | go | func (s *Store) TxFind(tx *bolt.Tx, result interface{}, query *Query) error {
return findQuery(tx, result, query)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxFind",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"result",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
")",
"error",
"{",
"return",
"findQuery",
"(",
"tx",
",",
"result",
",",
"query",
")",
"\n",
"}"
] | // TxFind allows you to pass in your own bolt transaction to retrieve a set of values from the bolthold | [
"TxFind",
"allows",
"you",
"to",
"pass",
"in",
"your",
"own",
"bolt",
"transaction",
"to",
"retrieve",
"a",
"set",
"of",
"values",
"from",
"the",
"bolthold"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/get.go#L57-L59 |
122 | timshannon/bolthold | put.go | TxInsert | func (s *Store) TxInsert(tx *bolt.Tx, key, data interface{}) error {
if !tx.Writable() {
return bolt.ErrTxNotWritable
}
storer := newStorer(data)
b, err := tx.CreateBucketIfNotExists([]byte(storer.Type()))
if err != nil {
return err
}
if _, ok := key.(sequence); ok {
key, err = b.NextSequence()
if err != nil {
return err
}
}
gk, err := encode(key)
if err != nil {
return err
}
if b.Get(gk) != nil {
return ErrKeyExists
}
value, err := encode(data)
if err != nil {
return err
}
// insert data
err = b.Put(gk, value)
if err != nil {
return err
}
// insert any indexes
err = indexAdd(storer, tx, gk, data)
if err != nil {
return err
}
dataVal := reflect.Indirect(reflect.ValueOf(data))
if !dataVal.CanSet() {
return nil
}
dataType := dataVal.Type()
for i := 0; i < dataType.NumField(); i++ {
tf := dataType.Field(i)
// XXX: should we require standard tag format so we can use StructTag.Lookup()?
// XXX: should we use strings.Contains(string(tf.Tag), BoltholdKeyTag) so we don't require proper tags?
if _, ok := tf.Tag.Lookup(BoltholdKeyTag); ok {
fieldValue := dataVal.Field(i)
keyValue := reflect.ValueOf(key)
if keyValue.Type() != tf.Type {
break
}
if !fieldValue.CanSet() {
break
}
if !reflect.DeepEqual(fieldValue.Interface(), reflect.Zero(tf.Type).Interface()) {
break
}
fieldValue.Set(keyValue)
break
}
}
return nil
} | go | func (s *Store) TxInsert(tx *bolt.Tx, key, data interface{}) error {
if !tx.Writable() {
return bolt.ErrTxNotWritable
}
storer := newStorer(data)
b, err := tx.CreateBucketIfNotExists([]byte(storer.Type()))
if err != nil {
return err
}
if _, ok := key.(sequence); ok {
key, err = b.NextSequence()
if err != nil {
return err
}
}
gk, err := encode(key)
if err != nil {
return err
}
if b.Get(gk) != nil {
return ErrKeyExists
}
value, err := encode(data)
if err != nil {
return err
}
// insert data
err = b.Put(gk, value)
if err != nil {
return err
}
// insert any indexes
err = indexAdd(storer, tx, gk, data)
if err != nil {
return err
}
dataVal := reflect.Indirect(reflect.ValueOf(data))
if !dataVal.CanSet() {
return nil
}
dataType := dataVal.Type()
for i := 0; i < dataType.NumField(); i++ {
tf := dataType.Field(i)
// XXX: should we require standard tag format so we can use StructTag.Lookup()?
// XXX: should we use strings.Contains(string(tf.Tag), BoltholdKeyTag) so we don't require proper tags?
if _, ok := tf.Tag.Lookup(BoltholdKeyTag); ok {
fieldValue := dataVal.Field(i)
keyValue := reflect.ValueOf(key)
if keyValue.Type() != tf.Type {
break
}
if !fieldValue.CanSet() {
break
}
if !reflect.DeepEqual(fieldValue.Interface(), reflect.Zero(tf.Type).Interface()) {
break
}
fieldValue.Set(keyValue)
break
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxInsert",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"key",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"!",
"tx",
".",
"Writable",
"(",
")",
"{",
"return",
"bolt",
".",
"ErrTxNotWritable",
"\n",
"}",
"\n\n",
"storer",
":=",
"newStorer",
"(",
"data",
")",
"\n\n",
"b",
",",
"err",
":=",
"tx",
".",
"CreateBucketIfNotExists",
"(",
"[",
"]",
"byte",
"(",
"storer",
".",
"Type",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"key",
".",
"(",
"sequence",
")",
";",
"ok",
"{",
"key",
",",
"err",
"=",
"b",
".",
"NextSequence",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"gk",
",",
"err",
":=",
"encode",
"(",
"key",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"b",
".",
"Get",
"(",
"gk",
")",
"!=",
"nil",
"{",
"return",
"ErrKeyExists",
"\n",
"}",
"\n\n",
"value",
",",
"err",
":=",
"encode",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// insert data",
"err",
"=",
"b",
".",
"Put",
"(",
"gk",
",",
"value",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// insert any indexes",
"err",
"=",
"indexAdd",
"(",
"storer",
",",
"tx",
",",
"gk",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"dataVal",
":=",
"reflect",
".",
"Indirect",
"(",
"reflect",
".",
"ValueOf",
"(",
"data",
")",
")",
"\n",
"if",
"!",
"dataVal",
".",
"CanSet",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"dataType",
":=",
"dataVal",
".",
"Type",
"(",
")",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"dataType",
".",
"NumField",
"(",
")",
";",
"i",
"++",
"{",
"tf",
":=",
"dataType",
".",
"Field",
"(",
"i",
")",
"\n",
"// XXX: should we require standard tag format so we can use StructTag.Lookup()?",
"// XXX: should we use strings.Contains(string(tf.Tag), BoltholdKeyTag) so we don't require proper tags?",
"if",
"_",
",",
"ok",
":=",
"tf",
".",
"Tag",
".",
"Lookup",
"(",
"BoltholdKeyTag",
")",
";",
"ok",
"{",
"fieldValue",
":=",
"dataVal",
".",
"Field",
"(",
"i",
")",
"\n",
"keyValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"key",
")",
"\n",
"if",
"keyValue",
".",
"Type",
"(",
")",
"!=",
"tf",
".",
"Type",
"{",
"break",
"\n",
"}",
"\n",
"if",
"!",
"fieldValue",
".",
"CanSet",
"(",
")",
"{",
"break",
"\n",
"}",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"fieldValue",
".",
"Interface",
"(",
")",
",",
"reflect",
".",
"Zero",
"(",
"tf",
".",
"Type",
")",
".",
"Interface",
"(",
")",
")",
"{",
"break",
"\n",
"}",
"\n",
"fieldValue",
".",
"Set",
"(",
"keyValue",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // TxInsert is the same as Insert except it allows you specify your own transaction | [
"TxInsert",
"is",
"the",
"same",
"as",
"Insert",
"except",
"it",
"allows",
"you",
"specify",
"your",
"own",
"transaction"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/put.go#L43-L118 |
123 | timshannon/bolthold | put.go | Update | func (s *Store) Update(key interface{}, data interface{}) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxUpdate(tx, key, data)
})
} | go | func (s *Store) Update(key interface{}, data interface{}) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxUpdate(tx, key, data)
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Update",
"(",
"key",
"interface",
"{",
"}",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"s",
".",
"TxUpdate",
"(",
"tx",
",",
"key",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Update updates an existing record in the bolthold
// if the Key doesn't already exist in the store, then it fails with ErrNotFound | [
"Update",
"updates",
"an",
"existing",
"record",
"in",
"the",
"bolthold",
"if",
"the",
"Key",
"doesn",
"t",
"already",
"exist",
"in",
"the",
"store",
"then",
"it",
"fails",
"with",
"ErrNotFound"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/put.go#L122-L126 |
124 | timshannon/bolthold | put.go | TxUpdate | func (s *Store) TxUpdate(tx *bolt.Tx, key interface{}, data interface{}) error {
if !tx.Writable() {
return bolt.ErrTxNotWritable
}
storer := newStorer(data)
gk, err := encode(key)
if err != nil {
return err
}
b, err := tx.CreateBucketIfNotExists([]byte(storer.Type()))
if err != nil {
return err
}
existing := b.Get(gk)
if existing == nil {
return ErrNotFound
}
// delete any existing indexes
existingVal := reflect.New(reflect.TypeOf(data)).Interface()
err = decode(existing, existingVal)
if err != nil {
return err
}
err = indexDelete(storer, tx, gk, existingVal)
if err != nil {
return err
}
value, err := encode(data)
if err != nil {
return err
}
// put data
err = b.Put(gk, value)
if err != nil {
return err
}
// insert any new indexes
return indexAdd(storer, tx, gk, data)
} | go | func (s *Store) TxUpdate(tx *bolt.Tx, key interface{}, data interface{}) error {
if !tx.Writable() {
return bolt.ErrTxNotWritable
}
storer := newStorer(data)
gk, err := encode(key)
if err != nil {
return err
}
b, err := tx.CreateBucketIfNotExists([]byte(storer.Type()))
if err != nil {
return err
}
existing := b.Get(gk)
if existing == nil {
return ErrNotFound
}
// delete any existing indexes
existingVal := reflect.New(reflect.TypeOf(data)).Interface()
err = decode(existing, existingVal)
if err != nil {
return err
}
err = indexDelete(storer, tx, gk, existingVal)
if err != nil {
return err
}
value, err := encode(data)
if err != nil {
return err
}
// put data
err = b.Put(gk, value)
if err != nil {
return err
}
// insert any new indexes
return indexAdd(storer, tx, gk, data)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxUpdate",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"key",
"interface",
"{",
"}",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"!",
"tx",
".",
"Writable",
"(",
")",
"{",
"return",
"bolt",
".",
"ErrTxNotWritable",
"\n",
"}",
"\n\n",
"storer",
":=",
"newStorer",
"(",
"data",
")",
"\n\n",
"gk",
",",
"err",
":=",
"encode",
"(",
"key",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"b",
",",
"err",
":=",
"tx",
".",
"CreateBucketIfNotExists",
"(",
"[",
"]",
"byte",
"(",
"storer",
".",
"Type",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"existing",
":=",
"b",
".",
"Get",
"(",
"gk",
")",
"\n\n",
"if",
"existing",
"==",
"nil",
"{",
"return",
"ErrNotFound",
"\n",
"}",
"\n\n",
"// delete any existing indexes",
"existingVal",
":=",
"reflect",
".",
"New",
"(",
"reflect",
".",
"TypeOf",
"(",
"data",
")",
")",
".",
"Interface",
"(",
")",
"\n\n",
"err",
"=",
"decode",
"(",
"existing",
",",
"existingVal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"indexDelete",
"(",
"storer",
",",
"tx",
",",
"gk",
",",
"existingVal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"value",
",",
"err",
":=",
"encode",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// put data",
"err",
"=",
"b",
".",
"Put",
"(",
"gk",
",",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// insert any new indexes",
"return",
"indexAdd",
"(",
"storer",
",",
"tx",
",",
"gk",
",",
"data",
")",
"\n",
"}"
] | // TxUpdate is the same as Update except it allows you to specify your own transaction | [
"TxUpdate",
"is",
"the",
"same",
"as",
"Update",
"except",
"it",
"allows",
"you",
"to",
"specify",
"your",
"own",
"transaction"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/put.go#L129-L179 |
125 | timshannon/bolthold | put.go | Upsert | func (s *Store) Upsert(key interface{}, data interface{}) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxUpsert(tx, key, data)
})
} | go | func (s *Store) Upsert(key interface{}, data interface{}) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxUpsert(tx, key, data)
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"Upsert",
"(",
"key",
"interface",
"{",
"}",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"s",
".",
"TxUpsert",
"(",
"tx",
",",
"key",
",",
"data",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Upsert inserts the record into the bolthold if it doesn't exist. If it does already exist, then it updates
// the existing record | [
"Upsert",
"inserts",
"the",
"record",
"into",
"the",
"bolthold",
"if",
"it",
"doesn",
"t",
"exist",
".",
"If",
"it",
"does",
"already",
"exist",
"then",
"it",
"updates",
"the",
"existing",
"record"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/put.go#L183-L187 |
126 | timshannon/bolthold | put.go | UpdateMatching | func (s *Store) UpdateMatching(dataType interface{}, query *Query, update func(record interface{}) error) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxUpdateMatching(tx, dataType, query, update)
})
} | go | func (s *Store) UpdateMatching(dataType interface{}, query *Query, update func(record interface{}) error) error {
return s.Bolt().Update(func(tx *bolt.Tx) error {
return s.TxUpdateMatching(tx, dataType, query, update)
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"UpdateMatching",
"(",
"dataType",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
",",
"update",
"func",
"(",
"record",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"s",
".",
"TxUpdateMatching",
"(",
"tx",
",",
"dataType",
",",
"query",
",",
"update",
")",
"\n",
"}",
")",
"\n",
"}"
] | // UpdateMatching runs the update function for every record that match the passed in query
// Note that the type of record in the update func always has to be a pointer | [
"UpdateMatching",
"runs",
"the",
"update",
"function",
"for",
"every",
"record",
"that",
"match",
"the",
"passed",
"in",
"query",
"Note",
"that",
"the",
"type",
"of",
"record",
"in",
"the",
"update",
"func",
"always",
"has",
"to",
"be",
"a",
"pointer"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/put.go#L244-L248 |
127 | timshannon/bolthold | put.go | TxUpdateMatching | func (s *Store) TxUpdateMatching(tx *bolt.Tx, dataType interface{}, query *Query, update func(record interface{}) error) error {
return updateQuery(tx, dataType, query, update)
} | go | func (s *Store) TxUpdateMatching(tx *bolt.Tx, dataType interface{}, query *Query, update func(record interface{}) error) error {
return updateQuery(tx, dataType, query, update)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxUpdateMatching",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"dataType",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
",",
"update",
"func",
"(",
"record",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"return",
"updateQuery",
"(",
"tx",
",",
"dataType",
",",
"query",
",",
"update",
")",
"\n",
"}"
] | // TxUpdateMatching does the same as UpdateMatching, but allows you to specify your own transaction | [
"TxUpdateMatching",
"does",
"the",
"same",
"as",
"UpdateMatching",
"but",
"allows",
"you",
"to",
"specify",
"your",
"own",
"transaction"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/put.go#L251-L253 |
128 | timshannon/bolthold | store.go | Open | func Open(filename string, mode os.FileMode, options *Options) (*Store, error) {
options = fillOptions(options)
encode = options.Encoder
decode = options.Decoder
db, err := bolt.Open(filename, mode, options.Options)
if err != nil {
return nil, err
}
return &Store{
db: db,
}, nil
} | go | func Open(filename string, mode os.FileMode, options *Options) (*Store, error) {
options = fillOptions(options)
encode = options.Encoder
decode = options.Decoder
db, err := bolt.Open(filename, mode, options.Options)
if err != nil {
return nil, err
}
return &Store{
db: db,
}, nil
} | [
"func",
"Open",
"(",
"filename",
"string",
",",
"mode",
"os",
".",
"FileMode",
",",
"options",
"*",
"Options",
")",
"(",
"*",
"Store",
",",
"error",
")",
"{",
"options",
"=",
"fillOptions",
"(",
"options",
")",
"\n\n",
"encode",
"=",
"options",
".",
"Encoder",
"\n",
"decode",
"=",
"options",
".",
"Decoder",
"\n\n",
"db",
",",
"err",
":=",
"bolt",
".",
"Open",
"(",
"filename",
",",
"mode",
",",
"options",
".",
"Options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Store",
"{",
"db",
":",
"db",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Open opens or creates a bolthold file. | [
"Open",
"opens",
"or",
"creates",
"a",
"bolthold",
"file",
"."
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/store.go#L29-L43 |
129 | timshannon/bolthold | store.go | fillOptions | func fillOptions(options *Options) *Options {
if options == nil {
options = &Options{}
}
if options.Encoder == nil {
options.Encoder = DefaultEncode
}
if options.Decoder == nil {
options.Decoder = DefaultDecode
}
return options
} | go | func fillOptions(options *Options) *Options {
if options == nil {
options = &Options{}
}
if options.Encoder == nil {
options.Encoder = DefaultEncode
}
if options.Decoder == nil {
options.Decoder = DefaultDecode
}
return options
} | [
"func",
"fillOptions",
"(",
"options",
"*",
"Options",
")",
"*",
"Options",
"{",
"if",
"options",
"==",
"nil",
"{",
"options",
"=",
"&",
"Options",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"options",
".",
"Encoder",
"==",
"nil",
"{",
"options",
".",
"Encoder",
"=",
"DefaultEncode",
"\n",
"}",
"\n",
"if",
"options",
".",
"Decoder",
"==",
"nil",
"{",
"options",
".",
"Decoder",
"=",
"DefaultDecode",
"\n",
"}",
"\n\n",
"return",
"options",
"\n",
"}"
] | // set any unspecified options to defaults | [
"set",
"any",
"unspecified",
"options",
"to",
"defaults"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/store.go#L46-L59 |
130 | timshannon/bolthold | store.go | RemoveIndex | func (s *Store) RemoveIndex(dataType interface{}, indexName string) error {
storer := newStorer(dataType)
return s.Bolt().Update(func(tx *bolt.Tx) error {
return tx.DeleteBucket(indexBucketName(storer.Type(), indexName))
})
} | go | func (s *Store) RemoveIndex(dataType interface{}, indexName string) error {
storer := newStorer(dataType)
return s.Bolt().Update(func(tx *bolt.Tx) error {
return tx.DeleteBucket(indexBucketName(storer.Type(), indexName))
})
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"RemoveIndex",
"(",
"dataType",
"interface",
"{",
"}",
",",
"indexName",
"string",
")",
"error",
"{",
"storer",
":=",
"newStorer",
"(",
"dataType",
")",
"\n",
"return",
"s",
".",
"Bolt",
"(",
")",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"return",
"tx",
".",
"DeleteBucket",
"(",
"indexBucketName",
"(",
"storer",
".",
"Type",
"(",
")",
",",
"indexName",
")",
")",
"\n\n",
"}",
")",
"\n",
"}"
] | // RemoveIndex removes an index from the store. | [
"RemoveIndex",
"removes",
"an",
"index",
"from",
"the",
"store",
"."
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/store.go#L127-L133 |
131 | timshannon/bolthold | query.go | IsEmpty | func (q *Query) IsEmpty() bool {
if q.index != "" {
return false
}
if len(q.fieldCriteria) != 0 {
return false
}
if q.ors != nil {
return false
}
return true
} | go | func (q *Query) IsEmpty() bool {
if q.index != "" {
return false
}
if len(q.fieldCriteria) != 0 {
return false
}
if q.ors != nil {
return false
}
return true
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"if",
"q",
".",
"index",
"!=",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"q",
".",
"fieldCriteria",
")",
"!=",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"ors",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // IsEmpty returns true if the query is an empty query
// an empty query matches against everything | [
"IsEmpty",
"returns",
"true",
"if",
"the",
"query",
"is",
"an",
"empty",
"query",
"an",
"empty",
"query",
"matches",
"against",
"everything"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L58-L71 |
132 | timshannon/bolthold | query.go | And | func (q *Query) And(field string) *Criterion {
if !startsUpper(field) {
panic("The first letter of a field in a bolthold query must be upper-case")
}
q.currentField = field
return &Criterion{
query: q,
}
} | go | func (q *Query) And(field string) *Criterion {
if !startsUpper(field) {
panic("The first letter of a field in a bolthold query must be upper-case")
}
q.currentField = field
return &Criterion{
query: q,
}
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"And",
"(",
"field",
"string",
")",
"*",
"Criterion",
"{",
"if",
"!",
"startsUpper",
"(",
"field",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"q",
".",
"currentField",
"=",
"field",
"\n",
"return",
"&",
"Criterion",
"{",
"query",
":",
"q",
",",
"}",
"\n",
"}"
] | // And creates a nother set of criterion the needs to apply to a query | [
"And",
"creates",
"a",
"nother",
"set",
"of",
"criterion",
"the",
"needs",
"to",
"apply",
"to",
"a",
"query"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L116-L125 |
133 | timshannon/bolthold | query.go | Skip | func (q *Query) Skip(amount int) *Query {
if amount < 0 {
panic("Skip must be set to a positive number")
}
if q.skip != 0 {
panic(fmt.Sprintf("Skip has already been set to %d", q.skip))
}
q.skip = amount
return q
} | go | func (q *Query) Skip(amount int) *Query {
if amount < 0 {
panic("Skip must be set to a positive number")
}
if q.skip != 0 {
panic(fmt.Sprintf("Skip has already been set to %d", q.skip))
}
q.skip = amount
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Skip",
"(",
"amount",
"int",
")",
"*",
"Query",
"{",
"if",
"amount",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"skip",
"!=",
"0",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"skip",
")",
")",
"\n",
"}",
"\n\n",
"q",
".",
"skip",
"=",
"amount",
"\n\n",
"return",
"q",
"\n",
"}"
] | // Skip skips the number of records that match all the rest of the query criteria, and does not return them
// in the result set. Setting skip multiple times, or to a negative value will panic | [
"Skip",
"skips",
"the",
"number",
"of",
"records",
"that",
"match",
"all",
"the",
"rest",
"of",
"the",
"query",
"criteria",
"and",
"does",
"not",
"return",
"them",
"in",
"the",
"result",
"set",
".",
"Setting",
"skip",
"multiple",
"times",
"or",
"to",
"a",
"negative",
"value",
"will",
"panic"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L129-L141 |
134 | timshannon/bolthold | query.go | Limit | func (q *Query) Limit(amount int) *Query {
if amount < 0 {
panic("Limit must be set to a positive number")
}
if q.limit != 0 {
panic(fmt.Sprintf("Limit has already been set to %d", q.limit))
}
q.limit = amount
return q
} | go | func (q *Query) Limit(amount int) *Query {
if amount < 0 {
panic("Limit must be set to a positive number")
}
if q.limit != 0 {
panic(fmt.Sprintf("Limit has already been set to %d", q.limit))
}
q.limit = amount
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Limit",
"(",
"amount",
"int",
")",
"*",
"Query",
"{",
"if",
"amount",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"q",
".",
"limit",
"!=",
"0",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"limit",
")",
")",
"\n",
"}",
"\n\n",
"q",
".",
"limit",
"=",
"amount",
"\n\n",
"return",
"q",
"\n",
"}"
] | // Limit sets the maximum number of records that can be returned by a query
// Setting Limit multiple times, or to a negative value will panic | [
"Limit",
"sets",
"the",
"maximum",
"number",
"of",
"records",
"that",
"can",
"be",
"returned",
"by",
"a",
"query",
"Setting",
"Limit",
"multiple",
"times",
"or",
"to",
"a",
"negative",
"value",
"will",
"panic"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L145-L157 |
135 | timshannon/bolthold | query.go | SortBy | func (q *Query) SortBy(fields ...string) *Query {
for i := range fields {
if fields[i] == Key {
panic("Cannot sort by Key.")
}
found := false
for k := range q.sort {
if q.sort[k] == fields[i] {
found = true
break
}
}
if !found {
q.sort = append(q.sort, fields[i])
}
}
return q
} | go | func (q *Query) SortBy(fields ...string) *Query {
for i := range fields {
if fields[i] == Key {
panic("Cannot sort by Key.")
}
found := false
for k := range q.sort {
if q.sort[k] == fields[i] {
found = true
break
}
}
if !found {
q.sort = append(q.sort, fields[i])
}
}
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"SortBy",
"(",
"fields",
"...",
"string",
")",
"*",
"Query",
"{",
"for",
"i",
":=",
"range",
"fields",
"{",
"if",
"fields",
"[",
"i",
"]",
"==",
"Key",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"found",
":=",
"false",
"\n",
"for",
"k",
":=",
"range",
"q",
".",
"sort",
"{",
"if",
"q",
".",
"sort",
"[",
"k",
"]",
"==",
"fields",
"[",
"i",
"]",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"q",
".",
"sort",
"=",
"append",
"(",
"q",
".",
"sort",
",",
"fields",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"q",
"\n",
"}"
] | // SortBy sorts the results by the given fields name
// Multiple fields can be used | [
"SortBy",
"sorts",
"the",
"results",
"by",
"the",
"given",
"fields",
"name",
"Multiple",
"fields",
"can",
"be",
"used"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L161-L178 |
136 | timshannon/bolthold | query.go | Index | func (q *Query) Index(indexName string) *Query {
if strings.Contains(indexName, ".") {
// NOTE: I may reconsider this in the future
panic("Nested indexes are not supported. Only top level structures can be indexed")
}
q.index = indexName
return q
} | go | func (q *Query) Index(indexName string) *Query {
if strings.Contains(indexName, ".") {
// NOTE: I may reconsider this in the future
panic("Nested indexes are not supported. Only top level structures can be indexed")
}
q.index = indexName
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Index",
"(",
"indexName",
"string",
")",
"*",
"Query",
"{",
"if",
"strings",
".",
"Contains",
"(",
"indexName",
",",
"\"",
"\"",
")",
"{",
"// NOTE: I may reconsider this in the future",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"q",
".",
"index",
"=",
"indexName",
"\n",
"return",
"q",
"\n",
"}"
] | // Index specifies the index to use when running this query | [
"Index",
"specifies",
"the",
"index",
"to",
"use",
"when",
"running",
"this",
"query"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L188-L195 |
137 | timshannon/bolthold | query.go | Or | func (q *Query) Or(query *Query) *Query {
if query.skip != 0 || query.limit != 0 {
panic("Or'd queries cannot contain skip or limit values")
}
q.ors = append(q.ors, query)
return q
} | go | func (q *Query) Or(query *Query) *Query {
if query.skip != 0 || query.limit != 0 {
panic("Or'd queries cannot contain skip or limit values")
}
q.ors = append(q.ors, query)
return q
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"Or",
"(",
"query",
"*",
"Query",
")",
"*",
"Query",
"{",
"if",
"query",
".",
"skip",
"!=",
"0",
"||",
"query",
".",
"limit",
"!=",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"q",
".",
"ors",
"=",
"append",
"(",
"q",
".",
"ors",
",",
"query",
")",
"\n",
"return",
"q",
"\n",
"}"
] | // Or creates another separate query that gets unioned with any other results in the query
// Or will panic if the query passed in contains a limit or skip value, as they are only
// allowed on top level queries | [
"Or",
"creates",
"another",
"separate",
"query",
"that",
"gets",
"unioned",
"with",
"any",
"other",
"results",
"in",
"the",
"query",
"Or",
"will",
"panic",
"if",
"the",
"query",
"passed",
"in",
"contains",
"a",
"limit",
"or",
"skip",
"value",
"as",
"they",
"are",
"only",
"allowed",
"on",
"top",
"level",
"queries"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L200-L206 |
138 | timshannon/bolthold | query.go | In | func (c *Criterion) In(values ...interface{}) *Query {
c.operator = in
c.inValues = values
q := c.query
q.fieldCriteria[q.currentField] = append(q.fieldCriteria[q.currentField], c)
return q
} | go | func (c *Criterion) In(values ...interface{}) *Query {
c.operator = in
c.inValues = values
q := c.query
q.fieldCriteria[q.currentField] = append(q.fieldCriteria[q.currentField], c)
return q
} | [
"func",
"(",
"c",
"*",
"Criterion",
")",
"In",
"(",
"values",
"...",
"interface",
"{",
"}",
")",
"*",
"Query",
"{",
"c",
".",
"operator",
"=",
"in",
"\n",
"c",
".",
"inValues",
"=",
"values",
"\n\n",
"q",
":=",
"c",
".",
"query",
"\n",
"q",
".",
"fieldCriteria",
"[",
"q",
".",
"currentField",
"]",
"=",
"append",
"(",
"q",
".",
"fieldCriteria",
"[",
"q",
".",
"currentField",
"]",
",",
"c",
")",
"\n\n",
"return",
"q",
"\n",
"}"
] | // In test if the current field is a member of the slice of values passed in | [
"In",
"test",
"if",
"the",
"current",
"field",
"is",
"a",
"member",
"of",
"the",
"slice",
"of",
"values",
"passed",
"in"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L306-L314 |
139 | timshannon/bolthold | query.go | SubQuery | func (r *RecordAccess) SubQuery(result interface{}, query *Query) error {
return findQuery(r.tx, result, query)
} | go | func (r *RecordAccess) SubQuery(result interface{}, query *Query) error {
return findQuery(r.tx, result, query)
} | [
"func",
"(",
"r",
"*",
"RecordAccess",
")",
"SubQuery",
"(",
"result",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
")",
"error",
"{",
"return",
"findQuery",
"(",
"r",
".",
"tx",
",",
"result",
",",
"query",
")",
"\n",
"}"
] | // SubQuery allows you to run another query in the same transaction for each
// record in a parent query | [
"SubQuery",
"allows",
"you",
"to",
"run",
"another",
"query",
"in",
"the",
"same",
"transaction",
"for",
"each",
"record",
"in",
"a",
"parent",
"query"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L350-L352 |
140 | timshannon/bolthold | query.go | SubAggregateQuery | func (r *RecordAccess) SubAggregateQuery(query *Query, groupBy ...string) ([]*AggregateResult, error) {
return aggregateQuery(r.tx, r.record, query, groupBy...)
} | go | func (r *RecordAccess) SubAggregateQuery(query *Query, groupBy ...string) ([]*AggregateResult, error) {
return aggregateQuery(r.tx, r.record, query, groupBy...)
} | [
"func",
"(",
"r",
"*",
"RecordAccess",
")",
"SubAggregateQuery",
"(",
"query",
"*",
"Query",
",",
"groupBy",
"...",
"string",
")",
"(",
"[",
"]",
"*",
"AggregateResult",
",",
"error",
")",
"{",
"return",
"aggregateQuery",
"(",
"r",
".",
"tx",
",",
"r",
".",
"record",
",",
"query",
",",
"groupBy",
"...",
")",
"\n",
"}"
] | // SubAggregateQuery allows you to run another aggregate query in the same transaction for each
// record in a parent query | [
"SubAggregateQuery",
"allows",
"you",
"to",
"run",
"another",
"aggregate",
"query",
"in",
"the",
"same",
"transaction",
"for",
"each",
"record",
"in",
"a",
"parent",
"query"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L356-L358 |
141 | timshannon/bolthold | query.go | MatchFunc | func (c *Criterion) MatchFunc(match MatchFunc) *Query {
if c.query.currentField == Key {
panic("Match func cannot be used against Keys, as the Key type is unknown at runtime, and there is no value compare against")
}
return c.op(fn, match)
} | go | func (c *Criterion) MatchFunc(match MatchFunc) *Query {
if c.query.currentField == Key {
panic("Match func cannot be used against Keys, as the Key type is unknown at runtime, and there is no value compare against")
}
return c.op(fn, match)
} | [
"func",
"(",
"c",
"*",
"Criterion",
")",
"MatchFunc",
"(",
"match",
"MatchFunc",
")",
"*",
"Query",
"{",
"if",
"c",
".",
"query",
".",
"currentField",
"==",
"Key",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"op",
"(",
"fn",
",",
"match",
")",
"\n",
"}"
] | // MatchFunc will test if a field matches the passed in function | [
"MatchFunc",
"will",
"test",
"if",
"a",
"field",
"matches",
"the",
"passed",
"in",
"function"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/query.go#L361-L367 |
142 | timshannon/bolthold | aggregate.go | Group | func (a *AggregateResult) Group(result ...interface{}) {
for i := range result {
resultVal := reflect.ValueOf(result[i])
if resultVal.Kind() != reflect.Ptr {
panic("result argument must be an address")
}
if i >= len(a.group) {
panic(fmt.Sprintf("There is not %d elements in the grouping", i))
}
resultVal.Elem().Set(a.group[i])
}
} | go | func (a *AggregateResult) Group(result ...interface{}) {
for i := range result {
resultVal := reflect.ValueOf(result[i])
if resultVal.Kind() != reflect.Ptr {
panic("result argument must be an address")
}
if i >= len(a.group) {
panic(fmt.Sprintf("There is not %d elements in the grouping", i))
}
resultVal.Elem().Set(a.group[i])
}
} | [
"func",
"(",
"a",
"*",
"AggregateResult",
")",
"Group",
"(",
"result",
"...",
"interface",
"{",
"}",
")",
"{",
"for",
"i",
":=",
"range",
"result",
"{",
"resultVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"result",
"[",
"i",
"]",
")",
"\n",
"if",
"resultVal",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"i",
">=",
"len",
"(",
"a",
".",
"group",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"}",
"\n\n",
"resultVal",
".",
"Elem",
"(",
")",
".",
"Set",
"(",
"a",
".",
"group",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}"
] | // Group returns the field grouped by in the query | [
"Group",
"returns",
"the",
"field",
"grouped",
"by",
"in",
"the",
"query"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/aggregate.go#L23-L36 |
143 | timshannon/bolthold | aggregate.go | Reduction | func (a *AggregateResult) Reduction(result interface{}) {
resultVal := reflect.ValueOf(result)
if resultVal.Kind() != reflect.Ptr || resultVal.Elem().Kind() != reflect.Slice {
panic("result argument must be a slice address")
}
sliceVal := resultVal.Elem()
elType := sliceVal.Type().Elem()
for i := range a.reduction {
if elType.Kind() == reflect.Ptr {
sliceVal = reflect.Append(sliceVal, a.reduction[i])
} else {
sliceVal = reflect.Append(sliceVal, a.reduction[i].Elem())
}
}
resultVal.Elem().Set(sliceVal.Slice(0, sliceVal.Len()))
} | go | func (a *AggregateResult) Reduction(result interface{}) {
resultVal := reflect.ValueOf(result)
if resultVal.Kind() != reflect.Ptr || resultVal.Elem().Kind() != reflect.Slice {
panic("result argument must be a slice address")
}
sliceVal := resultVal.Elem()
elType := sliceVal.Type().Elem()
for i := range a.reduction {
if elType.Kind() == reflect.Ptr {
sliceVal = reflect.Append(sliceVal, a.reduction[i])
} else {
sliceVal = reflect.Append(sliceVal, a.reduction[i].Elem())
}
}
resultVal.Elem().Set(sliceVal.Slice(0, sliceVal.Len()))
} | [
"func",
"(",
"a",
"*",
"AggregateResult",
")",
"Reduction",
"(",
"result",
"interface",
"{",
"}",
")",
"{",
"resultVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"result",
")",
"\n\n",
"if",
"resultVal",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"||",
"resultVal",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Slice",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"sliceVal",
":=",
"resultVal",
".",
"Elem",
"(",
")",
"\n\n",
"elType",
":=",
"sliceVal",
".",
"Type",
"(",
")",
".",
"Elem",
"(",
")",
"\n\n",
"for",
"i",
":=",
"range",
"a",
".",
"reduction",
"{",
"if",
"elType",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"sliceVal",
"=",
"reflect",
".",
"Append",
"(",
"sliceVal",
",",
"a",
".",
"reduction",
"[",
"i",
"]",
")",
"\n",
"}",
"else",
"{",
"sliceVal",
"=",
"reflect",
".",
"Append",
"(",
"sliceVal",
",",
"a",
".",
"reduction",
"[",
"i",
"]",
".",
"Elem",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"resultVal",
".",
"Elem",
"(",
")",
".",
"Set",
"(",
"sliceVal",
".",
"Slice",
"(",
"0",
",",
"sliceVal",
".",
"Len",
"(",
")",
")",
")",
"\n",
"}"
] | // Reduction is the collection of records that are part of the AggregateResult Group | [
"Reduction",
"is",
"the",
"collection",
"of",
"records",
"that",
"are",
"part",
"of",
"the",
"AggregateResult",
"Group"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/aggregate.go#L39-L59 |
144 | timshannon/bolthold | aggregate.go | Max | func (a *AggregateResult) Max(field string, result interface{}) {
a.Sort(field)
resultVal := reflect.ValueOf(result)
if resultVal.Kind() != reflect.Ptr {
panic("result argument must be an address")
}
if resultVal.IsNil() {
panic("result argument must not be nil")
}
resultVal.Elem().Set(a.reduction[len(a.reduction)-1].Elem())
} | go | func (a *AggregateResult) Max(field string, result interface{}) {
a.Sort(field)
resultVal := reflect.ValueOf(result)
if resultVal.Kind() != reflect.Ptr {
panic("result argument must be an address")
}
if resultVal.IsNil() {
panic("result argument must not be nil")
}
resultVal.Elem().Set(a.reduction[len(a.reduction)-1].Elem())
} | [
"func",
"(",
"a",
"*",
"AggregateResult",
")",
"Max",
"(",
"field",
"string",
",",
"result",
"interface",
"{",
"}",
")",
"{",
"a",
".",
"Sort",
"(",
"field",
")",
"\n\n",
"resultVal",
":=",
"reflect",
".",
"ValueOf",
"(",
"result",
")",
"\n",
"if",
"resultVal",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"resultVal",
".",
"IsNil",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resultVal",
".",
"Elem",
"(",
")",
".",
"Set",
"(",
"a",
".",
"reduction",
"[",
"len",
"(",
"a",
".",
"reduction",
")",
"-",
"1",
"]",
".",
"Elem",
"(",
")",
")",
"\n",
"}"
] | // Max Returns the maxiumum value of the Aggregate Grouping, uses the Comparer interface | [
"Max",
"Returns",
"the",
"maxiumum",
"value",
"of",
"the",
"Aggregate",
"Grouping",
"uses",
"the",
"Comparer",
"interface"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/aggregate.go#L103-L116 |
145 | timshannon/bolthold | aggregate.go | Avg | func (a *AggregateResult) Avg(field string) float64 {
sum := a.Sum(field)
return sum / float64(len(a.reduction))
} | go | func (a *AggregateResult) Avg(field string) float64 {
sum := a.Sum(field)
return sum / float64(len(a.reduction))
} | [
"func",
"(",
"a",
"*",
"AggregateResult",
")",
"Avg",
"(",
"field",
"string",
")",
"float64",
"{",
"sum",
":=",
"a",
".",
"Sum",
"(",
"field",
")",
"\n",
"return",
"sum",
"/",
"float64",
"(",
"len",
"(",
"a",
".",
"reduction",
")",
")",
"\n",
"}"
] | // Avg returns the average float value of the aggregate grouping
// panics if the field cannot be converted to an float64 | [
"Avg",
"returns",
"the",
"average",
"float",
"value",
"of",
"the",
"aggregate",
"grouping",
"panics",
"if",
"the",
"field",
"cannot",
"be",
"converted",
"to",
"an",
"float64"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/aggregate.go#L136-L139 |
146 | timshannon/bolthold | aggregate.go | Sum | func (a *AggregateResult) Sum(field string) float64 {
var sum float64
for i := range a.reduction {
fVal := a.reduction[i].Elem().FieldByName(field)
if !fVal.IsValid() {
panic(fmt.Sprintf("The field %s does not exist in the type %s", field, a.reduction[i].Type()))
}
sum += tryFloat(fVal)
}
return sum
} | go | func (a *AggregateResult) Sum(field string) float64 {
var sum float64
for i := range a.reduction {
fVal := a.reduction[i].Elem().FieldByName(field)
if !fVal.IsValid() {
panic(fmt.Sprintf("The field %s does not exist in the type %s", field, a.reduction[i].Type()))
}
sum += tryFloat(fVal)
}
return sum
} | [
"func",
"(",
"a",
"*",
"AggregateResult",
")",
"Sum",
"(",
"field",
"string",
")",
"float64",
"{",
"var",
"sum",
"float64",
"\n\n",
"for",
"i",
":=",
"range",
"a",
".",
"reduction",
"{",
"fVal",
":=",
"a",
".",
"reduction",
"[",
"i",
"]",
".",
"Elem",
"(",
")",
".",
"FieldByName",
"(",
"field",
")",
"\n",
"if",
"!",
"fVal",
".",
"IsValid",
"(",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
",",
"a",
".",
"reduction",
"[",
"i",
"]",
".",
"Type",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"sum",
"+=",
"tryFloat",
"(",
"fVal",
")",
"\n",
"}",
"\n\n",
"return",
"sum",
"\n",
"}"
] | // Sum returns the sum value of the aggregate grouping
// panics if the field cannot be converted to an float64 | [
"Sum",
"returns",
"the",
"sum",
"value",
"of",
"the",
"aggregate",
"grouping",
"panics",
"if",
"the",
"field",
"cannot",
"be",
"converted",
"to",
"an",
"float64"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/aggregate.go#L143-L156 |
147 | timshannon/bolthold | aggregate.go | FindAggregate | func (s *Store) FindAggregate(dataType interface{}, query *Query, groupBy ...string) ([]*AggregateResult, error) {
var result []*AggregateResult
var err error
err = s.Bolt().View(func(tx *bolt.Tx) error {
result, err = s.TxFindAggregate(tx, dataType, query, groupBy...)
return err
})
if err != nil {
return nil, err
}
return result, nil
} | go | func (s *Store) FindAggregate(dataType interface{}, query *Query, groupBy ...string) ([]*AggregateResult, error) {
var result []*AggregateResult
var err error
err = s.Bolt().View(func(tx *bolt.Tx) error {
result, err = s.TxFindAggregate(tx, dataType, query, groupBy...)
return err
})
if err != nil {
return nil, err
}
return result, nil
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"FindAggregate",
"(",
"dataType",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
",",
"groupBy",
"...",
"string",
")",
"(",
"[",
"]",
"*",
"AggregateResult",
",",
"error",
")",
"{",
"var",
"result",
"[",
"]",
"*",
"AggregateResult",
"\n",
"var",
"err",
"error",
"\n",
"err",
"=",
"s",
".",
"Bolt",
"(",
")",
".",
"View",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"result",
",",
"err",
"=",
"s",
".",
"TxFindAggregate",
"(",
"tx",
",",
"dataType",
",",
"query",
",",
"groupBy",
"...",
")",
"\n",
"return",
"err",
"\n",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // FindAggregate returns an aggregate grouping for the passed in query
// groupBy is optional | [
"FindAggregate",
"returns",
"an",
"aggregate",
"grouping",
"for",
"the",
"passed",
"in",
"query",
"groupBy",
"is",
"optional"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/aggregate.go#L165-L178 |
148 | timshannon/bolthold | aggregate.go | TxFindAggregate | func (s *Store) TxFindAggregate(tx *bolt.Tx, dataType interface{}, query *Query, groupBy ...string) ([]*AggregateResult, error) {
return aggregateQuery(tx, dataType, query, groupBy...)
} | go | func (s *Store) TxFindAggregate(tx *bolt.Tx, dataType interface{}, query *Query, groupBy ...string) ([]*AggregateResult, error) {
return aggregateQuery(tx, dataType, query, groupBy...)
} | [
"func",
"(",
"s",
"*",
"Store",
")",
"TxFindAggregate",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
",",
"dataType",
"interface",
"{",
"}",
",",
"query",
"*",
"Query",
",",
"groupBy",
"...",
"string",
")",
"(",
"[",
"]",
"*",
"AggregateResult",
",",
"error",
")",
"{",
"return",
"aggregateQuery",
"(",
"tx",
",",
"dataType",
",",
"query",
",",
"groupBy",
"...",
")",
"\n",
"}"
] | // TxFindAggregate is the same as FindAggregate, but you specify your own transaction
// groupBy is optional | [
"TxFindAggregate",
"is",
"the",
"same",
"as",
"FindAggregate",
"but",
"you",
"specify",
"your",
"own",
"transaction",
"groupBy",
"is",
"optional"
] | eed35b7556710c9108bd536193dae1ecb91f16fa | https://github.com/timshannon/bolthold/blob/eed35b7556710c9108bd536193dae1ecb91f16fa/aggregate.go#L182-L184 |
149 | tkanos/gonfig | gonfig.go | GetConf | func GetConf(filename string, configuration interface{}) (err error) {
configValue := reflect.ValueOf(configuration)
if typ := configValue.Type(); typ.Kind() != reflect.Ptr || typ.Elem().Kind() != reflect.Struct {
return fmt.Errorf("configuration should be a pointer to a struct type")
}
err = getFromYAML(filename, configuration)
if err == nil {
getFromEnvVariables(configuration)
}
return
} | go | func GetConf(filename string, configuration interface{}) (err error) {
configValue := reflect.ValueOf(configuration)
if typ := configValue.Type(); typ.Kind() != reflect.Ptr || typ.Elem().Kind() != reflect.Struct {
return fmt.Errorf("configuration should be a pointer to a struct type")
}
err = getFromYAML(filename, configuration)
if err == nil {
getFromEnvVariables(configuration)
}
return
} | [
"func",
"GetConf",
"(",
"filename",
"string",
",",
"configuration",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"configValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"configuration",
")",
"\n",
"if",
"typ",
":=",
"configValue",
".",
"Type",
"(",
")",
";",
"typ",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"||",
"typ",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Struct",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"getFromYAML",
"(",
"filename",
",",
"configuration",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"getFromEnvVariables",
"(",
"configuration",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // GetConf aggregates all the JSON and enviornment variable values
// and puts them into the passed interface. | [
"GetConf",
"aggregates",
"all",
"the",
"JSON",
"and",
"enviornment",
"variable",
"values",
"and",
"puts",
"them",
"into",
"the",
"passed",
"interface",
"."
] | 896f3d81fadfe082262467a1c22fd43278806a02 | https://github.com/tkanos/gonfig/blob/896f3d81fadfe082262467a1c22fd43278806a02/gonfig.go#L21-L34 |
150 | appc/spec | schema/types/semver.go | NewSemVer | func NewSemVer(s string) (*SemVer, error) {
nsv, err := semver.NewVersion(s)
if err != nil {
return nil, ErrBadSemVer
}
v := SemVer(*nsv)
if v.Empty() {
return nil, ErrNoZeroSemVer
}
return &v, nil
} | go | func NewSemVer(s string) (*SemVer, error) {
nsv, err := semver.NewVersion(s)
if err != nil {
return nil, ErrBadSemVer
}
v := SemVer(*nsv)
if v.Empty() {
return nil, ErrNoZeroSemVer
}
return &v, nil
} | [
"func",
"NewSemVer",
"(",
"s",
"string",
")",
"(",
"*",
"SemVer",
",",
"error",
")",
"{",
"nsv",
",",
"err",
":=",
"semver",
".",
"NewVersion",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"ErrBadSemVer",
"\n",
"}",
"\n",
"v",
":=",
"SemVer",
"(",
"*",
"nsv",
")",
"\n",
"if",
"v",
".",
"Empty",
"(",
")",
"{",
"return",
"nil",
",",
"ErrNoZeroSemVer",
"\n",
"}",
"\n",
"return",
"&",
"v",
",",
"nil",
"\n",
"}"
] | // NewSemVer generates a new SemVer from a string. If the given string does
// not represent a valid SemVer, nil and an error are returned. | [
"NewSemVer",
"generates",
"a",
"new",
"SemVer",
"from",
"a",
"string",
".",
"If",
"the",
"given",
"string",
"does",
"not",
"represent",
"a",
"valid",
"SemVer",
"nil",
"and",
"an",
"error",
"are",
"returned",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/semver.go#L35-L45 |
151 | appc/spec | actool/manifest.go | parseSeccompArgs | func parseSeccompArgs(patchSeccompMode string, patchSeccompSet string) (*types.Isolator, error) {
// Parse mode flag and additional keyed arguments.
var errno, mode string
args := strings.Split(patchSeccompMode, ",")
for _, a := range args {
kv := strings.Split(a, "=")
switch len(kv) {
case 1:
// mode, either "remove" or "retain"
mode = kv[0]
case 2:
// k=v argument, only "errno" allowed for now
if kv[0] == "errno" {
errno = kv[1]
} else {
return nil, fmt.Errorf("invalid seccomp-mode optional argument: %s", a)
}
default:
return nil, fmt.Errorf("cannot parse seccomp-mode argument: %s", a)
}
}
// Instantiate an Isolator with the content specified by the --seccomp-set parameter.
var err error
var seccomp types.AsIsolator
switch mode {
case "remove":
seccomp, err = types.NewLinuxSeccompRemoveSet(errno, strings.Split(patchSeccompSet, ",")...)
case "retain":
seccomp, err = types.NewLinuxSeccompRetainSet(errno, strings.Split(patchSeccompSet, ",")...)
default:
err = fmt.Errorf("unknown seccomp mode %s", mode)
}
if err != nil {
return nil, fmt.Errorf("cannot parse seccomp isolator: %s", err)
}
seccompIsolator, err := seccomp.AsIsolator()
if err != nil {
return nil, err
}
return seccompIsolator, nil
} | go | func parseSeccompArgs(patchSeccompMode string, patchSeccompSet string) (*types.Isolator, error) {
// Parse mode flag and additional keyed arguments.
var errno, mode string
args := strings.Split(patchSeccompMode, ",")
for _, a := range args {
kv := strings.Split(a, "=")
switch len(kv) {
case 1:
// mode, either "remove" or "retain"
mode = kv[0]
case 2:
// k=v argument, only "errno" allowed for now
if kv[0] == "errno" {
errno = kv[1]
} else {
return nil, fmt.Errorf("invalid seccomp-mode optional argument: %s", a)
}
default:
return nil, fmt.Errorf("cannot parse seccomp-mode argument: %s", a)
}
}
// Instantiate an Isolator with the content specified by the --seccomp-set parameter.
var err error
var seccomp types.AsIsolator
switch mode {
case "remove":
seccomp, err = types.NewLinuxSeccompRemoveSet(errno, strings.Split(patchSeccompSet, ",")...)
case "retain":
seccomp, err = types.NewLinuxSeccompRetainSet(errno, strings.Split(patchSeccompSet, ",")...)
default:
err = fmt.Errorf("unknown seccomp mode %s", mode)
}
if err != nil {
return nil, fmt.Errorf("cannot parse seccomp isolator: %s", err)
}
seccompIsolator, err := seccomp.AsIsolator()
if err != nil {
return nil, err
}
return seccompIsolator, nil
} | [
"func",
"parseSeccompArgs",
"(",
"patchSeccompMode",
"string",
",",
"patchSeccompSet",
"string",
")",
"(",
"*",
"types",
".",
"Isolator",
",",
"error",
")",
"{",
"// Parse mode flag and additional keyed arguments.",
"var",
"errno",
",",
"mode",
"string",
"\n",
"args",
":=",
"strings",
".",
"Split",
"(",
"patchSeccompMode",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"a",
":=",
"range",
"args",
"{",
"kv",
":=",
"strings",
".",
"Split",
"(",
"a",
",",
"\"",
"\"",
")",
"\n",
"switch",
"len",
"(",
"kv",
")",
"{",
"case",
"1",
":",
"// mode, either \"remove\" or \"retain\"",
"mode",
"=",
"kv",
"[",
"0",
"]",
"\n",
"case",
"2",
":",
"// k=v argument, only \"errno\" allowed for now",
"if",
"kv",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"errno",
"=",
"kv",
"[",
"1",
"]",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"a",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"a",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Instantiate an Isolator with the content specified by the --seccomp-set parameter.",
"var",
"err",
"error",
"\n",
"var",
"seccomp",
"types",
".",
"AsIsolator",
"\n",
"switch",
"mode",
"{",
"case",
"\"",
"\"",
":",
"seccomp",
",",
"err",
"=",
"types",
".",
"NewLinuxSeccompRemoveSet",
"(",
"errno",
",",
"strings",
".",
"Split",
"(",
"patchSeccompSet",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"case",
"\"",
"\"",
":",
"seccomp",
",",
"err",
"=",
"types",
".",
"NewLinuxSeccompRetainSet",
"(",
"errno",
",",
"strings",
".",
"Split",
"(",
"patchSeccompSet",
",",
"\"",
"\"",
")",
"...",
")",
"\n",
"default",
":",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"mode",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"seccompIsolator",
",",
"err",
":=",
"seccomp",
".",
"AsIsolator",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"seccompIsolator",
",",
"nil",
"\n",
"}"
] | // parseSeccompArgs parses seccomp mode and set CLI flags, preparing an
// appropriate seccomp isolator. | [
"parseSeccompArgs",
"parses",
"seccomp",
"mode",
"and",
"set",
"CLI",
"flags",
"preparing",
"an",
"appropriate",
"seccomp",
"isolator",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/actool/manifest.go#L309-L350 |
152 | appc/spec | actool/manifest.go | extractManifest | func extractManifest(tr *tar.Reader, tw *tar.Writer, printManifest bool, newManifest []byte) error {
Tar:
for {
hdr, err := tr.Next()
switch err {
case io.EOF:
break Tar
case nil:
if filepath.Clean(hdr.Name) == aci.ManifestFile {
var new_bytes []byte
bytes, err := ioutil.ReadAll(tr)
if err != nil {
return err
}
if printManifest && !catPrettyPrint {
fmt.Println(string(bytes))
}
im := &schema.ImageManifest{}
err = im.UnmarshalJSON(bytes)
if err != nil {
return err
}
if printManifest && catPrettyPrint {
output, err := json.MarshalIndent(im, "", " ")
if err != nil {
return err
}
fmt.Println(string(output))
}
if tw == nil {
return nil
}
if len(newManifest) == 0 {
err = patchManifest(im)
if err != nil {
return err
}
new_bytes, err = im.MarshalJSON()
if err != nil {
return err
}
} else {
new_bytes = newManifest
}
hdr.Size = int64(len(new_bytes))
err = tw.WriteHeader(hdr)
if err != nil {
return err
}
_, err = tw.Write(new_bytes)
if err != nil {
return err
}
} else if tw != nil {
err := tw.WriteHeader(hdr)
if err != nil {
return err
}
_, err = io.Copy(tw, tr)
if err != nil {
return err
}
}
default:
return fmt.Errorf("error reading tarball: %v", err)
}
}
return nil
} | go | func extractManifest(tr *tar.Reader, tw *tar.Writer, printManifest bool, newManifest []byte) error {
Tar:
for {
hdr, err := tr.Next()
switch err {
case io.EOF:
break Tar
case nil:
if filepath.Clean(hdr.Name) == aci.ManifestFile {
var new_bytes []byte
bytes, err := ioutil.ReadAll(tr)
if err != nil {
return err
}
if printManifest && !catPrettyPrint {
fmt.Println(string(bytes))
}
im := &schema.ImageManifest{}
err = im.UnmarshalJSON(bytes)
if err != nil {
return err
}
if printManifest && catPrettyPrint {
output, err := json.MarshalIndent(im, "", " ")
if err != nil {
return err
}
fmt.Println(string(output))
}
if tw == nil {
return nil
}
if len(newManifest) == 0 {
err = patchManifest(im)
if err != nil {
return err
}
new_bytes, err = im.MarshalJSON()
if err != nil {
return err
}
} else {
new_bytes = newManifest
}
hdr.Size = int64(len(new_bytes))
err = tw.WriteHeader(hdr)
if err != nil {
return err
}
_, err = tw.Write(new_bytes)
if err != nil {
return err
}
} else if tw != nil {
err := tw.WriteHeader(hdr)
if err != nil {
return err
}
_, err = io.Copy(tw, tr)
if err != nil {
return err
}
}
default:
return fmt.Errorf("error reading tarball: %v", err)
}
}
return nil
} | [
"func",
"extractManifest",
"(",
"tr",
"*",
"tar",
".",
"Reader",
",",
"tw",
"*",
"tar",
".",
"Writer",
",",
"printManifest",
"bool",
",",
"newManifest",
"[",
"]",
"byte",
")",
"error",
"{",
"Tar",
":",
"for",
"{",
"hdr",
",",
"err",
":=",
"tr",
".",
"Next",
"(",
")",
"\n",
"switch",
"err",
"{",
"case",
"io",
".",
"EOF",
":",
"break",
"Tar",
"\n",
"case",
"nil",
":",
"if",
"filepath",
".",
"Clean",
"(",
"hdr",
".",
"Name",
")",
"==",
"aci",
".",
"ManifestFile",
"{",
"var",
"new_bytes",
"[",
"]",
"byte",
"\n\n",
"bytes",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"tr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"printManifest",
"&&",
"!",
"catPrettyPrint",
"{",
"fmt",
".",
"Println",
"(",
"string",
"(",
"bytes",
")",
")",
"\n",
"}",
"\n\n",
"im",
":=",
"&",
"schema",
".",
"ImageManifest",
"{",
"}",
"\n",
"err",
"=",
"im",
".",
"UnmarshalJSON",
"(",
"bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"printManifest",
"&&",
"catPrettyPrint",
"{",
"output",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"im",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"string",
"(",
"output",
")",
")",
"\n",
"}",
"\n\n",
"if",
"tw",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"newManifest",
")",
"==",
"0",
"{",
"err",
"=",
"patchManifest",
"(",
"im",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"new_bytes",
",",
"err",
"=",
"im",
".",
"MarshalJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"new_bytes",
"=",
"newManifest",
"\n",
"}",
"\n\n",
"hdr",
".",
"Size",
"=",
"int64",
"(",
"len",
"(",
"new_bytes",
")",
")",
"\n",
"err",
"=",
"tw",
".",
"WriteHeader",
"(",
"hdr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"tw",
".",
"Write",
"(",
"new_bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"tw",
"!=",
"nil",
"{",
"err",
":=",
"tw",
".",
"WriteHeader",
"(",
"hdr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"tw",
",",
"tr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // extractManifest iterates over the tar reader and locate the manifest. Once
// located, the manifest can be printed, replaced or patched. | [
"extractManifest",
"iterates",
"over",
"the",
"tar",
"reader",
"and",
"locate",
"the",
"manifest",
".",
"Once",
"located",
"the",
"manifest",
"can",
"be",
"printed",
"replaced",
"or",
"patched",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/actool/manifest.go#L354-L432 |
153 | appc/spec | ace/validator.go | main | func main() {
if len(os.Args) != 2 {
stderr("usage: %s [main|sidekick|preStart|postStop]", os.Args[0])
os.Exit(64)
}
mode := os.Args[1]
var res results
switch strings.ToLower(mode) {
case "main":
res = validateMain()
case "sidekick":
res = validateSidekick()
case "prestart":
res = validatePrestart()
case "poststop":
res = validatePoststop()
default:
stderr("unrecognized mode: %s", mode)
os.Exit(64)
}
if len(res) == 0 {
fmt.Printf("%s OK\n", mode)
os.Exit(0)
}
fmt.Printf("%s FAIL\n", mode)
for _, err := range res {
fmt.Fprintln(os.Stderr, "==>", err)
}
os.Exit(1)
} | go | func main() {
if len(os.Args) != 2 {
stderr("usage: %s [main|sidekick|preStart|postStop]", os.Args[0])
os.Exit(64)
}
mode := os.Args[1]
var res results
switch strings.ToLower(mode) {
case "main":
res = validateMain()
case "sidekick":
res = validateSidekick()
case "prestart":
res = validatePrestart()
case "poststop":
res = validatePoststop()
default:
stderr("unrecognized mode: %s", mode)
os.Exit(64)
}
if len(res) == 0 {
fmt.Printf("%s OK\n", mode)
os.Exit(0)
}
fmt.Printf("%s FAIL\n", mode)
for _, err := range res {
fmt.Fprintln(os.Stderr, "==>", err)
}
os.Exit(1)
} | [
"func",
"main",
"(",
")",
"{",
"if",
"len",
"(",
"os",
".",
"Args",
")",
"!=",
"2",
"{",
"stderr",
"(",
"\"",
"\"",
",",
"os",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"os",
".",
"Exit",
"(",
"64",
")",
"\n",
"}",
"\n",
"mode",
":=",
"os",
".",
"Args",
"[",
"1",
"]",
"\n",
"var",
"res",
"results",
"\n",
"switch",
"strings",
".",
"ToLower",
"(",
"mode",
")",
"{",
"case",
"\"",
"\"",
":",
"res",
"=",
"validateMain",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"res",
"=",
"validateSidekick",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"res",
"=",
"validatePrestart",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"res",
"=",
"validatePoststop",
"(",
")",
"\n",
"default",
":",
"stderr",
"(",
"\"",
"\"",
",",
"mode",
")",
"\n",
"os",
".",
"Exit",
"(",
"64",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"res",
")",
"==",
"0",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"mode",
")",
"\n",
"os",
".",
"Exit",
"(",
"0",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"mode",
")",
"\n",
"for",
"_",
",",
"err",
":=",
"range",
"res",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}"
] | // main outputs diagnostic information to stderr and exits 1 if validation fails | [
"main",
"outputs",
"diagnostic",
"information",
"to",
"stderr",
"and",
"exits",
"1",
"if",
"validation",
"fails"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L96-L125 |
154 | appc/spec | ace/validator.go | ValidatePath | func ValidatePath(wp string) results {
r := results{}
gp := os.Getenv("PATH")
if wp != gp {
r = append(r, fmt.Errorf("PATH not set appropriately (need %q, got %q)", wp, gp))
}
return r
} | go | func ValidatePath(wp string) results {
r := results{}
gp := os.Getenv("PATH")
if wp != gp {
r = append(r, fmt.Errorf("PATH not set appropriately (need %q, got %q)", wp, gp))
}
return r
} | [
"func",
"ValidatePath",
"(",
"wp",
"string",
")",
"results",
"{",
"r",
":=",
"results",
"{",
"}",
"\n",
"gp",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
"\n",
"if",
"wp",
"!=",
"gp",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"wp",
",",
"gp",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // ValidatePath ensures that the PATH has been set up correctly within the
// environment in which this process is being run | [
"ValidatePath",
"ensures",
"that",
"the",
"PATH",
"has",
"been",
"set",
"up",
"correctly",
"within",
"the",
"environment",
"in",
"which",
"this",
"process",
"is",
"being",
"run"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L164-L171 |
155 | appc/spec | ace/validator.go | ValidateWorkingDirectory | func ValidateWorkingDirectory(wwd string) (r results) {
gwd, err := os.Getwd()
if err != nil {
r = append(r, fmt.Errorf("error getting working directory: %v", err))
return
}
if gwd != wwd {
r = append(r, fmt.Errorf("working directory not set appropriately (need %q, got %v)", wwd, gwd))
}
return
} | go | func ValidateWorkingDirectory(wwd string) (r results) {
gwd, err := os.Getwd()
if err != nil {
r = append(r, fmt.Errorf("error getting working directory: %v", err))
return
}
if gwd != wwd {
r = append(r, fmt.Errorf("working directory not set appropriately (need %q, got %v)", wwd, gwd))
}
return
} | [
"func",
"ValidateWorkingDirectory",
"(",
"wwd",
"string",
")",
"(",
"r",
"results",
")",
"{",
"gwd",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"gwd",
"!=",
"wwd",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"wwd",
",",
"gwd",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ValidateWorkingDirectory ensures that the process working directory is set
// to the desired path. | [
"ValidateWorkingDirectory",
"ensures",
"that",
"the",
"process",
"working",
"directory",
"is",
"set",
"to",
"the",
"desired",
"path",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L175-L185 |
156 | appc/spec | ace/validator.go | ValidateAppNameEnv | func ValidateAppNameEnv(want string) (r results) {
if got := os.Getenv(appNameEnv); got != want {
r = append(r, fmt.Errorf("%s not set appropriately (need %q, got %q)", appNameEnv, want, got))
}
return
} | go | func ValidateAppNameEnv(want string) (r results) {
if got := os.Getenv(appNameEnv); got != want {
r = append(r, fmt.Errorf("%s not set appropriately (need %q, got %q)", appNameEnv, want, got))
}
return
} | [
"func",
"ValidateAppNameEnv",
"(",
"want",
"string",
")",
"(",
"r",
"results",
")",
"{",
"if",
"got",
":=",
"os",
".",
"Getenv",
"(",
"appNameEnv",
")",
";",
"got",
"!=",
"want",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"appNameEnv",
",",
"want",
",",
"got",
")",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ValidateAppNameEnv ensures that the environment variable specifying the
// entrypoint of this process is set correctly. | [
"ValidateAppNameEnv",
"ensures",
"that",
"the",
"environment",
"variable",
"specifying",
"the",
"entrypoint",
"of",
"this",
"process",
"is",
"set",
"correctly",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L202-L207 |
157 | appc/spec | ace/validator.go | ValidateMountpoints | func ValidateMountpoints(wmp map[string]types.MountPoint) results {
r := results{}
// TODO(jonboulle): verify actual source
for _, mp := range wmp {
if err := checkMount(mp.Path, mp.ReadOnly); err != nil {
r = append(r, err)
}
}
return r
} | go | func ValidateMountpoints(wmp map[string]types.MountPoint) results {
r := results{}
// TODO(jonboulle): verify actual source
for _, mp := range wmp {
if err := checkMount(mp.Path, mp.ReadOnly); err != nil {
r = append(r, err)
}
}
return r
} | [
"func",
"ValidateMountpoints",
"(",
"wmp",
"map",
"[",
"string",
"]",
"types",
".",
"MountPoint",
")",
"results",
"{",
"r",
":=",
"results",
"{",
"}",
"\n",
"// TODO(jonboulle): verify actual source",
"for",
"_",
",",
"mp",
":=",
"range",
"wmp",
"{",
"if",
"err",
":=",
"checkMount",
"(",
"mp",
".",
"Path",
",",
"mp",
".",
"ReadOnly",
")",
";",
"err",
"!=",
"nil",
"{",
"r",
"=",
"append",
"(",
"r",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // ValidateMountpoints ensures that the given mount points are present in the
// environment in which this process is running | [
"ValidateMountpoints",
"ensures",
"that",
"the",
"given",
"mount",
"points",
"are",
"present",
"in",
"the",
"environment",
"in",
"which",
"this",
"process",
"is",
"running"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L211-L220 |
158 | appc/spec | ace/validator.go | assertNotExists | func assertNotExists(p string) []error {
var errs []error
e, err := fileExists(p)
if err != nil {
errs = append(errs, fmt.Errorf("error checking %q exists: %v", p, err))
}
if e {
errs = append(errs, fmt.Errorf("file %q exists unexpectedly", p))
}
return errs
} | go | func assertNotExists(p string) []error {
var errs []error
e, err := fileExists(p)
if err != nil {
errs = append(errs, fmt.Errorf("error checking %q exists: %v", p, err))
}
if e {
errs = append(errs, fmt.Errorf("file %q exists unexpectedly", p))
}
return errs
} | [
"func",
"assertNotExists",
"(",
"p",
"string",
")",
"[",
"]",
"error",
"{",
"var",
"errs",
"[",
"]",
"error",
"\n",
"e",
",",
"err",
":=",
"fileExists",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"if",
"e",
"{",
"errs",
"=",
"append",
"(",
"errs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
")",
")",
"\n",
"}",
"\n",
"return",
"errs",
"\n",
"}"
] | // assertNotExists asserts that a file at the given path does not exist. A
// non-empty list of errors is returned if the file exists or any error is
// encountered while checking. | [
"assertNotExists",
"asserts",
"that",
"a",
"file",
"at",
"the",
"given",
"path",
"does",
"not",
"exist",
".",
"A",
"non",
"-",
"empty",
"list",
"of",
"errors",
"is",
"returned",
"if",
"the",
"file",
"exists",
"or",
"any",
"error",
"is",
"encountered",
"while",
"checking",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L502-L512 |
159 | appc/spec | ace/validator.go | touchFile | func touchFile(p string) error {
_, err := os.Create(p)
return err
} | go | func touchFile(p string) error {
_, err := os.Create(p)
return err
} | [
"func",
"touchFile",
"(",
"p",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"p",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // touchFile creates an empty file, returning any error encountered | [
"touchFile",
"creates",
"an",
"empty",
"file",
"returning",
"any",
"error",
"encountered"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L530-L533 |
160 | appc/spec | ace/validator.go | waitForFile | func waitForFile(p string, to time.Duration) []error {
done := time.After(to)
for {
select {
case <-done:
return []error{
fmt.Errorf("timed out waiting for %s", p),
}
case <-time.After(1):
if ok, _ := fileExists(p); ok {
return nil
}
}
}
} | go | func waitForFile(p string, to time.Duration) []error {
done := time.After(to)
for {
select {
case <-done:
return []error{
fmt.Errorf("timed out waiting for %s", p),
}
case <-time.After(1):
if ok, _ := fileExists(p); ok {
return nil
}
}
}
} | [
"func",
"waitForFile",
"(",
"p",
"string",
",",
"to",
"time",
".",
"Duration",
")",
"[",
"]",
"error",
"{",
"done",
":=",
"time",
".",
"After",
"(",
"to",
")",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"done",
":",
"return",
"[",
"]",
"error",
"{",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
")",
",",
"}",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"1",
")",
":",
"if",
"ok",
",",
"_",
":=",
"fileExists",
"(",
"p",
")",
";",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // waitForFile waits for the file at the given path to appear | [
"waitForFile",
"waits",
"for",
"the",
"file",
"at",
"the",
"given",
"path",
"to",
"appear"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/ace/validator.go#L548-L562 |
161 | appc/spec | discovery/parse.go | String | func (a *App) String() string {
img := a.Name.String()
for n, v := range a.Labels {
img += fmt.Sprintf(",%s=%s", n, v)
}
return img
} | go | func (a *App) String() string {
img := a.Name.String()
for n, v := range a.Labels {
img += fmt.Sprintf(",%s=%s", n, v)
}
return img
} | [
"func",
"(",
"a",
"*",
"App",
")",
"String",
"(",
")",
"string",
"{",
"img",
":=",
"a",
".",
"Name",
".",
"String",
"(",
")",
"\n",
"for",
"n",
",",
"v",
":=",
"range",
"a",
".",
"Labels",
"{",
"img",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"n",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"img",
"\n",
"}"
] | // String returns the URL-like image name | [
"String",
"returns",
"the",
"URL",
"-",
"like",
"image",
"name"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/discovery/parse.go#L124-L130 |
162 | appc/spec | pkg/acirenderer/acirenderer.go | GetRenderedACIWithImageID | func GetRenderedACIWithImageID(imageID types.Hash, ap ACIRegistry) (RenderedACI, error) {
imgs, err := CreateDepListFromImageID(imageID, ap)
if err != nil {
return nil, err
}
return GetRenderedACIFromList(imgs, ap)
} | go | func GetRenderedACIWithImageID(imageID types.Hash, ap ACIRegistry) (RenderedACI, error) {
imgs, err := CreateDepListFromImageID(imageID, ap)
if err != nil {
return nil, err
}
return GetRenderedACIFromList(imgs, ap)
} | [
"func",
"GetRenderedACIWithImageID",
"(",
"imageID",
"types",
".",
"Hash",
",",
"ap",
"ACIRegistry",
")",
"(",
"RenderedACI",
",",
"error",
")",
"{",
"imgs",
",",
"err",
":=",
"CreateDepListFromImageID",
"(",
"imageID",
",",
"ap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"GetRenderedACIFromList",
"(",
"imgs",
",",
"ap",
")",
"\n",
"}"
] | // GetRenderedACIWithImageID, given an imageID, starts with the matching image
// available in the store, creates the dependencies list and returns the
// RenderedACI list. | [
"GetRenderedACIWithImageID",
"given",
"an",
"imageID",
"starts",
"with",
"the",
"matching",
"image",
"available",
"in",
"the",
"store",
"creates",
"the",
"dependencies",
"list",
"and",
"returns",
"the",
"RenderedACI",
"list",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/pkg/acirenderer/acirenderer.go#L81-L87 |
163 | appc/spec | pkg/acirenderer/acirenderer.go | GetRenderedACI | func GetRenderedACI(name types.ACIdentifier, labels types.Labels, ap ACIRegistry) (RenderedACI, error) {
imgs, err := CreateDepListFromNameLabels(name, labels, ap)
if err != nil {
return nil, err
}
return GetRenderedACIFromList(imgs, ap)
} | go | func GetRenderedACI(name types.ACIdentifier, labels types.Labels, ap ACIRegistry) (RenderedACI, error) {
imgs, err := CreateDepListFromNameLabels(name, labels, ap)
if err != nil {
return nil, err
}
return GetRenderedACIFromList(imgs, ap)
} | [
"func",
"GetRenderedACI",
"(",
"name",
"types",
".",
"ACIdentifier",
",",
"labels",
"types",
".",
"Labels",
",",
"ap",
"ACIRegistry",
")",
"(",
"RenderedACI",
",",
"error",
")",
"{",
"imgs",
",",
"err",
":=",
"CreateDepListFromNameLabels",
"(",
"name",
",",
"labels",
",",
"ap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"GetRenderedACIFromList",
"(",
"imgs",
",",
"ap",
")",
"\n",
"}"
] | // GetRenderedACI, given an image app name and optional labels, starts with the
// best matching image available in the store, creates the dependencies list
// and returns the RenderedACI list. | [
"GetRenderedACI",
"given",
"an",
"image",
"app",
"name",
"and",
"optional",
"labels",
"starts",
"with",
"the",
"best",
"matching",
"image",
"available",
"in",
"the",
"store",
"creates",
"the",
"dependencies",
"list",
"and",
"returns",
"the",
"RenderedACI",
"list",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/pkg/acirenderer/acirenderer.go#L92-L98 |
164 | appc/spec | schema/types/annotations.go | Get | func (a Annotations) Get(name string) (val string, ok bool) {
for _, anno := range a {
if anno.Name.String() == name {
return anno.Value, true
}
}
return "", false
} | go | func (a Annotations) Get(name string) (val string, ok bool) {
for _, anno := range a {
if anno.Name.String() == name {
return anno.Value, true
}
}
return "", false
} | [
"func",
"(",
"a",
"Annotations",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"val",
"string",
",",
"ok",
"bool",
")",
"{",
"for",
"_",
",",
"anno",
":=",
"range",
"a",
"{",
"if",
"anno",
".",
"Name",
".",
"String",
"(",
")",
"==",
"name",
"{",
"return",
"anno",
".",
"Value",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] | // Retrieve the value of an annotation by the given name from Annotations, if
// it exists. | [
"Retrieve",
"the",
"value",
"of",
"an",
"annotation",
"by",
"the",
"given",
"name",
"from",
"Annotations",
"if",
"it",
"exists",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/annotations.go#L81-L88 |
165 | appc/spec | schema/types/annotations.go | Set | func (a *Annotations) Set(name ACIdentifier, value string) {
for i, anno := range *a {
if anno.Name.Equals(name) {
(*a)[i] = Annotation{
Name: name,
Value: value,
}
return
}
}
anno := Annotation{
Name: name,
Value: value,
}
*a = append(*a, anno)
} | go | func (a *Annotations) Set(name ACIdentifier, value string) {
for i, anno := range *a {
if anno.Name.Equals(name) {
(*a)[i] = Annotation{
Name: name,
Value: value,
}
return
}
}
anno := Annotation{
Name: name,
Value: value,
}
*a = append(*a, anno)
} | [
"func",
"(",
"a",
"*",
"Annotations",
")",
"Set",
"(",
"name",
"ACIdentifier",
",",
"value",
"string",
")",
"{",
"for",
"i",
",",
"anno",
":=",
"range",
"*",
"a",
"{",
"if",
"anno",
".",
"Name",
".",
"Equals",
"(",
"name",
")",
"{",
"(",
"*",
"a",
")",
"[",
"i",
"]",
"=",
"Annotation",
"{",
"Name",
":",
"name",
",",
"Value",
":",
"value",
",",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"anno",
":=",
"Annotation",
"{",
"Name",
":",
"name",
",",
"Value",
":",
"value",
",",
"}",
"\n",
"*",
"a",
"=",
"append",
"(",
"*",
"a",
",",
"anno",
")",
"\n",
"}"
] | // Set sets the value of an annotation by the given name, overwriting if one already exists. | [
"Set",
"sets",
"the",
"value",
"of",
"an",
"annotation",
"by",
"the",
"given",
"name",
"overwriting",
"if",
"one",
"already",
"exists",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/annotations.go#L91-L106 |
166 | appc/spec | aci/file.go | ManifestFromImage | func ManifestFromImage(rs io.ReadSeeker) (*schema.ImageManifest, error) {
var im schema.ImageManifest
tr, err := NewCompressedTarReader(rs)
if err != nil {
return nil, err
}
defer tr.Close()
for {
hdr, err := tr.Next()
switch err {
case io.EOF:
return nil, errors.New("missing manifest")
case nil:
if filepath.Clean(hdr.Name) == ManifestFile {
data, err := ioutil.ReadAll(tr)
if err != nil {
return nil, err
}
if err := im.UnmarshalJSON(data); err != nil {
return nil, err
}
return &im, nil
}
default:
return nil, fmt.Errorf("error extracting tarball: %v", err)
}
}
} | go | func ManifestFromImage(rs io.ReadSeeker) (*schema.ImageManifest, error) {
var im schema.ImageManifest
tr, err := NewCompressedTarReader(rs)
if err != nil {
return nil, err
}
defer tr.Close()
for {
hdr, err := tr.Next()
switch err {
case io.EOF:
return nil, errors.New("missing manifest")
case nil:
if filepath.Clean(hdr.Name) == ManifestFile {
data, err := ioutil.ReadAll(tr)
if err != nil {
return nil, err
}
if err := im.UnmarshalJSON(data); err != nil {
return nil, err
}
return &im, nil
}
default:
return nil, fmt.Errorf("error extracting tarball: %v", err)
}
}
} | [
"func",
"ManifestFromImage",
"(",
"rs",
"io",
".",
"ReadSeeker",
")",
"(",
"*",
"schema",
".",
"ImageManifest",
",",
"error",
")",
"{",
"var",
"im",
"schema",
".",
"ImageManifest",
"\n\n",
"tr",
",",
"err",
":=",
"NewCompressedTarReader",
"(",
"rs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"tr",
".",
"Close",
"(",
")",
"\n\n",
"for",
"{",
"hdr",
",",
"err",
":=",
"tr",
".",
"Next",
"(",
")",
"\n",
"switch",
"err",
"{",
"case",
"io",
".",
"EOF",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"nil",
":",
"if",
"filepath",
".",
"Clean",
"(",
"hdr",
".",
"Name",
")",
"==",
"ManifestFile",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"tr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"im",
".",
"UnmarshalJSON",
"(",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"im",
",",
"nil",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ManifestFromImage extracts a new schema.ImageManifest from the given ACI image. | [
"ManifestFromImage",
"extracts",
"a",
"new",
"schema",
".",
"ImageManifest",
"from",
"the",
"given",
"ACI",
"image",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/aci/file.go#L146-L175 |
167 | appc/spec | aci/file.go | NewCompressedTarReader | func NewCompressedTarReader(rs io.ReadSeeker) (*TarReadCloser, error) {
cr, err := NewCompressedReader(rs)
if err != nil {
return nil, err
}
return &TarReadCloser{tar.NewReader(cr), cr}, nil
} | go | func NewCompressedTarReader(rs io.ReadSeeker) (*TarReadCloser, error) {
cr, err := NewCompressedReader(rs)
if err != nil {
return nil, err
}
return &TarReadCloser{tar.NewReader(cr), cr}, nil
} | [
"func",
"NewCompressedTarReader",
"(",
"rs",
"io",
".",
"ReadSeeker",
")",
"(",
"*",
"TarReadCloser",
",",
"error",
")",
"{",
"cr",
",",
"err",
":=",
"NewCompressedReader",
"(",
"rs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"TarReadCloser",
"{",
"tar",
".",
"NewReader",
"(",
"cr",
")",
",",
"cr",
"}",
",",
"nil",
"\n",
"}"
] | // NewCompressedTarReader creates a new TarReadCloser reading from the
// given ACI image.
// It is the caller's responsibility to call Close on the TarReadCloser
// when done. | [
"NewCompressedTarReader",
"creates",
"a",
"new",
"TarReadCloser",
"reading",
"from",
"the",
"given",
"ACI",
"image",
".",
"It",
"is",
"the",
"caller",
"s",
"responsibility",
"to",
"call",
"Close",
"on",
"the",
"TarReadCloser",
"when",
"done",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/aci/file.go#L193-L199 |
168 | appc/spec | aci/file.go | NewCompressedReader | func NewCompressedReader(rs io.ReadSeeker) (io.ReadCloser, error) {
var (
dr io.ReadCloser
err error
)
_, err = rs.Seek(0, 0)
if err != nil {
return nil, err
}
ftype, err := DetectFileType(rs)
if err != nil {
return nil, err
}
_, err = rs.Seek(0, 0)
if err != nil {
return nil, err
}
switch ftype {
case TypeGzip:
dr, err = gzip.NewReader(rs)
if err != nil {
return nil, err
}
case TypeBzip2:
dr = ioutil.NopCloser(bzip2.NewReader(rs))
case TypeXz:
dr, err = NewXzReader(rs)
if err != nil {
return nil, err
}
case TypeTar:
dr = ioutil.NopCloser(rs)
case TypeUnknown:
return nil, errors.New("error: unknown image filetype")
default:
return nil, errors.New("no type returned from DetectFileType?")
}
return dr, nil
} | go | func NewCompressedReader(rs io.ReadSeeker) (io.ReadCloser, error) {
var (
dr io.ReadCloser
err error
)
_, err = rs.Seek(0, 0)
if err != nil {
return nil, err
}
ftype, err := DetectFileType(rs)
if err != nil {
return nil, err
}
_, err = rs.Seek(0, 0)
if err != nil {
return nil, err
}
switch ftype {
case TypeGzip:
dr, err = gzip.NewReader(rs)
if err != nil {
return nil, err
}
case TypeBzip2:
dr = ioutil.NopCloser(bzip2.NewReader(rs))
case TypeXz:
dr, err = NewXzReader(rs)
if err != nil {
return nil, err
}
case TypeTar:
dr = ioutil.NopCloser(rs)
case TypeUnknown:
return nil, errors.New("error: unknown image filetype")
default:
return nil, errors.New("no type returned from DetectFileType?")
}
return dr, nil
} | [
"func",
"NewCompressedReader",
"(",
"rs",
"io",
".",
"ReadSeeker",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"var",
"(",
"dr",
"io",
".",
"ReadCloser",
"\n",
"err",
"error",
"\n",
")",
"\n\n",
"_",
",",
"err",
"=",
"rs",
".",
"Seek",
"(",
"0",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ftype",
",",
"err",
":=",
"DetectFileType",
"(",
"rs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"rs",
".",
"Seek",
"(",
"0",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"ftype",
"{",
"case",
"TypeGzip",
":",
"dr",
",",
"err",
"=",
"gzip",
".",
"NewReader",
"(",
"rs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"case",
"TypeBzip2",
":",
"dr",
"=",
"ioutil",
".",
"NopCloser",
"(",
"bzip2",
".",
"NewReader",
"(",
"rs",
")",
")",
"\n",
"case",
"TypeXz",
":",
"dr",
",",
"err",
"=",
"NewXzReader",
"(",
"rs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"case",
"TypeTar",
":",
"dr",
"=",
"ioutil",
".",
"NopCloser",
"(",
"rs",
")",
"\n",
"case",
"TypeUnknown",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"dr",
",",
"nil",
"\n",
"}"
] | // NewCompressedReader creates a new io.ReaderCloser from the given ACI image.
// It is the caller's responsibility to call Close on the Reader when done. | [
"NewCompressedReader",
"creates",
"a",
"new",
"io",
".",
"ReaderCloser",
"from",
"the",
"given",
"ACI",
"image",
".",
"It",
"is",
"the",
"caller",
"s",
"responsibility",
"to",
"call",
"Close",
"on",
"the",
"Reader",
"when",
"done",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/aci/file.go#L203-L246 |
169 | appc/spec | schema/types/resource/math.go | powInt64 | func powInt64(a, b int64) int64 {
p := int64(1)
for b > 0 {
if b&1 != 0 {
p *= a
}
b >>= 1
a *= a
}
return p
} | go | func powInt64(a, b int64) int64 {
p := int64(1)
for b > 0 {
if b&1 != 0 {
p *= a
}
b >>= 1
a *= a
}
return p
} | [
"func",
"powInt64",
"(",
"a",
",",
"b",
"int64",
")",
"int64",
"{",
"p",
":=",
"int64",
"(",
"1",
")",
"\n",
"for",
"b",
">",
"0",
"{",
"if",
"b",
"&",
"1",
"!=",
"0",
"{",
"p",
"*=",
"a",
"\n",
"}",
"\n",
"b",
">>=",
"1",
"\n",
"a",
"*=",
"a",
"\n",
"}",
"\n",
"return",
"p",
"\n",
"}"
] | // powInt64 raises a to the bth power. Is not overflow aware. | [
"powInt64",
"raises",
"a",
"to",
"the",
"bth",
"power",
".",
"Is",
"not",
"overflow",
"aware",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/resource/math.go#L251-L261 |
170 | appc/spec | schema/types/isolator.go | assertValid | func (isolators Isolators) assertValid() error {
typesMap := make(map[ACIdentifier]bool)
for _, i := range isolators {
v := i.Value()
if v == nil {
return ErrInvalidIsolator
}
if err := v.AssertValid(); err != nil {
return err
}
if _, ok := typesMap[i.Name]; ok {
if !v.multipleAllowed() {
return fmt.Errorf(`isolators set contains too many instances of type %s"`, i.Name)
}
}
for _, c := range v.Conflicts() {
if _, found := typesMap[c]; found {
return ErrIncompatibleIsolator
}
}
typesMap[i.Name] = true
}
return nil
} | go | func (isolators Isolators) assertValid() error {
typesMap := make(map[ACIdentifier]bool)
for _, i := range isolators {
v := i.Value()
if v == nil {
return ErrInvalidIsolator
}
if err := v.AssertValid(); err != nil {
return err
}
if _, ok := typesMap[i.Name]; ok {
if !v.multipleAllowed() {
return fmt.Errorf(`isolators set contains too many instances of type %s"`, i.Name)
}
}
for _, c := range v.Conflicts() {
if _, found := typesMap[c]; found {
return ErrIncompatibleIsolator
}
}
typesMap[i.Name] = true
}
return nil
} | [
"func",
"(",
"isolators",
"Isolators",
")",
"assertValid",
"(",
")",
"error",
"{",
"typesMap",
":=",
"make",
"(",
"map",
"[",
"ACIdentifier",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"isolators",
"{",
"v",
":=",
"i",
".",
"Value",
"(",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"return",
"ErrInvalidIsolator",
"\n",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"AssertValid",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"typesMap",
"[",
"i",
".",
"Name",
"]",
";",
"ok",
"{",
"if",
"!",
"v",
".",
"multipleAllowed",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"`isolators set contains too many instances of type %s\"`",
",",
"i",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"v",
".",
"Conflicts",
"(",
")",
"{",
"if",
"_",
",",
"found",
":=",
"typesMap",
"[",
"c",
"]",
";",
"found",
"{",
"return",
"ErrIncompatibleIsolator",
"\n",
"}",
"\n",
"}",
"\n",
"typesMap",
"[",
"i",
".",
"Name",
"]",
"=",
"true",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // assertValid checks that every single isolator is valid and that
// the whole set is well built | [
"assertValid",
"checks",
"that",
"every",
"single",
"isolator",
"is",
"valid",
"and",
"that",
"the",
"whole",
"set",
"is",
"well",
"built"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/isolator.go#L54-L77 |
171 | appc/spec | schema/types/isolator.go | GetByName | func (is *Isolators) GetByName(name ACIdentifier) *Isolator {
var i Isolator
for j := len(*is) - 1; j >= 0; j-- {
i = []Isolator(*is)[j]
if i.Name == name {
return &i
}
}
return nil
} | go | func (is *Isolators) GetByName(name ACIdentifier) *Isolator {
var i Isolator
for j := len(*is) - 1; j >= 0; j-- {
i = []Isolator(*is)[j]
if i.Name == name {
return &i
}
}
return nil
} | [
"func",
"(",
"is",
"*",
"Isolators",
")",
"GetByName",
"(",
"name",
"ACIdentifier",
")",
"*",
"Isolator",
"{",
"var",
"i",
"Isolator",
"\n",
"for",
"j",
":=",
"len",
"(",
"*",
"is",
")",
"-",
"1",
";",
"j",
">=",
"0",
";",
"j",
"--",
"{",
"i",
"=",
"[",
"]",
"Isolator",
"(",
"*",
"is",
")",
"[",
"j",
"]",
"\n",
"if",
"i",
".",
"Name",
"==",
"name",
"{",
"return",
"&",
"i",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // GetByName returns the last isolator in the list by the given name. | [
"GetByName",
"returns",
"the",
"last",
"isolator",
"in",
"the",
"list",
"by",
"the",
"given",
"name",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/isolator.go#L80-L89 |
172 | appc/spec | schema/types/isolator.go | ReplaceIsolatorsByName | func (is *Isolators) ReplaceIsolatorsByName(newIs Isolator, oldNames []ACIdentifier) {
var i Isolator
for j := len(*is) - 1; j >= 0; j-- {
i = []Isolator(*is)[j]
for _, name := range oldNames {
if i.Name == name {
*is = append((*is)[:j], (*is)[j+1:]...)
}
}
}
*is = append((*is)[:], newIs)
return
} | go | func (is *Isolators) ReplaceIsolatorsByName(newIs Isolator, oldNames []ACIdentifier) {
var i Isolator
for j := len(*is) - 1; j >= 0; j-- {
i = []Isolator(*is)[j]
for _, name := range oldNames {
if i.Name == name {
*is = append((*is)[:j], (*is)[j+1:]...)
}
}
}
*is = append((*is)[:], newIs)
return
} | [
"func",
"(",
"is",
"*",
"Isolators",
")",
"ReplaceIsolatorsByName",
"(",
"newIs",
"Isolator",
",",
"oldNames",
"[",
"]",
"ACIdentifier",
")",
"{",
"var",
"i",
"Isolator",
"\n",
"for",
"j",
":=",
"len",
"(",
"*",
"is",
")",
"-",
"1",
";",
"j",
">=",
"0",
";",
"j",
"--",
"{",
"i",
"=",
"[",
"]",
"Isolator",
"(",
"*",
"is",
")",
"[",
"j",
"]",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"oldNames",
"{",
"if",
"i",
".",
"Name",
"==",
"name",
"{",
"*",
"is",
"=",
"append",
"(",
"(",
"*",
"is",
")",
"[",
":",
"j",
"]",
",",
"(",
"*",
"is",
")",
"[",
"j",
"+",
"1",
":",
"]",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"*",
"is",
"=",
"append",
"(",
"(",
"*",
"is",
")",
"[",
":",
"]",
",",
"newIs",
")",
"\n",
"return",
"\n",
"}"
] | // ReplaceIsolatorsByName overrides matching isolator types with a new
// isolator, deleting them all and appending the new one instead | [
"ReplaceIsolatorsByName",
"overrides",
"matching",
"isolator",
"types",
"with",
"a",
"new",
"isolator",
"deleting",
"them",
"all",
"and",
"appending",
"the",
"new",
"one",
"instead"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/isolator.go#L93-L105 |
173 | appc/spec | schema/types/isolator.go | Unrecognized | func (is *Isolators) Unrecognized() Isolators {
u := Isolators{}
for _, i := range *is {
if i.value == nil {
u = append(u, i)
}
}
return u
} | go | func (is *Isolators) Unrecognized() Isolators {
u := Isolators{}
for _, i := range *is {
if i.value == nil {
u = append(u, i)
}
}
return u
} | [
"func",
"(",
"is",
"*",
"Isolators",
")",
"Unrecognized",
"(",
")",
"Isolators",
"{",
"u",
":=",
"Isolators",
"{",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"*",
"is",
"{",
"if",
"i",
".",
"value",
"==",
"nil",
"{",
"u",
"=",
"append",
"(",
"u",
",",
"i",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"u",
"\n",
"}"
] | // Unrecognized returns a set of isolators that are not recognized.
// An isolator is not recognized if it has not had an associated
// constructor registered with AddIsolatorValueConstructor. | [
"Unrecognized",
"returns",
"a",
"set",
"of",
"isolators",
"that",
"are",
"not",
"recognized",
".",
"An",
"isolator",
"is",
"not",
"recognized",
"if",
"it",
"has",
"not",
"had",
"an",
"associated",
"constructor",
"registered",
"with",
"AddIsolatorValueConstructor",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/isolator.go#L110-L118 |
174 | appc/spec | schema/types/isolator.go | UnmarshalJSON | func (i *Isolator) UnmarshalJSON(b []byte) error {
var ii isolator
err := json.Unmarshal(b, &ii)
if err != nil {
return err
}
var dst IsolatorValue
con, ok := isolatorMap[ii.Name]
if ok {
dst = con()
err = dst.UnmarshalJSON(*ii.ValueRaw)
if err != nil {
return err
}
err = dst.AssertValid()
if err != nil {
return err
}
}
i.value = dst
i.ValueRaw = ii.ValueRaw
i.Name = ii.Name
return nil
} | go | func (i *Isolator) UnmarshalJSON(b []byte) error {
var ii isolator
err := json.Unmarshal(b, &ii)
if err != nil {
return err
}
var dst IsolatorValue
con, ok := isolatorMap[ii.Name]
if ok {
dst = con()
err = dst.UnmarshalJSON(*ii.ValueRaw)
if err != nil {
return err
}
err = dst.AssertValid()
if err != nil {
return err
}
}
i.value = dst
i.ValueRaw = ii.ValueRaw
i.Name = ii.Name
return nil
} | [
"func",
"(",
"i",
"*",
"Isolator",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"ii",
"isolator",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"ii",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"dst",
"IsolatorValue",
"\n",
"con",
",",
"ok",
":=",
"isolatorMap",
"[",
"ii",
".",
"Name",
"]",
"\n",
"if",
"ok",
"{",
"dst",
"=",
"con",
"(",
")",
"\n",
"err",
"=",
"dst",
".",
"UnmarshalJSON",
"(",
"*",
"ii",
".",
"ValueRaw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"dst",
".",
"AssertValid",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"i",
".",
"value",
"=",
"dst",
"\n",
"i",
".",
"ValueRaw",
"=",
"ii",
".",
"ValueRaw",
"\n",
"i",
".",
"Name",
"=",
"ii",
".",
"Name",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON populates this Isolator from a JSON-encoded representation. To
// unmarshal the Value of the Isolator, it will use the appropriate constructor
// as registered by AddIsolatorValueConstructor. | [
"UnmarshalJSON",
"populates",
"this",
"Isolator",
"from",
"a",
"JSON",
"-",
"encoded",
"representation",
".",
"To",
"unmarshal",
"the",
"Value",
"of",
"the",
"Isolator",
"it",
"will",
"use",
"the",
"appropriate",
"constructor",
"as",
"registered",
"by",
"AddIsolatorValueConstructor",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/isolator.go#L164-L190 |
175 | appc/spec | schema/types/labels.go | IsValidOSArch | func IsValidOSArch(labels map[ACIdentifier]string, validOSArch map[string][]string) error {
if os, ok := labels["os"]; ok {
if validArchs, ok := validOSArch[os]; !ok {
// Not a whitelisted OS. TODO: how to warn rather than fail?
validOses := make([]string, 0, len(validOSArch))
for validOs := range validOSArch {
validOses = append(validOses, validOs)
}
sort.Strings(validOses)
return fmt.Errorf(`bad os %#v (must be one of: %v)`, os, validOses)
} else {
// Whitelisted OS. We check arch here, as arch makes sense only
// when os is defined.
if arch, ok := labels["arch"]; ok {
found := false
for _, validArch := range validArchs {
if arch == validArch {
found = true
break
}
}
if !found {
return fmt.Errorf(`bad arch %#v for %v (must be one of: %v)`, arch, os, validArchs)
}
}
}
}
return nil
} | go | func IsValidOSArch(labels map[ACIdentifier]string, validOSArch map[string][]string) error {
if os, ok := labels["os"]; ok {
if validArchs, ok := validOSArch[os]; !ok {
// Not a whitelisted OS. TODO: how to warn rather than fail?
validOses := make([]string, 0, len(validOSArch))
for validOs := range validOSArch {
validOses = append(validOses, validOs)
}
sort.Strings(validOses)
return fmt.Errorf(`bad os %#v (must be one of: %v)`, os, validOses)
} else {
// Whitelisted OS. We check arch here, as arch makes sense only
// when os is defined.
if arch, ok := labels["arch"]; ok {
found := false
for _, validArch := range validArchs {
if arch == validArch {
found = true
break
}
}
if !found {
return fmt.Errorf(`bad arch %#v for %v (must be one of: %v)`, arch, os, validArchs)
}
}
}
}
return nil
} | [
"func",
"IsValidOSArch",
"(",
"labels",
"map",
"[",
"ACIdentifier",
"]",
"string",
",",
"validOSArch",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"os",
",",
"ok",
":=",
"labels",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"if",
"validArchs",
",",
"ok",
":=",
"validOSArch",
"[",
"os",
"]",
";",
"!",
"ok",
"{",
"// Not a whitelisted OS. TODO: how to warn rather than fail?",
"validOses",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"validOSArch",
")",
")",
"\n",
"for",
"validOs",
":=",
"range",
"validOSArch",
"{",
"validOses",
"=",
"append",
"(",
"validOses",
",",
"validOs",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"validOses",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"`bad os %#v (must be one of: %v)`",
",",
"os",
",",
"validOses",
")",
"\n",
"}",
"else",
"{",
"// Whitelisted OS. We check arch here, as arch makes sense only",
"// when os is defined.",
"if",
"arch",
",",
"ok",
":=",
"labels",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"validArch",
":=",
"range",
"validArchs",
"{",
"if",
"arch",
"==",
"validArch",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"`bad arch %#v for %v (must be one of: %v)`",
",",
"arch",
",",
"os",
",",
"validArchs",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // IsValidOsArch checks if a OS-architecture combination is valid given a map
// of valid OS-architectures | [
"IsValidOsArch",
"checks",
"if",
"a",
"OS",
"-",
"architecture",
"combination",
"is",
"valid",
"given",
"a",
"map",
"of",
"valid",
"OS",
"-",
"architectures"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/labels.go#L55-L83 |
176 | appc/spec | schema/types/labels.go | Get | func (l Labels) Get(name string) (val string, ok bool) {
for _, lbl := range l {
if lbl.Name.String() == name {
return lbl.Value, true
}
}
return "", false
} | go | func (l Labels) Get(name string) (val string, ok bool) {
for _, lbl := range l {
if lbl.Name.String() == name {
return lbl.Value, true
}
}
return "", false
} | [
"func",
"(",
"l",
"Labels",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"val",
"string",
",",
"ok",
"bool",
")",
"{",
"for",
"_",
",",
"lbl",
":=",
"range",
"l",
"{",
"if",
"lbl",
".",
"Name",
".",
"String",
"(",
")",
"==",
"name",
"{",
"return",
"lbl",
".",
"Value",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] | // Get retrieves the value of the label by the given name from Labels, if it exists | [
"Get",
"retrieves",
"the",
"value",
"of",
"the",
"label",
"by",
"the",
"given",
"name",
"from",
"Labels",
"if",
"it",
"exists"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/labels.go#L121-L128 |
177 | appc/spec | schema/types/environment.go | Get | func (e Environment) Get(name string) (value string, ok bool) {
for _, env := range e {
if env.Name == name {
return env.Value, true
}
}
return "", false
} | go | func (e Environment) Get(name string) (value string, ok bool) {
for _, env := range e {
if env.Name == name {
return env.Value, true
}
}
return "", false
} | [
"func",
"(",
"e",
"Environment",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"value",
"string",
",",
"ok",
"bool",
")",
"{",
"for",
"_",
",",
"env",
":=",
"range",
"e",
"{",
"if",
"env",
".",
"Name",
"==",
"name",
"{",
"return",
"env",
".",
"Value",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}"
] | // Retrieve the value of an environment variable by the given name from
// Environment, if it exists. | [
"Retrieve",
"the",
"value",
"of",
"an",
"environment",
"variable",
"by",
"the",
"given",
"name",
"from",
"Environment",
"if",
"it",
"exists",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/environment.go#L84-L91 |
178 | appc/spec | schema/types/environment.go | Set | func (e *Environment) Set(name string, value string) {
for i, env := range *e {
if env.Name == name {
(*e)[i] = EnvironmentVariable{
Name: name,
Value: value,
}
return
}
}
env := EnvironmentVariable{
Name: name,
Value: value,
}
*e = append(*e, env)
} | go | func (e *Environment) Set(name string, value string) {
for i, env := range *e {
if env.Name == name {
(*e)[i] = EnvironmentVariable{
Name: name,
Value: value,
}
return
}
}
env := EnvironmentVariable{
Name: name,
Value: value,
}
*e = append(*e, env)
} | [
"func",
"(",
"e",
"*",
"Environment",
")",
"Set",
"(",
"name",
"string",
",",
"value",
"string",
")",
"{",
"for",
"i",
",",
"env",
":=",
"range",
"*",
"e",
"{",
"if",
"env",
".",
"Name",
"==",
"name",
"{",
"(",
"*",
"e",
")",
"[",
"i",
"]",
"=",
"EnvironmentVariable",
"{",
"Name",
":",
"name",
",",
"Value",
":",
"value",
",",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"env",
":=",
"EnvironmentVariable",
"{",
"Name",
":",
"name",
",",
"Value",
":",
"value",
",",
"}",
"\n",
"*",
"e",
"=",
"append",
"(",
"*",
"e",
",",
"env",
")",
"\n",
"}"
] | // Set sets the value of an environment variable by the given name,
// overwriting if one already exists. | [
"Set",
"sets",
"the",
"value",
"of",
"an",
"environment",
"variable",
"by",
"the",
"given",
"name",
"overwriting",
"if",
"one",
"already",
"exists",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/environment.go#L95-L110 |
179 | appc/spec | schema/types/uuid.go | NewUUID | func NewUUID(s string) (*UUID, error) {
s = strings.Replace(s, "-", "", -1)
if len(s) != 32 {
return nil, errors.New("bad UUID length != 32")
}
dec, err := hex.DecodeString(s)
if err != nil {
return nil, err
}
var u UUID
for i, b := range dec {
u[i] = b
}
return &u, nil
} | go | func NewUUID(s string) (*UUID, error) {
s = strings.Replace(s, "-", "", -1)
if len(s) != 32 {
return nil, errors.New("bad UUID length != 32")
}
dec, err := hex.DecodeString(s)
if err != nil {
return nil, err
}
var u UUID
for i, b := range dec {
u[i] = b
}
return &u, nil
} | [
"func",
"NewUUID",
"(",
"s",
"string",
")",
"(",
"*",
"UUID",
",",
"error",
")",
"{",
"s",
"=",
"strings",
".",
"Replace",
"(",
"s",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"if",
"len",
"(",
"s",
")",
"!=",
"32",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"dec",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"u",
"UUID",
"\n",
"for",
"i",
",",
"b",
":=",
"range",
"dec",
"{",
"u",
"[",
"i",
"]",
"=",
"b",
"\n",
"}",
"\n",
"return",
"&",
"u",
",",
"nil",
"\n",
"}"
] | // NewUUID generates a new UUID from the given string. If the string does not
// represent a valid UUID, nil and an error are returned. | [
"NewUUID",
"generates",
"a",
"new",
"UUID",
"from",
"the",
"given",
"string",
".",
"If",
"the",
"string",
"does",
"not",
"represent",
"a",
"valid",
"UUID",
"nil",
"and",
"an",
"error",
"are",
"returned",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/uuid.go#L52-L66 |
180 | appc/spec | schema/types/acidentifier.go | Set | func (n *ACIdentifier) Set(s string) error {
nn, err := NewACIdentifier(s)
if err == nil {
*n = *nn
}
return err
} | go | func (n *ACIdentifier) Set(s string) error {
nn, err := NewACIdentifier(s)
if err == nil {
*n = *nn
}
return err
} | [
"func",
"(",
"n",
"*",
"ACIdentifier",
")",
"Set",
"(",
"s",
"string",
")",
"error",
"{",
"nn",
",",
"err",
":=",
"NewACIdentifier",
"(",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"*",
"n",
"=",
"*",
"nn",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Set sets the ACIdentifier to the given value, if it is valid; if not,
// an error is returned. | [
"Set",
"sets",
"the",
"ACIdentifier",
"to",
"the",
"given",
"value",
"if",
"it",
"is",
"valid",
";",
"if",
"not",
"an",
"error",
"is",
"returned",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acidentifier.go#L54-L60 |
181 | appc/spec | schema/types/acidentifier.go | Equals | func (n ACIdentifier) Equals(o ACIdentifier) bool {
return strings.ToLower(string(n)) == strings.ToLower(string(o))
} | go | func (n ACIdentifier) Equals(o ACIdentifier) bool {
return strings.ToLower(string(n)) == strings.ToLower(string(o))
} | [
"func",
"(",
"n",
"ACIdentifier",
")",
"Equals",
"(",
"o",
"ACIdentifier",
")",
"bool",
"{",
"return",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"n",
")",
")",
"==",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"o",
")",
")",
"\n",
"}"
] | // Equals checks whether a given ACIdentifier is equal to this one. | [
"Equals",
"checks",
"whether",
"a",
"given",
"ACIdentifier",
"is",
"equal",
"to",
"this",
"one",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acidentifier.go#L63-L65 |
182 | appc/spec | schema/types/acidentifier.go | NewACIdentifier | func NewACIdentifier(s string) (*ACIdentifier, error) {
n := ACIdentifier(s)
if err := n.assertValid(); err != nil {
return nil, err
}
return &n, nil
} | go | func NewACIdentifier(s string) (*ACIdentifier, error) {
n := ACIdentifier(s)
if err := n.assertValid(); err != nil {
return nil, err
}
return &n, nil
} | [
"func",
"NewACIdentifier",
"(",
"s",
"string",
")",
"(",
"*",
"ACIdentifier",
",",
"error",
")",
"{",
"n",
":=",
"ACIdentifier",
"(",
"s",
")",
"\n",
"if",
"err",
":=",
"n",
".",
"assertValid",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"n",
",",
"nil",
"\n",
"}"
] | // NewACIdentifier generates a new ACIdentifier from a string. If the given string is
// not a valid ACIdentifier, nil and an error are returned. | [
"NewACIdentifier",
"generates",
"a",
"new",
"ACIdentifier",
"from",
"a",
"string",
".",
"If",
"the",
"given",
"string",
"is",
"not",
"a",
"valid",
"ACIdentifier",
"nil",
"and",
"an",
"error",
"are",
"returned",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acidentifier.go#L74-L80 |
183 | appc/spec | schema/types/acidentifier.go | MustACIdentifier | func MustACIdentifier(s string) *ACIdentifier {
n, err := NewACIdentifier(s)
if err != nil {
panic(err)
}
return n
} | go | func MustACIdentifier(s string) *ACIdentifier {
n, err := NewACIdentifier(s)
if err != nil {
panic(err)
}
return n
} | [
"func",
"MustACIdentifier",
"(",
"s",
"string",
")",
"*",
"ACIdentifier",
"{",
"n",
",",
"err",
":=",
"NewACIdentifier",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] | // MustACIdentifier generates a new ACIdentifier from a string, If the given string is
// not a valid ACIdentifier, it panics. | [
"MustACIdentifier",
"generates",
"a",
"new",
"ACIdentifier",
"from",
"a",
"string",
"If",
"the",
"given",
"string",
"is",
"not",
"a",
"valid",
"ACIdentifier",
"it",
"panics",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acidentifier.go#L84-L90 |
184 | appc/spec | schema/types/volume.go | maybeSetDefaults | func maybeSetDefaults(vol *Volume) {
if vol.Kind == "empty" {
if vol.Mode == nil {
m := emptyVolumeDefaultMode
vol.Mode = &m
}
if vol.UID == nil {
u := emptyVolumeDefaultUID
vol.UID = &u
}
if vol.GID == nil {
g := emptyVolumeDefaultGID
vol.GID = &g
}
}
} | go | func maybeSetDefaults(vol *Volume) {
if vol.Kind == "empty" {
if vol.Mode == nil {
m := emptyVolumeDefaultMode
vol.Mode = &m
}
if vol.UID == nil {
u := emptyVolumeDefaultUID
vol.UID = &u
}
if vol.GID == nil {
g := emptyVolumeDefaultGID
vol.GID = &g
}
}
} | [
"func",
"maybeSetDefaults",
"(",
"vol",
"*",
"Volume",
")",
"{",
"if",
"vol",
".",
"Kind",
"==",
"\"",
"\"",
"{",
"if",
"vol",
".",
"Mode",
"==",
"nil",
"{",
"m",
":=",
"emptyVolumeDefaultMode",
"\n",
"vol",
".",
"Mode",
"=",
"&",
"m",
"\n",
"}",
"\n",
"if",
"vol",
".",
"UID",
"==",
"nil",
"{",
"u",
":=",
"emptyVolumeDefaultUID",
"\n",
"vol",
".",
"UID",
"=",
"&",
"u",
"\n",
"}",
"\n",
"if",
"vol",
".",
"GID",
"==",
"nil",
"{",
"g",
":=",
"emptyVolumeDefaultGID",
"\n",
"vol",
".",
"GID",
"=",
"&",
"g",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // maybeSetDefaults sets the correct default values for certain fields on a
// Volume if they are not already been set. These fields are not
// pre-populated on all Volumes as the Volume type is polymorphic. | [
"maybeSetDefaults",
"sets",
"the",
"correct",
"default",
"values",
"for",
"certain",
"fields",
"on",
"a",
"Volume",
"if",
"they",
"are",
"not",
"already",
"been",
"set",
".",
"These",
"fields",
"are",
"not",
"pre",
"-",
"populated",
"on",
"all",
"Volumes",
"as",
"the",
"Volume",
"type",
"is",
"polymorphic",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/volume.go#L234-L249 |
185 | appc/spec | schema/types/acname.go | Set | func (n *ACName) Set(s string) error {
nn, err := NewACName(s)
if err == nil {
*n = *nn
}
return err
} | go | func (n *ACName) Set(s string) error {
nn, err := NewACName(s)
if err == nil {
*n = *nn
}
return err
} | [
"func",
"(",
"n",
"*",
"ACName",
")",
"Set",
"(",
"s",
"string",
")",
"error",
"{",
"nn",
",",
"err",
":=",
"NewACName",
"(",
"s",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"*",
"n",
"=",
"*",
"nn",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Set sets the ACName to the given value, if it is valid; if not,
// an error is returned. | [
"Set",
"sets",
"the",
"ACName",
"to",
"the",
"given",
"value",
"if",
"it",
"is",
"valid",
";",
"if",
"not",
"an",
"error",
"is",
"returned",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acname.go#L54-L60 |
186 | appc/spec | schema/types/acname.go | Equals | func (n ACName) Equals(o ACName) bool {
return strings.ToLower(string(n)) == strings.ToLower(string(o))
} | go | func (n ACName) Equals(o ACName) bool {
return strings.ToLower(string(n)) == strings.ToLower(string(o))
} | [
"func",
"(",
"n",
"ACName",
")",
"Equals",
"(",
"o",
"ACName",
")",
"bool",
"{",
"return",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"n",
")",
")",
"==",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"o",
")",
")",
"\n",
"}"
] | // Equals checks whether a given ACName is equal to this one. | [
"Equals",
"checks",
"whether",
"a",
"given",
"ACName",
"is",
"equal",
"to",
"this",
"one",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acname.go#L63-L65 |
187 | appc/spec | schema/types/acname.go | NewACName | func NewACName(s string) (*ACName, error) {
n := ACName(s)
if err := n.assertValid(); err != nil {
return nil, err
}
return &n, nil
} | go | func NewACName(s string) (*ACName, error) {
n := ACName(s)
if err := n.assertValid(); err != nil {
return nil, err
}
return &n, nil
} | [
"func",
"NewACName",
"(",
"s",
"string",
")",
"(",
"*",
"ACName",
",",
"error",
")",
"{",
"n",
":=",
"ACName",
"(",
"s",
")",
"\n",
"if",
"err",
":=",
"n",
".",
"assertValid",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"n",
",",
"nil",
"\n",
"}"
] | // NewACName generates a new ACName from a string. If the given string is
// not a valid ACName, nil and an error are returned. | [
"NewACName",
"generates",
"a",
"new",
"ACName",
"from",
"a",
"string",
".",
"If",
"the",
"given",
"string",
"is",
"not",
"a",
"valid",
"ACName",
"nil",
"and",
"an",
"error",
"are",
"returned",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acname.go#L74-L80 |
188 | appc/spec | schema/types/acname.go | MustACName | func MustACName(s string) *ACName {
n, err := NewACName(s)
if err != nil {
panic(err)
}
return n
} | go | func MustACName(s string) *ACName {
n, err := NewACName(s)
if err != nil {
panic(err)
}
return n
} | [
"func",
"MustACName",
"(",
"s",
"string",
")",
"*",
"ACName",
"{",
"n",
",",
"err",
":=",
"NewACName",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"n",
"\n",
"}"
] | // MustACName generates a new ACName from a string, If the given string is
// not a valid ACName, it panics. | [
"MustACName",
"generates",
"a",
"new",
"ACName",
"from",
"a",
"string",
"If",
"the",
"given",
"string",
"is",
"not",
"a",
"valid",
"ACName",
"it",
"panics",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/schema/types/acname.go#L84-L90 |
189 | appc/spec | aci/layout.go | ValidateLayout | func ValidateLayout(dir string) error {
fi, err := os.Stat(dir)
if err != nil {
return fmt.Errorf("error accessing layout: %v", err)
}
if !fi.IsDir() {
return fmt.Errorf("given path %q is not a directory", dir)
}
var flist []string
var imOK, rfsOK bool
var im io.Reader
walkLayout := func(fpath string, fi os.FileInfo, err error) error {
rpath, err := filepath.Rel(dir, fpath)
if err != nil {
return err
}
switch rpath {
case ".":
case ManifestFile:
im, err = os.Open(fpath)
if err != nil {
return err
}
imOK = true
case RootfsDir:
if !fi.IsDir() {
return errors.New("rootfs is not a directory")
}
rfsOK = true
default:
flist = append(flist, rpath)
}
return nil
}
if err := filepath.Walk(dir, walkLayout); err != nil {
return err
}
return validate(imOK, im, rfsOK, flist)
} | go | func ValidateLayout(dir string) error {
fi, err := os.Stat(dir)
if err != nil {
return fmt.Errorf("error accessing layout: %v", err)
}
if !fi.IsDir() {
return fmt.Errorf("given path %q is not a directory", dir)
}
var flist []string
var imOK, rfsOK bool
var im io.Reader
walkLayout := func(fpath string, fi os.FileInfo, err error) error {
rpath, err := filepath.Rel(dir, fpath)
if err != nil {
return err
}
switch rpath {
case ".":
case ManifestFile:
im, err = os.Open(fpath)
if err != nil {
return err
}
imOK = true
case RootfsDir:
if !fi.IsDir() {
return errors.New("rootfs is not a directory")
}
rfsOK = true
default:
flist = append(flist, rpath)
}
return nil
}
if err := filepath.Walk(dir, walkLayout); err != nil {
return err
}
return validate(imOK, im, rfsOK, flist)
} | [
"func",
"ValidateLayout",
"(",
"dir",
"string",
")",
"error",
"{",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"}",
"\n",
"var",
"flist",
"[",
"]",
"string",
"\n",
"var",
"imOK",
",",
"rfsOK",
"bool",
"\n",
"var",
"im",
"io",
".",
"Reader",
"\n",
"walkLayout",
":=",
"func",
"(",
"fpath",
"string",
",",
"fi",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"rpath",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"dir",
",",
"fpath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"switch",
"rpath",
"{",
"case",
"\"",
"\"",
":",
"case",
"ManifestFile",
":",
"im",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"fpath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"imOK",
"=",
"true",
"\n",
"case",
"RootfsDir",
":",
"if",
"!",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"rfsOK",
"=",
"true",
"\n",
"default",
":",
"flist",
"=",
"append",
"(",
"flist",
",",
"rpath",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"dir",
",",
"walkLayout",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"validate",
"(",
"imOK",
",",
"im",
",",
"rfsOK",
",",
"flist",
")",
"\n",
"}"
] | // ValidateLayout takes a directory and validates that the layout of the directory
// matches that expected by the Application Container Image format.
// If any errors are encountered during the validation, it will abort and
// return the first one. | [
"ValidateLayout",
"takes",
"a",
"directory",
"and",
"validates",
"that",
"the",
"layout",
"of",
"the",
"directory",
"matches",
"that",
"expected",
"by",
"the",
"Application",
"Container",
"Image",
"format",
".",
"If",
"any",
"errors",
"are",
"encountered",
"during",
"the",
"validation",
"it",
"will",
"abort",
"and",
"return",
"the",
"first",
"one",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/aci/layout.go#L70-L108 |
190 | appc/spec | pkg/acirenderer/resolve.go | CreateDepListFromImageID | func CreateDepListFromImageID(imageID types.Hash, ap ACIRegistry) (Images, error) {
key, err := ap.ResolveKey(imageID.String())
if err != nil {
return nil, err
}
return createDepList(key, ap)
} | go | func CreateDepListFromImageID(imageID types.Hash, ap ACIRegistry) (Images, error) {
key, err := ap.ResolveKey(imageID.String())
if err != nil {
return nil, err
}
return createDepList(key, ap)
} | [
"func",
"CreateDepListFromImageID",
"(",
"imageID",
"types",
".",
"Hash",
",",
"ap",
"ACIRegistry",
")",
"(",
"Images",
",",
"error",
")",
"{",
"key",
",",
"err",
":=",
"ap",
".",
"ResolveKey",
"(",
"imageID",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"createDepList",
"(",
"key",
",",
"ap",
")",
"\n",
"}"
] | // CreateDepListFromImageID returns the flat dependency tree of the image with
// the provided imageID | [
"CreateDepListFromImageID",
"returns",
"the",
"flat",
"dependency",
"tree",
"of",
"the",
"image",
"with",
"the",
"provided",
"imageID"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/pkg/acirenderer/resolve.go#L25-L31 |
191 | appc/spec | pkg/acirenderer/resolve.go | CreateDepListFromNameLabels | func CreateDepListFromNameLabels(name types.ACIdentifier, labels types.Labels, ap ACIRegistry) (Images, error) {
key, err := ap.GetACI(name, labels)
if err != nil {
return nil, err
}
return createDepList(key, ap)
} | go | func CreateDepListFromNameLabels(name types.ACIdentifier, labels types.Labels, ap ACIRegistry) (Images, error) {
key, err := ap.GetACI(name, labels)
if err != nil {
return nil, err
}
return createDepList(key, ap)
} | [
"func",
"CreateDepListFromNameLabels",
"(",
"name",
"types",
".",
"ACIdentifier",
",",
"labels",
"types",
".",
"Labels",
",",
"ap",
"ACIRegistry",
")",
"(",
"Images",
",",
"error",
")",
"{",
"key",
",",
"err",
":=",
"ap",
".",
"GetACI",
"(",
"name",
",",
"labels",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"createDepList",
"(",
"key",
",",
"ap",
")",
"\n",
"}"
] | // CreateDepListFromNameLabels returns the flat dependency tree of the image
// with the provided app name and optional labels. | [
"CreateDepListFromNameLabels",
"returns",
"the",
"flat",
"dependency",
"tree",
"of",
"the",
"image",
"with",
"the",
"provided",
"app",
"name",
"and",
"optional",
"labels",
"."
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/pkg/acirenderer/resolve.go#L35-L41 |
192 | appc/spec | pkg/acirenderer/resolve.go | createDepList | func createDepList(key string, ap ACIRegistry) (Images, error) {
imgsl := list.New()
im, err := ap.GetImageManifest(key)
if err != nil {
return nil, err
}
img := Image{Im: im, Key: key, Level: 0}
imgsl.PushFront(img)
// Create a flat dependency tree. Use a LinkedList to be able to
// insert elements in the list while working on it.
for el := imgsl.Front(); el != nil; el = el.Next() {
img := el.Value.(Image)
dependencies := img.Im.Dependencies
for _, d := range dependencies {
var depimg Image
var depKey string
if d.ImageID != nil && !d.ImageID.Empty() {
depKey, err = ap.ResolveKey(d.ImageID.String())
if err != nil {
return nil, err
}
} else {
var err error
depKey, err = ap.GetACI(d.ImageName, d.Labels)
if err != nil {
return nil, err
}
}
im, err := ap.GetImageManifest(depKey)
if err != nil {
return nil, err
}
depimg = Image{Im: im, Key: depKey, Level: img.Level + 1}
imgsl.InsertAfter(depimg, el)
}
}
imgs := Images{}
for el := imgsl.Front(); el != nil; el = el.Next() {
imgs = append(imgs, el.Value.(Image))
}
return imgs, nil
} | go | func createDepList(key string, ap ACIRegistry) (Images, error) {
imgsl := list.New()
im, err := ap.GetImageManifest(key)
if err != nil {
return nil, err
}
img := Image{Im: im, Key: key, Level: 0}
imgsl.PushFront(img)
// Create a flat dependency tree. Use a LinkedList to be able to
// insert elements in the list while working on it.
for el := imgsl.Front(); el != nil; el = el.Next() {
img := el.Value.(Image)
dependencies := img.Im.Dependencies
for _, d := range dependencies {
var depimg Image
var depKey string
if d.ImageID != nil && !d.ImageID.Empty() {
depKey, err = ap.ResolveKey(d.ImageID.String())
if err != nil {
return nil, err
}
} else {
var err error
depKey, err = ap.GetACI(d.ImageName, d.Labels)
if err != nil {
return nil, err
}
}
im, err := ap.GetImageManifest(depKey)
if err != nil {
return nil, err
}
depimg = Image{Im: im, Key: depKey, Level: img.Level + 1}
imgsl.InsertAfter(depimg, el)
}
}
imgs := Images{}
for el := imgsl.Front(); el != nil; el = el.Next() {
imgs = append(imgs, el.Value.(Image))
}
return imgs, nil
} | [
"func",
"createDepList",
"(",
"key",
"string",
",",
"ap",
"ACIRegistry",
")",
"(",
"Images",
",",
"error",
")",
"{",
"imgsl",
":=",
"list",
".",
"New",
"(",
")",
"\n",
"im",
",",
"err",
":=",
"ap",
".",
"GetImageManifest",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"img",
":=",
"Image",
"{",
"Im",
":",
"im",
",",
"Key",
":",
"key",
",",
"Level",
":",
"0",
"}",
"\n",
"imgsl",
".",
"PushFront",
"(",
"img",
")",
"\n\n",
"// Create a flat dependency tree. Use a LinkedList to be able to",
"// insert elements in the list while working on it.",
"for",
"el",
":=",
"imgsl",
".",
"Front",
"(",
")",
";",
"el",
"!=",
"nil",
";",
"el",
"=",
"el",
".",
"Next",
"(",
")",
"{",
"img",
":=",
"el",
".",
"Value",
".",
"(",
"Image",
")",
"\n",
"dependencies",
":=",
"img",
".",
"Im",
".",
"Dependencies",
"\n",
"for",
"_",
",",
"d",
":=",
"range",
"dependencies",
"{",
"var",
"depimg",
"Image",
"\n",
"var",
"depKey",
"string",
"\n",
"if",
"d",
".",
"ImageID",
"!=",
"nil",
"&&",
"!",
"d",
".",
"ImageID",
".",
"Empty",
"(",
")",
"{",
"depKey",
",",
"err",
"=",
"ap",
".",
"ResolveKey",
"(",
"d",
".",
"ImageID",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"var",
"err",
"error",
"\n",
"depKey",
",",
"err",
"=",
"ap",
".",
"GetACI",
"(",
"d",
".",
"ImageName",
",",
"d",
".",
"Labels",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"im",
",",
"err",
":=",
"ap",
".",
"GetImageManifest",
"(",
"depKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"depimg",
"=",
"Image",
"{",
"Im",
":",
"im",
",",
"Key",
":",
"depKey",
",",
"Level",
":",
"img",
".",
"Level",
"+",
"1",
"}",
"\n",
"imgsl",
".",
"InsertAfter",
"(",
"depimg",
",",
"el",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"imgs",
":=",
"Images",
"{",
"}",
"\n",
"for",
"el",
":=",
"imgsl",
".",
"Front",
"(",
")",
";",
"el",
"!=",
"nil",
";",
"el",
"=",
"el",
".",
"Next",
"(",
")",
"{",
"imgs",
"=",
"append",
"(",
"imgs",
",",
"el",
".",
"Value",
".",
"(",
"Image",
")",
")",
"\n",
"}",
"\n",
"return",
"imgs",
",",
"nil",
"\n",
"}"
] | // createDepList returns the flat dependency tree as a list of Image type | [
"createDepList",
"returns",
"the",
"flat",
"dependency",
"tree",
"as",
"a",
"list",
"of",
"Image",
"type"
] | 259c2eebc32df77c016974d5e8eed390d5a81500 | https://github.com/appc/spec/blob/259c2eebc32df77c016974d5e8eed390d5a81500/pkg/acirenderer/resolve.go#L44-L88 |
193 | gocraft/web | static_middleware.go | StaticMiddleware | func StaticMiddleware(path string, option ...StaticOption) func(ResponseWriter, *Request, NextMiddlewareFunc) {
return StaticMiddlewareFromDir(http.Dir(path), option...)
} | go | func StaticMiddleware(path string, option ...StaticOption) func(ResponseWriter, *Request, NextMiddlewareFunc) {
return StaticMiddlewareFromDir(http.Dir(path), option...)
} | [
"func",
"StaticMiddleware",
"(",
"path",
"string",
",",
"option",
"...",
"StaticOption",
")",
"func",
"(",
"ResponseWriter",
",",
"*",
"Request",
",",
"NextMiddlewareFunc",
")",
"{",
"return",
"StaticMiddlewareFromDir",
"(",
"http",
".",
"Dir",
"(",
"path",
")",
",",
"option",
"...",
")",
"\n",
"}"
] | // StaticMiddleware is the same as StaticMiddlewareFromDir, but accepts a
// path string for backwards compatibility. | [
"StaticMiddleware",
"is",
"the",
"same",
"as",
"StaticMiddlewareFromDir",
"but",
"accepts",
"a",
"path",
"string",
"for",
"backwards",
"compatibility",
"."
] | 9707327fb69b5b93fd722c6b4259a7b414bedac5 | https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/static_middleware.go#L19-L21 |
194 | gocraft/web | static_middleware.go | StaticMiddlewareFromDir | func StaticMiddlewareFromDir(dir http.FileSystem, options ...StaticOption) func(ResponseWriter, *Request, NextMiddlewareFunc) {
var option StaticOption
if len(options) > 0 {
option = options[0]
}
return func(w ResponseWriter, req *Request, next NextMiddlewareFunc) {
if req.Method != "GET" && req.Method != "HEAD" {
next(w, req)
return
}
file := req.URL.Path
if option.Prefix != "" {
if !strings.HasPrefix(file, option.Prefix) {
next(w, req)
return
}
file = file[len(option.Prefix):]
}
f, err := dir.Open(file)
if err != nil {
next(w, req)
return
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
next(w, req)
return
}
// If the file is a directory, try to serve an index file.
// If no index is available, DO NOT serve the directory to avoid
// Content-Length issues. Simply skip to the next middleware, and return
// a 404 if no route with the same name is handled.
if fi.IsDir() {
if option.IndexFile != "" {
file = filepath.Join(file, option.IndexFile)
f, err = dir.Open(file)
if err != nil {
next(w, req)
return
}
defer f.Close()
fi, err = f.Stat()
if err != nil || fi.IsDir() {
next(w, req)
return
}
} else {
next(w, req)
return
}
}
http.ServeContent(w, req.Request, file, fi.ModTime(), f)
}
} | go | func StaticMiddlewareFromDir(dir http.FileSystem, options ...StaticOption) func(ResponseWriter, *Request, NextMiddlewareFunc) {
var option StaticOption
if len(options) > 0 {
option = options[0]
}
return func(w ResponseWriter, req *Request, next NextMiddlewareFunc) {
if req.Method != "GET" && req.Method != "HEAD" {
next(w, req)
return
}
file := req.URL.Path
if option.Prefix != "" {
if !strings.HasPrefix(file, option.Prefix) {
next(w, req)
return
}
file = file[len(option.Prefix):]
}
f, err := dir.Open(file)
if err != nil {
next(w, req)
return
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
next(w, req)
return
}
// If the file is a directory, try to serve an index file.
// If no index is available, DO NOT serve the directory to avoid
// Content-Length issues. Simply skip to the next middleware, and return
// a 404 if no route with the same name is handled.
if fi.IsDir() {
if option.IndexFile != "" {
file = filepath.Join(file, option.IndexFile)
f, err = dir.Open(file)
if err != nil {
next(w, req)
return
}
defer f.Close()
fi, err = f.Stat()
if err != nil || fi.IsDir() {
next(w, req)
return
}
} else {
next(w, req)
return
}
}
http.ServeContent(w, req.Request, file, fi.ModTime(), f)
}
} | [
"func",
"StaticMiddlewareFromDir",
"(",
"dir",
"http",
".",
"FileSystem",
",",
"options",
"...",
"StaticOption",
")",
"func",
"(",
"ResponseWriter",
",",
"*",
"Request",
",",
"NextMiddlewareFunc",
")",
"{",
"var",
"option",
"StaticOption",
"\n",
"if",
"len",
"(",
"options",
")",
">",
"0",
"{",
"option",
"=",
"options",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"func",
"(",
"w",
"ResponseWriter",
",",
"req",
"*",
"Request",
",",
"next",
"NextMiddlewareFunc",
")",
"{",
"if",
"req",
".",
"Method",
"!=",
"\"",
"\"",
"&&",
"req",
".",
"Method",
"!=",
"\"",
"\"",
"{",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"file",
":=",
"req",
".",
"URL",
".",
"Path",
"\n",
"if",
"option",
".",
"Prefix",
"!=",
"\"",
"\"",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"file",
",",
"option",
".",
"Prefix",
")",
"{",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"\n",
"}",
"\n",
"file",
"=",
"file",
"[",
"len",
"(",
"option",
".",
"Prefix",
")",
":",
"]",
"\n",
"}",
"\n\n",
"f",
",",
"err",
":=",
"dir",
".",
"Open",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"fi",
",",
"err",
":=",
"f",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// If the file is a directory, try to serve an index file.",
"// If no index is available, DO NOT serve the directory to avoid",
"// Content-Length issues. Simply skip to the next middleware, and return",
"// a 404 if no route with the same name is handled. ",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"if",
"option",
".",
"IndexFile",
"!=",
"\"",
"\"",
"{",
"file",
"=",
"filepath",
".",
"Join",
"(",
"file",
",",
"option",
".",
"IndexFile",
")",
"\n",
"f",
",",
"err",
"=",
"dir",
".",
"Open",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"fi",
",",
"err",
"=",
"f",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"fi",
".",
"IsDir",
"(",
")",
"{",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"else",
"{",
"next",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"http",
".",
"ServeContent",
"(",
"w",
",",
"req",
".",
"Request",
",",
"file",
",",
"fi",
".",
"ModTime",
"(",
")",
",",
"f",
")",
"\n",
"}",
"\n",
"}"
] | // StaticMiddlewareFromDir returns a middleware that serves static files from the specified http.FileSystem.
// This middleware is great for development because each file is read from disk each time and no
// special caching or cache headers are sent.
//
// If a path is requested which maps to a folder with an index.html folder on your filesystem,
// then that index.html file will be served. | [
"StaticMiddlewareFromDir",
"returns",
"a",
"middleware",
"that",
"serves",
"static",
"files",
"from",
"the",
"specified",
"http",
".",
"FileSystem",
".",
"This",
"middleware",
"is",
"great",
"for",
"development",
"because",
"each",
"file",
"is",
"read",
"from",
"disk",
"each",
"time",
"and",
"no",
"special",
"caching",
"or",
"cache",
"headers",
"are",
"sent",
".",
"If",
"a",
"path",
"is",
"requested",
"which",
"maps",
"to",
"a",
"folder",
"with",
"an",
"index",
".",
"html",
"folder",
"on",
"your",
"filesystem",
"then",
"that",
"index",
".",
"html",
"file",
"will",
"be",
"served",
"."
] | 9707327fb69b5b93fd722c6b4259a7b414bedac5 | https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/static_middleware.go#L29-L88 |
195 | gocraft/web | router_setup.go | New | func New(ctx interface{}) *Router {
validateContext(ctx, nil)
r := &Router{}
r.contextType = reflect.TypeOf(ctx)
r.pathPrefix = "/"
r.maxChildrenDepth = 1
r.root = make(map[httpMethod]*pathNode)
for _, method := range httpMethods {
r.root[method] = newPathNode()
}
return r
} | go | func New(ctx interface{}) *Router {
validateContext(ctx, nil)
r := &Router{}
r.contextType = reflect.TypeOf(ctx)
r.pathPrefix = "/"
r.maxChildrenDepth = 1
r.root = make(map[httpMethod]*pathNode)
for _, method := range httpMethods {
r.root[method] = newPathNode()
}
return r
} | [
"func",
"New",
"(",
"ctx",
"interface",
"{",
"}",
")",
"*",
"Router",
"{",
"validateContext",
"(",
"ctx",
",",
"nil",
")",
"\n\n",
"r",
":=",
"&",
"Router",
"{",
"}",
"\n",
"r",
".",
"contextType",
"=",
"reflect",
".",
"TypeOf",
"(",
"ctx",
")",
"\n",
"r",
".",
"pathPrefix",
"=",
"\"",
"\"",
"\n",
"r",
".",
"maxChildrenDepth",
"=",
"1",
"\n",
"r",
".",
"root",
"=",
"make",
"(",
"map",
"[",
"httpMethod",
"]",
"*",
"pathNode",
")",
"\n",
"for",
"_",
",",
"method",
":=",
"range",
"httpMethods",
"{",
"r",
".",
"root",
"[",
"method",
"]",
"=",
"newPathNode",
"(",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // New returns a new router with context type ctx. ctx should be a struct instance,
// whose purpose is to communicate type information. On each request, an instance of this
// context type will be automatically allocated and sent to handlers. | [
"New",
"returns",
"a",
"new",
"router",
"with",
"context",
"type",
"ctx",
".",
"ctx",
"should",
"be",
"a",
"struct",
"instance",
"whose",
"purpose",
"is",
"to",
"communicate",
"type",
"information",
".",
"On",
"each",
"request",
"an",
"instance",
"of",
"this",
"context",
"type",
"will",
"be",
"automatically",
"allocated",
"and",
"sent",
"to",
"handlers",
"."
] | 9707327fb69b5b93fd722c6b4259a7b414bedac5 | https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L91-L103 |
196 | gocraft/web | router_setup.go | Subrouter | func (r *Router) Subrouter(ctx interface{}, pathPrefix string) *Router {
validateContext(ctx, r.contextType)
// Create new router, link up hierarchy
newRouter := &Router{parent: r}
r.children = append(r.children, newRouter)
// Increment maxChildrenDepth if this is the first child of the router
if len(r.children) == 1 {
curParent := r
for curParent != nil {
curParent.maxChildrenDepth = curParent.depth()
curParent = curParent.parent
}
}
newRouter.contextType = reflect.TypeOf(ctx)
newRouter.pathPrefix = appendPath(r.pathPrefix, pathPrefix)
newRouter.root = r.root
return newRouter
} | go | func (r *Router) Subrouter(ctx interface{}, pathPrefix string) *Router {
validateContext(ctx, r.contextType)
// Create new router, link up hierarchy
newRouter := &Router{parent: r}
r.children = append(r.children, newRouter)
// Increment maxChildrenDepth if this is the first child of the router
if len(r.children) == 1 {
curParent := r
for curParent != nil {
curParent.maxChildrenDepth = curParent.depth()
curParent = curParent.parent
}
}
newRouter.contextType = reflect.TypeOf(ctx)
newRouter.pathPrefix = appendPath(r.pathPrefix, pathPrefix)
newRouter.root = r.root
return newRouter
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Subrouter",
"(",
"ctx",
"interface",
"{",
"}",
",",
"pathPrefix",
"string",
")",
"*",
"Router",
"{",
"validateContext",
"(",
"ctx",
",",
"r",
".",
"contextType",
")",
"\n\n",
"// Create new router, link up hierarchy",
"newRouter",
":=",
"&",
"Router",
"{",
"parent",
":",
"r",
"}",
"\n",
"r",
".",
"children",
"=",
"append",
"(",
"r",
".",
"children",
",",
"newRouter",
")",
"\n\n",
"// Increment maxChildrenDepth if this is the first child of the router",
"if",
"len",
"(",
"r",
".",
"children",
")",
"==",
"1",
"{",
"curParent",
":=",
"r",
"\n",
"for",
"curParent",
"!=",
"nil",
"{",
"curParent",
".",
"maxChildrenDepth",
"=",
"curParent",
".",
"depth",
"(",
")",
"\n",
"curParent",
"=",
"curParent",
".",
"parent",
"\n",
"}",
"\n",
"}",
"\n\n",
"newRouter",
".",
"contextType",
"=",
"reflect",
".",
"TypeOf",
"(",
"ctx",
")",
"\n",
"newRouter",
".",
"pathPrefix",
"=",
"appendPath",
"(",
"r",
".",
"pathPrefix",
",",
"pathPrefix",
")",
"\n",
"newRouter",
".",
"root",
"=",
"r",
".",
"root",
"\n\n",
"return",
"newRouter",
"\n",
"}"
] | // Subrouter attaches a new subrouter to the specified router and returns it.
// You can use the same context or pass a new one. If you pass a new one, it must
// embed a pointer to the previous context in the first slot. You can also pass
// a pathPrefix that each route will have. If "" is passed, then no path prefix is applied. | [
"Subrouter",
"attaches",
"a",
"new",
"subrouter",
"to",
"the",
"specified",
"router",
"and",
"returns",
"it",
".",
"You",
"can",
"use",
"the",
"same",
"context",
"or",
"pass",
"a",
"new",
"one",
".",
"If",
"you",
"pass",
"a",
"new",
"one",
"it",
"must",
"embed",
"a",
"pointer",
"to",
"the",
"previous",
"context",
"in",
"the",
"first",
"slot",
".",
"You",
"can",
"also",
"pass",
"a",
"pathPrefix",
"that",
"each",
"route",
"will",
"have",
".",
"If",
"is",
"passed",
"then",
"no",
"path",
"prefix",
"is",
"applied",
"."
] | 9707327fb69b5b93fd722c6b4259a7b414bedac5 | https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L118-L139 |
197 | gocraft/web | router_setup.go | Middleware | func (r *Router) Middleware(fn interface{}) *Router {
vfn := reflect.ValueOf(fn)
validateMiddleware(vfn, r.contextType)
if vfn.Type().NumIn() == 3 {
r.middleware = append(r.middleware, &middlewareHandler{Generic: true, GenericMiddleware: fn.(func(ResponseWriter, *Request, NextMiddlewareFunc))})
} else {
r.middleware = append(r.middleware, &middlewareHandler{Generic: false, DynamicMiddleware: vfn})
}
return r
} | go | func (r *Router) Middleware(fn interface{}) *Router {
vfn := reflect.ValueOf(fn)
validateMiddleware(vfn, r.contextType)
if vfn.Type().NumIn() == 3 {
r.middleware = append(r.middleware, &middlewareHandler{Generic: true, GenericMiddleware: fn.(func(ResponseWriter, *Request, NextMiddlewareFunc))})
} else {
r.middleware = append(r.middleware, &middlewareHandler{Generic: false, DynamicMiddleware: vfn})
}
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Middleware",
"(",
"fn",
"interface",
"{",
"}",
")",
"*",
"Router",
"{",
"vfn",
":=",
"reflect",
".",
"ValueOf",
"(",
"fn",
")",
"\n",
"validateMiddleware",
"(",
"vfn",
",",
"r",
".",
"contextType",
")",
"\n",
"if",
"vfn",
".",
"Type",
"(",
")",
".",
"NumIn",
"(",
")",
"==",
"3",
"{",
"r",
".",
"middleware",
"=",
"append",
"(",
"r",
".",
"middleware",
",",
"&",
"middlewareHandler",
"{",
"Generic",
":",
"true",
",",
"GenericMiddleware",
":",
"fn",
".",
"(",
"func",
"(",
"ResponseWriter",
",",
"*",
"Request",
",",
"NextMiddlewareFunc",
")",
")",
"}",
")",
"\n",
"}",
"else",
"{",
"r",
".",
"middleware",
"=",
"append",
"(",
"r",
".",
"middleware",
",",
"&",
"middlewareHandler",
"{",
"Generic",
":",
"false",
",",
"DynamicMiddleware",
":",
"vfn",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // Middleware adds the specified middleware tot he router and returns the router. | [
"Middleware",
"adds",
"the",
"specified",
"middleware",
"tot",
"he",
"router",
"and",
"returns",
"the",
"router",
"."
] | 9707327fb69b5b93fd722c6b4259a7b414bedac5 | https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L142-L152 |
198 | gocraft/web | router_setup.go | OptionsHandler | func (r *Router) OptionsHandler(fn interface{}) *Router {
if r.parent != nil {
panic("You can only set an OptionsHandler on the root router.")
}
vfn := reflect.ValueOf(fn)
validateOptionsHandler(vfn, r.contextType)
r.optionsHandler = vfn
return r
} | go | func (r *Router) OptionsHandler(fn interface{}) *Router {
if r.parent != nil {
panic("You can only set an OptionsHandler on the root router.")
}
vfn := reflect.ValueOf(fn)
validateOptionsHandler(vfn, r.contextType)
r.optionsHandler = vfn
return r
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"OptionsHandler",
"(",
"fn",
"interface",
"{",
"}",
")",
"*",
"Router",
"{",
"if",
"r",
".",
"parent",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"vfn",
":=",
"reflect",
".",
"ValueOf",
"(",
"fn",
")",
"\n",
"validateOptionsHandler",
"(",
"vfn",
",",
"r",
".",
"contextType",
")",
"\n",
"r",
".",
"optionsHandler",
"=",
"vfn",
"\n",
"return",
"r",
"\n",
"}"
] | // OptionsHandler sets the specified function as the options handler and returns the router.
// Note that only the root router can have a OptionsHandler handler. | [
"OptionsHandler",
"sets",
"the",
"specified",
"function",
"as",
"the",
"options",
"handler",
"and",
"returns",
"the",
"router",
".",
"Note",
"that",
"only",
"the",
"root",
"router",
"can",
"have",
"a",
"OptionsHandler",
"handler",
"."
] | 9707327fb69b5b93fd722c6b4259a7b414bedac5 | https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L176-L184 |
199 | gocraft/web | router_setup.go | Get | func (r *Router) Get(path string, fn interface{}) *Router {
return r.addRoute(httpMethodGet, path, fn)
} | go | func (r *Router) Get(path string, fn interface{}) *Router {
return r.addRoute(httpMethodGet, path, fn)
} | [
"func",
"(",
"r",
"*",
"Router",
")",
"Get",
"(",
"path",
"string",
",",
"fn",
"interface",
"{",
"}",
")",
"*",
"Router",
"{",
"return",
"r",
".",
"addRoute",
"(",
"httpMethodGet",
",",
"path",
",",
"fn",
")",
"\n",
"}"
] | // Get will add a route to the router that matches on GET requests and the specified path. | [
"Get",
"will",
"add",
"a",
"route",
"to",
"the",
"router",
"that",
"matches",
"on",
"GET",
"requests",
"and",
"the",
"specified",
"path",
"."
] | 9707327fb69b5b93fd722c6b4259a7b414bedac5 | https://github.com/gocraft/web/blob/9707327fb69b5b93fd722c6b4259a7b414bedac5/router_setup.go#L187-L189 |