id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
131,800 | Fs02/grimoire | query.go | Select | func (query Query) Select(fields ...string) Query {
query.Fields = fields
return query
} | go | func (query Query) Select(fields ...string) Query {
query.Fields = fields
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Select",
"(",
"fields",
"...",
"string",
")",
"Query",
"{",
"query",
".",
"Fields",
"=",
"fields",
"\n",
"return",
"query",
"\n",
"}"
] | // Select filter fields to be selected from database. | [
"Select",
"filter",
"fields",
"to",
"be",
"selected",
"from",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L35-L38 |
131,801 | Fs02/grimoire | query.go | Join | func (query Query) Join(collection string, condition ...c.Condition) Query {
return query.JoinWith("JOIN", collection, condition...)
} | go | func (query Query) Join(collection string, condition ...c.Condition) Query {
return query.JoinWith("JOIN", collection, condition...)
} | [
"func",
"(",
"query",
"Query",
")",
"Join",
"(",
"collection",
"string",
",",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"return",
"query",
".",
"JoinWith",
"(",
"\"",
"\"",
",",
"collection",
",",
"condition",
"...",
")",
"\n",
"}"
... | // Join current collection with other collection. | [
"Join",
"current",
"collection",
"with",
"other",
"collection",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L47-L49 |
131,802 | Fs02/grimoire | query.go | JoinWith | func (query Query) JoinWith(mode string, collection string, condition ...c.Condition) Query {
if len(condition) == 0 {
query.JoinClause = append(query.JoinClause, c.Join{
Mode: mode,
Collection: collection,
Condition: c.And(c.Eq(
c.I(query.Collection+"."+strings.TrimSuffix(collection, "s")+"_id"),... | go | func (query Query) JoinWith(mode string, collection string, condition ...c.Condition) Query {
if len(condition) == 0 {
query.JoinClause = append(query.JoinClause, c.Join{
Mode: mode,
Collection: collection,
Condition: c.And(c.Eq(
c.I(query.Collection+"."+strings.TrimSuffix(collection, "s")+"_id"),... | [
"func",
"(",
"query",
"Query",
")",
"JoinWith",
"(",
"mode",
"string",
",",
"collection",
"string",
",",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"if",
"len",
"(",
"condition",
")",
"==",
"0",
"{",
"query",
".",
"JoinClause",
"=",
... | // JoinWith current collection with other collection with custom join mode. | [
"JoinWith",
"current",
"collection",
"with",
"other",
"collection",
"with",
"custom",
"join",
"mode",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L52-L71 |
131,803 | Fs02/grimoire | query.go | Where | func (query Query) Where(condition ...c.Condition) Query {
query.Condition = query.Condition.And(condition...)
return query
} | go | func (query Query) Where(condition ...c.Condition) Query {
query.Condition = query.Condition.And(condition...)
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Where",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"Condition",
"=",
"query",
".",
"Condition",
".",
"And",
"(",
"condition",
"...",
")",
"\n",
"return",
"query",
"\n",
"}"
] | // Where expressions are used to filter the result set. If there is more than one where expression, they are combined with an and operator. | [
"Where",
"expressions",
"are",
"used",
"to",
"filter",
"the",
"result",
"set",
".",
"If",
"there",
"is",
"more",
"than",
"one",
"where",
"expression",
"they",
"are",
"combined",
"with",
"an",
"and",
"operator",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L74-L77 |
131,804 | Fs02/grimoire | query.go | OrWhere | func (query Query) OrWhere(condition ...c.Condition) Query {
query.Condition = query.Condition.Or(c.And(condition...))
return query
} | go | func (query Query) OrWhere(condition ...c.Condition) Query {
query.Condition = query.Condition.Or(c.And(condition...))
return query
} | [
"func",
"(",
"query",
"Query",
")",
"OrWhere",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"Condition",
"=",
"query",
".",
"Condition",
".",
"Or",
"(",
"c",
".",
"And",
"(",
"condition",
"...",
")",
")",
"\n",
"... | // OrWhere behaves exactly the same as where except it combines with any previous expression by using an OR. | [
"OrWhere",
"behaves",
"exactly",
"the",
"same",
"as",
"where",
"except",
"it",
"combines",
"with",
"any",
"previous",
"expression",
"by",
"using",
"an",
"OR",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L80-L83 |
131,805 | Fs02/grimoire | query.go | Group | func (query Query) Group(fields ...string) Query {
query.GroupFields = fields
return query
} | go | func (query Query) Group(fields ...string) Query {
query.GroupFields = fields
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Group",
"(",
"fields",
"...",
"string",
")",
"Query",
"{",
"query",
".",
"GroupFields",
"=",
"fields",
"\n",
"return",
"query",
"\n",
"}"
] | // Group query using fields. | [
"Group",
"query",
"using",
"fields",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L86-L89 |
131,806 | Fs02/grimoire | query.go | Having | func (query Query) Having(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.And(condition...)
return query
} | go | func (query Query) Having(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.And(condition...)
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Having",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"HavingCondition",
"=",
"query",
".",
"HavingCondition",
".",
"And",
"(",
"condition",
"...",
")",
"\n",
"return",
"query",
"\n... | // Having adds condition for group query. | [
"Having",
"adds",
"condition",
"for",
"group",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L92-L95 |
131,807 | Fs02/grimoire | query.go | OrHaving | func (query Query) OrHaving(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.Or(c.And(condition...))
return query
} | go | func (query Query) OrHaving(condition ...c.Condition) Query {
query.HavingCondition = query.HavingCondition.Or(c.And(condition...))
return query
} | [
"func",
"(",
"query",
"Query",
")",
"OrHaving",
"(",
"condition",
"...",
"c",
".",
"Condition",
")",
"Query",
"{",
"query",
".",
"HavingCondition",
"=",
"query",
".",
"HavingCondition",
".",
"Or",
"(",
"c",
".",
"And",
"(",
"condition",
"...",
")",
")"... | // OrHaving behaves exactly the same as having except it combines with any previous expression by using an OR. | [
"OrHaving",
"behaves",
"exactly",
"the",
"same",
"as",
"having",
"except",
"it",
"combines",
"with",
"any",
"previous",
"expression",
"by",
"using",
"an",
"OR",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L98-L101 |
131,808 | Fs02/grimoire | query.go | Order | func (query Query) Order(order ...c.Order) Query {
query.OrderClause = append(query.OrderClause, order...)
return query
} | go | func (query Query) Order(order ...c.Order) Query {
query.OrderClause = append(query.OrderClause, order...)
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Order",
"(",
"order",
"...",
"c",
".",
"Order",
")",
"Query",
"{",
"query",
".",
"OrderClause",
"=",
"append",
"(",
"query",
".",
"OrderClause",
",",
"order",
"...",
")",
"\n",
"return",
"query",
"\n",
"}"
] | // Order the result returned by database. | [
"Order",
"the",
"result",
"returned",
"by",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L104-L107 |
131,809 | Fs02/grimoire | query.go | Offset | func (query Query) Offset(offset int) Query {
query.OffsetResult = offset
return query
} | go | func (query Query) Offset(offset int) Query {
query.OffsetResult = offset
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Offset",
"(",
"offset",
"int",
")",
"Query",
"{",
"query",
".",
"OffsetResult",
"=",
"offset",
"\n",
"return",
"query",
"\n",
"}"
] | // Offset the result returned by database. | [
"Offset",
"the",
"result",
"returned",
"by",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L110-L113 |
131,810 | Fs02/grimoire | query.go | Limit | func (query Query) Limit(limit int) Query {
query.LimitResult = limit
return query
} | go | func (query Query) Limit(limit int) Query {
query.LimitResult = limit
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Limit",
"(",
"limit",
"int",
")",
"Query",
"{",
"query",
".",
"LimitResult",
"=",
"limit",
"\n",
"return",
"query",
"\n",
"}"
] | // Limit result returned by database. | [
"Limit",
"result",
"returned",
"by",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L116-L119 |
131,811 | Fs02/grimoire | query.go | Lock | func (query Query) Lock(lock ...string) Query {
if !query.repo.inTransaction {
return query
}
if len(lock) > 0 {
query.LockClause = lock[0]
} else {
query.LockClause = "FOR UPDATE"
}
return query
} | go | func (query Query) Lock(lock ...string) Query {
if !query.repo.inTransaction {
return query
}
if len(lock) > 0 {
query.LockClause = lock[0]
} else {
query.LockClause = "FOR UPDATE"
}
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Lock",
"(",
"lock",
"...",
"string",
")",
"Query",
"{",
"if",
"!",
"query",
".",
"repo",
".",
"inTransaction",
"{",
"return",
"query",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"lock",
")",
">",
"0",
"{",
"query",
... | // Lock query using pessimistic locking.
// Lock expression can be specified as first parameter, default to FOR UPDATE. | [
"Lock",
"query",
"using",
"pessimistic",
"locking",
".",
"Lock",
"expression",
"can",
"be",
"specified",
"as",
"first",
"parameter",
"default",
"to",
"FOR",
"UPDATE",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L123-L135 |
131,812 | Fs02/grimoire | query.go | FindBy | func (query Query) FindBy(col string, val interface{}) Query {
return query.Where(c.Eq(c.I(query.Collection+"."+col), val))
} | go | func (query Query) FindBy(col string, val interface{}) Query {
return query.Where(c.Eq(c.I(query.Collection+"."+col), val))
} | [
"func",
"(",
"query",
"Query",
")",
"FindBy",
"(",
"col",
"string",
",",
"val",
"interface",
"{",
"}",
")",
"Query",
"{",
"return",
"query",
".",
"Where",
"(",
"c",
".",
"Eq",
"(",
"c",
".",
"I",
"(",
"query",
".",
"Collection",
"+",
"\"",
"\"",
... | // FindBy adds where col=? into query. | [
"FindBy",
"adds",
"where",
"col",
"=",
"?",
"into",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L144-L146 |
131,813 | Fs02/grimoire | query.go | Set | func (query Query) Set(field string, value interface{}) Query {
if query.Changes == nil {
query.Changes = make(map[string]interface{})
}
query.Changes[field] = value
return query
} | go | func (query Query) Set(field string, value interface{}) Query {
if query.Changes == nil {
query.Changes = make(map[string]interface{})
}
query.Changes[field] = value
return query
} | [
"func",
"(",
"query",
"Query",
")",
"Set",
"(",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
")",
"Query",
"{",
"if",
"query",
".",
"Changes",
"==",
"nil",
"{",
"query",
".",
"Changes",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"inter... | // Set value for insert or update operation that will replace changeset value. | [
"Set",
"value",
"for",
"insert",
"or",
"update",
"operation",
"that",
"will",
"replace",
"changeset",
"value",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L149-L156 |
131,814 | Fs02/grimoire | query.go | One | func (query Query) One(record interface{}) error {
query.LimitResult = 1
count, err := query.repo.adapter.All(query, record, query.repo.logger...)
if err != nil {
return transformError(err)
} else if count == 0 {
return errors.New("no result found", "", errors.NotFound)
} else {
return nil
}
} | go | func (query Query) One(record interface{}) error {
query.LimitResult = 1
count, err := query.repo.adapter.All(query, record, query.repo.logger...)
if err != nil {
return transformError(err)
} else if count == 0 {
return errors.New("no result found", "", errors.NotFound)
} else {
return nil
}
} | [
"func",
"(",
"query",
"Query",
")",
"One",
"(",
"record",
"interface",
"{",
"}",
")",
"error",
"{",
"query",
".",
"LimitResult",
"=",
"1",
"\n",
"count",
",",
"err",
":=",
"query",
".",
"repo",
".",
"adapter",
".",
"All",
"(",
"query",
",",
"record... | // One retrieves one result that match the query.
// If no result found, it'll return not found error. | [
"One",
"retrieves",
"one",
"result",
"that",
"match",
"the",
"query",
".",
"If",
"no",
"result",
"found",
"it",
"ll",
"return",
"not",
"found",
"error",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L160-L171 |
131,815 | Fs02/grimoire | query.go | All | func (query Query) All(record interface{}) error {
_, err := query.repo.adapter.All(query, record, query.repo.logger...)
return err
} | go | func (query Query) All(record interface{}) error {
_, err := query.repo.adapter.All(query, record, query.repo.logger...)
return err
} | [
"func",
"(",
"query",
"Query",
")",
"All",
"(",
"record",
"interface",
"{",
"}",
")",
"error",
"{",
"_",
",",
"err",
":=",
"query",
".",
"repo",
".",
"adapter",
".",
"All",
"(",
"query",
",",
"record",
",",
"query",
".",
"repo",
".",
"logger",
".... | // All retrieves all results that match the query. | [
"All",
"retrieves",
"all",
"results",
"that",
"match",
"the",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L180-L183 |
131,816 | Fs02/grimoire | query.go | Aggregate | func (query Query) Aggregate(mode string, field string, out interface{}) error {
query.AggregateMode = mode
query.AggregateField = field
return query.repo.adapter.Aggregate(query, out, query.repo.logger...)
} | go | func (query Query) Aggregate(mode string, field string, out interface{}) error {
query.AggregateMode = mode
query.AggregateField = field
return query.repo.adapter.Aggregate(query, out, query.repo.logger...)
} | [
"func",
"(",
"query",
"Query",
")",
"Aggregate",
"(",
"mode",
"string",
",",
"field",
"string",
",",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"query",
".",
"AggregateMode",
"=",
"mode",
"\n",
"query",
".",
"AggregateField",
"=",
"field",
"\n",
... | // Aggregate calculate aggregate over the given field. | [
"Aggregate",
"calculate",
"aggregate",
"over",
"the",
"given",
"field",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L192-L196 |
131,817 | Fs02/grimoire | query.go | MustAggregate | func (query Query) MustAggregate(mode string, field string, out interface{}) {
must(query.Aggregate(mode, field, out))
} | go | func (query Query) MustAggregate(mode string, field string, out interface{}) {
must(query.Aggregate(mode, field, out))
} | [
"func",
"(",
"query",
"Query",
")",
"MustAggregate",
"(",
"mode",
"string",
",",
"field",
"string",
",",
"out",
"interface",
"{",
"}",
")",
"{",
"must",
"(",
"query",
".",
"Aggregate",
"(",
"mode",
",",
"field",
",",
"out",
")",
")",
"\n",
"}"
] | // MustAggregate calculate aggregate over the given field.
// It'll panic if any error eccured. | [
"MustAggregate",
"calculate",
"aggregate",
"over",
"the",
"given",
"field",
".",
"It",
"ll",
"panic",
"if",
"any",
"error",
"eccured",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L200-L202 |
131,818 | Fs02/grimoire | query.go | Count | func (query Query) Count() (int, error) {
var out struct {
Count int
}
err := query.Aggregate("count", "*", &out)
return out.Count, err
} | go | func (query Query) Count() (int, error) {
var out struct {
Count int
}
err := query.Aggregate("count", "*", &out)
return out.Count, err
} | [
"func",
"(",
"query",
"Query",
")",
"Count",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"out",
"struct",
"{",
"Count",
"int",
"\n",
"}",
"\n\n",
"err",
":=",
"query",
".",
"Aggregate",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"out"... | // Count retrieves count of results that match the query. | [
"Count",
"retrieves",
"count",
"of",
"results",
"that",
"match",
"the",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L205-L212 |
131,819 | Fs02/grimoire | query.go | MustCount | func (query Query) MustCount() int {
count, err := query.Count()
must(err)
return count
} | go | func (query Query) MustCount() int {
count, err := query.Count()
must(err)
return count
} | [
"func",
"(",
"query",
"Query",
")",
"MustCount",
"(",
")",
"int",
"{",
"count",
",",
"err",
":=",
"query",
".",
"Count",
"(",
")",
"\n",
"must",
"(",
"err",
")",
"\n",
"return",
"count",
"\n",
"}"
] | // MustCount retrieves count of results that match the query.
// It'll panic if any error eccured. | [
"MustCount",
"retrieves",
"count",
"of",
"results",
"that",
"match",
"the",
"query",
".",
"It",
"ll",
"panic",
"if",
"any",
"error",
"eccured",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L216-L220 |
131,820 | Fs02/grimoire | query.go | Insert | func (query Query) Insert(record interface{}, chs ...*changeset.Changeset) error {
var err error
var ids []interface{}
if len(chs) == 1 {
// single insert
ch := chs[0]
changes := make(map[string]interface{})
cloneChangeset(changes, ch.Changes())
putTimestamp(changes, "created_at", ch.Types())
putTimesta... | go | func (query Query) Insert(record interface{}, chs ...*changeset.Changeset) error {
var err error
var ids []interface{}
if len(chs) == 1 {
// single insert
ch := chs[0]
changes := make(map[string]interface{})
cloneChangeset(changes, ch.Changes())
putTimestamp(changes, "created_at", ch.Types())
putTimesta... | [
"func",
"(",
"query",
"Query",
")",
"Insert",
"(",
"record",
"interface",
"{",
"}",
",",
"chs",
"...",
"*",
"changeset",
".",
"Changeset",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"var",
"ids",
"[",
"]",
"interface",
"{",
"}",
"\n\n",
"if",
... | // Insert records to database. | [
"Insert",
"records",
"to",
"database",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L223-L271 |
131,821 | Fs02/grimoire | query.go | MustInsert | func (query Query) MustInsert(record interface{}, chs ...*changeset.Changeset) {
must(query.Insert(record, chs...))
} | go | func (query Query) MustInsert(record interface{}, chs ...*changeset.Changeset) {
must(query.Insert(record, chs...))
} | [
"func",
"(",
"query",
"Query",
")",
"MustInsert",
"(",
"record",
"interface",
"{",
"}",
",",
"chs",
"...",
"*",
"changeset",
".",
"Changeset",
")",
"{",
"must",
"(",
"query",
".",
"Insert",
"(",
"record",
",",
"chs",
"...",
")",
")",
"\n",
"}"
] | // MustInsert records to database.
// It'll panic if any error occurred. | [
"MustInsert",
"records",
"to",
"database",
".",
"It",
"ll",
"panic",
"if",
"any",
"error",
"occurred",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L275-L277 |
131,822 | Fs02/grimoire | query.go | Update | func (query Query) Update(record interface{}, chs ...*changeset.Changeset) error {
changes := make(map[string]interface{})
// only take the first changeset if any
if len(chs) != 0 {
cloneChangeset(changes, chs[0].Changes())
putTimestamp(changes, "updated_at", chs[0].Types())
}
cloneQuery(changes, query.Chang... | go | func (query Query) Update(record interface{}, chs ...*changeset.Changeset) error {
changes := make(map[string]interface{})
// only take the first changeset if any
if len(chs) != 0 {
cloneChangeset(changes, chs[0].Changes())
putTimestamp(changes, "updated_at", chs[0].Types())
}
cloneQuery(changes, query.Chang... | [
"func",
"(",
"query",
"Query",
")",
"Update",
"(",
"record",
"interface",
"{",
"}",
",",
"chs",
"...",
"*",
"changeset",
".",
"Changeset",
")",
"error",
"{",
"changes",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n\n",... | // Update records in database.
// It'll panic if any error occurred. | [
"Update",
"records",
"in",
"database",
".",
"It",
"ll",
"panic",
"if",
"any",
"error",
"occurred",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L281-L309 |
131,823 | Fs02/grimoire | query.go | MustUpdate | func (query Query) MustUpdate(record interface{}, chs ...*changeset.Changeset) {
must(query.Update(record, chs...))
} | go | func (query Query) MustUpdate(record interface{}, chs ...*changeset.Changeset) {
must(query.Update(record, chs...))
} | [
"func",
"(",
"query",
"Query",
")",
"MustUpdate",
"(",
"record",
"interface",
"{",
"}",
",",
"chs",
"...",
"*",
"changeset",
".",
"Changeset",
")",
"{",
"must",
"(",
"query",
".",
"Update",
"(",
"record",
",",
"chs",
"...",
")",
")",
"\n",
"}"
] | // MustUpdate records in database.
// It'll panic if any error occurred. | [
"MustUpdate",
"records",
"in",
"database",
".",
"It",
"ll",
"panic",
"if",
"any",
"error",
"occurred",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L313-L315 |
131,824 | Fs02/grimoire | query.go | Save | func (query Query) Save(record interface{}) error {
rv := reflect.ValueOf(record)
rt := rv.Type()
if rt.Kind() == reflect.Ptr && rt.Elem().Kind() == reflect.Slice {
// Put multiple records
rv = rv.Elem()
// if it's an empty slice, do nothing
if rv.Len() == 0 {
return nil
}
if query.Condition.None() ... | go | func (query Query) Save(record interface{}) error {
rv := reflect.ValueOf(record)
rt := rv.Type()
if rt.Kind() == reflect.Ptr && rt.Elem().Kind() == reflect.Slice {
// Put multiple records
rv = rv.Elem()
// if it's an empty slice, do nothing
if rv.Len() == 0 {
return nil
}
if query.Condition.None() ... | [
"func",
"(",
"query",
"Query",
")",
"Save",
"(",
"record",
"interface",
"{",
"}",
")",
"error",
"{",
"rv",
":=",
"reflect",
".",
"ValueOf",
"(",
"record",
")",
"\n",
"rt",
":=",
"rv",
".",
"Type",
"(",
")",
"\n",
"if",
"rt",
".",
"Kind",
"(",
"... | // Save a record to database.
// If condition exist, it will try to update the record, otherwise it'll insert it.
// Save ignores id from record. | [
"Save",
"a",
"record",
"to",
"database",
".",
"If",
"condition",
"exist",
"it",
"will",
"try",
"to",
"update",
"the",
"record",
"otherwise",
"it",
"ll",
"insert",
"it",
".",
"Save",
"ignores",
"id",
"from",
"record",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L373-L417 |
131,825 | Fs02/grimoire | query.go | Delete | func (query Query) Delete() error {
return transformError(query.repo.adapter.Delete(query, query.repo.logger...))
} | go | func (query Query) Delete() error {
return transformError(query.repo.adapter.Delete(query, query.repo.logger...))
} | [
"func",
"(",
"query",
"Query",
")",
"Delete",
"(",
")",
"error",
"{",
"return",
"transformError",
"(",
"query",
".",
"repo",
".",
"adapter",
".",
"Delete",
"(",
"query",
",",
"query",
".",
"repo",
".",
"logger",
"...",
")",
")",
"\n",
"}"
] | // Delete deletes all results that match the query. | [
"Delete",
"deletes",
"all",
"results",
"that",
"match",
"the",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L426-L428 |
131,826 | Fs02/grimoire | query.go | Preload | func (query Query) Preload(record interface{}, field string) error {
path := strings.Split(field, ".")
rv := reflect.ValueOf(record)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
panic("grimoire: record parameter must be a pointer.")
}
preload := traversePreloadTarget(rv.Elem(), path)
if len(preload) == 0 {
r... | go | func (query Query) Preload(record interface{}, field string) error {
path := strings.Split(field, ".")
rv := reflect.ValueOf(record)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
panic("grimoire: record parameter must be a pointer.")
}
preload := traversePreloadTarget(rv.Elem(), path)
if len(preload) == 0 {
r... | [
"func",
"(",
"query",
"Query",
")",
"Preload",
"(",
"record",
"interface",
"{",
"}",
",",
"field",
"string",
")",
"error",
"{",
"path",
":=",
"strings",
".",
"Split",
"(",
"field",
",",
"\"",
"\"",
")",
"\n\n",
"rv",
":=",
"reflect",
".",
"ValueOf",
... | // Preload loads association with given query. | [
"Preload",
"loads",
"association",
"with",
"given",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L442-L499 |
131,827 | Fs02/grimoire | query.go | MustPreload | func (query Query) MustPreload(record interface{}, field string) {
must(query.Preload(record, field))
} | go | func (query Query) MustPreload(record interface{}, field string) {
must(query.Preload(record, field))
} | [
"func",
"(",
"query",
"Query",
")",
"MustPreload",
"(",
"record",
"interface",
"{",
"}",
",",
"field",
"string",
")",
"{",
"must",
"(",
"query",
".",
"Preload",
"(",
"record",
",",
"field",
")",
")",
"\n",
"}"
] | // MustPreload loads association with given query.
// It'll panic if any error occurred. | [
"MustPreload",
"loads",
"association",
"with",
"given",
"query",
".",
"It",
"ll",
"panic",
"if",
"any",
"error",
"occurred",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/query.go#L503-L505 |
131,828 | Fs02/grimoire | errors/errors.go | New | func New(message string, field string, kind Kind) Error {
return Error{message, field, 0, kind}
} | go | func New(message string, field string, kind Kind) Error {
return Error{message, field, 0, kind}
} | [
"func",
"New",
"(",
"message",
"string",
",",
"field",
"string",
",",
"kind",
"Kind",
")",
"Error",
"{",
"return",
"Error",
"{",
"message",
",",
"field",
",",
"0",
",",
"kind",
"}",
"\n",
"}"
] | // New creates an error. | [
"New",
"creates",
"an",
"error",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/errors/errors.go#L34-L36 |
131,829 | Fs02/grimoire | errors/errors.go | NewWithCode | func NewWithCode(message string, field string, code int, kind Kind) Error {
return Error{message, field, code, kind}
} | go | func NewWithCode(message string, field string, code int, kind Kind) Error {
return Error{message, field, code, kind}
} | [
"func",
"NewWithCode",
"(",
"message",
"string",
",",
"field",
"string",
",",
"code",
"int",
",",
"kind",
"Kind",
")",
"Error",
"{",
"return",
"Error",
"{",
"message",
",",
"field",
",",
"code",
",",
"kind",
"}",
"\n",
"}"
] | // NewWithCode creates an error with code. | [
"NewWithCode",
"creates",
"an",
"error",
"with",
"code",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/errors/errors.go#L39-L41 |
131,830 | Fs02/grimoire | changeset/unique_constraint.go | UniqueConstraint | func UniqueConstraint(ch *Changeset, field string, opts ...Option) {
options := Options{
message: UniqueConstraintMessage,
name: field,
exact: false,
}
options.apply(opts)
ch.constraints = append(ch.constraints, Constraint{
Field: field,
Message: strings.Replace(options.message, "{field}", field, ... | go | func UniqueConstraint(ch *Changeset, field string, opts ...Option) {
options := Options{
message: UniqueConstraintMessage,
name: field,
exact: false,
}
options.apply(opts)
ch.constraints = append(ch.constraints, Constraint{
Field: field,
Message: strings.Replace(options.message, "{field}", field, ... | [
"func",
"UniqueConstraint",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"opts",
"...",
"Option",
")",
"{",
"options",
":=",
"Options",
"{",
"message",
":",
"UniqueConstraintMessage",
",",
"name",
":",
"field",
",",
"exact",
":",
"false",
",",... | // UniqueConstraint adds an unique constraint to changeset. | [
"UniqueConstraint",
"adds",
"an",
"unique",
"constraint",
"to",
"changeset",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/unique_constraint.go#L13-L29 |
131,831 | Fs02/grimoire | changeset/put_assoc.go | PutAssoc | func PutAssoc(ch *Changeset, field string, value interface{}, opts ...Option) {
options := Options{
message: PutAssocErrorMessage,
}
options.apply(opts)
if typ, exist := ch.types[field]; exist {
if typ.Kind() == reflect.Struct {
valTyp := reflect.TypeOf(value)
if valTyp == reflect.TypeOf(ch) {
ch.chan... | go | func PutAssoc(ch *Changeset, field string, value interface{}, opts ...Option) {
options := Options{
message: PutAssocErrorMessage,
}
options.apply(opts)
if typ, exist := ch.types[field]; exist {
if typ.Kind() == reflect.Struct {
valTyp := reflect.TypeOf(value)
if valTyp == reflect.TypeOf(ch) {
ch.chan... | [
"func",
"PutAssoc",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"opts",
"...",
"Option",
")",
"{",
"options",
":=",
"Options",
"{",
"message",
":",
"PutAssocErrorMessage",
",",
"}",
"\n",
"options",
".",... | // PutAssoc to changeset. | [
"PutAssoc",
"to",
"changeset",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/put_assoc.go#L12-L34 |
131,832 | Fs02/grimoire | adapter/specs/constraint.go | UniqueConstraint | func UniqueConstraint(t *testing.T, repo grimoire.Repo) {
extra1 := Extra{}
extra2 := Extra{}
repo.From(extras).Set("slug", "slug1").MustInsert(&extra1)
repo.From(extras).Set("slug", "slug2").MustInsert(&extra2)
t.Run("UniqueConstraint", func(t *testing.T) {
// inserting
err := repo.From(extras).Set("slug", e... | go | func UniqueConstraint(t *testing.T, repo grimoire.Repo) {
extra1 := Extra{}
extra2 := Extra{}
repo.From(extras).Set("slug", "slug1").MustInsert(&extra1)
repo.From(extras).Set("slug", "slug2").MustInsert(&extra2)
t.Run("UniqueConstraint", func(t *testing.T) {
// inserting
err := repo.From(extras).Set("slug", e... | [
"func",
"UniqueConstraint",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"extra1",
":=",
"Extra",
"{",
"}",
"\n",
"extra2",
":=",
"Extra",
"{",
"}",
"\n",
"repo",
".",
"From",
"(",
"extras",
")",
".",
"Set",
... | // UniqueConstraint tests unique constraint specifications. | [
"UniqueConstraint",
"tests",
"unique",
"constraint",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/constraint.go#L11-L26 |
131,833 | Fs02/grimoire | adapter/specs/constraint.go | ForeignKeyConstraint | func ForeignKeyConstraint(t *testing.T, repo grimoire.Repo) {
extra := Extra{}
repo.From(extras).MustSave(&extra)
t.Run("ForeignKeyConstraint", func(t *testing.T) {
// inserting
err := repo.From(extras).Set("user_id", 1000).Insert(nil)
assertConstraint(t, err, errors.ForeignKeyConstraint, "user_id")
// upd... | go | func ForeignKeyConstraint(t *testing.T, repo grimoire.Repo) {
extra := Extra{}
repo.From(extras).MustSave(&extra)
t.Run("ForeignKeyConstraint", func(t *testing.T) {
// inserting
err := repo.From(extras).Set("user_id", 1000).Insert(nil)
assertConstraint(t, err, errors.ForeignKeyConstraint, "user_id")
// upd... | [
"func",
"ForeignKeyConstraint",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"extra",
":=",
"Extra",
"{",
"}",
"\n",
"repo",
".",
"From",
"(",
"extras",
")",
".",
"MustSave",
"(",
"&",
"extra",
")",
"\n\n",
"t... | // ForeignKeyConstraint tests foreign key constraint specifications. | [
"ForeignKeyConstraint",
"tests",
"foreign",
"key",
"constraint",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/constraint.go#L29-L42 |
131,834 | Fs02/grimoire | adapter/sql/scan.go | Scan | func Scan(value interface{}, rows Rows) (int64, error) {
columns, err := rows.Columns()
if err != nil {
return 0, err
}
rv := reflect.ValueOf(value)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
panic("grimoire: record parameter must be a pointer")
}
count := int64(0)
rv = rv.Elem()
var index map[string]in... | go | func Scan(value interface{}, rows Rows) (int64, error) {
columns, err := rows.Columns()
if err != nil {
return 0, err
}
rv := reflect.ValueOf(value)
if rv.Kind() != reflect.Ptr || rv.IsNil() {
panic("grimoire: record parameter must be a pointer")
}
count := int64(0)
rv = rv.Elem()
var index map[string]in... | [
"func",
"Scan",
"(",
"value",
"interface",
"{",
"}",
",",
"rows",
"Rows",
")",
"(",
"int64",
",",
"error",
")",
"{",
"columns",
",",
"err",
":=",
"rows",
".",
"Columns",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
... | // Scan rows into interface | [
"Scan",
"rows",
"into",
"interface"
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/scan.go#L21-L84 |
131,835 | Fs02/grimoire | changeset/unescape_string.go | UnescapeString | func UnescapeString(ch *Changeset, field string) {
ApplyString(ch, field, html.UnescapeString)
} | go | func UnescapeString(ch *Changeset, field string) {
ApplyString(ch, field, html.UnescapeString)
} | [
"func",
"UnescapeString",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
")",
"{",
"ApplyString",
"(",
"ch",
",",
"field",
",",
"html",
".",
"UnescapeString",
")",
"\n",
"}"
] | // UnescapeString unescapes entities like "<" to become "<". this is helper for html.UnescapeString. | [
"UnescapeString",
"unescapes",
"entities",
"like",
"<",
";",
"to",
"become",
"<",
".",
"this",
"is",
"helper",
"for",
"html",
".",
"UnescapeString",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/unescape_string.go#L8-L10 |
131,836 | Fs02/grimoire | changeset/put_default.go | PutDefault | func PutDefault(ch *Changeset, field string, value interface{}, opts ...Option) {
options := Options{
message: PutDefaultErrorMessage,
}
options.apply(opts)
if typ, exist := ch.types[field]; exist {
valTyp := reflect.TypeOf(value)
if valTyp.ConvertibleTo(typ) {
if ch.changes[field] == nil {
ch.changes... | go | func PutDefault(ch *Changeset, field string, value interface{}, opts ...Option) {
options := Options{
message: PutDefaultErrorMessage,
}
options.apply(opts)
if typ, exist := ch.types[field]; exist {
valTyp := reflect.TypeOf(value)
if valTyp.ConvertibleTo(typ) {
if ch.changes[field] == nil {
ch.changes... | [
"func",
"PutDefault",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"value",
"interface",
"{",
"}",
",",
"opts",
"...",
"Option",
")",
"{",
"options",
":=",
"Options",
"{",
"message",
":",
"PutDefaultErrorMessage",
",",
"}",
"\n",
"options",
... | // PutDefault to changeset. | [
"PutDefault",
"to",
"changeset",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/put_default.go#L12-L30 |
131,837 | Fs02/grimoire | changeset/constraint.go | GetError | func (constraints Constraints) GetError(err errors.Error) error {
if err.Kind() == errors.Unexpected || err.Kind() == errors.Changeset || err.Kind() == errors.NotFound {
return err
}
for _, c := range constraints {
if c.Kind == err.Kind() {
if c.Exact && c.Name != err.Field {
continue
}
if !c.Exac... | go | func (constraints Constraints) GetError(err errors.Error) error {
if err.Kind() == errors.Unexpected || err.Kind() == errors.Changeset || err.Kind() == errors.NotFound {
return err
}
for _, c := range constraints {
if c.Kind == err.Kind() {
if c.Exact && c.Name != err.Field {
continue
}
if !c.Exac... | [
"func",
"(",
"constraints",
"Constraints",
")",
"GetError",
"(",
"err",
"errors",
".",
"Error",
")",
"error",
"{",
"if",
"err",
".",
"Kind",
"(",
")",
"==",
"errors",
".",
"Unexpected",
"||",
"err",
".",
"Kind",
"(",
")",
"==",
"errors",
".",
"Change... | // GetError converts error based on constraints.
// If the original error is constraint error, and it's defined in the constraint list, then it'll be updated with constraint's message.
// If the original error is constraint error but not defined in the constraint list, it'll be converted to unexpected error.
// else it... | [
"GetError",
"converts",
"error",
"based",
"on",
"constraints",
".",
"If",
"the",
"original",
"error",
"is",
"constraint",
"error",
"and",
"it",
"s",
"defined",
"in",
"the",
"constraint",
"list",
"then",
"it",
"ll",
"be",
"updated",
"with",
"constraint",
"s",... | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/constraint.go#L27-L47 |
131,838 | Fs02/grimoire | adapter/specs/save.go | SaveInsert | func SaveInsert(t *testing.T, repo grimoire.Repo) {
tests := []grimoire.Query{
repo.From(users),
}
for _, query := range tests {
record := User{Name: "save insert", Age: 100}
t.Run("SaveInsert", func(t *testing.T) {
assert.Nil(t, query.Save(&record))
var result User
assert.Nil(t, query.Find(record.... | go | func SaveInsert(t *testing.T, repo grimoire.Repo) {
tests := []grimoire.Query{
repo.From(users),
}
for _, query := range tests {
record := User{Name: "save insert", Age: 100}
t.Run("SaveInsert", func(t *testing.T) {
assert.Nil(t, query.Save(&record))
var result User
assert.Nil(t, query.Find(record.... | [
"func",
"SaveInsert",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"tests",
":=",
"[",
"]",
"grimoire",
".",
"Query",
"{",
"repo",
".",
"From",
"(",
"users",
")",
",",
"}",
"\n\n",
"for",
"_",
",",
"query",
... | // SaveInsert tests insert specifications. | [
"SaveInsert",
"tests",
"insert",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/save.go#L12-L28 |
131,839 | Fs02/grimoire | adapter/specs/save.go | SaveInsertAll | func SaveInsertAll(t *testing.T, repo grimoire.Repo) {
tests := []grimoire.Query{
repo.From(users),
}
for _, query := range tests {
records := []User{
{Name: "save insert all 1", Age: 100},
{Name: "save insert all 2", Age: 100},
}
t.Run("SaveInsertAll", func(t *testing.T) {
assert.Nil(t, query.Sav... | go | func SaveInsertAll(t *testing.T, repo grimoire.Repo) {
tests := []grimoire.Query{
repo.From(users),
}
for _, query := range tests {
records := []User{
{Name: "save insert all 1", Age: 100},
{Name: "save insert all 2", Age: 100},
}
t.Run("SaveInsertAll", func(t *testing.T) {
assert.Nil(t, query.Sav... | [
"func",
"SaveInsertAll",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"tests",
":=",
"[",
"]",
"grimoire",
".",
"Query",
"{",
"repo",
".",
"From",
"(",
"users",
")",
",",
"}",
"\n\n",
"for",
"_",
",",
"query... | // SaveInsertAll tests insert multiple recors specifications. | [
"SaveInsertAll",
"tests",
"insert",
"multiple",
"recors",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/save.go#L31-L46 |
131,840 | Fs02/grimoire | params/form.go | ParseForm | func ParseForm(raw url.Values) Form {
result := make(Form, len(raw))
for k, v := range raw {
if len(v) == 0 {
continue
}
fields := strings.FieldsFunc(k, fieldsExtractor)
pfield, cfield := "", ""
form := result
for i := range fields {
pfield = cfield
cfield = fields[i]
if index, err := strc... | go | func ParseForm(raw url.Values) Form {
result := make(Form, len(raw))
for k, v := range raw {
if len(v) == 0 {
continue
}
fields := strings.FieldsFunc(k, fieldsExtractor)
pfield, cfield := "", ""
form := result
for i := range fields {
pfield = cfield
cfield = fields[i]
if index, err := strc... | [
"func",
"ParseForm",
"(",
"raw",
"url",
".",
"Values",
")",
"Form",
"{",
"result",
":=",
"make",
"(",
"Form",
",",
"len",
"(",
"raw",
")",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"raw",
"{",
"if",
"len",
"(",
"v",
")",
"==",
"0",
"{... | // ParseForm form from url values. | [
"ParseForm",
"form",
"from",
"url",
"values",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/params/form.go#L215-L254 |
131,841 | Fs02/grimoire | adapter/mysql/mysql.go | Open | func Open(dsn string) (*Adapter, error) {
var err error
adapter := &Adapter{
Adapter: &sql.Adapter{
Config: &sql.Config{
Placeholder: "?",
EscapeChar: "`",
IncrementFunc: incrementFunc,
ErrorFunc: errorFunc,
},
},
}
adapter.DB, err = db.Open("mysql", dsn)
return adapter, err
} | go | func Open(dsn string) (*Adapter, error) {
var err error
adapter := &Adapter{
Adapter: &sql.Adapter{
Config: &sql.Config{
Placeholder: "?",
EscapeChar: "`",
IncrementFunc: incrementFunc,
ErrorFunc: errorFunc,
},
},
}
adapter.DB, err = db.Open("mysql", dsn)
return adapter, err
} | [
"func",
"Open",
"(",
"dsn",
"string",
")",
"(",
"*",
"Adapter",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"adapter",
":=",
"&",
"Adapter",
"{",
"Adapter",
":",
"&",
"sql",
".",
"Adapter",
"{",
"Config",
":",
"&",
"sql",
".",
"Config",
... | // Open mysql connection using dsn. | [
"Open",
"mysql",
"connection",
"using",
"dsn",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/mysql/mysql.go#L34-L50 |
131,842 | Fs02/grimoire | changeset/validate_regexp.go | ValidateRegexp | func ValidateRegexp(ch *Changeset, field string, exp *regexp.Regexp, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateRegexpErrorMessage,
}
options.apply(opts)
if str, ok := val.(string); ok {
match := exp.MatchString(str)
if !match {
msg :=... | go | func ValidateRegexp(ch *Changeset, field string, exp *regexp.Regexp, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidateRegexpErrorMessage,
}
options.apply(opts)
if str, ok := val.(string); ok {
match := exp.MatchString(str)
if !match {
msg :=... | [
"func",
"ValidateRegexp",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"exp",
"*",
"regexp",
".",
"Regexp",
",",
"opts",
"...",
"Option",
")",
"{",
"val",
",",
"exist",
":=",
"ch",
".",
"changes",
"[",
"field",
"]",
"\n",
"if",
"!",
"e... | // ValidateRegexp validates the value of given field to match given regexp. | [
"ValidateRegexp",
"validates",
"the",
"value",
"of",
"given",
"field",
"to",
"match",
"given",
"regexp",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/validate_regexp.go#L12-L31 |
131,843 | Fs02/grimoire | adapter/specs/update.go | UpdateWhere | func UpdateWhere(t *testing.T, repo grimoire.Repo) {
user := User{Name: "update all"}
repo.From(users).MustSave(&user)
address := Address{Address: "update all"}
repo.From(addresses).MustSave(&address)
tests := []struct {
query grimoire.Query
schema interface{}
record interface{}
params params.Params
}{... | go | func UpdateWhere(t *testing.T, repo grimoire.Repo) {
user := User{Name: "update all"}
repo.From(users).MustSave(&user)
address := Address{Address: "update all"}
repo.From(addresses).MustSave(&address)
tests := []struct {
query grimoire.Query
schema interface{}
record interface{}
params params.Params
}{... | [
"func",
"UpdateWhere",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"user",
":=",
"User",
"{",
"Name",
":",
"\"",
"\"",
"}",
"\n",
"repo",
".",
"From",
"(",
"users",
")",
".",
"MustSave",
"(",
"&",
"user",
... | // UpdateWhere tests update specifications. | [
"UpdateWhere",
"tests",
"update",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/update.go#L48-L76 |
131,844 | Fs02/grimoire | adapter/specs/update.go | UpdateSet | func UpdateSet(t *testing.T, repo grimoire.Repo) {
user := User{Name: "update"}
repo.From(users).MustSave(&user)
address := Address{Address: "update"}
repo.From(addresses).MustSave(&address)
tests := []struct {
query grimoire.Query
record interface{}
}{
{repo.From(users).Find(user.ID).Set("name", "update... | go | func UpdateSet(t *testing.T, repo grimoire.Repo) {
user := User{Name: "update"}
repo.From(users).MustSave(&user)
address := Address{Address: "update"}
repo.From(addresses).MustSave(&address)
tests := []struct {
query grimoire.Query
record interface{}
}{
{repo.From(users).Find(user.ID).Set("name", "update... | [
"func",
"UpdateSet",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"user",
":=",
"User",
"{",
"Name",
":",
"\"",
"\"",
"}",
"\n",
"repo",
".",
"From",
"(",
"users",
")",
".",
"MustSave",
"(",
"&",
"user",
"... | // UpdateSet tests update specifications using Set query. | [
"UpdateSet",
"tests",
"update",
"specifications",
"using",
"Set",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/update.go#L79-L105 |
131,845 | Fs02/grimoire | adapter/specs/insert.go | Insert | func Insert(t *testing.T, repo grimoire.Repo) {
user := User{}
repo.From(users).MustSave(&user)
tests := []struct {
query grimoire.Query
record interface{}
input params.Params
}{
{repo.From(users), &User{}, params.Map{}},
{repo.From(users), &User{}, params.Map{"name": "insert", "age": 100}},
{repo.Fr... | go | func Insert(t *testing.T, repo grimoire.Repo) {
user := User{}
repo.From(users).MustSave(&user)
tests := []struct {
query grimoire.Query
record interface{}
input params.Params
}{
{repo.From(users), &User{}, params.Map{}},
{repo.From(users), &User{}, params.Map{"name": "insert", "age": 100}},
{repo.Fr... | [
"func",
"Insert",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"user",
":=",
"User",
"{",
"}",
"\n",
"repo",
".",
"From",
"(",
"users",
")",
".",
"MustSave",
"(",
"&",
"user",
")",
"\n\n",
"tests",
":=",
"... | // Insert tests insert specifications. | [
"Insert",
"tests",
"insert",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/insert.go#L15-L48 |
131,846 | Fs02/grimoire | adapter/specs/insert.go | InsertSet | func InsertSet(t *testing.T, repo grimoire.Repo) {
user := User{}
repo.From(users).MustSave(&user)
now := time.Now()
tests := []struct {
query grimoire.Query
record interface{}
}{
{repo.From(users).Set("created_at", now).Set("updated_at", now).Set("name", "insert set"), &User{}},
{repo.From(users).Set("c... | go | func InsertSet(t *testing.T, repo grimoire.Repo) {
user := User{}
repo.From(users).MustSave(&user)
now := time.Now()
tests := []struct {
query grimoire.Query
record interface{}
}{
{repo.From(users).Set("created_at", now).Set("updated_at", now).Set("name", "insert set"), &User{}},
{repo.From(users).Set("c... | [
"func",
"InsertSet",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"user",
":=",
"User",
"{",
"}",
"\n",
"repo",
".",
"From",
"(",
"users",
")",
".",
"MustSave",
"(",
"&",
"user",
")",
"\n",
"now",
":=",
"t... | // InsertSet tests insert specifications only using Set query. | [
"InsertSet",
"tests",
"insert",
"specifications",
"only",
"using",
"Set",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/insert.go#L86-L112 |
131,847 | Fs02/grimoire | adapter/sql/sql.go | All | func (adapter *Adapter) All(query grimoire.Query, doc interface{}, loggers ...grimoire.Logger) (int, error) {
statement, args := NewBuilder(adapter.Config).Find(query)
count, err := adapter.Query(doc, statement, args, loggers...)
return int(count), err
} | go | func (adapter *Adapter) All(query grimoire.Query, doc interface{}, loggers ...grimoire.Logger) (int, error) {
statement, args := NewBuilder(adapter.Config).Find(query)
count, err := adapter.Query(doc, statement, args, loggers...)
return int(count), err
} | [
"func",
"(",
"adapter",
"*",
"Adapter",
")",
"All",
"(",
"query",
"grimoire",
".",
"Query",
",",
"doc",
"interface",
"{",
"}",
",",
"loggers",
"...",
"grimoire",
".",
"Logger",
")",
"(",
"int",
",",
"error",
")",
"{",
"statement",
",",
"args",
":=",
... | // All retrieves all record that match the query. | [
"All",
"retrieves",
"all",
"record",
"that",
"match",
"the",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/sql.go#L39-L43 |
131,848 | Fs02/grimoire | adapter/sql/sql.go | Aggregate | func (adapter *Adapter) Aggregate(query grimoire.Query, doc interface{}, loggers ...grimoire.Logger) error {
statement, args := NewBuilder(adapter.Config).Aggregate(query)
_, err := adapter.Query(doc, statement, args, loggers...)
return err
} | go | func (adapter *Adapter) Aggregate(query grimoire.Query, doc interface{}, loggers ...grimoire.Logger) error {
statement, args := NewBuilder(adapter.Config).Aggregate(query)
_, err := adapter.Query(doc, statement, args, loggers...)
return err
} | [
"func",
"(",
"adapter",
"*",
"Adapter",
")",
"Aggregate",
"(",
"query",
"grimoire",
".",
"Query",
",",
"doc",
"interface",
"{",
"}",
",",
"loggers",
"...",
"grimoire",
".",
"Logger",
")",
"error",
"{",
"statement",
",",
"args",
":=",
"NewBuilder",
"(",
... | // Aggregate record using given query. | [
"Aggregate",
"record",
"using",
"given",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/sql.go#L46-L50 |
131,849 | Fs02/grimoire | adapter/sql/sql.go | InsertAll | func (adapter *Adapter) InsertAll(query grimoire.Query, fields []string, allchanges []map[string]interface{}, loggers ...grimoire.Logger) ([]interface{}, error) {
statement, args := NewBuilder(adapter.Config).InsertAll(query.Collection, fields, allchanges)
id, _, err := adapter.Exec(statement, args, loggers...)
if e... | go | func (adapter *Adapter) InsertAll(query grimoire.Query, fields []string, allchanges []map[string]interface{}, loggers ...grimoire.Logger) ([]interface{}, error) {
statement, args := NewBuilder(adapter.Config).InsertAll(query.Collection, fields, allchanges)
id, _, err := adapter.Exec(statement, args, loggers...)
if e... | [
"func",
"(",
"adapter",
"*",
"Adapter",
")",
"InsertAll",
"(",
"query",
"grimoire",
".",
"Query",
",",
"fields",
"[",
"]",
"string",
",",
"allchanges",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"loggers",
"...",
"grimoire",
".",
... | // InsertAll inserts all record to database and returns its ids. | [
"InsertAll",
"inserts",
"all",
"record",
"to",
"database",
"and",
"returns",
"its",
"ids",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/sql.go#L60-L79 |
131,850 | Fs02/grimoire | adapter/sql/sql.go | Commit | func (adapter *Adapter) Commit() error {
var err error
if adapter.Tx == nil {
err = errors.NewUnexpected("unable to commit outside transaction")
} else if adapter.savepoint > 0 {
_, _, err = adapter.Exec("RELEASE SAVEPOINT s"+strconv.Itoa(adapter.savepoint)+";", []interface{}{})
} else {
err = adapter.Tx.Com... | go | func (adapter *Adapter) Commit() error {
var err error
if adapter.Tx == nil {
err = errors.NewUnexpected("unable to commit outside transaction")
} else if adapter.savepoint > 0 {
_, _, err = adapter.Exec("RELEASE SAVEPOINT s"+strconv.Itoa(adapter.savepoint)+";", []interface{}{})
} else {
err = adapter.Tx.Com... | [
"func",
"(",
"adapter",
"*",
"Adapter",
")",
"Commit",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"adapter",
".",
"Tx",
"==",
"nil",
"{",
"err",
"=",
"errors",
".",
"NewUnexpected",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
... | // Commit commits current transaction. | [
"Commit",
"commits",
"current",
"transaction",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/sql.go#L117-L129 |
131,851 | Fs02/grimoire | adapter/sql/sql.go | Query | func (adapter *Adapter) Query(out interface{}, statement string, args []interface{}, loggers ...grimoire.Logger) (int64, error) {
var rows *sql.Rows
var err error
start := time.Now()
if adapter.Tx != nil {
rows, err = adapter.Tx.Query(statement, args...)
} else {
rows, err = adapter.DB.Query(statement, args..... | go | func (adapter *Adapter) Query(out interface{}, statement string, args []interface{}, loggers ...grimoire.Logger) (int64, error) {
var rows *sql.Rows
var err error
start := time.Now()
if adapter.Tx != nil {
rows, err = adapter.Tx.Query(statement, args...)
} else {
rows, err = adapter.DB.Query(statement, args..... | [
"func",
"(",
"adapter",
"*",
"Adapter",
")",
"Query",
"(",
"out",
"interface",
"{",
"}",
",",
"statement",
"string",
",",
"args",
"[",
"]",
"interface",
"{",
"}",
",",
"loggers",
"...",
"grimoire",
".",
"Logger",
")",
"(",
"int64",
",",
"error",
")",... | // Query performs query operation. | [
"Query",
"performs",
"query",
"operation",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/sql.go#L147-L166 |
131,852 | Fs02/grimoire | adapter/sql/sql.go | Exec | func (adapter *Adapter) Exec(statement string, args []interface{}, loggers ...grimoire.Logger) (int64, int64, error) {
var res sql.Result
var err error
start := time.Now()
if adapter.Tx != nil {
res, err = adapter.Tx.Exec(statement, args...)
} else {
res, err = adapter.DB.Exec(statement, args...)
}
go grimo... | go | func (adapter *Adapter) Exec(statement string, args []interface{}, loggers ...grimoire.Logger) (int64, int64, error) {
var res sql.Result
var err error
start := time.Now()
if adapter.Tx != nil {
res, err = adapter.Tx.Exec(statement, args...)
} else {
res, err = adapter.DB.Exec(statement, args...)
}
go grimo... | [
"func",
"(",
"adapter",
"*",
"Adapter",
")",
"Exec",
"(",
"statement",
"string",
",",
"args",
"[",
"]",
"interface",
"{",
"}",
",",
"loggers",
"...",
"grimoire",
".",
"Logger",
")",
"(",
"int64",
",",
"int64",
",",
"error",
")",
"{",
"var",
"res",
... | // Exec performs exec operation. | [
"Exec",
"performs",
"exec",
"operation",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/sql.go#L169-L189 |
131,853 | Fs02/grimoire | changeset/escape_string.go | EscapeString | func EscapeString(ch *Changeset, fields ...string) {
for _, field := range fields {
ApplyString(ch, field, html.EscapeString)
}
} | go | func EscapeString(ch *Changeset, fields ...string) {
for _, field := range fields {
ApplyString(ch, field, html.EscapeString)
}
} | [
"func",
"EscapeString",
"(",
"ch",
"*",
"Changeset",
",",
"fields",
"...",
"string",
")",
"{",
"for",
"_",
",",
"field",
":=",
"range",
"fields",
"{",
"ApplyString",
"(",
"ch",
",",
"field",
",",
"html",
".",
"EscapeString",
")",
"\n",
"}",
"\n",
"}"... | // EscapeString escapes special characters like "<" to become "<". this is helper for html.EscapeString | [
"EscapeString",
"escapes",
"special",
"characters",
"like",
"<",
"to",
"become",
"<",
";",
".",
"this",
"is",
"helper",
"for",
"html",
".",
"EscapeString"
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/escape_string.go#L8-L12 |
131,854 | Fs02/grimoire | adapter/specs/preload.go | Preload | func Preload(t *testing.T, repo grimoire.Repo) {
// preparte tests data
user := User{Name: "preload", Gender: "male", Age: 10}
repo.From(users).MustSave(&user)
userAddresses := []Address{
{Address: "preload1", UserID: &user.ID},
{Address: "preload2", UserID: &user.ID},
{Address: "preload3", UserID: &user.ID}... | go | func Preload(t *testing.T, repo grimoire.Repo) {
// preparte tests data
user := User{Name: "preload", Gender: "male", Age: 10}
repo.From(users).MustSave(&user)
userAddresses := []Address{
{Address: "preload1", UserID: &user.ID},
{Address: "preload2", UserID: &user.ID},
{Address: "preload3", UserID: &user.ID}... | [
"func",
"Preload",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"// preparte tests data",
"user",
":=",
"User",
"{",
"Name",
":",
"\"",
"\"",
",",
"Gender",
":",
"\"",
"\"",
",",
"Age",
":",
"10",
"}",
"\n",
... | // Preload tests query specifications for preloading. | [
"Preload",
"tests",
"query",
"specifications",
"for",
"preloading",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/preload.go#L12-L53 |
131,855 | Fs02/grimoire | logger.go | DefaultLogger | func DefaultLogger(query string, duration time.Duration, err error) {
if err != nil {
log.Print("[", duration, "] ", err, " - ", query)
} else {
log.Print("[", duration, "] OK - ", query)
}
} | go | func DefaultLogger(query string, duration time.Duration, err error) {
if err != nil {
log.Print("[", duration, "] ", err, " - ", query)
} else {
log.Print("[", duration, "] OK - ", query)
}
} | [
"func",
"DefaultLogger",
"(",
"query",
"string",
",",
"duration",
"time",
".",
"Duration",
",",
"err",
"error",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Print",
"(",
"\"",
"\"",
",",
"duration",
",",
"\"",
"\"",
",",
"err",
",",
"\"",
... | // DefaultLogger log query suing standard log library. | [
"DefaultLogger",
"log",
"query",
"suing",
"standard",
"log",
"library",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/logger.go#L12-L18 |
131,856 | Fs02/grimoire | logger.go | Log | func Log(logger []Logger, statement string, duration time.Duration, err error) {
for _, l := range logger {
l(statement, duration, err)
}
} | go | func Log(logger []Logger, statement string, duration time.Duration, err error) {
for _, l := range logger {
l(statement, duration, err)
}
} | [
"func",
"Log",
"(",
"logger",
"[",
"]",
"Logger",
",",
"statement",
"string",
",",
"duration",
"time",
".",
"Duration",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"l",
":=",
"range",
"logger",
"{",
"l",
"(",
"statement",
",",
"duration",
",",
... | // Log using multiple logger.
// This function intended to be used within adapter. | [
"Log",
"using",
"multiple",
"logger",
".",
"This",
"function",
"intended",
"to",
"be",
"used",
"within",
"adapter",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/logger.go#L22-L26 |
131,857 | Fs02/grimoire | params/json.go | Get | func (json *JSON) Get(name string) interface{} {
return json.Result.Get(name).Value()
} | go | func (json *JSON) Get(name string) interface{} {
return json.Result.Get(name).Value()
} | [
"func",
"(",
"json",
"*",
"JSON",
")",
"Get",
"(",
"name",
"string",
")",
"interface",
"{",
"}",
"{",
"return",
"json",
".",
"Result",
".",
"Get",
"(",
"name",
")",
".",
"Value",
"(",
")",
"\n",
"}"
] | // Get returns value as interface.
// returns nil if value doens't exists. | [
"Get",
"returns",
"value",
"as",
"interface",
".",
"returns",
"nil",
"if",
"value",
"doens",
"t",
"exists",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/params/json.go#L26-L28 |
131,858 | Fs02/grimoire | changeset/change.go | Change | func Change(schema interface{}, changes ...map[string]interface{}) *Changeset {
ch := &Changeset{}
ch.changes = make(map[string]interface{})
ch.values, ch.types, _ = mapSchema(schema)
if len(changes) > 0 {
ch.changes = changes[0]
} else {
ch.changes = make(map[string]interface{})
}
return ch
} | go | func Change(schema interface{}, changes ...map[string]interface{}) *Changeset {
ch := &Changeset{}
ch.changes = make(map[string]interface{})
ch.values, ch.types, _ = mapSchema(schema)
if len(changes) > 0 {
ch.changes = changes[0]
} else {
ch.changes = make(map[string]interface{})
}
return ch
} | [
"func",
"Change",
"(",
"schema",
"interface",
"{",
"}",
",",
"changes",
"...",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"*",
"Changeset",
"{",
"ch",
":=",
"&",
"Changeset",
"{",
"}",
"\n",
"ch",
".",
"changes",
"=",
"make",
"(",
"map"... | // Change make a new changeset without changes and build from given schema. Returns new Changeset. | [
"Change",
"make",
"a",
"new",
"changeset",
"without",
"changes",
"and",
"build",
"from",
"given",
"schema",
".",
"Returns",
"new",
"Changeset",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/change.go#L4-L16 |
131,859 | Fs02/grimoire | internal/extract_string.go | ExtractString | func ExtractString(s, left, right string) string {
return strings.Split(strings.Split(s, left)[1], right)[0]
} | go | func ExtractString(s, left, right string) string {
return strings.Split(strings.Split(s, left)[1], right)[0]
} | [
"func",
"ExtractString",
"(",
"s",
",",
"left",
",",
"right",
"string",
")",
"string",
"{",
"return",
"strings",
".",
"Split",
"(",
"strings",
".",
"Split",
"(",
"s",
",",
"left",
")",
"[",
"1",
"]",
",",
"right",
")",
"[",
"0",
"]",
"\n",
"}"
] | // ExtractString between two string. | [
"ExtractString",
"between",
"two",
"string",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/internal/extract_string.go#L8-L10 |
131,860 | Fs02/grimoire | adapter/specs/delete.go | Delete | func Delete(t *testing.T, repo grimoire.Repo) {
record := User{Name: "delete", Age: 100}
repo.From(users).MustSave(&record)
repo.From(users).MustSave(&User{Name: "delete", Age: 100})
repo.From(users).MustSave(&User{Name: "delete", Age: 100})
repo.From(users).MustSave(&User{Name: "other delete", Age: 110})
tests ... | go | func Delete(t *testing.T, repo grimoire.Repo) {
record := User{Name: "delete", Age: 100}
repo.From(users).MustSave(&record)
repo.From(users).MustSave(&User{Name: "delete", Age: 100})
repo.From(users).MustSave(&User{Name: "delete", Age: 100})
repo.From(users).MustSave(&User{Name: "other delete", Age: 110})
tests ... | [
"func",
"Delete",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"repo",
"grimoire",
".",
"Repo",
")",
"{",
"record",
":=",
"User",
"{",
"Name",
":",
"\"",
"\"",
",",
"Age",
":",
"100",
"}",
"\n",
"repo",
".",
"From",
"(",
"users",
")",
".",
"MustSav... | // Delete tests delete specifications. | [
"Delete",
"tests",
"delete",
"specifications",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/specs/delete.go#L12-L38 |
131,861 | Fs02/grimoire | changeset/validate_pattern.go | ValidatePattern | func ValidatePattern(ch *Changeset, field string, pattern string, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidatePatternErrorMessage,
}
options.apply(opts)
if str, ok := val.(string); ok {
match, _ := regexp.MatchString(pattern, str)
if !matc... | go | func ValidatePattern(ch *Changeset, field string, pattern string, opts ...Option) {
val, exist := ch.changes[field]
if !exist {
return
}
options := Options{
message: ValidatePatternErrorMessage,
}
options.apply(opts)
if str, ok := val.(string); ok {
match, _ := regexp.MatchString(pattern, str)
if !matc... | [
"func",
"ValidatePattern",
"(",
"ch",
"*",
"Changeset",
",",
"field",
"string",
",",
"pattern",
"string",
",",
"opts",
"...",
"Option",
")",
"{",
"val",
",",
"exist",
":=",
"ch",
".",
"changes",
"[",
"field",
"]",
"\n",
"if",
"!",
"exist",
"{",
"retu... | // ValidatePattern validates the value of given field to match given pattern. | [
"ValidatePattern",
"validates",
"the",
"value",
"of",
"given",
"field",
"to",
"match",
"given",
"pattern",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/changeset/validate_pattern.go#L12-L31 |
131,862 | Fs02/grimoire | adapter/sql/bulder.go | Find | func (builder *Builder) Find(q grimoire.Query) (string, []interface{}) {
qs, args := builder.query(q)
return builder.fields(q.AsDistinct, q.Fields...) + qs, args
} | go | func (builder *Builder) Find(q grimoire.Query) (string, []interface{}) {
qs, args := builder.query(q)
return builder.fields(q.AsDistinct, q.Fields...) + qs, args
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Find",
"(",
"q",
"grimoire",
".",
"Query",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"qs",
",",
"args",
":=",
"builder",
".",
"query",
"(",
"q",
")",
"\n",
"return",
"builder... | // Find generates query for select. | [
"Find",
"generates",
"query",
"for",
"select",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/bulder.go#L26-L29 |
131,863 | Fs02/grimoire | adapter/sql/bulder.go | Aggregate | func (builder *Builder) Aggregate(q grimoire.Query) (string, []interface{}) {
qs, args := builder.query(q)
field := q.AggregateMode + "(" + q.AggregateField + ") AS " + q.AggregateMode
return builder.fields(false, append(q.GroupFields, field)...) + qs, args
} | go | func (builder *Builder) Aggregate(q grimoire.Query) (string, []interface{}) {
qs, args := builder.query(q)
field := q.AggregateMode + "(" + q.AggregateField + ") AS " + q.AggregateMode
return builder.fields(false, append(q.GroupFields, field)...) + qs, args
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Aggregate",
"(",
"q",
"grimoire",
".",
"Query",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"qs",
",",
"args",
":=",
"builder",
".",
"query",
"(",
"q",
")",
"\n",
"field",
":="... | // Aggregate generates query for aggregation. | [
"Aggregate",
"generates",
"query",
"for",
"aggregation",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/bulder.go#L32-L37 |
131,864 | Fs02/grimoire | adapter/sql/bulder.go | Insert | func (builder *Builder) Insert(collection string, changes map[string]interface{}) (string, []interface{}) {
length := len(changes)
var buffer bytes.Buffer
var args = make([]interface{}, 0, length)
buffer.WriteString("INSERT INTO ")
buffer.WriteString(builder.config.EscapeChar)
buffer.WriteString(collection)
bu... | go | func (builder *Builder) Insert(collection string, changes map[string]interface{}) (string, []interface{}) {
length := len(changes)
var buffer bytes.Buffer
var args = make([]interface{}, 0, length)
buffer.WriteString("INSERT INTO ")
buffer.WriteString(builder.config.EscapeChar)
buffer.WriteString(collection)
bu... | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Insert",
"(",
"collection",
"string",
",",
"changes",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"length",
":=",
"len",
"(",
"c... | // Insert generates query for insert. | [
"Insert",
"generates",
"query",
"for",
"insert",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/bulder.go#L92-L145 |
131,865 | Fs02/grimoire | adapter/sql/bulder.go | InsertAll | func (builder *Builder) InsertAll(collection string, fields []string, allchanges []map[string]interface{}) (string, []interface{}) {
var buffer bytes.Buffer
var args = make([]interface{}, 0, len(fields)*len(allchanges))
buffer.WriteString("INSERT INTO ")
buffer.WriteString(builder.config.EscapeChar)
buffer.Write... | go | func (builder *Builder) InsertAll(collection string, fields []string, allchanges []map[string]interface{}) (string, []interface{}) {
var buffer bytes.Buffer
var args = make([]interface{}, 0, len(fields)*len(allchanges))
buffer.WriteString("INSERT INTO ")
buffer.WriteString(builder.config.EscapeChar)
buffer.Write... | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"InsertAll",
"(",
"collection",
"string",
",",
"fields",
"[",
"]",
"string",
",",
"allchanges",
"[",
"]",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"... | // InsertAll generates query for multiple insert. | [
"InsertAll",
"generates",
"query",
"for",
"multiple",
"insert",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/bulder.go#L148-L199 |
131,866 | Fs02/grimoire | adapter/sql/bulder.go | Update | func (builder *Builder) Update(collection string, changes map[string]interface{}, cond c.Condition) (string, []interface{}) {
length := len(changes)
var buffer bytes.Buffer
var args = make([]interface{}, 0, length)
buffer.WriteString("UPDATE ")
buffer.WriteString(builder.config.EscapeChar)
buffer.WriteString(co... | go | func (builder *Builder) Update(collection string, changes map[string]interface{}, cond c.Condition) (string, []interface{}) {
length := len(changes)
var buffer bytes.Buffer
var args = make([]interface{}, 0, length)
buffer.WriteString("UPDATE ")
buffer.WriteString(builder.config.EscapeChar)
buffer.WriteString(co... | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Update",
"(",
"collection",
"string",
",",
"changes",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"cond",
"c",
".",
"Condition",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
")",
... | // Update generates query for update. | [
"Update",
"generates",
"query",
"for",
"update",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/bulder.go#L202-L239 |
131,867 | Fs02/grimoire | adapter/sql/bulder.go | Delete | func (builder *Builder) Delete(collection string, cond c.Condition) (string, []interface{}) {
var buffer bytes.Buffer
var args []interface{}
buffer.WriteString("DELETE FROM ")
buffer.WriteString(builder.config.EscapeChar)
buffer.WriteString(collection)
buffer.WriteString(builder.config.EscapeChar)
if s, arg :=... | go | func (builder *Builder) Delete(collection string, cond c.Condition) (string, []interface{}) {
var buffer bytes.Buffer
var args []interface{}
buffer.WriteString("DELETE FROM ")
buffer.WriteString(builder.config.EscapeChar)
buffer.WriteString(collection)
buffer.WriteString(builder.config.EscapeChar)
if s, arg :=... | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Delete",
"(",
"collection",
"string",
",",
"cond",
"c",
".",
"Condition",
")",
"(",
"string",
",",
"[",
"]",
"interface",
"{",
"}",
")",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"var",
"args",
... | // Delete generates query for delete. | [
"Delete",
"generates",
"query",
"for",
"delete",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/bulder.go#L242-L260 |
131,868 | Fs02/grimoire | adapter/sql/bulder.go | Returning | func (builder *Builder) Returning(field string) *Builder {
builder.returnField = field
return builder
} | go | func (builder *Builder) Returning(field string) *Builder {
builder.returnField = field
return builder
} | [
"func",
"(",
"builder",
"*",
"Builder",
")",
"Returning",
"(",
"field",
"string",
")",
"*",
"Builder",
"{",
"builder",
".",
"returnField",
"=",
"field",
"\n",
"return",
"builder",
"\n",
"}"
] | // Returning append returning to insert query. | [
"Returning",
"append",
"returning",
"to",
"insert",
"query",
"."
] | 3299e8812ada63f878179b2b759a9f4959c8593f | https://github.com/Fs02/grimoire/blob/3299e8812ada63f878179b2b759a9f4959c8593f/adapter/sql/bulder.go#L536-L539 |
131,869 | minio/blake2b-simd | cpuid.go | haveAVX | func haveAVX() bool {
_, _, c, _ := cpuid(1)
// Check XGETBV, OXSAVE and AVX bits
if c&(1<<26) != 0 && c&(1<<27) != 0 && c&(1<<28) != 0 {
// Check for OS support
eax, _ := xgetbv(0)
return (eax & 0x6) == 0x6
}
return false
} | go | func haveAVX() bool {
_, _, c, _ := cpuid(1)
// Check XGETBV, OXSAVE and AVX bits
if c&(1<<26) != 0 && c&(1<<27) != 0 && c&(1<<28) != 0 {
// Check for OS support
eax, _ := xgetbv(0)
return (eax & 0x6) == 0x6
}
return false
} | [
"func",
"haveAVX",
"(",
")",
"bool",
"{",
"_",
",",
"_",
",",
"c",
",",
"_",
":=",
"cpuid",
"(",
"1",
")",
"\n\n",
"// Check XGETBV, OXSAVE and AVX bits",
"if",
"c",
"&",
"(",
"1",
"<<",
"26",
")",
"!=",
"0",
"&&",
"c",
"&",
"(",
"1",
"<<",
"27... | // haveAVX returns true when there is AVX support | [
"haveAVX",
"returns",
"true",
"when",
"there",
"is",
"AVX",
"support"
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/cpuid.go#L30-L40 |
131,870 | minio/blake2b-simd | cpuid.go | haveAVX2 | func haveAVX2() bool {
mfi, _, _, _ := cpuid(0)
// Check AVX2, AVX2 requires OS support, but BMI1/2 don't.
if mfi >= 7 && haveAVX() {
_, ebx, _, _ := cpuidex(7, 0)
return (ebx & 0x00000020) != 0
}
return false
} | go | func haveAVX2() bool {
mfi, _, _, _ := cpuid(0)
// Check AVX2, AVX2 requires OS support, but BMI1/2 don't.
if mfi >= 7 && haveAVX() {
_, ebx, _, _ := cpuidex(7, 0)
return (ebx & 0x00000020) != 0
}
return false
} | [
"func",
"haveAVX2",
"(",
")",
"bool",
"{",
"mfi",
",",
"_",
",",
"_",
",",
"_",
":=",
"cpuid",
"(",
"0",
")",
"\n\n",
"// Check AVX2, AVX2 requires OS support, but BMI1/2 don't.",
"if",
"mfi",
">=",
"7",
"&&",
"haveAVX",
"(",
")",
"{",
"_",
",",
"ebx",
... | // haveAVX2 returns true when there is AVX2 support | [
"haveAVX2",
"returns",
"true",
"when",
"there",
"is",
"AVX2",
"support"
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/cpuid.go#L43-L52 |
131,871 | minio/blake2b-simd | blake2b.go | New | func New(c *Config) (hash.Hash, error) {
if c == nil {
c = defaultConfig
} else {
if c.Size == 0 {
// Set default size if it's zero.
c.Size = Size
}
if err := verifyConfig(c); err != nil {
return nil, err
}
}
d := new(digest)
d.initialize(c)
return d, nil
} | go | func New(c *Config) (hash.Hash, error) {
if c == nil {
c = defaultConfig
} else {
if c.Size == 0 {
// Set default size if it's zero.
c.Size = Size
}
if err := verifyConfig(c); err != nil {
return nil, err
}
}
d := new(digest)
d.initialize(c)
return d, nil
} | [
"func",
"New",
"(",
"c",
"*",
"Config",
")",
"(",
"hash",
".",
"Hash",
",",
"error",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"c",
"=",
"defaultConfig",
"\n",
"}",
"else",
"{",
"if",
"c",
".",
"Size",
"==",
"0",
"{",
"// Set default size if it's zero... | // New returns a new hash.Hash configured with the given Config.
// Config can be nil, in which case the default one is used, calculating 64-byte digest.
// Returns non-nil error if Config contains invalid parameters. | [
"New",
"returns",
"a",
"new",
"hash",
".",
"Hash",
"configured",
"with",
"the",
"given",
"Config",
".",
"Config",
"can",
"be",
"nil",
"in",
"which",
"case",
"the",
"default",
"one",
"is",
"used",
"calculating",
"64",
"-",
"byte",
"digest",
".",
"Returns"... | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/blake2b.go#L105-L120 |
131,872 | minio/blake2b-simd | blake2b.go | initialize | func (d *digest) initialize(c *Config) {
// Create parameter block.
var p [BlockSize]byte
p[0] = c.Size
p[1] = uint8(len(c.Key))
if c.Salt != nil {
copy(p[32:], c.Salt)
}
if c.Person != nil {
copy(p[48:], c.Person)
}
if c.Tree != nil {
p[2] = c.Tree.Fanout
p[3] = c.Tree.MaxDepth
binary.LittleEndian.P... | go | func (d *digest) initialize(c *Config) {
// Create parameter block.
var p [BlockSize]byte
p[0] = c.Size
p[1] = uint8(len(c.Key))
if c.Salt != nil {
copy(p[32:], c.Salt)
}
if c.Person != nil {
copy(p[48:], c.Person)
}
if c.Tree != nil {
p[2] = c.Tree.Fanout
p[3] = c.Tree.MaxDepth
binary.LittleEndian.P... | [
"func",
"(",
"d",
"*",
"digest",
")",
"initialize",
"(",
"c",
"*",
"Config",
")",
"{",
"// Create parameter block.",
"var",
"p",
"[",
"BlockSize",
"]",
"byte",
"\n",
"p",
"[",
"0",
"]",
"=",
"c",
".",
"Size",
"\n",
"p",
"[",
"1",
"]",
"=",
"uint8... | // initialize initializes digest with the given
// config, which must be non-nil and verified. | [
"initialize",
"initializes",
"digest",
"with",
"the",
"given",
"config",
"which",
"must",
"be",
"non",
"-",
"nil",
"and",
"verified",
"."
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/blake2b.go#L124-L164 |
131,873 | minio/blake2b-simd | blake2b.go | New512 | func New512() hash.Hash {
d := new(digest)
d.initialize(defaultConfig)
return d
} | go | func New512() hash.Hash {
d := new(digest)
d.initialize(defaultConfig)
return d
} | [
"func",
"New512",
"(",
")",
"hash",
".",
"Hash",
"{",
"d",
":=",
"new",
"(",
"digest",
")",
"\n",
"d",
".",
"initialize",
"(",
"defaultConfig",
")",
"\n",
"return",
"d",
"\n",
"}"
] | // New512 returns a new hash.Hash computing the BLAKE2b 64-byte checksum. | [
"New512",
"returns",
"a",
"new",
"hash",
".",
"Hash",
"computing",
"the",
"BLAKE2b",
"64",
"-",
"byte",
"checksum",
"."
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/blake2b.go#L167-L171 |
131,874 | minio/blake2b-simd | blake2b.go | New256 | func New256() hash.Hash {
d := new(digest)
d.initialize(config256)
return d
} | go | func New256() hash.Hash {
d := new(digest)
d.initialize(config256)
return d
} | [
"func",
"New256",
"(",
")",
"hash",
".",
"Hash",
"{",
"d",
":=",
"new",
"(",
"digest",
")",
"\n",
"d",
".",
"initialize",
"(",
"config256",
")",
"\n",
"return",
"d",
"\n",
"}"
] | // New256 returns a new hash.Hash computing the BLAKE2b 32-byte checksum. | [
"New256",
"returns",
"a",
"new",
"hash",
".",
"Hash",
"computing",
"the",
"BLAKE2b",
"32",
"-",
"byte",
"checksum",
"."
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/blake2b.go#L174-L178 |
131,875 | minio/blake2b-simd | blake2b.go | Reset | func (d *digest) Reset() {
copy(d.h[:], d.ih[:])
d.t[0] = 0
d.t[1] = 0
d.f[0] = 0
d.f[1] = 0
d.nx = 0
if d.isKeyed {
d.Write(d.paddedKey[:])
}
} | go | func (d *digest) Reset() {
copy(d.h[:], d.ih[:])
d.t[0] = 0
d.t[1] = 0
d.f[0] = 0
d.f[1] = 0
d.nx = 0
if d.isKeyed {
d.Write(d.paddedKey[:])
}
} | [
"func",
"(",
"d",
"*",
"digest",
")",
"Reset",
"(",
")",
"{",
"copy",
"(",
"d",
".",
"h",
"[",
":",
"]",
",",
"d",
".",
"ih",
"[",
":",
"]",
")",
"\n",
"d",
".",
"t",
"[",
"0",
"]",
"=",
"0",
"\n",
"d",
".",
"t",
"[",
"1",
"]",
"=",... | // Reset resets the state of digest to the initial state
// after configuration and keying. | [
"Reset",
"resets",
"the",
"state",
"of",
"digest",
"to",
"the",
"initial",
"state",
"after",
"configuration",
"and",
"keying",
"."
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/blake2b.go#L193-L203 |
131,876 | minio/blake2b-simd | blake2b.go | Sum512 | func Sum512(data []byte) [64]byte {
var d digest
d.initialize(defaultConfig)
d.Write(data)
return d.checkSum()
} | go | func Sum512(data []byte) [64]byte {
var d digest
d.initialize(defaultConfig)
d.Write(data)
return d.checkSum()
} | [
"func",
"Sum512",
"(",
"data",
"[",
"]",
"byte",
")",
"[",
"64",
"]",
"byte",
"{",
"var",
"d",
"digest",
"\n",
"d",
".",
"initialize",
"(",
"defaultConfig",
")",
"\n",
"d",
".",
"Write",
"(",
"data",
")",
"\n",
"return",
"d",
".",
"checkSum",
"("... | // Sum512 returns a 64-byte BLAKE2b hash of data. | [
"Sum512",
"returns",
"a",
"64",
"-",
"byte",
"BLAKE2b",
"hash",
"of",
"data",
"."
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/blake2b.go#L286-L291 |
131,877 | minio/blake2b-simd | blake2b.go | Sum256 | func Sum256(data []byte) (out [32]byte) {
var d digest
d.initialize(config256)
d.Write(data)
sum := d.checkSum()
copy(out[:], sum[:32])
return
} | go | func Sum256(data []byte) (out [32]byte) {
var d digest
d.initialize(config256)
d.Write(data)
sum := d.checkSum()
copy(out[:], sum[:32])
return
} | [
"func",
"Sum256",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"out",
"[",
"32",
"]",
"byte",
")",
"{",
"var",
"d",
"digest",
"\n",
"d",
".",
"initialize",
"(",
"config256",
")",
"\n",
"d",
".",
"Write",
"(",
"data",
")",
"\n",
"sum",
":=",
"d",
... | // Sum256 returns a 32-byte BLAKE2b hash of data. | [
"Sum256",
"returns",
"a",
"32",
"-",
"byte",
"BLAKE2b",
"hash",
"of",
"data",
"."
] | 3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4 | https://github.com/minio/blake2b-simd/blob/3f5f724cb5b182a5c278d6d3d55b40e7f8c2efb4/blake2b.go#L294-L301 |
131,878 | sigurn/crc16 | crc16.go | MakeTable | func MakeTable(params Params) *Table {
table := new(Table)
table.params = params
for n := 0; n < 256; n++ {
crc := uint16(n) << 8
for i := 0; i < 8; i++ {
bit := (crc & 0x8000) != 0
crc <<= 1
if bit {
crc ^= params.Poly
}
}
table.data[n] = crc
}
return table
} | go | func MakeTable(params Params) *Table {
table := new(Table)
table.params = params
for n := 0; n < 256; n++ {
crc := uint16(n) << 8
for i := 0; i < 8; i++ {
bit := (crc & 0x8000) != 0
crc <<= 1
if bit {
crc ^= params.Poly
}
}
table.data[n] = crc
}
return table
} | [
"func",
"MakeTable",
"(",
"params",
"Params",
")",
"*",
"Table",
"{",
"table",
":=",
"new",
"(",
"Table",
")",
"\n",
"table",
".",
"params",
"=",
"params",
"\n",
"for",
"n",
":=",
"0",
";",
"n",
"<",
"256",
";",
"n",
"++",
"{",
"crc",
":=",
"ui... | // MakeTable returns the Table constructed from the specified algorithm. | [
"MakeTable",
"returns",
"the",
"Table",
"constructed",
"from",
"the",
"specified",
"algorithm",
"."
] | da416fad5162ac0f3338ba24dccdb26e4da22485 | https://github.com/sigurn/crc16/blob/da416fad5162ac0f3338ba24dccdb26e4da22485/crc16.go#L58-L73 |
131,879 | sigurn/crc16 | crc16.go | Update | func Update(crc uint16, data []byte, table *Table) uint16 {
for _, d := range data {
if table.params.RefIn {
d = utils.ReverseByte(d)
}
crc = crc<<8 ^ table.data[byte(crc>>8)^d]
}
return crc
} | go | func Update(crc uint16, data []byte, table *Table) uint16 {
for _, d := range data {
if table.params.RefIn {
d = utils.ReverseByte(d)
}
crc = crc<<8 ^ table.data[byte(crc>>8)^d]
}
return crc
} | [
"func",
"Update",
"(",
"crc",
"uint16",
",",
"data",
"[",
"]",
"byte",
",",
"table",
"*",
"Table",
")",
"uint16",
"{",
"for",
"_",
",",
"d",
":=",
"range",
"data",
"{",
"if",
"table",
".",
"params",
".",
"RefIn",
"{",
"d",
"=",
"utils",
".",
"R... | // Update returns the result of adding the bytes in data to the crc. | [
"Update",
"returns",
"the",
"result",
"of",
"adding",
"the",
"bytes",
"in",
"data",
"to",
"the",
"crc",
"."
] | da416fad5162ac0f3338ba24dccdb26e4da22485 | https://github.com/sigurn/crc16/blob/da416fad5162ac0f3338ba24dccdb26e4da22485/crc16.go#L81-L89 |
131,880 | sigurn/crc16 | crc16.go | Checksum | func Checksum(data []byte, table *Table) uint16 {
crc := Init(table)
crc = Update(crc, data, table)
return Complete(crc, table)
} | go | func Checksum(data []byte, table *Table) uint16 {
crc := Init(table)
crc = Update(crc, data, table)
return Complete(crc, table)
} | [
"func",
"Checksum",
"(",
"data",
"[",
"]",
"byte",
",",
"table",
"*",
"Table",
")",
"uint16",
"{",
"crc",
":=",
"Init",
"(",
"table",
")",
"\n",
"crc",
"=",
"Update",
"(",
"crc",
",",
"data",
",",
"table",
")",
"\n",
"return",
"Complete",
"(",
"c... | // Checksum returns CRC checksum of data usign scpecified algorithm represented by the Table. | [
"Checksum",
"returns",
"CRC",
"checksum",
"of",
"data",
"usign",
"scpecified",
"algorithm",
"represented",
"by",
"the",
"Table",
"."
] | da416fad5162ac0f3338ba24dccdb26e4da22485 | https://github.com/sigurn/crc16/blob/da416fad5162ac0f3338ba24dccdb26e4da22485/crc16.go#L100-L104 |
131,881 | kevinburke/nacl | auth/auth.go | Sum | func Sum(m []byte, key nacl.Key) *[Size]byte {
mac := hmac.New(sha512.New, (*key)[:])
mac.Write(m)
sum := mac.Sum(nil) // first 256 bits of 512 bit sum
out := new([32]byte)
copy(out[:], sum[:32])
return out
} | go | func Sum(m []byte, key nacl.Key) *[Size]byte {
mac := hmac.New(sha512.New, (*key)[:])
mac.Write(m)
sum := mac.Sum(nil) // first 256 bits of 512 bit sum
out := new([32]byte)
copy(out[:], sum[:32])
return out
} | [
"func",
"Sum",
"(",
"m",
"[",
"]",
"byte",
",",
"key",
"nacl",
".",
"Key",
")",
"*",
"[",
"Size",
"]",
"byte",
"{",
"mac",
":=",
"hmac",
".",
"New",
"(",
"sha512",
".",
"New",
",",
"(",
"*",
"key",
")",
"[",
":",
"]",
")",
"\n",
"mac",
".... | // Sum generates an authenticator for m using a secret key and returns the
// 32-byte digest. | [
"Sum",
"generates",
"an",
"authenticator",
"for",
"m",
"using",
"a",
"secret",
"key",
"and",
"returns",
"the",
"32",
"-",
"byte",
"digest",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/auth/auth.go#L38-L45 |
131,882 | kevinburke/nacl | auth/auth.go | Verify | func Verify(digest *[Size]byte, m []byte, key nacl.Key) bool {
mac := hmac.New(sha512.New, (*key)[:])
mac.Write(m)
expectedMAC := mac.Sum(nil) // first 256 bits of 512 bit sum
return hmac.Equal((*digest)[:], expectedMAC[:Size])
} | go | func Verify(digest *[Size]byte, m []byte, key nacl.Key) bool {
mac := hmac.New(sha512.New, (*key)[:])
mac.Write(m)
expectedMAC := mac.Sum(nil) // first 256 bits of 512 bit sum
return hmac.Equal((*digest)[:], expectedMAC[:Size])
} | [
"func",
"Verify",
"(",
"digest",
"*",
"[",
"Size",
"]",
"byte",
",",
"m",
"[",
"]",
"byte",
",",
"key",
"nacl",
".",
"Key",
")",
"bool",
"{",
"mac",
":=",
"hmac",
".",
"New",
"(",
"sha512",
".",
"New",
",",
"(",
"*",
"key",
")",
"[",
":",
"... | // Verify checks that digest is a correct authenticator of a message m under the
// secret key key. If not, the function returns false. Verify does not leak
// timing information. | [
"Verify",
"checks",
"that",
"digest",
"is",
"a",
"correct",
"authenticator",
"of",
"a",
"message",
"m",
"under",
"the",
"secret",
"key",
"key",
".",
"If",
"not",
"the",
"function",
"returns",
"false",
".",
"Verify",
"does",
"not",
"leak",
"timing",
"inform... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/auth/auth.go#L50-L55 |
131,883 | kevinburke/nacl | randombytes/randombytes.go | MustRead | func MustRead(in []byte) {
n, err := Read(in)
if err != nil {
panic(err)
}
if n != len(in) {
panic("did not read enough random data: only " + strconv.Itoa(n) + " bytes")
}
} | go | func MustRead(in []byte) {
n, err := Read(in)
if err != nil {
panic(err)
}
if n != len(in) {
panic("did not read enough random data: only " + strconv.Itoa(n) + " bytes")
}
} | [
"func",
"MustRead",
"(",
"in",
"[",
"]",
"byte",
")",
"{",
"n",
",",
"err",
":=",
"Read",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"n",
"!=",
"len",
"(",
"in",
")",
"{",
"panic",
... | // MustRead fills in entirely with random data, or panics. | [
"MustRead",
"fills",
"in",
"entirely",
"with",
"random",
"data",
"or",
"panics",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/randombytes/randombytes.go#L15-L23 |
131,884 | kevinburke/nacl | nacl.go | Load | func Load(hexkey string) (Key, error) {
if len(hexkey) != 64 {
return nil, fmt.Errorf("nacl: incorrect hex key length: %d, should be 64", len(hexkey))
}
keyBytes, err := hex.DecodeString(hexkey)
if err != nil {
return nil, err
}
if len(keyBytes) != KeySize {
return nil, fmt.Errorf("nacl: incorrect key lengt... | go | func Load(hexkey string) (Key, error) {
if len(hexkey) != 64 {
return nil, fmt.Errorf("nacl: incorrect hex key length: %d, should be 64", len(hexkey))
}
keyBytes, err := hex.DecodeString(hexkey)
if err != nil {
return nil, err
}
if len(keyBytes) != KeySize {
return nil, fmt.Errorf("nacl: incorrect key lengt... | [
"func",
"Load",
"(",
"hexkey",
"string",
")",
"(",
"Key",
",",
"error",
")",
"{",
"if",
"len",
"(",
"hexkey",
")",
"!=",
"64",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"hexkey",
")",
")",
"\n",
"}",
"... | // Load decodes a 64-byte hex string into a Key. A hex key is suitable for
// representation in a configuration file. You can generate one by running
// "openssl rand -hex 32". | [
"Load",
"decodes",
"a",
"64",
"-",
"byte",
"hex",
"string",
"into",
"a",
"Key",
".",
"A",
"hex",
"key",
"is",
"suitable",
"for",
"representation",
"in",
"a",
"configuration",
"file",
".",
"You",
"can",
"generate",
"one",
"by",
"running",
"openssl",
"rand... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/nacl.go#L55-L69 |
131,885 | kevinburke/nacl | nacl.go | NewKey | func NewKey() Key {
key := new([KeySize]byte)
randombytes.MustRead(key[:])
return key
} | go | func NewKey() Key {
key := new([KeySize]byte)
randombytes.MustRead(key[:])
return key
} | [
"func",
"NewKey",
"(",
")",
"Key",
"{",
"key",
":=",
"new",
"(",
"[",
"KeySize",
"]",
"byte",
")",
"\n",
"randombytes",
".",
"MustRead",
"(",
"key",
"[",
":",
"]",
")",
"\n",
"return",
"key",
"\n",
"}"
] | // NewKey returns a new Key with cryptographically random data. NewKey panics if
// we could not read the correct amount of random data into key. | [
"NewKey",
"returns",
"a",
"new",
"Key",
"with",
"cryptographically",
"random",
"data",
".",
"NewKey",
"panics",
"if",
"we",
"could",
"not",
"read",
"the",
"correct",
"amount",
"of",
"random",
"data",
"into",
"key",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/nacl.go#L92-L96 |
131,886 | kevinburke/nacl | nacl.go | NewNonce | func NewNonce() Nonce {
nonce := new([NonceSize]byte)
randombytes.MustRead(nonce[:])
return nonce
} | go | func NewNonce() Nonce {
nonce := new([NonceSize]byte)
randombytes.MustRead(nonce[:])
return nonce
} | [
"func",
"NewNonce",
"(",
")",
"Nonce",
"{",
"nonce",
":=",
"new",
"(",
"[",
"NonceSize",
"]",
"byte",
")",
"\n",
"randombytes",
".",
"MustRead",
"(",
"nonce",
"[",
":",
"]",
")",
"\n",
"return",
"nonce",
"\n",
"}"
] | // NewNonce returns a new Nonce with cryptographically random data. It panics if
// we could not read the correct amount of random data into nonce. | [
"NewNonce",
"returns",
"a",
"new",
"Nonce",
"with",
"cryptographically",
"random",
"data",
".",
"It",
"panics",
"if",
"we",
"could",
"not",
"read",
"the",
"correct",
"amount",
"of",
"random",
"data",
"into",
"nonce",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/nacl.go#L100-L104 |
131,887 | kevinburke/nacl | nacl.go | Verify16 | func Verify16(a, b *[16]byte) bool {
if a == nil || b == nil {
panic("nacl: nil input")
}
return subtle.ConstantTimeCompare(a[:], b[:]) == 1
} | go | func Verify16(a, b *[16]byte) bool {
if a == nil || b == nil {
panic("nacl: nil input")
}
return subtle.ConstantTimeCompare(a[:], b[:]) == 1
} | [
"func",
"Verify16",
"(",
"a",
",",
"b",
"*",
"[",
"16",
"]",
"byte",
")",
"bool",
"{",
"if",
"a",
"==",
"nil",
"||",
"b",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"subtle",
".",
"ConstantTimeCompare",
"(",
"a"... | // Verify16 returns true if and only if a and b have equal contents, without
// leaking timing information. | [
"Verify16",
"returns",
"true",
"if",
"and",
"only",
"if",
"a",
"and",
"b",
"have",
"equal",
"contents",
"without",
"leaking",
"timing",
"information",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/nacl.go#L116-L121 |
131,888 | kevinburke/nacl | nacl.go | Verify32 | func Verify32(a, b *[KeySize]byte) bool {
if a == nil || b == nil {
panic("nacl: nil input")
}
return subtle.ConstantTimeCompare(a[:], b[:]) == 1
} | go | func Verify32(a, b *[KeySize]byte) bool {
if a == nil || b == nil {
panic("nacl: nil input")
}
return subtle.ConstantTimeCompare(a[:], b[:]) == 1
} | [
"func",
"Verify32",
"(",
"a",
",",
"b",
"*",
"[",
"KeySize",
"]",
"byte",
")",
"bool",
"{",
"if",
"a",
"==",
"nil",
"||",
"b",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"subtle",
".",
"ConstantTimeCompare",
"(",
... | // Verify32 returns true if and only if a and b have equal contents, without
// leaking timing information. | [
"Verify32",
"returns",
"true",
"if",
"and",
"only",
"if",
"a",
"and",
"b",
"have",
"equal",
"contents",
"without",
"leaking",
"timing",
"information",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/nacl.go#L125-L130 |
131,889 | kevinburke/nacl | nacl.go | Hash | func Hash(m []byte) *[HashSize]byte {
out := sha512.Sum512(m)
return &out
} | go | func Hash(m []byte) *[HashSize]byte {
out := sha512.Sum512(m)
return &out
} | [
"func",
"Hash",
"(",
"m",
"[",
"]",
"byte",
")",
"*",
"[",
"HashSize",
"]",
"byte",
"{",
"out",
":=",
"sha512",
".",
"Sum512",
"(",
"m",
")",
"\n",
"return",
"&",
"out",
"\n",
"}"
] | // Hash hashes a message m.
//
// The crypto_hash function is designed to be usable as a strong component of
// DSA, RSA-PSS, key derivation, hash-based message-authentication codes,
// hash-based ciphers, and various other common applications. "Strong" means
// that the security of these applications, when instantiate... | [
"Hash",
"hashes",
"a",
"message",
"m",
".",
"The",
"crypto_hash",
"function",
"is",
"designed",
"to",
"be",
"usable",
"as",
"a",
"strong",
"component",
"of",
"DSA",
"RSA",
"-",
"PSS",
"key",
"derivation",
"hash",
"-",
"based",
"message",
"-",
"authenticati... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/nacl.go#L146-L149 |
131,890 | kevinburke/nacl | nacl.go | Setup | func Setup(nonce Nonce, key Key) (Key, *[16]byte) {
// We use XSalsa20 for encryption so first we need to generate a
// key and nonce with HSalsa20.
var hNonce [16]byte
copy(hNonce[:], nonce[:])
var subKey [32]byte
salsa.HSalsa20(&subKey, &hNonce, key, &salsa.Sigma)
// The final 8 bytes of the original nonce fo... | go | func Setup(nonce Nonce, key Key) (Key, *[16]byte) {
// We use XSalsa20 for encryption so first we need to generate a
// key and nonce with HSalsa20.
var hNonce [16]byte
copy(hNonce[:], nonce[:])
var subKey [32]byte
salsa.HSalsa20(&subKey, &hNonce, key, &salsa.Sigma)
// The final 8 bytes of the original nonce fo... | [
"func",
"Setup",
"(",
"nonce",
"Nonce",
",",
"key",
"Key",
")",
"(",
"Key",
",",
"*",
"[",
"16",
"]",
"byte",
")",
"{",
"// We use XSalsa20 for encryption so first we need to generate a",
"// key and nonce with HSalsa20.",
"var",
"hNonce",
"[",
"16",
"]",
"byte",
... | // Setup produces a sub-key and Salsa20 counter given a nonce and key. | [
"Setup",
"produces",
"a",
"sub",
"-",
"key",
"and",
"Salsa20",
"counter",
"given",
"a",
"nonce",
"and",
"key",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/nacl.go#L152-L164 |
131,891 | kevinburke/nacl | onetimeauth/onetimeauth.go | Verify | func Verify(mac *[Size]byte, m []byte, key nacl.Key) bool {
return poly1305.Verify(mac, m, key)
} | go | func Verify(mac *[Size]byte, m []byte, key nacl.Key) bool {
return poly1305.Verify(mac, m, key)
} | [
"func",
"Verify",
"(",
"mac",
"*",
"[",
"Size",
"]",
"byte",
",",
"m",
"[",
"]",
"byte",
",",
"key",
"nacl",
".",
"Key",
")",
"bool",
"{",
"return",
"poly1305",
".",
"Verify",
"(",
"mac",
",",
"m",
",",
"key",
")",
"\n",
"}"
] | // Verify returns true if mac is a valid authenticator for m with the given
// key, without leaking timing information. | [
"Verify",
"returns",
"true",
"if",
"mac",
"is",
"a",
"valid",
"authenticator",
"for",
"m",
"with",
"the",
"given",
"key",
"without",
"leaking",
"timing",
"information",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/onetimeauth/onetimeauth.go#L41-L43 |
131,892 | kevinburke/nacl | sign/internal/edwards25519/edwards25519.go | ScMinimal | func ScMinimal(scalar *[32]byte) bool {
for i := 3; ; i-- {
v := binary.LittleEndian.Uint64(scalar[i*8:])
if v > order[i] {
return false
} else if v < order[i] {
break
} else if i == 0 {
return false
}
}
return true
} | go | func ScMinimal(scalar *[32]byte) bool {
for i := 3; ; i-- {
v := binary.LittleEndian.Uint64(scalar[i*8:])
if v > order[i] {
return false
} else if v < order[i] {
break
} else if i == 0 {
return false
}
}
return true
} | [
"func",
"ScMinimal",
"(",
"scalar",
"*",
"[",
"32",
"]",
"byte",
")",
"bool",
"{",
"for",
"i",
":=",
"3",
";",
";",
"i",
"--",
"{",
"v",
":=",
"binary",
".",
"LittleEndian",
".",
"Uint64",
"(",
"scalar",
"[",
"i",
"*",
"8",
":",
"]",
")",
"\n... | // ScMinimal returns true if the given scalar is less than the order of the
// curve. | [
"ScMinimal",
"returns",
"true",
"if",
"the",
"given",
"scalar",
"is",
"less",
"than",
"the",
"order",
"of",
"the",
"curve",
"."
] | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/sign/internal/edwards25519/edwards25519.go#L1780-L1793 |
131,893 | kevinburke/nacl | secretbox/secretbox.go | sliceForAppend | func sliceForAppend(in []byte, n int) (head, tail []byte) {
if total := len(in) + n; cap(in) >= total {
head = in[:total]
} else {
head = make([]byte, total)
copy(head, in)
}
tail = head[len(in):]
return
} | go | func sliceForAppend(in []byte, n int) (head, tail []byte) {
if total := len(in) + n; cap(in) >= total {
head = in[:total]
} else {
head = make([]byte, total)
copy(head, in)
}
tail = head[len(in):]
return
} | [
"func",
"sliceForAppend",
"(",
"in",
"[",
"]",
"byte",
",",
"n",
"int",
")",
"(",
"head",
",",
"tail",
"[",
"]",
"byte",
")",
"{",
"if",
"total",
":=",
"len",
"(",
"in",
")",
"+",
"n",
";",
"cap",
"(",
"in",
")",
">=",
"total",
"{",
"head",
... | // sliceForAppend takes a slice and a requested number of bytes. It returns a
// slice with the contents of the given slice followed by that many bytes and a
// second slice that aliases into it and contains only the extra bytes. If the
// original slice has sufficient capacity then no allocation is performed. | [
"sliceForAppend",
"takes",
"a",
"slice",
"and",
"a",
"requested",
"number",
"of",
"bytes",
".",
"It",
"returns",
"a",
"slice",
"with",
"the",
"contents",
"of",
"the",
"given",
"slice",
"followed",
"by",
"that",
"many",
"bytes",
"and",
"a",
"second",
"slice... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/secretbox/secretbox.go#L36-L45 |
131,894 | kevinburke/nacl | secretbox/secretbox.go | EasySeal | func EasySeal(message []byte, key nacl.Key) []byte {
nonce := nacl.NewNonce()
return Seal(nonce[:], message, nonce, key)
} | go | func EasySeal(message []byte, key nacl.Key) []byte {
nonce := nacl.NewNonce()
return Seal(nonce[:], message, nonce, key)
} | [
"func",
"EasySeal",
"(",
"message",
"[",
"]",
"byte",
",",
"key",
"nacl",
".",
"Key",
")",
"[",
"]",
"byte",
"{",
"nonce",
":=",
"nacl",
".",
"NewNonce",
"(",
")",
"\n",
"return",
"Seal",
"(",
"nonce",
"[",
":",
"]",
",",
"message",
",",
"nonce",... | // EasySeal encrypts message using key. A 24-byte nonce is generated and
// prepended to the output. The key and nonce pair must be unique for each
// distinct message, and the output will be Overhead+24 bytes longer than
// message. | [
"EasySeal",
"encrypts",
"message",
"using",
"key",
".",
"A",
"24",
"-",
"byte",
"nonce",
"is",
"generated",
"and",
"prepended",
"to",
"the",
"output",
".",
"The",
"key",
"and",
"nonce",
"pair",
"must",
"be",
"unique",
"for",
"each",
"distinct",
"message",
... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/secretbox/secretbox.go#L51-L54 |
131,895 | kevinburke/nacl | secretbox/secretbox.go | Seal | func Seal(out, message []byte, nonce nacl.Nonce, key nacl.Key) []byte {
subKey, counter := nacl.Setup(nonce, key)
// The Poly1305 key is generated by encrypting 32 bytes of zeros. Since
// Salsa20 works with 64-byte blocks, we also generate 32 bytes of
// keystream as a side effect.
var firstBlock [64]byte
salsa... | go | func Seal(out, message []byte, nonce nacl.Nonce, key nacl.Key) []byte {
subKey, counter := nacl.Setup(nonce, key)
// The Poly1305 key is generated by encrypting 32 bytes of zeros. Since
// Salsa20 works with 64-byte blocks, we also generate 32 bytes of
// keystream as a side effect.
var firstBlock [64]byte
salsa... | [
"func",
"Seal",
"(",
"out",
",",
"message",
"[",
"]",
"byte",
",",
"nonce",
"nacl",
".",
"Nonce",
",",
"key",
"nacl",
".",
"Key",
")",
"[",
"]",
"byte",
"{",
"subKey",
",",
"counter",
":=",
"nacl",
".",
"Setup",
"(",
"nonce",
",",
"key",
")",
"... | // Seal appends an encrypted and authenticated copy of message to out, which
// must not overlap message. The key and nonce pair must be unique for each
// distinct message and the output will be Overhead bytes longer than message. | [
"Seal",
"appends",
"an",
"encrypted",
"and",
"authenticated",
"copy",
"of",
"message",
"to",
"out",
"which",
"must",
"not",
"overlap",
"message",
".",
"The",
"key",
"and",
"nonce",
"pair",
"must",
"be",
"unique",
"for",
"each",
"distinct",
"message",
"and",
... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/secretbox/secretbox.go#L59-L100 |
131,896 | kevinburke/nacl | secretbox/secretbox.go | EasyOpen | func EasyOpen(box []byte, key nacl.Key) ([]byte, error) {
if len(box) < 24 {
return nil, errors.New("secretbox: message too short")
}
decryptNonce := new([24]byte)
copy(decryptNonce[:], box[:24])
decrypted, ok := Open([]byte{}, box[24:], decryptNonce, key)
if !ok {
return nil, errInvalidInput
}
return decry... | go | func EasyOpen(box []byte, key nacl.Key) ([]byte, error) {
if len(box) < 24 {
return nil, errors.New("secretbox: message too short")
}
decryptNonce := new([24]byte)
copy(decryptNonce[:], box[:24])
decrypted, ok := Open([]byte{}, box[24:], decryptNonce, key)
if !ok {
return nil, errInvalidInput
}
return decry... | [
"func",
"EasyOpen",
"(",
"box",
"[",
"]",
"byte",
",",
"key",
"nacl",
".",
"Key",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"box",
")",
"<",
"24",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
... | // EasyOpen decrypts box using key. We assume a 24-byte nonce is prepended to
// the encrypted text in box. The key and nonce pair must be unique for each
// distinct message. | [
"EasyOpen",
"decrypts",
"box",
"using",
"key",
".",
"We",
"assume",
"a",
"24",
"-",
"byte",
"nonce",
"is",
"prepended",
"to",
"the",
"encrypted",
"text",
"in",
"box",
".",
"The",
"key",
"and",
"nonce",
"pair",
"must",
"be",
"unique",
"for",
"each",
"di... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/secretbox/secretbox.go#L107-L118 |
131,897 | kevinburke/nacl | box/box.go | Precompute | func Precompute(peersPublicKey, privateKey nacl.Key) nacl.Key {
sharedKey := scalarmult.Mult(privateKey, peersPublicKey)
salsa.HSalsa20(sharedKey, &zeros, sharedKey, &salsa.Sigma)
return sharedKey
} | go | func Precompute(peersPublicKey, privateKey nacl.Key) nacl.Key {
sharedKey := scalarmult.Mult(privateKey, peersPublicKey)
salsa.HSalsa20(sharedKey, &zeros, sharedKey, &salsa.Sigma)
return sharedKey
} | [
"func",
"Precompute",
"(",
"peersPublicKey",
",",
"privateKey",
"nacl",
".",
"Key",
")",
"nacl",
".",
"Key",
"{",
"sharedKey",
":=",
"scalarmult",
".",
"Mult",
"(",
"privateKey",
",",
"peersPublicKey",
")",
"\n",
"salsa",
".",
"HSalsa20",
"(",
"sharedKey",
... | // Precompute calculates the shared key between peersPublicKey and privateKey
// and writes it to sharedKey. The shared key can be used with
// OpenAfterPrecomputation and SealAfterPrecomputation to speed up processing
// when using the same pair of keys repeatedly. | [
"Precompute",
"calculates",
"the",
"shared",
"key",
"between",
"peersPublicKey",
"and",
"privateKey",
"and",
"writes",
"it",
"to",
"sharedKey",
".",
"The",
"shared",
"key",
"can",
"be",
"used",
"with",
"OpenAfterPrecomputation",
"and",
"SealAfterPrecomputation",
"to... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/box/box.go#L54-L58 |
131,898 | kevinburke/nacl | box/box.go | EasySeal | func EasySeal(message []byte, peersPublicKey, privateKey nacl.Key) []byte {
nonce := nacl.NewNonce()
return Seal(nonce[:], message, nonce, peersPublicKey, privateKey)
} | go | func EasySeal(message []byte, peersPublicKey, privateKey nacl.Key) []byte {
nonce := nacl.NewNonce()
return Seal(nonce[:], message, nonce, peersPublicKey, privateKey)
} | [
"func",
"EasySeal",
"(",
"message",
"[",
"]",
"byte",
",",
"peersPublicKey",
",",
"privateKey",
"nacl",
".",
"Key",
")",
"[",
"]",
"byte",
"{",
"nonce",
":=",
"nacl",
".",
"NewNonce",
"(",
")",
"\n",
"return",
"Seal",
"(",
"nonce",
"[",
":",
"]",
"... | // EasySeal encrypts message using peersPublicKey and privateKey. The output
// will have a randomly generated nonce prepended to it. The output will be
// Overhead + 24 bytes longer than the original. | [
"EasySeal",
"encrypts",
"message",
"using",
"peersPublicKey",
"and",
"privateKey",
".",
"The",
"output",
"will",
"have",
"a",
"randomly",
"generated",
"nonce",
"prepended",
"to",
"it",
".",
"The",
"output",
"will",
"be",
"Overhead",
"+",
"24",
"bytes",
"longer... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/box/box.go#L63-L66 |
131,899 | kevinburke/nacl | box/box.go | Seal | func Seal(out, message []byte, nonce nacl.Nonce, peersPublicKey, privateKey nacl.Key) []byte {
sharedKey := Precompute(peersPublicKey, privateKey)
return secretbox.Seal(out, message, nonce, sharedKey)
} | go | func Seal(out, message []byte, nonce nacl.Nonce, peersPublicKey, privateKey nacl.Key) []byte {
sharedKey := Precompute(peersPublicKey, privateKey)
return secretbox.Seal(out, message, nonce, sharedKey)
} | [
"func",
"Seal",
"(",
"out",
",",
"message",
"[",
"]",
"byte",
",",
"nonce",
"nacl",
".",
"Nonce",
",",
"peersPublicKey",
",",
"privateKey",
"nacl",
".",
"Key",
")",
"[",
"]",
"byte",
"{",
"sharedKey",
":=",
"Precompute",
"(",
"peersPublicKey",
",",
"pr... | // Seal appends an encrypted and authenticated copy of message to out, which
// will be Overhead bytes longer than the original and must not overlap. The
// nonce must be unique for each distinct message for a given pair of keys. | [
"Seal",
"appends",
"an",
"encrypted",
"and",
"authenticated",
"copy",
"of",
"message",
"to",
"out",
"which",
"will",
"be",
"Overhead",
"bytes",
"longer",
"than",
"the",
"original",
"and",
"must",
"not",
"overlap",
".",
"The",
"nonce",
"must",
"be",
"unique",... | 38063847a0c9aca6aa4248db9990b411da7b6f4e | https://github.com/kevinburke/nacl/blob/38063847a0c9aca6aa4248db9990b411da7b6f4e/box/box.go#L71-L74 |
Subsets and Splits
SQL Console for google/code_x_glue_ct_code_to_text
This query implements a thoughtful three-tier curation strategy to build a balanced safety dataset, categorizing code by destructive operations, safe I/O operations, and pure computational negatives with subsampling—revealing important patterns about how destructive intent manifests in Python code for model safety research.
SQL Console for google/code_x_glue_ct_code_to_text
This query performs meaningful classification of Python code samples into safety-relevant tiers based on destructive operations, I/O patterns, and pure computation, which could be valuable for building safety classifiers or curating training data, though the output itself is a filtered/ranked dataset rather than revealing novel statistical insights.