repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6
values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
ChrisTrenkamp/goxpath | tree/xmltree/xmlele/xmlele.go | GetAttrs | func (x *XMLEle) GetAttrs() []tree.Node {
ret := make([]tree.Node, len(x.Attrs))
for i := range x.Attrs {
ret[i] = x.Attrs[i]
}
return ret
} | go | func (x *XMLEle) GetAttrs() []tree.Node {
ret := make([]tree.Node, len(x.Attrs))
for i := range x.Attrs {
ret[i] = x.Attrs[i]
}
return ret
} | [
"func",
"(",
"x",
"*",
"XMLEle",
")",
"GetAttrs",
"(",
")",
"[",
"]",
"tree",
".",
"Node",
"{",
"ret",
":=",
"make",
"(",
"[",
"]",
"tree",
".",
"Node",
",",
"len",
"(",
"x",
".",
"Attrs",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"x",
"."... | //GetAttrs returns all attributes of the element | [
"GetAttrs",
"returns",
"all",
"attributes",
"of",
"the",
"element"
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/xmltree/xmlele/xmlele.go#L88-L94 | test |
ChrisTrenkamp/goxpath | tree/xmltree/xmlele/xmlele.go | ResValue | func (x *XMLEle) ResValue() string {
ret := ""
for i := range x.Children {
switch x.Children[i].GetNodeType() {
case tree.NtChd, tree.NtElem, tree.NtRoot:
ret += x.Children[i].ResValue()
}
}
return ret
} | go | func (x *XMLEle) ResValue() string {
ret := ""
for i := range x.Children {
switch x.Children[i].GetNodeType() {
case tree.NtChd, tree.NtElem, tree.NtRoot:
ret += x.Children[i].ResValue()
}
}
return ret
} | [
"func",
"(",
"x",
"*",
"XMLEle",
")",
"ResValue",
"(",
")",
"string",
"{",
"ret",
":=",
"\"\"",
"\n",
"for",
"i",
":=",
"range",
"x",
".",
"Children",
"{",
"switch",
"x",
".",
"Children",
"[",
"i",
"]",
".",
"GetNodeType",
"(",
")",
"{",
"case",
... | //ResValue returns the string value of the element and children | [
"ResValue",
"returns",
"the",
"string",
"value",
"of",
"the",
"element",
"and",
"children"
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/xmltree/xmlele/xmlele.go#L97-L106 | test |
ChrisTrenkamp/goxpath | parser/parser.go | Parse | func Parse(xp string) (*Node, error) {
var err error
c := lexer.Lex(xp)
n := &Node{}
p := &parseStack{cur: n}
for next := range c {
if next.Typ != lexer.XItemError {
parseMap[next.Typ](p, next)
} else if err == nil {
err = fmt.Errorf(next.Val)
}
}
return n, err
} | go | func Parse(xp string) (*Node, error) {
var err error
c := lexer.Lex(xp)
n := &Node{}
p := &parseStack{cur: n}
for next := range c {
if next.Typ != lexer.XItemError {
parseMap[next.Typ](p, next)
} else if err == nil {
err = fmt.Errorf(next.Val)
}
}
return n, err
} | [
"func",
"Parse",
"(",
"xp",
"string",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"c",
":=",
"lexer",
".",
"Lex",
"(",
"xp",
")",
"\n",
"n",
":=",
"&",
"Node",
"{",
"}",
"\n",
"p",
":=",
"&",
"parseStack",
"{",... | //Parse creates an AST tree for XPath expressions. | [
"Parse",
"creates",
"an",
"AST",
"tree",
"for",
"XPath",
"expressions",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/parser/parser.go#L89-L104 | test |
ChrisTrenkamp/goxpath | tree/xmltree/xmlnode/xmlnode.go | GetToken | func (a XMLNode) GetToken() xml.Token {
if a.NodeType == tree.NtAttr {
ret := a.Token.(*xml.Attr)
return *ret
}
return a.Token
} | go | func (a XMLNode) GetToken() xml.Token {
if a.NodeType == tree.NtAttr {
ret := a.Token.(*xml.Attr)
return *ret
}
return a.Token
} | [
"func",
"(",
"a",
"XMLNode",
")",
"GetToken",
"(",
")",
"xml",
".",
"Token",
"{",
"if",
"a",
".",
"NodeType",
"==",
"tree",
".",
"NtAttr",
"{",
"ret",
":=",
"a",
".",
"Token",
".",
"(",
"*",
"xml",
".",
"Attr",
")",
"\n",
"return",
"*",
"ret",
... | //GetToken returns the xml.Token representation of the node | [
"GetToken",
"returns",
"the",
"xml",
".",
"Token",
"representation",
"of",
"the",
"node"
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/xmltree/xmlnode/xmlnode.go#L18-L24 | test |
ChrisTrenkamp/goxpath | tree/xmltree/xmlnode/xmlnode.go | ResValue | func (a XMLNode) ResValue() string {
switch a.NodeType {
case tree.NtAttr:
return a.Token.(*xml.Attr).Value
case tree.NtChd:
return string(a.Token.(xml.CharData))
case tree.NtComm:
return string(a.Token.(xml.Comment))
}
//case tree.NtPi:
return string(a.Token.(xml.ProcInst).Inst)
} | go | func (a XMLNode) ResValue() string {
switch a.NodeType {
case tree.NtAttr:
return a.Token.(*xml.Attr).Value
case tree.NtChd:
return string(a.Token.(xml.CharData))
case tree.NtComm:
return string(a.Token.(xml.Comment))
}
//case tree.NtPi:
return string(a.Token.(xml.ProcInst).Inst)
} | [
"func",
"(",
"a",
"XMLNode",
")",
"ResValue",
"(",
")",
"string",
"{",
"switch",
"a",
".",
"NodeType",
"{",
"case",
"tree",
".",
"NtAttr",
":",
"return",
"a",
".",
"Token",
".",
"(",
"*",
"xml",
".",
"Attr",
")",
".",
"Value",
"\n",
"case",
"tree... | //ResValue returns the string value of the attribute | [
"ResValue",
"returns",
"the",
"string",
"value",
"of",
"the",
"attribute"
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/xmltree/xmlnode/xmlnode.go#L32-L43 | test |
ChrisTrenkamp/goxpath | internal/execxp/execxp.go | Exec | func Exec(n *parser.Node, t tree.Node, ns map[string]string, fns map[xml.Name]tree.Wrap, v map[string]tree.Result) (tree.Result, error) {
f := xpFilt{
t: t,
ns: ns,
ctx: tree.NodeSet{t},
fns: fns,
variables: v,
}
return exec(&f, n)
} | go | func Exec(n *parser.Node, t tree.Node, ns map[string]string, fns map[xml.Name]tree.Wrap, v map[string]tree.Result) (tree.Result, error) {
f := xpFilt{
t: t,
ns: ns,
ctx: tree.NodeSet{t},
fns: fns,
variables: v,
}
return exec(&f, n)
} | [
"func",
"Exec",
"(",
"n",
"*",
"parser",
".",
"Node",
",",
"t",
"tree",
".",
"Node",
",",
"ns",
"map",
"[",
"string",
"]",
"string",
",",
"fns",
"map",
"[",
"xml",
".",
"Name",
"]",
"tree",
".",
"Wrap",
",",
"v",
"map",
"[",
"string",
"]",
"t... | //Exec executes the XPath expression, xp, against the tree, t, with the
//namespace mappings, ns. | [
"Exec",
"executes",
"the",
"XPath",
"expression",
"xp",
"against",
"the",
"tree",
"t",
"with",
"the",
"namespace",
"mappings",
"ns",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/internal/execxp/execxp.go#L12-L22 | test |
ChrisTrenkamp/goxpath | tree/xtypes.go | String | func (n Num) String() string {
if math.IsInf(float64(n), 0) {
if math.IsInf(float64(n), 1) {
return "Infinity"
}
return "-Infinity"
}
return fmt.Sprintf("%g", float64(n))
} | go | func (n Num) String() string {
if math.IsInf(float64(n), 0) {
if math.IsInf(float64(n), 1) {
return "Infinity"
}
return "-Infinity"
}
return fmt.Sprintf("%g", float64(n))
} | [
"func",
"(",
"n",
"Num",
")",
"String",
"(",
")",
"string",
"{",
"if",
"math",
".",
"IsInf",
"(",
"float64",
"(",
"n",
")",
",",
"0",
")",
"{",
"if",
"math",
".",
"IsInf",
"(",
"float64",
"(",
"n",
")",
",",
"1",
")",
"{",
"return",
"\"Infini... | //ResValue satisfies the Res interface for Num | [
"ResValue",
"satisfies",
"the",
"Res",
"interface",
"for",
"Num"
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/xtypes.go#L46-L54 | test |
ChrisTrenkamp/goxpath | tree/xtypes.go | Num | func (s String) Num() Num {
num, err := strconv.ParseFloat(strings.TrimSpace(string(s)), 64)
if err != nil {
return Num(math.NaN())
}
return Num(num)
} | go | func (s String) Num() Num {
num, err := strconv.ParseFloat(strings.TrimSpace(string(s)), 64)
if err != nil {
return Num(math.NaN())
}
return Num(num)
} | [
"func",
"(",
"s",
"String",
")",
"Num",
"(",
")",
"Num",
"{",
"num",
",",
"err",
":=",
"strconv",
".",
"ParseFloat",
"(",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"s",
")",
")",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | //Num satisfies the HasNum interface for String's | [
"Num",
"satisfies",
"the",
"HasNum",
"interface",
"for",
"String",
"s"
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/xtypes.go#L80-L86 | test |
ChrisTrenkamp/goxpath | tree/tree.go | BuildNS | func BuildNS(t Elem) (ret []NS) {
vals := make(map[xml.Name]string)
if nselem, ok := t.(NSElem); ok {
buildNS(nselem, vals)
ret = make([]NS, 0, len(vals))
i := 1
for k, v := range vals {
if !(k.Local == "xmlns" && k.Space == "" && v == "") {
ret = append(ret, NS{
Attr: xml.Attr{Name: k, Val... | go | func BuildNS(t Elem) (ret []NS) {
vals := make(map[xml.Name]string)
if nselem, ok := t.(NSElem); ok {
buildNS(nselem, vals)
ret = make([]NS, 0, len(vals))
i := 1
for k, v := range vals {
if !(k.Local == "xmlns" && k.Space == "" && v == "") {
ret = append(ret, NS{
Attr: xml.Attr{Name: k, Val... | [
"func",
"BuildNS",
"(",
"t",
"Elem",
")",
"(",
"ret",
"[",
"]",
"NS",
")",
"{",
"vals",
":=",
"make",
"(",
"map",
"[",
"xml",
".",
"Name",
"]",
"string",
")",
"\n",
"if",
"nselem",
",",
"ok",
":=",
"t",
".",
"(",
"NSElem",
")",
";",
"ok",
"... | //BuildNS resolves all the namespace nodes of the element and returns them | [
"BuildNS",
"resolves",
"all",
"the",
"namespace",
"nodes",
"of",
"the",
"element",
"and",
"returns",
"them"
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/tree.go#L89-L116 | test |
ChrisTrenkamp/goxpath | tree/tree.go | GetAttribute | func GetAttribute(n Elem, local, space string) (xml.Attr, bool) {
attrs := n.GetAttrs()
for _, i := range attrs {
attr := i.GetToken().(xml.Attr)
if local == attr.Name.Local && space == attr.Name.Space {
return attr, true
}
}
return xml.Attr{}, false
} | go | func GetAttribute(n Elem, local, space string) (xml.Attr, bool) {
attrs := n.GetAttrs()
for _, i := range attrs {
attr := i.GetToken().(xml.Attr)
if local == attr.Name.Local && space == attr.Name.Space {
return attr, true
}
}
return xml.Attr{}, false
} | [
"func",
"GetAttribute",
"(",
"n",
"Elem",
",",
"local",
",",
"space",
"string",
")",
"(",
"xml",
".",
"Attr",
",",
"bool",
")",
"{",
"attrs",
":=",
"n",
".",
"GetAttrs",
"(",
")",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"attrs",
"{",
"attr",
... | //GetAttribute is a convenience function for getting the specified attribute from an element.
//false is returned if the attribute is not found. | [
"GetAttribute",
"is",
"a",
"convenience",
"function",
"for",
"getting",
"the",
"specified",
"attribute",
"from",
"an",
"element",
".",
"false",
"is",
"returned",
"if",
"the",
"attribute",
"is",
"not",
"found",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/tree.go#L157-L166 | test |
ChrisTrenkamp/goxpath | tree/tree.go | GetAttributeVal | func GetAttributeVal(n Elem, local, space string) (string, bool) {
attr, ok := GetAttribute(n, local, space)
return attr.Value, ok
} | go | func GetAttributeVal(n Elem, local, space string) (string, bool) {
attr, ok := GetAttribute(n, local, space)
return attr.Value, ok
} | [
"func",
"GetAttributeVal",
"(",
"n",
"Elem",
",",
"local",
",",
"space",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"attr",
",",
"ok",
":=",
"GetAttribute",
"(",
"n",
",",
"local",
",",
"space",
")",
"\n",
"return",
"attr",
".",
"Value",
... | //GetAttributeVal is like GetAttribute, except it returns the attribute's value. | [
"GetAttributeVal",
"is",
"like",
"GetAttribute",
"except",
"it",
"returns",
"the",
"attribute",
"s",
"value",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/tree.go#L169-L172 | test |
ChrisTrenkamp/goxpath | tree/tree.go | GetAttrValOrEmpty | func GetAttrValOrEmpty(n Elem, local, space string) string {
val, ok := GetAttributeVal(n, local, space)
if !ok {
return ""
}
return val
} | go | func GetAttrValOrEmpty(n Elem, local, space string) string {
val, ok := GetAttributeVal(n, local, space)
if !ok {
return ""
}
return val
} | [
"func",
"GetAttrValOrEmpty",
"(",
"n",
"Elem",
",",
"local",
",",
"space",
"string",
")",
"string",
"{",
"val",
",",
"ok",
":=",
"GetAttributeVal",
"(",
"n",
",",
"local",
",",
"space",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"\"",
"\n",
"}",
... | //GetAttrValOrEmpty is like GetAttributeVal, except it returns an empty string if
//the attribute is not found instead of false. | [
"GetAttrValOrEmpty",
"is",
"like",
"GetAttributeVal",
"except",
"it",
"returns",
"an",
"empty",
"string",
"if",
"the",
"attribute",
"is",
"not",
"found",
"instead",
"of",
"false",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/tree.go#L176-L182 | test |
ChrisTrenkamp/goxpath | tree/tree.go | FindNodeByPos | func FindNodeByPos(n Node, pos int) Node {
if n.Pos() == pos {
return n
}
if elem, ok := n.(Elem); ok {
chldrn := elem.GetChildren()
for i := 1; i < len(chldrn); i++ {
if chldrn[i-1].Pos() <= pos && chldrn[i].Pos() > pos {
return FindNodeByPos(chldrn[i-1], pos)
}
}
if len(chldrn) > 0 {
if ch... | go | func FindNodeByPos(n Node, pos int) Node {
if n.Pos() == pos {
return n
}
if elem, ok := n.(Elem); ok {
chldrn := elem.GetChildren()
for i := 1; i < len(chldrn); i++ {
if chldrn[i-1].Pos() <= pos && chldrn[i].Pos() > pos {
return FindNodeByPos(chldrn[i-1], pos)
}
}
if len(chldrn) > 0 {
if ch... | [
"func",
"FindNodeByPos",
"(",
"n",
"Node",
",",
"pos",
"int",
")",
"Node",
"{",
"if",
"n",
".",
"Pos",
"(",
")",
"==",
"pos",
"{",
"return",
"n",
"\n",
"}",
"\n",
"if",
"elem",
",",
"ok",
":=",
"n",
".",
"(",
"Elem",
")",
";",
"ok",
"{",
"c... | //FindNodeByPos finds a node from the given position. Returns nil if the node
//is not found. | [
"FindNodeByPos",
"finds",
"a",
"node",
"from",
"the",
"given",
"position",
".",
"Returns",
"nil",
"if",
"the",
"node",
"is",
"not",
"found",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/tree/tree.go#L186-L221 | test |
ChrisTrenkamp/goxpath | marshal.go | Marshal | func Marshal(n tree.Node, w io.Writer) error {
return marshal(n, w)
} | go | func Marshal(n tree.Node, w io.Writer) error {
return marshal(n, w)
} | [
"func",
"Marshal",
"(",
"n",
"tree",
".",
"Node",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"marshal",
"(",
"n",
",",
"w",
")",
"\n",
"}"
] | //Marshal prints the result tree, r, in XML form to w. | [
"Marshal",
"prints",
"the",
"result",
"tree",
"r",
"in",
"XML",
"form",
"to",
"w",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/marshal.go#L12-L14 | test |
ChrisTrenkamp/goxpath | marshal.go | MarshalStr | func MarshalStr(n tree.Node) (string, error) {
ret := bytes.NewBufferString("")
err := marshal(n, ret)
return ret.String(), err
} | go | func MarshalStr(n tree.Node) (string, error) {
ret := bytes.NewBufferString("")
err := marshal(n, ret)
return ret.String(), err
} | [
"func",
"MarshalStr",
"(",
"n",
"tree",
".",
"Node",
")",
"(",
"string",
",",
"error",
")",
"{",
"ret",
":=",
"bytes",
".",
"NewBufferString",
"(",
"\"\"",
")",
"\n",
"err",
":=",
"marshal",
"(",
"n",
",",
"ret",
")",
"\n",
"return",
"ret",
".",
... | //MarshalStr is like Marhal, but returns a string. | [
"MarshalStr",
"is",
"like",
"Marhal",
"but",
"returns",
"a",
"string",
"."
] | c385f95c6022e7756e91beac5f5510872f7dcb7d | https://github.com/ChrisTrenkamp/goxpath/blob/c385f95c6022e7756e91beac5f5510872f7dcb7d/marshal.go#L17-L22 | test |
anmitsu/go-shlex | shlex.go | NewLexer | func NewLexer(r io.Reader, posix, whitespacesplit bool) *Lexer {
return &Lexer{
reader: bufio.NewReader(r),
tokenizer: &DefaultTokenizer{},
posix: posix,
whitespacesplit: whitespacesplit,
}
} | go | func NewLexer(r io.Reader, posix, whitespacesplit bool) *Lexer {
return &Lexer{
reader: bufio.NewReader(r),
tokenizer: &DefaultTokenizer{},
posix: posix,
whitespacesplit: whitespacesplit,
}
} | [
"func",
"NewLexer",
"(",
"r",
"io",
".",
"Reader",
",",
"posix",
",",
"whitespacesplit",
"bool",
")",
"*",
"Lexer",
"{",
"return",
"&",
"Lexer",
"{",
"reader",
":",
"bufio",
".",
"NewReader",
"(",
"r",
")",
",",
"tokenizer",
":",
"&",
"DefaultTokenizer... | // NewLexer creates a new Lexer reading from io.Reader. This Lexer
// has a DefaultTokenizer according to posix and whitespacesplit
// rules. | [
"NewLexer",
"creates",
"a",
"new",
"Lexer",
"reading",
"from",
"io",
".",
"Reader",
".",
"This",
"Lexer",
"has",
"a",
"DefaultTokenizer",
"according",
"to",
"posix",
"and",
"whitespacesplit",
"rules",
"."
] | 648efa622239a2f6ff949fed78ee37b48d499ba4 | https://github.com/anmitsu/go-shlex/blob/648efa622239a2f6ff949fed78ee37b48d499ba4/shlex.go#L62-L69 | test |
anmitsu/go-shlex | shlex.go | NewLexerString | func NewLexerString(s string, posix, whitespacesplit bool) *Lexer {
return NewLexer(strings.NewReader(s), posix, whitespacesplit)
} | go | func NewLexerString(s string, posix, whitespacesplit bool) *Lexer {
return NewLexer(strings.NewReader(s), posix, whitespacesplit)
} | [
"func",
"NewLexerString",
"(",
"s",
"string",
",",
"posix",
",",
"whitespacesplit",
"bool",
")",
"*",
"Lexer",
"{",
"return",
"NewLexer",
"(",
"strings",
".",
"NewReader",
"(",
"s",
")",
",",
"posix",
",",
"whitespacesplit",
")",
"\n",
"}"
] | // NewLexerString creates a new Lexer reading from a string. This
// Lexer has a DefaultTokenizer according to posix and whitespacesplit
// rules. | [
"NewLexerString",
"creates",
"a",
"new",
"Lexer",
"reading",
"from",
"a",
"string",
".",
"This",
"Lexer",
"has",
"a",
"DefaultTokenizer",
"according",
"to",
"posix",
"and",
"whitespacesplit",
"rules",
"."
] | 648efa622239a2f6ff949fed78ee37b48d499ba4 | https://github.com/anmitsu/go-shlex/blob/648efa622239a2f6ff949fed78ee37b48d499ba4/shlex.go#L74-L76 | test |
anmitsu/go-shlex | shlex.go | Split | func Split(s string, posix bool) ([]string, error) {
return NewLexerString(s, posix, true).Split()
} | go | func Split(s string, posix bool) ([]string, error) {
return NewLexerString(s, posix, true).Split()
} | [
"func",
"Split",
"(",
"s",
"string",
",",
"posix",
"bool",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"return",
"NewLexerString",
"(",
"s",
",",
"posix",
",",
"true",
")",
".",
"Split",
"(",
")",
"\n",
"}"
] | // Split splits a string according to posix or non-posix rules. | [
"Split",
"splits",
"a",
"string",
"according",
"to",
"posix",
"or",
"non",
"-",
"posix",
"rules",
"."
] | 648efa622239a2f6ff949fed78ee37b48d499ba4 | https://github.com/anmitsu/go-shlex/blob/648efa622239a2f6ff949fed78ee37b48d499ba4/shlex.go#L79-L81 | test |
TheThingsNetwork/go-utils | errors/registry.go | Register | func (r *registry) Register(err *ErrDescriptor) {
r.Lock()
defer r.Unlock()
if err.Code == NoCode {
panic(fmt.Errorf("No code defined in error descriptor (message: `%s`)", err.MessageFormat))
}
if r.byCode[err.Code] != nil {
panic(fmt.Errorf("errors: Duplicate error code %v registered", err.Code))
}
err.r... | go | func (r *registry) Register(err *ErrDescriptor) {
r.Lock()
defer r.Unlock()
if err.Code == NoCode {
panic(fmt.Errorf("No code defined in error descriptor (message: `%s`)", err.MessageFormat))
}
if r.byCode[err.Code] != nil {
panic(fmt.Errorf("errors: Duplicate error code %v registered", err.Code))
}
err.r... | [
"func",
"(",
"r",
"*",
"registry",
")",
"Register",
"(",
"err",
"*",
"ErrDescriptor",
")",
"{",
"r",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
".",
"Code",
"==",
"NoCode",
"{",
"panic",
"(",
"fmt",
"... | // Register registers a new error type | [
"Register",
"registers",
"a",
"new",
"error",
"type"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/registry.go#L18-L32 | test |
TheThingsNetwork/go-utils | errors/registry.go | Get | func (r *registry) Get(code Code) *ErrDescriptor {
r.RLock()
defer r.RUnlock()
return r.byCode[code]
} | go | func (r *registry) Get(code Code) *ErrDescriptor {
r.RLock()
defer r.RUnlock()
return r.byCode[code]
} | [
"func",
"(",
"r",
"*",
"registry",
")",
"Get",
"(",
"code",
"Code",
")",
"*",
"ErrDescriptor",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"r",
".",
"byCode",
"[",
"code",
"]",
"\n",
"}"
] | // Get returns the descriptor if it exists or nil otherwise | [
"Get",
"returns",
"the",
"descriptor",
"if",
"it",
"exists",
"or",
"nil",
"otherwise"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/registry.go#L35-L39 | test |
TheThingsNetwork/go-utils | errors/registry.go | GetAll | func (r *registry) GetAll() []*ErrDescriptor {
r.RLock()
defer r.RUnlock()
res := make([]*ErrDescriptor, 0, len(r.byCode))
for _, d := range r.byCode {
res = append(res, d)
}
return res
} | go | func (r *registry) GetAll() []*ErrDescriptor {
r.RLock()
defer r.RUnlock()
res := make([]*ErrDescriptor, 0, len(r.byCode))
for _, d := range r.byCode {
res = append(res, d)
}
return res
} | [
"func",
"(",
"r",
"*",
"registry",
")",
"GetAll",
"(",
")",
"[",
"]",
"*",
"ErrDescriptor",
"{",
"r",
".",
"RLock",
"(",
")",
"\n",
"defer",
"r",
".",
"RUnlock",
"(",
")",
"\n",
"res",
":=",
"make",
"(",
"[",
"]",
"*",
"ErrDescriptor",
",",
"0"... | // GetAll returns all registered error descriptors | [
"GetAll",
"returns",
"all",
"registered",
"error",
"descriptors"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/registry.go#L42-L51 | test |
TheThingsNetwork/go-utils | errors/registry.go | From | func From(in error) Error {
if err, ok := in.(Error); ok {
return err
}
return FromGRPC(in)
} | go | func From(in error) Error {
if err, ok := in.(Error); ok {
return err
}
return FromGRPC(in)
} | [
"func",
"From",
"(",
"in",
"error",
")",
"Error",
"{",
"if",
"err",
",",
"ok",
":=",
"in",
".",
"(",
"Error",
")",
";",
"ok",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"FromGRPC",
"(",
"in",
")",
"\n",
"}"
] | // From lifts an error to be and Error | [
"From",
"lifts",
"an",
"error",
"to",
"be",
"and",
"Error"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/registry.go#L71-L77 | test |
TheThingsNetwork/go-utils | errors/registry.go | Descriptor | func Descriptor(in error) (desc *ErrDescriptor) {
err := From(in)
descriptor := Get(err.Code())
if descriptor != nil {
return descriptor
}
// return a new error descriptor with sane defaults
return &ErrDescriptor{
MessageFormat: err.Error(),
Type: err.Type(),
Code: err.Code(),
}
} | go | func Descriptor(in error) (desc *ErrDescriptor) {
err := From(in)
descriptor := Get(err.Code())
if descriptor != nil {
return descriptor
}
// return a new error descriptor with sane defaults
return &ErrDescriptor{
MessageFormat: err.Error(),
Type: err.Type(),
Code: err.Code(),
}
} | [
"func",
"Descriptor",
"(",
"in",
"error",
")",
"(",
"desc",
"*",
"ErrDescriptor",
")",
"{",
"err",
":=",
"From",
"(",
"in",
")",
"\n",
"descriptor",
":=",
"Get",
"(",
"err",
".",
"Code",
"(",
")",
")",
"\n",
"if",
"descriptor",
"!=",
"nil",
"{",
... | // Descriptor returns the error descriptor from any error | [
"Descriptor",
"returns",
"the",
"error",
"descriptor",
"from",
"any",
"error"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/registry.go#L80-L93 | test |
TheThingsNetwork/go-utils | errors/registry.go | GetAttributes | func GetAttributes(err error) Attributes {
e, ok := err.(Error)
if ok {
return e.Attributes()
}
return Attributes{}
} | go | func GetAttributes(err error) Attributes {
e, ok := err.(Error)
if ok {
return e.Attributes()
}
return Attributes{}
} | [
"func",
"GetAttributes",
"(",
"err",
"error",
")",
"Attributes",
"{",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"Error",
")",
"\n",
"if",
"ok",
"{",
"return",
"e",
".",
"Attributes",
"(",
")",
"\n",
"}",
"\n",
"return",
"Attributes",
"{",
"}",
"\n",
... | // GetAttributes returns the error attributes or falls back
// to empty attributes | [
"GetAttributes",
"returns",
"the",
"error",
"attributes",
"or",
"falls",
"back",
"to",
"empty",
"attributes"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/registry.go#L114-L121 | test |
TheThingsNetwork/go-utils | errors/http.go | HTTPStatusCode | func (t Type) HTTPStatusCode() int {
switch t {
case Canceled:
return http.StatusRequestTimeout
case InvalidArgument:
return http.StatusBadRequest
case OutOfRange:
return http.StatusBadRequest
case NotFound:
return http.StatusNotFound
case Conflict:
return http.StatusConflict
case AlreadyExists:
retu... | go | func (t Type) HTTPStatusCode() int {
switch t {
case Canceled:
return http.StatusRequestTimeout
case InvalidArgument:
return http.StatusBadRequest
case OutOfRange:
return http.StatusBadRequest
case NotFound:
return http.StatusNotFound
case Conflict:
return http.StatusConflict
case AlreadyExists:
retu... | [
"func",
"(",
"t",
"Type",
")",
"HTTPStatusCode",
"(",
")",
"int",
"{",
"switch",
"t",
"{",
"case",
"Canceled",
":",
"return",
"http",
".",
"StatusRequestTimeout",
"\n",
"case",
"InvalidArgument",
":",
"return",
"http",
".",
"StatusBadRequest",
"\n",
"case",
... | // HTTPStatusCode returns the corresponding http status code from an error type | [
"HTTPStatusCode",
"returns",
"the",
"corresponding",
"http",
"status",
"code",
"from",
"an",
"error",
"type"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/http.go#L15-L50 | test |
TheThingsNetwork/go-utils | errors/http.go | HTTPStatusCode | func HTTPStatusCode(err error) int {
e, ok := err.(Error)
if ok {
return e.Type().HTTPStatusCode()
}
return http.StatusInternalServerError
} | go | func HTTPStatusCode(err error) int {
e, ok := err.(Error)
if ok {
return e.Type().HTTPStatusCode()
}
return http.StatusInternalServerError
} | [
"func",
"HTTPStatusCode",
"(",
"err",
"error",
")",
"int",
"{",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"Error",
")",
"\n",
"if",
"ok",
"{",
"return",
"e",
".",
"Type",
"(",
")",
".",
"HTTPStatusCode",
"(",
")",
"\n",
"}",
"\n",
"return",
"http",
... | // HTTPStatusCode returns the HTTP status code for the given error or 500 if it doesn't know | [
"HTTPStatusCode",
"returns",
"the",
"HTTP",
"status",
"code",
"for",
"the",
"given",
"error",
"or",
"500",
"if",
"it",
"doesn",
"t",
"know"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/http.go#L53-L60 | test |
TheThingsNetwork/go-utils | errors/http.go | HTTPStatusToType | func HTTPStatusToType(status int) Type {
switch status {
case http.StatusBadRequest:
return InvalidArgument
case http.StatusNotFound:
return NotFound
case http.StatusConflict:
return Conflict
case http.StatusUnauthorized:
return Unauthorized
case http.StatusForbidden:
return PermissionDenied
case http.... | go | func HTTPStatusToType(status int) Type {
switch status {
case http.StatusBadRequest:
return InvalidArgument
case http.StatusNotFound:
return NotFound
case http.StatusConflict:
return Conflict
case http.StatusUnauthorized:
return Unauthorized
case http.StatusForbidden:
return PermissionDenied
case http.... | [
"func",
"HTTPStatusToType",
"(",
"status",
"int",
")",
"Type",
"{",
"switch",
"status",
"{",
"case",
"http",
".",
"StatusBadRequest",
":",
"return",
"InvalidArgument",
"\n",
"case",
"http",
".",
"StatusNotFound",
":",
"return",
"NotFound",
"\n",
"case",
"http"... | // HTTPStatusToType infers the error Type from a HTTP Status code | [
"HTTPStatusToType",
"infers",
"the",
"error",
"Type",
"from",
"a",
"HTTP",
"Status",
"code"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/http.go#L63-L90 | test |
TheThingsNetwork/go-utils | errors/http.go | ToHTTP | func ToHTTP(in error, w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
if err, ok := in.(Error); ok {
w.Header().Set(CodeHeader, err.Code().String())
w.WriteHeader(err.Type().HTTPStatusCode())
return json.NewEncoder(w).Encode(toJSON(err))
}
w.WriteHeader(http.StatusInternalSe... | go | func ToHTTP(in error, w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
if err, ok := in.(Error); ok {
w.Header().Set(CodeHeader, err.Code().String())
w.WriteHeader(err.Type().HTTPStatusCode())
return json.NewEncoder(w).Encode(toJSON(err))
}
w.WriteHeader(http.StatusInternalSe... | [
"func",
"ToHTTP",
"(",
"in",
"error",
",",
"w",
"http",
".",
"ResponseWriter",
")",
"error",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"Content-Type\"",
",",
"\"application/json\"",
")",
"\n",
"if",
"err",
",",
"ok",
":=",
"in",
".",
"(",... | // ToHTTP writes the error to the http response | [
"ToHTTP",
"writes",
"the",
"error",
"to",
"the",
"http",
"response"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/http.go#L122-L135 | test |
TheThingsNetwork/go-utils | errors/impl.go | toImpl | func toImpl(err Error) *impl {
if i, ok := err.(*impl); ok {
return i
}
return &impl{
message: err.Error(),
code: err.Code(),
typ: err.Type(),
attributes: err.Attributes(),
}
} | go | func toImpl(err Error) *impl {
if i, ok := err.(*impl); ok {
return i
}
return &impl{
message: err.Error(),
code: err.Code(),
typ: err.Type(),
attributes: err.Attributes(),
}
} | [
"func",
"toImpl",
"(",
"err",
"Error",
")",
"*",
"impl",
"{",
"if",
"i",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"impl",
")",
";",
"ok",
"{",
"return",
"i",
"\n",
"}",
"\n",
"return",
"&",
"impl",
"{",
"message",
":",
"err",
".",
"Error",
"(",... | // toImpl creates an equivalent impl for any Error | [
"toImpl",
"creates",
"an",
"equivalent",
"impl",
"for",
"any",
"Error"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/impl.go#L35-L46 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | MetadataFromIncomingContext | func MetadataFromIncomingContext(ctx context.Context) metadata.MD {
md, _ := metadata.FromIncomingContext(ctx)
return md
} | go | func MetadataFromIncomingContext(ctx context.Context) metadata.MD {
md, _ := metadata.FromIncomingContext(ctx)
return md
} | [
"func",
"MetadataFromIncomingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"metadata",
".",
"MD",
"{",
"md",
",",
"_",
":=",
"metadata",
".",
"FromIncomingContext",
"(",
"ctx",
")",
"\n",
"return",
"md",
"\n",
"}"
] | // MetadataFromIncomingContext gets the metadata from the given context | [
"MetadataFromIncomingContext",
"gets",
"the",
"metadata",
"from",
"the",
"given",
"context"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L15-L18 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | MetadataFromOutgoingContext | func MetadataFromOutgoingContext(ctx context.Context) metadata.MD {
md, _ := metadata.FromOutgoingContext(ctx)
return md
} | go | func MetadataFromOutgoingContext(ctx context.Context) metadata.MD {
md, _ := metadata.FromOutgoingContext(ctx)
return md
} | [
"func",
"MetadataFromOutgoingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"metadata",
".",
"MD",
"{",
"md",
",",
"_",
":=",
"metadata",
".",
"FromOutgoingContext",
"(",
"ctx",
")",
"\n",
"return",
"md",
"\n",
"}"
] | // MetadataFromOutgoingContext gets the metadata from the given context | [
"MetadataFromOutgoingContext",
"gets",
"the",
"metadata",
"from",
"the",
"given",
"context"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L21-L24 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | TokenFromMetadata | func TokenFromMetadata(md metadata.MD) (string, error) {
token, ok := md["token"]
if !ok || len(token) == 0 {
return "", ErrNoToken
}
return token[0], nil
} | go | func TokenFromMetadata(md metadata.MD) (string, error) {
token, ok := md["token"]
if !ok || len(token) == 0 {
return "", ErrNoToken
}
return token[0], nil
} | [
"func",
"TokenFromMetadata",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"string",
",",
"error",
")",
"{",
"token",
",",
"ok",
":=",
"md",
"[",
"\"token\"",
"]",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"token",
")",
"==",
"0",
"{",
"return",
"\"... | // TokenFromMetadata gets the token from the metadata or returns ErrNoToken | [
"TokenFromMetadata",
"gets",
"the",
"token",
"from",
"the",
"metadata",
"or",
"returns",
"ErrNoToken"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L27-L33 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | TokenFromIncomingContext | func TokenFromIncomingContext(ctx context.Context) (string, error) {
md := MetadataFromIncomingContext(ctx)
return TokenFromMetadata(md)
} | go | func TokenFromIncomingContext(ctx context.Context) (string, error) {
md := MetadataFromIncomingContext(ctx)
return TokenFromMetadata(md)
} | [
"func",
"TokenFromIncomingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"string",
",",
"error",
")",
"{",
"md",
":=",
"MetadataFromIncomingContext",
"(",
"ctx",
")",
"\n",
"return",
"TokenFromMetadata",
"(",
"md",
")",
"\n",
"}"
] | // TokenFromIncomingContext gets the token from the incoming context or returns ErrNoToken | [
"TokenFromIncomingContext",
"gets",
"the",
"token",
"from",
"the",
"incoming",
"context",
"or",
"returns",
"ErrNoToken"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L42-L45 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | OutgoingContextWithToken | func OutgoingContextWithToken(ctx context.Context, token string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "token", token)
} | go | func OutgoingContextWithToken(ctx context.Context, token string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "token", token)
} | [
"func",
"OutgoingContextWithToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"token",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"outgoingContextWithMergedMetadata",
"(",
"ctx",
",",
"\"token\"",
",",
"token",
")",
"\n",
"}"
] | // OutgoingContextWithToken returns an outgoing context with the token | [
"OutgoingContextWithToken",
"returns",
"an",
"outgoing",
"context",
"with",
"the",
"token"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L48-L50 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | KeyFromMetadata | func KeyFromMetadata(md metadata.MD) (string, error) {
key, ok := md["key"]
if !ok || len(key) == 0 {
return "", ErrNoKey
}
return key[0], nil
} | go | func KeyFromMetadata(md metadata.MD) (string, error) {
key, ok := md["key"]
if !ok || len(key) == 0 {
return "", ErrNoKey
}
return key[0], nil
} | [
"func",
"KeyFromMetadata",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"string",
",",
"error",
")",
"{",
"key",
",",
"ok",
":=",
"md",
"[",
"\"key\"",
"]",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"key",
")",
"==",
"0",
"{",
"return",
"\"\"",
"... | // KeyFromMetadata gets the key from the metadata or returns ErrNoKey | [
"KeyFromMetadata",
"gets",
"the",
"key",
"from",
"the",
"metadata",
"or",
"returns",
"ErrNoKey"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L53-L59 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | KeyFromIncomingContext | func KeyFromIncomingContext(ctx context.Context) (string, error) {
md := MetadataFromIncomingContext(ctx)
return KeyFromMetadata(md)
} | go | func KeyFromIncomingContext(ctx context.Context) (string, error) {
md := MetadataFromIncomingContext(ctx)
return KeyFromMetadata(md)
} | [
"func",
"KeyFromIncomingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"string",
",",
"error",
")",
"{",
"md",
":=",
"MetadataFromIncomingContext",
"(",
"ctx",
")",
"\n",
"return",
"KeyFromMetadata",
"(",
"md",
")",
"\n",
"}"
] | // KeyFromIncomingContext gets the key from the incoming context or returns ErrNoKey | [
"KeyFromIncomingContext",
"gets",
"the",
"key",
"from",
"the",
"incoming",
"context",
"or",
"returns",
"ErrNoKey"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L62-L65 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | OutgoingContextWithKey | func OutgoingContextWithKey(ctx context.Context, key string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "key", key)
} | go | func OutgoingContextWithKey(ctx context.Context, key string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "key", key)
} | [
"func",
"OutgoingContextWithKey",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"outgoingContextWithMergedMetadata",
"(",
"ctx",
",",
"\"key\"",
",",
"key",
")",
"\n",
"}"
] | // OutgoingContextWithKey returns an outgoing context with the key | [
"OutgoingContextWithKey",
"returns",
"an",
"outgoing",
"context",
"with",
"the",
"key"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L68-L70 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | IDFromMetadata | func IDFromMetadata(md metadata.MD) (string, error) {
id, ok := md["id"]
if !ok || len(id) == 0 {
return "", ErrNoID
}
return id[0], nil
} | go | func IDFromMetadata(md metadata.MD) (string, error) {
id, ok := md["id"]
if !ok || len(id) == 0 {
return "", ErrNoID
}
return id[0], nil
} | [
"func",
"IDFromMetadata",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"string",
",",
"error",
")",
"{",
"id",
",",
"ok",
":=",
"md",
"[",
"\"id\"",
"]",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"id",
")",
"==",
"0",
"{",
"return",
"\"\"",
",",
... | // IDFromMetadata gets the key from the metadata or returns ErrNoID | [
"IDFromMetadata",
"gets",
"the",
"key",
"from",
"the",
"metadata",
"or",
"returns",
"ErrNoID"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L73-L79 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | IDFromIncomingContext | func IDFromIncomingContext(ctx context.Context) (string, error) {
md := MetadataFromIncomingContext(ctx)
return IDFromMetadata(md)
} | go | func IDFromIncomingContext(ctx context.Context) (string, error) {
md := MetadataFromIncomingContext(ctx)
return IDFromMetadata(md)
} | [
"func",
"IDFromIncomingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"string",
",",
"error",
")",
"{",
"md",
":=",
"MetadataFromIncomingContext",
"(",
"ctx",
")",
"\n",
"return",
"IDFromMetadata",
"(",
"md",
")",
"\n",
"}"
] | // IDFromIncomingContext gets the key from the incoming context or returns ErrNoID | [
"IDFromIncomingContext",
"gets",
"the",
"key",
"from",
"the",
"incoming",
"context",
"or",
"returns",
"ErrNoID"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L82-L85 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | OutgoingContextWithID | func OutgoingContextWithID(ctx context.Context, id string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "id", id)
} | go | func OutgoingContextWithID(ctx context.Context, id string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "id", id)
} | [
"func",
"OutgoingContextWithID",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"outgoingContextWithMergedMetadata",
"(",
"ctx",
",",
"\"id\"",
",",
"id",
")",
"\n",
"}"
] | // OutgoingContextWithID returns an outgoing context with the id | [
"OutgoingContextWithID",
"returns",
"an",
"outgoing",
"context",
"with",
"the",
"id"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L88-L90 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | ServiceInfoFromMetadata | func ServiceInfoFromMetadata(md metadata.MD) (serviceName, serviceVersion, netAddress string, err error) {
serviceNameL, ok := md["service-name"]
if ok && len(serviceNameL) > 0 {
serviceName = serviceNameL[0]
}
serviceVersionL, ok := md["service-version"]
if ok && len(serviceVersionL) > 0 {
serviceVersion = se... | go | func ServiceInfoFromMetadata(md metadata.MD) (serviceName, serviceVersion, netAddress string, err error) {
serviceNameL, ok := md["service-name"]
if ok && len(serviceNameL) > 0 {
serviceName = serviceNameL[0]
}
serviceVersionL, ok := md["service-version"]
if ok && len(serviceVersionL) > 0 {
serviceVersion = se... | [
"func",
"ServiceInfoFromMetadata",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"serviceName",
",",
"serviceVersion",
",",
"netAddress",
"string",
",",
"err",
"error",
")",
"{",
"serviceNameL",
",",
"ok",
":=",
"md",
"[",
"\"service-name\"",
"]",
"\n",
"if",
... | // ServiceInfoFromMetadata gets the service information from the metadata or returns empty strings | [
"ServiceInfoFromMetadata",
"gets",
"the",
"service",
"information",
"from",
"the",
"metadata",
"or",
"returns",
"empty",
"strings"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L93-L107 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | ServiceInfoFromIncomingContext | func ServiceInfoFromIncomingContext(ctx context.Context) (serviceName, serviceVersion, netAddress string, err error) {
md := MetadataFromIncomingContext(ctx)
return ServiceInfoFromMetadata(md)
} | go | func ServiceInfoFromIncomingContext(ctx context.Context) (serviceName, serviceVersion, netAddress string, err error) {
md := MetadataFromIncomingContext(ctx)
return ServiceInfoFromMetadata(md)
} | [
"func",
"ServiceInfoFromIncomingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"serviceName",
",",
"serviceVersion",
",",
"netAddress",
"string",
",",
"err",
"error",
")",
"{",
"md",
":=",
"MetadataFromIncomingContext",
"(",
"ctx",
")",
"\n",
"return... | // ServiceInfoFromIncomingContext gets the service information from the incoming context or returns empty strings | [
"ServiceInfoFromIncomingContext",
"gets",
"the",
"service",
"information",
"from",
"the",
"incoming",
"context",
"or",
"returns",
"empty",
"strings"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L110-L113 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | OutgoingContextWithServiceInfo | func OutgoingContextWithServiceInfo(ctx context.Context, serviceName, serviceVersion, netAddress string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "service-name", serviceName, "service-version", serviceVersion, "net-address", netAddress)
} | go | func OutgoingContextWithServiceInfo(ctx context.Context, serviceName, serviceVersion, netAddress string) context.Context {
return outgoingContextWithMergedMetadata(ctx, "service-name", serviceName, "service-version", serviceVersion, "net-address", netAddress)
} | [
"func",
"OutgoingContextWithServiceInfo",
"(",
"ctx",
"context",
".",
"Context",
",",
"serviceName",
",",
"serviceVersion",
",",
"netAddress",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"outgoingContextWithMergedMetadata",
"(",
"ctx",
",",
"\"service-nam... | // OutgoingContextWithServiceInfo returns an outgoing context with the id | [
"OutgoingContextWithServiceInfo",
"returns",
"an",
"outgoing",
"context",
"with",
"the",
"id"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L116-L118 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | LimitFromMetadata | func LimitFromMetadata(md metadata.MD) (uint64, error) {
limit, ok := md["limit"]
if !ok || len(limit) == 0 {
return 0, nil
}
return strconv.ParseUint(limit[0], 10, 64)
} | go | func LimitFromMetadata(md metadata.MD) (uint64, error) {
limit, ok := md["limit"]
if !ok || len(limit) == 0 {
return 0, nil
}
return strconv.ParseUint(limit[0], 10, 64)
} | [
"func",
"LimitFromMetadata",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"limit",
",",
"ok",
":=",
"md",
"[",
"\"limit\"",
"]",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"limit",
")",
"==",
"0",
"{",
"return",
"0"... | // LimitFromMetadata gets the limit from the metadata | [
"LimitFromMetadata",
"gets",
"the",
"limit",
"from",
"the",
"metadata"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L121-L127 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | OffsetFromMetadata | func OffsetFromMetadata(md metadata.MD) (uint64, error) {
offset, ok := md["offset"]
if !ok || len(offset) == 0 {
return 0, nil
}
return strconv.ParseUint(offset[0], 10, 64)
} | go | func OffsetFromMetadata(md metadata.MD) (uint64, error) {
offset, ok := md["offset"]
if !ok || len(offset) == 0 {
return 0, nil
}
return strconv.ParseUint(offset[0], 10, 64)
} | [
"func",
"OffsetFromMetadata",
"(",
"md",
"metadata",
".",
"MD",
")",
"(",
"uint64",
",",
"error",
")",
"{",
"offset",
",",
"ok",
":=",
"md",
"[",
"\"offset\"",
"]",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"offset",
")",
"==",
"0",
"{",
"return",
... | // OffsetFromMetadata gets the offset from the metadata | [
"OffsetFromMetadata",
"gets",
"the",
"offset",
"from",
"the",
"metadata"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L130-L136 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | LimitAndOffsetFromIncomingContext | func LimitAndOffsetFromIncomingContext(ctx context.Context) (limit, offset uint64, err error) {
md := MetadataFromIncomingContext(ctx)
limit, err = LimitFromMetadata(md)
if err != nil {
return 0, 0, err
}
offset, err = OffsetFromMetadata(md)
if err != nil {
return 0, 0, err
}
return limit, offset, nil
} | go | func LimitAndOffsetFromIncomingContext(ctx context.Context) (limit, offset uint64, err error) {
md := MetadataFromIncomingContext(ctx)
limit, err = LimitFromMetadata(md)
if err != nil {
return 0, 0, err
}
offset, err = OffsetFromMetadata(md)
if err != nil {
return 0, 0, err
}
return limit, offset, nil
} | [
"func",
"LimitAndOffsetFromIncomingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"limit",
",",
"offset",
"uint64",
",",
"err",
"error",
")",
"{",
"md",
":=",
"MetadataFromIncomingContext",
"(",
"ctx",
")",
"\n",
"limit",
",",
"err",
"=",
"LimitF... | // LimitAndOffsetFromIncomingContext gets the limit and offset from the incoming context | [
"LimitAndOffsetFromIncomingContext",
"gets",
"the",
"limit",
"and",
"offset",
"from",
"the",
"incoming",
"context"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L139-L150 | test |
TheThingsNetwork/go-utils | grpc/ttnctx/context.go | OutgoingContextWithLimitAndOffset | func OutgoingContextWithLimitAndOffset(ctx context.Context, limit, offset uint64) context.Context {
var pairs []string
if limit != 0 {
pairs = append(pairs, "limit", strconv.FormatUint(limit, 10))
}
if offset != 0 {
pairs = append(pairs, "offset", strconv.FormatUint(offset, 10))
}
if len(pairs) == 0 {
retur... | go | func OutgoingContextWithLimitAndOffset(ctx context.Context, limit, offset uint64) context.Context {
var pairs []string
if limit != 0 {
pairs = append(pairs, "limit", strconv.FormatUint(limit, 10))
}
if offset != 0 {
pairs = append(pairs, "offset", strconv.FormatUint(offset, 10))
}
if len(pairs) == 0 {
retur... | [
"func",
"OutgoingContextWithLimitAndOffset",
"(",
"ctx",
"context",
".",
"Context",
",",
"limit",
",",
"offset",
"uint64",
")",
"context",
".",
"Context",
"{",
"var",
"pairs",
"[",
"]",
"string",
"\n",
"if",
"limit",
"!=",
"0",
"{",
"pairs",
"=",
"append",... | // OutgoingContextWithLimitAndOffset returns an outgoing context with the limit and offset | [
"OutgoingContextWithLimitAndOffset",
"returns",
"an",
"outgoing",
"context",
"with",
"the",
"limit",
"and",
"offset"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/ttnctx/context.go#L153-L165 | test |
TheThingsNetwork/go-utils | queue/schedule.go | before | func before(i, j ScheduleItem) bool {
iEnd := i.Time().UnixNano() + i.Duration().Nanoseconds()
jStart := j.Time().UnixNano()
if i, ok := i.(ScheduleItemWithTimestamp); ok {
if j, ok := j.(ScheduleItemWithTimestamp); ok {
iEnd = i.Timestamp() + i.Duration().Nanoseconds()
jStart = j.Timestamp()
}
}
return ... | go | func before(i, j ScheduleItem) bool {
iEnd := i.Time().UnixNano() + i.Duration().Nanoseconds()
jStart := j.Time().UnixNano()
if i, ok := i.(ScheduleItemWithTimestamp); ok {
if j, ok := j.(ScheduleItemWithTimestamp); ok {
iEnd = i.Timestamp() + i.Duration().Nanoseconds()
jStart = j.Timestamp()
}
}
return ... | [
"func",
"before",
"(",
"i",
",",
"j",
"ScheduleItem",
")",
"bool",
"{",
"iEnd",
":=",
"i",
".",
"Time",
"(",
")",
".",
"UnixNano",
"(",
")",
"+",
"i",
".",
"Duration",
"(",
")",
".",
"Nanoseconds",
"(",
")",
"\n",
"jStart",
":=",
"j",
".",
"Tim... | // returns true if i before j | [
"returns",
"true",
"if",
"i",
"before",
"j"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/queue/schedule.go#L67-L77 | test |
TheThingsNetwork/go-utils | errors/descriptor.go | New | func (err *ErrDescriptor) New(attributes Attributes) Error {
if err.Code != NoCode && !err.registered {
panic(fmt.Errorf("Error descriptor with code %v was not registered", err.Code))
}
return &impl{
message: Format(err.MessageFormat, attributes),
code: err.Code,
typ: err.Type,
attributes:... | go | func (err *ErrDescriptor) New(attributes Attributes) Error {
if err.Code != NoCode && !err.registered {
panic(fmt.Errorf("Error descriptor with code %v was not registered", err.Code))
}
return &impl{
message: Format(err.MessageFormat, attributes),
code: err.Code,
typ: err.Type,
attributes:... | [
"func",
"(",
"err",
"*",
"ErrDescriptor",
")",
"New",
"(",
"attributes",
"Attributes",
")",
"Error",
"{",
"if",
"err",
".",
"Code",
"!=",
"NoCode",
"&&",
"!",
"err",
".",
"registered",
"{",
"panic",
"(",
"fmt",
".",
"Errorf",
"(",
"\"Error descriptor wit... | // New creates a new error based on the error descriptor | [
"New",
"creates",
"a",
"new",
"error",
"based",
"on",
"the",
"error",
"descriptor"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/descriptor.go#L38-L49 | test |
TheThingsNetwork/go-utils | log/namespaced/namespaced.go | WithNamespace | func WithNamespace(namespace string, ctx log.Interface) log.Interface {
return ctx.WithField(NamespaceKey, namespace)
} | go | func WithNamespace(namespace string, ctx log.Interface) log.Interface {
return ctx.WithField(NamespaceKey, namespace)
} | [
"func",
"WithNamespace",
"(",
"namespace",
"string",
",",
"ctx",
"log",
".",
"Interface",
")",
"log",
".",
"Interface",
"{",
"return",
"ctx",
".",
"WithField",
"(",
"NamespaceKey",
",",
"namespace",
")",
"\n",
"}"
] | // WithNamespace adds a namespace to the logging context | [
"WithNamespace",
"adds",
"a",
"namespace",
"to",
"the",
"logging",
"context"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/namespaced/namespaced.go#L21-L23 | test |
TheThingsNetwork/go-utils | log/namespaced/namespaced.go | Wrap | func Wrap(ctx log.Interface, namespaces ...string) *Namespaced {
return &Namespaced{
Interface: ctx,
namespaces: &ns{
namespaces: namespaces,
},
}
} | go | func Wrap(ctx log.Interface, namespaces ...string) *Namespaced {
return &Namespaced{
Interface: ctx,
namespaces: &ns{
namespaces: namespaces,
},
}
} | [
"func",
"Wrap",
"(",
"ctx",
"log",
".",
"Interface",
",",
"namespaces",
"...",
"string",
")",
"*",
"Namespaced",
"{",
"return",
"&",
"Namespaced",
"{",
"Interface",
":",
"ctx",
",",
"namespaces",
":",
"&",
"ns",
"{",
"namespaces",
":",
"namespaces",
",",... | // Wrap wraps the logger in a Namespaced logger and enables the specified
// namespaces. See SetNamespaces for information on how to set the namspaces | [
"Wrap",
"wraps",
"the",
"logger",
"in",
"a",
"Namespaced",
"logger",
"and",
"enables",
"the",
"specified",
"namespaces",
".",
"See",
"SetNamespaces",
"for",
"information",
"on",
"how",
"to",
"set",
"the",
"namspaces"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/namespaced/namespaced.go#L27-L34 | test |
TheThingsNetwork/go-utils | log/namespaced/namespaced.go | WithField | func (n *Namespaced) WithField(k string, v interface{}) log.Interface {
if k == NamespaceKey {
if str, ok := v.(string); ok {
return &Namespaced{
Interface: n.Interface,
namespaces: n.namespaces,
namespace: str,
}
}
}
return &Namespaced{
Interface: n.Interface.WithField(k, v),
namespace... | go | func (n *Namespaced) WithField(k string, v interface{}) log.Interface {
if k == NamespaceKey {
if str, ok := v.(string); ok {
return &Namespaced{
Interface: n.Interface,
namespaces: n.namespaces,
namespace: str,
}
}
}
return &Namespaced{
Interface: n.Interface.WithField(k, v),
namespace... | [
"func",
"(",
"n",
"*",
"Namespaced",
")",
"WithField",
"(",
"k",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"log",
".",
"Interface",
"{",
"if",
"k",
"==",
"NamespaceKey",
"{",
"if",
"str",
",",
"ok",
":=",
"v",
".",
"(",
"string",
")",
";",
... | // WithField adds a field to the logger | [
"WithField",
"adds",
"a",
"field",
"to",
"the",
"logger"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/namespaced/namespaced.go#L52-L68 | test |
TheThingsNetwork/go-utils | log/namespaced/namespaced.go | WithFields | func (n *Namespaced) WithFields(fields log.Fields) log.Interface {
return &Namespaced{
Interface: n.Interface.WithFields(fields),
namespaces: n.namespaces,
namespace: n.namespace,
}
} | go | func (n *Namespaced) WithFields(fields log.Fields) log.Interface {
return &Namespaced{
Interface: n.Interface.WithFields(fields),
namespaces: n.namespaces,
namespace: n.namespace,
}
} | [
"func",
"(",
"n",
"*",
"Namespaced",
")",
"WithFields",
"(",
"fields",
"log",
".",
"Fields",
")",
"log",
".",
"Interface",
"{",
"return",
"&",
"Namespaced",
"{",
"Interface",
":",
"n",
".",
"Interface",
".",
"WithFields",
"(",
"fields",
")",
",",
"name... | // WithFields adds multiple fields to the logger | [
"WithFields",
"adds",
"multiple",
"fields",
"to",
"the",
"logger"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/namespaced/namespaced.go#L71-L77 | test |
TheThingsNetwork/go-utils | errors/format.go | Format | func Format(format string, values Attributes) string {
formatter, err := messageformat.New()
if err != nil {
return format
}
fm, err := formatter.Parse(format)
if err != nil {
return format
}
fixed := make(map[string]interface{}, len(values))
for k, v := range values {
fixed[k] = fix(v)
}
// todo for... | go | func Format(format string, values Attributes) string {
formatter, err := messageformat.New()
if err != nil {
return format
}
fm, err := formatter.Parse(format)
if err != nil {
return format
}
fixed := make(map[string]interface{}, len(values))
for k, v := range values {
fixed[k] = fix(v)
}
// todo for... | [
"func",
"Format",
"(",
"format",
"string",
",",
"values",
"Attributes",
")",
"string",
"{",
"formatter",
",",
"err",
":=",
"messageformat",
".",
"New",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"format",
"\n",
"}",
"\n",
"fm",
",",
"er... | // Format formats the values into the provided string | [
"Format",
"formats",
"the",
"values",
"into",
"the",
"provided",
"string"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/format.go#L14-L38 | test |
TheThingsNetwork/go-utils | errors/format.go | fix | func fix(v interface{}) interface{} {
if v == nil {
return "<nil>"
}
switch reflect.TypeOf(v).Kind() {
case reflect.Bool:
case reflect.Int:
case reflect.Int8:
case reflect.Int16:
case reflect.Int32:
case reflect.Int64:
case reflect.Uint:
case reflect.Uint8:
case reflect.Uint16:
case reflect.Uint32:
cas... | go | func fix(v interface{}) interface{} {
if v == nil {
return "<nil>"
}
switch reflect.TypeOf(v).Kind() {
case reflect.Bool:
case reflect.Int:
case reflect.Int8:
case reflect.Int16:
case reflect.Int32:
case reflect.Int64:
case reflect.Uint:
case reflect.Uint8:
case reflect.Uint16:
case reflect.Uint32:
cas... | [
"func",
"fix",
"(",
"v",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"if",
"v",
"==",
"nil",
"{",
"return",
"\"<nil>\"",
"\n",
"}",
"\n",
"switch",
"reflect",
".",
"TypeOf",
"(",
"v",
")",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect"... | // Fix coerces types that cannot be formatted by messageformat to string | [
"Fix",
"coerces",
"types",
"that",
"cannot",
"be",
"formatted",
"by",
"messageformat",
"to",
"string"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/format.go#L41-L67 | test |
TheThingsNetwork/go-utils | errors/grpc.go | GRPCCode | func (t Type) GRPCCode() codes.Code {
switch t {
case InvalidArgument:
return codes.InvalidArgument
case OutOfRange:
return codes.OutOfRange
case NotFound:
return codes.NotFound
case Conflict:
case AlreadyExists:
return codes.AlreadyExists
case Unauthorized:
return codes.Unauthenticated
case Permissio... | go | func (t Type) GRPCCode() codes.Code {
switch t {
case InvalidArgument:
return codes.InvalidArgument
case OutOfRange:
return codes.OutOfRange
case NotFound:
return codes.NotFound
case Conflict:
case AlreadyExists:
return codes.AlreadyExists
case Unauthorized:
return codes.Unauthenticated
case Permissio... | [
"func",
"(",
"t",
"Type",
")",
"GRPCCode",
"(",
")",
"codes",
".",
"Code",
"{",
"switch",
"t",
"{",
"case",
"InvalidArgument",
":",
"return",
"codes",
".",
"InvalidArgument",
"\n",
"case",
"OutOfRange",
":",
"return",
"codes",
".",
"OutOfRange",
"\n",
"c... | // GRPCCode returns the corresponding http status code from an error type | [
"GRPCCode",
"returns",
"the",
"corresponding",
"http",
"status",
"code",
"from",
"an",
"error",
"type"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/grpc.go#L15-L48 | test |
TheThingsNetwork/go-utils | errors/grpc.go | GRPCCodeToType | func GRPCCodeToType(code codes.Code) Type {
switch code {
case codes.InvalidArgument:
return InvalidArgument
case codes.OutOfRange:
return OutOfRange
case codes.NotFound:
return NotFound
case codes.AlreadyExists:
return AlreadyExists
case codes.Unauthenticated:
return Unauthorized
case codes.Permission... | go | func GRPCCodeToType(code codes.Code) Type {
switch code {
case codes.InvalidArgument:
return InvalidArgument
case codes.OutOfRange:
return OutOfRange
case codes.NotFound:
return NotFound
case codes.AlreadyExists:
return AlreadyExists
case codes.Unauthenticated:
return Unauthorized
case codes.Permission... | [
"func",
"GRPCCodeToType",
"(",
"code",
"codes",
".",
"Code",
")",
"Type",
"{",
"switch",
"code",
"{",
"case",
"codes",
".",
"InvalidArgument",
":",
"return",
"InvalidArgument",
"\n",
"case",
"codes",
".",
"OutOfRange",
":",
"return",
"OutOfRange",
"\n",
"cas... | // GRPCCodeToType converts the gRPC error code to an error type or returns the
// Unknown type if not possible. | [
"GRPCCodeToType",
"converts",
"the",
"gRPC",
"error",
"code",
"to",
"an",
"error",
"type",
"or",
"returns",
"the",
"Unknown",
"type",
"if",
"not",
"possible",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/grpc.go#L52-L82 | test |
TheThingsNetwork/go-utils | errors/grpc.go | GRPCCode | func GRPCCode(err error) codes.Code {
e, ok := err.(Error)
if ok {
return e.Type().GRPCCode()
}
return grpc.Code(err)
} | go | func GRPCCode(err error) codes.Code {
e, ok := err.(Error)
if ok {
return e.Type().GRPCCode()
}
return grpc.Code(err)
} | [
"func",
"GRPCCode",
"(",
"err",
"error",
")",
"codes",
".",
"Code",
"{",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"Error",
")",
"\n",
"if",
"ok",
"{",
"return",
"e",
".",
"Type",
"(",
")",
".",
"GRPCCode",
"(",
")",
"\n",
"}",
"\n",
"return",
"... | // GRPCCode returns the corresponding http status code from an error | [
"GRPCCode",
"returns",
"the",
"corresponding",
"http",
"status",
"code",
"from",
"an",
"error"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/grpc.go#L85-L92 | test |
TheThingsNetwork/go-utils | errors/grpc.go | FromGRPC | func FromGRPC(in error) Error {
out := &impl{
message: grpc.ErrorDesc(in),
typ: GRPCCodeToType(grpc.Code(in)),
code: NoCode,
}
matches := grpcMessageFormat.FindStringSubmatch(in.Error())
if len(matches) < 4 {
return out
}
out.message = matches[1]
out.code = parseCode(matches[2])
_ = json.Unmar... | go | func FromGRPC(in error) Error {
out := &impl{
message: grpc.ErrorDesc(in),
typ: GRPCCodeToType(grpc.Code(in)),
code: NoCode,
}
matches := grpcMessageFormat.FindStringSubmatch(in.Error())
if len(matches) < 4 {
return out
}
out.message = matches[1]
out.code = parseCode(matches[2])
_ = json.Unmar... | [
"func",
"FromGRPC",
"(",
"in",
"error",
")",
"Error",
"{",
"out",
":=",
"&",
"impl",
"{",
"message",
":",
"grpc",
".",
"ErrorDesc",
"(",
"in",
")",
",",
"typ",
":",
"GRPCCodeToType",
"(",
"grpc",
".",
"Code",
"(",
"in",
")",
")",
",",
"code",
":"... | // FromGRPC parses a gRPC error and returns an Error | [
"FromGRPC",
"parses",
"a",
"gRPC",
"error",
"and",
"returns",
"an",
"Error"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/grpc.go#L98-L121 | test |
TheThingsNetwork/go-utils | errors/grpc.go | ToGRPC | func ToGRPC(in error) error {
if err, ok := in.(Error); ok {
attrs, _ := json.Marshal(err.Attributes())
return grpc.Errorf(err.Type().GRPCCode(), format, err.Error(), err.Code(), attrs)
}
return grpc.Errorf(codes.Unknown, in.Error())
} | go | func ToGRPC(in error) error {
if err, ok := in.(Error); ok {
attrs, _ := json.Marshal(err.Attributes())
return grpc.Errorf(err.Type().GRPCCode(), format, err.Error(), err.Code(), attrs)
}
return grpc.Errorf(codes.Unknown, in.Error())
} | [
"func",
"ToGRPC",
"(",
"in",
"error",
")",
"error",
"{",
"if",
"err",
",",
"ok",
":=",
"in",
".",
"(",
"Error",
")",
";",
"ok",
"{",
"attrs",
",",
"_",
":=",
"json",
".",
"Marshal",
"(",
"err",
".",
"Attributes",
"(",
")",
")",
"\n",
"return",
... | // ToGRPC turns an error into a gRPC error | [
"ToGRPC",
"turns",
"an",
"error",
"into",
"a",
"gRPC",
"error"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/grpc.go#L124-L131 | test |
TheThingsNetwork/go-utils | log/namespaced/namespaces.go | IsEnabled | func (n *ns) IsEnabled(namespace string) bool {
n.RLock()
defer n.RUnlock()
if namespace == "" {
return true
}
hasStar := false
included := false
for _, ns := range n.namespaces {
// if the namspace is negated, it can never be enabled
if ns == negate(namespace) {
return false
}
// if the namespa... | go | func (n *ns) IsEnabled(namespace string) bool {
n.RLock()
defer n.RUnlock()
if namespace == "" {
return true
}
hasStar := false
included := false
for _, ns := range n.namespaces {
// if the namspace is negated, it can never be enabled
if ns == negate(namespace) {
return false
}
// if the namespa... | [
"func",
"(",
"n",
"*",
"ns",
")",
"IsEnabled",
"(",
"namespace",
"string",
")",
"bool",
"{",
"n",
".",
"RLock",
"(",
")",
"\n",
"defer",
"n",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"namespace",
"==",
"\"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",... | // isEnabled checks wether or not the namespace is enabled | [
"isEnabled",
"checks",
"wether",
"or",
"not",
"the",
"namespace",
"is",
"enabled"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/namespaced/namespaces.go#L16-L46 | test |
TheThingsNetwork/go-utils | log/namespaced/namespaces.go | Set | func (n *ns) Set(namespaces []string) {
n.Lock()
defer n.Unlock()
n.namespaces = namespaces
} | go | func (n *ns) Set(namespaces []string) {
n.Lock()
defer n.Unlock()
n.namespaces = namespaces
} | [
"func",
"(",
"n",
"*",
"ns",
")",
"Set",
"(",
"namespaces",
"[",
"]",
"string",
")",
"{",
"n",
".",
"Lock",
"(",
")",
"\n",
"defer",
"n",
".",
"Unlock",
"(",
")",
"\n",
"n",
".",
"namespaces",
"=",
"namespaces",
"\n",
"}"
] | // Set updates the namespaces | [
"Set",
"updates",
"the",
"namespaces"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/namespaced/namespaces.go#L49-L53 | test |
TheThingsNetwork/go-utils | errors/cause.go | Cause | func Cause(err Error) error {
attributes := err.Attributes()
if attributes == nil {
return nil
}
cause, ok := attributes[causeKey]
if !ok {
return nil
}
switch v := cause.(type) {
case error:
return v
case string:
return errors.New(v)
default:
return nil
}
} | go | func Cause(err Error) error {
attributes := err.Attributes()
if attributes == nil {
return nil
}
cause, ok := attributes[causeKey]
if !ok {
return nil
}
switch v := cause.(type) {
case error:
return v
case string:
return errors.New(v)
default:
return nil
}
} | [
"func",
"Cause",
"(",
"err",
"Error",
")",
"error",
"{",
"attributes",
":=",
"err",
".",
"Attributes",
"(",
")",
"\n",
"if",
"attributes",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cause",
",",
"ok",
":=",
"attributes",
"[",
"causeKey",
"]... | // Cause returns the cause of an error | [
"Cause",
"returns",
"the",
"cause",
"of",
"an",
"error"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/cause.go#L16-L35 | test |
TheThingsNetwork/go-utils | errors/code.go | parseCode | func parseCode(str string) Code {
code, err := strconv.Atoi(str)
if err != nil {
return Code(0)
}
return Code(code)
} | go | func parseCode(str string) Code {
code, err := strconv.Atoi(str)
if err != nil {
return Code(0)
}
return Code(code)
} | [
"func",
"parseCode",
"(",
"str",
"string",
")",
"Code",
"{",
"code",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Code",
"(",
"0",
")",
"\n",
"}",
"\n",
"return",
"Code",
"(",
"code",
... | // pareCode parses a string into a Code or returns 0 if the parse failed | [
"pareCode",
"parses",
"a",
"string",
"into",
"a",
"Code",
"or",
"returns",
"0",
"if",
"the",
"parse",
"failed"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/code.go#L23-L29 | test |
TheThingsNetwork/go-utils | grpc/rpcerror/grpc.go | UnaryServerInterceptor | func UnaryServerInterceptor(fn ConvertFunc) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
resp, err = handler(ctx, req)
return resp, fn(err)
}
} | go | func UnaryServerInterceptor(fn ConvertFunc) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
resp, err = handler(ctx, req)
return resp, fn(err)
}
} | [
"func",
"UnaryServerInterceptor",
"(",
"fn",
"ConvertFunc",
")",
"grpc",
".",
"UnaryServerInterceptor",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"interface",
"{",
"}",
",",
"info",
"*",
"grpc",
".",
"UnaryServerInfo",
",",
"h... | // UnaryServerInterceptor applies fn to errors returned by server. | [
"UnaryServerInterceptor",
"applies",
"fn",
"to",
"errors",
"returned",
"by",
"server",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/rpcerror/grpc.go#L15-L20 | test |
TheThingsNetwork/go-utils | grpc/rpcerror/grpc.go | StreamServerInterceptor | func StreamServerInterceptor(fn ConvertFunc) grpc.StreamServerInterceptor {
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
return fn(handler(srv, ss))
}
} | go | func StreamServerInterceptor(fn ConvertFunc) grpc.StreamServerInterceptor {
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error) {
return fn(handler(srv, ss))
}
} | [
"func",
"StreamServerInterceptor",
"(",
"fn",
"ConvertFunc",
")",
"grpc",
".",
"StreamServerInterceptor",
"{",
"return",
"func",
"(",
"srv",
"interface",
"{",
"}",
",",
"ss",
"grpc",
".",
"ServerStream",
",",
"info",
"*",
"grpc",
".",
"StreamServerInfo",
",",
... | // StreamServerInterceptor applies fn to errors returned by server. | [
"StreamServerInterceptor",
"applies",
"fn",
"to",
"errors",
"returned",
"by",
"server",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/rpcerror/grpc.go#L23-L27 | test |
TheThingsNetwork/go-utils | grpc/rpcerror/grpc.go | UnaryClientInterceptor | func UnaryClientInterceptor(fn ConvertFunc) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) (err error) {
return fn(invoker(ctx, method, req, reply, cc, opts...))
}
} | go | func UnaryClientInterceptor(fn ConvertFunc) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) (err error) {
return fn(invoker(ctx, method, req, reply, cc, opts...))
}
} | [
"func",
"UnaryClientInterceptor",
"(",
"fn",
"ConvertFunc",
")",
"grpc",
".",
"UnaryClientInterceptor",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"method",
"string",
",",
"req",
",",
"reply",
"interface",
"{",
"}",
",",
"cc",
"*",
... | // UnaryClientInterceptor applies fn to errors recieved by client. | [
"UnaryClientInterceptor",
"applies",
"fn",
"to",
"errors",
"recieved",
"by",
"client",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/rpcerror/grpc.go#L30-L34 | test |
TheThingsNetwork/go-utils | grpc/rpcerror/grpc.go | StreamClientInterceptor | func StreamClientInterceptor(fn ConvertFunc) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (stream grpc.ClientStream, err error) {
stream, err = streamer(ctx, desc, cc, method, opts...)
ret... | go | func StreamClientInterceptor(fn ConvertFunc) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (stream grpc.ClientStream, err error) {
stream, err = streamer(ctx, desc, cc, method, opts...)
ret... | [
"func",
"StreamClientInterceptor",
"(",
"fn",
"ConvertFunc",
")",
"grpc",
".",
"StreamClientInterceptor",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"desc",
"*",
"grpc",
".",
"StreamDesc",
",",
"cc",
"*",
"grpc",
".",
"ClientConn",
",... | // StreamClientInterceptor applies fn to errors recieved by client. | [
"StreamClientInterceptor",
"applies",
"fn",
"to",
"errors",
"recieved",
"by",
"client",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/rpcerror/grpc.go#L37-L42 | test |
TheThingsNetwork/go-utils | grpc/restartstream/restart.go | Interceptor | func Interceptor(settings Settings) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (stream grpc.ClientStream, err error) {
s := &restartingStream{
log: log.Get().WithField("method", method)... | go | func Interceptor(settings Settings) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (stream grpc.ClientStream, err error) {
s := &restartingStream{
log: log.Get().WithField("method", method)... | [
"func",
"Interceptor",
"(",
"settings",
"Settings",
")",
"grpc",
".",
"StreamClientInterceptor",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"desc",
"*",
"grpc",
".",
"StreamDesc",
",",
"cc",
"*",
"grpc",
".",
"ClientConn",
",",
"met... | // Interceptor automatically restarts streams on non-expected errors
// To do so, the application should create a for-loop around RecvMsg, which
// returns the same errors that are received from the server.
//
// An io.EOF indicates the end of the stream
//
// To stop the reconnect behaviour, you have to cancel the con... | [
"Interceptor",
"automatically",
"restarts",
"streams",
"on",
"non",
"-",
"expected",
"errors",
"To",
"do",
"so",
"the",
"application",
"should",
"create",
"a",
"for",
"-",
"loop",
"around",
"RecvMsg",
"which",
"returns",
"the",
"same",
"errors",
"that",
"are",... | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/restartstream/restart.go#L200-L222 | test |
TheThingsNetwork/go-utils | log/logrus/logrus.go | Wrap | func Wrap(logger *logrus.Logger) log.Interface {
return &logrusEntryWrapper{logrus.NewEntry(logger)}
} | go | func Wrap(logger *logrus.Logger) log.Interface {
return &logrusEntryWrapper{logrus.NewEntry(logger)}
} | [
"func",
"Wrap",
"(",
"logger",
"*",
"logrus",
".",
"Logger",
")",
"log",
".",
"Interface",
"{",
"return",
"&",
"logrusEntryWrapper",
"{",
"logrus",
".",
"NewEntry",
"(",
"logger",
")",
"}",
"\n",
"}"
] | // Wrap logrus.Logger | [
"Wrap",
"logrus",
".",
"Logger"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/logrus/logrus.go#L14-L16 | test |
TheThingsNetwork/go-utils | rate/rate.go | NewCounter | func NewCounter(bucketSize, retention time.Duration) Counter {
return &counter{
bucketSize: bucketSize,
retention: retention,
buckets: make([]uint64, 2*retention/bucketSize),
}
} | go | func NewCounter(bucketSize, retention time.Duration) Counter {
return &counter{
bucketSize: bucketSize,
retention: retention,
buckets: make([]uint64, 2*retention/bucketSize),
}
} | [
"func",
"NewCounter",
"(",
"bucketSize",
",",
"retention",
"time",
".",
"Duration",
")",
"Counter",
"{",
"return",
"&",
"counter",
"{",
"bucketSize",
":",
"bucketSize",
",",
"retention",
":",
"retention",
",",
"buckets",
":",
"make",
"(",
"[",
"]",
"uint64... | // NewCounter returns a new rate counter with the given bucket size and retention | [
"NewCounter",
"returns",
"a",
"new",
"rate",
"counter",
"with",
"the",
"given",
"bucket",
"size",
"and",
"retention"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/rate/rate.go#L27-L33 | test |
TheThingsNetwork/go-utils | rate/rate.go | NewRedisCounter | func NewRedisCounter(client *redis.Client, key string, bucketSize, retention time.Duration) Counter {
return &redisCounter{
client: client,
key: key,
bucketSize: bucketSize,
retention: retention,
}
} | go | func NewRedisCounter(client *redis.Client, key string, bucketSize, retention time.Duration) Counter {
return &redisCounter{
client: client,
key: key,
bucketSize: bucketSize,
retention: retention,
}
} | [
"func",
"NewRedisCounter",
"(",
"client",
"*",
"redis",
".",
"Client",
",",
"key",
"string",
",",
"bucketSize",
",",
"retention",
"time",
".",
"Duration",
")",
"Counter",
"{",
"return",
"&",
"redisCounter",
"{",
"client",
":",
"client",
",",
"key",
":",
... | // NewRedisCounter returns a new redis-based counter | [
"NewRedisCounter",
"returns",
"a",
"new",
"redis",
"-",
"based",
"counter"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/rate/rate.go#L97-L104 | test |
TheThingsNetwork/go-utils | rate/rate.go | NewLimiter | func NewLimiter(counter Counter, duration time.Duration, limit uint64) Limiter {
return &limiter{
Counter: counter,
duration: duration,
limit: limit,
}
} | go | func NewLimiter(counter Counter, duration time.Duration, limit uint64) Limiter {
return &limiter{
Counter: counter,
duration: duration,
limit: limit,
}
} | [
"func",
"NewLimiter",
"(",
"counter",
"Counter",
",",
"duration",
"time",
".",
"Duration",
",",
"limit",
"uint64",
")",
"Limiter",
"{",
"return",
"&",
"limiter",
"{",
"Counter",
":",
"counter",
",",
"duration",
":",
"duration",
",",
"limit",
":",
"limit",
... | // NewLimiter returns a new limiter | [
"NewLimiter",
"returns",
"a",
"new",
"limiter"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/rate/rate.go#L166-L172 | test |
TheThingsNetwork/go-utils | grpc/auth/auth.go | WithInsecure | func (c *TokenCredentials) WithInsecure() *TokenCredentials {
return &TokenCredentials{token: c.token, tokenFunc: c.tokenFunc, allowInsecure: true}
} | go | func (c *TokenCredentials) WithInsecure() *TokenCredentials {
return &TokenCredentials{token: c.token, tokenFunc: c.tokenFunc, allowInsecure: true}
} | [
"func",
"(",
"c",
"*",
"TokenCredentials",
")",
"WithInsecure",
"(",
")",
"*",
"TokenCredentials",
"{",
"return",
"&",
"TokenCredentials",
"{",
"token",
":",
"c",
".",
"token",
",",
"tokenFunc",
":",
"c",
".",
"tokenFunc",
",",
"allowInsecure",
":",
"true"... | // WithInsecure returns a copy of the TokenCredentials, allowing insecure transport | [
"WithInsecure",
"returns",
"a",
"copy",
"of",
"the",
"TokenCredentials",
"allowing",
"insecure",
"transport"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/auth/auth.go#L23-L25 | test |
TheThingsNetwork/go-utils | grpc/auth/auth.go | WithTokenFunc | func WithTokenFunc(k string, tokenFunc func(v string) string) *TokenCredentials {
return &TokenCredentials{
tokenFunc: tokenFunc,
tokenFuncKey: k,
}
} | go | func WithTokenFunc(k string, tokenFunc func(v string) string) *TokenCredentials {
return &TokenCredentials{
tokenFunc: tokenFunc,
tokenFuncKey: k,
}
} | [
"func",
"WithTokenFunc",
"(",
"k",
"string",
",",
"tokenFunc",
"func",
"(",
"v",
"string",
")",
"string",
")",
"*",
"TokenCredentials",
"{",
"return",
"&",
"TokenCredentials",
"{",
"tokenFunc",
":",
"tokenFunc",
",",
"tokenFuncKey",
":",
"k",
",",
"}",
"\n... | // WithTokenFunc returns TokenCredentials that execute the tokenFunc on each request
// The value of v sent to the tokenFunk is the MD value of the supplied k | [
"WithTokenFunc",
"returns",
"TokenCredentials",
"that",
"execute",
"the",
"tokenFunc",
"on",
"each",
"request",
"The",
"value",
"of",
"v",
"sent",
"to",
"the",
"tokenFunk",
"is",
"the",
"MD",
"value",
"of",
"the",
"supplied",
"k"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/auth/auth.go#L36-L41 | test |
TheThingsNetwork/go-utils | grpc/auth/auth.go | GetRequestMetadata | func (c *TokenCredentials) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
md := ttnctx.MetadataFromOutgoingContext(ctx)
token, _ := ttnctx.TokenFromMetadata(md)
if token != "" {
return map[string]string{tokenKey: token}, nil
}
if c.tokenFunc != nil {
var k string
if v, ok... | go | func (c *TokenCredentials) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
md := ttnctx.MetadataFromOutgoingContext(ctx)
token, _ := ttnctx.TokenFromMetadata(md)
if token != "" {
return map[string]string{tokenKey: token}, nil
}
if c.tokenFunc != nil {
var k string
if v, ok... | [
"func",
"(",
"c",
"*",
"TokenCredentials",
")",
"GetRequestMetadata",
"(",
"ctx",
"context",
".",
"Context",
",",
"uri",
"...",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"md",
":=",
"ttnctx",
".",
"MetadataFromOutgo... | // GetRequestMetadata implements credentials.PerRPCCredentials | [
"GetRequestMetadata",
"implements",
"credentials",
".",
"PerRPCCredentials"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/auth/auth.go#L47-L64 | test |
TheThingsNetwork/go-utils | grpc/rpclog/fields.go | FieldsFromIncomingContext | func FieldsFromIncomingContext(ctx context.Context) ttnlog.Fields {
fields := make(fieldMap)
if peer, ok := peer.FromContext(ctx); ok {
fields.addFromPeer(peer)
}
if md, ok := metadata.FromIncomingContext(ctx); ok {
fields.addFromMD(md)
}
return fields.LogFields()
} | go | func FieldsFromIncomingContext(ctx context.Context) ttnlog.Fields {
fields := make(fieldMap)
if peer, ok := peer.FromContext(ctx); ok {
fields.addFromPeer(peer)
}
if md, ok := metadata.FromIncomingContext(ctx); ok {
fields.addFromMD(md)
}
return fields.LogFields()
} | [
"func",
"FieldsFromIncomingContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"ttnlog",
".",
"Fields",
"{",
"fields",
":=",
"make",
"(",
"fieldMap",
")",
"\n",
"if",
"peer",
",",
"ok",
":=",
"peer",
".",
"FromContext",
"(",
"ctx",
")",
";",
"ok",
"{... | // FieldsFromIncomingContext returns peer information and MDLogFields from the given context | [
"FieldsFromIncomingContext",
"returns",
"peer",
"information",
"and",
"MDLogFields",
"from",
"the",
"given",
"context"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/rpclog/fields.go#L68-L77 | test |
TheThingsNetwork/go-utils | errors/type.go | String | func (t Type) String() string {
switch t {
case Unknown:
return "Unknown"
case Internal:
return "Internal"
case InvalidArgument:
return "Invalid argument"
case OutOfRange:
return "Out of range"
case NotFound:
return "Not found"
case Conflict:
return "Conflict"
case AlreadyExists:
return "Already e... | go | func (t Type) String() string {
switch t {
case Unknown:
return "Unknown"
case Internal:
return "Internal"
case InvalidArgument:
return "Invalid argument"
case OutOfRange:
return "Out of range"
case NotFound:
return "Not found"
case Conflict:
return "Conflict"
case AlreadyExists:
return "Already e... | [
"func",
"(",
"t",
"Type",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"t",
"{",
"case",
"Unknown",
":",
"return",
"\"Unknown\"",
"\n",
"case",
"Internal",
":",
"return",
"\"Internal\"",
"\n",
"case",
"InvalidArgument",
":",
"return",
"\"Invalid argumen... | // String implements stringer | [
"String",
"implements",
"stringer"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/type.go#L73-L108 | test |
TheThingsNetwork/go-utils | errors/type.go | UnmarshalText | func (t *Type) UnmarshalText(text []byte) error {
e, err := fromString(string(text))
if err != nil {
return err
}
*t = e
return nil
} | go | func (t *Type) UnmarshalText(text []byte) error {
e, err := fromString(string(text))
if err != nil {
return err
}
*t = e
return nil
} | [
"func",
"(",
"t",
"*",
"Type",
")",
"UnmarshalText",
"(",
"text",
"[",
"]",
"byte",
")",
"error",
"{",
"e",
",",
"err",
":=",
"fromString",
"(",
"string",
"(",
"text",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"... | // UnmarshalText implements TextUnmarsheler | [
"UnmarshalText",
"implements",
"TextUnmarsheler"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/type.go#L116-L125 | test |
TheThingsNetwork/go-utils | errors/type.go | fromString | func fromString(str string) (Type, error) {
enum := strings.ToLower(str)
switch enum {
case "unknown":
return Unknown, nil
case "internal":
return Internal, nil
case "invalid argument":
return InvalidArgument, nil
case "out of range":
return OutOfRange, nil
case "not found":
return NotFound, nil
case ... | go | func fromString(str string) (Type, error) {
enum := strings.ToLower(str)
switch enum {
case "unknown":
return Unknown, nil
case "internal":
return Internal, nil
case "invalid argument":
return InvalidArgument, nil
case "out of range":
return OutOfRange, nil
case "not found":
return NotFound, nil
case ... | [
"func",
"fromString",
"(",
"str",
"string",
")",
"(",
"Type",
",",
"error",
")",
"{",
"enum",
":=",
"strings",
".",
"ToLower",
"(",
"str",
")",
"\n",
"switch",
"enum",
"{",
"case",
"\"unknown\"",
":",
"return",
"Unknown",
",",
"nil",
"\n",
"case",
"\... | // fromString parses a string into an error type. If the type is invalid, the
// Unknown type will be returned as well as an error. | [
"fromString",
"parses",
"a",
"string",
"into",
"an",
"error",
"type",
".",
"If",
"the",
"type",
"is",
"invalid",
"the",
"Unknown",
"type",
"will",
"be",
"returned",
"as",
"well",
"as",
"an",
"error",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/errors/type.go#L129-L165 | test |
TheThingsNetwork/go-utils | stats/stats.go | Start | func Start(ctx log.Interface, interval time.Duration) {
ctx.WithField("interval", interval).Debug("starting stats loop")
go func() {
memstats := new(runtime.MemStats)
for range time.Tick(interval) {
runtime.ReadMemStats(memstats)
ctx.WithFields(log.Fields{
"goroutines": runtime.NumGoroutine(),
"memo... | go | func Start(ctx log.Interface, interval time.Duration) {
ctx.WithField("interval", interval).Debug("starting stats loop")
go func() {
memstats := new(runtime.MemStats)
for range time.Tick(interval) {
runtime.ReadMemStats(memstats)
ctx.WithFields(log.Fields{
"goroutines": runtime.NumGoroutine(),
"memo... | [
"func",
"Start",
"(",
"ctx",
"log",
".",
"Interface",
",",
"interval",
"time",
".",
"Duration",
")",
"{",
"ctx",
".",
"WithField",
"(",
"\"interval\"",
",",
"interval",
")",
".",
"Debug",
"(",
"\"starting stats loop\"",
")",
"\n",
"go",
"func",
"(",
")",... | // Start starts the stat process that will log relevant memory-related stats
// to ctx, at an interval determined by interval. | [
"Start",
"starts",
"the",
"stat",
"process",
"that",
"will",
"log",
"relevant",
"memory",
"-",
"related",
"stats",
"to",
"ctx",
"at",
"an",
"interval",
"determined",
"by",
"interval",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/stats/stats.go#L17-L29 | test |
TheThingsNetwork/go-utils | queue/simple.go | NewSimple | func NewSimple() Simple {
q := &simpleQueue{
queue: make([]interface{}, 0),
}
q.available = sync.NewCond(&q.mu)
return q
} | go | func NewSimple() Simple {
q := &simpleQueue{
queue: make([]interface{}, 0),
}
q.available = sync.NewCond(&q.mu)
return q
} | [
"func",
"NewSimple",
"(",
")",
"Simple",
"{",
"q",
":=",
"&",
"simpleQueue",
"{",
"queue",
":",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
",",
"}",
"\n",
"q",
".",
"available",
"=",
"sync",
".",
"NewCond",
"(",
"&",
"q",
".",... | // NewSimple returns a new Simple Queue | [
"NewSimple",
"returns",
"a",
"new",
"Simple",
"Queue"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/queue/simple.go#L23-L29 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | Wrap | func Wrap(logger log.Interface, filters ...Filter) *Filtered {
return &Filtered{
Interface: logger,
filters: filters,
}
} | go | func Wrap(logger log.Interface, filters ...Filter) *Filtered {
return &Filtered{
Interface: logger,
filters: filters,
}
} | [
"func",
"Wrap",
"(",
"logger",
"log",
".",
"Interface",
",",
"filters",
"...",
"Filter",
")",
"*",
"Filtered",
"{",
"return",
"&",
"Filtered",
"{",
"Interface",
":",
"logger",
",",
"filters",
":",
"filters",
",",
"}",
"\n",
"}"
] | // Wrap wraps an existing logger, filtering the fields as it goes along
// using the provided filters | [
"Wrap",
"wraps",
"an",
"existing",
"logger",
"filtering",
"the",
"fields",
"as",
"it",
"goes",
"along",
"using",
"the",
"provided",
"filters"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L31-L36 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | WithFilters | func (f *Filtered) WithFilters(filters ...Filter) *Filtered {
return &Filtered{
Interface: f.Interface,
filters: append(f.filters, filters...),
}
} | go | func (f *Filtered) WithFilters(filters ...Filter) *Filtered {
return &Filtered{
Interface: f.Interface,
filters: append(f.filters, filters...),
}
} | [
"func",
"(",
"f",
"*",
"Filtered",
")",
"WithFilters",
"(",
"filters",
"...",
"Filter",
")",
"*",
"Filtered",
"{",
"return",
"&",
"Filtered",
"{",
"Interface",
":",
"f",
".",
"Interface",
",",
"filters",
":",
"append",
"(",
"f",
".",
"filters",
",",
... | // WithFilter creates a new Filtered that will use the extra filters | [
"WithFilter",
"creates",
"a",
"new",
"Filtered",
"that",
"will",
"use",
"the",
"extra",
"filters"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L39-L44 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | WithField | func (f *Filtered) WithField(k string, v interface{}) log.Interface {
val := v
// apply the filters
for _, filter := range f.filters {
val = filter.Filter(k, val)
}
return &Filtered{
Interface: f.Interface.WithField(k, val),
filters: f.filters,
}
} | go | func (f *Filtered) WithField(k string, v interface{}) log.Interface {
val := v
// apply the filters
for _, filter := range f.filters {
val = filter.Filter(k, val)
}
return &Filtered{
Interface: f.Interface.WithField(k, val),
filters: f.filters,
}
} | [
"func",
"(",
"f",
"*",
"Filtered",
")",
"WithField",
"(",
"k",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"log",
".",
"Interface",
"{",
"val",
":=",
"v",
"\n",
"for",
"_",
",",
"filter",
":=",
"range",
"f",
".",
"filters",
"{",
"val",
"=",
... | // WithField filters the field and passes it on to the wrapped loggers WithField | [
"WithField",
"filters",
"the",
"field",
"and",
"passes",
"it",
"on",
"to",
"the",
"wrapped",
"loggers",
"WithField"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L47-L59 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | WithFields | func (f *Filtered) WithFields(fields log.Fields) log.Interface {
res := make(map[string]interface{}, len(fields))
for k, v := range fields {
val := v
// apply the filters
for _, filter := range f.filters {
val = filter.Filter(k, val)
}
res[k] = val
}
return &Filtered{
Interface: f.Interface.WithF... | go | func (f *Filtered) WithFields(fields log.Fields) log.Interface {
res := make(map[string]interface{}, len(fields))
for k, v := range fields {
val := v
// apply the filters
for _, filter := range f.filters {
val = filter.Filter(k, val)
}
res[k] = val
}
return &Filtered{
Interface: f.Interface.WithF... | [
"func",
"(",
"f",
"*",
"Filtered",
")",
"WithFields",
"(",
"fields",
"log",
".",
"Fields",
")",
"log",
".",
"Interface",
"{",
"res",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"fields",
")",
")",
"\n",
"... | // WithFields filters the fields and passes them on to the wrapped loggers WithFields | [
"WithFields",
"filters",
"the",
"fields",
"and",
"passes",
"them",
"on",
"to",
"the",
"wrapped",
"loggers",
"WithFields"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L62-L80 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | FilterSensitive | func FilterSensitive(sensitive []string, elided interface{}) Filter {
return FilterFunc(func(key string, v interface{}) interface{} {
lower := strings.ToLower(key)
for _, s := range sensitive {
if lower == s {
return elided
}
}
return v
})
} | go | func FilterSensitive(sensitive []string, elided interface{}) Filter {
return FilterFunc(func(key string, v interface{}) interface{} {
lower := strings.ToLower(key)
for _, s := range sensitive {
if lower == s {
return elided
}
}
return v
})
} | [
"func",
"FilterSensitive",
"(",
"sensitive",
"[",
"]",
"string",
",",
"elided",
"interface",
"{",
"}",
")",
"Filter",
"{",
"return",
"FilterFunc",
"(",
"func",
"(",
"key",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"low... | // FilterSensitive creates a Filter that filters most sensitive data like passwords,
// keys, access_tokens, etc. and replaces them with the elided value | [
"FilterSensitive",
"creates",
"a",
"Filter",
"that",
"filters",
"most",
"sensitive",
"data",
"like",
"passwords",
"keys",
"access_tokens",
"etc",
".",
"and",
"replaces",
"them",
"with",
"the",
"elided",
"value"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L105-L116 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | SliceFilter | func SliceFilter(filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
r := reflect.ValueOf(v)
if r.Kind() == reflect.Slice {
res := make([]interface{}, 0, r.Len())
for i := 0; i < r.Len(); i++ {
el := r.Index(i).Interface()
res = append(res, filter.Filter(k, el))
}... | go | func SliceFilter(filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
r := reflect.ValueOf(v)
if r.Kind() == reflect.Slice {
res := make([]interface{}, 0, r.Len())
for i := 0; i < r.Len(); i++ {
el := r.Index(i).Interface()
res = append(res, filter.Filter(k, el))
}... | [
"func",
"SliceFilter",
"(",
"filter",
"Filter",
")",
"Filter",
"{",
"return",
"FilterFunc",
"(",
"func",
"(",
"k",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"r",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
... | // SliceFilter lifts the filter to also work on slices. It loses the
// type information of the slice elements | [
"SliceFilter",
"lifts",
"the",
"filter",
"to",
"also",
"work",
"on",
"slices",
".",
"It",
"loses",
"the",
"type",
"information",
"of",
"the",
"slice",
"elements"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L120-L135 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | MapFilter | func MapFilter(filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
r := reflect.ValueOf(v)
if r.Kind() == reflect.Map {
// res will be the filtered map
res := make(map[string]interface{}, r.Len())
for _, key := range r.MapKeys() {
str := key.String()
val := r.MapI... | go | func MapFilter(filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
r := reflect.ValueOf(v)
if r.Kind() == reflect.Map {
// res will be the filtered map
res := make(map[string]interface{}, r.Len())
for _, key := range r.MapKeys() {
str := key.String()
val := r.MapI... | [
"func",
"MapFilter",
"(",
"filter",
"Filter",
")",
"Filter",
"{",
"return",
"FilterFunc",
"(",
"func",
"(",
"k",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"r",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
... | // MapFilter lifts the filter to also work on maps. It loses the type
// information of the map fields | [
"MapFilter",
"lifts",
"the",
"filter",
"to",
"also",
"work",
"on",
"maps",
".",
"It",
"loses",
"the",
"type",
"information",
"of",
"the",
"map",
"fields"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L139-L156 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | RestrictFilter | func RestrictFilter(fieldName string, filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
if fieldName == k {
return filter.Filter(k, v)
}
return v
})
} | go | func RestrictFilter(fieldName string, filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
if fieldName == k {
return filter.Filter(k, v)
}
return v
})
} | [
"func",
"RestrictFilter",
"(",
"fieldName",
"string",
",",
"filter",
"Filter",
")",
"Filter",
"{",
"return",
"FilterFunc",
"(",
"func",
"(",
"k",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"if",
"fieldName",
"==",
"k",
... | // RestrictFilter restricts the filter to only work on a certain field | [
"RestrictFilter",
"restricts",
"the",
"filter",
"to",
"only",
"work",
"on",
"a",
"certain",
"field"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L159-L167 | test |
TheThingsNetwork/go-utils | log/filtered/filtered.go | LowerCaseFilter | func LowerCaseFilter(filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
return filter.Filter(strings.ToLower(k), v)
})
} | go | func LowerCaseFilter(filter Filter) Filter {
return FilterFunc(func(k string, v interface{}) interface{} {
return filter.Filter(strings.ToLower(k), v)
})
} | [
"func",
"LowerCaseFilter",
"(",
"filter",
"Filter",
")",
"Filter",
"{",
"return",
"FilterFunc",
"(",
"func",
"(",
"k",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"return",
"filter",
".",
"Filter",
"(",
"strings",
".",
"... | // LowerCaseFilter creates a filter that only get passed lowercase field names | [
"LowerCaseFilter",
"creates",
"a",
"filter",
"that",
"only",
"get",
"passed",
"lowercase",
"field",
"names"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/filtered/filtered.go#L170-L174 | test |
TheThingsNetwork/go-utils | influx/writer.go | newBatchPoints | func newBatchPoints(bpConf influxdb.BatchPointsConfig) influxdb.BatchPoints {
bp, err := influxdb.NewBatchPoints(bpConf)
if err != nil {
// Can only happen if there's an error in the code
panic(fmt.Errorf("Invalid batch point configuration: %s", err))
}
return bp
} | go | func newBatchPoints(bpConf influxdb.BatchPointsConfig) influxdb.BatchPoints {
bp, err := influxdb.NewBatchPoints(bpConf)
if err != nil {
// Can only happen if there's an error in the code
panic(fmt.Errorf("Invalid batch point configuration: %s", err))
}
return bp
} | [
"func",
"newBatchPoints",
"(",
"bpConf",
"influxdb",
".",
"BatchPointsConfig",
")",
"influxdb",
".",
"BatchPoints",
"{",
"bp",
",",
"err",
":=",
"influxdb",
".",
"NewBatchPoints",
"(",
"bpConf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt"... | // newBatchPoints creates new influxdb.BatchPoints with specified bpConf.
// Panics on errors. | [
"newBatchPoints",
"creates",
"new",
"influxdb",
".",
"BatchPoints",
"with",
"specified",
"bpConf",
".",
"Panics",
"on",
"errors",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/influx/writer.go#L24-L31 | test |
TheThingsNetwork/go-utils | influx/writer.go | NewSinglePointWriter | func NewSinglePointWriter(log ttnlog.Interface, w BatchPointsWriter) *SinglePointWriter {
return &SinglePointWriter{
log: log,
writer: w,
}
} | go | func NewSinglePointWriter(log ttnlog.Interface, w BatchPointsWriter) *SinglePointWriter {
return &SinglePointWriter{
log: log,
writer: w,
}
} | [
"func",
"NewSinglePointWriter",
"(",
"log",
"ttnlog",
".",
"Interface",
",",
"w",
"BatchPointsWriter",
")",
"*",
"SinglePointWriter",
"{",
"return",
"&",
"SinglePointWriter",
"{",
"log",
":",
"log",
",",
"writer",
":",
"w",
",",
"}",
"\n",
"}"
] | // NewSinglePointWriter creates new SinglePointWriter | [
"NewSinglePointWriter",
"creates",
"new",
"SinglePointWriter"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/influx/writer.go#L50-L55 | test |
TheThingsNetwork/go-utils | influx/writer.go | Write | func (w *SinglePointWriter) Write(bpConf influxdb.BatchPointsConfig, p *influxdb.Point) error {
bp := newBatchPoints(bpConf)
bp.AddPoint(p)
return w.writer.Write(bp)
} | go | func (w *SinglePointWriter) Write(bpConf influxdb.BatchPointsConfig, p *influxdb.Point) error {
bp := newBatchPoints(bpConf)
bp.AddPoint(p)
return w.writer.Write(bp)
} | [
"func",
"(",
"w",
"*",
"SinglePointWriter",
")",
"Write",
"(",
"bpConf",
"influxdb",
".",
"BatchPointsConfig",
",",
"p",
"*",
"influxdb",
".",
"Point",
")",
"error",
"{",
"bp",
":=",
"newBatchPoints",
"(",
"bpConf",
")",
"\n",
"bp",
".",
"AddPoint",
"(",... | // Write creates new influxdb.BatchPoints containing p and delegates that to the writer | [
"Write",
"creates",
"new",
"influxdb",
".",
"BatchPoints",
"containing",
"p",
"and",
"delegates",
"that",
"to",
"the",
"writer"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/influx/writer.go#L58-L62 | test |
TheThingsNetwork/go-utils | influx/writer.go | WithScalingInterval | func WithScalingInterval(v time.Duration) BatchingWriterOption {
return func(w *BatchingWriter) {
w.scalingInterval = v
}
} | go | func WithScalingInterval(v time.Duration) BatchingWriterOption {
return func(w *BatchingWriter) {
w.scalingInterval = v
}
} | [
"func",
"WithScalingInterval",
"(",
"v",
"time",
".",
"Duration",
")",
"BatchingWriterOption",
"{",
"return",
"func",
"(",
"w",
"*",
"BatchingWriter",
")",
"{",
"w",
".",
"scalingInterval",
"=",
"v",
"\n",
"}",
"\n",
"}"
] | // WithInstanceLimit sets a limit on amount of additional instances spawned by BatchingWriter | [
"WithInstanceLimit",
"sets",
"a",
"limit",
"on",
"amount",
"of",
"additional",
"instances",
"spawned",
"by",
"BatchingWriter"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/influx/writer.go#L148-L152 | test |
TheThingsNetwork/go-utils | influx/writer.go | NewBatchingWriter | func NewBatchingWriter(log ttnlog.Interface, w BatchPointsWriter, opts ...BatchingWriterOption) *BatchingWriter {
bw := &BatchingWriter{
log: log,
writer: w,
scalingInterval: DefaultScalingInterval,
limit: DefaultInstanceLimit,
pointChans: make(map[influxdb.BatchPointsConf... | go | func NewBatchingWriter(log ttnlog.Interface, w BatchPointsWriter, opts ...BatchingWriterOption) *BatchingWriter {
bw := &BatchingWriter{
log: log,
writer: w,
scalingInterval: DefaultScalingInterval,
limit: DefaultInstanceLimit,
pointChans: make(map[influxdb.BatchPointsConf... | [
"func",
"NewBatchingWriter",
"(",
"log",
"ttnlog",
".",
"Interface",
",",
"w",
"BatchPointsWriter",
",",
"opts",
"...",
"BatchingWriterOption",
")",
"*",
"BatchingWriter",
"{",
"bw",
":=",
"&",
"BatchingWriter",
"{",
"log",
":",
"log",
",",
"writer",
":",
"w... | // NewBatchingWriter creates new BatchingWriter. If WithScalingInterval is not specified, DefaultScalingInterval value is used. If WithInstanceLimit is not specified, DefaultInstanceLimit is used. | [
"NewBatchingWriter",
"creates",
"new",
"BatchingWriter",
".",
"If",
"WithScalingInterval",
"is",
"not",
"specified",
"DefaultScalingInterval",
"value",
"is",
"used",
".",
"If",
"WithInstanceLimit",
"is",
"not",
"specified",
"DefaultInstanceLimit",
"is",
"used",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/influx/writer.go#L155-L171 | test |
TheThingsNetwork/go-utils | influx/writer.go | Write | func (w *BatchingWriter) Write(bpConf influxdb.BatchPointsConfig, p *influxdb.Point) error {
log := w.log.WithField("config", bpConf)
w.pointChanMutex.RLock()
ch, ok := w.pointChans[bpConf]
w.pointChanMutex.RUnlock()
if !ok {
w.pointChanMutex.Lock()
ch, ok = w.pointChans[bpConf]
if !ok {
w.mutex.Lock()
... | go | func (w *BatchingWriter) Write(bpConf influxdb.BatchPointsConfig, p *influxdb.Point) error {
log := w.log.WithField("config", bpConf)
w.pointChanMutex.RLock()
ch, ok := w.pointChans[bpConf]
w.pointChanMutex.RUnlock()
if !ok {
w.pointChanMutex.Lock()
ch, ok = w.pointChans[bpConf]
if !ok {
w.mutex.Lock()
... | [
"func",
"(",
"w",
"*",
"BatchingWriter",
")",
"Write",
"(",
"bpConf",
"influxdb",
".",
"BatchPointsConfig",
",",
"p",
"*",
"influxdb",
".",
"Point",
")",
"error",
"{",
"log",
":=",
"w",
".",
"log",
".",
"WithField",
"(",
"\"config\"",
",",
"bpConf",
")... | // Write delegates p to a running instance of BatchingWriter and spawns new instances as required. | [
"Write",
"delegates",
"p",
"to",
"a",
"running",
"instance",
"of",
"BatchingWriter",
"and",
"spawns",
"new",
"instances",
"as",
"required",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/influx/writer.go#L174-L212 | test |
TheThingsNetwork/go-utils | log/apex/apex.go | MustParseLevel | func (w *apexInterfaceWrapper) MustParseLevel(s string) {
level, err := ParseLevel(s)
if err != nil {
w.WithError(err).WithField("level", s).Fatal("Could not parse log level")
}
w.Level = level
} | go | func (w *apexInterfaceWrapper) MustParseLevel(s string) {
level, err := ParseLevel(s)
if err != nil {
w.WithError(err).WithField("level", s).Fatal("Could not parse log level")
}
w.Level = level
} | [
"func",
"(",
"w",
"*",
"apexInterfaceWrapper",
")",
"MustParseLevel",
"(",
"s",
"string",
")",
"{",
"level",
",",
"err",
":=",
"ParseLevel",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"WithError",
"(",
"err",
")",
".",
"WithField",... | // MustParseLevel is a convience function that parses the passed in string
// as a log level and sets the log level of the apexInterfaceWrapper to the
// parsed level. If an error occurs it will handle it with w.Fatal | [
"MustParseLevel",
"is",
"a",
"convience",
"function",
"that",
"parses",
"the",
"passed",
"in",
"string",
"as",
"a",
"log",
"level",
"and",
"sets",
"the",
"log",
"level",
"of",
"the",
"apexInterfaceWrapper",
"to",
"the",
"parsed",
"level",
".",
"If",
"an",
... | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/log/apex/apex.go#L56-L62 | test |
TheThingsNetwork/go-utils | grpc/streambuffer/streambuffer.go | New | func New(bufferSize int, setup func() (grpc.ClientStream, error)) *Stream {
return &Stream{
setupFunc: setup,
sendBuffer: make(chan interface{}, bufferSize),
log: ttnlog.Get(),
}
} | go | func New(bufferSize int, setup func() (grpc.ClientStream, error)) *Stream {
return &Stream{
setupFunc: setup,
sendBuffer: make(chan interface{}, bufferSize),
log: ttnlog.Get(),
}
} | [
"func",
"New",
"(",
"bufferSize",
"int",
",",
"setup",
"func",
"(",
")",
"(",
"grpc",
".",
"ClientStream",
",",
"error",
")",
")",
"*",
"Stream",
"{",
"return",
"&",
"Stream",
"{",
"setupFunc",
":",
"setup",
",",
"sendBuffer",
":",
"make",
"(",
"chan... | // New returns a new Stream with the given buffer size and setup function. | [
"New",
"returns",
"a",
"new",
"Stream",
"with",
"the",
"given",
"buffer",
"size",
"and",
"setup",
"function",
"."
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/streambuffer/streambuffer.go#L19-L25 | test |
TheThingsNetwork/go-utils | grpc/streambuffer/streambuffer.go | SetLogger | func (s *Stream) SetLogger(log ttnlog.Interface) {
s.mu.Lock()
s.log = log
s.mu.Unlock()
} | go | func (s *Stream) SetLogger(log ttnlog.Interface) {
s.mu.Lock()
s.log = log
s.mu.Unlock()
} | [
"func",
"(",
"s",
"*",
"Stream",
")",
"SetLogger",
"(",
"log",
"ttnlog",
".",
"Interface",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"log",
"=",
"log",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetLogger sets the logger for this streambuffer | [
"SetLogger",
"sets",
"the",
"logger",
"for",
"this",
"streambuffer"
] | aa2a11bd59104d2a8609328c2b2b55da61826470 | https://github.com/TheThingsNetwork/go-utils/blob/aa2a11bd59104d2a8609328c2b2b55da61826470/grpc/streambuffer/streambuffer.go#L54-L58 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.