id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
137,000 | sajari/word2vec | word2vec.go | Dot | func (v Vector) Dot(u Vector) float32 {
return blas.Sdot(len(v), u, 1, v, 1)
} | go | func (v Vector) Dot(u Vector) float32 {
return blas.Sdot(len(v), u, 1, v, 1)
} | [
"func",
"(",
"v",
"Vector",
")",
"Dot",
"(",
"u",
"Vector",
")",
"float32",
"{",
"return",
"blas",
".",
"Sdot",
"(",
"len",
"(",
"v",
")",
",",
"u",
",",
"1",
",",
"v",
",",
"1",
")",
"\n",
"}"
] | // Dot computes the dot product with u. | [
"Dot",
"computes",
"the",
"dot",
"product",
"with",
"u",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L98-L100 |
137,001 | sajari/word2vec | word2vec.go | Add | func (e Expr) Add(weight float32, word string) {
e[word] += weight
} | go | func (e Expr) Add(weight float32, word string) {
e[word] += weight
} | [
"func",
"(",
"e",
"Expr",
")",
"Add",
"(",
"weight",
"float32",
",",
"word",
"string",
")",
"{",
"e",
"[",
"word",
"]",
"+=",
"weight",
"\n",
"}"
] | // Add appends the given word with specified weight to the expression. If the word already
// exists in the expression, then the weights are added. | [
"Add",
"appends",
"the",
"given",
"word",
"with",
"specified",
"weight",
"to",
"the",
"expression",
".",
"If",
"the",
"word",
"already",
"exists",
"in",
"the",
"expression",
"then",
"the",
"weights",
"are",
"added",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L118-L120 |
137,002 | sajari/word2vec | word2vec.go | Eval | func (e Expr) Eval(m *Model) (Vector, error) {
if len(e) == 0 {
return nil, fmt.Errorf("must specify at least one word to evaluate")
}
return m.Eval(e)
} | go | func (e Expr) Eval(m *Model) (Vector, error) {
if len(e) == 0 {
return nil, fmt.Errorf("must specify at least one word to evaluate")
}
return m.Eval(e)
} | [
"func",
"(",
"e",
"Expr",
")",
"Eval",
"(",
"m",
"*",
"Model",
")",
"(",
"Vector",
",",
"error",
")",
"{",
"if",
"len",
"(",
"e",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"retur... | // Eval evaluates the Expr to a Vector using a Model. | [
"Eval",
"evaluates",
"the",
"Expr",
"to",
"a",
"Vector",
"using",
"a",
"Model",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L123-L128 |
137,003 | sajari/word2vec | word2vec.go | Add | func Add(e Expr, weight float32, words []string) {
for _, w := range words {
e.Add(weight, w)
}
} | go | func Add(e Expr, weight float32, words []string) {
for _, w := range words {
e.Add(weight, w)
}
} | [
"func",
"Add",
"(",
"e",
"Expr",
",",
"weight",
"float32",
",",
"words",
"[",
"]",
"string",
")",
"{",
"for",
"_",
",",
"w",
":=",
"range",
"words",
"{",
"e",
".",
"Add",
"(",
"weight",
",",
"w",
")",
"\n",
"}",
"\n",
"}"
] | // Add is a convenience method for adding multiple words to an Expr. | [
"Add",
"is",
"a",
"convenience",
"method",
"for",
"adding",
"multiple",
"words",
"to",
"an",
"Expr",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L131-L135 |
137,004 | sajari/word2vec | word2vec.go | AddWeight | func AddWeight(e Expr, weights []float32, words []string) {
if len(weights) != len(words) {
panic("weight and words must be the same length")
}
for i, w := range weights {
e.Add(w, words[i])
}
} | go | func AddWeight(e Expr, weights []float32, words []string) {
if len(weights) != len(words) {
panic("weight and words must be the same length")
}
for i, w := range weights {
e.Add(w, words[i])
}
} | [
"func",
"AddWeight",
"(",
"e",
"Expr",
",",
"weights",
"[",
"]",
"float32",
",",
"words",
"[",
"]",
"string",
")",
"{",
"if",
"len",
"(",
"weights",
")",
"!=",
"len",
"(",
"words",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"fo... | // AddWeight is a convenience method for adding multiple weighted words to an Expr. | [
"AddWeight",
"is",
"a",
"convenience",
"method",
"for",
"adding",
"multiple",
"weighted",
"words",
"to",
"an",
"Expr",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L138-L146 |
137,005 | sajari/word2vec | word2vec.go | Map | func (m *Model) Map(words []string) map[string]Vector {
result := make(map[string]Vector)
for _, w := range words {
if v, ok := m.words[w]; ok {
result[w] = v
}
}
return result
} | go | func (m *Model) Map(words []string) map[string]Vector {
result := make(map[string]Vector)
for _, w := range words {
if v, ok := m.words[w]; ok {
result[w] = v
}
}
return result
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Map",
"(",
"words",
"[",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"Vector",
"{",
"result",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Vector",
")",
"\n",
"for",
"_",
",",
"w",
":=",
"range",
"word... | // Map returns a mapping word -> Vector for each word in `words`.
// Unknown words are ignored. | [
"Map",
"returns",
"a",
"mapping",
"word",
"-",
">",
"Vector",
"for",
"each",
"word",
"in",
"words",
".",
"Unknown",
"words",
"are",
"ignored",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L179-L187 |
137,006 | sajari/word2vec | word2vec.go | Cos | func (m *Model) Cos(a, b Expr) (float32, error) {
u, err := a.Eval(m)
if err != nil {
return 0, err
}
v, err := b.Eval(m)
if err != nil {
return 0, err
}
return u.Dot(v), nil
} | go | func (m *Model) Cos(a, b Expr) (float32, error) {
u, err := a.Eval(m)
if err != nil {
return 0, err
}
v, err := b.Eval(m)
if err != nil {
return 0, err
}
return u.Dot(v), nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Cos",
"(",
"a",
",",
"b",
"Expr",
")",
"(",
"float32",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"a",
".",
"Eval",
"(",
"m",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"... | // Cos returns the cosine similarity of the given expressions. | [
"Cos",
"returns",
"the",
"cosine",
"similarity",
"of",
"the",
"given",
"expressions",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L190-L201 |
137,007 | sajari/word2vec | word2vec.go | Coses | func (m *Model) Coses(pairs [][2]Expr) ([]float32, error) {
out := make([]float32, len(pairs))
for i, p := range pairs {
c, err := m.Cos(p[0], p[1])
if err != nil {
return nil, err
}
out[i] = c
}
return out, nil
} | go | func (m *Model) Coses(pairs [][2]Expr) ([]float32, error) {
out := make([]float32, len(pairs))
for i, p := range pairs {
c, err := m.Cos(p[0], p[1])
if err != nil {
return nil, err
}
out[i] = c
}
return out, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Coses",
"(",
"pairs",
"[",
"]",
"[",
"2",
"]",
"Expr",
")",
"(",
"[",
"]",
"float32",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"float32",
",",
"len",
"(",
"pairs",
")",
")",
"\n",
"fo... | // Coses returns the cosine similarity of each pair of expressions in the list. Returns
// immediately if an error occurs. | [
"Coses",
"returns",
"the",
"cosine",
"similarity",
"of",
"each",
"pair",
"of",
"expressions",
"in",
"the",
"list",
".",
"Returns",
"immediately",
"if",
"an",
"error",
"occurs",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L205-L215 |
137,008 | sajari/word2vec | word2vec.go | Eval | func (m *Model) Eval(expr Expr) (Vector, error) {
v := Vector(make([]float32, m.dim))
for w, c := range expr {
u, ok := m.words[w]
if !ok {
return nil, &NotFoundError{w}
}
v.Add(c, u)
}
v.Normalise()
return v, nil
} | go | func (m *Model) Eval(expr Expr) (Vector, error) {
v := Vector(make([]float32, m.dim))
for w, c := range expr {
u, ok := m.words[w]
if !ok {
return nil, &NotFoundError{w}
}
v.Add(c, u)
}
v.Normalise()
return v, nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Eval",
"(",
"expr",
"Expr",
")",
"(",
"Vector",
",",
"error",
")",
"{",
"v",
":=",
"Vector",
"(",
"make",
"(",
"[",
"]",
"float32",
",",
"m",
".",
"dim",
")",
")",
"\n",
"for",
"w",
",",
"c",
":=",
"ran... | // Eval constructs a vector by evaluating the expression
// vector. Returns an error if a word is not in the model. | [
"Eval",
"constructs",
"a",
"vector",
"by",
"evaluating",
"the",
"expression",
"vector",
".",
"Returns",
"an",
"error",
"if",
"a",
"word",
"is",
"not",
"in",
"the",
"model",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L219-L230 |
137,009 | sajari/word2vec | word2vec.go | CosN | func (m *Model) CosN(e Expr, n int) ([]Match, error) {
if n == 0 {
return nil, nil
}
v, err := e.Eval(m)
if err != nil {
return nil, err
}
v.Normalise()
return m.cosineN(v, n), nil
} | go | func (m *Model) CosN(e Expr, n int) ([]Match, error) {
if n == 0 {
return nil, nil
}
v, err := e.Eval(m)
if err != nil {
return nil, err
}
v.Normalise()
return m.cosineN(v, n), nil
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"CosN",
"(",
"e",
"Expr",
",",
"n",
"int",
")",
"(",
"[",
"]",
"Match",
",",
"error",
")",
"{",
"if",
"n",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"v",
",",
"err",
":=",
"e",
".... | // CosN computes the n most similar words to the expression. Returns an error if the
// expression could not be evaluated. | [
"CosN",
"computes",
"the",
"n",
"most",
"similar",
"words",
"to",
"the",
"expression",
".",
"Returns",
"an",
"error",
"if",
"the",
"expression",
"could",
"not",
"be",
"evaluated",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L241-L253 |
137,010 | sajari/word2vec | word2vec.go | cosineN | func (m *Model) cosineN(v Vector, n int) []Match {
r := make([]Match, n)
for w, u := range m.words {
score := v.Dot(u)
p := Match{w, score}
// TODO(dhowden): MaxHeap would be better here if n is large.
if r[n-1].Score > p.Score {
continue
}
r[n-1] = p
for j := n - 2; j >= 0; j-- {
if r[j].Score > ... | go | func (m *Model) cosineN(v Vector, n int) []Match {
r := make([]Match, n)
for w, u := range m.words {
score := v.Dot(u)
p := Match{w, score}
// TODO(dhowden): MaxHeap would be better here if n is large.
if r[n-1].Score > p.Score {
continue
}
r[n-1] = p
for j := n - 2; j >= 0; j-- {
if r[j].Score > ... | [
"func",
"(",
"m",
"*",
"Model",
")",
"cosineN",
"(",
"v",
"Vector",
",",
"n",
"int",
")",
"[",
"]",
"Match",
"{",
"r",
":=",
"make",
"(",
"[",
"]",
"Match",
",",
"n",
")",
"\n",
"for",
"w",
",",
"u",
":=",
"range",
"m",
".",
"words",
"{",
... | // cosineN is a method which returns a list of `n` most similar vectors to `v` in the model. | [
"cosineN",
"is",
"a",
"method",
"which",
"returns",
"a",
"list",
"of",
"n",
"most",
"similar",
"vectors",
"to",
"v",
"in",
"the",
"model",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L256-L274 |
137,011 | sajari/word2vec | word2vec.go | MultiCosN | func MultiCosN(m *Model, exprs []Expr, n int) ([][]Match, error) {
if n == 0 {
return make([][]Match, len(exprs)), nil
}
vecs := make([]Vector, len(exprs))
for i, e := range exprs {
v, err := e.Eval(m)
if err != nil {
return nil, err
}
vecs[i] = v
}
wg := &sync.WaitGroup{}
wg.Add(len(vecs))
ch :=... | go | func MultiCosN(m *Model, exprs []Expr, n int) ([][]Match, error) {
if n == 0 {
return make([][]Match, len(exprs)), nil
}
vecs := make([]Vector, len(exprs))
for i, e := range exprs {
v, err := e.Eval(m)
if err != nil {
return nil, err
}
vecs[i] = v
}
wg := &sync.WaitGroup{}
wg.Add(len(vecs))
ch :=... | [
"func",
"MultiCosN",
"(",
"m",
"*",
"Model",
",",
"exprs",
"[",
"]",
"Expr",
",",
"n",
"int",
")",
"(",
"[",
"]",
"[",
"]",
"Match",
",",
"error",
")",
"{",
"if",
"n",
"==",
"0",
"{",
"return",
"make",
"(",
"[",
"]",
"[",
"]",
"Match",
",",... | // MultiCosN takes a list of expressions and computes the
// n most similar words for each. | [
"MultiCosN",
"takes",
"a",
"list",
"of",
"expressions",
"and",
"computes",
"the",
"n",
"most",
"similar",
"words",
"for",
"each",
"."
] | 350028ca6b1214bc12c20ff3b466733e1d0af3ac | https://github.com/sajari/word2vec/blob/350028ca6b1214bc12c20ff3b466733e1d0af3ac/word2vec.go#L303-L334 |
137,012 | omise/omise-go | webhook.go | HandleEvent | func (f EventHandlerFunc) HandleEvent(resp http.ResponseWriter, req *http.Request, event *Event) {
f(resp, req, event)
} | go | func (f EventHandlerFunc) HandleEvent(resp http.ResponseWriter, req *http.Request, event *Event) {
f(resp, req, event)
} | [
"func",
"(",
"f",
"EventHandlerFunc",
")",
"HandleEvent",
"(",
"resp",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
",",
"event",
"*",
"Event",
")",
"{",
"f",
"(",
"resp",
",",
"req",
",",
"event",
")",
"\n",
"}"
] | // HandleEvent implements the EventHandler interface by calling the underlying funciton. | [
"HandleEvent",
"implements",
"the",
"EventHandler",
"interface",
"by",
"calling",
"the",
"underlying",
"funciton",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/webhook.go#L17-L19 |
137,013 | omise/omise-go | client.go | Do | func (c *Client) Do(result interface{}, operation internal.Operation) error {
req, err := c.Request(operation)
if err != nil {
return err
}
// response
resp, err := c.Client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return err
}
buffer, err := ioutil.ReadAll(resp.Body)
if err... | go | func (c *Client) Do(result interface{}, operation internal.Operation) error {
req, err := c.Request(operation)
if err != nil {
return err
}
// response
resp, err := c.Client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return err
}
buffer, err := ioutil.ReadAll(resp.Body)
if err... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Do",
"(",
"result",
"interface",
"{",
"}",
",",
"operation",
"internal",
".",
"Operation",
")",
"error",
"{",
"req",
",",
"err",
":=",
"c",
".",
"Request",
"(",
"operation",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // Do performs the supplied operation against Omise's REST API and unmarshal the response
// into the given result parameter. Results are usually basic objects or a list that
// corresponds to the operations being done.
//
// If the operation is successful, result should contains the response data. Otherwise a
// non-n... | [
"Do",
"performs",
"the",
"supplied",
"operation",
"against",
"Omise",
"s",
"REST",
"API",
"and",
"unmarshal",
"the",
"response",
"into",
"the",
"given",
"result",
"parameter",
".",
"Results",
"are",
"usually",
"basic",
"objects",
"or",
"a",
"list",
"that",
"... | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/client.go#L128-L169 |
137,014 | omise/omise-go | event.go | UnmarshalJSON | func (ev *Event) UnmarshalJSON(buffer []byte) error {
shim := &eventShim{}
if err := json.Unmarshal(buffer, shim); err != nil {
return err
}
// go through a proxy type to undefine UnmarshalJSON (stack overflow, otherwise)
type EventProxy Event
proxy := EventProxy(*ev)
proxy.Key = shim.Key
// Pre-init the ri... | go | func (ev *Event) UnmarshalJSON(buffer []byte) error {
shim := &eventShim{}
if err := json.Unmarshal(buffer, shim); err != nil {
return err
}
// go through a proxy type to undefine UnmarshalJSON (stack overflow, otherwise)
type EventProxy Event
proxy := EventProxy(*ev)
proxy.Key = shim.Key
// Pre-init the ri... | [
"func",
"(",
"ev",
"*",
"Event",
")",
"UnmarshalJSON",
"(",
"buffer",
"[",
"]",
"byte",
")",
"error",
"{",
"shim",
":=",
"&",
"eventShim",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"buffer",
",",
"shim",
")",
";",
"err",
"... | // UnmarshalJSON unmarshals the buffer into an internal shim structure first, in order to
// determine the right structure to use for the .Data field. Then will re-unmarshal the
// structure as normal. | [
"UnmarshalJSON",
"unmarshals",
"the",
"buffer",
"into",
"an",
"internal",
"shim",
"structure",
"first",
"in",
"order",
"to",
"determine",
"the",
"right",
"structure",
"to",
"use",
"for",
"the",
".",
"Data",
"field",
".",
"Then",
"will",
"re",
"-",
"unmarshal... | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/event.go#L23-L47 |
137,015 | omise/omise-go | list_types.go | Find | func (list *AccountList) Find(id string) *Account {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *AccountList) Find(id string) *Account {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"AccountList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Account",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Account with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Account",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L17-L25 |
137,016 | omise/omise-go | list_types.go | Find | func (list *BalanceList) Find(id string) *Balance {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *BalanceList) Find(id string) *Balance {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"BalanceList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Balance",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Balance with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Balance",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L36-L44 |
137,017 | omise/omise-go | list_types.go | Find | func (list *BankAccountList) Find(id string) *BankAccount {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *BankAccountList) Find(id string) *BankAccount {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"BankAccountList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"BankAccount",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
... | // Find finds and returns BankAccount with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"BankAccount",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L55-L63 |
137,018 | omise/omise-go | list_types.go | Find | func (list *CardList) Find(id string) *Card {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *CardList) Find(id string) *Card {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"CardList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Card",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
"}",
... | // Find finds and returns Card with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Card",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L74-L82 |
137,019 | omise/omise-go | list_types.go | Find | func (list *ChargeList) Find(id string) *Charge {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *ChargeList) Find(id string) *Charge {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"ChargeList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Charge",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
"}... | // Find finds and returns Charge with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Charge",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L93-L101 |
137,020 | omise/omise-go | list_types.go | Find | func (list *CustomerList) Find(id string) *Customer {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *CustomerList) Find(id string) *Customer {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"CustomerList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Customer",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Customer with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Customer",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L112-L120 |
137,021 | omise/omise-go | list_types.go | Find | func (list *DeletionList) Find(id string) *Deletion {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *DeletionList) Find(id string) *Deletion {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"DeletionList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Deletion",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Deletion with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Deletion",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L131-L139 |
137,022 | omise/omise-go | list_types.go | Find | func (list *DisputeList) Find(id string) *Dispute {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *DisputeList) Find(id string) *Dispute {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"DisputeList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Dispute",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Dispute with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Dispute",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L150-L158 |
137,023 | omise/omise-go | list_types.go | Find | func (list *DocumentList) Find(id string) *Document {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *DocumentList) Find(id string) *Document {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"DocumentList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Document",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Document with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Document",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L169-L177 |
137,024 | omise/omise-go | list_types.go | Find | func (list *EventList) Find(id string) *Event {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *EventList) Find(id string) *Event {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"EventList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Event",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
"}",... | // Find finds and returns Event with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Event",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L188-L196 |
137,025 | omise/omise-go | list_types.go | Find | func (list *LinkList) Find(id string) *Link {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *LinkList) Find(id string) *Link {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"LinkList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Link",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
"}",
... | // Find finds and returns Link with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Link",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L207-L215 |
137,026 | omise/omise-go | list_types.go | Find | func (list *OccurrenceList) Find(id string) *Occurrence {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *OccurrenceList) Find(id string) *Occurrence {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"OccurrenceList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Occurrence",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\... | // Find finds and returns Occurrence with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Occurrence",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L226-L234 |
137,027 | omise/omise-go | list_types.go | Find | func (list *ReceiptList) Find(id string) *Receipt {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *ReceiptList) Find(id string) *Receipt {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"ReceiptList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Receipt",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Receipt with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Receipt",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L245-L253 |
137,028 | omise/omise-go | list_types.go | Find | func (list *RecipientList) Find(id string) *Recipient {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *RecipientList) Find(id string) *Recipient {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"RecipientList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Recipient",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n"... | // Find finds and returns Recipient with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Recipient",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L264-L272 |
137,029 | omise/omise-go | list_types.go | Find | func (list *RefundList) Find(id string) *Refund {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *RefundList) Find(id string) *Refund {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"RefundList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Refund",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
"}... | // Find finds and returns Refund with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Refund",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L283-L291 |
137,030 | omise/omise-go | list_types.go | Find | func (list *ScheduleList) Find(id string) *Schedule {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *ScheduleList) Find(id string) *Schedule {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"ScheduleList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Schedule",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Schedule with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Schedule",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L302-L310 |
137,031 | omise/omise-go | list_types.go | Find | func (list *TokenList) Find(id string) *Token {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *TokenList) Find(id string) *Token {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"TokenList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Token",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
"}",... | // Find finds and returns Token with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Token",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L321-L329 |
137,032 | omise/omise-go | list_types.go | Find | func (list *TransactionList) Find(id string) *Transaction {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *TransactionList) Find(id string) *Transaction {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"TransactionList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Transaction",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
... | // Find finds and returns Transaction with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Transaction",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L340-L348 |
137,033 | omise/omise-go | list_types.go | Find | func (list *TransferList) Find(id string) *Transfer {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | go | func (list *TransferList) Find(id string) *Transfer {
for _, item := range list.Data {
if item.ID == id {
return item
}
}
return nil
} | [
"func",
"(",
"list",
"*",
"TransferList",
")",
"Find",
"(",
"id",
"string",
")",
"*",
"Transfer",
"{",
"for",
"_",
",",
"item",
":=",
"range",
"list",
".",
"Data",
"{",
"if",
"item",
".",
"ID",
"==",
"id",
"{",
"return",
"item",
"\n",
"}",
"\n",
... | // Find finds and returns Transfer with the given id. Returns nil if not found. | [
"Find",
"finds",
"and",
"returns",
"Transfer",
"with",
"the",
"given",
"id",
".",
"Returns",
"nil",
"if",
"not",
"found",
"."
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/list_types.go#L359-L367 |
137,034 | omise/omise-go | operations/list.go | MarshalJSON | func (l List) MarshalJSON() ([]byte, error) {
type Alias List
params := struct {
Alias
PFrom *time.Time `json:"from,omitempty"`
PTo *time.Time `json:"to,omitempty"`
}{
Alias: Alias(l),
}
if !l.From.IsZero() {
params.PFrom = &l.From
}
if !l.To.IsZero() {
params.PTo = &l.To
}
return json.Marshal(pa... | go | func (l List) MarshalJSON() ([]byte, error) {
type Alias List
params := struct {
Alias
PFrom *time.Time `json:"from,omitempty"`
PTo *time.Time `json:"to,omitempty"`
}{
Alias: Alias(l),
}
if !l.From.IsZero() {
params.PFrom = &l.From
}
if !l.To.IsZero() {
params.PTo = &l.To
}
return json.Marshal(pa... | [
"func",
"(",
"l",
"List",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"type",
"Alias",
"List",
"\n",
"params",
":=",
"struct",
"{",
"Alias",
"\n",
"PFrom",
"*",
"time",
".",
"Time",
"`json:\"from,omitempty\"`",
"\n",
... | // MarshalJSON List type | [
"MarshalJSON",
"List",
"type"
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/operations/list.go#L26-L42 |
137,035 | omise/omise-go | date.go | UnmarshalJSON | func (d *Date) UnmarshalJSON(b []byte) error {
tm, err := time.Parse("\"2006-01-02\"", string(b))
if err != nil {
return json.Unmarshal(b, (*time.Time)(d))
}
*d = Date(tm)
return nil
} | go | func (d *Date) UnmarshalJSON(b []byte) error {
tm, err := time.Parse("\"2006-01-02\"", string(b))
if err != nil {
return json.Unmarshal(b, (*time.Time)(d))
}
*d = Date(tm)
return nil
} | [
"func",
"(",
"d",
"*",
"Date",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"tm",
",",
"err",
":=",
"time",
".",
"Parse",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"string",
"(",
"b",
")",
")",
"\n",
"if",
"err",
"!=",
"ni... | // UnmarshalJSON Date type | [
"UnmarshalJSON",
"Date",
"type"
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/date.go#L14-L21 |
137,036 | omise/omise-go | date.go | MarshalJSON | func (d Date) MarshalJSON() ([]byte, error) {
return []byte(time.Time(d).Format("\"2006-01-02\"")), nil
} | go | func (d Date) MarshalJSON() ([]byte, error) {
return []byte(time.Time(d).Format("\"2006-01-02\"")), nil
} | [
"func",
"(",
"d",
"Date",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"[",
"]",
"byte",
"(",
"time",
".",
"Time",
"(",
"d",
")",
".",
"Format",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
")",
")",
",",
"nil",
... | // MarshalJSON Date type | [
"MarshalJSON",
"Date",
"type"
] | 9a222d84d0900ef788cda8a6bfffdca165175138 | https://github.com/omise/omise-go/blob/9a222d84d0900ef788cda8a6bfffdca165175138/date.go#L24-L26 |
137,037 | rhinoman/couchdb-go | auth.go | AddAuthHeaders | func (ba *BasicAuth) AddAuthHeaders(req *http.Request) {
authString := []byte(ba.Username + ":" + ba.Password)
header := "Basic " + base64.StdEncoding.EncodeToString(authString)
req.Header.Set("Authorization", string(header))
} | go | func (ba *BasicAuth) AddAuthHeaders(req *http.Request) {
authString := []byte(ba.Username + ":" + ba.Password)
header := "Basic " + base64.StdEncoding.EncodeToString(authString)
req.Header.Set("Authorization", string(header))
} | [
"func",
"(",
"ba",
"*",
"BasicAuth",
")",
"AddAuthHeaders",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"authString",
":=",
"[",
"]",
"byte",
"(",
"ba",
".",
"Username",
"+",
"\"",
"\"",
"+",
"ba",
".",
"Password",
")",
"\n",
"header",
":=",... | //Adds Basic Authentication headers to an http request | [
"Adds",
"Basic",
"Authentication",
"headers",
"to",
"an",
"http",
"request"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/auth.go#L48-L52 |
137,038 | rhinoman/couchdb-go | auth.go | AddAuthHeaders | func (pta *PassThroughAuth) AddAuthHeaders(req *http.Request) {
req.Header.Set("Authorization", pta.AuthHeader)
} | go | func (pta *PassThroughAuth) AddAuthHeaders(req *http.Request) {
req.Header.Set("Authorization", pta.AuthHeader)
} | [
"func",
"(",
"pta",
"*",
"PassThroughAuth",
")",
"AddAuthHeaders",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"pta",
".",
"AuthHeader",
")",
"\n",
"}"
] | //Use if you already have an Authentication header you want to pass through to couchdb | [
"Use",
"if",
"you",
"already",
"have",
"an",
"Authentication",
"header",
"you",
"want",
"to",
"pass",
"through",
"to",
"couchdb"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/auth.go#L55-L57 |
137,039 | rhinoman/couchdb-go | auth.go | AddAuthHeaders | func (ca *CookieAuth) AddAuthHeaders(req *http.Request) {
authString := "AuthSession=" + ca.AuthToken
req.Header.Set("Cookie", authString)
req.Header.Set("X-CouchDB-WWW-Authenticate", "Cookie")
} | go | func (ca *CookieAuth) AddAuthHeaders(req *http.Request) {
authString := "AuthSession=" + ca.AuthToken
req.Header.Set("Cookie", authString)
req.Header.Set("X-CouchDB-WWW-Authenticate", "Cookie")
} | [
"func",
"(",
"ca",
"*",
"CookieAuth",
")",
"AddAuthHeaders",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"authString",
":=",
"\"",
"\"",
"+",
"ca",
".",
"AuthToken",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"authString",
... | //Adds session token to request | [
"Adds",
"session",
"token",
"to",
"request"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/auth.go#L60-L64 |
137,040 | rhinoman/couchdb-go | auth.go | UpdateAuth | func (ca *CookieAuth) UpdateAuth(resp *http.Response) {
for _, cookie := range resp.Cookies() {
if cookie.Name == "AuthSession" {
ca.UpdatedAuthToken = cookie.Value
}
}
} | go | func (ca *CookieAuth) UpdateAuth(resp *http.Response) {
for _, cookie := range resp.Cookies() {
if cookie.Name == "AuthSession" {
ca.UpdatedAuthToken = cookie.Value
}
}
} | [
"func",
"(",
"ca",
"*",
"CookieAuth",
")",
"UpdateAuth",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"{",
"for",
"_",
",",
"cookie",
":=",
"range",
"resp",
".",
"Cookies",
"(",
")",
"{",
"if",
"cookie",
".",
"Name",
"==",
"\"",
"\"",
"{",
"ca... | //Couchdb returns updated AuthSession tokens | [
"Couchdb",
"returns",
"updated",
"AuthSession",
"tokens"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/auth.go#L83-L89 |
137,041 | rhinoman/couchdb-go | auth.go | GetUpdatedAuth | func (ca *CookieAuth) GetUpdatedAuth() map[string]string {
am := make(map[string]string)
if ca.UpdatedAuthToken != "" {
am["AuthSession"] = ca.UpdatedAuthToken
}
return am
} | go | func (ca *CookieAuth) GetUpdatedAuth() map[string]string {
am := make(map[string]string)
if ca.UpdatedAuthToken != "" {
am["AuthSession"] = ca.UpdatedAuthToken
}
return am
} | [
"func",
"(",
"ca",
"*",
"CookieAuth",
")",
"GetUpdatedAuth",
"(",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"am",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"if",
"ca",
".",
"UpdatedAuthToken",
"!=",
"\"",
"\"",
"{",
"a... | //Set AuthSession Cookie | [
"Set",
"AuthSession",
"Cookie"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/auth.go#L109-L115 |
137,042 | rhinoman/couchdb-go | auth.go | DebugString | func (ba *BasicAuth) DebugString() string {
return fmt.Sprintf("Username: %v, Password: %v", ba.Username, ba.Password)
} | go | func (ba *BasicAuth) DebugString() string {
return fmt.Sprintf("Username: %v, Password: %v", ba.Username, ba.Password)
} | [
"func",
"(",
"ba",
"*",
"BasicAuth",
")",
"DebugString",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ba",
".",
"Username",
",",
"ba",
".",
"Password",
")",
"\n",
"}"
] | //Return a Debug string | [
"Return",
"a",
"Debug",
"string"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/auth.go#L124-L126 |
137,043 | rhinoman/couchdb-go | couchdb.go | NewConnection | func NewConnection(address string, port int,
timeout time.Duration) (*Connection, error) {
url := "http://" + address + ":" + strconv.Itoa(port)
return createConnection(url, timeout)
} | go | func NewConnection(address string, port int,
timeout time.Duration) (*Connection, error) {
url := "http://" + address + ":" + strconv.Itoa(port)
return createConnection(url, timeout)
} | [
"func",
"NewConnection",
"(",
"address",
"string",
",",
"port",
"int",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"*",
"Connection",
",",
"error",
")",
"{",
"url",
":=",
"\"",
"\"",
"+",
"address",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa"... | //Creates a regular http connection.
//Timeout sets the timeout for the http Client | [
"Creates",
"a",
"regular",
"http",
"connection",
".",
"Timeout",
"sets",
"the",
"timeout",
"for",
"the",
"http",
"Client"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L27-L32 |
137,044 | rhinoman/couchdb-go | couchdb.go | Ping | func (conn *Connection) Ping() error {
resp, err := conn.request("HEAD", "/", nil, nil, nil)
if err == nil {
resp.Body.Close()
}
return err
} | go | func (conn *Connection) Ping() error {
resp, err := conn.request("HEAD", "/", nil, nil, nil)
if err == nil {
resp.Body.Close()
}
return err
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"Ping",
"(",
")",
"error",
"{",
"resp",
",",
"err",
":=",
"conn",
".",
"request",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"re... | //Use to check if database server is alive. | [
"Use",
"to",
"check",
"if",
"database",
"server",
"is",
"alive",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L59-L65 |
137,045 | rhinoman/couchdb-go | couchdb.go | GetDBList | func (conn *Connection) GetDBList() (dbList []string, err error) {
resp, err := conn.request("GET", "/_all_dbs", nil, nil, nil)
if err != nil {
return dbList, err
}
err = parseBody(resp, &dbList)
return dbList, err
} | go | func (conn *Connection) GetDBList() (dbList []string, err error) {
resp, err := conn.request("GET", "/_all_dbs", nil, nil, nil)
if err != nil {
return dbList, err
}
err = parseBody(resp, &dbList)
return dbList, err
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"GetDBList",
"(",
")",
"(",
"dbList",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"conn",
".",
"request",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",... | //DATABASES.
//Return a list of all databases on the server | [
"DATABASES",
".",
"Return",
"a",
"list",
"of",
"all",
"databases",
"on",
"the",
"server"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L69-L76 |
137,046 | rhinoman/couchdb-go | couchdb.go | CreateDB | func (conn *Connection) CreateDB(name string, auth Auth) error {
url, err := buildUrl(name)
if err != nil {
return err
}
resp, err := conn.request("PUT", url, nil, nil, auth)
if err == nil {
resp.Body.Close()
}
return err
} | go | func (conn *Connection) CreateDB(name string, auth Auth) error {
url, err := buildUrl(name)
if err != nil {
return err
}
resp, err := conn.request("PUT", url, nil, nil, auth)
if err == nil {
resp.Body.Close()
}
return err
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"CreateDB",
"(",
"name",
"string",
",",
"auth",
"Auth",
")",
"error",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
... | //Create a new Database. | [
"Create",
"a",
"new",
"Database",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L79-L89 |
137,047 | rhinoman/couchdb-go | couchdb.go | SetConfig | func (conn *Connection) SetConfig(section string,
option string, value string, auth Auth) error {
url, err := buildUrl("_node/_local/_config", section, option)
if err != nil {
return err
}
body := strings.NewReader("\"" + value + "\"")
resp, err := conn.request("PUT", url, body, nil, auth)
if err == nil {
re... | go | func (conn *Connection) SetConfig(section string,
option string, value string, auth Auth) error {
url, err := buildUrl("_node/_local/_config", section, option)
if err != nil {
return err
}
body := strings.NewReader("\"" + value + "\"")
resp, err := conn.request("PUT", url, body, nil, auth)
if err == nil {
re... | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"SetConfig",
"(",
"section",
"string",
",",
"option",
"string",
",",
"value",
"string",
",",
"auth",
"Auth",
")",
"error",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"\"",
"\"",
",",
"section",
",",
"o... | //Set a CouchDB configuration option | [
"Set",
"a",
"CouchDB",
"configuration",
"option"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L105-L117 |
137,048 | rhinoman/couchdb-go | couchdb.go | GetConfigOption | func (conn *Connection) GetConfigOption(section string,
option string, auth Auth) (string, error) {
url, err := buildUrl("_node/_local/_config", section, option)
if err != nil {
return "", err
}
resp, err := conn.request("GET", url, nil, nil, auth)
var val interface{}
parseBody(resp, &val)
if num, ok := val.(... | go | func (conn *Connection) GetConfigOption(section string,
option string, auth Auth) (string, error) {
url, err := buildUrl("_node/_local/_config", section, option)
if err != nil {
return "", err
}
resp, err := conn.request("GET", url, nil, nil, auth)
var val interface{}
parseBody(resp, &val)
if num, ok := val.(... | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"GetConfigOption",
"(",
"section",
"string",
",",
"option",
"string",
",",
"auth",
"Auth",
")",
"(",
"string",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"\"",
"\"",
",",
"section",
... | //Gets a CouchDB configuration option | [
"Gets",
"a",
"CouchDB",
"configuration",
"option"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L120-L136 |
137,049 | rhinoman/couchdb-go | couchdb.go | AddUser | func (conn *Connection) AddUser(username string, password string,
roles []string, auth Auth) (string, error) {
userData := UserRecord{
Name: username,
Password: password,
Roles: roles,
TheType: "user"}
userDb := conn.SelectDB("_users", auth)
namestring := "org.couchdb.user:" + userData.Name
return... | go | func (conn *Connection) AddUser(username string, password string,
roles []string, auth Auth) (string, error) {
userData := UserRecord{
Name: username,
Password: password,
Roles: roles,
TheType: "user"}
userDb := conn.SelectDB("_users", auth)
namestring := "org.couchdb.user:" + userData.Name
return... | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"AddUser",
"(",
"username",
"string",
",",
"password",
"string",
",",
"roles",
"[",
"]",
"string",
",",
"auth",
"Auth",
")",
"(",
"string",
",",
"error",
")",
"{",
"userData",
":=",
"UserRecord",
"{",
"Name"... | //Add a User.
//This is a convenience method for adding a simple user to CouchDB.
//If you need a User with custom fields, etc., you'll just have to use the
//ordinary document methods on the "_users" database. | [
"Add",
"a",
"User",
".",
"This",
"is",
"a",
"convenience",
"method",
"for",
"adding",
"a",
"simple",
"user",
"to",
"CouchDB",
".",
"If",
"you",
"need",
"a",
"User",
"with",
"custom",
"fields",
"etc",
".",
"you",
"ll",
"just",
"have",
"to",
"use",
"th... | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L150-L162 |
137,050 | rhinoman/couchdb-go | couchdb.go | GrantRole | func (conn *Connection) GrantRole(username string, role string,
auth Auth) (string, error) {
userDb := conn.SelectDB("_users", auth)
namestring := "org.couchdb.user:" + username
var userData interface{}
rev, err := userDb.Read(namestring, &userData, nil)
if err != nil {
return "", err
}
if reflect.ValueOf(us... | go | func (conn *Connection) GrantRole(username string, role string,
auth Auth) (string, error) {
userDb := conn.SelectDB("_users", auth)
namestring := "org.couchdb.user:" + username
var userData interface{}
rev, err := userDb.Read(namestring, &userData, nil)
if err != nil {
return "", err
}
if reflect.ValueOf(us... | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"GrantRole",
"(",
"username",
"string",
",",
"role",
"string",
",",
"auth",
"Auth",
")",
"(",
"string",
",",
"error",
")",
"{",
"userDb",
":=",
"conn",
".",
"SelectDB",
"(",
"\"",
"\"",
",",
"auth",
")",
... | //Grants a role to a user | [
"Grants",
"a",
"role",
"to",
"a",
"user"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L165-L191 |
137,051 | rhinoman/couchdb-go | couchdb.go | CreateSession | func (conn *Connection) CreateSession(username string,
password string) (*CookieAuth, error) {
sessUrl, err := buildUrl("_session")
if err != nil {
return &CookieAuth{}, err
}
var headers = make(map[string]string)
body := "name=" + username + "&password=" + password
headers["Content-Type"] = "application/x-www... | go | func (conn *Connection) CreateSession(username string,
password string) (*CookieAuth, error) {
sessUrl, err := buildUrl("_session")
if err != nil {
return &CookieAuth{}, err
}
var headers = make(map[string]string)
body := "name=" + username + "&password=" + password
headers["Content-Type"] = "application/x-www... | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"CreateSession",
"(",
"username",
"string",
",",
"password",
"string",
")",
"(",
"*",
"CookieAuth",
",",
"error",
")",
"{",
"sessUrl",
",",
"err",
":=",
"buildUrl",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
... | //Creates a session using the Couchdb session api. Returns auth token on success | [
"Creates",
"a",
"session",
"using",
"the",
"Couchdb",
"session",
"api",
".",
"Returns",
"auth",
"token",
"on",
"success"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L246-L270 |
137,052 | rhinoman/couchdb-go | couchdb.go | GetAuthInfo | func (conn *Connection) GetAuthInfo(auth Auth) (*AuthInfoResponse, error) {
authInfo := AuthInfoResponse{}
sessUrl, err := buildUrl("_session")
if err != nil {
return nil, err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
resp, err := conn.request("GET", sessUrl, nil, headers, ... | go | func (conn *Connection) GetAuthInfo(auth Auth) (*AuthInfoResponse, error) {
authInfo := AuthInfoResponse{}
sessUrl, err := buildUrl("_session")
if err != nil {
return nil, err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
resp, err := conn.request("GET", sessUrl, nil, headers, ... | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"GetAuthInfo",
"(",
"auth",
"Auth",
")",
"(",
"*",
"AuthInfoResponse",
",",
"error",
")",
"{",
"authInfo",
":=",
"AuthInfoResponse",
"{",
"}",
"\n",
"sessUrl",
",",
"err",
":=",
"buildUrl",
"(",
"\"",
"\"",
... | //Returns auth information for a user | [
"Returns",
"auth",
"information",
"for",
"a",
"user"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L289-L307 |
137,053 | rhinoman/couchdb-go | couchdb.go | GetUser | func (conn *Connection) GetUser(username string, userData interface{},
auth Auth) (string, error) {
userDb := conn.SelectDB("_users", auth)
namestring := "org.couchdb.user:" + username
return userDb.Read(namestring, &userData, nil)
} | go | func (conn *Connection) GetUser(username string, userData interface{},
auth Auth) (string, error) {
userDb := conn.SelectDB("_users", auth)
namestring := "org.couchdb.user:" + username
return userDb.Read(namestring, &userData, nil)
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"GetUser",
"(",
"username",
"string",
",",
"userData",
"interface",
"{",
"}",
",",
"auth",
"Auth",
")",
"(",
"string",
",",
"error",
")",
"{",
"userDb",
":=",
"conn",
".",
"SelectDB",
"(",
"\"",
"\"",
",",... | //Fetch a user record | [
"Fetch",
"a",
"user",
"record"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L310-L315 |
137,054 | rhinoman/couchdb-go | couchdb.go | SelectDB | func (conn *Connection) SelectDB(dbName string, auth Auth) *Database {
return &Database{
dbName: dbName,
connection: conn,
auth: auth,
}
} | go | func (conn *Connection) SelectDB(dbName string, auth Auth) *Database {
return &Database{
dbName: dbName,
connection: conn,
auth: auth,
}
} | [
"func",
"(",
"conn",
"*",
"Connection",
")",
"SelectDB",
"(",
"dbName",
"string",
",",
"auth",
"Auth",
")",
"*",
"Database",
"{",
"return",
"&",
"Database",
"{",
"dbName",
":",
"dbName",
",",
"connection",
":",
"conn",
",",
"auth",
":",
"auth",
",",
... | //Select a Database. | [
"Select",
"a",
"Database",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L325-L331 |
137,055 | rhinoman/couchdb-go | couchdb.go | DbExists | func (db *Database) DbExists() error {
resp, err := db.connection.request("HEAD", "/"+db.dbName, nil, nil, db.auth)
if err != nil {
if resp != nil {
resp.Body.Close()
}
}
return err
} | go | func (db *Database) DbExists() error {
resp, err := db.connection.request("HEAD", "/"+db.dbName, nil, nil, db.auth)
if err != nil {
if resp != nil {
resp.Body.Close()
}
}
return err
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"DbExists",
"(",
")",
"error",
"{",
"resp",
",",
"err",
":=",
"db",
".",
"connection",
".",
"request",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"db",
".",
"dbName",
",",
"nil",
",",
"nil",
",",
"db",
".",
... | //DbExists checks if the database exists | [
"DbExists",
"checks",
"if",
"the",
"database",
"exists"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L334-L342 |
137,056 | rhinoman/couchdb-go | couchdb.go | Compact | func (db *Database) Compact() (resp string, e error) {
url, err := buildUrl(db.dbName, "_compact")
fmt.Println(url)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
headers["Content-Type"] = "application/json"
emtpyBody := ""
dbResponse, err := ... | go | func (db *Database) Compact() (resp string, e error) {
url, err := buildUrl(db.dbName, "_compact")
fmt.Println(url)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
headers["Content-Type"] = "application/json"
emtpyBody := ""
dbResponse, err := ... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Compact",
"(",
")",
"(",
"resp",
"string",
",",
"e",
"error",
")",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"db",
".",
"dbName",
",",
"\"",
"\"",
")",
"\n",
"fmt",
".",
"Println",
"(",
"url",
")",... | //Compact the current database. | [
"Compact",
"the",
"current",
"database",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L345-L366 |
137,057 | rhinoman/couchdb-go | couchdb.go | Save | func (db *Database) Save(doc interface{}, id string, rev string) (string, error) {
url, err := buildUrl(db.dbName, id)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Content-Type"] = "application/json"
headers["Accept"] = "application/json"
if id == "" {
return "", fmt.Errorf... | go | func (db *Database) Save(doc interface{}, id string, rev string) (string, error) {
url, err := buildUrl(db.dbName, id)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Content-Type"] = "application/json"
headers["Accept"] = "application/json"
if id == "" {
return "", fmt.Errorf... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Save",
"(",
"doc",
"interface",
"{",
"}",
",",
"id",
"string",
",",
"rev",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"db",
".",
"dbName",
",",
"id",
... | //Save a document to the database.
//If you're creating a new document, pass an empty string for rev.
//If updating, you must specify the current rev.
//Returns the revision number assigned to the doc by CouchDB. | [
"Save",
"a",
"document",
"to",
"the",
"database",
".",
"If",
"you",
"re",
"creating",
"a",
"new",
"document",
"pass",
"an",
"empty",
"string",
"for",
"rev",
".",
"If",
"updating",
"you",
"must",
"specify",
"the",
"current",
"rev",
".",
"Returns",
"the",
... | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L372-L408 |
137,058 | rhinoman/couchdb-go | couchdb.go | Copy | func (db *Database) Copy(fromId string, fromRev string, toId string) (string, error) {
url, err := buildUrl(db.dbName, fromId)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
if fromId == "" || toId == "" {
return "", fmt.Errorf("Invalid request. ... | go | func (db *Database) Copy(fromId string, fromRev string, toId string) (string, error) {
url, err := buildUrl(db.dbName, fromId)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
if fromId == "" || toId == "" {
return "", fmt.Errorf("Invalid request. ... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Copy",
"(",
"fromId",
"string",
",",
"fromRev",
"string",
",",
"toId",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"db",
".",
"dbName",
",",
"fromId",
")"... | //Copies a document into a new... document.
//Returns the revision of the newly created document | [
"Copies",
"a",
"document",
"into",
"a",
"new",
"...",
"document",
".",
"Returns",
"the",
"revision",
"of",
"the",
"newly",
"created",
"document"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L412-L432 |
137,059 | rhinoman/couchdb-go | couchdb.go | ReadMultiple | func (db *Database) ReadMultiple(ids []string, results interface{}) error {
type RequestBody struct {
Keys []string `json:"keys"`
}
parameters := url.Values{}
parameters.Set("include_docs", "true")
url, err := buildParamUrl(parameters, db.dbName, "_all_docs")
if err != nil {
return err
}
var headers = make(... | go | func (db *Database) ReadMultiple(ids []string, results interface{}) error {
type RequestBody struct {
Keys []string `json:"keys"`
}
parameters := url.Values{}
parameters.Set("include_docs", "true")
url, err := buildParamUrl(parameters, db.dbName, "_all_docs")
if err != nil {
return err
}
var headers = make(... | [
"func",
"(",
"db",
"*",
"Database",
")",
"ReadMultiple",
"(",
"ids",
"[",
"]",
"string",
",",
"results",
"interface",
"{",
"}",
")",
"error",
"{",
"type",
"RequestBody",
"struct",
"{",
"Keys",
"[",
"]",
"string",
"`json:\"keys\"`",
"\n",
"}",
"\n",
"pa... | //Fetches multiple documents in a single request given a set of arbitrary _ids | [
"Fetches",
"multiple",
"documents",
"in",
"a",
"single",
"request",
"given",
"a",
"set",
"of",
"arbitrary",
"_ids"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L462-L492 |
137,060 | rhinoman/couchdb-go | couchdb.go | Delete | func (db *Database) Delete(id string, rev string) (string, error) {
url, err := buildUrl(db.dbName, id)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
headers["If-Match"] = rev
resp, err := db.connection.request("DELETE", url, nil, headers, db.auth... | go | func (db *Database) Delete(id string, rev string) (string, error) {
url, err := buildUrl(db.dbName, id)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
headers["If-Match"] = rev
resp, err := db.connection.request("DELETE", url, nil, headers, db.auth... | [
"func",
"(",
"db",
"*",
"Database",
")",
"Delete",
"(",
"id",
"string",
",",
"rev",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"db",
".",
"dbName",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"n... | //Deletes a document.
//Or rather, tells CouchDB to mark the document as deleted.
//Yes, CouchDB will return a new revision, so this function returns it. | [
"Deletes",
"a",
"document",
".",
"Or",
"rather",
"tells",
"CouchDB",
"to",
"mark",
"the",
"document",
"as",
"deleted",
".",
"Yes",
"CouchDB",
"will",
"return",
"a",
"new",
"revision",
"so",
"this",
"function",
"returns",
"it",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L497-L511 |
137,061 | rhinoman/couchdb-go | couchdb.go | GetAttachmentByProxy | func (db *Database) GetAttachmentByProxy(docId string, docRev string,
attType string, attName string, r *http.Request, w http.ResponseWriter) error {
path, err := buildUrl(db.dbName, docId, attName)
if err != nil {
return err
}
var headers = make(map[string]string)
headers["Accept"] = attType
if docRev != "" {... | go | func (db *Database) GetAttachmentByProxy(docId string, docRev string,
attType string, attName string, r *http.Request, w http.ResponseWriter) error {
path, err := buildUrl(db.dbName, docId, attName)
if err != nil {
return err
}
var headers = make(map[string]string)
headers["Accept"] = attType
if docRev != "" {... | [
"func",
"(",
"db",
"*",
"Database",
")",
"GetAttachmentByProxy",
"(",
"docId",
"string",
",",
"docRev",
"string",
",",
"attType",
"string",
",",
"attName",
"string",
",",
"r",
"*",
"http",
".",
"Request",
",",
"w",
"http",
".",
"ResponseWriter",
")",
"er... | //Fetches an attachment and proxies the result | [
"Fetches",
"an",
"attachment",
"and",
"proxies",
"the",
"result"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L560-L575 |
137,062 | rhinoman/couchdb-go | couchdb.go | DeleteAttachment | func (db *Database) DeleteAttachment(docId string, docRev string,
attName string) (string, error) {
url, err := buildUrl(db.dbName, docId, attName)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
headers["If-Match"] = docRev
resp, err := db.connect... | go | func (db *Database) DeleteAttachment(docId string, docRev string,
attName string) (string, error) {
url, err := buildUrl(db.dbName, docId, attName)
if err != nil {
return "", err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
headers["If-Match"] = docRev
resp, err := db.connect... | [
"func",
"(",
"db",
"*",
"Database",
")",
"DeleteAttachment",
"(",
"docId",
"string",
",",
"docRev",
"string",
",",
"attName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"db",
".",
"dbName",
",",
"d... | //Deletes an attachment | [
"Deletes",
"an",
"attachment"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L578-L593 |
137,063 | rhinoman/couchdb-go | couchdb.go | GetSecurity | func (db *Database) GetSecurity() (*Security, error) {
url, err := buildUrl(db.dbName, "_security")
if err != nil {
return nil, err
}
var headers = make(map[string]string)
sec := Security{}
headers["Accept"] = "application/json"
resp, err := db.connection.request("GET", url, nil, headers, db.auth)
if err != n... | go | func (db *Database) GetSecurity() (*Security, error) {
url, err := buildUrl(db.dbName, "_security")
if err != nil {
return nil, err
}
var headers = make(map[string]string)
sec := Security{}
headers["Accept"] = "application/json"
resp, err := db.connection.request("GET", url, nil, headers, db.auth)
if err != n... | [
"func",
"(",
"db",
"*",
"Database",
")",
"GetSecurity",
"(",
")",
"(",
"*",
"Security",
",",
"error",
")",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"db",
".",
"dbName",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | //Returns the Security document from the database. | [
"Returns",
"the",
"Security",
"document",
"from",
"the",
"database",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L606-L624 |
137,064 | rhinoman/couchdb-go | couchdb.go | SaveSecurity | func (db *Database) SaveSecurity(sec Security) error {
url, err := buildUrl(db.dbName, "_security")
if err != nil {
return err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
data, numBytes, err := encodeData(sec)
if err != nil {
return err
}
headers["Content-Length"] = strco... | go | func (db *Database) SaveSecurity(sec Security) error {
url, err := buildUrl(db.dbName, "_security")
if err != nil {
return err
}
var headers = make(map[string]string)
headers["Accept"] = "application/json"
data, numBytes, err := encodeData(sec)
if err != nil {
return err
}
headers["Content-Length"] = strco... | [
"func",
"(",
"db",
"*",
"Database",
")",
"SaveSecurity",
"(",
"sec",
"Security",
")",
"error",
"{",
"url",
",",
"err",
":=",
"buildUrl",
"(",
"db",
".",
"dbName",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"... | //Save a security document to the database. | [
"Save",
"a",
"security",
"document",
"to",
"the",
"database",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L627-L647 |
137,065 | rhinoman/couchdb-go | couchdb.go | AddRole | func (db *Database) AddRole(role string, isAdmin bool) error {
sec, err := db.GetSecurity()
if err != nil {
return err
}
roles := func() *[]string {
if isAdmin {
return &sec.Admins.Roles
} else {
return &sec.Members.Roles
}
}
//Make sure the role isn't already there (couchdb will let you add it twic... | go | func (db *Database) AddRole(role string, isAdmin bool) error {
sec, err := db.GetSecurity()
if err != nil {
return err
}
roles := func() *[]string {
if isAdmin {
return &sec.Admins.Roles
} else {
return &sec.Members.Roles
}
}
//Make sure the role isn't already there (couchdb will let you add it twic... | [
"func",
"(",
"db",
"*",
"Database",
")",
"AddRole",
"(",
"role",
"string",
",",
"isAdmin",
"bool",
")",
"error",
"{",
"sec",
",",
"err",
":=",
"db",
".",
"GetSecurity",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\... | // Security helper function.
// Adds a role to a database security doc. | [
"Security",
"helper",
"function",
".",
"Adds",
"a",
"role",
"to",
"a",
"database",
"security",
"doc",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L651-L673 |
137,066 | rhinoman/couchdb-go | couchdb.go | RemoveRole | func (db *Database) RemoveRole(role string) error {
sec, err := db.GetSecurity()
if err != nil {
return err
}
remove := func(isAdmin bool) bool {
var rolesPtr *[]string
if isAdmin {
rolesPtr = &sec.Admins.Roles
} else {
rolesPtr = &sec.Members.Roles
}
roles := *rolesPtr
for i, r := range roles {... | go | func (db *Database) RemoveRole(role string) error {
sec, err := db.GetSecurity()
if err != nil {
return err
}
remove := func(isAdmin bool) bool {
var rolesPtr *[]string
if isAdmin {
rolesPtr = &sec.Admins.Roles
} else {
rolesPtr = &sec.Members.Roles
}
roles := *rolesPtr
for i, r := range roles {... | [
"func",
"(",
"db",
"*",
"Database",
")",
"RemoveRole",
"(",
"role",
"string",
")",
"error",
"{",
"sec",
",",
"err",
":=",
"db",
".",
"GetSecurity",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"remove",
":=",
"... | // Security helper function.
// Removes a role from a database security doc. | [
"Security",
"helper",
"function",
".",
"Removes",
"a",
"role",
"from",
"a",
"database",
"security",
"doc",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L677-L706 |
137,067 | rhinoman/couchdb-go | couchdb.go | GetView | func (db *Database) GetView(designDoc string, view string,
results interface{}, params *url.Values) error {
var err error
var url string
if params == nil {
url, err = buildUrl(db.dbName, "_design", designDoc, "_view", view)
} else {
url, err = buildParamUrl(*params, db.dbName, "_design",
designDoc, "_view",... | go | func (db *Database) GetView(designDoc string, view string,
results interface{}, params *url.Values) error {
var err error
var url string
if params == nil {
url, err = buildUrl(db.dbName, "_design", designDoc, "_view", view)
} else {
url, err = buildParamUrl(*params, db.dbName, "_design",
designDoc, "_view",... | [
"func",
"(",
"db",
"*",
"Database",
")",
"GetView",
"(",
"designDoc",
"string",
",",
"view",
"string",
",",
"results",
"interface",
"{",
"}",
",",
"params",
"*",
"url",
".",
"Values",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"url",
"str... | //Get the results of a view. | [
"Get",
"the",
"results",
"of",
"a",
"view",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L709-L735 |
137,068 | rhinoman/couchdb-go | couchdb.go | GetMultipleFromView | func (db *Database) GetMultipleFromView(designDoc string, view string,
results interface{}, keys []string) error {
var err error
var url string
type RequestBody struct {
Keys []string `json:"keys"`
}
url, err = buildUrl(db.dbName, "_design", designDoc, "_view", view)
if err != nil {
return err
}
fmt.Errorf... | go | func (db *Database) GetMultipleFromView(designDoc string, view string,
results interface{}, keys []string) error {
var err error
var url string
type RequestBody struct {
Keys []string `json:"keys"`
}
url, err = buildUrl(db.dbName, "_design", designDoc, "_view", view)
if err != nil {
return err
}
fmt.Errorf... | [
"func",
"(",
"db",
"*",
"Database",
")",
"GetMultipleFromView",
"(",
"designDoc",
"string",
",",
"view",
"string",
",",
"results",
"interface",
"{",
"}",
",",
"keys",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"url",
"st... | //Get multiple results of a view. | [
"Get",
"multiple",
"results",
"of",
"a",
"view",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L738-L770 |
137,069 | rhinoman/couchdb-go | couchdb.go | SaveDesignDoc | func (db *Database) SaveDesignDoc(name string,
designDoc interface{}, rev string) (string, error) {
path := "_design/" + name
newRev, err := db.Save(designDoc, path, rev)
if err != nil {
return "", err
} else if newRev == "" {
return "", fmt.Errorf("CouchDB returned an empty revision string.")
}
return newRe... | go | func (db *Database) SaveDesignDoc(name string,
designDoc interface{}, rev string) (string, error) {
path := "_design/" + name
newRev, err := db.Save(designDoc, path, rev)
if err != nil {
return "", err
} else if newRev == "" {
return "", fmt.Errorf("CouchDB returned an empty revision string.")
}
return newRe... | [
"func",
"(",
"db",
"*",
"Database",
")",
"SaveDesignDoc",
"(",
"name",
"string",
",",
"designDoc",
"interface",
"{",
"}",
",",
"rev",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"path",
":=",
"\"",
"\"",
"+",
"name",
"\n",
"newRev",
",",
... | //Save a design document.
//If creating a new design doc, set rev to "". | [
"Save",
"a",
"design",
"document",
".",
"If",
"creating",
"a",
"new",
"design",
"doc",
"set",
"rev",
"to",
"."
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/couchdb.go#L844-L855 |
137,070 | rhinoman/couchdb-go | bulk_docs.go | NewBulkDocument | func (db *Database) NewBulkDocument() *BulkDocument {
b := &BulkDocument{}
b.db = db
return b
} | go | func (db *Database) NewBulkDocument() *BulkDocument {
b := &BulkDocument{}
b.db = db
return b
} | [
"func",
"(",
"db",
"*",
"Database",
")",
"NewBulkDocument",
"(",
")",
"*",
"BulkDocument",
"{",
"b",
":=",
"&",
"BulkDocument",
"{",
"}",
"\n",
"b",
".",
"db",
"=",
"db",
"\n",
"return",
"b",
"\n",
"}"
] | // NewBulkDocument New BulkDocument instance | [
"NewBulkDocument",
"New",
"BulkDocument",
"instance"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/bulk_docs.go#L52-L56 |
137,071 | rhinoman/couchdb-go | bulk_docs.go | Save | func (b *BulkDocument) Save(doc interface{}, id, rev string) error {
if id == "" {
return fmt.Errorf("No ID specified")
}
b.docs = append(b.docs, bulkDoc{id, rev, false, doc})
return nil
} | go | func (b *BulkDocument) Save(doc interface{}, id, rev string) error {
if id == "" {
return fmt.Errorf("No ID specified")
}
b.docs = append(b.docs, bulkDoc{id, rev, false, doc})
return nil
} | [
"func",
"(",
"b",
"*",
"BulkDocument",
")",
"Save",
"(",
"doc",
"interface",
"{",
"}",
",",
"id",
",",
"rev",
"string",
")",
"error",
"{",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",... | // Save Save document | [
"Save",
"Save",
"document"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/bulk_docs.go#L59-L65 |
137,072 | rhinoman/couchdb-go | bulk_docs.go | Delete | func (b *BulkDocument) Delete(id, rev string) error {
if id == "" {
return fmt.Errorf("No ID specified")
}
if rev == "" {
return fmt.Errorf("No Revision specified")
}
b.docs = append(b.docs, bulkDoc{id, rev, true, nil})
return nil
} | go | func (b *BulkDocument) Delete(id, rev string) error {
if id == "" {
return fmt.Errorf("No ID specified")
}
if rev == "" {
return fmt.Errorf("No Revision specified")
}
b.docs = append(b.docs, bulkDoc{id, rev, true, nil})
return nil
} | [
"func",
"(",
"b",
"*",
"BulkDocument",
")",
"Delete",
"(",
"id",
",",
"rev",
"string",
")",
"error",
"{",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"rev",
"==",
"\"",
"\"",
... | // Delete Delete document | [
"Delete",
"Delete",
"document"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/bulk_docs.go#L68-L77 |
137,073 | rhinoman/couchdb-go | connection.go | request | func (conn *connection) request(method, path string,
body io.Reader, headers map[string]string, auth Auth) (*http.Response, error) {
req, err := http.NewRequest(method, conn.url+path, body)
//set headers
for k, v := range headers {
req.Header.Set(k, v)
}
if err != nil {
return nil, err
}
if auth != nil {
... | go | func (conn *connection) request(method, path string,
body io.Reader, headers map[string]string, auth Auth) (*http.Response, error) {
req, err := http.NewRequest(method, conn.url+path, body)
//set headers
for k, v := range headers {
req.Header.Set(k, v)
}
if err != nil {
return nil, err
}
if auth != nil {
... | [
"func",
"(",
"conn",
"*",
"connection",
")",
"request",
"(",
"method",
",",
"path",
"string",
",",
"body",
"io",
".",
"Reader",
",",
"headers",
"map",
"[",
"string",
"]",
"string",
",",
"auth",
"Auth",
")",
"(",
"*",
"http",
".",
"Response",
",",
"... | //processes a request | [
"processes",
"a",
"request"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L22-L41 |
137,074 | rhinoman/couchdb-go | connection.go | reverseProxyRequest | func (conn *connection) reverseProxyRequest(w http.ResponseWriter,
r *http.Request, path string, auth Auth) error {
target, err := url.Parse(conn.url)
if err != nil {
return err
}
if auth != nil {
auth.AddAuthHeaders(r)
}
director := func(req *http.Request) {
req.URL.Scheme = target.Scheme
req.URL.Host =... | go | func (conn *connection) reverseProxyRequest(w http.ResponseWriter,
r *http.Request, path string, auth Auth) error {
target, err := url.Parse(conn.url)
if err != nil {
return err
}
if auth != nil {
auth.AddAuthHeaders(r)
}
director := func(req *http.Request) {
req.URL.Scheme = target.Scheme
req.URL.Host =... | [
"func",
"(",
"conn",
"*",
"connection",
")",
"reverseProxyRequest",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"path",
"string",
",",
"auth",
"Auth",
")",
"error",
"{",
"target",
",",
"err",
":=",
"url",
".",
... | //Returns a result from couchdb directly to a requesting client
//Useful for downloading large files | [
"Returns",
"a",
"result",
"from",
"couchdb",
"directly",
"to",
"a",
"requesting",
"client",
"Useful",
"for",
"downloading",
"large",
"files"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L45-L62 |
137,075 | rhinoman/couchdb-go | connection.go | Error | func (err *Error) Error() string {
return fmt.Sprintf("[Error]:%v: %v %v - %v %v",
err.StatusCode, err.Method, err.URL, err.ErrorCode, err.Reason)
} | go | func (err *Error) Error() string {
return fmt.Sprintf("[Error]:%v: %v %v - %v %v",
err.StatusCode, err.Method, err.URL, err.ErrorCode, err.Reason)
} | [
"func",
"(",
"err",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
".",
"StatusCode",
",",
"err",
".",
"Method",
",",
"err",
".",
"URL",
",",
"err",
".",
"ErrorCode",
",",
"err",... | //stringify the error | [
"stringify",
"the",
"error"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L111-L114 |
137,076 | rhinoman/couchdb-go | connection.go | getRevInfo | func getRevInfo(resp *http.Response) (string, error) {
if rev := resp.Header.Get("ETag"); rev == "" {
var dbResponse struct {
Ok bool `json:"ok"`
Id string `json:"id"`
Rev string `json:"rev"`
}
// if ETag header isn't present, attempt to get the rev from the response body
// see: https://issues.ap... | go | func getRevInfo(resp *http.Response) (string, error) {
if rev := resp.Header.Get("ETag"); rev == "" {
var dbResponse struct {
Ok bool `json:"ok"`
Id string `json:"id"`
Rev string `json:"rev"`
}
// if ETag header isn't present, attempt to get the rev from the response body
// see: https://issues.ap... | [
"func",
"getRevInfo",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"rev",
":=",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"rev",
"==",
"\"",
"\"",
"{",
"var",
"dbResponse",
"stru... | //extracts rev code from header | [
"extracts",
"rev",
"code",
"from",
"header"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L117-L134 |
137,077 | rhinoman/couchdb-go | connection.go | parseBody | func parseBody(resp *http.Response, o interface{}) error {
err := json.NewDecoder(resp.Body).Decode(&o)
if err != nil {
resp.Body.Close()
return err
} else {
return resp.Body.Close()
}
} | go | func parseBody(resp *http.Response, o interface{}) error {
err := json.NewDecoder(resp.Body).Decode(&o)
if err != nil {
resp.Body.Close()
return err
} else {
return resp.Body.Close()
}
} | [
"func",
"parseBody",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"o",
"interface",
"{",
"}",
")",
"error",
"{",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"&",
"o",
")",
"\n",
"if",
"err",
"!=",... | //unmarshalls a JSON Response Body | [
"unmarshalls",
"a",
"JSON",
"Response",
"Body"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L137-L145 |
137,078 | rhinoman/couchdb-go | connection.go | parseError | func parseError(resp *http.Response) error {
var couchReply struct{ Error, Reason string }
if resp.Request.Method != "HEAD" {
err := parseBody(resp, &couchReply)
if err != nil {
return fmt.Errorf("Unknown error accessing CouchDB: %v", err)
}
}
return &Error{
StatusCode: resp.StatusCode,
URL: res... | go | func parseError(resp *http.Response) error {
var couchReply struct{ Error, Reason string }
if resp.Request.Method != "HEAD" {
err := parseBody(resp, &couchReply)
if err != nil {
return fmt.Errorf("Unknown error accessing CouchDB: %v", err)
}
}
return &Error{
StatusCode: resp.StatusCode,
URL: res... | [
"func",
"parseError",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"error",
"{",
"var",
"couchReply",
"struct",
"{",
"Error",
",",
"Reason",
"string",
"}",
"\n",
"if",
"resp",
".",
"Request",
".",
"Method",
"!=",
"\"",
"\"",
"{",
"err",
":=",
"par... | //Parse a CouchDB error response | [
"Parse",
"a",
"CouchDB",
"error",
"response"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L162-L177 |
137,079 | rhinoman/couchdb-go | connection.go | buildString | func buildString(pathSegments []string) string {
pathSegments = makeSegments(pathSegments)
urlString := ""
for _, pathSegment := range pathSegments {
urlString += "/"
urlString += url.QueryEscape(pathSegment)
}
return urlString
} | go | func buildString(pathSegments []string) string {
pathSegments = makeSegments(pathSegments)
urlString := ""
for _, pathSegment := range pathSegments {
urlString += "/"
urlString += url.QueryEscape(pathSegment)
}
return urlString
} | [
"func",
"buildString",
"(",
"pathSegments",
"[",
"]",
"string",
")",
"string",
"{",
"pathSegments",
"=",
"makeSegments",
"(",
"pathSegments",
")",
"\n",
"urlString",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"pathSegment",
":=",
"range",
"pathSegments",
"{",
... | //smooshes url segments together | [
"smooshes",
"url",
"segments",
"together"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L180-L188 |
137,080 | rhinoman/couchdb-go | connection.go | buildParamUrl | func buildParamUrl(params url.Values, pathSegments ...string) (string, error) {
var Url *url.URL
urlString := buildString(pathSegments)
Url, err := url.Parse(urlString)
if err != nil {
return "", err
}
Url.RawQuery = params.Encode()
return Url.String(), nil
} | go | func buildParamUrl(params url.Values, pathSegments ...string) (string, error) {
var Url *url.URL
urlString := buildString(pathSegments)
Url, err := url.Parse(urlString)
if err != nil {
return "", err
}
Url.RawQuery = params.Encode()
return Url.String(), nil
} | [
"func",
"buildParamUrl",
"(",
"params",
"url",
".",
"Values",
",",
"pathSegments",
"...",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"Url",
"*",
"url",
".",
"URL",
"\n",
"urlString",
":=",
"buildString",
"(",
"pathSegments",
")",
"\n",
... | //Build Url with query arguments | [
"Build",
"Url",
"with",
"query",
"arguments"
] | 310a5a9beb662138d34cc3e2d510824047e58553 | https://github.com/rhinoman/couchdb-go/blob/310a5a9beb662138d34cc3e2d510824047e58553/connection.go#L210-L219 |
137,081 | eaburns/flac | decode.go | Decode | func Decode(r io.Reader) ([]byte, MetaData, error) {
d, err := NewDecoder(r)
if err != nil {
return nil, MetaData{}, err
}
data := make([]byte, 0, d.TotalSamples*int64(d.NChannels)*int64(d.BitsPerSample/8))
for {
frame, err := d.Next()
if err == io.EOF {
break
} else if err != nil {
return nil, Meta... | go | func Decode(r io.Reader) ([]byte, MetaData, error) {
d, err := NewDecoder(r)
if err != nil {
return nil, MetaData{}, err
}
data := make([]byte, 0, d.TotalSamples*int64(d.NChannels)*int64(d.BitsPerSample/8))
for {
frame, err := d.Next()
if err == io.EOF {
break
} else if err != nil {
return nil, Meta... | [
"func",
"Decode",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"[",
"]",
"byte",
",",
"MetaData",
",",
"error",
")",
"{",
"d",
",",
"err",
":=",
"NewDecoder",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"MetaData",
"{"... | // Decode reads a FLAC file, decodes it, verifies its MD5 checksum, and returns the data and metadata. | [
"Decode",
"reads",
"a",
"FLAC",
"file",
"decodes",
"it",
"verifies",
"its",
"MD5",
"checksum",
"and",
"returns",
"the",
"data",
"and",
"metadata",
"."
] | 9a6fb92396d1ba6412b82819435dca0b46f959fb | https://github.com/eaburns/flac/blob/9a6fb92396d1ba6412b82819435dca0b46f959fb/decode.go#L21-L46 |
137,082 | eaburns/flac | decode.go | NewDecoder | func NewDecoder(r io.Reader) (*Decoder, error) {
err := checkMagic(r)
if err != nil {
return nil, err
}
d := &Decoder{r: r}
if d.MetaData, err = readMetaData(d.r); err != nil {
return nil, err
}
if d.StreamInfo == nil {
return nil, errors.New("Missing STREAMINFO header")
}
if d.BitsPerSample != 8 && d.... | go | func NewDecoder(r io.Reader) (*Decoder, error) {
err := checkMagic(r)
if err != nil {
return nil, err
}
d := &Decoder{r: r}
if d.MetaData, err = readMetaData(d.r); err != nil {
return nil, err
}
if d.StreamInfo == nil {
return nil, errors.New("Missing STREAMINFO header")
}
if d.BitsPerSample != 8 && d.... | [
"func",
"NewDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"*",
"Decoder",
",",
"error",
")",
"{",
"err",
":=",
"checkMagic",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"d",
":=",
"&"... | // NewDecoder reads the FLAC header information and returns a new Decoder.
// If an error is encountered while reading the header information then nil is
// returned along with the error. | [
"NewDecoder",
"reads",
"the",
"FLAC",
"header",
"information",
"and",
"returns",
"a",
"new",
"Decoder",
".",
"If",
"an",
"error",
"is",
"encountered",
"while",
"reading",
"the",
"header",
"information",
"then",
"nil",
"is",
"returned",
"along",
"with",
"the",
... | 9a6fb92396d1ba6412b82819435dca0b46f959fb | https://github.com/eaburns/flac/blob/9a6fb92396d1ba6412b82819435dca0b46f959fb/decode.go#L88-L107 |
137,083 | eaburns/flac | decode.go | Next | func (d *Decoder) Next() ([]byte, error) {
defer func() { d.n++ }()
raw := bytes.NewBuffer(nil)
frame := io.TeeReader(d.r, raw)
h, err := readFrameHeader(frame, d.StreamInfo)
if err == io.EOF {
return nil, err
} else if err != nil {
return nil, errors.New("Failed to read the frame header: " + err.Error())
}... | go | func (d *Decoder) Next() ([]byte, error) {
defer func() { d.n++ }()
raw := bytes.NewBuffer(nil)
frame := io.TeeReader(d.r, raw)
h, err := readFrameHeader(frame, d.StreamInfo)
if err == io.EOF {
return nil, err
} else if err != nil {
return nil, errors.New("Failed to read the frame header: " + err.Error())
}... | [
"func",
"(",
"d",
"*",
"Decoder",
")",
"Next",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"d",
".",
"n",
"++",
"}",
"(",
")",
"\n\n",
"raw",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n... | // Next returns the audio data from the next frame. | [
"Next",
"returns",
"the",
"audio",
"data",
"from",
"the",
"next",
"frame",
"."
] | 9a6fb92396d1ba6412b82819435dca0b46f959fb | https://github.com/eaburns/flac/blob/9a6fb92396d1ba6412b82819435dca0b46f959fb/decode.go#L274-L307 |
137,084 | petar/GoMNIST | util.go | ReadSet | func ReadSet(iname, lname string) (set *Set, err error) {
set = &Set{}
if set.NRow, set.NCol, set.Images, err = ReadImageFile(iname); err != nil {
return nil, err
}
if set.Labels, err = ReadLabelFile(lname); err != nil {
return nil, err
}
return
} | go | func ReadSet(iname, lname string) (set *Set, err error) {
set = &Set{}
if set.NRow, set.NCol, set.Images, err = ReadImageFile(iname); err != nil {
return nil, err
}
if set.Labels, err = ReadLabelFile(lname); err != nil {
return nil, err
}
return
} | [
"func",
"ReadSet",
"(",
"iname",
",",
"lname",
"string",
")",
"(",
"set",
"*",
"Set",
",",
"err",
"error",
")",
"{",
"set",
"=",
"&",
"Set",
"{",
"}",
"\n",
"if",
"set",
".",
"NRow",
",",
"set",
".",
"NCol",
",",
"set",
".",
"Images",
",",
"e... | // ReadSet reads a set from the images file iname and the corresponding labels file lname | [
"ReadSet",
"reads",
"a",
"set",
"from",
"the",
"images",
"file",
"iname",
"and",
"the",
"corresponding",
"labels",
"file",
"lname"
] | 2fbe10d0fa631498b80acb2b7d8546e5229d57b0 | https://github.com/petar/GoMNIST/blob/2fbe10d0fa631498b80acb2b7d8546e5229d57b0/util.go#L30-L39 |
137,085 | petar/GoMNIST | util.go | Get | func (s *Set) Get(i int) (RawImage, Label) {
return s.Images[i], s.Labels[i]
} | go | func (s *Set) Get(i int) (RawImage, Label) {
return s.Images[i], s.Labels[i]
} | [
"func",
"(",
"s",
"*",
"Set",
")",
"Get",
"(",
"i",
"int",
")",
"(",
"RawImage",
",",
"Label",
")",
"{",
"return",
"s",
".",
"Images",
"[",
"i",
"]",
",",
"s",
".",
"Labels",
"[",
"i",
"]",
"\n",
"}"
] | // Get returns the i-th image and its corresponding label | [
"Get",
"returns",
"the",
"i",
"-",
"th",
"image",
"and",
"its",
"corresponding",
"label"
] | 2fbe10d0fa631498b80acb2b7d8546e5229d57b0 | https://github.com/petar/GoMNIST/blob/2fbe10d0fa631498b80acb2b7d8546e5229d57b0/util.go#L47-L49 |
137,086 | petar/GoMNIST | util.go | Next | func (sw *Sweeper) Next() (image RawImage, label Label, present bool) {
if sw.i >= len(sw.set.Images) {
return nil, 0, false
}
return sw.set.Images[sw.i], sw.set.Labels[sw.i], true
} | go | func (sw *Sweeper) Next() (image RawImage, label Label, present bool) {
if sw.i >= len(sw.set.Images) {
return nil, 0, false
}
return sw.set.Images[sw.i], sw.set.Labels[sw.i], true
} | [
"func",
"(",
"sw",
"*",
"Sweeper",
")",
"Next",
"(",
")",
"(",
"image",
"RawImage",
",",
"label",
"Label",
",",
"present",
"bool",
")",
"{",
"if",
"sw",
".",
"i",
">=",
"len",
"(",
"sw",
".",
"set",
".",
"Images",
")",
"{",
"return",
"nil",
","... | // Next returns the next image and its label in the data set.
// If the end is reached, present is set to false. | [
"Next",
"returns",
"the",
"next",
"image",
"and",
"its",
"label",
"in",
"the",
"data",
"set",
".",
"If",
"the",
"end",
"is",
"reached",
"present",
"is",
"set",
"to",
"false",
"."
] | 2fbe10d0fa631498b80acb2b7d8546e5229d57b0 | https://github.com/petar/GoMNIST/blob/2fbe10d0fa631498b80acb2b7d8546e5229d57b0/util.go#L59-L64 |
137,087 | petar/GoMNIST | util.go | Load | func Load(dir string) (train, test *Set, err error) {
if train, err = ReadSet(path.Join(dir, "train-images-idx3-ubyte.gz"), path.Join(dir, "train-labels-idx1-ubyte.gz")); err != nil {
return nil, nil, err
}
if test, err = ReadSet(path.Join(dir, "t10k-images-idx3-ubyte.gz"), path.Join(dir, "t10k-labels-idx1-ubyte.g... | go | func Load(dir string) (train, test *Set, err error) {
if train, err = ReadSet(path.Join(dir, "train-images-idx3-ubyte.gz"), path.Join(dir, "train-labels-idx1-ubyte.gz")); err != nil {
return nil, nil, err
}
if test, err = ReadSet(path.Join(dir, "t10k-images-idx3-ubyte.gz"), path.Join(dir, "t10k-labels-idx1-ubyte.g... | [
"func",
"Load",
"(",
"dir",
"string",
")",
"(",
"train",
",",
"test",
"*",
"Set",
",",
"err",
"error",
")",
"{",
"if",
"train",
",",
"err",
"=",
"ReadSet",
"(",
"path",
".",
"Join",
"(",
"dir",
",",
"\"",
"\"",
")",
",",
"path",
".",
"Join",
... | // Load reads both the training and the testing MNIST data sets, given
// a local directory dir, containing the MNIST distribution files. | [
"Load",
"reads",
"both",
"the",
"training",
"and",
"the",
"testing",
"MNIST",
"data",
"sets",
"given",
"a",
"local",
"directory",
"dir",
"containing",
"the",
"MNIST",
"distribution",
"files",
"."
] | 2fbe10d0fa631498b80acb2b7d8546e5229d57b0 | https://github.com/petar/GoMNIST/blob/2fbe10d0fa631498b80acb2b7d8546e5229d57b0/util.go#L73-L81 |
137,088 | szuecs/gin-gomonitor | aspects/counter.go | CounterHandler | func CounterHandler(ca *CounterAspect) gin.HandlerFunc {
return func(ctx *gin.Context) {
ctx.Next()
ca.inc <- tuple{
path: ctx.Request.URL.Path,
code: ctx.Writer.Status(),
}
}
} | go | func CounterHandler(ca *CounterAspect) gin.HandlerFunc {
return func(ctx *gin.Context) {
ctx.Next()
ca.inc <- tuple{
path: ctx.Request.URL.Path,
code: ctx.Writer.Status(),
}
}
} | [
"func",
"CounterHandler",
"(",
"ca",
"*",
"CounterAspect",
")",
"gin",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"ctx",
"*",
"gin",
".",
"Context",
")",
"{",
"ctx",
".",
"Next",
"(",
")",
"\n",
"ca",
".",
"inc",
"<-",
"tuple",
"{",
"path",
":... | // CounterHandler is a Gin middleware function that increments a
// global counter on each request. | [
"CounterHandler",
"is",
"a",
"Gin",
"middleware",
"function",
"that",
"increments",
"a",
"global",
"counter",
"on",
"each",
"request",
"."
] | 52a62f5215c5f8058fd3745158b10db84f795d32 | https://github.com/szuecs/gin-gomonitor/blob/52a62f5215c5f8058fd3745158b10db84f795d32/aspects/counter.go#L11-L19 |
137,089 | szuecs/gin-gomonitor | aspects/counter.go | NewCounterAspect | func NewCounterAspect() *CounterAspect {
ca := &CounterAspect{}
ca.inc = make(chan tuple)
ca.internalRequestsSum = 0
ca.internalRequests = make(map[string]int, 0)
ca.internalRequestCodes = make(map[int]int, 0)
return ca
} | go | func NewCounterAspect() *CounterAspect {
ca := &CounterAspect{}
ca.inc = make(chan tuple)
ca.internalRequestsSum = 0
ca.internalRequests = make(map[string]int, 0)
ca.internalRequestCodes = make(map[int]int, 0)
return ca
} | [
"func",
"NewCounterAspect",
"(",
")",
"*",
"CounterAspect",
"{",
"ca",
":=",
"&",
"CounterAspect",
"{",
"}",
"\n",
"ca",
".",
"inc",
"=",
"make",
"(",
"chan",
"tuple",
")",
"\n",
"ca",
".",
"internalRequestsSum",
"=",
"0",
"\n",
"ca",
".",
"internalReq... | // NewCounterAspect returns a new initialized CounterAspect object. | [
"NewCounterAspect",
"returns",
"a",
"new",
"initialized",
"CounterAspect",
"object",
"."
] | 52a62f5215c5f8058fd3745158b10db84f795d32 | https://github.com/szuecs/gin-gomonitor/blob/52a62f5215c5f8058fd3745158b10db84f795d32/aspects/counter.go#L38-L45 |
137,090 | szuecs/gin-gomonitor | aspects/generic_channel.go | NewGenericChannelAspect | func NewGenericChannelAspect(name string) *GenericChannelAspect {
gc := &GenericChannelAspect{name: name}
gc.tempStore = NewDataStore()
gc.Gcd = make(map[string]GenericChannelData, 0)
return gc
} | go | func NewGenericChannelAspect(name string) *GenericChannelAspect {
gc := &GenericChannelAspect{name: name}
gc.tempStore = NewDataStore()
gc.Gcd = make(map[string]GenericChannelData, 0)
return gc
} | [
"func",
"NewGenericChannelAspect",
"(",
"name",
"string",
")",
"*",
"GenericChannelAspect",
"{",
"gc",
":=",
"&",
"GenericChannelAspect",
"{",
"name",
":",
"name",
"}",
"\n",
"gc",
".",
"tempStore",
"=",
"NewDataStore",
"(",
")",
"\n",
"gc",
".",
"Gcd",
"=... | // NewGenericChannelAspect returns a new initialized GenericChannelAspect
// object. | [
"NewGenericChannelAspect",
"returns",
"a",
"new",
"initialized",
"GenericChannelAspect",
"object",
"."
] | 52a62f5215c5f8058fd3745158b10db84f795d32 | https://github.com/szuecs/gin-gomonitor/blob/52a62f5215c5f8058fd3745158b10db84f795d32/aspects/generic_channel.go#L67-L72 |
137,091 | szuecs/gin-gomonitor | aspects/generic_channel.go | GetStats | func (gc *GenericChannelAspect) GetStats() interface{} {
gc.gcdLock.RLock()
defer gc.gcdLock.RUnlock()
var mod bytes.Buffer
enc := gob.NewEncoder(&mod)
dec := gob.NewDecoder(&mod)
err := enc.Encode(gc.Gcd)
if err != nil {
return err
}
var cpy map[string]GenericChannelData
err = dec.Decode(&cpy)
if err !... | go | func (gc *GenericChannelAspect) GetStats() interface{} {
gc.gcdLock.RLock()
defer gc.gcdLock.RUnlock()
var mod bytes.Buffer
enc := gob.NewEncoder(&mod)
dec := gob.NewDecoder(&mod)
err := enc.Encode(gc.Gcd)
if err != nil {
return err
}
var cpy map[string]GenericChannelData
err = dec.Decode(&cpy)
if err !... | [
"func",
"(",
"gc",
"*",
"GenericChannelAspect",
")",
"GetStats",
"(",
")",
"interface",
"{",
"}",
"{",
"gc",
".",
"gcdLock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"gc",
".",
"gcdLock",
".",
"RUnlock",
"(",
")",
"\n\n",
"var",
"mod",
"bytes",
".",
... | // GetStats to fulfill aspects.Aspect interface, it returns a copy of
// the calculated data set that will be served as JSON. | [
"GetStats",
"to",
"fulfill",
"aspects",
".",
"Aspect",
"interface",
"it",
"returns",
"a",
"copy",
"of",
"the",
"calculated",
"data",
"set",
"that",
"will",
"be",
"served",
"as",
"JSON",
"."
] | 52a62f5215c5f8058fd3745158b10db84f795d32 | https://github.com/szuecs/gin-gomonitor/blob/52a62f5215c5f8058fd3745158b10db84f795d32/aspects/generic_channel.go#L102-L122 |
137,092 | szuecs/gin-gomonitor | aspects/request_time.go | NewRequestTimeAspect | func NewRequestTimeAspect() *RequestTimeAspect {
rt := &RequestTimeAspect{}
rt.lastMinuteRequestTimes = make([]float64, 0)
rt.Timestamp = time.Now()
return rt
} | go | func NewRequestTimeAspect() *RequestTimeAspect {
rt := &RequestTimeAspect{}
rt.lastMinuteRequestTimes = make([]float64, 0)
rt.Timestamp = time.Now()
return rt
} | [
"func",
"NewRequestTimeAspect",
"(",
")",
"*",
"RequestTimeAspect",
"{",
"rt",
":=",
"&",
"RequestTimeAspect",
"{",
"}",
"\n",
"rt",
".",
"lastMinuteRequestTimes",
"=",
"make",
"(",
"[",
"]",
"float64",
",",
"0",
")",
"\n",
"rt",
".",
"Timestamp",
"=",
"... | // NewRequestTimeAspect returns a new initialized RequestTimeAspect
// object. | [
"NewRequestTimeAspect",
"returns",
"a",
"new",
"initialized",
"RequestTimeAspect",
"object",
"."
] | 52a62f5215c5f8058fd3745158b10db84f795d32 | https://github.com/szuecs/gin-gomonitor/blob/52a62f5215c5f8058fd3745158b10db84f795d32/aspects/request_time.go#L27-L32 |
137,093 | szuecs/gin-gomonitor | aspects/request_time.go | RequestTimeHandler | func RequestTimeHandler(rt *RequestTimeAspect) gin.HandlerFunc {
_rt := rt // save rt in closure
return func(c *gin.Context) {
now := time.Now()
c.Next()
took := time.Now().Sub(now)
_rt.add(float64(took))
}
} | go | func RequestTimeHandler(rt *RequestTimeAspect) gin.HandlerFunc {
_rt := rt // save rt in closure
return func(c *gin.Context) {
now := time.Now()
c.Next()
took := time.Now().Sub(now)
_rt.add(float64(took))
}
} | [
"func",
"RequestTimeHandler",
"(",
"rt",
"*",
"RequestTimeAspect",
")",
"gin",
".",
"HandlerFunc",
"{",
"_rt",
":=",
"rt",
"// save rt in closure",
"\n",
"return",
"func",
"(",
"c",
"*",
"gin",
".",
"Context",
")",
"{",
"now",
":=",
"time",
".",
"Now",
"... | // RequestTimeHandler is a middleware function to use in Gin | [
"RequestTimeHandler",
"is",
"a",
"middleware",
"function",
"to",
"use",
"in",
"Gin"
] | 52a62f5215c5f8058fd3745158b10db84f795d32 | https://github.com/szuecs/gin-gomonitor/blob/52a62f5215c5f8058fd3745158b10db84f795d32/aspects/request_time.go#L65-L73 |
137,094 | dselans/dmidecode | dmidecode.go | Run | func (d *DMI) Run() error {
bin, err := d.FindBin(d.Binary)
if err != nil {
return err
}
output, err := d.ExecDmidecode(bin)
if err != nil {
return err
}
return d.ParseDmidecode(output)
} | go | func (d *DMI) Run() error {
bin, err := d.FindBin(d.Binary)
if err != nil {
return err
}
output, err := d.ExecDmidecode(bin)
if err != nil {
return err
}
return d.ParseDmidecode(output)
} | [
"func",
"(",
"d",
"*",
"DMI",
")",
"Run",
"(",
")",
"error",
"{",
"bin",
",",
"err",
":=",
"d",
".",
"FindBin",
"(",
"d",
".",
"Binary",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"output",
",",
"err",
":=",... | // Run will attempt to find a a valid `dmidecode` bin, attempt to execute it and
// parse whatever data it gets. | [
"Run",
"will",
"attempt",
"to",
"find",
"a",
"a",
"valid",
"dmidecode",
"bin",
"attempt",
"to",
"execute",
"it",
"and",
"parse",
"whatever",
"data",
"it",
"gets",
"."
] | 65c3f9d819108e993ede783bdecbc7d28748cbd9 | https://github.com/dselans/dmidecode/blob/65c3f9d819108e993ede783bdecbc7d28748cbd9/dmidecode.go#L32-L44 |
137,095 | dselans/dmidecode | dmidecode.go | FindBin | func (d *DMI) FindBin(binary string) (string, error) {
locations := []string{"/sbin", "/usr/sbin", "/usr/local/sbin"}
for _, path := range locations {
lookup := path + "/" + binary
fileInfo, err := os.Stat(path + "/" + binary)
if err != nil {
continue
}
if !fileInfo.IsDir() {
return lookup, nil
}... | go | func (d *DMI) FindBin(binary string) (string, error) {
locations := []string{"/sbin", "/usr/sbin", "/usr/local/sbin"}
for _, path := range locations {
lookup := path + "/" + binary
fileInfo, err := os.Stat(path + "/" + binary)
if err != nil {
continue
}
if !fileInfo.IsDir() {
return lookup, nil
}... | [
"func",
"(",
"d",
"*",
"DMI",
")",
"FindBin",
"(",
"binary",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"locations",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n\n",
"for",
"_",
",",
"path",
... | // FindBin will attempt to find a given binary in common bin paths. | [
"FindBin",
"will",
"attempt",
"to",
"find",
"a",
"given",
"binary",
"in",
"common",
"bin",
"paths",
"."
] | 65c3f9d819108e993ede783bdecbc7d28748cbd9 | https://github.com/dselans/dmidecode/blob/65c3f9d819108e993ede783bdecbc7d28748cbd9/dmidecode.go#L47-L64 |
137,096 | dselans/dmidecode | dmidecode.go | ParseDmidecode | func (d *DMI) ParseDmidecode(output string) error {
// Each record is separated by double newlines
splitOutput := strings.Split(output, "\n\n")
for _, record := range splitOutput {
recordElements := strings.Split(record, "\n")
// Entries with less than 3 lines are incomplete/inactive; skip them
if len(record... | go | func (d *DMI) ParseDmidecode(output string) error {
// Each record is separated by double newlines
splitOutput := strings.Split(output, "\n\n")
for _, record := range splitOutput {
recordElements := strings.Split(record, "\n")
// Entries with less than 3 lines are incomplete/inactive; skip them
if len(record... | [
"func",
"(",
"d",
"*",
"DMI",
")",
"ParseDmidecode",
"(",
"output",
"string",
")",
"error",
"{",
"// Each record is separated by double newlines",
"splitOutput",
":=",
"strings",
".",
"Split",
"(",
"output",
",",
"\"",
"\\n",
"\\n",
"\"",
")",
"\n\n",
"for",
... | // ParseDmiDecode will attempt to parse dmidecode output and place all matching
// content in d.Data. | [
"ParseDmiDecode",
"will",
"attempt",
"to",
"parse",
"dmidecode",
"output",
"and",
"place",
"all",
"matching",
"content",
"in",
"d",
".",
"Data",
"."
] | 65c3f9d819108e993ede783bdecbc7d28748cbd9 | https://github.com/dselans/dmidecode/blob/65c3f9d819108e993ede783bdecbc7d28748cbd9/dmidecode.go#L81-L163 |
137,097 | dselans/dmidecode | dmidecode.go | SearchByName | func (d *DMI) SearchByName(name string) ([]Record, error) {
return d.GenericSearchBy("DMIName", name)
} | go | func (d *DMI) SearchByName(name string) ([]Record, error) {
return d.GenericSearchBy("DMIName", name)
} | [
"func",
"(",
"d",
"*",
"DMI",
")",
"SearchByName",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"Record",
",",
"error",
")",
"{",
"return",
"d",
".",
"GenericSearchBy",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // SearchByName will search for a specific DMI record by name in d.Data | [
"SearchByName",
"will",
"search",
"for",
"a",
"specific",
"DMI",
"record",
"by",
"name",
"in",
"d",
".",
"Data"
] | 65c3f9d819108e993ede783bdecbc7d28748cbd9 | https://github.com/dselans/dmidecode/blob/65c3f9d819108e993ede783bdecbc7d28748cbd9/dmidecode.go#L187-L189 |
137,098 | dselans/dmidecode | dmidecode.go | SearchByType | func (d *DMI) SearchByType(id int) ([]Record, error) {
return d.GenericSearchBy("DMIType", strconv.Itoa(id))
} | go | func (d *DMI) SearchByType(id int) ([]Record, error) {
return d.GenericSearchBy("DMIType", strconv.Itoa(id))
} | [
"func",
"(",
"d",
"*",
"DMI",
")",
"SearchByType",
"(",
"id",
"int",
")",
"(",
"[",
"]",
"Record",
",",
"error",
")",
"{",
"return",
"d",
".",
"GenericSearchBy",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"id",
")",
")",
"\n",
"}"
] | // SearchByType will search for a specific DMI record by its type in d.Data | [
"SearchByType",
"will",
"search",
"for",
"a",
"specific",
"DMI",
"record",
"by",
"its",
"type",
"in",
"d",
".",
"Data"
] | 65c3f9d819108e993ede783bdecbc7d28748cbd9 | https://github.com/dselans/dmidecode/blob/65c3f9d819108e993ede783bdecbc7d28748cbd9/dmidecode.go#L192-L194 |
137,099 | danryan/hal | adapter.go | NewAdapter | func NewAdapter(robot *Robot) (Adapter, error) {
name := Config.AdapterName
if _, ok := AvailableAdapters[name]; !ok {
return nil, fmt.Errorf("%s is not a registered adapter", Config.AdapterName)
}
adapter, err := AvailableAdapters[name].newFunc(robot)
if err != nil {
return nil, err
}
return adapter, nil
} | go | func NewAdapter(robot *Robot) (Adapter, error) {
name := Config.AdapterName
if _, ok := AvailableAdapters[name]; !ok {
return nil, fmt.Errorf("%s is not a registered adapter", Config.AdapterName)
}
adapter, err := AvailableAdapters[name].newFunc(robot)
if err != nil {
return nil, err
}
return adapter, nil
} | [
"func",
"NewAdapter",
"(",
"robot",
"*",
"Robot",
")",
"(",
"Adapter",
",",
"error",
")",
"{",
"name",
":=",
"Config",
".",
"AdapterName",
"\n",
"if",
"_",
",",
"ok",
":=",
"AvailableAdapters",
"[",
"name",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
... | // NewAdapter creates a new initialized adapter | [
"NewAdapter",
"creates",
"a",
"new",
"initialized",
"adapter"
] | c4a180833c0b8fd4f4f5c6fcaa611b8cb72c23c7 | https://github.com/danryan/hal/blob/c4a180833c0b8fd4f4f5c6fcaa611b8cb72c23c7/adapter.go#L34-L45 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.