id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
151,300 | ahmetb/go-linq | except.go | Except | func (q Query) Except(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
set := make(map[interface{}]bool)
for i, ok := next2(); ok; i, ok = next2() {
set[i] = true
}
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
return
}
}
return
}
},
}
} | go | func (q Query) Except(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
set := make(map[interface{}]bool)
for i, ok := next2(); ok; i, ok = next2() {
set[i] = true
}
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
return
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Except",
"(",
"q2",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"next2",
":=",
"q2",
".",
"Iterate",
... | // Except produces the set difference of two sequences. The set difference is
// the members of the first sequence that don't appear in the second sequence. | [
"Except",
"produces",
"the",
"set",
"difference",
"of",
"two",
"sequences",
".",
"The",
"set",
"difference",
"is",
"the",
"members",
"of",
"the",
"first",
"sequence",
"that",
"don",
"t",
"appear",
"in",
"the",
"second",
"sequence",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/except.go#L5-L27 |
151,301 | ahmetb/go-linq | selectmany.go | SelectMany | func (q Query) SelectMany(selector func(interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = outernext()
if !ok {
return
}
innernext = selector(inner).Iterate()
}
item, ok = innernext()
if !ok {
inner = nil
}
}
return
}
},
}
} | go | func (q Query) SelectMany(selector func(interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = outernext()
if !ok {
return
}
innernext = selector(inner).Iterate()
}
item, ok = innernext()
if !ok {
inner = nil
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"SelectMany",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"outernext",
":=",
"q",
".",
"Iterate",
"("... | // SelectMany projects each element of a collection to a Query, iterates and
// flattens the resulting collection into one collection. | [
"SelectMany",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L5-L33 |
151,302 | ahmetb/go-linq | selectmany.go | SelectManyIndexed | func (q Query) SelectManyIndexed(selector func(int, interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = outernext()
if !ok {
return
}
innernext = selector(index, inner).Iterate()
index++
}
item, ok = innernext()
if !ok {
inner = nil
}
}
return
}
},
}
} | go | func (q Query) SelectManyIndexed(selector func(int, interface{}) Query) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var inner interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if inner == nil {
inner, ok = outernext()
if !ok {
return
}
innernext = selector(index, inner).Iterate()
index++
}
item, ok = innernext()
if !ok {
inner = nil
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"SelectManyIndexed",
"(",
"selector",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"outernext",
":=",
"q",
... | // SelectManyIndexed projects each element of a collection to a Query, iterates
// and flattens the resulting collection into one collection.
//
// The first argument to selector represents the zero-based index of that
// element in the source collection. This can be useful if the elements are in a
// known order and you want to do something with an element at a particular
// index, for example. It can also be useful if you want to retrieve the index
// of one or more elements. The second argument to selector represents the
// element to process. | [
"SelectManyIndexed",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
".",
"The",
"first",
"argument",
"to",
"selector",
"represents",
"the",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L66-L96 |
151,303 | ahmetb/go-linq | selectmany.go | SelectManyBy | func (q Query) SelectManyBy(selector func(interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if outer == nil {
outer, ok = outernext()
if !ok {
return
}
innernext = selector(outer).Iterate()
}
item, ok = innernext()
if !ok {
outer = nil
}
}
item = resultSelector(item, outer)
return
}
},
}
} | go | func (q Query) SelectManyBy(selector func(interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if outer == nil {
outer, ok = outernext()
if !ok {
return
}
innernext = selector(outer).Iterate()
}
item, ok = innernext()
if !ok {
outer = nil
}
}
item = resultSelector(item, outer)
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"SelectManyBy",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"Query",
",",
"resultSelector",
"func",
"(",
"interface",
"{",
"}",
",",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"... | // SelectManyBy projects each element of a collection to a Query, iterates and
// flattens the resulting collection into one collection, and invokes a result
// selector function on each element therein. | [
"SelectManyBy",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
"and",
"invokes",
"a",
"result",
"selector",
"function",
"on",
"each",
"elem... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L123-L154 |
151,304 | ahmetb/go-linq | selectmany.go | SelectManyByIndexed | func (q Query) SelectManyByIndexed(selector func(int, interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if outer == nil {
outer, ok = outernext()
if !ok {
return
}
innernext = selector(index, outer).Iterate()
index++
}
item, ok = innernext()
if !ok {
outer = nil
}
}
item = resultSelector(item, outer)
return
}
},
}
} | go | func (q Query) SelectManyByIndexed(selector func(int, interface{}) Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
index := 0
var outer interface{}
var innernext Iterator
return func() (item interface{}, ok bool) {
for !ok {
if outer == nil {
outer, ok = outernext()
if !ok {
return
}
innernext = selector(index, outer).Iterate()
index++
}
item, ok = innernext()
if !ok {
outer = nil
}
}
item = resultSelector(item, outer)
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"SelectManyByIndexed",
"(",
"selector",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"Query",
",",
"resultSelector",
"func",
"(",
"interface",
"{",
"}",
",",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")"... | // SelectManyByIndexed projects each element of a collection to a Query,
// iterates and flattens the resulting collection into one collection, and
// invokes a result selector function on each element therein. The index of each
// source element is used in the intermediate projected form of that element. | [
"SelectManyByIndexed",
"projects",
"each",
"element",
"of",
"a",
"collection",
"to",
"a",
"Query",
"iterates",
"and",
"flattens",
"the",
"resulting",
"collection",
"into",
"one",
"collection",
"and",
"invokes",
"a",
"result",
"selector",
"function",
"on",
"each",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L196-L229 |
151,305 | ahmetb/go-linq | where.go | Where | func (q Query) Where(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(item) {
return
}
}
return
}
},
}
} | go | func (q Query) Where(predicate func(interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(item) {
return
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Where",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
... | // Where filters a collection of values based on a predicate. | [
"Where",
"filters",
"a",
"collection",
"of",
"values",
"based",
"on",
"a",
"predicate",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/where.go#L4-L20 |
151,306 | ahmetb/go-linq | where.go | WhereIndexed | func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
index := 0
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(index, item) {
return
}
index++
}
return
}
},
}
} | go | func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
index := 0
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if predicate(index, item) {
return
}
index++
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"WhereIndexed",
"(",
"predicate",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"bool",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"It... | // WhereIndexed filters a collection of values based on a predicate. Each
// element's index is used in the logic of the predicate function.
//
// The first argument represents the zero-based index of the element within
// collection. The second argument of predicate represents the element to test. | [
"WhereIndexed",
"filters",
"a",
"collection",
"of",
"values",
"based",
"on",
"a",
"predicate",
".",
"Each",
"element",
"s",
"index",
"is",
"used",
"in",
"the",
"logic",
"of",
"the",
"predicate",
"function",
".",
"The",
"first",
"argument",
"represents",
"the... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/where.go#L49-L68 |
151,307 | ahmetb/go-linq | groupjoin.go | GroupJoin | func (q Query) GroupJoin(inner Query,
outerKeySelector func(interface{}) interface{},
innerKeySelector func(interface{}) interface{},
resultSelector func(outer interface{}, inners []interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
innernext := inner.Iterate()
innerLookup := make(map[interface{}][]interface{})
for innerItem, ok := innernext(); ok; innerItem, ok = innernext() {
innerKey := innerKeySelector(innerItem)
innerLookup[innerKey] = append(innerLookup[innerKey], innerItem)
}
return func() (item interface{}, ok bool) {
if item, ok = outernext(); !ok {
return
}
if group, has := innerLookup[outerKeySelector(item)]; !has {
item = resultSelector(item, []interface{}{})
} else {
item = resultSelector(item, group)
}
return
}
},
}
} | go | func (q Query) GroupJoin(inner Query,
outerKeySelector func(interface{}) interface{},
innerKeySelector func(interface{}) interface{},
resultSelector func(outer interface{}, inners []interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
outernext := q.Iterate()
innernext := inner.Iterate()
innerLookup := make(map[interface{}][]interface{})
for innerItem, ok := innernext(); ok; innerItem, ok = innernext() {
innerKey := innerKeySelector(innerItem)
innerLookup[innerKey] = append(innerLookup[innerKey], innerItem)
}
return func() (item interface{}, ok bool) {
if item, ok = outernext(); !ok {
return
}
if group, has := innerLookup[outerKeySelector(item)]; !has {
item = resultSelector(item, []interface{}{})
} else {
item = resultSelector(item, group)
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"GroupJoin",
"(",
"inner",
"Query",
",",
"outerKeySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"innerKeySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"... | // GroupJoin correlates the elements of two collections based on key equality,
// and groups the results.
//
// This method produces hierarchical results, which means that elements from
// outer query are paired with collections of matching elements from inner.
// GroupJoin enables you to base your results on a whole set of matches for each
// element of outer query.
//
// The resultSelector function is called only one time for each outer element
// together with a collection of all the inner elements that match the outer
// element. This differs from the Join method, in which the result selector
// function is invoked on pairs that contain one element from outer and one
// element from inner.
//
// GroupJoin preserves the order of the elements of outer, and for each element
// of outer, the order of the matching elements from inner. | [
"GroupJoin",
"correlates",
"the",
"elements",
"of",
"two",
"collections",
"based",
"on",
"key",
"equality",
"and",
"groups",
"the",
"results",
".",
"This",
"method",
"produces",
"hierarchical",
"results",
"which",
"means",
"that",
"elements",
"from",
"outer",
"q... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/groupjoin.go#L21-L52 |
151,308 | ahmetb/go-linq | distinct.go | Distinct | func (q Query) Distinct() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
return
}
},
}
} | go | func (q Query) Distinct() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Distinct",
"(",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"set",
":=",
"make",
"(",
"map",
"[",
"interface",
"... | // Distinct method returns distinct elements from a collection. The result is an
// unordered collection that contains no duplicate values. | [
"Distinct",
"method",
"returns",
"distinct",
"elements",
"from",
"a",
"collection",
".",
"The",
"result",
"is",
"an",
"unordered",
"collection",
"that",
"contains",
"no",
"duplicate",
"values",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/distinct.go#L5-L23 |
151,309 | ahmetb/go-linq | distinct.go | DistinctBy | func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
s := selector(item)
if _, has := set[s]; !has {
set[s] = true
return
}
}
return
}
},
}
} | go | func (q Query) DistinctBy(selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
set := make(map[interface{}]bool)
return func() (item interface{}, ok bool) {
for item, ok = next(); ok; item, ok = next() {
s := selector(item)
if _, has := set[s]; !has {
set[s] = true
return
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"DistinctBy",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"It... | // DistinctBy method returns distinct elements from a collection. This method
// executes selector function for each element to determine a value to compare.
// The result is an unordered collection that contains no duplicate values. | [
"DistinctBy",
"method",
"returns",
"distinct",
"elements",
"from",
"a",
"collection",
".",
"This",
"method",
"executes",
"selector",
"function",
"for",
"each",
"element",
"to",
"determine",
"a",
"value",
"to",
"compare",
".",
"The",
"result",
"is",
"an",
"unor... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/distinct.go#L56-L75 |
151,310 | ahmetb/go-linq | groupby.go | GroupBy | func (q Query) GroupBy(keySelector func(interface{}) interface{},
elementSelector func(interface{}) interface{}) Query {
return Query{
func() Iterator {
next := q.Iterate()
set := make(map[interface{}][]interface{})
for item, ok := next(); ok; item, ok = next() {
key := keySelector(item)
set[key] = append(set[key], elementSelector(item))
}
len := len(set)
idx := 0
groups := make([]Group, len)
for k, v := range set {
groups[idx] = Group{k, v}
idx++
}
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = groups[index]
index++
}
return
}
},
}
} | go | func (q Query) GroupBy(keySelector func(interface{}) interface{},
elementSelector func(interface{}) interface{}) Query {
return Query{
func() Iterator {
next := q.Iterate()
set := make(map[interface{}][]interface{})
for item, ok := next(); ok; item, ok = next() {
key := keySelector(item)
set[key] = append(set[key], elementSelector(item))
}
len := len(set)
idx := 0
groups := make([]Group, len)
for k, v := range set {
groups[idx] = Group{k, v}
idx++
}
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = groups[index]
index++
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"GroupBy",
"(",
"keySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"elementSelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",... | // GroupBy method groups the elements of a collection according to a specified
// key selector function and projects the elements for each group by using a
// specified function. | [
"GroupBy",
"method",
"groups",
"the",
"elements",
"of",
"a",
"collection",
"according",
"to",
"a",
"specified",
"key",
"selector",
"function",
"and",
"projects",
"the",
"elements",
"for",
"each",
"group",
"by",
"using",
"a",
"specified",
"function",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/groupby.go#L12-L45 |
151,311 | ahmetb/go-linq | result.go | All | func (q Query) All(predicate func(interface{}) bool) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if !predicate(item) {
return false
}
}
return true
} | go | func (q Query) All(predicate func(interface{}) bool) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if !predicate(item) {
return false
}
}
return true
} | [
"func",
"(",
"q",
"Query",
")",
"All",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"bool",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
... | // All determines whether all elements of a collection satisfy a condition. | [
"All",
"determines",
"whether",
"all",
"elements",
"of",
"a",
"collection",
"satisfy",
"a",
"condition",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L9-L19 |
151,312 | ahmetb/go-linq | result.go | Average | func (q Query) Average() (r float64) {
next := q.Iterate()
item, ok := next()
if !ok {
return math.NaN()
}
n := 1
switch item.(type) {
case int, int8, int16, int32, int64:
conv := getIntConverter(item)
sum := conv(item)
for item, ok = next(); ok; item, ok = next() {
sum += conv(item)
n++
}
r = float64(sum)
case uint, uint8, uint16, uint32, uint64:
conv := getUIntConverter(item)
sum := conv(item)
for item, ok = next(); ok; item, ok = next() {
sum += conv(item)
n++
}
r = float64(sum)
default:
conv := getFloatConverter(item)
r = conv(item)
for item, ok = next(); ok; item, ok = next() {
r += conv(item)
n++
}
}
return r / float64(n)
} | go | func (q Query) Average() (r float64) {
next := q.Iterate()
item, ok := next()
if !ok {
return math.NaN()
}
n := 1
switch item.(type) {
case int, int8, int16, int32, int64:
conv := getIntConverter(item)
sum := conv(item)
for item, ok = next(); ok; item, ok = next() {
sum += conv(item)
n++
}
r = float64(sum)
case uint, uint8, uint16, uint32, uint64:
conv := getUIntConverter(item)
sum := conv(item)
for item, ok = next(); ok; item, ok = next() {
sum += conv(item)
n++
}
r = float64(sum)
default:
conv := getFloatConverter(item)
r = conv(item)
for item, ok = next(); ok; item, ok = next() {
r += conv(item)
n++
}
}
return r / float64(n)
} | [
"func",
"(",
"q",
"Query",
")",
"Average",
"(",
")",
"(",
"r",
"float64",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"item",
",",
"ok",
":=",
"next",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"math",
".",
"NaN",
"(",
... | // Average computes the average of a collection of numeric values. | [
"Average",
"computes",
"the",
"average",
"of",
"a",
"collection",
"of",
"numeric",
"values",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L84-L124 |
151,313 | ahmetb/go-linq | result.go | Contains | func (q Query) Contains(value interface{}) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if item == value {
return true
}
}
return false
} | go | func (q Query) Contains(value interface{}) bool {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if item == value {
return true
}
}
return false
} | [
"func",
"(",
"q",
"Query",
")",
"Contains",
"(",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"item",
",",
"ok",
"=",
... | // Contains determines whether a collection contains a specified element. | [
"Contains",
"determines",
"whether",
"a",
"collection",
"contains",
"a",
"specified",
"element",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L127-L137 |
151,314 | ahmetb/go-linq | result.go | Count | func (q Query) Count() (r int) {
next := q.Iterate()
for _, ok := next(); ok; _, ok = next() {
r++
}
return
} | go | func (q Query) Count() (r int) {
next := q.Iterate()
for _, ok := next(); ok; _, ok = next() {
r++
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"Count",
"(",
")",
"(",
"r",
"int",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"_",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"_",
",",
"ok",
"=",
"next",
"(",
")",
"{",
... | // Count returns the number of elements in a collection. | [
"Count",
"returns",
"the",
"number",
"of",
"elements",
"in",
"a",
"collection",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L140-L148 |
151,315 | ahmetb/go-linq | result.go | CountWith | func (q Query) CountWith(predicate func(interface{}) bool) (r int) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
r++
}
}
return
} | go | func (q Query) CountWith(predicate func(interface{}) bool) (r int) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
r++
}
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"CountWith",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"(",
"r",
"int",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")... | // CountWith returns a number that represents how many elements in the specified
// collection satisfy a condition. | [
"CountWith",
"returns",
"a",
"number",
"that",
"represents",
"how",
"many",
"elements",
"in",
"the",
"specified",
"collection",
"satisfy",
"a",
"condition",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L152-L162 |
151,316 | ahmetb/go-linq | result.go | FirstWith | func (q Query) FirstWith(predicate func(interface{}) bool) interface{} {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
return item
}
}
return nil
} | go | func (q Query) FirstWith(predicate func(interface{}) bool) interface{} {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
return item
}
}
return nil
} | [
"func",
"(",
"q",
"Query",
")",
"FirstWith",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"interface",
"{",
"}",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")"... | // FirstWith returns the first element of a collection that satisfies a
// specified condition. | [
"FirstWith",
"returns",
"the",
"first",
"element",
"of",
"a",
"collection",
"that",
"satisfies",
"a",
"specified",
"condition",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L194-L204 |
151,317 | ahmetb/go-linq | result.go | ForEach | func (q Query) ForEach(action func(interface{})) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
action(item)
}
} | go | func (q Query) ForEach(action func(interface{})) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
action(item)
}
} | [
"func",
"(",
"q",
"Query",
")",
"ForEach",
"(",
"action",
"func",
"(",
"interface",
"{",
"}",
")",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"item",
",",
"... | // ForEach performs the specified action on each element of a collection. | [
"ForEach",
"performs",
"the",
"specified",
"action",
"on",
"each",
"element",
"of",
"a",
"collection",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L229-L235 |
151,318 | ahmetb/go-linq | result.go | ForEachIndexed | func (q Query) ForEachIndexed(action func(int, interface{})) {
next := q.Iterate()
index := 0
for item, ok := next(); ok; item, ok = next() {
action(index, item)
index++
}
} | go | func (q Query) ForEachIndexed(action func(int, interface{})) {
next := q.Iterate()
index := 0
for item, ok := next(); ok; item, ok = next() {
action(index, item)
index++
}
} | [
"func",
"(",
"q",
"Query",
")",
"ForEachIndexed",
"(",
"action",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"index",
":=",
"0",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",... | // ForEachIndexed performs the specified action on each element of a collection.
//
// The first argument to action represents the zero-based index of that
// element in the source collection. This can be useful if the elements are in a
// known order and you want to do something with an element at a particular
// index, for example. It can also be useful if you want to retrieve the index
// of one or more elements. The second argument to action represents the
// element to process. | [
"ForEachIndexed",
"performs",
"the",
"specified",
"action",
"on",
"each",
"element",
"of",
"a",
"collection",
".",
"The",
"first",
"argument",
"to",
"action",
"represents",
"the",
"zero",
"-",
"based",
"index",
"of",
"that",
"element",
"in",
"the",
"source",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L267-L275 |
151,319 | ahmetb/go-linq | result.go | Last | func (q Query) Last() (r interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
r = item
}
return
} | go | func (q Query) Last() (r interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
r = item
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"Last",
"(",
")",
"(",
"r",
"interface",
"{",
"}",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"item",
",",
"ok",
"=",
"nex... | // Last returns the last element of a collection. | [
"Last",
"returns",
"the",
"last",
"element",
"of",
"a",
"collection",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L300-L308 |
151,320 | ahmetb/go-linq | result.go | LastWith | func (q Query) LastWith(predicate func(interface{}) bool) (r interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
r = item
}
}
return
} | go | func (q Query) LastWith(predicate func(interface{}) bool) (r interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
r = item
}
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"LastWith",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"(",
"r",
"interface",
"{",
"}",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
... | // LastWith returns the last element of a collection that satisfies a specified
// condition. | [
"LastWith",
"returns",
"the",
"last",
"element",
"of",
"a",
"collection",
"that",
"satisfies",
"a",
"specified",
"condition",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L312-L322 |
151,321 | ahmetb/go-linq | result.go | Min | func (q Query) Min() (r interface{}) {
next := q.Iterate()
item, ok := next()
if !ok {
return nil
}
compare := getComparer(item)
r = item
for item, ok := next(); ok; item, ok = next() {
if compare(item, r) < 0 {
r = item
}
}
return
} | go | func (q Query) Min() (r interface{}) {
next := q.Iterate()
item, ok := next()
if !ok {
return nil
}
compare := getComparer(item)
r = item
for item, ok := next(); ok; item, ok = next() {
if compare(item, r) < 0 {
r = item
}
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"Min",
"(",
")",
"(",
"r",
"interface",
"{",
"}",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"item",
",",
"ok",
":=",
"next",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}"... | // Min returns the minimum value in a collection of values. | [
"Min",
"returns",
"the",
"minimum",
"value",
"in",
"a",
"collection",
"of",
"values",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L367-L384 |
151,322 | ahmetb/go-linq | result.go | Results | func (q Query) Results() (r []interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
r = append(r, item)
}
return
} | go | func (q Query) Results() (r []interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
r = append(r, item)
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"Results",
"(",
")",
"(",
"r",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"item",
",",
"o... | // Results iterates over a collection and returnes slice of interfaces | [
"Results",
"iterates",
"over",
"a",
"collection",
"and",
"returnes",
"slice",
"of",
"interfaces"
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L387-L395 |
151,323 | ahmetb/go-linq | result.go | SequenceEqual | func (q Query) SequenceEqual(q2 Query) bool {
next := q.Iterate()
next2 := q2.Iterate()
for item, ok := next(); ok; item, ok = next() {
item2, ok2 := next2()
if !ok2 || item != item2 {
return false
}
}
_, ok2 := next2()
return !ok2
} | go | func (q Query) SequenceEqual(q2 Query) bool {
next := q.Iterate()
next2 := q2.Iterate()
for item, ok := next(); ok; item, ok = next() {
item2, ok2 := next2()
if !ok2 || item != item2 {
return false
}
}
_, ok2 := next2()
return !ok2
} | [
"func",
"(",
"q",
"Query",
")",
"SequenceEqual",
"(",
"q2",
"Query",
")",
"bool",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"next2",
":=",
"q2",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
"... | // SequenceEqual determines whether two collections are equal. | [
"SequenceEqual",
"determines",
"whether",
"two",
"collections",
"are",
"equal",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L398-L411 |
151,324 | ahmetb/go-linq | result.go | Single | func (q Query) Single() interface{} {
next := q.Iterate()
item, ok := next()
if !ok {
return nil
}
_, ok = next()
if ok {
return nil
}
return item
} | go | func (q Query) Single() interface{} {
next := q.Iterate()
item, ok := next()
if !ok {
return nil
}
_, ok = next()
if ok {
return nil
}
return item
} | [
"func",
"(",
"q",
"Query",
")",
"Single",
"(",
")",
"interface",
"{",
"}",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"item",
",",
"ok",
":=",
"next",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"_",... | // Single returns the only element of a collection, and nil if there is not
// exactly one element in the collection. | [
"Single",
"returns",
"the",
"only",
"element",
"of",
"a",
"collection",
"and",
"nil",
"if",
"there",
"is",
"not",
"exactly",
"one",
"element",
"in",
"the",
"collection",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L415-L428 |
151,325 | ahmetb/go-linq | result.go | SingleWith | func (q Query) SingleWith(predicate func(interface{}) bool) (r interface{}) {
next := q.Iterate()
found := false
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
if found {
return nil
}
found = true
r = item
}
}
return
} | go | func (q Query) SingleWith(predicate func(interface{}) bool) (r interface{}) {
next := q.Iterate()
found := false
for item, ok := next(); ok; item, ok = next() {
if predicate(item) {
if found {
return nil
}
found = true
r = item
}
}
return
} | [
"func",
"(",
"q",
"Query",
")",
"SingleWith",
"(",
"predicate",
"func",
"(",
"interface",
"{",
"}",
")",
"bool",
")",
"(",
"r",
"interface",
"{",
"}",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"found",
":=",
"false",
"\n\n",
"f... | // SingleWith returns the only element of a collection that satisfies a
// specified condition, and nil if more than one such element exists. | [
"SingleWith",
"returns",
"the",
"only",
"element",
"of",
"a",
"collection",
"that",
"satisfies",
"a",
"specified",
"condition",
"and",
"nil",
"if",
"more",
"than",
"one",
"such",
"element",
"exists",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L432-L448 |
151,326 | ahmetb/go-linq | result.go | ToChannel | func (q Query) ToChannel(result chan<- interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
result <- item
}
close(result)
} | go | func (q Query) ToChannel(result chan<- interface{}) {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
result <- item
}
close(result)
} | [
"func",
"(",
"q",
"Query",
")",
"ToChannel",
"(",
"result",
"chan",
"<-",
"interface",
"{",
"}",
")",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"for",
"item",
",",
"ok",
":=",
"next",
"(",
")",
";",
"ok",
";",
"item",
",",
"ok",... | // ToChannel iterates over a collection and outputs each element to a channel,
// then closes it. | [
"ToChannel",
"iterates",
"over",
"a",
"collection",
"and",
"outputs",
"each",
"element",
"to",
"a",
"channel",
"then",
"closes",
"it",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L537-L545 |
151,327 | ahmetb/go-linq | result.go | ToMap | func (q Query) ToMap(result interface{}) {
q.ToMapBy(
result,
func(i interface{}) interface{} {
return i.(KeyValue).Key
},
func(i interface{}) interface{} {
return i.(KeyValue).Value
})
} | go | func (q Query) ToMap(result interface{}) {
q.ToMapBy(
result,
func(i interface{}) interface{} {
return i.(KeyValue).Key
},
func(i interface{}) interface{} {
return i.(KeyValue).Value
})
} | [
"func",
"(",
"q",
"Query",
")",
"ToMap",
"(",
"result",
"interface",
"{",
"}",
")",
"{",
"q",
".",
"ToMapBy",
"(",
"result",
",",
"func",
"(",
"i",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"return",
"i",
".",
"(",
"KeyValue",
")",
... | // ToMap iterates over a collection and populates result map with elements.
// Collection elements have to be of KeyValue type to use this method. To
// populate a map with elements of different type use ToMapBy method. ToMap
// doesn't empty the result map before populating it. | [
"ToMap",
"iterates",
"over",
"a",
"collection",
"and",
"populates",
"result",
"map",
"with",
"elements",
".",
"Collection",
"elements",
"have",
"to",
"be",
"of",
"KeyValue",
"type",
"to",
"use",
"this",
"method",
".",
"To",
"populate",
"a",
"map",
"with",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L551-L560 |
151,328 | ahmetb/go-linq | result.go | ToMapBy | func (q Query) ToMapBy(result interface{},
keySelector func(interface{}) interface{},
valueSelector func(interface{}) interface{}) {
res := reflect.ValueOf(result)
m := reflect.Indirect(res)
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
key := reflect.ValueOf(keySelector(item))
value := reflect.ValueOf(valueSelector(item))
m.SetMapIndex(key, value)
}
res.Elem().Set(m)
} | go | func (q Query) ToMapBy(result interface{},
keySelector func(interface{}) interface{},
valueSelector func(interface{}) interface{}) {
res := reflect.ValueOf(result)
m := reflect.Indirect(res)
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
key := reflect.ValueOf(keySelector(item))
value := reflect.ValueOf(valueSelector(item))
m.SetMapIndex(key, value)
}
res.Elem().Set(m)
} | [
"func",
"(",
"q",
"Query",
")",
"ToMapBy",
"(",
"result",
"interface",
"{",
"}",
",",
"keySelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
",",
"valueSelector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
... | // ToMapBy iterates over a collection and populates the result map with
// elements. Functions keySelector and valueSelector are executed for each
// element of the collection to generate key and value for the map. Generated
// key and value types must be assignable to the map's key and value types.
// ToMapBy doesn't empty the result map before populating it. | [
"ToMapBy",
"iterates",
"over",
"a",
"collection",
"and",
"populates",
"the",
"result",
"map",
"with",
"elements",
".",
"Functions",
"keySelector",
"and",
"valueSelector",
"are",
"executed",
"for",
"each",
"element",
"of",
"the",
"collection",
"to",
"generate",
"... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L567-L582 |
151,329 | ahmetb/go-linq | result.go | ToSlice | func (q Query) ToSlice(v interface{}) {
res := reflect.ValueOf(v)
slice := reflect.Indirect(res)
cap := slice.Cap()
res.Elem().Set(slice.Slice(0, cap)) // make len(slice)==cap(slice) from now on
next := q.Iterate()
index := 0
for item, ok := next(); ok; item, ok = next() {
if index >= cap {
slice, cap = grow(slice)
}
slice.Index(index).Set(reflect.ValueOf(item))
index++
}
// reslice the len(res)==cap(res) actual res size
res.Elem().Set(slice.Slice(0, index))
} | go | func (q Query) ToSlice(v interface{}) {
res := reflect.ValueOf(v)
slice := reflect.Indirect(res)
cap := slice.Cap()
res.Elem().Set(slice.Slice(0, cap)) // make len(slice)==cap(slice) from now on
next := q.Iterate()
index := 0
for item, ok := next(); ok; item, ok = next() {
if index >= cap {
slice, cap = grow(slice)
}
slice.Index(index).Set(reflect.ValueOf(item))
index++
}
// reslice the len(res)==cap(res) actual res size
res.Elem().Set(slice.Slice(0, index))
} | [
"func",
"(",
"q",
"Query",
")",
"ToSlice",
"(",
"v",
"interface",
"{",
"}",
")",
"{",
"res",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"slice",
":=",
"reflect",
".",
"Indirect",
"(",
"res",
")",
"\n\n",
"cap",
":=",
"slice",
".",
"Cap... | // ToSlice iterates over a collection and saves the results in the slice pointed
// by v. It overwrites the existing slice, starting from index 0.
//
// If the slice pointed by v has sufficient capacity, v will be pointed to a
// resliced slice. If it does not, a new underlying array will be allocated and
// v will point to it. | [
"ToSlice",
"iterates",
"over",
"a",
"collection",
"and",
"saves",
"the",
"results",
"in",
"the",
"slice",
"pointed",
"by",
"v",
".",
"It",
"overwrites",
"the",
"existing",
"slice",
"starting",
"from",
"index",
"0",
".",
"If",
"the",
"slice",
"pointed",
"by... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L625-L644 |
151,330 | ahmetb/go-linq | union.go | Union | func (q Query) Union(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
set := make(map[interface{}]bool)
use1 := true
return func() (item interface{}, ok bool) {
if use1 {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
use1 = false
}
for item, ok = next2(); ok; item, ok = next2() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
return
}
},
}
} | go | func (q Query) Union(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
set := make(map[interface{}]bool)
use1 := true
return func() (item interface{}, ok bool) {
if use1 {
for item, ok = next(); ok; item, ok = next() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
use1 = false
}
for item, ok = next2(); ok; item, ok = next2() {
if _, has := set[item]; !has {
set[item] = true
return
}
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Union",
"(",
"q2",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"next2",
":=",
"q2",
".",
"Iterate",
"("... | // Union produces the set union of two collections.
//
// This method excludes duplicates from the return set. This is different
// behavior to the Concat method, which returns all the elements in the input
// collection including duplicates. | [
"Union",
"produces",
"the",
"set",
"union",
"of",
"two",
"collections",
".",
"This",
"method",
"excludes",
"duplicates",
"from",
"the",
"return",
"set",
".",
"This",
"is",
"different",
"behavior",
"to",
"the",
"Concat",
"method",
"which",
"returns",
"all",
"... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/union.go#L8-L40 |
151,331 | ahmetb/go-linq | select.go | Select | func (q Query) Select(selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
return func() (item interface{}, ok bool) {
var it interface{}
it, ok = next()
if ok {
item = selector(it)
}
return
}
},
}
} | go | func (q Query) Select(selector func(interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
return func() (item interface{}, ok bool) {
var it interface{}
it, ok = next()
if ok {
item = selector(it)
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Select",
"(",
"selector",
"func",
"(",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterat... | // Select projects each element of a collection into a new form. Returns a query
// with the result of invoking the transform function on each element of
// original source.
//
// This projection method requires the transform function, selector, to produce
// one value for each value in the source collection. If selector returns a
// value that is itself a collection, it is up to the consumer to traverse the
// subcollections manually. In such a situation, it might be better for your
// query to return a single coalesced collection of values. To achieve this, use
// the SelectMany method instead of Select. Although SelectMany works similarly
// to Select, it differs in that the transform function returns a collection
// that is then expanded by SelectMany before it is returned. | [
"Select",
"projects",
"each",
"element",
"of",
"a",
"collection",
"into",
"a",
"new",
"form",
".",
"Returns",
"a",
"query",
"with",
"the",
"result",
"of",
"invoking",
"the",
"transform",
"function",
"on",
"each",
"element",
"of",
"original",
"source",
".",
... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/select.go#L15-L31 |
151,332 | ahmetb/go-linq | select.go | SelectIndexed | func (q Query) SelectIndexed(selector func(int, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
index := 0
return func() (item interface{}, ok bool) {
var it interface{}
it, ok = next()
if ok {
item = selector(index, it)
index++
}
return
}
},
}
} | go | func (q Query) SelectIndexed(selector func(int, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
index := 0
return func() (item interface{}, ok bool) {
var it interface{}
it, ok = next()
if ok {
item = selector(index, it)
index++
}
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"SelectIndexed",
"(",
"selector",
"func",
"(",
"int",
",",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
... | // SelectIndexed projects each element of a collection into a new form by
// incorporating the element's index. Returns a query with the result of
// invoking the transform function on each element of original source.
//
// The first argument to selector represents the zero-based index of that
// element in the source collection. This can be useful if the elements are in a
// known order and you want to do something with an element at a particular
// index, for example. It can also be useful if you want to retrieve the index
// of one or more elements. The second argument to selector represents the
// element to process.
//
// This projection method requires the transform function, selector, to produce
// one value for each value in the source collection. If selector returns a
// value that is itself a collection, it is up to the consumer to traverse the
// subcollections manually. In such a situation, it might be better for your
// query to return a single coalesced collection of values. To achieve this, use
// the SelectMany method instead of Select. Although SelectMany works similarly
// to Select, it differs in that the transform function returns a collection
// that is then expanded by SelectMany before it is returned. | [
"SelectIndexed",
"projects",
"each",
"element",
"of",
"a",
"collection",
"into",
"a",
"new",
"form",
"by",
"incorporating",
"the",
"element",
"s",
"index",
".",
"Returns",
"a",
"query",
"with",
"the",
"result",
"of",
"invoking",
"the",
"transform",
"function",... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/select.go#L72-L90 |
151,333 | ahmetb/go-linq | reverse.go | Reverse | func (q Query) Reverse() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
items := []interface{}{}
for item, ok := next(); ok; item, ok = next() {
items = append(items, item)
}
index := len(items) - 1
return func() (item interface{}, ok bool) {
if index < 0 {
return
}
item, ok = items[index], true
index--
return
}
},
}
} | go | func (q Query) Reverse() Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
items := []interface{}{}
for item, ok := next(); ok; item, ok = next() {
items = append(items, item)
}
index := len(items) - 1
return func() (item interface{}, ok bool) {
if index < 0 {
return
}
item, ok = items[index], true
index--
return
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Reverse",
"(",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n\n",
"items",
":=",
"[",
"]",
"interface",
"{",
"}",
"{"... | // Reverse inverts the order of the elements in a collection.
//
// Unlike OrderBy, this sorting method does not consider the actual values
// themselves in determining the order. Rather, it just returns the elements in
// the reverse order from which they are produced by the underlying source. | [
"Reverse",
"inverts",
"the",
"order",
"of",
"the",
"elements",
"in",
"a",
"collection",
".",
"Unlike",
"OrderBy",
"this",
"sorting",
"method",
"does",
"not",
"consider",
"the",
"actual",
"values",
"themselves",
"in",
"determining",
"the",
"order",
".",
"Rather... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/reverse.go#L8-L30 |
151,334 | ahmetb/go-linq | zip.go | Zip | func (q Query) Zip(q2 Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next1 := q.Iterate()
next2 := q2.Iterate()
return func() (item interface{}, ok bool) {
item1, ok1 := next1()
item2, ok2 := next2()
if ok1 && ok2 {
return resultSelector(item1, item2), true
}
return nil, false
}
},
}
} | go | func (q Query) Zip(q2 Query,
resultSelector func(interface{}, interface{}) interface{}) Query {
return Query{
Iterate: func() Iterator {
next1 := q.Iterate()
next2 := q2.Iterate()
return func() (item interface{}, ok bool) {
item1, ok1 := next1()
item2, ok2 := next2()
if ok1 && ok2 {
return resultSelector(item1, item2), true
}
return nil, false
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Zip",
"(",
"q2",
"Query",
",",
"resultSelector",
"func",
"(",
"interface",
"{",
"}",
",",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")... | // Zip applies a specified function to the corresponding elements of two
// collections, producing a collection of the results.
//
// The method steps through the two input collections, applying function
// resultSelector to corresponding elements of the two collections. The method
// returns a collection of the values that are returned by resultSelector. If
// the input collections do not have the same number of elements, the method
// combines elements until it reaches the end of one of the collections. For
// example, if one collection has three elements and the other one has four, the
// result collection has only three elements. | [
"Zip",
"applies",
"a",
"specified",
"function",
"to",
"the",
"corresponding",
"elements",
"of",
"two",
"collections",
"producing",
"a",
"collection",
"of",
"the",
"results",
".",
"The",
"method",
"steps",
"through",
"the",
"two",
"input",
"collections",
"applyin... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/zip.go#L13-L33 |
151,335 | ahmetb/go-linq | from.go | From | func From(source interface{}) Query {
src := reflect.ValueOf(source)
switch src.Kind() {
case reflect.Slice, reflect.Array:
len := src.Len()
return Query{
Iterate: func() Iterator {
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = src.Index(index).Interface()
index++
}
return
}
},
}
case reflect.Map:
len := src.Len()
return Query{
Iterate: func() Iterator {
index := 0
keys := src.MapKeys()
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
key := keys[index]
item = KeyValue{
Key: key.Interface(),
Value: src.MapIndex(key).Interface(),
}
index++
}
return
}
},
}
case reflect.String:
return FromString(source.(string))
case reflect.Chan:
return FromChannel(source.(chan interface{}))
default:
return FromIterable(source.(Iterable))
}
} | go | func From(source interface{}) Query {
src := reflect.ValueOf(source)
switch src.Kind() {
case reflect.Slice, reflect.Array:
len := src.Len()
return Query{
Iterate: func() Iterator {
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = src.Index(index).Interface()
index++
}
return
}
},
}
case reflect.Map:
len := src.Len()
return Query{
Iterate: func() Iterator {
index := 0
keys := src.MapKeys()
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
key := keys[index]
item = KeyValue{
Key: key.Interface(),
Value: src.MapIndex(key).Interface(),
}
index++
}
return
}
},
}
case reflect.String:
return FromString(source.(string))
case reflect.Chan:
return FromChannel(source.(chan interface{}))
default:
return FromIterable(source.(Iterable))
}
} | [
"func",
"From",
"(",
"source",
"interface",
"{",
"}",
")",
"Query",
"{",
"src",
":=",
"reflect",
".",
"ValueOf",
"(",
"source",
")",
"\n\n",
"switch",
"src",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Slice",
",",
"reflect",
".",
"Array",
... | // From initializes a linq query with passed slice, array or map as the source.
// String, channel or struct implementing Iterable interface can be used as an
// input. In this case From delegates it to FromString, FromChannel and
// FromIterable internally. | [
"From",
"initializes",
"a",
"linq",
"query",
"with",
"passed",
"slice",
"array",
"or",
"map",
"as",
"the",
"source",
".",
"String",
"channel",
"or",
"struct",
"implementing",
"Iterable",
"interface",
"can",
"be",
"used",
"as",
"an",
"input",
".",
"In",
"th... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L32-L85 |
151,336 | ahmetb/go-linq | from.go | FromChannel | func FromChannel(source <-chan interface{}) Query {
return Query{
Iterate: func() Iterator {
return func() (item interface{}, ok bool) {
item, ok = <-source
return
}
},
}
} | go | func FromChannel(source <-chan interface{}) Query {
return Query{
Iterate: func() Iterator {
return func() (item interface{}, ok bool) {
item, ok = <-source
return
}
},
}
} | [
"func",
"FromChannel",
"(",
"source",
"<-",
"chan",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"return",
"func",
"(",
")",
"(",
"item",
"interface",
"{",
"}",
",",
"ok",
"bool"... | // FromChannel initializes a linq query with passed channel, linq iterates over
// channel until it is closed. | [
"FromChannel",
"initializes",
"a",
"linq",
"query",
"with",
"passed",
"channel",
"linq",
"iterates",
"over",
"channel",
"until",
"it",
"is",
"closed",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L89-L98 |
151,337 | ahmetb/go-linq | from.go | FromString | func FromString(source string) Query {
runes := []rune(source)
len := len(runes)
return Query{
Iterate: func() Iterator {
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = runes[index]
index++
}
return
}
},
}
} | go | func FromString(source string) Query {
runes := []rune(source)
len := len(runes)
return Query{
Iterate: func() Iterator {
index := 0
return func() (item interface{}, ok bool) {
ok = index < len
if ok {
item = runes[index]
index++
}
return
}
},
}
} | [
"func",
"FromString",
"(",
"source",
"string",
")",
"Query",
"{",
"runes",
":=",
"[",
"]",
"rune",
"(",
"source",
")",
"\n",
"len",
":=",
"len",
"(",
"runes",
")",
"\n\n",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"... | // FromString initializes a linq query with passed string, linq iterates over
// runes of string. | [
"FromString",
"initializes",
"a",
"linq",
"query",
"with",
"passed",
"string",
"linq",
"iterates",
"over",
"runes",
"of",
"string",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L102-L121 |
151,338 | ahmetb/go-linq | from.go | Range | func Range(start, count int) Query {
return Query{
Iterate: func() Iterator {
index := 0
current := start
return func() (item interface{}, ok bool) {
if index >= count {
return nil, false
}
item, ok = current, true
index++
current++
return
}
},
}
} | go | func Range(start, count int) Query {
return Query{
Iterate: func() Iterator {
index := 0
current := start
return func() (item interface{}, ok bool) {
if index >= count {
return nil, false
}
item, ok = current, true
index++
current++
return
}
},
}
} | [
"func",
"Range",
"(",
"start",
",",
"count",
"int",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"index",
":=",
"0",
"\n",
"current",
":=",
"start",
"\n\n",
"return",
"func",
"(",
")",
"(",
"item",
"... | // Range generates a sequence of integral numbers within a specified range. | [
"Range",
"generates",
"a",
"sequence",
"of",
"integral",
"numbers",
"within",
"a",
"specified",
"range",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L133-L152 |
151,339 | ahmetb/go-linq | from.go | Repeat | func Repeat(value interface{}, count int) Query {
return Query{
Iterate: func() Iterator {
index := 0
return func() (item interface{}, ok bool) {
if index >= count {
return nil, false
}
item, ok = value, true
index++
return
}
},
}
} | go | func Repeat(value interface{}, count int) Query {
return Query{
Iterate: func() Iterator {
index := 0
return func() (item interface{}, ok bool) {
if index >= count {
return nil, false
}
item, ok = value, true
index++
return
}
},
}
} | [
"func",
"Repeat",
"(",
"value",
"interface",
"{",
"}",
",",
"count",
"int",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"index",
":=",
"0",
"\n\n",
"return",
"func",
"(",
")",
"(",
"item",
"interface"... | // Repeat generates a sequence that contains one repeated value. | [
"Repeat",
"generates",
"a",
"sequence",
"that",
"contains",
"one",
"repeated",
"value",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L155-L172 |
151,340 | ahmetb/go-linq | genericfunc.go | Call | func (g *genericFunc) Call(params ...interface{}) interface{} {
paramsIn := make([]reflect.Value, len(params))
for i, param := range params {
paramsIn[i] = reflect.ValueOf(param)
}
paramsOut := g.Cache.FnValue.Call(paramsIn)
if len(paramsOut) >= 1 {
return paramsOut[0].Interface()
}
return nil
} | go | func (g *genericFunc) Call(params ...interface{}) interface{} {
paramsIn := make([]reflect.Value, len(params))
for i, param := range params {
paramsIn[i] = reflect.ValueOf(param)
}
paramsOut := g.Cache.FnValue.Call(paramsIn)
if len(paramsOut) >= 1 {
return paramsOut[0].Interface()
}
return nil
} | [
"func",
"(",
"g",
"*",
"genericFunc",
")",
"Call",
"(",
"params",
"...",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"paramsIn",
":=",
"make",
"(",
"[",
"]",
"reflect",
".",
"Value",
",",
"len",
"(",
"params",
")",
")",
"\n",
"for",
"... | // Call calls a dynamic function. | [
"Call",
"calls",
"a",
"dynamic",
"function",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L30-L40 |
151,341 | ahmetb/go-linq | genericfunc.go | newGenericFunc | func newGenericFunc(methodName, paramName string, fn interface{}, validateFunc func(*functionCache) error) (*genericFunc, error) {
cache := &functionCache{}
cache.FnValue = reflect.ValueOf(fn)
if cache.FnValue.Kind() != reflect.Func {
return nil, fmt.Errorf("%s: parameter [%s] is not a function type. It is a '%s'", methodName, paramName, cache.FnValue.Type())
}
cache.MethodName = methodName
cache.ParamName = paramName
cache.FnType = cache.FnValue.Type()
numTypesIn := cache.FnType.NumIn()
cache.TypesIn = make([]reflect.Type, numTypesIn)
for i := 0; i < numTypesIn; i++ {
cache.TypesIn[i] = cache.FnType.In(i)
}
numTypesOut := cache.FnType.NumOut()
cache.TypesOut = make([]reflect.Type, numTypesOut)
for i := 0; i < numTypesOut; i++ {
cache.TypesOut[i] = cache.FnType.Out(i)
}
if err := validateFunc(cache); err != nil {
return nil, err
}
return &genericFunc{Cache: cache}, nil
} | go | func newGenericFunc(methodName, paramName string, fn interface{}, validateFunc func(*functionCache) error) (*genericFunc, error) {
cache := &functionCache{}
cache.FnValue = reflect.ValueOf(fn)
if cache.FnValue.Kind() != reflect.Func {
return nil, fmt.Errorf("%s: parameter [%s] is not a function type. It is a '%s'", methodName, paramName, cache.FnValue.Type())
}
cache.MethodName = methodName
cache.ParamName = paramName
cache.FnType = cache.FnValue.Type()
numTypesIn := cache.FnType.NumIn()
cache.TypesIn = make([]reflect.Type, numTypesIn)
for i := 0; i < numTypesIn; i++ {
cache.TypesIn[i] = cache.FnType.In(i)
}
numTypesOut := cache.FnType.NumOut()
cache.TypesOut = make([]reflect.Type, numTypesOut)
for i := 0; i < numTypesOut; i++ {
cache.TypesOut[i] = cache.FnType.Out(i)
}
if err := validateFunc(cache); err != nil {
return nil, err
}
return &genericFunc{Cache: cache}, nil
} | [
"func",
"newGenericFunc",
"(",
"methodName",
",",
"paramName",
"string",
",",
"fn",
"interface",
"{",
"}",
",",
"validateFunc",
"func",
"(",
"*",
"functionCache",
")",
"error",
")",
"(",
"*",
"genericFunc",
",",
"error",
")",
"{",
"cache",
":=",
"&",
"fu... | // newGenericFunc instantiates a new genericFunc pointer | [
"newGenericFunc",
"instantiates",
"a",
"new",
"genericFunc",
"pointer"
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L43-L69 |
151,342 | ahmetb/go-linq | genericfunc.go | simpleParamValidator | func simpleParamValidator(In []reflect.Type, Out []reflect.Type) func(cache *functionCache) error {
return func(cache *functionCache) error {
var isValid = func() bool {
if In != nil {
if len(In) != len(cache.TypesIn) {
return false
}
for i, paramIn := range In {
if paramIn != genericTp && paramIn != cache.TypesIn[i] {
return false
}
}
}
if Out != nil {
if len(Out) != len(cache.TypesOut) {
return false
}
for i, paramOut := range Out {
if paramOut != genericTp && paramOut != cache.TypesOut[i] {
return false
}
}
}
return true
}
if !isValid() {
return fmt.Errorf("%s: parameter [%s] has a invalid function signature. Expected: '%s', actual: '%s'", cache.MethodName, cache.ParamName, formatFnSignature(In, Out), formatFnSignature(cache.TypesIn, cache.TypesOut))
}
return nil
}
} | go | func simpleParamValidator(In []reflect.Type, Out []reflect.Type) func(cache *functionCache) error {
return func(cache *functionCache) error {
var isValid = func() bool {
if In != nil {
if len(In) != len(cache.TypesIn) {
return false
}
for i, paramIn := range In {
if paramIn != genericTp && paramIn != cache.TypesIn[i] {
return false
}
}
}
if Out != nil {
if len(Out) != len(cache.TypesOut) {
return false
}
for i, paramOut := range Out {
if paramOut != genericTp && paramOut != cache.TypesOut[i] {
return false
}
}
}
return true
}
if !isValid() {
return fmt.Errorf("%s: parameter [%s] has a invalid function signature. Expected: '%s', actual: '%s'", cache.MethodName, cache.ParamName, formatFnSignature(In, Out), formatFnSignature(cache.TypesIn, cache.TypesOut))
}
return nil
}
} | [
"func",
"simpleParamValidator",
"(",
"In",
"[",
"]",
"reflect",
".",
"Type",
",",
"Out",
"[",
"]",
"reflect",
".",
"Type",
")",
"func",
"(",
"cache",
"*",
"functionCache",
")",
"error",
"{",
"return",
"func",
"(",
"cache",
"*",
"functionCache",
")",
"e... | // simpleParamValidator creates a function to validate genericFunc based in the
// In and Out function parameters. | [
"simpleParamValidator",
"creates",
"a",
"function",
"to",
"validate",
"genericFunc",
"based",
"in",
"the",
"In",
"and",
"Out",
"function",
"parameters",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L73-L104 |
151,343 | ahmetb/go-linq | genericfunc.go | newElemTypeSlice | func newElemTypeSlice(items ...interface{}) []reflect.Type {
typeList := make([]reflect.Type, len(items))
for i, item := range items {
typeItem := reflect.TypeOf(item)
if typeItem.Kind() == reflect.Ptr {
typeList[i] = typeItem.Elem()
}
}
return typeList
} | go | func newElemTypeSlice(items ...interface{}) []reflect.Type {
typeList := make([]reflect.Type, len(items))
for i, item := range items {
typeItem := reflect.TypeOf(item)
if typeItem.Kind() == reflect.Ptr {
typeList[i] = typeItem.Elem()
}
}
return typeList
} | [
"func",
"newElemTypeSlice",
"(",
"items",
"...",
"interface",
"{",
"}",
")",
"[",
"]",
"reflect",
".",
"Type",
"{",
"typeList",
":=",
"make",
"(",
"[",
"]",
"reflect",
".",
"Type",
",",
"len",
"(",
"items",
")",
")",
"\n",
"for",
"i",
",",
"item",
... | // newElemTypeSlice creates a slice of items elem types. | [
"newElemTypeSlice",
"creates",
"a",
"slice",
"of",
"items",
"elem",
"types",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L107-L116 |
151,344 | ahmetb/go-linq | genericfunc.go | formatFnSignature | func formatFnSignature(In []reflect.Type, Out []reflect.Type) string {
paramInNames := make([]string, len(In))
for i, typeIn := range In {
if typeIn == genericTp {
paramInNames[i] = "T"
} else {
paramInNames[i] = typeIn.String()
}
}
paramOutNames := make([]string, len(Out))
for i, typeOut := range Out {
if typeOut == genericTp {
paramOutNames[i] = "T"
} else {
paramOutNames[i] = typeOut.String()
}
}
return fmt.Sprintf("func(%s)%s", strings.Join(paramInNames, ","), strings.Join(paramOutNames, ","))
} | go | func formatFnSignature(In []reflect.Type, Out []reflect.Type) string {
paramInNames := make([]string, len(In))
for i, typeIn := range In {
if typeIn == genericTp {
paramInNames[i] = "T"
} else {
paramInNames[i] = typeIn.String()
}
}
paramOutNames := make([]string, len(Out))
for i, typeOut := range Out {
if typeOut == genericTp {
paramOutNames[i] = "T"
} else {
paramOutNames[i] = typeOut.String()
}
}
return fmt.Sprintf("func(%s)%s", strings.Join(paramInNames, ","), strings.Join(paramOutNames, ","))
} | [
"func",
"formatFnSignature",
"(",
"In",
"[",
"]",
"reflect",
".",
"Type",
",",
"Out",
"[",
"]",
"reflect",
".",
"Type",
")",
"string",
"{",
"paramInNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"In",
")",
")",
"\n",
"for",
"i",
... | // formatFnSignature formats the func signature based in the parameters types. | [
"formatFnSignature",
"formats",
"the",
"func",
"signature",
"based",
"in",
"the",
"parameters",
"types",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L119-L138 |
151,345 | ahmetb/go-linq | concat.go | Append | func (q Query) Append(item interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
appended := false
return func() (interface{}, bool) {
i, ok := next()
if ok {
return i, ok
}
if !appended {
appended = true
return item, true
}
return nil, false
}
},
}
} | go | func (q Query) Append(item interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
appended := false
return func() (interface{}, bool) {
i, ok := next()
if ok {
return i, ok
}
if !appended {
appended = true
return item, true
}
return nil, false
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Append",
"(",
"item",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"appended",
":=",
"false"... | // Append inserts an item to the end of a collection, so it becomes the last
// item. | [
"Append",
"inserts",
"an",
"item",
"to",
"the",
"end",
"of",
"a",
"collection",
"so",
"it",
"becomes",
"the",
"last",
"item",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/concat.go#L5-L26 |
151,346 | ahmetb/go-linq | concat.go | Concat | func (q Query) Concat(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
use1 := true
return func() (item interface{}, ok bool) {
if use1 {
item, ok = next()
if ok {
return
}
use1 = false
}
return next2()
}
},
}
} | go | func (q Query) Concat(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
use1 := true
return func() (item interface{}, ok bool) {
if use1 {
item, ok = next()
if ok {
return
}
use1 = false
}
return next2()
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Concat",
"(",
"q2",
"Query",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"next2",
":=",
"q2",
".",
"Iterate",
"(... | // Concat concatenates two collections.
//
// The Concat method differs from the Union method because the Concat method
// returns all the original elements in the input sequences. The Union method
// returns only unique elements. | [
"Concat",
"concatenates",
"two",
"collections",
".",
"The",
"Concat",
"method",
"differs",
"from",
"the",
"Union",
"method",
"because",
"the",
"Concat",
"method",
"returns",
"all",
"the",
"original",
"elements",
"in",
"the",
"input",
"sequences",
".",
"The",
"... | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/concat.go#L33-L54 |
151,347 | ahmetb/go-linq | concat.go | Prepend | func (q Query) Prepend(item interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
prepended := false
return func() (interface{}, bool) {
if prepended {
return next()
}
prepended = true
return item, true
}
},
}
} | go | func (q Query) Prepend(item interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
prepended := false
return func() (interface{}, bool) {
if prepended {
return next()
}
prepended = true
return item, true
}
},
}
} | [
"func",
"(",
"q",
"Query",
")",
"Prepend",
"(",
"item",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"Query",
"{",
"Iterate",
":",
"func",
"(",
")",
"Iterator",
"{",
"next",
":=",
"q",
".",
"Iterate",
"(",
")",
"\n",
"prepended",
":=",
"fals... | // Prepend inserts an item to the beginning of a collection, so it becomes the
// first item. | [
"Prepend",
"inserts",
"an",
"item",
"to",
"the",
"beginning",
"of",
"a",
"collection",
"so",
"it",
"becomes",
"the",
"first",
"item",
"."
] | 9f6960b5d2e017ec4b7820f045fbd7db66dd53b6 | https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/concat.go#L58-L74 |
151,348 | sfreiberg/gotwilio | proxy_participant.go | AddParticipant | func (session *ProxySession) AddParticipant(req ParticipantRequest) (response Participant, exception *Exception, err error) {
twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants")
res, err := session.twilio.post(participantFormValues(req), twilioUrl)
if err != nil {
return response, exception, err
}
defer res.Body.Close()
responseBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return response, exception, err
}
if res.StatusCode != http.StatusCreated {
exception = new(Exception)
err = json.Unmarshal(responseBody, exception)
// We aren't checking the error because we don't actually care.
// It's going to be passed to the client either way.
return response, exception, err
}
err = json.Unmarshal(responseBody, &response)
return response, exception, err
} | go | func (session *ProxySession) AddParticipant(req ParticipantRequest) (response Participant, exception *Exception, err error) {
twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants")
res, err := session.twilio.post(participantFormValues(req), twilioUrl)
if err != nil {
return response, exception, err
}
defer res.Body.Close()
responseBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return response, exception, err
}
if res.StatusCode != http.StatusCreated {
exception = new(Exception)
err = json.Unmarshal(responseBody, exception)
// We aren't checking the error because we don't actually care.
// It's going to be passed to the client either way.
return response, exception, err
}
err = json.Unmarshal(responseBody, &response)
return response, exception, err
} | [
"func",
"(",
"session",
"*",
"ProxySession",
")",
"AddParticipant",
"(",
"req",
"ParticipantRequest",
")",
"(",
"response",
"Participant",
",",
"exception",
"*",
"Exception",
",",
"err",
"error",
")",
"{",
"twilioUrl",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",... | // AddParticipant adds Participant to Session | [
"AddParticipant",
"adds",
"Participant",
"to",
"Session"
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/proxy_participant.go#L89-L116 |
151,349 | sfreiberg/gotwilio | proxy_participant.go | DeleteParticipant | func (session *ProxySession) DeleteParticipant(participantID string) (exception *Exception, err error) {
twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants", participantID)
res, err := session.twilio.delete(twilioUrl)
if err != nil {
return exception, err
}
respBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
if res.StatusCode != http.StatusNoContent {
exc := new(Exception)
err = json.Unmarshal(respBody, exc)
return exc, err
}
return nil, nil
} | go | func (session *ProxySession) DeleteParticipant(participantID string) (exception *Exception, err error) {
twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants", participantID)
res, err := session.twilio.delete(twilioUrl)
if err != nil {
return exception, err
}
respBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
if res.StatusCode != http.StatusNoContent {
exc := new(Exception)
err = json.Unmarshal(respBody, exc)
return exc, err
}
return nil, nil
} | [
"func",
"(",
"session",
"*",
"ProxySession",
")",
"DeleteParticipant",
"(",
"participantID",
"string",
")",
"(",
"exception",
"*",
"Exception",
",",
"err",
"error",
")",
"{",
"twilioUrl",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ProxyBaseUrl",
"... | // Participants cannot be changed once added. To add a new Participant, delete a Participant and add a new one. | [
"Participants",
"cannot",
"be",
"changed",
"once",
"added",
".",
"To",
"add",
"a",
"new",
"Participant",
"delete",
"a",
"Participant",
"and",
"add",
"a",
"new",
"one",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/proxy_participant.go#L179-L199 |
151,350 | sfreiberg/gotwilio | gotwilio.go | NewTwilioClientCustomHTTP | func NewTwilioClientCustomHTTP(accountSid, authToken string, HTTPClient *http.Client) *Twilio {
if HTTPClient == nil {
HTTPClient = defaultClient
}
return &Twilio{
AccountSid: accountSid,
AuthToken: authToken,
BaseUrl: baseURL,
VideoUrl: videoURL,
HTTPClient: HTTPClient,
}
} | go | func NewTwilioClientCustomHTTP(accountSid, authToken string, HTTPClient *http.Client) *Twilio {
if HTTPClient == nil {
HTTPClient = defaultClient
}
return &Twilio{
AccountSid: accountSid,
AuthToken: authToken,
BaseUrl: baseURL,
VideoUrl: videoURL,
HTTPClient: HTTPClient,
}
} | [
"func",
"NewTwilioClientCustomHTTP",
"(",
"accountSid",
",",
"authToken",
"string",
",",
"HTTPClient",
"*",
"http",
".",
"Client",
")",
"*",
"Twilio",
"{",
"if",
"HTTPClient",
"==",
"nil",
"{",
"HTTPClient",
"=",
"defaultClient",
"\n",
"}",
"\n\n",
"return",
... | // Create a new Twilio client, optionally using a custom http.Client | [
"Create",
"a",
"new",
"Twilio",
"client",
"optionally",
"using",
"a",
"custom",
"http",
".",
"Client"
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/gotwilio.go#L49-L61 |
151,351 | sfreiberg/gotwilio | fax.go | DateCreatedAsTime | func (d *FaxBase) DateCreatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, d.DateCreated)
} | go | func (d *FaxBase) DateCreatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, d.DateCreated)
} | [
"func",
"(",
"d",
"*",
"FaxBase",
")",
"DateCreatedAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"d",
".",
"DateCreated",
")",
"\n",
"}"
] | // DateCreatedAsTime returns FaxBase.DateCreated as a time.Time object
// instead of a string. | [
"DateCreatedAsTime",
"returns",
"FaxBase",
".",
"DateCreated",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/fax.go#L20-L22 |
151,352 | sfreiberg/gotwilio | fax.go | DateUpdatesAsTime | func (d *FaxBase) DateUpdatesAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, d.DateUpdated)
} | go | func (d *FaxBase) DateUpdatesAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, d.DateUpdated)
} | [
"func",
"(",
"d",
"*",
"FaxBase",
")",
"DateUpdatesAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"d",
".",
"DateUpdated",
")",
"\n",
"}"
] | // DateUpdatesAsTime returns FaxBase.DateUpdated as a time.Time object
// instead of a string. | [
"DateUpdatesAsTime",
"returns",
"FaxBase",
".",
"DateUpdated",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/fax.go#L26-L28 |
151,353 | sfreiberg/gotwilio | sms.go | DateCreatedAsTime | func (sms *SmsResponse) DateCreatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, sms.DateCreated)
} | go | func (sms *SmsResponse) DateCreatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, sms.DateCreated)
} | [
"func",
"(",
"sms",
"*",
"SmsResponse",
")",
"DateCreatedAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"sms",
".",
"DateCreated",
")",
"\n",
"}"
] | // DateCreatedAsTime returns SmsResponse.DateCreated as a time.Time object
// instead of a string. | [
"DateCreatedAsTime",
"returns",
"SmsResponse",
".",
"DateCreated",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L31-L33 |
151,354 | sfreiberg/gotwilio | sms.go | DateUpdateAsTime | func (sms *SmsResponse) DateUpdateAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, sms.DateUpdate)
} | go | func (sms *SmsResponse) DateUpdateAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, sms.DateUpdate)
} | [
"func",
"(",
"sms",
"*",
"SmsResponse",
")",
"DateUpdateAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"sms",
".",
"DateUpdate",
")",
"\n",
"}"
] | // DateUpdateAsTime returns SmsResponse.DateUpdate as a time.Time object
// instead of a string. | [
"DateUpdateAsTime",
"returns",
"SmsResponse",
".",
"DateUpdate",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L37-L39 |
151,355 | sfreiberg/gotwilio | sms.go | DateSentAsTime | func (sms *SmsResponse) DateSentAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, sms.DateSent)
} | go | func (sms *SmsResponse) DateSentAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, sms.DateSent)
} | [
"func",
"(",
"sms",
"*",
"SmsResponse",
")",
"DateSentAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"sms",
".",
"DateSent",
")",
"\n",
"}"
] | // DateSentAsTime returns SmsResponse.DateSent as a time.Time object
// instead of a string. | [
"DateSentAsTime",
"returns",
"SmsResponse",
".",
"DateSent",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L43-L45 |
151,356 | sfreiberg/gotwilio | sms.go | sendMessage | func (twilio *Twilio) sendMessage(formValues url.Values) (smsResponse *SmsResponse, exception *Exception, err error) {
twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Messages.json"
res, err := twilio.post(formValues, twilioUrl)
if err != nil {
return smsResponse, exception, err
}
defer res.Body.Close()
responseBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return smsResponse, exception, err
}
if res.StatusCode != http.StatusCreated {
exception = new(Exception)
err = json.Unmarshal(responseBody, exception)
// We aren't checking the error because we don't actually care.
// It's going to be passed to the client either way.
return smsResponse, exception, err
}
smsResponse = new(SmsResponse)
err = json.Unmarshal(responseBody, smsResponse)
return smsResponse, exception, err
} | go | func (twilio *Twilio) sendMessage(formValues url.Values) (smsResponse *SmsResponse, exception *Exception, err error) {
twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Messages.json"
res, err := twilio.post(formValues, twilioUrl)
if err != nil {
return smsResponse, exception, err
}
defer res.Body.Close()
responseBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return smsResponse, exception, err
}
if res.StatusCode != http.StatusCreated {
exception = new(Exception)
err = json.Unmarshal(responseBody, exception)
// We aren't checking the error because we don't actually care.
// It's going to be passed to the client either way.
return smsResponse, exception, err
}
smsResponse = new(SmsResponse)
err = json.Unmarshal(responseBody, smsResponse)
return smsResponse, exception, err
} | [
"func",
"(",
"twilio",
"*",
"Twilio",
")",
"sendMessage",
"(",
"formValues",
"url",
".",
"Values",
")",
"(",
"smsResponse",
"*",
"SmsResponse",
",",
"exception",
"*",
"Exception",
",",
"err",
"error",
")",
"{",
"twilioUrl",
":=",
"twilio",
".",
"BaseUrl",
... | // Core method to send message | [
"Core",
"method",
"to",
"send",
"message"
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L107-L133 |
151,357 | sfreiberg/gotwilio | voice.go | DateCreatedAsTime | func (vr *VoiceResponse) DateCreatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.DateCreated)
} | go | func (vr *VoiceResponse) DateCreatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.DateCreated)
} | [
"func",
"(",
"vr",
"*",
"VoiceResponse",
")",
"DateCreatedAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"vr",
".",
"DateCreated",
")",
"\n",
"}"
] | // DateCreatedAsTime returns VoiceResponse.DateCreated as a time.Time object
// instead of a string. | [
"DateCreatedAsTime",
"returns",
"VoiceResponse",
".",
"DateCreated",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L65-L67 |
151,358 | sfreiberg/gotwilio | voice.go | DateUpdatedAsTime | func (vr *VoiceResponse) DateUpdatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.DateUpdated)
} | go | func (vr *VoiceResponse) DateUpdatedAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.DateUpdated)
} | [
"func",
"(",
"vr",
"*",
"VoiceResponse",
")",
"DateUpdatedAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"vr",
".",
"DateUpdated",
")",
"\n",
"}"
] | // DateUpdatedAsTime returns VoiceResponse.DateUpdated as a time.Time object
// instead of a string. | [
"DateUpdatedAsTime",
"returns",
"VoiceResponse",
".",
"DateUpdated",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L71-L73 |
151,359 | sfreiberg/gotwilio | voice.go | StartTimeAsTime | func (vr *VoiceResponse) StartTimeAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.StartTime)
} | go | func (vr *VoiceResponse) StartTimeAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.StartTime)
} | [
"func",
"(",
"vr",
"*",
"VoiceResponse",
")",
"StartTimeAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"vr",
".",
"StartTime",
")",
"\n",
"}"
] | // StartTimeAsTime returns VoiceResponse.StartTime as a time.Time object
// instead of a string. | [
"StartTimeAsTime",
"returns",
"VoiceResponse",
".",
"StartTime",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L77-L79 |
151,360 | sfreiberg/gotwilio | voice.go | EndTimeAsTime | func (vr *VoiceResponse) EndTimeAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.EndTime)
} | go | func (vr *VoiceResponse) EndTimeAsTime() (time.Time, error) {
return time.Parse(time.RFC1123Z, vr.EndTime)
} | [
"func",
"(",
"vr",
"*",
"VoiceResponse",
")",
"EndTimeAsTime",
"(",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"return",
"time",
".",
"Parse",
"(",
"time",
".",
"RFC1123Z",
",",
"vr",
".",
"EndTime",
")",
"\n",
"}"
] | // EndTimeAsTime returns VoiceResponse.EndTime as a time.Time object
// instead of a string. | [
"EndTimeAsTime",
"returns",
"VoiceResponse",
".",
"EndTime",
"as",
"a",
"time",
".",
"Time",
"object",
"instead",
"of",
"a",
"string",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L83-L85 |
151,361 | sfreiberg/gotwilio | voice.go | CallWithUrlCallbacks | func (twilio *Twilio) CallWithUrlCallbacks(from, to string, callbackParameters *CallbackParameters) (*VoiceResponse, *Exception, error) {
formValues := url.Values{}
formValues.Set("From", from)
formValues.Set("To", to)
formValues.Set("Url", callbackParameters.Url)
// Optional values
if callbackParameters.Method != "" {
formValues.Set("Method", callbackParameters.Method)
}
if callbackParameters.FallbackUrl != "" {
formValues.Set("FallbackUrl", callbackParameters.FallbackUrl)
}
if callbackParameters.FallbackMethod != "" {
formValues.Set("FallbackMethod", callbackParameters.FallbackMethod)
}
if callbackParameters.StatusCallback != "" {
formValues.Set("StatusCallback", callbackParameters.StatusCallback)
}
if callbackParameters.StatusCallbackMethod != "" {
formValues.Set("StatusCallbackMethod", callbackParameters.StatusCallbackMethod)
}
for _, event := range callbackParameters.StatusCallbackEvent {
formValues.Add("StatusCallbackEvent", event)
}
if callbackParameters.SendDigits != "" {
formValues.Set("SendDigits", callbackParameters.SendDigits)
}
if callbackParameters.IfMachine != "" {
formValues.Set("IfMachine", callbackParameters.IfMachine)
}
if callbackParameters.Timeout != 0 {
formValues.Set("Timeout", strconv.Itoa(callbackParameters.Timeout))
}
if callbackParameters.MachineDetection != "" {
formValues.Set("MachineDetection", callbackParameters.MachineDetection)
}
if callbackParameters.MachineDetectionTimeout != 0 {
formValues.Set(
"MachineDetectionTimeout",
strconv.Itoa(callbackParameters.MachineDetectionTimeout),
)
}
if callbackParameters.Record {
formValues.Set("Record", "true")
if callbackParameters.RecordingChannels != "" {
formValues.Set("RecordingChannels", callbackParameters.RecordingChannels)
}
if callbackParameters.RecordingStatusCallback != "" {
formValues.Set("RecordingStatusCallback", callbackParameters.RecordingStatusCallback)
}
if callbackParameters.RecordingStatusCallbackMethod != "" {
formValues.Set("RecordingStatusCallbackMethod", callbackParameters.RecordingStatusCallbackMethod)
}
} else {
formValues.Set("Record", "false")
}
return twilio.voicePost(formValues)
} | go | func (twilio *Twilio) CallWithUrlCallbacks(from, to string, callbackParameters *CallbackParameters) (*VoiceResponse, *Exception, error) {
formValues := url.Values{}
formValues.Set("From", from)
formValues.Set("To", to)
formValues.Set("Url", callbackParameters.Url)
// Optional values
if callbackParameters.Method != "" {
formValues.Set("Method", callbackParameters.Method)
}
if callbackParameters.FallbackUrl != "" {
formValues.Set("FallbackUrl", callbackParameters.FallbackUrl)
}
if callbackParameters.FallbackMethod != "" {
formValues.Set("FallbackMethod", callbackParameters.FallbackMethod)
}
if callbackParameters.StatusCallback != "" {
formValues.Set("StatusCallback", callbackParameters.StatusCallback)
}
if callbackParameters.StatusCallbackMethod != "" {
formValues.Set("StatusCallbackMethod", callbackParameters.StatusCallbackMethod)
}
for _, event := range callbackParameters.StatusCallbackEvent {
formValues.Add("StatusCallbackEvent", event)
}
if callbackParameters.SendDigits != "" {
formValues.Set("SendDigits", callbackParameters.SendDigits)
}
if callbackParameters.IfMachine != "" {
formValues.Set("IfMachine", callbackParameters.IfMachine)
}
if callbackParameters.Timeout != 0 {
formValues.Set("Timeout", strconv.Itoa(callbackParameters.Timeout))
}
if callbackParameters.MachineDetection != "" {
formValues.Set("MachineDetection", callbackParameters.MachineDetection)
}
if callbackParameters.MachineDetectionTimeout != 0 {
formValues.Set(
"MachineDetectionTimeout",
strconv.Itoa(callbackParameters.MachineDetectionTimeout),
)
}
if callbackParameters.Record {
formValues.Set("Record", "true")
if callbackParameters.RecordingChannels != "" {
formValues.Set("RecordingChannels", callbackParameters.RecordingChannels)
}
if callbackParameters.RecordingStatusCallback != "" {
formValues.Set("RecordingStatusCallback", callbackParameters.RecordingStatusCallback)
}
if callbackParameters.RecordingStatusCallbackMethod != "" {
formValues.Set("RecordingStatusCallbackMethod", callbackParameters.RecordingStatusCallbackMethod)
}
} else {
formValues.Set("Record", "false")
}
return twilio.voicePost(formValues)
} | [
"func",
"(",
"twilio",
"*",
"Twilio",
")",
"CallWithUrlCallbacks",
"(",
"from",
",",
"to",
"string",
",",
"callbackParameters",
"*",
"CallbackParameters",
")",
"(",
"*",
"VoiceResponse",
",",
"*",
"Exception",
",",
"error",
")",
"{",
"formValues",
":=",
"url... | // Place a voice call with a list of callbacks specified. | [
"Place",
"a",
"voice",
"call",
"with",
"a",
"list",
"of",
"callbacks",
"specified",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L122-L183 |
151,362 | sfreiberg/gotwilio | voice.go | CallWithApplicationCallbacks | func (twilio *Twilio) CallWithApplicationCallbacks(from, to, applicationSid string) (*VoiceResponse, *Exception, error) {
formValues := url.Values{}
formValues.Set("From", from)
formValues.Set("To", to)
formValues.Set("ApplicationSid", applicationSid)
return twilio.voicePost(formValues)
} | go | func (twilio *Twilio) CallWithApplicationCallbacks(from, to, applicationSid string) (*VoiceResponse, *Exception, error) {
formValues := url.Values{}
formValues.Set("From", from)
formValues.Set("To", to)
formValues.Set("ApplicationSid", applicationSid)
return twilio.voicePost(formValues)
} | [
"func",
"(",
"twilio",
"*",
"Twilio",
")",
"CallWithApplicationCallbacks",
"(",
"from",
",",
"to",
",",
"applicationSid",
"string",
")",
"(",
"*",
"VoiceResponse",
",",
"*",
"Exception",
",",
"error",
")",
"{",
"formValues",
":=",
"url",
".",
"Values",
"{"... | // Place a voice call with an ApplicationSid specified. | [
"Place",
"a",
"voice",
"call",
"with",
"an",
"ApplicationSid",
"specified",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L186-L193 |
151,363 | sfreiberg/gotwilio | voice.go | voicePost | func (twilio *Twilio) voicePost(formValues url.Values) (*VoiceResponse, *Exception, error) {
var voiceResponse *VoiceResponse
var exception *Exception
twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Calls.json"
res, err := twilio.post(formValues, twilioUrl)
if err != nil {
return voiceResponse, exception, err
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
if res.StatusCode != http.StatusCreated {
exception = new(Exception)
err = decoder.Decode(exception)
// We aren't checking the error because we don't actually care.
// It's going to be passed to the client either way.
return voiceResponse, exception, err
}
voiceResponse = new(VoiceResponse)
err = decoder.Decode(voiceResponse)
return voiceResponse, exception, err
} | go | func (twilio *Twilio) voicePost(formValues url.Values) (*VoiceResponse, *Exception, error) {
var voiceResponse *VoiceResponse
var exception *Exception
twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Calls.json"
res, err := twilio.post(formValues, twilioUrl)
if err != nil {
return voiceResponse, exception, err
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
if res.StatusCode != http.StatusCreated {
exception = new(Exception)
err = decoder.Decode(exception)
// We aren't checking the error because we don't actually care.
// It's going to be passed to the client either way.
return voiceResponse, exception, err
}
voiceResponse = new(VoiceResponse)
err = decoder.Decode(voiceResponse)
return voiceResponse, exception, err
} | [
"func",
"(",
"twilio",
"*",
"Twilio",
")",
"voicePost",
"(",
"formValues",
"url",
".",
"Values",
")",
"(",
"*",
"VoiceResponse",
",",
"*",
"Exception",
",",
"error",
")",
"{",
"var",
"voiceResponse",
"*",
"VoiceResponse",
"\n",
"var",
"exception",
"*",
"... | // This is a private method that has the common bits for making a voice call. | [
"This",
"is",
"a",
"private",
"method",
"that",
"has",
"the",
"common",
"bits",
"for",
"making",
"a",
"voice",
"call",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L196-L221 |
151,364 | sfreiberg/gotwilio | util.go | CheckRequestSignature | func (twilio *Twilio) CheckRequestSignature(r *http.Request, baseURL string) (bool, error) {
if r.Method != "POST" {
return false, errors.New("Checking signatures on non-POST requests is not implemented")
}
if err := r.ParseForm(); err != nil {
return false, err
}
url := baseURL + r.URL.String()
expected, err := twilio.GenerateSignature(url, r.PostForm)
if err != nil {
return false, err
}
actual := r.Header.Get("X-Twilio-Signature")
if actual == "" {
return false, errors.New("Request does not have a twilio signature header")
}
return hmac.Equal(expected, []byte(actual)), nil
} | go | func (twilio *Twilio) CheckRequestSignature(r *http.Request, baseURL string) (bool, error) {
if r.Method != "POST" {
return false, errors.New("Checking signatures on non-POST requests is not implemented")
}
if err := r.ParseForm(); err != nil {
return false, err
}
url := baseURL + r.URL.String()
expected, err := twilio.GenerateSignature(url, r.PostForm)
if err != nil {
return false, err
}
actual := r.Header.Get("X-Twilio-Signature")
if actual == "" {
return false, errors.New("Request does not have a twilio signature header")
}
return hmac.Equal(expected, []byte(actual)), nil
} | [
"func",
"(",
"twilio",
"*",
"Twilio",
")",
"CheckRequestSignature",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"baseURL",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"r",
".",
"Method",
"!=",
"\"",
"\"",
"{",
"return",
"false",
",",
... | // CheckRequestSignature checks that the X-Twilio-Signature header on a request
// matches the expected signature defined by the GenerateSignature function.
//
// The baseUrl parameter will be prepended to the request URL. It is useful for
// specifying the protocol and host parts of the server URL hosting your endpoint.
//
// Passing a non-POST request or a request without the X-Twilio-Signature
// header is an error. | [
"CheckRequestSignature",
"checks",
"that",
"the",
"X",
"-",
"Twilio",
"-",
"Signature",
"header",
"on",
"a",
"request",
"matches",
"the",
"expected",
"signature",
"defined",
"by",
"the",
"GenerateSignature",
"function",
".",
"The",
"baseUrl",
"parameter",
"will",
... | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/util.go#L62-L84 |
151,365 | sfreiberg/gotwilio | access_token.go | NewAccessToken | func (twilio *Twilio) NewAccessToken() *AccessToken {
return &AccessToken{
AccountSid: twilio.AccountSid,
APIKeySid: twilio.APIKeySid,
APIKeySecret: twilio.APIKeySecret,
}
} | go | func (twilio *Twilio) NewAccessToken() *AccessToken {
return &AccessToken{
AccountSid: twilio.AccountSid,
APIKeySid: twilio.APIKeySid,
APIKeySecret: twilio.APIKeySecret,
}
} | [
"func",
"(",
"twilio",
"*",
"Twilio",
")",
"NewAccessToken",
"(",
")",
"*",
"AccessToken",
"{",
"return",
"&",
"AccessToken",
"{",
"AccountSid",
":",
"twilio",
".",
"AccountSid",
",",
"APIKeySid",
":",
"twilio",
".",
"APIKeySid",
",",
"APIKeySecret",
":",
... | // NewAccessToken creates a new Access Token which
// can be used to authenticate Twilio Client SDKs
// for a short period of time. | [
"NewAccessToken",
"creates",
"a",
"new",
"Access",
"Token",
"which",
"can",
"be",
"used",
"to",
"authenticate",
"Twilio",
"Client",
"SDKs",
"for",
"a",
"short",
"period",
"of",
"time",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/access_token.go#L45-L51 |
151,366 | sfreiberg/gotwilio | access_token.go | AddGrant | func (a *AccessToken) AddGrant(grant Grant) *AccessToken {
a.Grants = append(a.Grants, grant)
return a
} | go | func (a *AccessToken) AddGrant(grant Grant) *AccessToken {
a.Grants = append(a.Grants, grant)
return a
} | [
"func",
"(",
"a",
"*",
"AccessToken",
")",
"AddGrant",
"(",
"grant",
"Grant",
")",
"*",
"AccessToken",
"{",
"a",
".",
"Grants",
"=",
"append",
"(",
"a",
".",
"Grants",
",",
"grant",
")",
"\n",
"return",
"a",
"\n",
"}"
] | // AddGrant adds a given Grant to the Access Token. | [
"AddGrant",
"adds",
"a",
"given",
"Grant",
"to",
"the",
"Access",
"Token",
"."
] | 4c78e78c98b65cf3b9ab4edbe635d4080c6db6da | https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/access_token.go#L54-L57 |
151,367 | kr/pty | run.go | Start | func Start(c *exec.Cmd) (pty *os.File, err error) {
return StartWithSize(c, nil)
} | go | func Start(c *exec.Cmd) (pty *os.File, err error) {
return StartWithSize(c, nil)
} | [
"func",
"Start",
"(",
"c",
"*",
"exec",
".",
"Cmd",
")",
"(",
"pty",
"*",
"os",
".",
"File",
",",
"err",
"error",
")",
"{",
"return",
"StartWithSize",
"(",
"c",
",",
"nil",
")",
"\n",
"}"
] | // Start assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout,
// and c.Stderr, calls c.Start, and returns the File of the tty's
// corresponding pty. | [
"Start",
"assigns",
"a",
"pseudo",
"-",
"terminal",
"tty",
"os",
".",
"File",
"to",
"c",
".",
"Stdin",
"c",
".",
"Stdout",
"and",
"c",
".",
"Stderr",
"calls",
"c",
".",
"Start",
"and",
"returns",
"the",
"File",
"of",
"the",
"tty",
"s",
"corresponding... | b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17 | https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/run.go#L14-L16 |
151,368 | kr/pty | run.go | StartWithSize | func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) {
pty, tty, err := Open()
if err != nil {
return nil, err
}
defer tty.Close()
if sz != nil {
err = Setsize(pty, sz)
if err != nil {
pty.Close()
return nil, err
}
}
if c.Stdout == nil {
c.Stdout = tty
}
if c.Stderr == nil {
c.Stderr = tty
}
if c.Stdin == nil {
c.Stdin = tty
}
if c.SysProcAttr == nil {
c.SysProcAttr = &syscall.SysProcAttr{}
}
c.SysProcAttr.Setctty = true
c.SysProcAttr.Setsid = true
c.SysProcAttr.Ctty = int(tty.Fd())
err = c.Start()
if err != nil {
pty.Close()
return nil, err
}
return pty, err
} | go | func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) {
pty, tty, err := Open()
if err != nil {
return nil, err
}
defer tty.Close()
if sz != nil {
err = Setsize(pty, sz)
if err != nil {
pty.Close()
return nil, err
}
}
if c.Stdout == nil {
c.Stdout = tty
}
if c.Stderr == nil {
c.Stderr = tty
}
if c.Stdin == nil {
c.Stdin = tty
}
if c.SysProcAttr == nil {
c.SysProcAttr = &syscall.SysProcAttr{}
}
c.SysProcAttr.Setctty = true
c.SysProcAttr.Setsid = true
c.SysProcAttr.Ctty = int(tty.Fd())
err = c.Start()
if err != nil {
pty.Close()
return nil, err
}
return pty, err
} | [
"func",
"StartWithSize",
"(",
"c",
"*",
"exec",
".",
"Cmd",
",",
"sz",
"*",
"Winsize",
")",
"(",
"pty",
"*",
"os",
".",
"File",
",",
"err",
"error",
")",
"{",
"pty",
",",
"tty",
",",
"err",
":=",
"Open",
"(",
")",
"\n",
"if",
"err",
"!=",
"ni... | // StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout,
// and c.Stderr, calls c.Start, and returns the File of the tty's
// corresponding pty.
//
// This will resize the pty to the specified size before starting the command | [
"StartWithSize",
"assigns",
"a",
"pseudo",
"-",
"terminal",
"tty",
"os",
".",
"File",
"to",
"c",
".",
"Stdin",
"c",
".",
"Stdout",
"and",
"c",
".",
"Stderr",
"calls",
"c",
".",
"Start",
"and",
"returns",
"the",
"File",
"of",
"the",
"tty",
"s",
"corre... | b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17 | https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/run.go#L23-L57 |
151,369 | kr/pty | pty_dragonfly.go | open | func open() (pty, tty *os.File, err error) {
p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
// In case of error after this point, make sure we close the ptmx fd.
defer func() {
if err != nil {
_ = p.Close() // Best effort.
}
}()
sname, err := ptsname(p)
if err != nil {
return nil, nil, err
}
if err := grantpt(p); err != nil {
return nil, nil, err
}
if err := unlockpt(p); err != nil {
return nil, nil, err
}
t, err := os.OpenFile(sname, os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
return p, t, nil
} | go | func open() (pty, tty *os.File, err error) {
p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
// In case of error after this point, make sure we close the ptmx fd.
defer func() {
if err != nil {
_ = p.Close() // Best effort.
}
}()
sname, err := ptsname(p)
if err != nil {
return nil, nil, err
}
if err := grantpt(p); err != nil {
return nil, nil, err
}
if err := unlockpt(p); err != nil {
return nil, nil, err
}
t, err := os.OpenFile(sname, os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
return p, t, nil
} | [
"func",
"open",
"(",
")",
"(",
"pty",
",",
"tty",
"*",
"os",
".",
"File",
",",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"\"",
"\"",
",",
"os",
".",
"O_RDWR",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",... | // same code as pty_darwin.go | [
"same",
"code",
"as",
"pty_darwin",
".",
"go"
] | b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17 | https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/pty_dragonfly.go#L12-L42 |
151,370 | kr/pty | util.go | InheritSize | func InheritSize(pty, tty *os.File) error {
size, err := GetsizeFull(pty)
if err != nil {
return err
}
err = Setsize(tty, size)
if err != nil {
return err
}
return nil
} | go | func InheritSize(pty, tty *os.File) error {
size, err := GetsizeFull(pty)
if err != nil {
return err
}
err = Setsize(tty, size)
if err != nil {
return err
}
return nil
} | [
"func",
"InheritSize",
"(",
"pty",
",",
"tty",
"*",
"os",
".",
"File",
")",
"error",
"{",
"size",
",",
"err",
":=",
"GetsizeFull",
"(",
"pty",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"Setsize",
"(",... | // InheritSize applies the terminal size of pty to tty. This should be run
// in a signal handler for syscall.SIGWINCH to automatically resize the tty when
// the pty receives a window size change notification. | [
"InheritSize",
"applies",
"the",
"terminal",
"size",
"of",
"pty",
"to",
"tty",
".",
"This",
"should",
"be",
"run",
"in",
"a",
"signal",
"handler",
"for",
"syscall",
".",
"SIGWINCH",
"to",
"automatically",
"resize",
"the",
"tty",
"when",
"the",
"pty",
"rece... | b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17 | https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/util.go#L14-L24 |
151,371 | kr/pty | util.go | Setsize | func Setsize(t *os.File, ws *Winsize) error {
return windowRectCall(ws, t.Fd(), syscall.TIOCSWINSZ)
} | go | func Setsize(t *os.File, ws *Winsize) error {
return windowRectCall(ws, t.Fd(), syscall.TIOCSWINSZ)
} | [
"func",
"Setsize",
"(",
"t",
"*",
"os",
".",
"File",
",",
"ws",
"*",
"Winsize",
")",
"error",
"{",
"return",
"windowRectCall",
"(",
"ws",
",",
"t",
".",
"Fd",
"(",
")",
",",
"syscall",
".",
"TIOCSWINSZ",
")",
"\n",
"}"
] | // Setsize resizes t to s. | [
"Setsize",
"resizes",
"t",
"to",
"s",
"."
] | b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17 | https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/util.go#L27-L29 |
151,372 | kr/pty | util.go | GetsizeFull | func GetsizeFull(t *os.File) (size *Winsize, err error) {
var ws Winsize
err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ)
return &ws, err
} | go | func GetsizeFull(t *os.File) (size *Winsize, err error) {
var ws Winsize
err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ)
return &ws, err
} | [
"func",
"GetsizeFull",
"(",
"t",
"*",
"os",
".",
"File",
")",
"(",
"size",
"*",
"Winsize",
",",
"err",
"error",
")",
"{",
"var",
"ws",
"Winsize",
"\n",
"err",
"=",
"windowRectCall",
"(",
"&",
"ws",
",",
"t",
".",
"Fd",
"(",
")",
",",
"syscall",
... | // GetsizeFull returns the full terminal size description. | [
"GetsizeFull",
"returns",
"the",
"full",
"terminal",
"size",
"description",
"."
] | b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17 | https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/util.go#L32-L36 |
151,373 | justinas/nosurf | handler.go | extractToken | func extractToken(r *http.Request) []byte {
// Prefer the header over form value
sentToken := r.Header.Get(HeaderName)
// Then POST values
if len(sentToken) == 0 {
sentToken = r.PostFormValue(FormFieldName)
}
// If all else fails, try a multipart value.
// PostFormValue() will already have called ParseMultipartForm()
if len(sentToken) == 0 && r.MultipartForm != nil {
vals := r.MultipartForm.Value[FormFieldName]
if len(vals) != 0 {
sentToken = vals[0]
}
}
return b64decode(sentToken)
} | go | func extractToken(r *http.Request) []byte {
// Prefer the header over form value
sentToken := r.Header.Get(HeaderName)
// Then POST values
if len(sentToken) == 0 {
sentToken = r.PostFormValue(FormFieldName)
}
// If all else fails, try a multipart value.
// PostFormValue() will already have called ParseMultipartForm()
if len(sentToken) == 0 && r.MultipartForm != nil {
vals := r.MultipartForm.Value[FormFieldName]
if len(vals) != 0 {
sentToken = vals[0]
}
}
return b64decode(sentToken)
} | [
"func",
"extractToken",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"[",
"]",
"byte",
"{",
"// Prefer the header over form value",
"sentToken",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"HeaderName",
")",
"\n\n",
"// Then POST values",
"if",
"len",
"(",
"se... | // Extracts the "sent" token from the request
// and returns an unmasked version of it | [
"Extracts",
"the",
"sent",
"token",
"from",
"the",
"request",
"and",
"returns",
"an",
"unmasked",
"version",
"of",
"it"
] | 05988550ea1890c49b702363e53b3afa7aad2b4b | https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/handler.go#L68-L87 |
151,374 | justinas/nosurf | handler.go | New | func New(handler http.Handler) *CSRFHandler {
baseCookie := http.Cookie{}
baseCookie.MaxAge = MaxAge
csrf := &CSRFHandler{successHandler: handler,
failureHandler: http.HandlerFunc(defaultFailureHandler),
baseCookie: baseCookie,
}
return csrf
} | go | func New(handler http.Handler) *CSRFHandler {
baseCookie := http.Cookie{}
baseCookie.MaxAge = MaxAge
csrf := &CSRFHandler{successHandler: handler,
failureHandler: http.HandlerFunc(defaultFailureHandler),
baseCookie: baseCookie,
}
return csrf
} | [
"func",
"New",
"(",
"handler",
"http",
".",
"Handler",
")",
"*",
"CSRFHandler",
"{",
"baseCookie",
":=",
"http",
".",
"Cookie",
"{",
"}",
"\n",
"baseCookie",
".",
"MaxAge",
"=",
"MaxAge",
"\n\n",
"csrf",
":=",
"&",
"CSRFHandler",
"{",
"successHandler",
"... | // Constructs a new CSRFHandler that calls
// the specified handler if the CSRF check succeeds. | [
"Constructs",
"a",
"new",
"CSRFHandler",
"that",
"calls",
"the",
"specified",
"handler",
"if",
"the",
"CSRF",
"check",
"succeeds",
"."
] | 05988550ea1890c49b702363e53b3afa7aad2b4b | https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/handler.go#L91-L101 |
151,375 | justinas/nosurf | handler.go | RegenerateToken | func (h *CSRFHandler) RegenerateToken(w http.ResponseWriter, r *http.Request) string {
token := generateToken()
h.setTokenCookie(w, r, token)
return Token(r)
} | go | func (h *CSRFHandler) RegenerateToken(w http.ResponseWriter, r *http.Request) string {
token := generateToken()
h.setTokenCookie(w, r, token)
return Token(r)
} | [
"func",
"(",
"h",
"*",
"CSRFHandler",
")",
"RegenerateToken",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"token",
":=",
"generateToken",
"(",
")",
"\n",
"h",
".",
"setTokenCookie",
"(",
"w",
",",... | // Generates a new token, sets it on the given request and returns it | [
"Generates",
"a",
"new",
"token",
"sets",
"it",
"on",
"the",
"given",
"request",
"and",
"returns",
"it"
] | 05988550ea1890c49b702363e53b3afa7aad2b4b | https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/handler.go#L197-L202 |
151,376 | justinas/nosurf | context_legacy.go | ctxSetToken | func ctxSetToken(req *http.Request, token []byte) *http.Request {
cmMutex.Lock()
defer cmMutex.Unlock()
ctx, ok := contextMap[req]
if !ok {
ctx = new(csrfContext)
contextMap[req] = ctx
}
ctx.token = b64encode(maskToken(token))
return req
} | go | func ctxSetToken(req *http.Request, token []byte) *http.Request {
cmMutex.Lock()
defer cmMutex.Unlock()
ctx, ok := contextMap[req]
if !ok {
ctx = new(csrfContext)
contextMap[req] = ctx
}
ctx.token = b64encode(maskToken(token))
return req
} | [
"func",
"ctxSetToken",
"(",
"req",
"*",
"http",
".",
"Request",
",",
"token",
"[",
"]",
"byte",
")",
"*",
"http",
".",
"Request",
"{",
"cmMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cmMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"ctx",
",",
"ok",
... | // Takes a raw token, masks it with a per-request key,
// encodes in base64 and makes it available to the wrapped handler | [
"Takes",
"a",
"raw",
"token",
"masks",
"it",
"with",
"a",
"per",
"-",
"request",
"key",
"encodes",
"in",
"base64",
"and",
"makes",
"it",
"available",
"to",
"the",
"wrapped",
"handler"
] | 05988550ea1890c49b702363e53b3afa7aad2b4b | https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/context_legacy.go#L67-L80 |
151,377 | justinas/nosurf | token.go | verifyMasked | func verifyMasked(realToken, sentToken []byte) bool {
sentPlain := unmaskToken(sentToken)
return subtle.ConstantTimeCompare(realToken, sentPlain) == 1
} | go | func verifyMasked(realToken, sentToken []byte) bool {
sentPlain := unmaskToken(sentToken)
return subtle.ConstantTimeCompare(realToken, sentPlain) == 1
} | [
"func",
"verifyMasked",
"(",
"realToken",
",",
"sentToken",
"[",
"]",
"byte",
")",
"bool",
"{",
"sentPlain",
":=",
"unmaskToken",
"(",
"sentToken",
")",
"\n",
"return",
"subtle",
".",
"ConstantTimeCompare",
"(",
"realToken",
",",
"sentPlain",
")",
"==",
"1",... | // Verifies the masked token | [
"Verifies",
"the",
"masked",
"token"
] | 05988550ea1890c49b702363e53b3afa7aad2b4b | https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/token.go#L86-L89 |
151,378 | justinas/nosurf | exempt.go | IsExempt | func (h *CSRFHandler) IsExempt(r *http.Request) bool {
if h.exemptFunc != nil && h.exemptFunc(r) {
return true
}
path := r.URL.Path
if sContains(h.exemptPaths, path) {
return true
}
// then the globs
for _, glob := range h.exemptGlobs {
matched, err := pathModule.Match(glob, path)
if matched && err == nil {
return true
}
}
// finally, the regexps
for _, re := range h.exemptRegexps {
if re.MatchString(path) {
return true
}
}
return false
} | go | func (h *CSRFHandler) IsExempt(r *http.Request) bool {
if h.exemptFunc != nil && h.exemptFunc(r) {
return true
}
path := r.URL.Path
if sContains(h.exemptPaths, path) {
return true
}
// then the globs
for _, glob := range h.exemptGlobs {
matched, err := pathModule.Match(glob, path)
if matched && err == nil {
return true
}
}
// finally, the regexps
for _, re := range h.exemptRegexps {
if re.MatchString(path) {
return true
}
}
return false
} | [
"func",
"(",
"h",
"*",
"CSRFHandler",
")",
"IsExempt",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"if",
"h",
".",
"exemptFunc",
"!=",
"nil",
"&&",
"h",
".",
"exemptFunc",
"(",
"r",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"pat... | // Checks if the given request is exempt from CSRF checks.
// It checks the ExemptFunc first, then the exact paths,
// then the globs and finally the regexps. | [
"Checks",
"if",
"the",
"given",
"request",
"is",
"exempt",
"from",
"CSRF",
"checks",
".",
"It",
"checks",
"the",
"ExemptFunc",
"first",
"then",
"the",
"exact",
"paths",
"then",
"the",
"globs",
"and",
"finally",
"the",
"regexps",
"."
] | 05988550ea1890c49b702363e53b3afa7aad2b4b | https://github.com/justinas/nosurf/blob/05988550ea1890c49b702363e53b3afa7aad2b4b/exempt.go#L14-L40 |
151,379 | prometheus/haproxy_exporter | haproxy_exporter.go | NewExporter | func NewExporter(uri string, sslVerify bool, selectedServerMetrics map[int]*prometheus.Desc, timeout time.Duration) (*Exporter, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, err
}
var fetch func() (io.ReadCloser, error)
switch u.Scheme {
case "http", "https", "file":
fetch = fetchHTTP(uri, sslVerify, timeout)
case "unix":
fetch = fetchUnix(u, timeout)
default:
return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme)
}
return &Exporter{
URI: uri,
fetch: fetch,
up: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "up",
Help: "Was the last scrape of haproxy successful.",
}),
totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "exporter_total_scrapes",
Help: "Current total HAProxy scrapes.",
}),
csvParseFailures: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "exporter_csv_parse_failures",
Help: "Number of errors while parsing CSV.",
}),
serverMetrics: selectedServerMetrics,
}, nil
} | go | func NewExporter(uri string, sslVerify bool, selectedServerMetrics map[int]*prometheus.Desc, timeout time.Duration) (*Exporter, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, err
}
var fetch func() (io.ReadCloser, error)
switch u.Scheme {
case "http", "https", "file":
fetch = fetchHTTP(uri, sslVerify, timeout)
case "unix":
fetch = fetchUnix(u, timeout)
default:
return nil, fmt.Errorf("unsupported scheme: %q", u.Scheme)
}
return &Exporter{
URI: uri,
fetch: fetch,
up: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "up",
Help: "Was the last scrape of haproxy successful.",
}),
totalScrapes: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "exporter_total_scrapes",
Help: "Current total HAProxy scrapes.",
}),
csvParseFailures: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "exporter_csv_parse_failures",
Help: "Number of errors while parsing CSV.",
}),
serverMetrics: selectedServerMetrics,
}, nil
} | [
"func",
"NewExporter",
"(",
"uri",
"string",
",",
"sslVerify",
"bool",
",",
"selectedServerMetrics",
"map",
"[",
"int",
"]",
"*",
"prometheus",
".",
"Desc",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Exporter",
",",
"error",
")",
"{",
"u",
... | // NewExporter returns an initialized Exporter. | [
"NewExporter",
"returns",
"an",
"initialized",
"Exporter",
"."
] | f9813cf8bc6d469e80f7e6007a66c095b45616ed | https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L188-L224 |
151,380 | prometheus/haproxy_exporter | haproxy_exporter.go | Describe | func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
for _, m := range frontendMetrics {
ch <- m
}
for _, m := range backendMetrics {
ch <- m
}
for _, m := range e.serverMetrics {
ch <- m
}
ch <- haproxyUp
ch <- e.totalScrapes.Desc()
ch <- e.csvParseFailures.Desc()
} | go | func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
for _, m := range frontendMetrics {
ch <- m
}
for _, m := range backendMetrics {
ch <- m
}
for _, m := range e.serverMetrics {
ch <- m
}
ch <- haproxyUp
ch <- e.totalScrapes.Desc()
ch <- e.csvParseFailures.Desc()
} | [
"func",
"(",
"e",
"*",
"Exporter",
")",
"Describe",
"(",
"ch",
"chan",
"<-",
"*",
"prometheus",
".",
"Desc",
")",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"frontendMetrics",
"{",
"ch",
"<-",
"m",
"\n",
"}",
"\n",
"for",
"_",
",",
"m",
":=",
"r... | // Describe describes all the metrics ever exported by the HAProxy exporter. It
// implements prometheus.Collector. | [
"Describe",
"describes",
"all",
"the",
"metrics",
"ever",
"exported",
"by",
"the",
"HAProxy",
"exporter",
".",
"It",
"implements",
"prometheus",
".",
"Collector",
"."
] | f9813cf8bc6d469e80f7e6007a66c095b45616ed | https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L228-L241 |
151,381 | prometheus/haproxy_exporter | haproxy_exporter.go | Collect | func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.mutex.Lock() // To protect metrics from concurrent collects.
defer e.mutex.Unlock()
up := e.scrape(ch)
ch <- prometheus.MustNewConstMetric(haproxyUp, prometheus.GaugeValue, up)
ch <- e.totalScrapes
ch <- e.csvParseFailures
} | go | func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.mutex.Lock() // To protect metrics from concurrent collects.
defer e.mutex.Unlock()
up := e.scrape(ch)
ch <- prometheus.MustNewConstMetric(haproxyUp, prometheus.GaugeValue, up)
ch <- e.totalScrapes
ch <- e.csvParseFailures
} | [
"func",
"(",
"e",
"*",
"Exporter",
")",
"Collect",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"{",
"e",
".",
"mutex",
".",
"Lock",
"(",
")",
"// To protect metrics from concurrent collects.",
"\n",
"defer",
"e",
".",
"mutex",
".",
"Unlock",... | // Collect fetches the stats from configured HAProxy location and delivers them
// as Prometheus metrics. It implements prometheus.Collector. | [
"Collect",
"fetches",
"the",
"stats",
"from",
"configured",
"HAProxy",
"location",
"and",
"delivers",
"them",
"as",
"Prometheus",
"metrics",
".",
"It",
"implements",
"prometheus",
".",
"Collector",
"."
] | f9813cf8bc6d469e80f7e6007a66c095b45616ed | https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L245-L254 |
151,382 | prometheus/haproxy_exporter | haproxy_exporter.go | filterServerMetrics | func filterServerMetrics(filter string) (map[int]*prometheus.Desc, error) {
metrics := map[int]*prometheus.Desc{}
if len(filter) == 0 {
return metrics, nil
}
selected := map[int]struct{}{}
for _, f := range strings.Split(filter, ",") {
field, err := strconv.Atoi(f)
if err != nil {
return nil, fmt.Errorf("invalid server metric field number: %v", f)
}
selected[field] = struct{}{}
}
for field, metric := range serverMetrics {
if _, ok := selected[field]; ok {
metrics[field] = metric
}
}
return metrics, nil
} | go | func filterServerMetrics(filter string) (map[int]*prometheus.Desc, error) {
metrics := map[int]*prometheus.Desc{}
if len(filter) == 0 {
return metrics, nil
}
selected := map[int]struct{}{}
for _, f := range strings.Split(filter, ",") {
field, err := strconv.Atoi(f)
if err != nil {
return nil, fmt.Errorf("invalid server metric field number: %v", f)
}
selected[field] = struct{}{}
}
for field, metric := range serverMetrics {
if _, ok := selected[field]; ok {
metrics[field] = metric
}
}
return metrics, nil
} | [
"func",
"filterServerMetrics",
"(",
"filter",
"string",
")",
"(",
"map",
"[",
"int",
"]",
"*",
"prometheus",
".",
"Desc",
",",
"error",
")",
"{",
"metrics",
":=",
"map",
"[",
"int",
"]",
"*",
"prometheus",
".",
"Desc",
"{",
"}",
"\n",
"if",
"len",
... | // filterServerMetrics returns the set of server metrics specified by the comma
// separated filter. | [
"filterServerMetrics",
"returns",
"the",
"set",
"of",
"server",
"metrics",
"specified",
"by",
"the",
"comma",
"separated",
"filter",
"."
] | f9813cf8bc6d469e80f7e6007a66c095b45616ed | https://github.com/prometheus/haproxy_exporter/blob/f9813cf8bc6d469e80f7e6007a66c095b45616ed/haproxy_exporter.go#L407-L428 |
151,383 | go-chat-bot/bot | rocket/rocket.go | Run | func Run(c *Config) {
config = c
client = rest.NewClient(config.Server, config.Port, config.UseTLS, config.Debug)
err := client.Login(api.UserCredentials{Email: config.Email, Name: config.User, Password: config.Password})
if err != nil {
log.Fatalf("login err: %s\n", err)
}
b := bot.New(&bot.Handlers{
Response: responseHandler,
},
&bot.Config{
Protocol: protocol,
Server: config.Server,
},
)
b.Disable([]string{"url"})
msgChan := client.GetAllMessages()
for {
select {
case msgs := <-msgChan:
for _, msg := range msgs {
if !ownMessage(c, msg) {
b.MessageReceived(
&bot.ChannelData{
Protocol: protocol,
Server: "",
Channel: msg.ChannelId,
IsPrivate: false,
},
&bot.Message{Text: msg.Text},
&bot.User{ID: msg.User.Id, RealName: msg.User.UserName, Nick: msg.User.UserName, IsBot: false})
}
}
}
}
} | go | func Run(c *Config) {
config = c
client = rest.NewClient(config.Server, config.Port, config.UseTLS, config.Debug)
err := client.Login(api.UserCredentials{Email: config.Email, Name: config.User, Password: config.Password})
if err != nil {
log.Fatalf("login err: %s\n", err)
}
b := bot.New(&bot.Handlers{
Response: responseHandler,
},
&bot.Config{
Protocol: protocol,
Server: config.Server,
},
)
b.Disable([]string{"url"})
msgChan := client.GetAllMessages()
for {
select {
case msgs := <-msgChan:
for _, msg := range msgs {
if !ownMessage(c, msg) {
b.MessageReceived(
&bot.ChannelData{
Protocol: protocol,
Server: "",
Channel: msg.ChannelId,
IsPrivate: false,
},
&bot.Message{Text: msg.Text},
&bot.User{ID: msg.User.Id, RealName: msg.User.UserName, Nick: msg.User.UserName, IsBot: false})
}
}
}
}
} | [
"func",
"Run",
"(",
"c",
"*",
"Config",
")",
"{",
"config",
"=",
"c",
"\n",
"client",
"=",
"rest",
".",
"NewClient",
"(",
"config",
".",
"Server",
",",
"config",
".",
"Port",
",",
"config",
".",
"UseTLS",
",",
"config",
".",
"Debug",
")",
"\n",
"... | // Run reads the Config, connect to the specified rocket.chat server and starts the bot. | [
"Run",
"reads",
"the",
"Config",
"connect",
"to",
"the",
"specified",
"rocket",
".",
"chat",
"server",
"and",
"starts",
"the",
"bot",
"."
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/rocket/rocket.go#L52-L91 |
151,384 | go-chat-bot/bot | cmd.go | URI | func (c *ChannelData) URI() string {
return fmt.Sprintf("%s://%s/%s", c.Protocol, c.Server, c.Channel)
} | go | func (c *ChannelData) URI() string {
return fmt.Sprintf("%s://%s/%s", c.Protocol, c.Server, c.Channel)
} | [
"func",
"(",
"c",
"*",
"ChannelData",
")",
"URI",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Protocol",
",",
"c",
".",
"Server",
",",
"c",
".",
"Channel",
")",
"\n",
"}"
] | // URI gives back an URI-fied string containing protocol, server and channel. | [
"URI",
"gives",
"back",
"an",
"URI",
"-",
"fied",
"string",
"containing",
"protocol",
"server",
"and",
"channel",
"."
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L38-L40 |
151,385 | go-chat-bot/bot | cmd.go | RegisterCommandV2 | func RegisterCommandV2(command, description, exampleArgs string, cmdFunc activeCmdFuncV2) {
commands[command] = &customCommand{
Version: v2,
Cmd: command,
CmdFuncV2: cmdFunc,
Description: description,
ExampleArgs: exampleArgs,
}
} | go | func RegisterCommandV2(command, description, exampleArgs string, cmdFunc activeCmdFuncV2) {
commands[command] = &customCommand{
Version: v2,
Cmd: command,
CmdFuncV2: cmdFunc,
Description: description,
ExampleArgs: exampleArgs,
}
} | [
"func",
"RegisterCommandV2",
"(",
"command",
",",
"description",
",",
"exampleArgs",
"string",
",",
"cmdFunc",
"activeCmdFuncV2",
")",
"{",
"commands",
"[",
"command",
"]",
"=",
"&",
"customCommand",
"{",
"Version",
":",
"v2",
",",
"Cmd",
":",
"command",
","... | // RegisterCommandV2 adds a new command to the bot.
// It is the same as RegisterCommand but the command can specify the channel to reply to | [
"RegisterCommandV2",
"adds",
"a",
"new",
"command",
"to",
"the",
"bot",
".",
"It",
"is",
"the",
"same",
"as",
"RegisterCommand",
"but",
"the",
"command",
"can",
"specify",
"the",
"channel",
"to",
"reply",
"to"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L196-L204 |
151,386 | go-chat-bot/bot | cmd.go | RegisterCommandV3 | func RegisterCommandV3(command, description, exampleArgs string, cmdFunc activeCmdFuncV3) {
commands[command] = &customCommand{
Version: v3,
Cmd: command,
CmdFuncV3: cmdFunc,
Description: description,
ExampleArgs: exampleArgs,
}
} | go | func RegisterCommandV3(command, description, exampleArgs string, cmdFunc activeCmdFuncV3) {
commands[command] = &customCommand{
Version: v3,
Cmd: command,
CmdFuncV3: cmdFunc,
Description: description,
ExampleArgs: exampleArgs,
}
} | [
"func",
"RegisterCommandV3",
"(",
"command",
",",
"description",
",",
"exampleArgs",
"string",
",",
"cmdFunc",
"activeCmdFuncV3",
")",
"{",
"commands",
"[",
"command",
"]",
"=",
"&",
"customCommand",
"{",
"Version",
":",
"v3",
",",
"Cmd",
":",
"command",
","... | // RegisterCommandV3 adds a new command to the bot.
// It is the same as RegisterCommand but the command return a chan | [
"RegisterCommandV3",
"adds",
"a",
"new",
"command",
"to",
"the",
"bot",
".",
"It",
"is",
"the",
"same",
"as",
"RegisterCommand",
"but",
"the",
"command",
"return",
"a",
"chan"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L208-L216 |
151,387 | go-chat-bot/bot | cmd.go | Disable | func (b *Bot) Disable(cmds []string) {
b.disabledCmds = append(b.disabledCmds, cmds...)
} | go | func (b *Bot) Disable(cmds []string) {
b.disabledCmds = append(b.disabledCmds, cmds...)
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"Disable",
"(",
"cmds",
"[",
"]",
"string",
")",
"{",
"b",
".",
"disabledCmds",
"=",
"append",
"(",
"b",
".",
"disabledCmds",
",",
"cmds",
"...",
")",
"\n",
"}"
] | // Disable allows disabling commands that were registered.
// It is useful when running multiple bot instances to disabled some plugins like url which
// is already present on some protocols. | [
"Disable",
"allows",
"disabling",
"commands",
"that",
"were",
"registered",
".",
"It",
"is",
"useful",
"when",
"running",
"multiple",
"bot",
"instances",
"to",
"disabled",
"some",
"plugins",
"like",
"url",
"which",
"is",
"already",
"present",
"on",
"some",
"pr... | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/cmd.go#L296-L298 |
151,388 | go-chat-bot/bot | bot.go | New | func New(h *Handlers, bc *Config) *Bot {
if h.Errored == nil {
h.Errored = logErrorHandler
}
b := &Bot{
handlers: h,
cron: cron.New(),
msgsToSend: make(chan responseMessage, MsgBuffer),
done: make(chan struct{}),
Protocol: bc.Protocol,
Server: bc.Server,
}
// Launch the background goroutine that isolates the possibly non-threadsafe
// message sending logic of the underlying transport layer.
go b.processMessages()
b.startMessageStreams()
b.startPeriodicCommands()
return b
} | go | func New(h *Handlers, bc *Config) *Bot {
if h.Errored == nil {
h.Errored = logErrorHandler
}
b := &Bot{
handlers: h,
cron: cron.New(),
msgsToSend: make(chan responseMessage, MsgBuffer),
done: make(chan struct{}),
Protocol: bc.Protocol,
Server: bc.Server,
}
// Launch the background goroutine that isolates the possibly non-threadsafe
// message sending logic of the underlying transport layer.
go b.processMessages()
b.startMessageStreams()
b.startPeriodicCommands()
return b
} | [
"func",
"New",
"(",
"h",
"*",
"Handlers",
",",
"bc",
"*",
"Config",
")",
"*",
"Bot",
"{",
"if",
"h",
".",
"Errored",
"==",
"nil",
"{",
"h",
".",
"Errored",
"=",
"logErrorHandler",
"\n",
"}",
"\n\n",
"b",
":=",
"&",
"Bot",
"{",
"handlers",
":",
... | // New configures a new bot instance | [
"New",
"configures",
"a",
"new",
"bot",
"instance"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/bot.go#L77-L99 |
151,389 | go-chat-bot/bot | bot.go | MessageReceived | func (b *Bot) MessageReceived(channel *ChannelData, message *Message, sender *User) {
command, err := parse(message.Text, channel, sender)
if err != nil {
b.SendMessage(channel.Channel, err.Error(), sender)
return
}
if command == nil {
b.executePassiveCommands(&PassiveCmd{
Raw: message.Text,
MessageData: message,
Channel: channel.Channel,
ChannelData: channel,
User: sender,
})
return
}
if b.isDisabled(command.Command) {
return
}
switch command.Command {
case helpCommand:
b.help(command)
default:
b.handleCmd(command)
}
} | go | func (b *Bot) MessageReceived(channel *ChannelData, message *Message, sender *User) {
command, err := parse(message.Text, channel, sender)
if err != nil {
b.SendMessage(channel.Channel, err.Error(), sender)
return
}
if command == nil {
b.executePassiveCommands(&PassiveCmd{
Raw: message.Text,
MessageData: message,
Channel: channel.Channel,
ChannelData: channel,
User: sender,
})
return
}
if b.isDisabled(command.Command) {
return
}
switch command.Command {
case helpCommand:
b.help(command)
default:
b.handleCmd(command)
}
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"MessageReceived",
"(",
"channel",
"*",
"ChannelData",
",",
"message",
"*",
"Message",
",",
"sender",
"*",
"User",
")",
"{",
"command",
",",
"err",
":=",
"parse",
"(",
"message",
".",
"Text",
",",
"channel",
",",
"s... | // MessageReceived must be called by the protocol upon receiving a message | [
"MessageReceived",
"must",
"be",
"called",
"by",
"the",
"protocol",
"upon",
"receiving",
"a",
"message"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/bot.go#L160-L188 |
151,390 | go-chat-bot/bot | bot.go | SendMessage | func (b *Bot) SendMessage(target string, message string, sender *User) {
message = b.executeFilterCommands(&FilterCmd{
Target: target,
Message: message,
User: sender})
if message == "" {
return
}
select {
case b.msgsToSend <- responseMessage{target, message, sender}:
default:
b.errored("Failed to queue message to send.", errors.New("Too busy"))
}
} | go | func (b *Bot) SendMessage(target string, message string, sender *User) {
message = b.executeFilterCommands(&FilterCmd{
Target: target,
Message: message,
User: sender})
if message == "" {
return
}
select {
case b.msgsToSend <- responseMessage{target, message, sender}:
default:
b.errored("Failed to queue message to send.", errors.New("Too busy"))
}
} | [
"func",
"(",
"b",
"*",
"Bot",
")",
"SendMessage",
"(",
"target",
"string",
",",
"message",
"string",
",",
"sender",
"*",
"User",
")",
"{",
"message",
"=",
"b",
".",
"executeFilterCommands",
"(",
"&",
"FilterCmd",
"{",
"Target",
":",
"target",
",",
"Mes... | // SendMessage queues a message for a target recipient, optionally from a particular sender. | [
"SendMessage",
"queues",
"a",
"message",
"for",
"a",
"target",
"recipient",
"optionally",
"from",
"a",
"particular",
"sender",
"."
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/bot.go#L191-L205 |
151,391 | go-chat-bot/bot | slack/slack.go | FindUserBySlackID | func FindUserBySlackID(userID string) *bot.User {
slackUser, err := api.GetUserInfo(userID)
if err != nil {
fmt.Printf("Error retrieving slack user: %s\n", err)
return &bot.User{
ID: userID,
IsBot: false}
}
return &bot.User{
ID: userID,
Nick: slackUser.Name,
RealName: slackUser.Profile.RealName,
IsBot: slackUser.IsBot}
} | go | func FindUserBySlackID(userID string) *bot.User {
slackUser, err := api.GetUserInfo(userID)
if err != nil {
fmt.Printf("Error retrieving slack user: %s\n", err)
return &bot.User{
ID: userID,
IsBot: false}
}
return &bot.User{
ID: userID,
Nick: slackUser.Name,
RealName: slackUser.Profile.RealName,
IsBot: slackUser.IsBot}
} | [
"func",
"FindUserBySlackID",
"(",
"userID",
"string",
")",
"*",
"bot",
".",
"User",
"{",
"slackUser",
",",
"err",
":=",
"api",
".",
"GetUserInfo",
"(",
"userID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
... | // FindUserBySlackID converts a slack.User into a bot.User struct | [
"FindUserBySlackID",
"converts",
"a",
"slack",
".",
"User",
"into",
"a",
"bot",
".",
"User",
"struct"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L42-L55 |
151,392 | go-chat-bot/bot | slack/slack.go | extractUser | func extractUser(event *slack.MessageEvent) *bot.User {
var isBot bool
var userID string
if len(event.User) == 0 {
userID = event.BotID
isBot = true
} else {
userID = event.User
isBot = false
}
user := FindUserBySlackID(userID)
if len(user.Nick) == 0 {
user.IsBot = isBot
}
return user
} | go | func extractUser(event *slack.MessageEvent) *bot.User {
var isBot bool
var userID string
if len(event.User) == 0 {
userID = event.BotID
isBot = true
} else {
userID = event.User
isBot = false
}
user := FindUserBySlackID(userID)
if len(user.Nick) == 0 {
user.IsBot = isBot
}
return user
} | [
"func",
"extractUser",
"(",
"event",
"*",
"slack",
".",
"MessageEvent",
")",
"*",
"bot",
".",
"User",
"{",
"var",
"isBot",
"bool",
"\n",
"var",
"userID",
"string",
"\n",
"if",
"len",
"(",
"event",
".",
"User",
")",
"==",
"0",
"{",
"userID",
"=",
"e... | // Extracts user information from slack API | [
"Extracts",
"user",
"information",
"from",
"slack",
"API"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L58-L74 |
151,393 | go-chat-bot/bot | slack/slack.go | RunWithFilter | func RunWithFilter(token string, customMessageFilter MessageFilter) {
if customMessageFilter == nil {
panic("A valid message filter must be provided.")
}
messageFilter = customMessageFilter
Run(token)
} | go | func RunWithFilter(token string, customMessageFilter MessageFilter) {
if customMessageFilter == nil {
panic("A valid message filter must be provided.")
}
messageFilter = customMessageFilter
Run(token)
} | [
"func",
"RunWithFilter",
"(",
"token",
"string",
",",
"customMessageFilter",
"MessageFilter",
")",
"{",
"if",
"customMessageFilter",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"messageFilter",
"=",
"customMessageFilter",
"\n",
"Run",
"("... | // RunWithFilter executes the bot and sets up a message filter which will
// receive all the messages before they are sent to slack | [
"RunWithFilter",
"executes",
"the",
"bot",
"and",
"sets",
"up",
"a",
"message",
"filter",
"which",
"will",
"receive",
"all",
"the",
"messages",
"before",
"they",
"are",
"sent",
"to",
"slack"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L118-L124 |
151,394 | go-chat-bot/bot | slack/slack.go | Run | func Run(token string) {
api = slack.New(token)
rtm = api.NewRTM()
teaminfo, _ = api.GetTeamInfo()
b := bot.New(&bot.Handlers{
Response: responseHandler,
},
&bot.Config{
Protocol: protocol,
Server: teaminfo.Domain,
},
)
b.Disable([]string{"url"})
go rtm.ManageConnection()
Loop:
for {
select {
case msg := <-rtm.IncomingEvents:
switch ev := msg.Data.(type) {
case *slack.HelloEvent:
readBotInfo(api)
readChannelData(api)
case *slack.ChannelCreatedEvent:
readChannelData(api)
case *slack.ChannelRenameEvent:
readChannelData(api)
case *slack.MessageEvent:
if !ev.Hidden && !ownMessage(ev.User) {
C := channelList[ev.Channel]
var channel = ev.Channel
if C.IsChannel {
channel = fmt.Sprintf("#%s", C.Name)
}
go b.MessageReceived(
&bot.ChannelData{
Protocol: "slack",
Server: teaminfo.Domain,
Channel: channel,
HumanName: C.Name,
IsPrivate: !C.IsChannel,
},
extractText(ev),
extractUser(ev),
)
}
case *slack.RTMError:
fmt.Printf("Error: %s\n", ev.Error())
case *slack.InvalidAuthEvent:
fmt.Printf("Invalid credentials")
break Loop
}
}
}
} | go | func Run(token string) {
api = slack.New(token)
rtm = api.NewRTM()
teaminfo, _ = api.GetTeamInfo()
b := bot.New(&bot.Handlers{
Response: responseHandler,
},
&bot.Config{
Protocol: protocol,
Server: teaminfo.Domain,
},
)
b.Disable([]string{"url"})
go rtm.ManageConnection()
Loop:
for {
select {
case msg := <-rtm.IncomingEvents:
switch ev := msg.Data.(type) {
case *slack.HelloEvent:
readBotInfo(api)
readChannelData(api)
case *slack.ChannelCreatedEvent:
readChannelData(api)
case *slack.ChannelRenameEvent:
readChannelData(api)
case *slack.MessageEvent:
if !ev.Hidden && !ownMessage(ev.User) {
C := channelList[ev.Channel]
var channel = ev.Channel
if C.IsChannel {
channel = fmt.Sprintf("#%s", C.Name)
}
go b.MessageReceived(
&bot.ChannelData{
Protocol: "slack",
Server: teaminfo.Domain,
Channel: channel,
HumanName: C.Name,
IsPrivate: !C.IsChannel,
},
extractText(ev),
extractUser(ev),
)
}
case *slack.RTMError:
fmt.Printf("Error: %s\n", ev.Error())
case *slack.InvalidAuthEvent:
fmt.Printf("Invalid credentials")
break Loop
}
}
}
} | [
"func",
"Run",
"(",
"token",
"string",
")",
"{",
"api",
"=",
"slack",
".",
"New",
"(",
"token",
")",
"\n",
"rtm",
"=",
"api",
".",
"NewRTM",
"(",
")",
"\n",
"teaminfo",
",",
"_",
"=",
"api",
".",
"GetTeamInfo",
"(",
")",
"\n\n",
"b",
":=",
"bot... | // Run connects to slack RTM API using the provided token | [
"Run",
"connects",
"to",
"slack",
"RTM",
"API",
"using",
"the",
"provided",
"token"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/slack/slack.go#L127-L187 |
151,395 | go-chat-bot/bot | irc/irc.go | SetUpConn | func SetUpConn(c *Config) (*bot.Bot, *ircevent.Connection) {
return SetUp(c), ircConn
} | go | func SetUpConn(c *Config) (*bot.Bot, *ircevent.Connection) {
return SetUp(c), ircConn
} | [
"func",
"SetUpConn",
"(",
"c",
"*",
"Config",
")",
"(",
"*",
"bot",
".",
"Bot",
",",
"*",
"ircevent",
".",
"Connection",
")",
"{",
"return",
"SetUp",
"(",
"c",
")",
",",
"ircConn",
"\n",
"}"
] | // SetUpConn wraps SetUp and returns ircConn in addition to bot | [
"SetUpConn",
"wraps",
"SetUp",
"and",
"returns",
"ircConn",
"in",
"addition",
"to",
"bot"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/irc/irc.go#L128-L130 |
151,396 | go-chat-bot/bot | irc/irc.go | Run | func Run(c *Config) {
if c != nil {
SetUp(c)
}
err := ircConn.Connect(config.Server)
if err != nil {
log.Fatal(err)
}
ircConn.Loop()
} | go | func Run(c *Config) {
if c != nil {
SetUp(c)
}
err := ircConn.Connect(config.Server)
if err != nil {
log.Fatal(err)
}
ircConn.Loop()
} | [
"func",
"Run",
"(",
"c",
"*",
"Config",
")",
"{",
"if",
"c",
"!=",
"nil",
"{",
"SetUp",
"(",
"c",
")",
"\n",
"}",
"\n\n",
"err",
":=",
"ircConn",
".",
"Connect",
"(",
"config",
".",
"Server",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
"... | // Run reads the Config, connect to the specified IRC server and starts the bot.
// The bot will automatically join all the channels specified in the configuration | [
"Run",
"reads",
"the",
"Config",
"connect",
"to",
"the",
"specified",
"IRC",
"server",
"and",
"starts",
"the",
"bot",
".",
"The",
"bot",
"will",
"automatically",
"join",
"all",
"the",
"channels",
"specified",
"in",
"the",
"configuration"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/irc/irc.go#L134-L144 |
151,397 | go-chat-bot/bot | telegram/telegram.go | Run | func Run(token string, debug bool) {
var err error
tg, err = tgbotapi.NewBotAPI(token)
if err != nil {
log.Fatal(err)
}
tg.Debug = debug
log.Printf("Authorized on account %s", tg.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := tg.GetUpdatesChan(u)
if err != nil {
log.Fatal(err)
}
b := bot.New(&bot.Handlers{
Response: responseHandler,
}, &bot.Config{
Protocol: protocol,
Server: server,
},
)
b.Disable([]string{"url"})
for update := range updates {
target := &bot.ChannelData{
Protocol: protocol,
Server: server,
Channel: strconv.FormatInt(update.Message.Chat.ID, 10),
IsPrivate: update.Message.Chat.IsPrivate()}
name := []string{update.Message.From.FirstName, update.Message.From.LastName}
message := &bot.Message{
Text: update.Message.Text,
}
b.MessageReceived(target, message, &bot.User{
ID: strconv.Itoa(update.Message.From.ID),
Nick: update.Message.From.UserName,
RealName: strings.Join(name, " ")})
}
} | go | func Run(token string, debug bool) {
var err error
tg, err = tgbotapi.NewBotAPI(token)
if err != nil {
log.Fatal(err)
}
tg.Debug = debug
log.Printf("Authorized on account %s", tg.Self.UserName)
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := tg.GetUpdatesChan(u)
if err != nil {
log.Fatal(err)
}
b := bot.New(&bot.Handlers{
Response: responseHandler,
}, &bot.Config{
Protocol: protocol,
Server: server,
},
)
b.Disable([]string{"url"})
for update := range updates {
target := &bot.ChannelData{
Protocol: protocol,
Server: server,
Channel: strconv.FormatInt(update.Message.Chat.ID, 10),
IsPrivate: update.Message.Chat.IsPrivate()}
name := []string{update.Message.From.FirstName, update.Message.From.LastName}
message := &bot.Message{
Text: update.Message.Text,
}
b.MessageReceived(target, message, &bot.User{
ID: strconv.Itoa(update.Message.From.ID),
Nick: update.Message.From.UserName,
RealName: strings.Join(name, " ")})
}
} | [
"func",
"Run",
"(",
"token",
"string",
",",
"debug",
"bool",
")",
"{",
"var",
"err",
"error",
"\n",
"tg",
",",
"err",
"=",
"tgbotapi",
".",
"NewBotAPI",
"(",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",... | // Run executes the bot and connects to Telegram using the provided token. Use the debug flag if you wish to see all traffic logged | [
"Run",
"executes",
"the",
"bot",
"and",
"connects",
"to",
"Telegram",
"using",
"the",
"provided",
"token",
".",
"Use",
"the",
"debug",
"flag",
"if",
"you",
"wish",
"to",
"see",
"all",
"traffic",
"logged"
] | a72276ecd4eadb8f0129aa19caad1fc180d8f0f7 | https://github.com/go-chat-bot/bot/blob/a72276ecd4eadb8f0129aa19caad1fc180d8f0f7/telegram/telegram.go#L34-L79 |
151,398 | stathat/consistent | consistent.go | New | func New() *Consistent {
c := new(Consistent)
c.NumberOfReplicas = 20
c.circle = make(map[uint32]string)
c.members = make(map[string]bool)
return c
} | go | func New() *Consistent {
c := new(Consistent)
c.NumberOfReplicas = 20
c.circle = make(map[uint32]string)
c.members = make(map[string]bool)
return c
} | [
"func",
"New",
"(",
")",
"*",
"Consistent",
"{",
"c",
":=",
"new",
"(",
"Consistent",
")",
"\n",
"c",
".",
"NumberOfReplicas",
"=",
"20",
"\n",
"c",
".",
"circle",
"=",
"make",
"(",
"map",
"[",
"uint32",
"]",
"string",
")",
"\n",
"c",
".",
"membe... | // New creates a new Consistent object with a default setting of 20 replicas for each entry.
//
// To change the number of replicas, set NumberOfReplicas before adding entries. | [
"New",
"creates",
"a",
"new",
"Consistent",
"object",
"with",
"a",
"default",
"setting",
"of",
"20",
"replicas",
"for",
"each",
"entry",
".",
"To",
"change",
"the",
"number",
"of",
"replicas",
"set",
"NumberOfReplicas",
"before",
"adding",
"entries",
"."
] | ad91dc4a3a642859730ff3d65929fce009bfdc23 | https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L59-L65 |
151,399 | stathat/consistent | consistent.go | eltKey | func (c *Consistent) eltKey(elt string, idx int) string {
// return elt + "|" + strconv.Itoa(idx)
return strconv.Itoa(idx) + elt
} | go | func (c *Consistent) eltKey(elt string, idx int) string {
// return elt + "|" + strconv.Itoa(idx)
return strconv.Itoa(idx) + elt
} | [
"func",
"(",
"c",
"*",
"Consistent",
")",
"eltKey",
"(",
"elt",
"string",
",",
"idx",
"int",
")",
"string",
"{",
"// return elt + \"|\" + strconv.Itoa(idx)",
"return",
"strconv",
".",
"Itoa",
"(",
"idx",
")",
"+",
"elt",
"\n",
"}"
] | // eltKey generates a string key for an element with an index. | [
"eltKey",
"generates",
"a",
"string",
"key",
"for",
"an",
"element",
"with",
"an",
"index",
"."
] | ad91dc4a3a642859730ff3d65929fce009bfdc23 | https://github.com/stathat/consistent/blob/ad91dc4a3a642859730ff3d65929fce009bfdc23/consistent.go#L68-L71 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.