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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
152,500 | appc/goaci | proj2aci/util.go | listSeparator | func listSeparator() string {
if pathListSep == "" {
len := utf8.RuneLen(filepath.ListSeparator)
if len < 0 {
panic("filepath.ListSeparator is not valid utf8?!")
}
buf := make([]byte, len)
len = utf8.EncodeRune(buf, filepath.ListSeparator)
pathListSep = string(buf[:len])
}
return pathListSep
} | go | func listSeparator() string {
if pathListSep == "" {
len := utf8.RuneLen(filepath.ListSeparator)
if len < 0 {
panic("filepath.ListSeparator is not valid utf8?!")
}
buf := make([]byte, len)
len = utf8.EncodeRune(buf, filepath.ListSeparator)
pathListSep = string(buf[:len])
}
return pathListSep
} | [
"func",
"listSeparator",
"(",
")",
"string",
"{",
"if",
"pathListSep",
"==",
"\"",
"\"",
"{",
"len",
":=",
"utf8",
".",
"RuneLen",
"(",
"filepath",
".",
"ListSeparator",
")",
"\n",
"if",
"len",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}... | // listSeparator returns filepath.ListSeparator rune as a string. | [
"listSeparator",
"returns",
"filepath",
".",
"ListSeparator",
"rune",
"as",
"a",
"string",
"."
] | a9f06a2e5e7e897acc6a1fbcf21236a406315111 | https://github.com/appc/goaci/blob/a9f06a2e5e7e897acc6a1fbcf21236a406315111/proj2aci/util.go#L70-L82 |
152,501 | JustinBeckwith/go-yelp | examples/yelp-http/yelp-http.go | getOptions | func getOptions(w http.ResponseWriter) (options *yelp.AuthOptions, err error) {
var o *yelp.AuthOptions
// start by looking for the keys in config.json
data, err := ioutil.ReadFile("../../config.json")
if err != nil {
// if the file isn't there, check environment variables
o = &yelp.AuthOptions{
ConsumerKey: os.Getenv("CONSUMER_KEY"),
ConsumerSecret: os.Getenv("CONSUMER_SECRET"),
AccessToken: os.Getenv("ACCESS_TOKEN"),
AccessTokenSecret: os.Getenv("ACCESS_TOKEN_SECRET"),
}
if o.ConsumerKey == "" || o.ConsumerSecret == "" || o.AccessToken == "" || o.AccessTokenSecret == "" {
return o, errors.New("to use the sample, keys must be provided either in a config.json file at the root of the repo, or in environment variables")
}
} else {
err = json.Unmarshal(data, &o)
return o, err
}
return o, nil
} | go | func getOptions(w http.ResponseWriter) (options *yelp.AuthOptions, err error) {
var o *yelp.AuthOptions
// start by looking for the keys in config.json
data, err := ioutil.ReadFile("../../config.json")
if err != nil {
// if the file isn't there, check environment variables
o = &yelp.AuthOptions{
ConsumerKey: os.Getenv("CONSUMER_KEY"),
ConsumerSecret: os.Getenv("CONSUMER_SECRET"),
AccessToken: os.Getenv("ACCESS_TOKEN"),
AccessTokenSecret: os.Getenv("ACCESS_TOKEN_SECRET"),
}
if o.ConsumerKey == "" || o.ConsumerSecret == "" || o.AccessToken == "" || o.AccessTokenSecret == "" {
return o, errors.New("to use the sample, keys must be provided either in a config.json file at the root of the repo, or in environment variables")
}
} else {
err = json.Unmarshal(data, &o)
return o, err
}
return o, nil
} | [
"func",
"getOptions",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"(",
"options",
"*",
"yelp",
".",
"AuthOptions",
",",
"err",
"error",
")",
"{",
"var",
"o",
"*",
"yelp",
".",
"AuthOptions",
"\n\n",
"// start by looking for the keys in config.json",
"data",
... | // getOptions obtains the keys required to use the Yelp API from a config file
// or from environment variables. | [
"getOptions",
"obtains",
"the",
"keys",
"required",
"to",
"use",
"the",
"Yelp",
"API",
"from",
"a",
"config",
"file",
"or",
"from",
"environment",
"variables",
"."
] | 2228f91f3d151c1cd01f8e916b5cc89741b6ac92 | https://github.com/JustinBeckwith/go-yelp/blob/2228f91f3d151c1cd01f8e916b5cc89741b6ac92/examples/yelp-http/yelp-http.go#L52-L74 |
152,502 | wirepair/autogcd | element.go | populateElement | func (e *Element) populateElement(node *gcdapi.DOMNode) {
e.lock.Lock()
e.node = node
e.id = node.NodeId
e.nodeType = node.NodeType
e.nodeName = strings.ToLower(node.NodeName)
e.childNodeCount = node.ChildNodeCount
if node.NodeType == int(TEXT_NODE) {
e.characterData = node.NodeValue
}
e.lock.Unlock()
for i := 0; i < len(node.Attributes); i += 2 {
e.updateAttribute(node.Attributes[i], node.Attributes[i+1])
}
// close it
if !e.ready {
close(e.readyGate)
}
e.lock.Lock()
defer e.lock.Unlock()
e.ready = true
} | go | func (e *Element) populateElement(node *gcdapi.DOMNode) {
e.lock.Lock()
e.node = node
e.id = node.NodeId
e.nodeType = node.NodeType
e.nodeName = strings.ToLower(node.NodeName)
e.childNodeCount = node.ChildNodeCount
if node.NodeType == int(TEXT_NODE) {
e.characterData = node.NodeValue
}
e.lock.Unlock()
for i := 0; i < len(node.Attributes); i += 2 {
e.updateAttribute(node.Attributes[i], node.Attributes[i+1])
}
// close it
if !e.ready {
close(e.readyGate)
}
e.lock.Lock()
defer e.lock.Unlock()
e.ready = true
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"populateElement",
"(",
"node",
"*",
"gcdapi",
".",
"DOMNode",
")",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"node",
"=",
"node",
"\n",
"e",
".",
"id",
"=",
"node",
".",
"NodeId",
"\n"... | // populate the Element with node data. | [
"populate",
"the",
"Element",
"with",
"node",
"data",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L123-L147 |
152,503 | wirepair/autogcd | element.go | IsReady | func (e *Element) IsReady() bool {
e.lock.RLock()
defer e.lock.RUnlock()
return (e.ready && !e.invalidated)
} | go | func (e *Element) IsReady() bool {
e.lock.RLock()
defer e.lock.RUnlock()
return (e.ready && !e.invalidated)
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"IsReady",
"(",
")",
"bool",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"(",
"e",
".",
"ready",
"&&",
"!",
"e",
".",
"invali... | // Has the Chrome Debugger notified us of this Elements data yet? | [
"Has",
"the",
"Chrome",
"Debugger",
"notified",
"us",
"of",
"this",
"Elements",
"data",
"yet?"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L150-L154 |
152,504 | wirepair/autogcd | element.go | setInvalidated | func (e *Element) setInvalidated(invalid bool) {
e.lock.Lock()
e.invalidated = invalid
e.lock.Unlock()
} | go | func (e *Element) setInvalidated(invalid bool) {
e.lock.Lock()
e.invalidated = invalid
e.lock.Unlock()
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"setInvalidated",
"(",
"invalid",
"bool",
")",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"e",
".",
"invalidated",
"=",
"invalid",
"\n",
"e",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // The element has become invalid. | [
"The",
"element",
"has",
"become",
"invalid",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L171-L175 |
152,505 | wirepair/autogcd | element.go | WaitForReady | func (e *Element) WaitForReady() error {
e.lock.RLock()
ready := e.ready
e.lock.RUnlock()
if ready {
return nil
}
timeout := time.NewTimer(e.tab.elementTimeout)
defer timeout.Stop()
select {
case <-e.readyGate:
return nil
case <-timeout.C:
return &ElementNotReadyErr{}
}
} | go | func (e *Element) WaitForReady() error {
e.lock.RLock()
ready := e.ready
e.lock.RUnlock()
if ready {
return nil
}
timeout := time.NewTimer(e.tab.elementTimeout)
defer timeout.Stop()
select {
case <-e.readyGate:
return nil
case <-timeout.C:
return &ElementNotReadyErr{}
}
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"WaitForReady",
"(",
")",
"error",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"ready",
":=",
"e",
".",
"ready",
"\n",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"ready",
"{",
"retu... | // If we are ready, just return, if we are not, wait for the readyGate
// to be closed or for the timeout timer to fired. | [
"If",
"we",
"are",
"ready",
"just",
"return",
"if",
"we",
"are",
"not",
"wait",
"for",
"the",
"readyGate",
"to",
"be",
"closed",
"or",
"for",
"the",
"timeout",
"timer",
"to",
"fired",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L179-L197 |
152,506 | wirepair/autogcd | element.go | GetSource | func (e *Element) GetSource() (string, error) {
e.lock.RLock()
id := e.id
e.lock.RUnlock()
if e.invalidated {
return "", &InvalidElementErr{}
}
e.tab.debugf("id: %d\n", id)
outerParams := &gcdapi.DOMGetOuterHTMLParams{NodeId: id}
return e.tab.DOM.GetOuterHTMLWithParams(outerParams)
} | go | func (e *Element) GetSource() (string, error) {
e.lock.RLock()
id := e.id
e.lock.RUnlock()
if e.invalidated {
return "", &InvalidElementErr{}
}
e.tab.debugf("id: %d\n", id)
outerParams := &gcdapi.DOMGetOuterHTMLParams{NodeId: id}
return e.tab.DOM.GetOuterHTMLWithParams(outerParams)
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetSource",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"id",
":=",
"e",
".",
"id",
"\n",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
... | // Returns the outer html of the element. | [
"Returns",
"the",
"outer",
"html",
"of",
"the",
"element",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L200-L211 |
152,507 | wirepair/autogcd | element.go | GetFrameDocumentNodeId | func (e *Element) GetFrameDocumentNodeId() (int, error) {
if !e.IsReady() {
return -1, &ElementNotReadyErr{}
}
e.lock.RLock()
defer e.lock.RUnlock()
if e.node != nil && e.node.ContentDocument != nil {
return e.node.ContentDocument.NodeId, nil
}
return -1, &IncorrectElementTypeErr{ExpectedName: "(i)frame", NodeName: e.nodeName}
} | go | func (e *Element) GetFrameDocumentNodeId() (int, error) {
if !e.IsReady() {
return -1, &ElementNotReadyErr{}
}
e.lock.RLock()
defer e.lock.RUnlock()
if e.node != nil && e.node.ContentDocument != nil {
return e.node.ContentDocument.NodeId, nil
}
return -1, &IncorrectElementTypeErr{ExpectedName: "(i)frame", NodeName: e.nodeName}
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetFrameDocumentNodeId",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"!",
"e",
".",
"IsReady",
"(",
")",
"{",
"return",
"-",
"1",
",",
"&",
"ElementNotReadyErr",
"{",
"}",
"\n",
"}",
"\n",
"e",
".",... | // If this element is a frame or iframe, return the ContentDocument node id | [
"If",
"this",
"element",
"is",
"a",
"frame",
"or",
"iframe",
"return",
"the",
"ContentDocument",
"node",
"id"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L244-L255 |
152,508 | wirepair/autogcd | element.go | NodeId | func (e *Element) NodeId() int {
e.lock.RLock()
defer e.lock.RUnlock()
return e.id
} | go | func (e *Element) NodeId() int {
e.lock.RLock()
defer e.lock.RUnlock()
return e.id
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"NodeId",
"(",
")",
"int",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"e",
".",
"id",
"\n",
"}"
] | // Returns the underlying chrome debugger node id of this Element | [
"Returns",
"the",
"underlying",
"chrome",
"debugger",
"node",
"id",
"of",
"this",
"Element"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L258-L263 |
152,509 | wirepair/autogcd | element.go | GetEventListeners | func (e *Element) GetEventListeners() ([]*gcdapi.DOMDebuggerEventListener, error) {
e.lock.RLock()
id := e.id
e.lock.RUnlock()
params := &gcdapi.DOMResolveNodeParams{
NodeId: id,
}
rro, err := e.tab.DOM.ResolveNodeWithParams(params)
if err != nil {
return nil, err
}
eventListeners, err := e.tab.DOMDebugger.GetEventListeners(rro.ObjectId, 1, false)
if err != nil {
return nil, err
}
return eventListeners, nil
} | go | func (e *Element) GetEventListeners() ([]*gcdapi.DOMDebuggerEventListener, error) {
e.lock.RLock()
id := e.id
e.lock.RUnlock()
params := &gcdapi.DOMResolveNodeParams{
NodeId: id,
}
rro, err := e.tab.DOM.ResolveNodeWithParams(params)
if err != nil {
return nil, err
}
eventListeners, err := e.tab.DOMDebugger.GetEventListeners(rro.ObjectId, 1, false)
if err != nil {
return nil, err
}
return eventListeners, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetEventListeners",
"(",
")",
"(",
"[",
"]",
"*",
"gcdapi",
".",
"DOMDebuggerEventListener",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"id",
":=",
"e",
".",
"id",
"\n",
"e",
".... | // Returns event listeners for the element, both static and dynamically bound. | [
"Returns",
"event",
"listeners",
"for",
"the",
"element",
"both",
"static",
"and",
"dynamically",
"bound",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L266-L284 |
152,510 | wirepair/autogcd | element.go | GetDebuggerDOMNode | func (e *Element) GetDebuggerDOMNode() (*gcdapi.DOMNode, error) {
if !e.IsReady() {
return nil, &ElementNotReadyErr{}
}
e.lock.RLock()
defer e.lock.RUnlock()
if e.invalidated {
return nil, &InvalidElementErr{}
}
return e.node, nil
} | go | func (e *Element) GetDebuggerDOMNode() (*gcdapi.DOMNode, error) {
if !e.IsReady() {
return nil, &ElementNotReadyErr{}
}
e.lock.RLock()
defer e.lock.RUnlock()
if e.invalidated {
return nil, &InvalidElementErr{}
}
return e.node, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetDebuggerDOMNode",
"(",
")",
"(",
"*",
"gcdapi",
".",
"DOMNode",
",",
"error",
")",
"{",
"if",
"!",
"e",
".",
"IsReady",
"(",
")",
"{",
"return",
"nil",
",",
"&",
"ElementNotReadyErr",
"{",
"}",
"\n",
"}",
... | // Returns the underlying DOMNode for this element. Note this is potentially
// unsafe to access as we give up the ability to lock. | [
"Returns",
"the",
"underlying",
"DOMNode",
"for",
"this",
"element",
".",
"Note",
"this",
"is",
"potentially",
"unsafe",
"to",
"access",
"as",
"we",
"give",
"up",
"the",
"ability",
"to",
"lock",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L288-L299 |
152,511 | wirepair/autogcd | element.go | removeAttribute | func (e *Element) removeAttribute(name string) {
e.lock.Lock()
defer e.lock.Unlock()
delete(e.attributes, name)
} | go | func (e *Element) removeAttribute(name string) {
e.lock.Lock()
defer e.lock.Unlock()
delete(e.attributes, name)
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"removeAttribute",
"(",
"name",
"string",
")",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"delete",
"(",
"e",
".",
"attributes",
",",
"nam... | // removes the attribute from our attributes list. | [
"removes",
"the",
"attribute",
"from",
"our",
"attributes",
"list",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L310-L315 |
152,512 | wirepair/autogcd | element.go | updateCharacterData | func (e *Element) updateCharacterData(newValue string) {
e.lock.Lock()
defer e.lock.Unlock()
e.characterData = newValue
} | go | func (e *Element) updateCharacterData(newValue string) {
e.lock.Lock()
defer e.lock.Unlock()
e.characterData = newValue
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"updateCharacterData",
"(",
"newValue",
"string",
")",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"e",
".",
"characterData",
"=",
"newValue",
... | // updates character data | [
"updates",
"character",
"data"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L318-L323 |
152,513 | wirepair/autogcd | element.go | updateChildNodeCount | func (e *Element) updateChildNodeCount(newValue int) {
e.lock.Lock()
defer e.lock.Unlock()
e.childNodeCount = newValue
} | go | func (e *Element) updateChildNodeCount(newValue int) {
e.lock.Lock()
defer e.lock.Unlock()
e.childNodeCount = newValue
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"updateChildNodeCount",
"(",
"newValue",
"int",
")",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"e",
".",
"childNodeCount",
"=",
"newValue",
... | // updates child node counts. | [
"updates",
"child",
"node",
"counts",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L326-L331 |
152,514 | wirepair/autogcd | element.go | addChild | func (e *Element) addChild(child *gcdapi.DOMNode) {
e.lock.Lock()
defer e.lock.Unlock()
if e.node == nil {
return
}
if e.node.Children == nil {
e.node.Children = make([]*gcdapi.DOMNode, 0)
}
e.node.Children = append(e.node.Children, child)
e.childNodeCount++
} | go | func (e *Element) addChild(child *gcdapi.DOMNode) {
e.lock.Lock()
defer e.lock.Unlock()
if e.node == nil {
return
}
if e.node.Children == nil {
e.node.Children = make([]*gcdapi.DOMNode, 0)
}
e.node.Children = append(e.node.Children, child)
e.childNodeCount++
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"addChild",
"(",
"child",
"*",
"gcdapi",
".",
"DOMNode",
")",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"e",
".",
"node",
"==",
... | // adds the child to our DOMNode. | [
"adds",
"the",
"child",
"to",
"our",
"DOMNode",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L334-L347 |
152,515 | wirepair/autogcd | element.go | addChildren | func (e *Element) addChildren(childNodes []*gcdapi.DOMNode) {
for _, child := range childNodes {
if child != nil {
e.addChild(child)
}
}
} | go | func (e *Element) addChildren(childNodes []*gcdapi.DOMNode) {
for _, child := range childNodes {
if child != nil {
e.addChild(child)
}
}
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"addChildren",
"(",
"childNodes",
"[",
"]",
"*",
"gcdapi",
".",
"DOMNode",
")",
"{",
"for",
"_",
",",
"child",
":=",
"range",
"childNodes",
"{",
"if",
"child",
"!=",
"nil",
"{",
"e",
".",
"addChild",
"(",
"chi... | // adds the children to our DOMNode | [
"adds",
"the",
"children",
"to",
"our",
"DOMNode"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L350-L356 |
152,516 | wirepair/autogcd | element.go | removeChild | func (e *Element) removeChild(removedNodeId int) {
var idx int
var child *gcdapi.DOMNode
e.lock.Lock()
defer e.lock.Unlock()
if e.node == nil || e.node.Children == nil {
return
}
for idx, child = range e.node.Children {
if child != nil && child.NodeId == removedNodeId {
e.node.Children = append(e.node.Children[:idx], e.node.Children[idx+1:]...)
e.childNodeCount = e.childNodeCount - 1
break
}
}
} | go | func (e *Element) removeChild(removedNodeId int) {
var idx int
var child *gcdapi.DOMNode
e.lock.Lock()
defer e.lock.Unlock()
if e.node == nil || e.node.Children == nil {
return
}
for idx, child = range e.node.Children {
if child != nil && child.NodeId == removedNodeId {
e.node.Children = append(e.node.Children[:idx], e.node.Children[idx+1:]...)
e.childNodeCount = e.childNodeCount - 1
break
}
}
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"removeChild",
"(",
"removedNodeId",
"int",
")",
"{",
"var",
"idx",
"int",
"\n",
"var",
"child",
"*",
"gcdapi",
".",
"DOMNode",
"\n\n",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",... | // removes the child from our DOMNode | [
"removes",
"the",
"child",
"from",
"our",
"DOMNode"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L359-L377 |
152,517 | wirepair/autogcd | element.go | GetChildNodeIds | func (e *Element) GetChildNodeIds() ([]int, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return nil, &ElementNotReadyErr{}
}
if e.node == nil || e.node.Children == nil {
return nil, &ElementHasNoChildrenErr{}
}
ids := make([]int, len(e.node.Children))
for k, child := range e.node.Children {
ids[k] = child.NodeId
}
return ids, nil
} | go | func (e *Element) GetChildNodeIds() ([]int, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return nil, &ElementNotReadyErr{}
}
if e.node == nil || e.node.Children == nil {
return nil, &ElementHasNoChildrenErr{}
}
ids := make([]int, len(e.node.Children))
for k, child := range e.node.Children {
ids[k] = child.NodeId
}
return ids, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetChildNodeIds",
"(",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"!",
"e",
"."... | // Get child node ids, returns nil if node is not ready | [
"Get",
"child",
"node",
"ids",
"returns",
"nil",
"if",
"node",
"is",
"not",
"ready"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L380-L397 |
152,518 | wirepair/autogcd | element.go | GetNodeType | func (e *Element) GetNodeType() (int, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return -1, &ElementNotReadyErr{}
}
return e.nodeType, nil
} | go | func (e *Element) GetNodeType() (int, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return -1, &ElementNotReadyErr{}
}
return e.nodeType, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetNodeType",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"!",
"e",
".",
"ready",
"{"... | // Returns the node type if the element is in a ready state. | [
"Returns",
"the",
"node",
"type",
"if",
"the",
"element",
"is",
"in",
"a",
"ready",
"state",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L411-L419 |
152,519 | wirepair/autogcd | element.go | GetCharacterData | func (e *Element) GetCharacterData() (string, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return "", &ElementNotReadyErr{}
}
return e.characterData, nil
} | go | func (e *Element) GetCharacterData() (string, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return "", &ElementNotReadyErr{}
}
return e.characterData, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetCharacterData",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"!",
"e",
".",
"ready... | // Returns the character data if the element is in a ready state. | [
"Returns",
"the",
"character",
"data",
"if",
"the",
"element",
"is",
"in",
"a",
"ready",
"state",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L422-L431 |
152,520 | wirepair/autogcd | element.go | IsEnabled | func (e *Element) IsEnabled() (bool, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return false, &ElementNotReadyErr{}
}
disabled, ok := e.attributes["disabled"]
// if the attribute doesn't exist, it's enabled.
if !ok {
return true, nil
}
if disabled == "true" || disabled == "" {
return false, nil
}
return true, nil
} | go | func (e *Element) IsEnabled() (bool, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return false, &ElementNotReadyErr{}
}
disabled, ok := e.attributes["disabled"]
// if the attribute doesn't exist, it's enabled.
if !ok {
return true, nil
}
if disabled == "true" || disabled == "" {
return false, nil
}
return true, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"IsEnabled",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"!",
"e",
".",
"ready",
"{",... | // Returns true if the node is enabled, only makes sense for form controls.
// Element must be in a ready state. | [
"Returns",
"true",
"if",
"the",
"node",
"is",
"enabled",
"only",
"makes",
"sense",
"for",
"form",
"controls",
".",
"Element",
"must",
"be",
"in",
"a",
"ready",
"state",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L435-L451 |
152,521 | wirepair/autogcd | element.go | IsSelected | func (e *Element) IsSelected() (bool, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return false, &ElementNotReadyErr{}
}
checked, ok := e.attributes["checked"]
if ok == true && checked != "false" {
return true, nil
}
return false, nil
} | go | func (e *Element) IsSelected() (bool, error) {
e.lock.RLock()
defer e.lock.RUnlock()
if !e.ready {
return false, &ElementNotReadyErr{}
}
checked, ok := e.attributes["checked"]
if ok == true && checked != "false" {
return true, nil
}
return false, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"IsSelected",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"!",
"e",
".",
"ready",
"{"... | // Simulate WebDrivers checked propertyname check | [
"Simulate",
"WebDrivers",
"checked",
"propertyname",
"check"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L454-L467 |
152,522 | wirepair/autogcd | element.go | GetCssInlineStyleText | func (e *Element) GetCssInlineStyleText() (string, string, error) {
e.lock.RLock()
inline, attribute, err := e.tab.CSS.GetInlineStylesForNode(e.id)
e.lock.RUnlock()
if err != nil {
return "", "", err
}
return inline.CssText, attribute.CssText, nil
} | go | func (e *Element) GetCssInlineStyleText() (string, string, error) {
e.lock.RLock()
inline, attribute, err := e.tab.CSS.GetInlineStylesForNode(e.id)
e.lock.RUnlock()
if err != nil {
return "", "", err
}
return inline.CssText, attribute.CssText, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetCssInlineStyleText",
"(",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"inline",
",",
"attribute",
",",
"err",
":=",
"e",
".",
"tab",
".",
"C... | // Returns the CSS Style Text of the element, returns the inline style first
// and the attribute style second, or error. | [
"Returns",
"the",
"CSS",
"Style",
"Text",
"of",
"the",
"element",
"returns",
"the",
"inline",
"style",
"first",
"and",
"the",
"attribute",
"style",
"second",
"or",
"error",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L471-L480 |
152,523 | wirepair/autogcd | element.go | GetComputedCssStyle | func (e *Element) GetComputedCssStyle() (map[string]string, error) {
e.lock.RLock()
styles, err := e.tab.CSS.GetComputedStyleForNode(e.id)
e.lock.RUnlock()
if err != nil {
return nil, err
}
styleMap := make(map[string]string, len(styles))
for _, style := range styles {
styleMap[style.Name] = style.Value
}
return styleMap, nil
} | go | func (e *Element) GetComputedCssStyle() (map[string]string, error) {
e.lock.RLock()
styles, err := e.tab.CSS.GetComputedStyleForNode(e.id)
e.lock.RUnlock()
if err != nil {
return nil, err
}
styleMap := make(map[string]string, len(styles))
for _, style := range styles {
styleMap[style.Name] = style.Value
}
return styleMap, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetComputedCssStyle",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"styles",
",",
"err",
":=",
"e",
".",
"tab",
".",
"CSS",
"... | // Returns all of the computed css styles in form of name value map. | [
"Returns",
"all",
"of",
"the",
"computed",
"css",
"styles",
"in",
"form",
"of",
"name",
"value",
"map",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L483-L496 |
152,524 | wirepair/autogcd | element.go | GetAttributes | func (e *Element) GetAttributes() (map[string]string, error) {
e.lock.RLock()
attr, err := e.tab.DOM.GetAttributes(e.id)
e.lock.RUnlock()
if err != nil {
return nil, err
}
for i := 0; i < len(attr); i += 2 {
e.updateAttribute(attr[i], attr[i+1])
}
return e.attributes, nil
} | go | func (e *Element) GetAttributes() (map[string]string, error) {
e.lock.RLock()
attr, err := e.tab.DOM.GetAttributes(e.id)
e.lock.RUnlock()
if err != nil {
return nil, err
}
for i := 0; i < len(attr); i += 2 {
e.updateAttribute(attr[i], attr[i+1])
}
return e.attributes, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetAttributes",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"attr",
",",
"err",
":=",
"e",
".",
"tab",
".",
"DOM",
".",
"G... | // Get attributes of the node returning a map of name,value pairs. | [
"Get",
"attributes",
"of",
"the",
"node",
"returning",
"a",
"map",
"of",
"name",
"value",
"pairs",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L499-L512 |
152,525 | wirepair/autogcd | element.go | GetAttribute | func (e *Element) GetAttribute(name string) string {
attr, err := e.GetAttributes()
if err != nil {
return ""
}
return attr[name]
} | go | func (e *Element) GetAttribute(name string) string {
attr, err := e.GetAttributes()
if err != nil {
return ""
}
return attr[name]
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"GetAttribute",
"(",
"name",
"string",
")",
"string",
"{",
"attr",
",",
"err",
":=",
"e",
".",
"GetAttributes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
... | // Gets a single attribute by name, returns empty string if it does not exist
// or is empty. | [
"Gets",
"a",
"single",
"attribute",
"by",
"name",
"returns",
"empty",
"string",
"if",
"it",
"does",
"not",
"exist",
"or",
"is",
"empty",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L516-L522 |
152,526 | wirepair/autogcd | element.go | SetAttributeValue | func (e *Element) SetAttributeValue(name, value string) error {
e.lock.Lock()
defer e.lock.Unlock()
_, err := e.tab.DOM.SetAttributeValue(e.id, name, value)
if err != nil {
return err
}
e.attributes[name] = value
return nil
} | go | func (e *Element) SetAttributeValue(name, value string) error {
e.lock.Lock()
defer e.lock.Unlock()
_, err := e.tab.DOM.SetAttributeValue(e.id, name, value)
if err != nil {
return err
}
e.attributes[name] = value
return nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"SetAttributeValue",
"(",
"name",
",",
"value",
"string",
")",
"error",
"{",
"e",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"_",
",",
"err",
":=",
... | // SetAttributeValue sets an element's attribute with name to value. | [
"SetAttributeValue",
"sets",
"an",
"element",
"s",
"attribute",
"with",
"name",
"to",
"value",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L537-L549 |
152,527 | wirepair/autogcd | element.go | Click | func (e *Element) Click() error {
x, y, err := e.getCenter()
if err != nil {
return err
}
// click the centroid of the element.
return e.tab.Click(float64(x), float64(y))
} | go | func (e *Element) Click() error {
x, y, err := e.getCenter()
if err != nil {
return err
}
// click the centroid of the element.
return e.tab.Click(float64(x), float64(y))
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"Click",
"(",
")",
"error",
"{",
"x",
",",
"y",
",",
"err",
":=",
"e",
".",
"getCenter",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// click the centroid of the element."... | // Clicks the center of the element. | [
"Clicks",
"the",
"center",
"of",
"the",
"element",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L575-L583 |
152,528 | wirepair/autogcd | element.go | Focus | func (e *Element) Focus() error {
e.lock.RLock()
defer e.lock.RUnlock()
params := &gcdapi.DOMFocusParams{
NodeId: e.id,
}
_, err := e.tab.DOM.FocusWithParams(params)
return err
} | go | func (e *Element) Focus() error {
e.lock.RLock()
defer e.lock.RUnlock()
params := &gcdapi.DOMFocusParams{
NodeId: e.id,
}
_, err := e.tab.DOM.FocusWithParams(params)
return err
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"Focus",
"(",
")",
"error",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"params",
":=",
"&",
"gcdapi",
".",
"DOMFocusParams",
"{",
"NodeI... | // Focus on the element. | [
"Focus",
"on",
"the",
"element",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L596-L605 |
152,529 | wirepair/autogcd | element.go | MouseOver | func (e *Element) MouseOver() error {
x, y, err := e.getCenter()
if err != nil {
return err
}
return e.tab.MoveMouse(float64(x), float64(y))
} | go | func (e *Element) MouseOver() error {
x, y, err := e.getCenter()
if err != nil {
return err
}
return e.tab.MoveMouse(float64(x), float64(y))
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"MouseOver",
"(",
")",
"error",
"{",
"x",
",",
"y",
",",
"err",
":=",
"e",
".",
"getCenter",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"e",
".",
"tab",
".... | // moves the mouse over the center of the element. | [
"moves",
"the",
"mouse",
"over",
"the",
"center",
"of",
"the",
"element",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L608-L614 |
152,530 | wirepair/autogcd | element.go | Dimensions | func (e *Element) Dimensions() ([]float64, error) {
var points []float64
e.lock.RLock()
params := &gcdapi.DOMGetBoxModelParams{
NodeId: e.id,
}
box, err := e.tab.DOM.GetBoxModelWithParams(params)
e.lock.RUnlock()
if err != nil {
return nil, err
}
points = box.Content
return points, nil
} | go | func (e *Element) Dimensions() ([]float64, error) {
var points []float64
e.lock.RLock()
params := &gcdapi.DOMGetBoxModelParams{
NodeId: e.id,
}
box, err := e.tab.DOM.GetBoxModelWithParams(params)
e.lock.RUnlock()
if err != nil {
return nil, err
}
points = box.Content
return points, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"Dimensions",
"(",
")",
"(",
"[",
"]",
"float64",
",",
"error",
")",
"{",
"var",
"points",
"[",
"]",
"float64",
"\n",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n\n",
"params",
":=",
"&",
"gcdapi",
".",
"... | // Returns the dimensions of the element. | [
"Returns",
"the",
"dimensions",
"of",
"the",
"element",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L617-L633 |
152,531 | wirepair/autogcd | element.go | getCenter | func (e *Element) getCenter() (int, int, error) {
points, err := e.Dimensions()
if err != nil {
return 0, 0, err
}
x, y, err := centroid(points)
if err != nil {
return 0, 0, err
}
return x, y, nil
} | go | func (e *Element) getCenter() (int, int, error) {
points, err := e.Dimensions()
if err != nil {
return 0, 0, err
}
x, y, err := centroid(points)
if err != nil {
return 0, 0, err
}
return x, y, nil
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"getCenter",
"(",
")",
"(",
"int",
",",
"int",
",",
"error",
")",
"{",
"points",
",",
"err",
":=",
"e",
".",
"Dimensions",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"er... | // gets the center of the element | [
"gets",
"the",
"center",
"of",
"the",
"element"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L636-L647 |
152,532 | wirepair/autogcd | element.go | String | func (e *Element) String() string {
e.lock.RLock()
defer e.lock.RUnlock()
output := fmt.Sprintf("NodeId: %d Invalid: %t Ready: %t", e.id, e.invalidated, e.ready)
if !e.ready {
return output
}
attrs := ""
for key, value := range e.attributes {
attrs = attrs + "\t" + key + "=" + value + "\n"
}
output = fmt.Sprintf("%s NodeType: %d TagName: %s characterData: %s childNodeCount: %d attributes (%d): \n%s", output, e.nodeType, e.nodeName, e.characterData, e.childNodeCount, len(e.attributes), attrs)
if e.nodeType == int(DOCUMENT_NODE) {
output = fmt.Sprintf("%s FrameId: %s documentURL: %s\n", output, e.node.FrameId, e.node.DocumentURL)
}
//output = fmt.Sprintf("%s %#v", output, e.node)
return output
} | go | func (e *Element) String() string {
e.lock.RLock()
defer e.lock.RUnlock()
output := fmt.Sprintf("NodeId: %d Invalid: %t Ready: %t", e.id, e.invalidated, e.ready)
if !e.ready {
return output
}
attrs := ""
for key, value := range e.attributes {
attrs = attrs + "\t" + key + "=" + value + "\n"
}
output = fmt.Sprintf("%s NodeType: %d TagName: %s characterData: %s childNodeCount: %d attributes (%d): \n%s", output, e.nodeType, e.nodeName, e.characterData, e.childNodeCount, len(e.attributes), attrs)
if e.nodeType == int(DOCUMENT_NODE) {
output = fmt.Sprintf("%s FrameId: %s documentURL: %s\n", output, e.node.FrameId, e.node.DocumentURL)
}
//output = fmt.Sprintf("%s %#v", output, e.node)
return output
} | [
"func",
"(",
"e",
"*",
"Element",
")",
"String",
"(",
")",
"string",
"{",
"e",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"e",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n",
"output",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
... | // Gnarly output mode activated | [
"Gnarly",
"output",
"mode",
"activated"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/element.go#L661-L678 |
152,533 | drone/go-github | github/repo_keys.go | Create | func (r *RepoKeyResource) Create(owner, repo, key, title string) (*Key, error) {
in := Key{Title: title, Key: key}
out := Key{}
path := fmt.Sprintf("/repos/%s/%s/keys", owner, repo)
if err := r.client.do("POST", path, &in, &out); err != nil {
return nil, err
}
return &out, nil
} | go | func (r *RepoKeyResource) Create(owner, repo, key, title string) (*Key, error) {
in := Key{Title: title, Key: key}
out := Key{}
path := fmt.Sprintf("/repos/%s/%s/keys", owner, repo)
if err := r.client.do("POST", path, &in, &out); err != nil {
return nil, err
}
return &out, nil
} | [
"func",
"(",
"r",
"*",
"RepoKeyResource",
")",
"Create",
"(",
"owner",
",",
"repo",
",",
"key",
",",
"title",
"string",
")",
"(",
"*",
"Key",
",",
"error",
")",
"{",
"in",
":=",
"Key",
"{",
"Title",
":",
"title",
",",
"Key",
":",
"key",
"}",
"\... | // Creates a key on the specified repo. You must supply a valid key
// that is unique across the Github service. | [
"Creates",
"a",
"key",
"on",
"the",
"specified",
"repo",
".",
"You",
"must",
"supply",
"a",
"valid",
"key",
"that",
"is",
"unique",
"across",
"the",
"Github",
"service",
"."
] | 323fe992f17d4e42a048c8406b034863c925cbdc | https://github.com/drone/go-github/blob/323fe992f17d4e42a048c8406b034863c925cbdc/github/repo_keys.go#L52-L62 |
152,534 | drone/go-github | github/repo_keys.go | CreateUpdate | func (r *RepoKeyResource) CreateUpdate(owner, repo, key, title string) (*Key, error) {
if found, err := r.FindName(owner, repo, title); err == nil {
// if the public keys are different we should update
if found.Key != key {
return r.Update(owner, repo, key, title, found.Id)
}
// otherwise we should just return the key, since there
// is nothing to update
return found, nil
}
return r.Create(owner, repo, key, title)
} | go | func (r *RepoKeyResource) CreateUpdate(owner, repo, key, title string) (*Key, error) {
if found, err := r.FindName(owner, repo, title); err == nil {
// if the public keys are different we should update
if found.Key != key {
return r.Update(owner, repo, key, title, found.Id)
}
// otherwise we should just return the key, since there
// is nothing to update
return found, nil
}
return r.Create(owner, repo, key, title)
} | [
"func",
"(",
"r",
"*",
"RepoKeyResource",
")",
"CreateUpdate",
"(",
"owner",
",",
"repo",
",",
"key",
",",
"title",
"string",
")",
"(",
"*",
"Key",
",",
"error",
")",
"{",
"if",
"found",
",",
"err",
":=",
"r",
".",
"FindName",
"(",
"owner",
",",
... | // Creates a key for the specified repo, assuming it does not already
// exist in the system | [
"Creates",
"a",
"key",
"for",
"the",
"specified",
"repo",
"assuming",
"it",
"does",
"not",
"already",
"exist",
"in",
"the",
"system"
] | 323fe992f17d4e42a048c8406b034863c925cbdc | https://github.com/drone/go-github/blob/323fe992f17d4e42a048c8406b034863c925cbdc/github/repo_keys.go#L81-L94 |
152,535 | drone/go-github | github/repo_keys.go | Delete | func (r *RepoKeyResource) Delete(owner, repo string, id int) error {
path := fmt.Sprintf("/repos/%s/%s/keys/%v", owner, repo, id)
return r.client.do("DELETE", path, nil, nil)
} | go | func (r *RepoKeyResource) Delete(owner, repo string, id int) error {
path := fmt.Sprintf("/repos/%s/%s/keys/%v", owner, repo, id)
return r.client.do("DELETE", path, nil, nil)
} | [
"func",
"(",
"r",
"*",
"RepoKeyResource",
")",
"Delete",
"(",
"owner",
",",
"repo",
"string",
",",
"id",
"int",
")",
"error",
"{",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"owner",
",",
"repo",
",",
"id",
")",
"\n",
"return",
"r... | // Deletes the key specified by the id value. | [
"Deletes",
"the",
"key",
"specified",
"by",
"the",
"id",
"value",
"."
] | 323fe992f17d4e42a048c8406b034863c925cbdc | https://github.com/drone/go-github/blob/323fe992f17d4e42a048c8406b034863c925cbdc/github/repo_keys.go#L106-L109 |
152,536 | JustinBeckwith/go-yelp | yelp/yelp.go | DoSimpleSearch | func (client *Client) DoSimpleSearch(term, location string) (result SearchResult, err error) {
// verify the term and location are not empty
if location == "" {
return SearchResult{}, errUnspecifiedLocation
}
// set up the query options
params := map[string]string{
"term": term,
"location": location,
}
// perform the search request
_, err = client.makeRequest(searchArea, "", params, &result)
if err != nil {
return SearchResult{}, err
}
return result, nil
} | go | func (client *Client) DoSimpleSearch(term, location string) (result SearchResult, err error) {
// verify the term and location are not empty
if location == "" {
return SearchResult{}, errUnspecifiedLocation
}
// set up the query options
params := map[string]string{
"term": term,
"location": location,
}
// perform the search request
_, err = client.makeRequest(searchArea, "", params, &result)
if err != nil {
return SearchResult{}, err
}
return result, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"DoSimpleSearch",
"(",
"term",
",",
"location",
"string",
")",
"(",
"result",
"SearchResult",
",",
"err",
"error",
")",
"{",
"// verify the term and location are not empty",
"if",
"location",
"==",
"\"",
"\"",
"{",
"r... | // DoSimpleSearch performs a simple search with a term and location. | [
"DoSimpleSearch",
"performs",
"a",
"simple",
"search",
"with",
"a",
"term",
"and",
"location",
"."
] | 2228f91f3d151c1cd01f8e916b5cc89741b6ac92 | https://github.com/JustinBeckwith/go-yelp/blob/2228f91f3d151c1cd01f8e916b5cc89741b6ac92/yelp/yelp.go#L43-L62 |
152,537 | JustinBeckwith/go-yelp | yelp/yelp.go | DoSearch | func (client *Client) DoSearch(options SearchOptions) (result SearchResult, err error) {
// get the options from the search provider
params, err := options.getParameters()
if err != nil {
return SearchResult{}, err
}
// perform the search request
_, err = client.makeRequest(searchArea, "", params, &result)
if err != nil {
return SearchResult{}, err
}
return result, nil
} | go | func (client *Client) DoSearch(options SearchOptions) (result SearchResult, err error) {
// get the options from the search provider
params, err := options.getParameters()
if err != nil {
return SearchResult{}, err
}
// perform the search request
_, err = client.makeRequest(searchArea, "", params, &result)
if err != nil {
return SearchResult{}, err
}
return result, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"DoSearch",
"(",
"options",
"SearchOptions",
")",
"(",
"result",
"SearchResult",
",",
"err",
"error",
")",
"{",
"// get the options from the search provider",
"params",
",",
"err",
":=",
"options",
".",
"getParameters",
... | // DoSearch performs a complex search with full search options. | [
"DoSearch",
"performs",
"a",
"complex",
"search",
"with",
"full",
"search",
"options",
"."
] | 2228f91f3d151c1cd01f8e916b5cc89741b6ac92 | https://github.com/JustinBeckwith/go-yelp/blob/2228f91f3d151c1cd01f8e916b5cc89741b6ac92/yelp/yelp.go#L65-L79 |
152,538 | JustinBeckwith/go-yelp | yelp/yelp.go | GetBusiness | func (client *Client) GetBusiness(name string) (result Business, err error) {
statusCode, err := client.makeRequest(businessArea, name, nil, &result)
if err != nil {
// At some point the Yelp API stopped reporting 404s for missing business names, and
// started reporting 400s :(
if statusCode == 400 {
return Business{}, errBusinessNotFound
}
return Business{}, err
}
return result, nil
} | go | func (client *Client) GetBusiness(name string) (result Business, err error) {
statusCode, err := client.makeRequest(businessArea, name, nil, &result)
if err != nil {
// At some point the Yelp API stopped reporting 404s for missing business names, and
// started reporting 400s :(
if statusCode == 400 {
return Business{}, errBusinessNotFound
}
return Business{}, err
}
return result, nil
} | [
"func",
"(",
"client",
"*",
"Client",
")",
"GetBusiness",
"(",
"name",
"string",
")",
"(",
"result",
"Business",
",",
"err",
"error",
")",
"{",
"statusCode",
",",
"err",
":=",
"client",
".",
"makeRequest",
"(",
"businessArea",
",",
"name",
",",
"nil",
... | // GetBusiness obtains a single business by name. | [
"GetBusiness",
"obtains",
"a",
"single",
"business",
"by",
"name",
"."
] | 2228f91f3d151c1cd01f8e916b5cc89741b6ac92 | https://github.com/JustinBeckwith/go-yelp/blob/2228f91f3d151c1cd01f8e916b5cc89741b6ac92/yelp/yelp.go#L82-L93 |
152,539 | JustinBeckwith/go-yelp | yelp/yelp.go | New | func New(options *AuthOptions, httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
return &Client{
Options: options,
Client: httpClient,
}
} | go | func New(options *AuthOptions, httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
return &Client{
Options: options,
Client: httpClient,
}
} | [
"func",
"New",
"(",
"options",
"*",
"AuthOptions",
",",
"httpClient",
"*",
"http",
".",
"Client",
")",
"*",
"Client",
"{",
"if",
"httpClient",
"==",
"nil",
"{",
"httpClient",
"=",
"http",
".",
"DefaultClient",
"\n",
"}",
"\n\n",
"return",
"&",
"Client",
... | // New will create a new yelp search client. All search operations should go through this API. | [
"New",
"will",
"create",
"a",
"new",
"yelp",
"search",
"client",
".",
"All",
"search",
"operations",
"should",
"go",
"through",
"this",
"API",
"."
] | 2228f91f3d151c1cd01f8e916b5cc89741b6ac92 | https://github.com/JustinBeckwith/go-yelp/blob/2228f91f3d151c1cd01f8e916b5cc89741b6ac92/yelp/yelp.go#L151-L160 |
152,540 | drone/go-github | github/emails.go | List | func (r *EmailResource) List() ([]*Email, error) {
emails := []*Email{}
if err := r.client.do("GET", "/user/emails", nil, &emails); err != nil {
return nil, err
}
return emails, nil
} | go | func (r *EmailResource) List() ([]*Email, error) {
emails := []*Email{}
if err := r.client.do("GET", "/user/emails", nil, &emails); err != nil {
return nil, err
}
return emails, nil
} | [
"func",
"(",
"r",
"*",
"EmailResource",
")",
"List",
"(",
")",
"(",
"[",
"]",
"*",
"Email",
",",
"error",
")",
"{",
"emails",
":=",
"[",
"]",
"*",
"Email",
"{",
"}",
"\n",
"if",
"err",
":=",
"r",
".",
"client",
".",
"do",
"(",
"\"",
"\"",
"... | // Gets the email addresses associated with the account. | [
"Gets",
"the",
"email",
"addresses",
"associated",
"with",
"the",
"account",
"."
] | 323fe992f17d4e42a048c8406b034863c925cbdc | https://github.com/drone/go-github/blob/323fe992f17d4e42a048c8406b034863c925cbdc/github/emails.go#L21-L28 |
152,541 | drone/go-github | github/emails.go | Find | func (r *EmailResource) Find(address string) (*Email, error) {
emails, err := r.List()
if err != nil {
return nil, err
}
for _, email := range emails {
if email.Email == address {
return email, nil
}
}
return nil, ErrNotFound
} | go | func (r *EmailResource) Find(address string) (*Email, error) {
emails, err := r.List()
if err != nil {
return nil, err
}
for _, email := range emails {
if email.Email == address {
return email, nil
}
}
return nil, ErrNotFound
} | [
"func",
"(",
"r",
"*",
"EmailResource",
")",
"Find",
"(",
"address",
"string",
")",
"(",
"*",
"Email",
",",
"error",
")",
"{",
"emails",
",",
"err",
":=",
"r",
".",
"List",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"e... | // Gets an individual email address associated with an account. | [
"Gets",
"an",
"individual",
"email",
"address",
"associated",
"with",
"an",
"account",
"."
] | 323fe992f17d4e42a048c8406b034863c925cbdc | https://github.com/drone/go-github/blob/323fe992f17d4e42a048c8406b034863c925cbdc/github/emails.go#L31-L44 |
152,542 | drone/go-github | github/emails.go | Create | func (r *EmailResource) Create(address string) (error) {
emails := []string{ address }
if err := r.client.do("POST", "/user/emails", &emails, nil); err != nil {
return err
}
return nil
} | go | func (r *EmailResource) Create(address string) (error) {
emails := []string{ address }
if err := r.client.do("POST", "/user/emails", &emails, nil); err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"EmailResource",
")",
"Create",
"(",
"address",
"string",
")",
"(",
"error",
")",
"{",
"emails",
":=",
"[",
"]",
"string",
"{",
"address",
"}",
"\n",
"if",
"err",
":=",
"r",
".",
"client",
".",
"do",
"(",
"\"",
"\"",
",",
... | // Adds additional email addresses to an account. | [
"Adds",
"additional",
"email",
"addresses",
"to",
"an",
"account",
"."
] | 323fe992f17d4e42a048c8406b034863c925cbdc | https://github.com/drone/go-github/blob/323fe992f17d4e42a048c8406b034863c925cbdc/github/emails.go#L63-L70 |
152,543 | wirepair/autogcd | examples/googler/googler.go | configureTab | func configureTab(tab *autogcd.Tab) {
tab.SetNavigationTimeout(navigationTimeout) // give up after 10 seconds for navigating, default is 30 seconds
tab.SetStabilityTime(stableAfter)
if debug {
domHandlerFn := func(tab *autogcd.Tab, change *autogcd.NodeChangeEvent) {
log.Printf("change event %s occurred\n", change.EventType)
}
tab.GetDOMChanges(domHandlerFn)
}
} | go | func configureTab(tab *autogcd.Tab) {
tab.SetNavigationTimeout(navigationTimeout) // give up after 10 seconds for navigating, default is 30 seconds
tab.SetStabilityTime(stableAfter)
if debug {
domHandlerFn := func(tab *autogcd.Tab, change *autogcd.NodeChangeEvent) {
log.Printf("change event %s occurred\n", change.EventType)
}
tab.GetDOMChanges(domHandlerFn)
}
} | [
"func",
"configureTab",
"(",
"tab",
"*",
"autogcd",
".",
"Tab",
")",
"{",
"tab",
".",
"SetNavigationTimeout",
"(",
"navigationTimeout",
")",
"// give up after 10 seconds for navigating, default is 30 seconds",
"\n",
"tab",
".",
"SetStabilityTime",
"(",
"stableAfter",
")... | // Set various timeouts | [
"Set",
"various",
"timeouts"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/examples/googler/googler.go#L108-L117 |
152,544 | urakozz/go-json-schema-generator | generator.go | Read | func (d *Document) Read(variable interface{}) *Document {
d.setDefaultSchema()
value := reflect.ValueOf(variable)
d.read(value.Type())
return d
} | go | func (d *Document) Read(variable interface{}) *Document {
d.setDefaultSchema()
value := reflect.ValueOf(variable)
d.read(value.Type())
return d
} | [
"func",
"(",
"d",
"*",
"Document",
")",
"Read",
"(",
"variable",
"interface",
"{",
"}",
")",
"*",
"Document",
"{",
"d",
".",
"setDefaultSchema",
"(",
")",
"\n\n",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"variable",
")",
"\n",
"d",
".",
"read",... | // Reads the variable structure into the JSON-Schema Document | [
"Reads",
"the",
"variable",
"structure",
"into",
"the",
"JSON",
"-",
"Schema",
"Document"
] | 645b0ded705ed7cec8c301e3bf11df8a4e544551 | https://github.com/urakozz/go-json-schema-generator/blob/645b0ded705ed7cec8c301e3bf11df8a4e544551/generator.go#L33-L39 |
152,545 | urakozz/go-json-schema-generator | generator.go | int64ptr | func int64ptr(i interface{}) *int64 {
v := reflect.ValueOf(i)
if !v.Type().ConvertibleTo(rTypeInt64) {
return nil
}
j := v.Convert(rTypeInt64).Interface().(int64)
return &j
} | go | func int64ptr(i interface{}) *int64 {
v := reflect.ValueOf(i)
if !v.Type().ConvertibleTo(rTypeInt64) {
return nil
}
j := v.Convert(rTypeInt64).Interface().(int64)
return &j
} | [
"func",
"int64ptr",
"(",
"i",
"interface",
"{",
"}",
")",
"*",
"int64",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"i",
")",
"\n",
"if",
"!",
"v",
".",
"Type",
"(",
")",
".",
"ConvertibleTo",
"(",
"rTypeInt64",
")",
"{",
"return",
"nil",
"\n... | // Some helper functions for not having to create temp variables all over the place | [
"Some",
"helper",
"functions",
"for",
"not",
"having",
"to",
"create",
"temp",
"variables",
"all",
"over",
"the",
"place"
] | 645b0ded705ed7cec8c301e3bf11df8a4e544551 | https://github.com/urakozz/go-json-schema-generator/blob/645b0ded705ed7cec8c301e3bf11df8a4e544551/generator.go#L176-L183 |
152,546 | wirepair/autogcd | conditionals.go | UrlEquals | func UrlEquals(tab *Tab, equalsUrl string) ConditionalFunc {
return func(tab *Tab) bool {
if url, err := tab.GetCurrentUrl(); err == nil && url == equalsUrl {
return true
}
return false
}
} | go | func UrlEquals(tab *Tab, equalsUrl string) ConditionalFunc {
return func(tab *Tab) bool {
if url, err := tab.GetCurrentUrl(); err == nil && url == equalsUrl {
return true
}
return false
}
} | [
"func",
"UrlEquals",
"(",
"tab",
"*",
"Tab",
",",
"equalsUrl",
"string",
")",
"ConditionalFunc",
"{",
"return",
"func",
"(",
"tab",
"*",
"Tab",
")",
"bool",
"{",
"if",
"url",
",",
"err",
":=",
"tab",
".",
"GetCurrentUrl",
"(",
")",
";",
"err",
"==",
... | // Returns true when the current url equals the equalsUrl | [
"Returns",
"true",
"when",
"the",
"current",
"url",
"equals",
"the",
"equalsUrl"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/conditionals.go#L32-L39 |
152,547 | wirepair/autogcd | conditionals.go | UrlContains | func UrlContains(tab *Tab, containsUrl string) ConditionalFunc {
return func(tab *Tab) bool {
if url, err := tab.GetCurrentUrl(); err == nil && strings.Contains(url, containsUrl) {
return true
}
return false
}
} | go | func UrlContains(tab *Tab, containsUrl string) ConditionalFunc {
return func(tab *Tab) bool {
if url, err := tab.GetCurrentUrl(); err == nil && strings.Contains(url, containsUrl) {
return true
}
return false
}
} | [
"func",
"UrlContains",
"(",
"tab",
"*",
"Tab",
",",
"containsUrl",
"string",
")",
"ConditionalFunc",
"{",
"return",
"func",
"(",
"tab",
"*",
"Tab",
")",
"bool",
"{",
"if",
"url",
",",
"err",
":=",
"tab",
".",
"GetCurrentUrl",
"(",
")",
";",
"err",
"=... | // Returns true when the current url contains the containsUrl | [
"Returns",
"true",
"when",
"the",
"current",
"url",
"contains",
"the",
"containsUrl"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/conditionals.go#L42-L49 |
152,548 | wirepair/autogcd | conditionals.go | TitleEquals | func TitleEquals(tab *Tab, equalsTitle string) ConditionalFunc {
return func(tab *Tab) bool {
if pageTitle, err := tab.GetTitle(); err == nil && pageTitle == equalsTitle {
return true
}
return false
}
} | go | func TitleEquals(tab *Tab, equalsTitle string) ConditionalFunc {
return func(tab *Tab) bool {
if pageTitle, err := tab.GetTitle(); err == nil && pageTitle == equalsTitle {
return true
}
return false
}
} | [
"func",
"TitleEquals",
"(",
"tab",
"*",
"Tab",
",",
"equalsTitle",
"string",
")",
"ConditionalFunc",
"{",
"return",
"func",
"(",
"tab",
"*",
"Tab",
")",
"bool",
"{",
"if",
"pageTitle",
",",
"err",
":=",
"tab",
".",
"GetTitle",
"(",
")",
";",
"err",
"... | // Returns true when the page title equals the provided equalsTitle | [
"Returns",
"true",
"when",
"the",
"page",
"title",
"equals",
"the",
"provided",
"equalsTitle"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/conditionals.go#L52-L59 |
152,549 | wirepair/autogcd | conditionals.go | TitleContains | func TitleContains(tab *Tab, searchTitle string) ConditionalFunc {
return func(tab *Tab) bool {
if pageTitle, err := tab.GetTitle(); err == nil && strings.Contains(pageTitle, searchTitle) {
return true
}
return false
}
} | go | func TitleContains(tab *Tab, searchTitle string) ConditionalFunc {
return func(tab *Tab) bool {
if pageTitle, err := tab.GetTitle(); err == nil && strings.Contains(pageTitle, searchTitle) {
return true
}
return false
}
} | [
"func",
"TitleContains",
"(",
"tab",
"*",
"Tab",
",",
"searchTitle",
"string",
")",
"ConditionalFunc",
"{",
"return",
"func",
"(",
"tab",
"*",
"Tab",
")",
"bool",
"{",
"if",
"pageTitle",
",",
"err",
":=",
"tab",
".",
"GetTitle",
"(",
")",
";",
"err",
... | // Returns true if the searchTitle is contained within the page title. | [
"Returns",
"true",
"if",
"the",
"searchTitle",
"is",
"contained",
"within",
"the",
"page",
"title",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/conditionals.go#L62-L69 |
152,550 | wirepair/autogcd | conditionals.go | ElementByIdReady | func ElementByIdReady(tab *Tab, elementAttributeId string) ConditionalFunc {
return func(tab *Tab) bool {
element, _, _ := tab.GetElementById(elementAttributeId)
return (element != nil) && (element.IsReady())
}
} | go | func ElementByIdReady(tab *Tab, elementAttributeId string) ConditionalFunc {
return func(tab *Tab) bool {
element, _, _ := tab.GetElementById(elementAttributeId)
return (element != nil) && (element.IsReady())
}
} | [
"func",
"ElementByIdReady",
"(",
"tab",
"*",
"Tab",
",",
"elementAttributeId",
"string",
")",
"ConditionalFunc",
"{",
"return",
"func",
"(",
"tab",
"*",
"Tab",
")",
"bool",
"{",
"element",
",",
"_",
",",
"_",
":=",
"tab",
".",
"GetElementById",
"(",
"ele... | // Returns true when the element exists and is ready | [
"Returns",
"true",
"when",
"the",
"element",
"exists",
"and",
"is",
"ready"
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/conditionals.go#L72-L77 |
152,551 | wirepair/autogcd | conditionals.go | ElementAttributeEquals | func ElementAttributeEquals(tab *Tab, element *Element, name, value string) ConditionalFunc {
return func(tab *Tab) bool {
if element.GetAttribute(name) == value {
return true
}
return false
}
} | go | func ElementAttributeEquals(tab *Tab, element *Element, name, value string) ConditionalFunc {
return func(tab *Tab) bool {
if element.GetAttribute(name) == value {
return true
}
return false
}
} | [
"func",
"ElementAttributeEquals",
"(",
"tab",
"*",
"Tab",
",",
"element",
"*",
"Element",
",",
"name",
",",
"value",
"string",
")",
"ConditionalFunc",
"{",
"return",
"func",
"(",
"tab",
"*",
"Tab",
")",
"bool",
"{",
"if",
"element",
".",
"GetAttribute",
... | // Returns true when the element's attribute of name equals value. | [
"Returns",
"true",
"when",
"the",
"element",
"s",
"attribute",
"of",
"name",
"equals",
"value",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/conditionals.go#L80-L87 |
152,552 | wirepair/autogcd | conditionals.go | ElementsBySelectorNotEmpty | func ElementsBySelectorNotEmpty(tab *Tab, elementSelector string) ConditionalFunc {
return func(tab *Tab) bool {
eles, err := tab.GetElementsBySelector(elementSelector)
if err == nil && len(eles) > 0 {
return true
}
return false
}
} | go | func ElementsBySelectorNotEmpty(tab *Tab, elementSelector string) ConditionalFunc {
return func(tab *Tab) bool {
eles, err := tab.GetElementsBySelector(elementSelector)
if err == nil && len(eles) > 0 {
return true
}
return false
}
} | [
"func",
"ElementsBySelectorNotEmpty",
"(",
"tab",
"*",
"Tab",
",",
"elementSelector",
"string",
")",
"ConditionalFunc",
"{",
"return",
"func",
"(",
"tab",
"*",
"Tab",
")",
"bool",
"{",
"eles",
",",
"err",
":=",
"tab",
".",
"GetElementsBySelector",
"(",
"elem... | // Returns true when a selector returns a valid list of elements. | [
"Returns",
"true",
"when",
"a",
"selector",
"returns",
"a",
"valid",
"list",
"of",
"elements",
"."
] | 80392884ea9402ba4b8ecb1eccf361611b171df8 | https://github.com/wirepair/autogcd/blob/80392884ea9402ba4b8ecb1eccf361611b171df8/conditionals.go#L90-L98 |
152,553 | JustinBeckwith/go-yelp | yelp/search_options.go | getParameters | func (o *SearchOptions) getParameters() (params map[string]string, err error) {
// ensure only one loc option provider is being used
locOptionsCnt := 0
if o.LocationOptions != nil {
locOptionsCnt++
}
if o.CoordinateOptions != nil {
locOptionsCnt++
}
if o.BoundOptions != nil {
locOptionsCnt++
}
if locOptionsCnt == 0 {
return params, errors.New("a single location search options type (Location, Coordinate, Bound) must be used")
}
if locOptionsCnt > 1 {
return params, errors.New("only a single location search options type (Location, Coordinate, Bound) can be used at a time")
}
// create an empty map of options
params = make(map[string]string)
// reflect over the properties in o, adding parameters to the global map
val := reflect.ValueOf(o).Elem()
for i := 0; i < val.NumField(); i++ {
if !val.Field(i).IsNil() {
o := val.Field(i).Interface().(OptionProvider)
fieldParams, err := o.getParameters()
if err != nil {
return params, err
}
for k, v := range fieldParams {
params[k] = v
}
}
}
return params, nil
} | go | func (o *SearchOptions) getParameters() (params map[string]string, err error) {
// ensure only one loc option provider is being used
locOptionsCnt := 0
if o.LocationOptions != nil {
locOptionsCnt++
}
if o.CoordinateOptions != nil {
locOptionsCnt++
}
if o.BoundOptions != nil {
locOptionsCnt++
}
if locOptionsCnt == 0 {
return params, errors.New("a single location search options type (Location, Coordinate, Bound) must be used")
}
if locOptionsCnt > 1 {
return params, errors.New("only a single location search options type (Location, Coordinate, Bound) can be used at a time")
}
// create an empty map of options
params = make(map[string]string)
// reflect over the properties in o, adding parameters to the global map
val := reflect.ValueOf(o).Elem()
for i := 0; i < val.NumField(); i++ {
if !val.Field(i).IsNil() {
o := val.Field(i).Interface().(OptionProvider)
fieldParams, err := o.getParameters()
if err != nil {
return params, err
}
for k, v := range fieldParams {
params[k] = v
}
}
}
return params, nil
} | [
"func",
"(",
"o",
"*",
"SearchOptions",
")",
"getParameters",
"(",
")",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
",",
"err",
"error",
")",
"{",
"// ensure only one loc option provider is being used",
"locOptionsCnt",
":=",
"0",
"\n",
"if",
"o",
".",... | // Generate a map that contains the querystring parameters for
// all of the defined options. | [
"Generate",
"a",
"map",
"that",
"contains",
"the",
"querystring",
"parameters",
"for",
"all",
"of",
"the",
"defined",
"options",
"."
] | 2228f91f3d151c1cd01f8e916b5cc89741b6ac92 | https://github.com/JustinBeckwith/go-yelp/blob/2228f91f3d151c1cd01f8e916b5cc89741b6ac92/yelp/search_options.go#L27-L66 |
152,554 | xsleonard/go-merkle | merkle.go | NewNode | func NewNode(h hash.Hash, block []byte) (Node, error) {
if h == nil {
return Node{Hash: block}, nil
}
if block == nil {
return Node{}, nil
}
defer h.Reset()
_, err := h.Write(block[:])
if err != nil {
return Node{}, err
}
return Node{Hash: h.Sum(nil)}, nil
} | go | func NewNode(h hash.Hash, block []byte) (Node, error) {
if h == nil {
return Node{Hash: block}, nil
}
if block == nil {
return Node{}, nil
}
defer h.Reset()
_, err := h.Write(block[:])
if err != nil {
return Node{}, err
}
return Node{Hash: h.Sum(nil)}, nil
} | [
"func",
"NewNode",
"(",
"h",
"hash",
".",
"Hash",
",",
"block",
"[",
"]",
"byte",
")",
"(",
"Node",
",",
"error",
")",
"{",
"if",
"h",
"==",
"nil",
"{",
"return",
"Node",
"{",
"Hash",
":",
"block",
"}",
",",
"nil",
"\n",
"}",
"\n",
"if",
"blo... | // NewNode creates a node given a hash function and data to hash. If the hash function is nil, the data
// will be added without being hashed. | [
"NewNode",
"creates",
"a",
"node",
"given",
"a",
"hash",
"function",
"and",
"data",
"to",
"hash",
".",
"If",
"the",
"hash",
"function",
"is",
"nil",
"the",
"data",
"will",
"be",
"added",
"without",
"being",
"hashed",
"."
] | 84ec7cea74067a61c2b26bea753c9612c8edc9db | https://github.com/xsleonard/go-merkle/blob/84ec7cea74067a61c2b26bea753c9612c8edc9db/merkle.go#L37-L50 |
152,555 | xsleonard/go-merkle | merkle.go | Leaves | func (self *Tree) Leaves() []Node {
if self.Levels == nil {
return nil
} else {
return self.Levels[len(self.Levels)-1]
}
} | go | func (self *Tree) Leaves() []Node {
if self.Levels == nil {
return nil
} else {
return self.Levels[len(self.Levels)-1]
}
} | [
"func",
"(",
"self",
"*",
"Tree",
")",
"Leaves",
"(",
")",
"[",
"]",
"Node",
"{",
"if",
"self",
".",
"Levels",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"else",
"{",
"return",
"self",
".",
"Levels",
"[",
"len",
"(",
"self",
".",
"Levels",
"... | // Returns a slice of the leaf nodes in the tree, if available, else nil | [
"Returns",
"a",
"slice",
"of",
"the",
"leaf",
"nodes",
"in",
"the",
"tree",
"if",
"available",
"else",
"nil"
] | 84ec7cea74067a61c2b26bea753c9612c8edc9db | https://github.com/xsleonard/go-merkle/blob/84ec7cea74067a61c2b26bea753c9612c8edc9db/merkle.go#L73-L79 |
152,556 | xsleonard/go-merkle | merkle.go | Root | func (self *Tree) Root() *Node {
if self.Nodes == nil {
return nil
} else {
return &self.Levels[0][0]
}
} | go | func (self *Tree) Root() *Node {
if self.Nodes == nil {
return nil
} else {
return &self.Levels[0][0]
}
} | [
"func",
"(",
"self",
"*",
"Tree",
")",
"Root",
"(",
")",
"*",
"Node",
"{",
"if",
"self",
".",
"Nodes",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"else",
"{",
"return",
"&",
"self",
".",
"Levels",
"[",
"0",
"]",
"[",
"0",
"]",
"\n",
"}",
... | // Returns the root node of the tree, if available, else nil | [
"Returns",
"the",
"root",
"node",
"of",
"the",
"tree",
"if",
"available",
"else",
"nil"
] | 84ec7cea74067a61c2b26bea753c9612c8edc9db | https://github.com/xsleonard/go-merkle/blob/84ec7cea74067a61c2b26bea753c9612c8edc9db/merkle.go#L82-L88 |
152,557 | xsleonard/go-merkle | merkle.go | Generate | func (self *Tree) Generate(blocks [][]byte, hashf hash.Hash) error {
blockCount := uint64(len(blocks))
if blockCount == 0 {
return errors.New("Empty tree")
}
height, nodeCount := CalculateHeightAndNodeCount(blockCount)
levels := make([][]Node, height)
nodes := make([]Node, nodeCount)
// Create the leaf nodes
for i, block := range blocks {
var node Node
var err error
if self.Options.DisableHashLeaves {
node, err = NewNode(nil, block)
} else {
node, err = NewNode(hashf, block)
}
if err != nil {
return err
}
nodes[i] = node
}
levels[height-1] = nodes[:len(blocks)]
// Create each node level
current := nodes[len(blocks):]
h := height - 1
for ; h > 0; h-- {
below := levels[h]
wrote, err := self.generateNodeLevel(below, current, hashf)
if err != nil {
return err
}
levels[h-1] = current[:wrote]
current = current[wrote:]
}
self.Nodes = nodes
self.Levels = levels
return nil
} | go | func (self *Tree) Generate(blocks [][]byte, hashf hash.Hash) error {
blockCount := uint64(len(blocks))
if blockCount == 0 {
return errors.New("Empty tree")
}
height, nodeCount := CalculateHeightAndNodeCount(blockCount)
levels := make([][]Node, height)
nodes := make([]Node, nodeCount)
// Create the leaf nodes
for i, block := range blocks {
var node Node
var err error
if self.Options.DisableHashLeaves {
node, err = NewNode(nil, block)
} else {
node, err = NewNode(hashf, block)
}
if err != nil {
return err
}
nodes[i] = node
}
levels[height-1] = nodes[:len(blocks)]
// Create each node level
current := nodes[len(blocks):]
h := height - 1
for ; h > 0; h-- {
below := levels[h]
wrote, err := self.generateNodeLevel(below, current, hashf)
if err != nil {
return err
}
levels[h-1] = current[:wrote]
current = current[wrote:]
}
self.Nodes = nodes
self.Levels = levels
return nil
} | [
"func",
"(",
"self",
"*",
"Tree",
")",
"Generate",
"(",
"blocks",
"[",
"]",
"[",
"]",
"byte",
",",
"hashf",
"hash",
".",
"Hash",
")",
"error",
"{",
"blockCount",
":=",
"uint64",
"(",
"len",
"(",
"blocks",
")",
")",
"\n",
"if",
"blockCount",
"==",
... | // Generates the tree nodes | [
"Generates",
"the",
"tree",
"nodes"
] | 84ec7cea74067a61c2b26bea753c9612c8edc9db | https://github.com/xsleonard/go-merkle/blob/84ec7cea74067a61c2b26bea753c9612c8edc9db/merkle.go#L107-L148 |
152,558 | xsleonard/go-merkle | merkle.go | CalculateHeightAndNodeCount | func CalculateHeightAndNodeCount(leaves uint64) (height, nodeCount uint64) {
height = calculateTreeHeight(leaves)
nodeCount = calculateNodeCount(height, leaves)
return
} | go | func CalculateHeightAndNodeCount(leaves uint64) (height, nodeCount uint64) {
height = calculateTreeHeight(leaves)
nodeCount = calculateNodeCount(height, leaves)
return
} | [
"func",
"CalculateHeightAndNodeCount",
"(",
"leaves",
"uint64",
")",
"(",
"height",
",",
"nodeCount",
"uint64",
")",
"{",
"height",
"=",
"calculateTreeHeight",
"(",
"leaves",
")",
"\n",
"nodeCount",
"=",
"calculateNodeCount",
"(",
"height",
",",
"leaves",
")",
... | // Returns the height and number of nodes in an unbalanced binary tree given
// number of leaves | [
"Returns",
"the",
"height",
"and",
"number",
"of",
"nodes",
"in",
"an",
"unbalanced",
"binary",
"tree",
"given",
"number",
"of",
"leaves"
] | 84ec7cea74067a61c2b26bea753c9612c8edc9db | https://github.com/xsleonard/go-merkle/blob/84ec7cea74067a61c2b26bea753c9612c8edc9db/merkle.go#L205-L209 |
152,559 | xsleonard/go-merkle | merkle.go | nextPowerOfTwo | func nextPowerOfTwo(n uint64) uint64 {
if n == 0 {
return 1
}
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
n--
n |= n >> 1
n |= n >> 2
n |= n >> 4
n |= n >> 8
n |= n >> 16
n |= n >> 32
n++
return n
} | go | func nextPowerOfTwo(n uint64) uint64 {
if n == 0 {
return 1
}
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
n--
n |= n >> 1
n |= n >> 2
n |= n >> 4
n |= n >> 8
n |= n >> 16
n |= n >> 32
n++
return n
} | [
"func",
"nextPowerOfTwo",
"(",
"n",
"uint64",
")",
"uint64",
"{",
"if",
"n",
"==",
"0",
"{",
"return",
"1",
"\n",
"}",
"\n",
"// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2",
"n",
"--",
"\n",
"n",
"|=",
"n",
">>",
"1",
"\n",
"n",
"|="... | // Returns the next highest power of 2 above n, if n is not already a
// power of 2 | [
"Returns",
"the",
"next",
"highest",
"power",
"of",
"2",
"above",
"n",
"if",
"n",
"is",
"not",
"already",
"a",
"power",
"of",
"2"
] | 84ec7cea74067a61c2b26bea753c9612c8edc9db | https://github.com/xsleonard/go-merkle/blob/84ec7cea74067a61c2b26bea753c9612c8edc9db/merkle.go#L246-L260 |
152,560 | weberhong/figlet4go | render.go | Render | func (this *AsciiRender) Render(asciiStr string) (string, error) {
return this.render(asciiStr, NewRenderOptions())
} | go | func (this *AsciiRender) Render(asciiStr string) (string, error) {
return this.render(asciiStr, NewRenderOptions())
} | [
"func",
"(",
"this",
"*",
"AsciiRender",
")",
"Render",
"(",
"asciiStr",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"this",
".",
"render",
"(",
"asciiStr",
",",
"NewRenderOptions",
"(",
")",
")",
"\n",
"}"
] | // render with default options | [
"render",
"with",
"default",
"options"
] | bc879344e874dd110753d17083a2a7acf3136683 | https://github.com/weberhong/figlet4go/blob/bc879344e874dd110753d17083a2a7acf3136683/render.go#L39-L41 |
152,561 | weberhong/figlet4go | render.go | RenderOpts | func (this *AsciiRender) RenderOpts(asciiStr string, opts *RenderOptions) (string, error) {
return this.render(asciiStr, opts)
} | go | func (this *AsciiRender) RenderOpts(asciiStr string, opts *RenderOptions) (string, error) {
return this.render(asciiStr, opts)
} | [
"func",
"(",
"this",
"*",
"AsciiRender",
")",
"RenderOpts",
"(",
"asciiStr",
"string",
",",
"opts",
"*",
"RenderOptions",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"this",
".",
"render",
"(",
"asciiStr",
",",
"opts",
")",
"\n",
"}"
] | // render with options | [
"render",
"with",
"options"
] | bc879344e874dd110753d17083a2a7acf3136683 | https://github.com/weberhong/figlet4go/blob/bc879344e874dd110753d17083a2a7acf3136683/render.go#L44-L46 |
152,562 | jgautheron/codename-generator | codename.go | Get | func Get(format FormatType) (string, error) {
// Load Superb words
sp, err := Asset(SuperbFilePath)
if err != nil {
return "", err
}
var spa JSONData
json.Unmarshal(sp, &spa)
// Load Superheroes words
sh, err := Asset(SuperheroesFilePath)
if err != nil {
return "", err
}
var sha JSONData
json.Unmarshal(sh, &sha)
// Seed the randomizer
rand.Seed(time.Now().UTC().UnixNano())
// Pick random items from each list
fw := spa[rand.Intn(len(spa))]
sw := sha[rand.Intn(len(sha))]
codename := fmt.Sprintf("%s %s", fw, sw)
switch format {
case SpacedString:
upperCaseFirst := func(s string) string {
if len(s) == 0 {
return ""
}
r, n := utf8.DecodeRuneInString(s)
return string(unicode.ToUpper(r)) + s[n:]
}
cs, csn := strings.Split(codename, " "), []string{}
for _, csi := range cs {
csn = append(csn, upperCaseFirst(csi))
}
codename = strings.Join(csn, " ")
break
case Sanitized:
codename = strings.ToLower(strings.TrimSpace(codename))
codename = strings.Replace(codename, " ", "-", -1)
reg, err := regexp.Compile("[^a-z0-9-]+")
if err != nil {
return "", err
}
codename = reg.ReplaceAllString(codename, "")
break
}
return codename, nil
} | go | func Get(format FormatType) (string, error) {
// Load Superb words
sp, err := Asset(SuperbFilePath)
if err != nil {
return "", err
}
var spa JSONData
json.Unmarshal(sp, &spa)
// Load Superheroes words
sh, err := Asset(SuperheroesFilePath)
if err != nil {
return "", err
}
var sha JSONData
json.Unmarshal(sh, &sha)
// Seed the randomizer
rand.Seed(time.Now().UTC().UnixNano())
// Pick random items from each list
fw := spa[rand.Intn(len(spa))]
sw := sha[rand.Intn(len(sha))]
codename := fmt.Sprintf("%s %s", fw, sw)
switch format {
case SpacedString:
upperCaseFirst := func(s string) string {
if len(s) == 0 {
return ""
}
r, n := utf8.DecodeRuneInString(s)
return string(unicode.ToUpper(r)) + s[n:]
}
cs, csn := strings.Split(codename, " "), []string{}
for _, csi := range cs {
csn = append(csn, upperCaseFirst(csi))
}
codename = strings.Join(csn, " ")
break
case Sanitized:
codename = strings.ToLower(strings.TrimSpace(codename))
codename = strings.Replace(codename, " ", "-", -1)
reg, err := regexp.Compile("[^a-z0-9-]+")
if err != nil {
return "", err
}
codename = reg.ReplaceAllString(codename, "")
break
}
return codename, nil
} | [
"func",
"Get",
"(",
"format",
"FormatType",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Load Superb words",
"sp",
",",
"err",
":=",
"Asset",
"(",
"SuperbFilePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
... | // GetCodename generates a code name with the given format. | [
"GetCodename",
"generates",
"a",
"code",
"name",
"with",
"the",
"given",
"format",
"."
] | 16d037c7cc3c9b552fe4af9828b7338d752dbaf9 | https://github.com/jgautheron/codename-generator/blob/16d037c7cc3c9b552fe4af9828b7338d752dbaf9/codename.go#L37-L92 |
152,563 | bobziuchkovski/cue | context.go | basicValue | func basicValue(value interface{}) interface{} {
rval := reflect.ValueOf(value)
if !rval.IsValid() {
return fmt.Sprint(value)
}
for rval.Kind() == reflect.Ptr {
if rval.IsNil() {
break
}
if rval.Type().Implements(stringerT) || rval.Type().Implements(errorT) {
break
}
rval = rval.Elem()
}
switch rval.Kind() {
case reflect.Bool, reflect.String:
return rval.Interface()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return rval.Interface()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return rval.Interface()
case reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
return rval.Interface()
default:
return fmt.Sprint(rval.Interface())
}
} | go | func basicValue(value interface{}) interface{} {
rval := reflect.ValueOf(value)
if !rval.IsValid() {
return fmt.Sprint(value)
}
for rval.Kind() == reflect.Ptr {
if rval.IsNil() {
break
}
if rval.Type().Implements(stringerT) || rval.Type().Implements(errorT) {
break
}
rval = rval.Elem()
}
switch rval.Kind() {
case reflect.Bool, reflect.String:
return rval.Interface()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return rval.Interface()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return rval.Interface()
case reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
return rval.Interface()
default:
return fmt.Sprint(rval.Interface())
}
} | [
"func",
"basicValue",
"(",
"value",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"rval",
":=",
"reflect",
".",
"ValueOf",
"(",
"value",
")",
"\n",
"if",
"!",
"rval",
".",
"IsValid",
"(",
")",
"{",
"return",
"fmt",
".",
"Sprint",
"(",
"va... | // basicValue serves to dereference pointers and coerce non-basic types to strings,
// ensuring all values are effectively immutable. The latter is critical for
// asynchronous operation. We can't have context values changing while an event is
// queued, or else the logged value won't represent the value as it was at the
// time the event was generated. | [
"basicValue",
"serves",
"to",
"dereference",
"pointers",
"and",
"coerce",
"non",
"-",
"basic",
"types",
"to",
"strings",
"ensuring",
"all",
"values",
"are",
"effectively",
"immutable",
".",
"The",
"latter",
"is",
"critical",
"for",
"asynchronous",
"operation",
"... | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/context.go#L186-L213 |
152,564 | bobziuchkovski/cue | collector/socket.go | New | func (s Socket) New() cue.Collector {
if s.Network == "" {
log.Warn("Socket.New called to created a collector, but Network param is empty. Returning nil collector.")
return nil
}
if s.Address == "" {
log.Warn("Socket.New called to created a collector, but Address param is empty. Returning nil collector.")
return nil
}
if s.Formatter == nil {
s.Formatter = format.HumanReadable
}
return &socketCollector{Socket: s}
} | go | func (s Socket) New() cue.Collector {
if s.Network == "" {
log.Warn("Socket.New called to created a collector, but Network param is empty. Returning nil collector.")
return nil
}
if s.Address == "" {
log.Warn("Socket.New called to created a collector, but Address param is empty. Returning nil collector.")
return nil
}
if s.Formatter == nil {
s.Formatter = format.HumanReadable
}
return &socketCollector{Socket: s}
} | [
"func",
"(",
"s",
"Socket",
")",
"New",
"(",
")",
"cue",
".",
"Collector",
"{",
"if",
"s",
".",
"Network",
"==",
"\"",
"\"",
"{",
"log",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"s",
".",
"Address",
"==... | // New returns a new collector based on the Socket configuration. | [
"New",
"returns",
"a",
"new",
"collector",
"based",
"on",
"the",
"Socket",
"configuration",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/collector/socket.go#L47-L60 |
152,565 | bobziuchkovski/cue | format/format.go | RenderBytes | func RenderBytes(formatter Formatter, event *cue.Event) []byte {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
result := make([]byte, tmp.Len())
copy(result, tmp.Bytes())
return result
} | go | func RenderBytes(formatter Formatter, event *cue.Event) []byte {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
result := make([]byte, tmp.Len())
copy(result, tmp.Bytes())
return result
} | [
"func",
"RenderBytes",
"(",
"formatter",
"Formatter",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"[",
"]",
"byte",
"{",
"tmp",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"ReleaseBuffer",
"(",
"tmp",
")",
"\n\n",
"formatter",
"(",
"tmp",
",",
"event"... | // RenderBytes renders the given event using formatter. | [
"RenderBytes",
"renders",
"the",
"given",
"event",
"using",
"formatter",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L62-L70 |
152,566 | bobziuchkovski/cue | format/format.go | RenderString | func RenderString(formatter Formatter, event *cue.Event) string {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
return string(tmp.Bytes())
} | go | func RenderString(formatter Formatter, event *cue.Event) string {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
return string(tmp.Bytes())
} | [
"func",
"RenderString",
"(",
"formatter",
"Formatter",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"string",
"{",
"tmp",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"ReleaseBuffer",
"(",
"tmp",
")",
"\n\n",
"formatter",
"(",
"tmp",
",",
"event",
")",
... | // RenderString renders the given event using formatter. | [
"RenderString",
"renders",
"the",
"given",
"event",
"using",
"formatter",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L73-L79 |
152,567 | bobziuchkovski/cue | format/format.go | Join | func Join(sep string, formatters ...Formatter) Formatter {
return func(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
needSep := false
for _, formatter := range formatters {
formatter(tmp, event)
if tmp.Len() == 0 {
continue
}
if needSep {
buffer.AppendString(sep)
}
buffer.Append(tmp.Bytes())
tmp.Reset()
needSep = true
}
}
} | go | func Join(sep string, formatters ...Formatter) Formatter {
return func(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
needSep := false
for _, formatter := range formatters {
formatter(tmp, event)
if tmp.Len() == 0 {
continue
}
if needSep {
buffer.AppendString(sep)
}
buffer.Append(tmp.Bytes())
tmp.Reset()
needSep = true
}
}
} | [
"func",
"Join",
"(",
"sep",
"string",
",",
"formatters",
"...",
"Formatter",
")",
"Formatter",
"{",
"return",
"func",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"tmp",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"Release... | // Join returns a new Formatter that appends sep between the contents of
// underlying formatters. Sep is only appended between formatters that write
// one or more bytes to their buffers. | [
"Join",
"returns",
"a",
"new",
"Formatter",
"that",
"appends",
"sep",
"between",
"the",
"contents",
"of",
"underlying",
"formatters",
".",
"Sep",
"is",
"only",
"appended",
"between",
"formatters",
"that",
"write",
"one",
"or",
"more",
"bytes",
"to",
"their",
... | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L84-L104 |
152,568 | bobziuchkovski/cue | format/format.go | Formatf | func Formatf(format string, formatters ...Formatter) Formatter {
formatterIdx := 0
segments := splitFormat(format)
chain := make([]Formatter, len(segments))
for i, seg := range segments {
switch {
case seg == "%v" && formatterIdx < len(formatters):
chain[i] = formatters[formatterIdx]
formatterIdx++
case seg == "%v":
chain[i] = Literal("%!v(MISSING)")
default:
chain[i] = Literal(seg)
}
}
return func(buffer Buffer, event *cue.Event) {
for _, formatter := range chain {
formatter(buffer, event)
}
}
} | go | func Formatf(format string, formatters ...Formatter) Formatter {
formatterIdx := 0
segments := splitFormat(format)
chain := make([]Formatter, len(segments))
for i, seg := range segments {
switch {
case seg == "%v" && formatterIdx < len(formatters):
chain[i] = formatters[formatterIdx]
formatterIdx++
case seg == "%v":
chain[i] = Literal("%!v(MISSING)")
default:
chain[i] = Literal(seg)
}
}
return func(buffer Buffer, event *cue.Event) {
for _, formatter := range chain {
formatter(buffer, event)
}
}
} | [
"func",
"Formatf",
"(",
"format",
"string",
",",
"formatters",
"...",
"Formatter",
")",
"Formatter",
"{",
"formatterIdx",
":=",
"0",
"\n",
"segments",
":=",
"splitFormat",
"(",
"format",
")",
"\n",
"chain",
":=",
"make",
"(",
"[",
"]",
"Formatter",
",",
... | // Formatf provides printf-like formatting of source formatters. The "%v"
// placeholder is used to specify formatter placeholders. In the rare event
// a literal "%v" is required, "%%v" renders the literal. No alignment,
// padding, or other printf constructs are currently supported, though code
// contributions are certainly welcome. | [
"Formatf",
"provides",
"printf",
"-",
"like",
"formatting",
"of",
"source",
"formatters",
".",
"The",
"%v",
"placeholder",
"is",
"used",
"to",
"specify",
"formatter",
"placeholders",
".",
"In",
"the",
"rare",
"event",
"a",
"literal",
"%v",
"is",
"required",
... | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L111-L132 |
152,569 | bobziuchkovski/cue | format/format.go | Trim | func Trim(formatter Formatter) Formatter {
return func(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
buffer.AppendString(strings.TrimSpace(string(tmp.Bytes())))
}
} | go | func Trim(formatter Formatter) Formatter {
return func(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
buffer.AppendString(strings.TrimSpace(string(tmp.Bytes())))
}
} | [
"func",
"Trim",
"(",
"formatter",
"Formatter",
")",
"Formatter",
"{",
"return",
"func",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"tmp",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"ReleaseBuffer",
"(",
"tmp",
")",
"\n\... | // Trim returns a formatter that trims leading and trailing whitespace from
// the input formatter. | [
"Trim",
"returns",
"a",
"formatter",
"that",
"trims",
"leading",
"and",
"trailing",
"whitespace",
"from",
"the",
"input",
"formatter",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L200-L208 |
152,570 | bobziuchkovski/cue | format/format.go | Truncate | func Truncate(formatter Formatter, length int) Formatter {
return func(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
bytes := tmp.Bytes()
if len(bytes) > length {
bytes = bytes[:length]
}
buffer.Append(bytes)
}
} | go | func Truncate(formatter Formatter, length int) Formatter {
return func(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
formatter(tmp, event)
bytes := tmp.Bytes()
if len(bytes) > length {
bytes = bytes[:length]
}
buffer.Append(bytes)
}
} | [
"func",
"Truncate",
"(",
"formatter",
"Formatter",
",",
"length",
"int",
")",
"Formatter",
"{",
"return",
"func",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"tmp",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"ReleaseBuffer... | // Truncate returns a new formatter that truncates the input formatter after
// length bytes are written. | [
"Truncate",
"returns",
"a",
"new",
"formatter",
"that",
"truncates",
"the",
"input",
"formatter",
"after",
"length",
"bytes",
"are",
"written",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L235-L247 |
152,571 | bobziuchkovski/cue | format/format.go | Literal | func Literal(s string) Formatter {
return func(buffer Buffer, event *cue.Event) {
buffer.AppendString(s)
}
} | go | func Literal(s string) Formatter {
return func(buffer Buffer, event *cue.Event) {
buffer.AppendString(s)
}
} | [
"func",
"Literal",
"(",
"s",
"string",
")",
"Formatter",
"{",
"return",
"func",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"buffer",
".",
"AppendString",
"(",
"s",
")",
"\n",
"}",
"\n",
"}"
] | // Literal returns a formatter that always writes s to its buffer. | [
"Literal",
"returns",
"a",
"formatter",
"that",
"always",
"writes",
"s",
"to",
"its",
"buffer",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L250-L254 |
152,572 | bobziuchkovski/cue | format/format.go | Time | func Time(timeFormat string) Formatter {
return func(buffer Buffer, event *cue.Event) {
buffer.AppendString(event.Time.Format(timeFormat))
}
} | go | func Time(timeFormat string) Formatter {
return func(buffer Buffer, event *cue.Event) {
buffer.AppendString(event.Time.Format(timeFormat))
}
} | [
"func",
"Time",
"(",
"timeFormat",
"string",
")",
"Formatter",
"{",
"return",
"func",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"buffer",
".",
"AppendString",
"(",
"event",
".",
"Time",
".",
"Format",
"(",
"timeFormat",
... | // Time returns a formatter that writes the event's timestamp to the buffer
// using the formatting rules from the time package. | [
"Time",
"returns",
"a",
"formatter",
"that",
"writes",
"the",
"event",
"s",
"timestamp",
"to",
"the",
"buffer",
"using",
"the",
"formatting",
"rules",
"from",
"the",
"time",
"package",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L258-L262 |
152,573 | bobziuchkovski/cue | format/format.go | Hostname | func Hostname(buffer Buffer, event *cue.Event) {
name, err := os.Hostname()
if err != nil {
name = "unknown"
}
idx := strings.Index(name, ".")
if idx != -1 {
name = name[:idx]
}
buffer.AppendString(name)
} | go | func Hostname(buffer Buffer, event *cue.Event) {
name, err := os.Hostname()
if err != nil {
name = "unknown"
}
idx := strings.Index(name, ".")
if idx != -1 {
name = name[:idx]
}
buffer.AppendString(name)
} | [
"func",
"Hostname",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"name",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"name",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"idx",
":="... | // Hostname writes the host's short name to the buffer, domain excluded.
// If the hostname cannot be determined, "unknown" is written instead. | [
"Hostname",
"writes",
"the",
"host",
"s",
"short",
"name",
"to",
"the",
"buffer",
"domain",
"excluded",
".",
"If",
"the",
"hostname",
"cannot",
"be",
"determined",
"unknown",
"is",
"written",
"instead",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L266-L276 |
152,574 | bobziuchkovski/cue | format/format.go | Line | func Line(buffer Buffer, event *cue.Event) {
if len(event.Frames) == 0 {
buffer.AppendString("0")
return
}
buffer.AppendString(fmt.Sprintf("%d", event.Frames[0].Line))
} | go | func Line(buffer Buffer, event *cue.Event) {
if len(event.Frames) == 0 {
buffer.AppendString("0")
return
}
buffer.AppendString(fmt.Sprintf("%d", event.Frames[0].Line))
} | [
"func",
"Line",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"if",
"len",
"(",
"event",
".",
"Frames",
")",
"==",
"0",
"{",
"buffer",
".",
"AppendString",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"buffe... | // Line writes the source line number that generated the event. If this
// cannot be determined or frame collection is disabled, it writes "0"
// instead. | [
"Line",
"writes",
"the",
"source",
"line",
"number",
"that",
"generated",
"the",
"event",
".",
"If",
"this",
"cannot",
"be",
"determined",
"or",
"frame",
"collection",
"is",
"disabled",
"it",
"writes",
"0",
"instead",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L346-L352 |
152,575 | bobziuchkovski/cue | format/format.go | Message | func Message(buffer Buffer, event *cue.Event) {
buffer.AppendString(event.Message)
} | go | func Message(buffer Buffer, event *cue.Event) {
buffer.AppendString(event.Message)
} | [
"func",
"Message",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"buffer",
".",
"AppendString",
"(",
"event",
".",
"Message",
")",
"\n",
"}"
] | // Message writes event.Message to the buffer. | [
"Message",
"writes",
"event",
".",
"Message",
"to",
"the",
"buffer",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L355-L357 |
152,576 | bobziuchkovski/cue | format/format.go | ErrorType | func ErrorType(buffer Buffer, event *cue.Event) {
if event.Error == nil {
return
}
rtype := reflect.TypeOf(event.Error)
for rtype.Kind() == reflect.Ptr {
rtype = rtype.Elem()
}
buffer.AppendString(rtype.String())
} | go | func ErrorType(buffer Buffer, event *cue.Event) {
if event.Error == nil {
return
}
rtype := reflect.TypeOf(event.Error)
for rtype.Kind() == reflect.Ptr {
rtype = rtype.Elem()
}
buffer.AppendString(rtype.String())
} | [
"func",
"ErrorType",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"if",
"event",
".",
"Error",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"rtype",
":=",
"reflect",
".",
"TypeOf",
"(",
"event",
".",
"Error",
")",
"\n"... | // ErrorType writes the dereferenced type name for the event's Error field.
// If event.Error is nil, nothing is written. | [
"ErrorType",
"writes",
"the",
"dereferenced",
"type",
"name",
"for",
"the",
"event",
"s",
"Error",
"field",
".",
"If",
"event",
".",
"Error",
"is",
"nil",
"nothing",
"is",
"written",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L370-L379 |
152,577 | bobziuchkovski/cue | format/format.go | JSONContext | func JSONContext(buffer Buffer, event *cue.Event) {
fields := event.Context.Fields()
marshaled, _ := json.Marshal(fields)
buffer.Append(marshaled)
} | go | func JSONContext(buffer Buffer, event *cue.Event) {
fields := event.Context.Fields()
marshaled, _ := json.Marshal(fields)
buffer.Append(marshaled)
} | [
"func",
"JSONContext",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"fields",
":=",
"event",
".",
"Context",
".",
"Fields",
"(",
")",
"\n",
"marshaled",
",",
"_",
":=",
"json",
".",
"Marshal",
"(",
"fields",
")",
"\n",
... | // JSONContext marshals the event.Context fields into JSON and writes the
// result. | [
"JSONContext",
"marshals",
"the",
"event",
".",
"Context",
"fields",
"into",
"JSON",
"and",
"writes",
"the",
"result",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L459-L463 |
152,578 | bobziuchkovski/cue | format/format.go | StructuredContext | func StructuredContext(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
needSep := false
event.Context.Each(func(name string, value interface{}) {
if !validStructuredKey(name) {
return
}
writeStructuredPair(tmp, name, value)
if needSep {
buffer.AppendRune(' ')
}
buffer.Append(tmp.Bytes())
tmp.Reset()
needSep = true
})
} | go | func StructuredContext(buffer Buffer, event *cue.Event) {
tmp := GetBuffer()
defer ReleaseBuffer(tmp)
needSep := false
event.Context.Each(func(name string, value interface{}) {
if !validStructuredKey(name) {
return
}
writeStructuredPair(tmp, name, value)
if needSep {
buffer.AppendRune(' ')
}
buffer.Append(tmp.Bytes())
tmp.Reset()
needSep = true
})
} | [
"func",
"StructuredContext",
"(",
"buffer",
"Buffer",
",",
"event",
"*",
"cue",
".",
"Event",
")",
"{",
"tmp",
":=",
"GetBuffer",
"(",
")",
"\n",
"defer",
"ReleaseBuffer",
"(",
"tmp",
")",
"\n\n",
"needSep",
":=",
"false",
"\n",
"event",
".",
"Context",
... | // StructuredContext marshals the event.Context fields into structured
// key=value pairs as prescribed by RFC 5424, "The Syslog Protocol". | [
"StructuredContext",
"marshals",
"the",
"event",
".",
"Context",
"fields",
"into",
"structured",
"key",
"=",
"value",
"pairs",
"as",
"prescribed",
"by",
"RFC",
"5424",
"The",
"Syslog",
"Protocol",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L467-L485 |
152,579 | bobziuchkovski/cue | format/format.go | validStructuredKey | func validStructuredKey(name string) bool {
if len(name) > 32 {
return false
}
for _, r := range []rune(name) {
switch {
case r <= 32:
return false
case r >= 127:
return false
case r == '=', r == ']', r == '"':
return false
}
}
return true
} | go | func validStructuredKey(name string) bool {
if len(name) > 32 {
return false
}
for _, r := range []rune(name) {
switch {
case r <= 32:
return false
case r >= 127:
return false
case r == '=', r == ']', r == '"':
return false
}
}
return true
} | [
"func",
"validStructuredKey",
"(",
"name",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"name",
")",
">",
"32",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"[",
"]",
"rune",
"(",
"name",
")",
"{",
"switch",
"{",... | // These restrictions are imposed by RFC 5424. | [
"These",
"restrictions",
"are",
"imposed",
"by",
"RFC",
"5424",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L488-L503 |
152,580 | bobziuchkovski/cue | format/format.go | writeStructuredValue | func writeStructuredValue(buffer Buffer, v interface{}) {
s, ok := v.(string)
if !ok {
s = fmt.Sprint(v)
}
for _, r := range []rune(s) {
switch r {
case '"':
buffer.AppendRune('\\')
buffer.AppendRune('"')
case '\\':
buffer.AppendRune('\\')
buffer.AppendRune('\\')
case ']':
buffer.AppendRune('\\')
buffer.AppendRune(']')
default:
buffer.AppendRune(r)
}
}
} | go | func writeStructuredValue(buffer Buffer, v interface{}) {
s, ok := v.(string)
if !ok {
s = fmt.Sprint(v)
}
for _, r := range []rune(s) {
switch r {
case '"':
buffer.AppendRune('\\')
buffer.AppendRune('"')
case '\\':
buffer.AppendRune('\\')
buffer.AppendRune('\\')
case ']':
buffer.AppendRune('\\')
buffer.AppendRune(']')
default:
buffer.AppendRune(r)
}
}
} | [
"func",
"writeStructuredValue",
"(",
"buffer",
"Buffer",
",",
"v",
"interface",
"{",
"}",
")",
"{",
"s",
",",
"ok",
":=",
"v",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"s",
"=",
"fmt",
".",
"Sprint",
"(",
"v",
")",
"\n",
"}",
"\n\n"... | // See Section 6.3.3 of RFC 5424 for details on the character escapes | [
"See",
"Section",
"6",
".",
"3",
".",
"3",
"of",
"RFC",
"5424",
"for",
"details",
"on",
"the",
"character",
"escapes"
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/format/format.go#L514-L535 |
152,581 | bobziuchkovski/cue | hosted/loggly.go | New | func (l Loggly) New() cue.Collector {
if l.Token == "" {
log.Warn("Loggly.New called to created a collector, but the Token param is empty. Returning nil collector.")
return nil
}
if l.App == "" {
log.Warn("Loggly.New called to created a collector, but the App param is empty. Returning nil collector.")
return nil
}
if l.Network == "" {
l.Network = logglyNetwork
}
if l.Address == "" {
l.Address = logglyAddress
}
if l.Formatter == nil {
l.Formatter = format.JSONMessage
}
return &logglyCollector{
Loggly: l,
syslog: collector.StructuredSyslog{
Facility: l.Facility,
App: l.App,
Network: l.Network,
Address: l.Address,
TLS: l.TLS,
MessageFormatter: l.Formatter,
StructuredFormatter: l.structuredFormatter(),
ID: fmt.Sprintf("%s@%d", l.Token, logglyEnterpriseID),
}.New(),
}
} | go | func (l Loggly) New() cue.Collector {
if l.Token == "" {
log.Warn("Loggly.New called to created a collector, but the Token param is empty. Returning nil collector.")
return nil
}
if l.App == "" {
log.Warn("Loggly.New called to created a collector, but the App param is empty. Returning nil collector.")
return nil
}
if l.Network == "" {
l.Network = logglyNetwork
}
if l.Address == "" {
l.Address = logglyAddress
}
if l.Formatter == nil {
l.Formatter = format.JSONMessage
}
return &logglyCollector{
Loggly: l,
syslog: collector.StructuredSyslog{
Facility: l.Facility,
App: l.App,
Network: l.Network,
Address: l.Address,
TLS: l.TLS,
MessageFormatter: l.Formatter,
StructuredFormatter: l.structuredFormatter(),
ID: fmt.Sprintf("%s@%d", l.Token, logglyEnterpriseID),
}.New(),
}
} | [
"func",
"(",
"l",
"Loggly",
")",
"New",
"(",
")",
"cue",
".",
"Collector",
"{",
"if",
"l",
".",
"Token",
"==",
"\"",
"\"",
"{",
"log",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"l",
".",
"App",
"==",
... | // New returns a new collector based on the Loggly configuration. | [
"New",
"returns",
"a",
"new",
"collector",
"based",
"on",
"the",
"Loggly",
"configuration",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/hosted/loggly.go#L58-L92 |
152,582 | bobziuchkovski/cue | collector/pipeline.go | FilterEvent | func (p *Pipeline) FilterEvent(filters ...EventFilter) *Pipeline {
return &Pipeline{
prior: p,
transformer: filterNilEvent(filterEvent(filters...)),
}
} | go | func (p *Pipeline) FilterEvent(filters ...EventFilter) *Pipeline {
return &Pipeline{
prior: p,
transformer: filterNilEvent(filterEvent(filters...)),
}
} | [
"func",
"(",
"p",
"*",
"Pipeline",
")",
"FilterEvent",
"(",
"filters",
"...",
"EventFilter",
")",
"*",
"Pipeline",
"{",
"return",
"&",
"Pipeline",
"{",
"prior",
":",
"p",
",",
"transformer",
":",
"filterNilEvent",
"(",
"filterEvent",
"(",
"filters",
"...",... | // FilterEvent returns an updated copy of Pipeline that drops events
// that match any of the provided filters. | [
"FilterEvent",
"returns",
"an",
"updated",
"copy",
"of",
"Pipeline",
"that",
"drops",
"events",
"that",
"match",
"any",
"of",
"the",
"provided",
"filters",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/collector/pipeline.go#L84-L89 |
152,583 | bobziuchkovski/cue | collector/pipeline.go | TransformContext | func (p *Pipeline) TransformContext(transformers ...ContextTransformer) *Pipeline {
return &Pipeline{
prior: p,
transformer: filterNilEvent(transformContext(transformers...)),
}
} | go | func (p *Pipeline) TransformContext(transformers ...ContextTransformer) *Pipeline {
return &Pipeline{
prior: p,
transformer: filterNilEvent(transformContext(transformers...)),
}
} | [
"func",
"(",
"p",
"*",
"Pipeline",
")",
"TransformContext",
"(",
"transformers",
"...",
"ContextTransformer",
")",
"*",
"Pipeline",
"{",
"return",
"&",
"Pipeline",
"{",
"prior",
":",
"p",
",",
"transformer",
":",
"filterNilEvent",
"(",
"transformContext",
"(",... | // TransformContext returns an updated copy of Pipeline that transforms event
// contexts according to the provided transformers. | [
"TransformContext",
"returns",
"an",
"updated",
"copy",
"of",
"Pipeline",
"that",
"transforms",
"event",
"contexts",
"according",
"to",
"the",
"provided",
"transformers",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/collector/pipeline.go#L93-L98 |
152,584 | bobziuchkovski/cue | collector/pipeline.go | TransformEvent | func (p *Pipeline) TransformEvent(transformers ...EventTransformer) *Pipeline {
return &Pipeline{
prior: p,
transformer: filterNilEvent(transformEvent(transformers...)),
}
} | go | func (p *Pipeline) TransformEvent(transformers ...EventTransformer) *Pipeline {
return &Pipeline{
prior: p,
transformer: filterNilEvent(transformEvent(transformers...)),
}
} | [
"func",
"(",
"p",
"*",
"Pipeline",
")",
"TransformEvent",
"(",
"transformers",
"...",
"EventTransformer",
")",
"*",
"Pipeline",
"{",
"return",
"&",
"Pipeline",
"{",
"prior",
":",
"p",
",",
"transformer",
":",
"filterNilEvent",
"(",
"transformEvent",
"(",
"tr... | // TransformEvent returns an updated copy of Pipeline that transforms events
// according to the provided transformers. | [
"TransformEvent",
"returns",
"an",
"updated",
"copy",
"of",
"Pipeline",
"that",
"transforms",
"events",
"according",
"to",
"the",
"provided",
"transformers",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/collector/pipeline.go#L102-L107 |
152,585 | bobziuchkovski/cue | collector/pipeline.go | Attach | func (p *Pipeline) Attach(c cue.Collector) cue.Collector {
if p.prior == nil {
log.Warn("Pipeline.Attach called on an empty pipeline.")
}
return &pipelineCollector{
pipeline: p,
collector: c,
}
} | go | func (p *Pipeline) Attach(c cue.Collector) cue.Collector {
if p.prior == nil {
log.Warn("Pipeline.Attach called on an empty pipeline.")
}
return &pipelineCollector{
pipeline: p,
collector: c,
}
} | [
"func",
"(",
"p",
"*",
"Pipeline",
")",
"Attach",
"(",
"c",
"cue",
".",
"Collector",
")",
"cue",
".",
"Collector",
"{",
"if",
"p",
".",
"prior",
"==",
"nil",
"{",
"log",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"pipeli... | // Attach returns a new collector with the pipeline attached to c. | [
"Attach",
"returns",
"a",
"new",
"collector",
"with",
"the",
"pipeline",
"attached",
"to",
"c",
"."
] | 852726be06b5c373580e50301c29f53f642f65ec | https://github.com/bobziuchkovski/cue/blob/852726be06b5c373580e50301c29f53f642f65ec/collector/pipeline.go#L110-L118 |
152,586 | naegelejd/go-acl | perms.go | AddPerm | func (pset *Permset) AddPerm(perm Perm) error {
rv, _ := C.acl_add_perm(pset.p, C.acl_perm_t(perm))
if rv < 0 {
return fmt.Errorf("unable to add perm to permset")
}
return nil
} | go | func (pset *Permset) AddPerm(perm Perm) error {
rv, _ := C.acl_add_perm(pset.p, C.acl_perm_t(perm))
if rv < 0 {
return fmt.Errorf("unable to add perm to permset")
}
return nil
} | [
"func",
"(",
"pset",
"*",
"Permset",
")",
"AddPerm",
"(",
"perm",
"Perm",
")",
"error",
"{",
"rv",
",",
"_",
":=",
"C",
".",
"acl_add_perm",
"(",
"pset",
".",
"p",
",",
"C",
".",
"acl_perm_t",
"(",
"perm",
")",
")",
"\n",
"if",
"rv",
"<",
"0",
... | // AddPerm adds a new permission to a Permset. | [
"AddPerm",
"adds",
"a",
"new",
"permission",
"to",
"a",
"Permset",
"."
] | f33f8615f62b73adb4e690a688a42dcf671ce6a4 | https://github.com/naegelejd/go-acl/blob/f33f8615f62b73adb4e690a688a42dcf671ce6a4/perms.go#L26-L32 |
152,587 | naegelejd/go-acl | perms.go | ClearPerms | func (pset *Permset) ClearPerms() error {
rv, _ := C.acl_clear_perms(pset.p)
if rv < 0 {
return fmt.Errorf("unable to clear perms")
}
return nil
} | go | func (pset *Permset) ClearPerms() error {
rv, _ := C.acl_clear_perms(pset.p)
if rv < 0 {
return fmt.Errorf("unable to clear perms")
}
return nil
} | [
"func",
"(",
"pset",
"*",
"Permset",
")",
"ClearPerms",
"(",
")",
"error",
"{",
"rv",
",",
"_",
":=",
"C",
".",
"acl_clear_perms",
"(",
"pset",
".",
"p",
")",
"\n",
"if",
"rv",
"<",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")"... | // ClearPerms removes all permissions from a Permset. | [
"ClearPerms",
"removes",
"all",
"permissions",
"from",
"a",
"Permset",
"."
] | f33f8615f62b73adb4e690a688a42dcf671ce6a4 | https://github.com/naegelejd/go-acl/blob/f33f8615f62b73adb4e690a688a42dcf671ce6a4/perms.go#L35-L41 |
152,588 | naegelejd/go-acl | perms.go | DeletePerm | func (pset *Permset) DeletePerm(perm Perm) error {
p := C.acl_perm_t(perm)
rv, _ := C.acl_delete_perm(pset.p, p)
if rv < 0 {
return fmt.Errorf("unable to delete perm")
}
return nil
} | go | func (pset *Permset) DeletePerm(perm Perm) error {
p := C.acl_perm_t(perm)
rv, _ := C.acl_delete_perm(pset.p, p)
if rv < 0 {
return fmt.Errorf("unable to delete perm")
}
return nil
} | [
"func",
"(",
"pset",
"*",
"Permset",
")",
"DeletePerm",
"(",
"perm",
"Perm",
")",
"error",
"{",
"p",
":=",
"C",
".",
"acl_perm_t",
"(",
"perm",
")",
"\n",
"rv",
",",
"_",
":=",
"C",
".",
"acl_delete_perm",
"(",
"pset",
".",
"p",
",",
"p",
")",
... | // DeletePerm removes a single permission from a Permset. | [
"DeletePerm",
"removes",
"a",
"single",
"permission",
"from",
"a",
"Permset",
"."
] | f33f8615f62b73adb4e690a688a42dcf671ce6a4 | https://github.com/naegelejd/go-acl/blob/f33f8615f62b73adb4e690a688a42dcf671ce6a4/perms.go#L44-L51 |
152,589 | peter-edge/openflights-go | id_store.go | GetAllAirports | func (i *IDStore) GetAllAirports() (<-chan *Airport, chan<- bool, <-chan error, error) {
out := make(chan *Airport)
cancel := make(chan bool, 1)
callbackErr := make(chan error, 1)
go func() {
defer close(out)
defer close(callbackErr)
for _, airport := range i.IdToAirport {
select {
case out <- airport:
case <-cancel:
// I don't particularly like the context.Canceled error, but we do this to
// be consistent with other Go libraries.
callbackErr <- context.Canceled
return
}
}
callbackErr <- nil
}()
return out, cancel, callbackErr, nil
} | go | func (i *IDStore) GetAllAirports() (<-chan *Airport, chan<- bool, <-chan error, error) {
out := make(chan *Airport)
cancel := make(chan bool, 1)
callbackErr := make(chan error, 1)
go func() {
defer close(out)
defer close(callbackErr)
for _, airport := range i.IdToAirport {
select {
case out <- airport:
case <-cancel:
// I don't particularly like the context.Canceled error, but we do this to
// be consistent with other Go libraries.
callbackErr <- context.Canceled
return
}
}
callbackErr <- nil
}()
return out, cancel, callbackErr, nil
} | [
"func",
"(",
"i",
"*",
"IDStore",
")",
"GetAllAirports",
"(",
")",
"(",
"<-",
"chan",
"*",
"Airport",
",",
"chan",
"<-",
"bool",
",",
"<-",
"chan",
"error",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"chan",
"*",
"Airport",
")",
"\n",
"can... | // GetAllAirports returns all Airports. | [
"GetAllAirports",
"returns",
"all",
"Airports",
"."
] | 57f47382fa8160af6c37944830d46fcaaa6bdf00 | https://github.com/peter-edge/openflights-go/blob/57f47382fa8160af6c37944830d46fcaaa6bdf00/id_store.go#L33-L53 |
152,590 | peter-edge/openflights-go | id_store.go | GetAllAirlines | func (i *IDStore) GetAllAirlines() (<-chan *Airline, chan<- bool, <-chan error, error) {
out := make(chan *Airline)
cancel := make(chan bool, 1)
callbackErr := make(chan error, 1)
go func() {
defer close(out)
defer close(callbackErr)
for _, airline := range i.IdToAirline {
select {
case out <- airline:
case <-cancel:
callbackErr <- context.Canceled
return
}
}
callbackErr <- nil
}()
return out, cancel, callbackErr, nil
} | go | func (i *IDStore) GetAllAirlines() (<-chan *Airline, chan<- bool, <-chan error, error) {
out := make(chan *Airline)
cancel := make(chan bool, 1)
callbackErr := make(chan error, 1)
go func() {
defer close(out)
defer close(callbackErr)
for _, airline := range i.IdToAirline {
select {
case out <- airline:
case <-cancel:
callbackErr <- context.Canceled
return
}
}
callbackErr <- nil
}()
return out, cancel, callbackErr, nil
} | [
"func",
"(",
"i",
"*",
"IDStore",
")",
"GetAllAirlines",
"(",
")",
"(",
"<-",
"chan",
"*",
"Airline",
",",
"chan",
"<-",
"bool",
",",
"<-",
"chan",
"error",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"chan",
"*",
"Airline",
")",
"\n",
"can... | // GetAllAirlines returns all Airlines. | [
"GetAllAirlines",
"returns",
"all",
"Airlines",
"."
] | 57f47382fa8160af6c37944830d46fcaaa6bdf00 | https://github.com/peter-edge/openflights-go/blob/57f47382fa8160af6c37944830d46fcaaa6bdf00/id_store.go#L56-L74 |
152,591 | peter-edge/openflights-go | id_store.go | GetAllRoutes | func (i *IDStore) GetAllRoutes() (<-chan *Route, chan<- bool, <-chan error, error) {
out := make(chan *Route)
cancel := make(chan bool, 1)
callbackErr := make(chan error, 1)
go func() {
defer close(out)
defer close(callbackErr)
for _, route := range i.Route {
select {
case out <- route:
case <-cancel:
callbackErr <- context.Canceled
return
}
}
callbackErr <- nil
}()
return out, cancel, callbackErr, nil
} | go | func (i *IDStore) GetAllRoutes() (<-chan *Route, chan<- bool, <-chan error, error) {
out := make(chan *Route)
cancel := make(chan bool, 1)
callbackErr := make(chan error, 1)
go func() {
defer close(out)
defer close(callbackErr)
for _, route := range i.Route {
select {
case out <- route:
case <-cancel:
callbackErr <- context.Canceled
return
}
}
callbackErr <- nil
}()
return out, cancel, callbackErr, nil
} | [
"func",
"(",
"i",
"*",
"IDStore",
")",
"GetAllRoutes",
"(",
")",
"(",
"<-",
"chan",
"*",
"Route",
",",
"chan",
"<-",
"bool",
",",
"<-",
"chan",
"error",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"chan",
"*",
"Route",
")",
"\n",
"cancel",
... | // GetAllRoutes returns all Routes. | [
"GetAllRoutes",
"returns",
"all",
"Routes",
"."
] | 57f47382fa8160af6c37944830d46fcaaa6bdf00 | https://github.com/peter-edge/openflights-go/blob/57f47382fa8160af6c37944830d46fcaaa6bdf00/id_store.go#L77-L95 |
152,592 | peter-edge/openflights-go | id_store.go | GetAirportByID | func (i *IDStore) GetAirportByID(id string) (*Airport, error) {
return getAirportByKey(i.IdToAirport, id)
} | go | func (i *IDStore) GetAirportByID(id string) (*Airport, error) {
return getAirportByKey(i.IdToAirport, id)
} | [
"func",
"(",
"i",
"*",
"IDStore",
")",
"GetAirportByID",
"(",
"id",
"string",
")",
"(",
"*",
"Airport",
",",
"error",
")",
"{",
"return",
"getAirportByKey",
"(",
"i",
".",
"IdToAirport",
",",
"id",
")",
"\n",
"}"
] | // GetAirportByID returns an Airport by ID, or error if it does not exist. | [
"GetAirportByID",
"returns",
"an",
"Airport",
"by",
"ID",
"or",
"error",
"if",
"it",
"does",
"not",
"exist",
"."
] | 57f47382fa8160af6c37944830d46fcaaa6bdf00 | https://github.com/peter-edge/openflights-go/blob/57f47382fa8160af6c37944830d46fcaaa6bdf00/id_store.go#L98-L100 |
152,593 | peter-edge/openflights-go | id_store.go | GetAirlineByID | func (i *IDStore) GetAirlineByID(id string) (*Airline, error) {
return getAirlineByKey(i.IdToAirline, id)
} | go | func (i *IDStore) GetAirlineByID(id string) (*Airline, error) {
return getAirlineByKey(i.IdToAirline, id)
} | [
"func",
"(",
"i",
"*",
"IDStore",
")",
"GetAirlineByID",
"(",
"id",
"string",
")",
"(",
"*",
"Airline",
",",
"error",
")",
"{",
"return",
"getAirlineByKey",
"(",
"i",
".",
"IdToAirline",
",",
"id",
")",
"\n",
"}"
] | // GetAirlineByID returns an Airline by ID, or error if it does not exist. | [
"GetAirlineByID",
"returns",
"an",
"Airline",
"by",
"ID",
"or",
"error",
"if",
"it",
"does",
"not",
"exist",
"."
] | 57f47382fa8160af6c37944830d46fcaaa6bdf00 | https://github.com/peter-edge/openflights-go/blob/57f47382fa8160af6c37944830d46fcaaa6bdf00/id_store.go#L103-L105 |
152,594 | aybabtme/color | color.go | NewStyle | func NewStyle(background, foreground Paint) Style {
bg := background
fg := foreground
return Style{
bg,
fg,
computeColorCode(bg, fg),
}
} | go | func NewStyle(background, foreground Paint) Style {
bg := background
fg := foreground
return Style{
bg,
fg,
computeColorCode(bg, fg),
}
} | [
"func",
"NewStyle",
"(",
"background",
",",
"foreground",
"Paint",
")",
"Style",
"{",
"bg",
":=",
"background",
"\n",
"fg",
":=",
"foreground",
"\n",
"return",
"Style",
"{",
"bg",
",",
"fg",
",",
"computeColorCode",
"(",
"bg",
",",
"fg",
")",
",",
"}",... | // NewStyle gives you a style ready to produce strings with the given
// background and foreground colors | [
"NewStyle",
"gives",
"you",
"a",
"style",
"ready",
"to",
"produce",
"strings",
"with",
"the",
"given",
"background",
"and",
"foreground",
"colors"
] | 28ad4cc941d69a60df8d0af1233fd5a2793c2801 | https://github.com/aybabtme/color/blob/28ad4cc941d69a60df8d0af1233fd5a2793c2801/color.go#L51-L59 |
152,595 | aybabtme/color | color.go | WithBackground | func (s Style) WithBackground(color Paint) Style {
newS := s
newS.bg = color
newS.code = computeColorCode(newS.bg, newS.fg)
return newS
} | go | func (s Style) WithBackground(color Paint) Style {
newS := s
newS.bg = color
newS.code = computeColorCode(newS.bg, newS.fg)
return newS
} | [
"func",
"(",
"s",
"Style",
")",
"WithBackground",
"(",
"color",
"Paint",
")",
"Style",
"{",
"newS",
":=",
"s",
"\n",
"newS",
".",
"bg",
"=",
"color",
"\n",
"newS",
".",
"code",
"=",
"computeColorCode",
"(",
"newS",
".",
"bg",
",",
"newS",
".",
"fg"... | // WithBackground copies the current style and return a new Style that
// has the desired background. The original Style is unchanged and you
// must capture the return value. | [
"WithBackground",
"copies",
"the",
"current",
"style",
"and",
"return",
"a",
"new",
"Style",
"that",
"has",
"the",
"desired",
"background",
".",
"The",
"original",
"Style",
"is",
"unchanged",
"and",
"you",
"must",
"capture",
"the",
"return",
"value",
"."
] | 28ad4cc941d69a60df8d0af1233fd5a2793c2801 | https://github.com/aybabtme/color/blob/28ad4cc941d69a60df8d0af1233fd5a2793c2801/color.go#L74-L79 |
152,596 | EconomistDigitalSolutions/ramlapi | ramlapi.go | String | func (e *Endpoint) String() string {
return fmt.Sprintf("verb: %s handler: %s path:%s\n", e.Verb, e.Handler, e.Path)
} | go | func (e *Endpoint) String() string {
return fmt.Sprintf("verb: %s handler: %s path:%s\n", e.Verb, e.Handler, e.Path)
} | [
"func",
"(",
"e",
"*",
"Endpoint",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"e",
".",
"Verb",
",",
"e",
".",
"Handler",
",",
"e",
".",
"Path",
")",
"\n",
"}"
] | // String returns the string representation of an Endpoint. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"an",
"Endpoint",
"."
] | 68c3a8caa1d4b685b5b6a872d5fec2be84564a3b | https://github.com/EconomistDigitalSolutions/ramlapi/blob/68c3a8caa1d4b685b5b6a872d5fec2be84564a3b/ramlapi.go#L38-L40 |
152,597 | EconomistDigitalSolutions/ramlapi | ramlapi.go | Build | func Build(api *raml.APIDefinition, routerFunc func(s *Endpoint)) error {
for name, resource := range api.Resources {
var resourceParams []*Parameter
err := processResource("", name, &resource, resourceParams, routerFunc)
if err != nil {
return err
}
}
return nil
} | go | func Build(api *raml.APIDefinition, routerFunc func(s *Endpoint)) error {
for name, resource := range api.Resources {
var resourceParams []*Parameter
err := processResource("", name, &resource, resourceParams, routerFunc)
if err != nil {
return err
}
}
return nil
} | [
"func",
"Build",
"(",
"api",
"*",
"raml",
".",
"APIDefinition",
",",
"routerFunc",
"func",
"(",
"s",
"*",
"Endpoint",
")",
")",
"error",
"{",
"for",
"name",
",",
"resource",
":=",
"range",
"api",
".",
"Resources",
"{",
"var",
"resourceParams",
"[",
"]"... | // Build takes a RAML API definition, a router and a routing map,
// and wires them all together. | [
"Build",
"takes",
"a",
"RAML",
"API",
"definition",
"a",
"router",
"and",
"a",
"routing",
"map",
"and",
"wires",
"them",
"all",
"together",
"."
] | 68c3a8caa1d4b685b5b6a872d5fec2be84564a3b | https://github.com/EconomistDigitalSolutions/ramlapi/blob/68c3a8caa1d4b685b5b6a872d5fec2be84564a3b/ramlapi.go#L50-L60 |
152,598 | EconomistDigitalSolutions/ramlapi | ramlapi.go | Process | func Process(file string) (*raml.APIDefinition, error) {
routes, err := raml.ParseFile(file)
if err != nil {
return nil, fmt.Errorf("Failed parsing RAML file: %s\n", err.Error())
}
return routes, nil
} | go | func Process(file string) (*raml.APIDefinition, error) {
routes, err := raml.ParseFile(file)
if err != nil {
return nil, fmt.Errorf("Failed parsing RAML file: %s\n", err.Error())
}
return routes, nil
} | [
"func",
"Process",
"(",
"file",
"string",
")",
"(",
"*",
"raml",
".",
"APIDefinition",
",",
"error",
")",
"{",
"routes",
",",
"err",
":=",
"raml",
".",
"ParseFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",... | // Process processes a RAML file and returns an API definition. | [
"Process",
"processes",
"a",
"RAML",
"file",
"and",
"returns",
"an",
"API",
"definition",
"."
] | 68c3a8caa1d4b685b5b6a872d5fec2be84564a3b | https://github.com/EconomistDigitalSolutions/ramlapi/blob/68c3a8caa1d4b685b5b6a872d5fec2be84564a3b/ramlapi.go#L63-L69 |
152,599 | EconomistDigitalSolutions/ramlapi | ramlapi.go | processResource | func processResource(parent, name string, resource *raml.Resource, params []*Parameter, routerFunc func(s *Endpoint)) error {
var path = parent + name
var err error
for name, param := range resource.UriParameters {
params = append(params, newParam(name, ¶m))
}
s := make([]*Endpoint, 0, 6)
for _, m := range resource.Methods() {
s, err = appendEndpoint(s, m, params)
if err != nil {
return err
}
}
for _, ep := range s {
ep.Path = path
log.Println("processing", ep)
routerFunc(ep)
}
// Get all children.
for nestname, nested := range resource.Nested {
return processResource(path, nestname, nested, params, routerFunc)
}
return nil
} | go | func processResource(parent, name string, resource *raml.Resource, params []*Parameter, routerFunc func(s *Endpoint)) error {
var path = parent + name
var err error
for name, param := range resource.UriParameters {
params = append(params, newParam(name, ¶m))
}
s := make([]*Endpoint, 0, 6)
for _, m := range resource.Methods() {
s, err = appendEndpoint(s, m, params)
if err != nil {
return err
}
}
for _, ep := range s {
ep.Path = path
log.Println("processing", ep)
routerFunc(ep)
}
// Get all children.
for nestname, nested := range resource.Nested {
return processResource(path, nestname, nested, params, routerFunc)
}
return nil
} | [
"func",
"processResource",
"(",
"parent",
",",
"name",
"string",
",",
"resource",
"*",
"raml",
".",
"Resource",
",",
"params",
"[",
"]",
"*",
"Parameter",
",",
"routerFunc",
"func",
"(",
"s",
"*",
"Endpoint",
")",
")",
"error",
"{",
"var",
"path",
"=",... | // processResource recursively process resources and their nested children
// and returns the path so far for the children. The function takes a routerFunc
// as an argument that is invoked with the verb, resource path and handler as
// the resources are processed, so the calling code can use pat, mux, httprouter
// or whatever router they desire and we don't need to know about it. | [
"processResource",
"recursively",
"process",
"resources",
"and",
"their",
"nested",
"children",
"and",
"returns",
"the",
"path",
"so",
"far",
"for",
"the",
"children",
".",
"The",
"function",
"takes",
"a",
"routerFunc",
"as",
"an",
"argument",
"that",
"is",
"i... | 68c3a8caa1d4b685b5b6a872d5fec2be84564a3b | https://github.com/EconomistDigitalSolutions/ramlapi/blob/68c3a8caa1d4b685b5b6a872d5fec2be84564a3b/ramlapi.go#L117-L144 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.