repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
tidwall/buntdb
buntdb.go
IndexJSONCaseSensitive
func IndexJSONCaseSensitive(path string) func(a, b string) bool { return func(a, b string) bool { return gjson.Get(a, path).Less(gjson.Get(b, path), true) } }
go
func IndexJSONCaseSensitive(path string) func(a, b string) bool { return func(a, b string) bool { return gjson.Get(a, path).Less(gjson.Get(b, path), true) } }
[ "func", "IndexJSONCaseSensitive", "(", "path", "string", ")", "func", "(", "a", ",", "b", "string", ")", "bool", "{", "return", "func", "(", "a", ",", "b", "string", ")", "bool", "{", "return", "gjson", ".", "Get", "(", "a", ",", "path", ")", ".", ...
// IndexJSONCaseSensitive provides for the ability to create an index on // any JSON field. // When the field is a string, the comparison will be case-sensitive. // It returns a helper function used by CreateIndex.
[ "IndexJSONCaseSensitive", "provides", "for", "the", "ability", "to", "create", "an", "index", "on", "any", "JSON", "field", ".", "When", "the", "field", "is", "a", "string", "the", "comparison", "will", "be", "case", "-", "sensitive", ".", "It", "returns", ...
6249481c29c2cd96f53b691b74ac1893f72774c2
https://github.com/tidwall/buntdb/blob/6249481c29c2cd96f53b691b74ac1893f72774c2/buntdb.go#L2186-L2190
train
tidwall/buntdb
buntdb.go
Desc
func Desc(less func(a, b string) bool) func(a, b string) bool { return func(a, b string) bool { return less(b, a) } }
go
func Desc(less func(a, b string) bool) func(a, b string) bool { return func(a, b string) bool { return less(b, a) } }
[ "func", "Desc", "(", "less", "func", "(", "a", ",", "b", "string", ")", "bool", ")", "func", "(", "a", ",", "b", "string", ")", "bool", "{", "return", "func", "(", "a", ",", "b", "string", ")", "bool", "{", "return", "less", "(", "b", ",", "a...
// Desc is a helper function that changes the order of an index.
[ "Desc", "is", "a", "helper", "function", "that", "changes", "the", "order", "of", "an", "index", "." ]
6249481c29c2cd96f53b691b74ac1893f72774c2
https://github.com/tidwall/buntdb/blob/6249481c29c2cd96f53b691b74ac1893f72774c2/buntdb.go#L2193-L2195
train
asdine/storm
q/tree.go
Eq
func Eq(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.EQL}) }
go
func Eq(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.EQL}) }
[ "func", "Eq", "(", "field", "string", ",", "v", "interface", "{", "}", ")", "Matcher", "{", "return", "NewFieldMatcher", "(", "field", ",", "&", "cmp", "{", "value", ":", "v", ",", "token", ":", "token", ".", "EQL", "}", ")", "\n", "}" ]
// Eq matcher, checks if the given field is equal to the given value
[ "Eq", "matcher", "checks", "if", "the", "given", "field", "is", "equal", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L177-L179
train
asdine/storm
q/tree.go
EqF
func EqF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.EQL) }
go
func EqF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.EQL) }
[ "func", "EqF", "(", "field1", ",", "field2", "string", ")", "Matcher", "{", "return", "NewField2FieldMatcher", "(", "field1", ",", "field2", ",", "token", ".", "EQL", ")", "\n", "}" ]
// EqF matcher, checks if the given field is equal to the given field
[ "EqF", "matcher", "checks", "if", "the", "given", "field", "is", "equal", "to", "the", "given", "field" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L182-L184
train
asdine/storm
q/tree.go
StrictEq
func StrictEq(field string, v interface{}) Matcher { return NewFieldMatcher(field, &strictEq{value: v}) }
go
func StrictEq(field string, v interface{}) Matcher { return NewFieldMatcher(field, &strictEq{value: v}) }
[ "func", "StrictEq", "(", "field", "string", ",", "v", "interface", "{", "}", ")", "Matcher", "{", "return", "NewFieldMatcher", "(", "field", ",", "&", "strictEq", "{", "value", ":", "v", "}", ")", "\n", "}" ]
// StrictEq matcher, checks if the given field is deeply equal to the given value
[ "StrictEq", "matcher", "checks", "if", "the", "given", "field", "is", "deeply", "equal", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L187-L189
train
asdine/storm
q/tree.go
Gt
func Gt(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.GTR}) }
go
func Gt(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.GTR}) }
[ "func", "Gt", "(", "field", "string", ",", "v", "interface", "{", "}", ")", "Matcher", "{", "return", "NewFieldMatcher", "(", "field", ",", "&", "cmp", "{", "value", ":", "v", ",", "token", ":", "token", ".", "GTR", "}", ")", "\n", "}" ]
// Gt matcher, checks if the given field is greater than the given value
[ "Gt", "matcher", "checks", "if", "the", "given", "field", "is", "greater", "than", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L192-L194
train
asdine/storm
q/tree.go
GtF
func GtF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.GTR) }
go
func GtF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.GTR) }
[ "func", "GtF", "(", "field1", ",", "field2", "string", ")", "Matcher", "{", "return", "NewField2FieldMatcher", "(", "field1", ",", "field2", ",", "token", ".", "GTR", ")", "\n", "}" ]
// GtF matcher, checks if the given field is greater than the given field
[ "GtF", "matcher", "checks", "if", "the", "given", "field", "is", "greater", "than", "the", "given", "field" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L197-L199
train
asdine/storm
q/tree.go
Gte
func Gte(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.GEQ}) }
go
func Gte(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.GEQ}) }
[ "func", "Gte", "(", "field", "string", ",", "v", "interface", "{", "}", ")", "Matcher", "{", "return", "NewFieldMatcher", "(", "field", ",", "&", "cmp", "{", "value", ":", "v", ",", "token", ":", "token", ".", "GEQ", "}", ")", "\n", "}" ]
// Gte matcher, checks if the given field is greater than or equal to the given value
[ "Gte", "matcher", "checks", "if", "the", "given", "field", "is", "greater", "than", "or", "equal", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L202-L204
train
asdine/storm
q/tree.go
GteF
func GteF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.GEQ) }
go
func GteF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.GEQ) }
[ "func", "GteF", "(", "field1", ",", "field2", "string", ")", "Matcher", "{", "return", "NewField2FieldMatcher", "(", "field1", ",", "field2", ",", "token", ".", "GEQ", ")", "\n", "}" ]
// GteF matcher, checks if the given field is greater than or equal to the given field
[ "GteF", "matcher", "checks", "if", "the", "given", "field", "is", "greater", "than", "or", "equal", "to", "the", "given", "field" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L207-L209
train
asdine/storm
q/tree.go
Lt
func Lt(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.LSS}) }
go
func Lt(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.LSS}) }
[ "func", "Lt", "(", "field", "string", ",", "v", "interface", "{", "}", ")", "Matcher", "{", "return", "NewFieldMatcher", "(", "field", ",", "&", "cmp", "{", "value", ":", "v", ",", "token", ":", "token", ".", "LSS", "}", ")", "\n", "}" ]
// Lt matcher, checks if the given field is lesser than the given value
[ "Lt", "matcher", "checks", "if", "the", "given", "field", "is", "lesser", "than", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L212-L214
train
asdine/storm
q/tree.go
LtF
func LtF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.LSS) }
go
func LtF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.LSS) }
[ "func", "LtF", "(", "field1", ",", "field2", "string", ")", "Matcher", "{", "return", "NewField2FieldMatcher", "(", "field1", ",", "field2", ",", "token", ".", "LSS", ")", "\n", "}" ]
// LtF matcher, checks if the given field is lesser than the given field
[ "LtF", "matcher", "checks", "if", "the", "given", "field", "is", "lesser", "than", "the", "given", "field" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L217-L219
train
asdine/storm
q/tree.go
Lte
func Lte(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.LEQ}) }
go
func Lte(field string, v interface{}) Matcher { return NewFieldMatcher(field, &cmp{value: v, token: token.LEQ}) }
[ "func", "Lte", "(", "field", "string", ",", "v", "interface", "{", "}", ")", "Matcher", "{", "return", "NewFieldMatcher", "(", "field", ",", "&", "cmp", "{", "value", ":", "v", ",", "token", ":", "token", ".", "LEQ", "}", ")", "\n", "}" ]
// Lte matcher, checks if the given field is lesser than or equal to the given value
[ "Lte", "matcher", "checks", "if", "the", "given", "field", "is", "lesser", "than", "or", "equal", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L222-L224
train
asdine/storm
q/tree.go
LteF
func LteF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.LEQ) }
go
func LteF(field1, field2 string) Matcher { return NewField2FieldMatcher(field1, field2, token.LEQ) }
[ "func", "LteF", "(", "field1", ",", "field2", "string", ")", "Matcher", "{", "return", "NewField2FieldMatcher", "(", "field1", ",", "field2", ",", "token", ".", "LEQ", ")", "\n", "}" ]
// LteF matcher, checks if the given field is lesser than or equal to the given field
[ "LteF", "matcher", "checks", "if", "the", "given", "field", "is", "lesser", "than", "or", "equal", "to", "the", "given", "field" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L227-L229
train
asdine/storm
q/tree.go
In
func In(field string, v interface{}) Matcher { return NewFieldMatcher(field, &in{list: v}) }
go
func In(field string, v interface{}) Matcher { return NewFieldMatcher(field, &in{list: v}) }
[ "func", "In", "(", "field", "string", ",", "v", "interface", "{", "}", ")", "Matcher", "{", "return", "NewFieldMatcher", "(", "field", ",", "&", "in", "{", "list", ":", "v", "}", ")", "\n", "}" ]
// In matcher, checks if the given field matches one of the value of the given slice. // v must be a slice.
[ "In", "matcher", "checks", "if", "the", "given", "field", "matches", "one", "of", "the", "value", "of", "the", "given", "slice", ".", "v", "must", "be", "a", "slice", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/tree.go#L233-L235
train
asdine/storm
scan.go
PrefixScan
func (n *node) PrefixScan(prefix string) []Node { if n.tx != nil { return n.prefixScan(n.tx, prefix) } var nodes []Node n.readTx(func(tx *bolt.Tx) error { nodes = n.prefixScan(tx, prefix) return nil }) return nodes }
go
func (n *node) PrefixScan(prefix string) []Node { if n.tx != nil { return n.prefixScan(n.tx, prefix) } var nodes []Node n.readTx(func(tx *bolt.Tx) error { nodes = n.prefixScan(tx, prefix) return nil }) return nodes }
[ "func", "(", "n", "*", "node", ")", "PrefixScan", "(", "prefix", "string", ")", "[", "]", "Node", "{", "if", "n", ".", "tx", "!=", "nil", "{", "return", "n", ".", "prefixScan", "(", "n", ".", "tx", ",", "prefix", ")", "\n", "}", "\n", "var", ...
// PrefixScan scans the buckets in this node for keys matching the given prefix.
[ "PrefixScan", "scans", "the", "buckets", "in", "this", "node", "for", "keys", "matching", "the", "given", "prefix", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/scan.go#L18-L31
train
asdine/storm
scan.go
RangeScan
func (n *node) RangeScan(min, max string) []Node { if n.tx != nil { return n.rangeScan(n.tx, min, max) } var nodes []Node n.readTx(func(tx *bolt.Tx) error { nodes = n.rangeScan(tx, min, max) return nil }) return nodes }
go
func (n *node) RangeScan(min, max string) []Node { if n.tx != nil { return n.rangeScan(n.tx, min, max) } var nodes []Node n.readTx(func(tx *bolt.Tx) error { nodes = n.rangeScan(tx, min, max) return nil }) return nodes }
[ "func", "(", "n", "*", "node", ")", "RangeScan", "(", "min", ",", "max", "string", ")", "[", "]", "Node", "{", "if", "n", ".", "tx", "!=", "nil", "{", "return", "n", ".", "rangeScan", "(", "n", ".", "tx", ",", "min", ",", "max", ")", "\n", ...
// RangeScan scans the buckets in this node over a range such as a sortable time range.
[ "RangeScan", "scans", "the", "buckets", "in", "this", "node", "over", "a", "range", "such", "as", "a", "sortable", "time", "range", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/scan.go#L53-L66
train
asdine/storm
bucket.go
CreateBucketIfNotExists
func (n *node) CreateBucketIfNotExists(tx *bolt.Tx, bucket string) (*bolt.Bucket, error) { var b *bolt.Bucket var err error bucketNames := append(n.rootBucket, bucket) for _, bucketName := range bucketNames { if b != nil { if b, err = b.CreateBucketIfNotExists([]byte(bucketName)); err != nil { return nil, err } } else { if b, err = tx.CreateBucketIfNotExists([]byte(bucketName)); err != nil { return nil, err } } } return b, nil }
go
func (n *node) CreateBucketIfNotExists(tx *bolt.Tx, bucket string) (*bolt.Bucket, error) { var b *bolt.Bucket var err error bucketNames := append(n.rootBucket, bucket) for _, bucketName := range bucketNames { if b != nil { if b, err = b.CreateBucketIfNotExists([]byte(bucketName)); err != nil { return nil, err } } else { if b, err = tx.CreateBucketIfNotExists([]byte(bucketName)); err != nil { return nil, err } } } return b, nil }
[ "func", "(", "n", "*", "node", ")", "CreateBucketIfNotExists", "(", "tx", "*", "bolt", ".", "Tx", ",", "bucket", "string", ")", "(", "*", "bolt", ".", "Bucket", ",", "error", ")", "{", "var", "b", "*", "bolt", ".", "Bucket", "\n", "var", "err", "...
// CreateBucketIfNotExists creates the bucket below the current node if it doesn't // already exist.
[ "CreateBucketIfNotExists", "creates", "the", "bucket", "below", "the", "current", "node", "if", "it", "doesn", "t", "already", "exist", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/bucket.go#L7-L27
train
asdine/storm
bucket.go
GetBucket
func (n *node) GetBucket(tx *bolt.Tx, children ...string) *bolt.Bucket { var b *bolt.Bucket bucketNames := append(n.rootBucket, children...) for _, bucketName := range bucketNames { if b != nil { if b = b.Bucket([]byte(bucketName)); b == nil { return nil } } else { if b = tx.Bucket([]byte(bucketName)); b == nil { return nil } } } return b }
go
func (n *node) GetBucket(tx *bolt.Tx, children ...string) *bolt.Bucket { var b *bolt.Bucket bucketNames := append(n.rootBucket, children...) for _, bucketName := range bucketNames { if b != nil { if b = b.Bucket([]byte(bucketName)); b == nil { return nil } } else { if b = tx.Bucket([]byte(bucketName)); b == nil { return nil } } } return b }
[ "func", "(", "n", "*", "node", ")", "GetBucket", "(", "tx", "*", "bolt", ".", "Tx", ",", "children", "...", "string", ")", "*", "bolt", ".", "Bucket", "{", "var", "b", "*", "bolt", ".", "Bucket", "\n", "bucketNames", ":=", "append", "(", "n", "."...
// GetBucket returns the given bucket below the current node.
[ "GetBucket", "returns", "the", "given", "bucket", "below", "the", "current", "node", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/bucket.go#L30-L47
train
asdine/storm
transaction.go
Begin
func (n node) Begin(writable bool) (Node, error) { var err error n.tx, err = n.s.Bolt.Begin(writable) if err != nil { return nil, err } return &n, nil }
go
func (n node) Begin(writable bool) (Node, error) { var err error n.tx, err = n.s.Bolt.Begin(writable) if err != nil { return nil, err } return &n, nil }
[ "func", "(", "n", "node", ")", "Begin", "(", "writable", "bool", ")", "(", "Node", ",", "error", ")", "{", "var", "err", "error", "\n", "n", ".", "tx", ",", "err", "=", "n", ".", "s", ".", "Bolt", ".", "Begin", "(", "writable", ")", "\n", "if...
// Begin starts a new transaction.
[ "Begin", "starts", "a", "new", "transaction", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/transaction.go#L15-L24
train
asdine/storm
transaction.go
Rollback
func (n *node) Rollback() error { if n.tx == nil { return ErrNotInTransaction } err := n.tx.Rollback() if err == bolt.ErrTxClosed { return ErrNotInTransaction } return err }
go
func (n *node) Rollback() error { if n.tx == nil { return ErrNotInTransaction } err := n.tx.Rollback() if err == bolt.ErrTxClosed { return ErrNotInTransaction } return err }
[ "func", "(", "n", "*", "node", ")", "Rollback", "(", ")", "error", "{", "if", "n", ".", "tx", "==", "nil", "{", "return", "ErrNotInTransaction", "\n", "}", "\n", "err", ":=", "n", ".", "tx", ".", "Rollback", "(", ")", "\n", "if", "err", "==", "...
// Rollback closes the transaction and ignores all previous updates.
[ "Rollback", "closes", "the", "transaction", "and", "ignores", "all", "previous", "updates", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/transaction.go#L27-L38
train
asdine/storm
q/fieldmatcher.go
NewFieldMatcher
func NewFieldMatcher(field string, fm FieldMatcher) Matcher { return fieldMatcherDelegate{Field: field, FieldMatcher: fm} }
go
func NewFieldMatcher(field string, fm FieldMatcher) Matcher { return fieldMatcherDelegate{Field: field, FieldMatcher: fm} }
[ "func", "NewFieldMatcher", "(", "field", "string", ",", "fm", "FieldMatcher", ")", "Matcher", "{", "return", "fieldMatcherDelegate", "{", "Field", ":", "field", ",", "FieldMatcher", ":", "fm", "}", "\n", "}" ]
// NewFieldMatcher creates a Matcher for a given field.
[ "NewFieldMatcher", "creates", "a", "Matcher", "for", "a", "given", "field", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/fieldmatcher.go#L18-L20
train
asdine/storm
q/fieldmatcher.go
NewField2FieldMatcher
func NewField2FieldMatcher(field1, field2 string, tok token.Token) Matcher { return field2fieldMatcherDelegate{Field1: field1, Field2: field2, Tok: tok} }
go
func NewField2FieldMatcher(field1, field2 string, tok token.Token) Matcher { return field2fieldMatcherDelegate{Field1: field1, Field2: field2, Tok: tok} }
[ "func", "NewField2FieldMatcher", "(", "field1", ",", "field2", "string", ",", "tok", "token", ".", "Token", ")", "Matcher", "{", "return", "field2fieldMatcherDelegate", "{", "Field1", ":", "field1", ",", "Field2", ":", "field2", ",", "Tok", ":", "tok", "}", ...
// NewField2FieldMatcher creates a Matcher for a given field1 and field2.
[ "NewField2FieldMatcher", "creates", "a", "Matcher", "for", "a", "given", "field1", "and", "field2", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/q/fieldmatcher.go#L43-L45
train
asdine/storm
finder.go
One
func (n *node) One(fieldName string, value interface{}, to interface{}) error { sink, err := newFirstSink(n, to) if err != nil { return err } bucketName := sink.bucketName() if bucketName == "" { return ErrNoName } if fieldName == "" { return ErrNotFound } ref := reflect.Indirect(sink.ref) cfg, err := extractSingleField(&ref, fieldName) if err != nil { return err } field, ok := cfg.Fields[fieldName] if !ok || (!field.IsID && field.Index == "") { query := newQuery(n, q.StrictEq(fieldName, value)) query.Limit(1) if n.tx != nil { err = query.query(n.tx, sink) } else { err = n.s.Bolt.View(func(tx *bolt.Tx) error { return query.query(tx, sink) }) } if err != nil { return err } return sink.flush() } val, err := toBytes(value, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { return n.one(tx, bucketName, fieldName, cfg, to, val, field.IsID) }) }
go
func (n *node) One(fieldName string, value interface{}, to interface{}) error { sink, err := newFirstSink(n, to) if err != nil { return err } bucketName := sink.bucketName() if bucketName == "" { return ErrNoName } if fieldName == "" { return ErrNotFound } ref := reflect.Indirect(sink.ref) cfg, err := extractSingleField(&ref, fieldName) if err != nil { return err } field, ok := cfg.Fields[fieldName] if !ok || (!field.IsID && field.Index == "") { query := newQuery(n, q.StrictEq(fieldName, value)) query.Limit(1) if n.tx != nil { err = query.query(n.tx, sink) } else { err = n.s.Bolt.View(func(tx *bolt.Tx) error { return query.query(tx, sink) }) } if err != nil { return err } return sink.flush() } val, err := toBytes(value, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { return n.one(tx, bucketName, fieldName, cfg, to, val, field.IsID) }) }
[ "func", "(", "n", "*", "node", ")", "One", "(", "fieldName", "string", ",", "value", "interface", "{", "}", ",", "to", "interface", "{", "}", ")", "error", "{", "sink", ",", "err", ":=", "newFirstSink", "(", "n", ",", "to", ")", "\n", "if", "err"...
// One returns one record by the specified index
[ "One", "returns", "one", "record", "by", "the", "specified", "index" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L41-L90
train
asdine/storm
finder.go
AllByIndex
func (n *node) AllByIndex(fieldName string, to interface{}, options ...func(*index.Options)) error { if fieldName == "" { return n.All(to, options...) } ref := reflect.ValueOf(to) if ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Slice { return ErrSlicePtrNeeded } typ := reflect.Indirect(ref).Type().Elem() if typ.Kind() == reflect.Ptr { typ = typ.Elem() } newElem := reflect.New(typ) cfg, err := extract(&newElem) if err != nil { return err } if cfg.ID.Name == fieldName { return n.All(to, options...) } opts := index.NewOptions() for _, fn := range options { fn(opts) } return n.readTx(func(tx *bolt.Tx) error { return n.allByIndex(tx, fieldName, cfg, &ref, opts) }) }
go
func (n *node) AllByIndex(fieldName string, to interface{}, options ...func(*index.Options)) error { if fieldName == "" { return n.All(to, options...) } ref := reflect.ValueOf(to) if ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Slice { return ErrSlicePtrNeeded } typ := reflect.Indirect(ref).Type().Elem() if typ.Kind() == reflect.Ptr { typ = typ.Elem() } newElem := reflect.New(typ) cfg, err := extract(&newElem) if err != nil { return err } if cfg.ID.Name == fieldName { return n.All(to, options...) } opts := index.NewOptions() for _, fn := range options { fn(opts) } return n.readTx(func(tx *bolt.Tx) error { return n.allByIndex(tx, fieldName, cfg, &ref, opts) }) }
[ "func", "(", "n", "*", "node", ")", "AllByIndex", "(", "fieldName", "string", ",", "to", "interface", "{", "}", ",", "options", "...", "func", "(", "*", "index", ".", "Options", ")", ")", "error", "{", "if", "fieldName", "==", "\"\"", "{", "return", ...
// AllByIndex gets all the records of a bucket that are indexed in the specified index
[ "AllByIndex", "gets", "all", "the", "records", "of", "a", "bucket", "that", "are", "indexed", "in", "the", "specified", "index" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L213-L249
train
asdine/storm
finder.go
All
func (n *node) All(to interface{}, options ...func(*index.Options)) error { opts := index.NewOptions() for _, fn := range options { fn(opts) } query := newQuery(n, nil).Limit(opts.Limit).Skip(opts.Skip) if opts.Reverse { query.Reverse() } err := query.Find(to) if err != nil && err != ErrNotFound { return err } if err == ErrNotFound { ref := reflect.ValueOf(to) results := reflect.MakeSlice(reflect.Indirect(ref).Type(), 0, 0) reflect.Indirect(ref).Set(results) } return nil }
go
func (n *node) All(to interface{}, options ...func(*index.Options)) error { opts := index.NewOptions() for _, fn := range options { fn(opts) } query := newQuery(n, nil).Limit(opts.Limit).Skip(opts.Skip) if opts.Reverse { query.Reverse() } err := query.Find(to) if err != nil && err != ErrNotFound { return err } if err == ErrNotFound { ref := reflect.ValueOf(to) results := reflect.MakeSlice(reflect.Indirect(ref).Type(), 0, 0) reflect.Indirect(ref).Set(results) } return nil }
[ "func", "(", "n", "*", "node", ")", "All", "(", "to", "interface", "{", "}", ",", "options", "...", "func", "(", "*", "index", ".", "Options", ")", ")", "error", "{", "opts", ":=", "index", ".", "NewOptions", "(", ")", "\n", "for", "_", ",", "f...
// All gets all the records of a bucket. // If there are no records it returns no error and the 'to' parameter is set to an empty slice.
[ "All", "gets", "all", "the", "records", "of", "a", "bucket", ".", "If", "there", "are", "no", "records", "it", "returns", "no", "error", "and", "the", "to", "parameter", "is", "set", "to", "an", "empty", "slice", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L295-L317
train
asdine/storm
finder.go
Range
func (n *node) Range(fieldName string, min, max, to interface{}, options ...func(*index.Options)) error { sink, err := newListSink(n, to) if err != nil { return err } bucketName := sink.bucketName() if bucketName == "" { return ErrNoName } ref := reflect.Indirect(reflect.New(sink.elemType)) cfg, err := extractSingleField(&ref, fieldName) if err != nil { return err } opts := index.NewOptions() for _, fn := range options { fn(opts) } field, ok := cfg.Fields[fieldName] if !ok || (!field.IsID && field.Index == "") { query := newQuery(n, q.And(q.Gte(fieldName, min), q.Lte(fieldName, max))) query.Skip(opts.Skip).Limit(opts.Limit) if opts.Reverse { query.Reverse() } err = n.readTx(func(tx *bolt.Tx) error { return query.query(tx, sink) }) if err != nil { return err } return sink.flush() } mn, err := toBytes(min, n.codec) if err != nil { return err } mx, err := toBytes(max, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { return n.rnge(tx, bucketName, fieldName, cfg, sink, mn, mx, opts) }) }
go
func (n *node) Range(fieldName string, min, max, to interface{}, options ...func(*index.Options)) error { sink, err := newListSink(n, to) if err != nil { return err } bucketName := sink.bucketName() if bucketName == "" { return ErrNoName } ref := reflect.Indirect(reflect.New(sink.elemType)) cfg, err := extractSingleField(&ref, fieldName) if err != nil { return err } opts := index.NewOptions() for _, fn := range options { fn(opts) } field, ok := cfg.Fields[fieldName] if !ok || (!field.IsID && field.Index == "") { query := newQuery(n, q.And(q.Gte(fieldName, min), q.Lte(fieldName, max))) query.Skip(opts.Skip).Limit(opts.Limit) if opts.Reverse { query.Reverse() } err = n.readTx(func(tx *bolt.Tx) error { return query.query(tx, sink) }) if err != nil { return err } return sink.flush() } mn, err := toBytes(min, n.codec) if err != nil { return err } mx, err := toBytes(max, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { return n.rnge(tx, bucketName, fieldName, cfg, sink, mn, mx, opts) }) }
[ "func", "(", "n", "*", "node", ")", "Range", "(", "fieldName", "string", ",", "min", ",", "max", ",", "to", "interface", "{", "}", ",", "options", "...", "func", "(", "*", "index", ".", "Options", ")", ")", "error", "{", "sink", ",", "err", ":=",...
// Range returns one or more records by the specified index within the specified range
[ "Range", "returns", "one", "or", "more", "records", "by", "the", "specified", "index", "within", "the", "specified", "range" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L320-L375
train
asdine/storm
finder.go
Prefix
func (n *node) Prefix(fieldName string, prefix string, to interface{}, options ...func(*index.Options)) error { sink, err := newListSink(n, to) if err != nil { return err } bucketName := sink.bucketName() if bucketName == "" { return ErrNoName } ref := reflect.Indirect(reflect.New(sink.elemType)) cfg, err := extractSingleField(&ref, fieldName) if err != nil { return err } opts := index.NewOptions() for _, fn := range options { fn(opts) } field, ok := cfg.Fields[fieldName] if !ok || (!field.IsID && field.Index == "") { query := newQuery(n, q.Re(fieldName, fmt.Sprintf("^%s", prefix))) query.Skip(opts.Skip).Limit(opts.Limit) if opts.Reverse { query.Reverse() } err = n.readTx(func(tx *bolt.Tx) error { return query.query(tx, sink) }) if err != nil { return err } return sink.flush() } prfx, err := toBytes(prefix, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { return n.prefix(tx, bucketName, fieldName, cfg, sink, prfx, opts) }) }
go
func (n *node) Prefix(fieldName string, prefix string, to interface{}, options ...func(*index.Options)) error { sink, err := newListSink(n, to) if err != nil { return err } bucketName := sink.bucketName() if bucketName == "" { return ErrNoName } ref := reflect.Indirect(reflect.New(sink.elemType)) cfg, err := extractSingleField(&ref, fieldName) if err != nil { return err } opts := index.NewOptions() for _, fn := range options { fn(opts) } field, ok := cfg.Fields[fieldName] if !ok || (!field.IsID && field.Index == "") { query := newQuery(n, q.Re(fieldName, fmt.Sprintf("^%s", prefix))) query.Skip(opts.Skip).Limit(opts.Limit) if opts.Reverse { query.Reverse() } err = n.readTx(func(tx *bolt.Tx) error { return query.query(tx, sink) }) if err != nil { return err } return sink.flush() } prfx, err := toBytes(prefix, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { return n.prefix(tx, bucketName, fieldName, cfg, sink, prfx, opts) }) }
[ "func", "(", "n", "*", "node", ")", "Prefix", "(", "fieldName", "string", ",", "prefix", "string", ",", "to", "interface", "{", "}", ",", "options", "...", "func", "(", "*", "index", ".", "Options", ")", ")", "error", "{", "sink", ",", "err", ":=",...
// Prefix returns one or more records whose given field starts with the specified prefix.
[ "Prefix", "returns", "one", "or", "more", "records", "whose", "given", "field", "starts", "with", "the", "specified", "prefix", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L411-L461
train
asdine/storm
finder.go
Count
func (n *node) Count(data interface{}) (int, error) { return n.Select().Count(data) }
go
func (n *node) Count(data interface{}) (int, error) { return n.Select().Count(data) }
[ "func", "(", "n", "*", "node", ")", "Count", "(", "data", "interface", "{", "}", ")", "(", "int", ",", "error", ")", "{", "return", "n", ".", "Select", "(", ")", ".", "Count", "(", "data", ")", "\n", "}" ]
// Count counts all the records of a bucket
[ "Count", "counts", "all", "the", "records", "of", "a", "bucket" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/finder.go#L497-L499
train
asdine/storm
query.go
Select
func (n *node) Select(matchers ...q.Matcher) Query { tree := q.And(matchers...) return newQuery(n, tree) }
go
func (n *node) Select(matchers ...q.Matcher) Query { tree := q.And(matchers...) return newQuery(n, tree) }
[ "func", "(", "n", "*", "node", ")", "Select", "(", "matchers", "...", "q", ".", "Matcher", ")", "Query", "{", "tree", ":=", "q", ".", "And", "(", "matchers", "...", ")", "\n", "return", "newQuery", "(", "n", ",", "tree", ")", "\n", "}" ]
// Select a list of records that match a list of matchers. Doesn't use indexes.
[ "Select", "a", "list", "of", "records", "that", "match", "a", "list", "of", "matchers", ".", "Doesn", "t", "use", "indexes", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/query.go#L10-L13
train
asdine/storm
index/list.go
NewListIndex
func NewListIndex(parent *bolt.Bucket, indexName []byte) (*ListIndex, error) { var err error b := parent.Bucket(indexName) if b == nil { if !parent.Writable() { return nil, ErrNotFound } b, err = parent.CreateBucket(indexName) if err != nil { return nil, err } } ids, err := NewUniqueIndex(b, []byte("storm__ids")) if err != nil { return nil, err } return &ListIndex{ IndexBucket: b, Parent: parent, IDs: ids, }, nil }
go
func NewListIndex(parent *bolt.Bucket, indexName []byte) (*ListIndex, error) { var err error b := parent.Bucket(indexName) if b == nil { if !parent.Writable() { return nil, ErrNotFound } b, err = parent.CreateBucket(indexName) if err != nil { return nil, err } } ids, err := NewUniqueIndex(b, []byte("storm__ids")) if err != nil { return nil, err } return &ListIndex{ IndexBucket: b, Parent: parent, IDs: ids, }, nil }
[ "func", "NewListIndex", "(", "parent", "*", "bolt", ".", "Bucket", ",", "indexName", "[", "]", "byte", ")", "(", "*", "ListIndex", ",", "error", ")", "{", "var", "err", "error", "\n", "b", ":=", "parent", ".", "Bucket", "(", "indexName", ")", "\n", ...
// NewListIndex loads a ListIndex
[ "NewListIndex", "loads", "a", "ListIndex" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L11-L34
train
asdine/storm
index/list.go
Add
func (idx *ListIndex) Add(newValue []byte, targetID []byte) error { if newValue == nil || len(newValue) == 0 { return ErrNilParam } if targetID == nil || len(targetID) == 0 { return ErrNilParam } key := idx.IDs.Get(targetID) if key != nil { err := idx.IndexBucket.Delete(key) if err != nil { return err } err = idx.IDs.Remove(targetID) if err != nil { return err } key = key[:0] } key = append(key, newValue...) key = append(key, '_') key = append(key, '_') key = append(key, targetID...) err := idx.IDs.Add(targetID, key) if err != nil { return err } return idx.IndexBucket.Put(key, targetID) }
go
func (idx *ListIndex) Add(newValue []byte, targetID []byte) error { if newValue == nil || len(newValue) == 0 { return ErrNilParam } if targetID == nil || len(targetID) == 0 { return ErrNilParam } key := idx.IDs.Get(targetID) if key != nil { err := idx.IndexBucket.Delete(key) if err != nil { return err } err = idx.IDs.Remove(targetID) if err != nil { return err } key = key[:0] } key = append(key, newValue...) key = append(key, '_') key = append(key, '_') key = append(key, targetID...) err := idx.IDs.Add(targetID, key) if err != nil { return err } return idx.IndexBucket.Put(key, targetID) }
[ "func", "(", "idx", "*", "ListIndex", ")", "Add", "(", "newValue", "[", "]", "byte", ",", "targetID", "[", "]", "byte", ")", "error", "{", "if", "newValue", "==", "nil", "||", "len", "(", "newValue", ")", "==", "0", "{", "return", "ErrNilParam", "\...
// Add a value to the list index
[ "Add", "a", "value", "to", "the", "list", "index" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L44-L78
train
asdine/storm
index/list.go
RemoveID
func (idx *ListIndex) RemoveID(targetID []byte) error { value := idx.IDs.Get(targetID) if value == nil { return nil } err := idx.IndexBucket.Delete(value) if err != nil { return err } return idx.IDs.Remove(targetID) }
go
func (idx *ListIndex) RemoveID(targetID []byte) error { value := idx.IDs.Get(targetID) if value == nil { return nil } err := idx.IndexBucket.Delete(value) if err != nil { return err } return idx.IDs.Remove(targetID) }
[ "func", "(", "idx", "*", "ListIndex", ")", "RemoveID", "(", "targetID", "[", "]", "byte", ")", "error", "{", "value", ":=", "idx", ".", "IDs", ".", "Get", "(", "targetID", ")", "\n", "if", "value", "==", "nil", "{", "return", "nil", "\n", "}", "\...
// RemoveID removes an ID from the list index
[ "RemoveID", "removes", "an", "ID", "from", "the", "list", "index" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L103-L115
train
asdine/storm
index/list.go
Get
func (idx *ListIndex) Get(value []byte) []byte { c := idx.IndexBucket.Cursor() prefix := generatePrefix(value) for k, id := c.Seek(prefix); bytes.HasPrefix(k, prefix); k, id = c.Next() { return id } return nil }
go
func (idx *ListIndex) Get(value []byte) []byte { c := idx.IndexBucket.Cursor() prefix := generatePrefix(value) for k, id := c.Seek(prefix); bytes.HasPrefix(k, prefix); k, id = c.Next() { return id } return nil }
[ "func", "(", "idx", "*", "ListIndex", ")", "Get", "(", "value", "[", "]", "byte", ")", "[", "]", "byte", "{", "c", ":=", "idx", ".", "IndexBucket", ".", "Cursor", "(", ")", "\n", "prefix", ":=", "generatePrefix", "(", "value", ")", "\n", "for", "...
// Get the first ID corresponding to the given value
[ "Get", "the", "first", "ID", "corresponding", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L118-L127
train
asdine/storm
index/list.go
All
func (idx *ListIndex) All(value []byte, opts *Options) ([][]byte, error) { var list [][]byte c := idx.IndexBucket.Cursor() cur := internal.Cursor{C: c, Reverse: opts != nil && opts.Reverse} prefix := generatePrefix(value) k, id := c.Seek(prefix) if cur.Reverse { var count int kc := k idc := id for ; kc != nil && bytes.HasPrefix(kc, prefix); kc, idc = c.Next() { count++ k, id = kc, idc } if kc != nil { k, id = c.Prev() } list = make([][]byte, 0, count) } for ; bytes.HasPrefix(k, prefix); k, id = cur.Next() { if opts != nil && opts.Skip > 0 { opts.Skip-- continue } if opts != nil && opts.Limit == 0 { break } if opts != nil && opts.Limit > 0 { opts.Limit-- } list = append(list, id) } return list, nil }
go
func (idx *ListIndex) All(value []byte, opts *Options) ([][]byte, error) { var list [][]byte c := idx.IndexBucket.Cursor() cur := internal.Cursor{C: c, Reverse: opts != nil && opts.Reverse} prefix := generatePrefix(value) k, id := c.Seek(prefix) if cur.Reverse { var count int kc := k idc := id for ; kc != nil && bytes.HasPrefix(kc, prefix); kc, idc = c.Next() { count++ k, id = kc, idc } if kc != nil { k, id = c.Prev() } list = make([][]byte, 0, count) } for ; bytes.HasPrefix(k, prefix); k, id = cur.Next() { if opts != nil && opts.Skip > 0 { opts.Skip-- continue } if opts != nil && opts.Limit == 0 { break } if opts != nil && opts.Limit > 0 { opts.Limit-- } list = append(list, id) } return list, nil }
[ "func", "(", "idx", "*", "ListIndex", ")", "All", "(", "value", "[", "]", "byte", ",", "opts", "*", "Options", ")", "(", "[", "]", "[", "]", "byte", ",", "error", ")", "{", "var", "list", "[", "]", "[", "]", "byte", "\n", "c", ":=", "idx", ...
// All the IDs corresponding to the given value
[ "All", "the", "IDs", "corresponding", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/list.go#L130-L170
train
asdine/storm
node.go
From
func (n node) From(addend ...string) Node { n.rootBucket = append(n.rootBucket, addend...) return &n }
go
func (n node) From(addend ...string) Node { n.rootBucket = append(n.rootBucket, addend...) return &n }
[ "func", "(", "n", "node", ")", "From", "(", "addend", "...", "string", ")", "Node", "{", "n", ".", "rootBucket", "=", "append", "(", "n", ".", "rootBucket", ",", "addend", "...", ")", "\n", "return", "&", "n", "\n", "}" ]
// From returns a new Storm Node with a new bucket root below the current. // All DB operations on the new node will be executed relative to this bucket.
[ "From", "returns", "a", "new", "Storm", "Node", "with", "a", "new", "bucket", "root", "below", "the", "current", ".", "All", "DB", "operations", "on", "the", "new", "node", "will", "be", "executed", "relative", "to", "this", "bucket", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L65-L68
train
asdine/storm
node.go
WithTransaction
func (n node) WithTransaction(tx *bolt.Tx) Node { n.tx = tx return &n }
go
func (n node) WithTransaction(tx *bolt.Tx) Node { n.tx = tx return &n }
[ "func", "(", "n", "node", ")", "WithTransaction", "(", "tx", "*", "bolt", ".", "Tx", ")", "Node", "{", "n", ".", "tx", "=", "tx", "\n", "return", "&", "n", "\n", "}" ]
// WithTransaction returns a new Storm Node that will use the given transaction.
[ "WithTransaction", "returns", "a", "new", "Storm", "Node", "that", "will", "use", "the", "given", "transaction", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L71-L74
train
asdine/storm
node.go
WithCodec
func (n node) WithCodec(codec codec.MarshalUnmarshaler) Node { n.codec = codec return &n }
go
func (n node) WithCodec(codec codec.MarshalUnmarshaler) Node { n.codec = codec return &n }
[ "func", "(", "n", "node", ")", "WithCodec", "(", "codec", "codec", ".", "MarshalUnmarshaler", ")", "Node", "{", "n", ".", "codec", "=", "codec", "\n", "return", "&", "n", "\n", "}" ]
// WithCodec returns a new Storm Node that will use the given Codec.
[ "WithCodec", "returns", "a", "new", "Storm", "Node", "that", "will", "use", "the", "given", "Codec", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L77-L80
train
asdine/storm
node.go
WithBatch
func (n node) WithBatch(enabled bool) Node { n.batchMode = enabled return &n }
go
func (n node) WithBatch(enabled bool) Node { n.batchMode = enabled return &n }
[ "func", "(", "n", "node", ")", "WithBatch", "(", "enabled", "bool", ")", "Node", "{", "n", ".", "batchMode", "=", "enabled", "\n", "return", "&", "n", "\n", "}" ]
// WithBatch returns a new Storm Node with the batch mode enabled.
[ "WithBatch", "returns", "a", "new", "Storm", "Node", "with", "the", "batch", "mode", "enabled", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L83-L86
train
asdine/storm
node.go
readWriteTx
func (n *node) readWriteTx(fn func(tx *bolt.Tx) error) error { if n.tx != nil { return fn(n.tx) } if n.batchMode { return n.s.Bolt.Batch(func(tx *bolt.Tx) error { return fn(tx) }) } return n.s.Bolt.Update(func(tx *bolt.Tx) error { return fn(tx) }) }
go
func (n *node) readWriteTx(fn func(tx *bolt.Tx) error) error { if n.tx != nil { return fn(n.tx) } if n.batchMode { return n.s.Bolt.Batch(func(tx *bolt.Tx) error { return fn(tx) }) } return n.s.Bolt.Update(func(tx *bolt.Tx) error { return fn(tx) }) }
[ "func", "(", "n", "*", "node", ")", "readWriteTx", "(", "fn", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", ")", "error", "{", "if", "n", ".", "tx", "!=", "nil", "{", "return", "fn", "(", "n", ".", "tx", ")", "\n", "}", "\n", "if...
// Detects if already in transaction or runs a read write transaction. // Uses batch mode if enabled.
[ "Detects", "if", "already", "in", "transaction", "or", "runs", "a", "read", "write", "transaction", ".", "Uses", "batch", "mode", "if", "enabled", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L101-L115
train
asdine/storm
node.go
readTx
func (n *node) readTx(fn func(tx *bolt.Tx) error) error { if n.tx != nil { return fn(n.tx) } return n.s.Bolt.View(func(tx *bolt.Tx) error { return fn(tx) }) }
go
func (n *node) readTx(fn func(tx *bolt.Tx) error) error { if n.tx != nil { return fn(n.tx) } return n.s.Bolt.View(func(tx *bolt.Tx) error { return fn(tx) }) }
[ "func", "(", "n", "*", "node", ")", "readTx", "(", "fn", "func", "(", "tx", "*", "bolt", ".", "Tx", ")", "error", ")", "error", "{", "if", "n", ".", "tx", "!=", "nil", "{", "return", "fn", "(", "n", ".", "tx", ")", "\n", "}", "\n", "return"...
// Detects if already in transaction or runs a read transaction.
[ "Detects", "if", "already", "in", "transaction", "or", "runs", "a", "read", "transaction", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/node.go#L118-L126
train
asdine/storm
index/unique.go
NewUniqueIndex
func NewUniqueIndex(parent *bolt.Bucket, indexName []byte) (*UniqueIndex, error) { var err error b := parent.Bucket(indexName) if b == nil { if !parent.Writable() { return nil, ErrNotFound } b, err = parent.CreateBucket(indexName) if err != nil { return nil, err } } return &UniqueIndex{ IndexBucket: b, Parent: parent, }, nil }
go
func NewUniqueIndex(parent *bolt.Bucket, indexName []byte) (*UniqueIndex, error) { var err error b := parent.Bucket(indexName) if b == nil { if !parent.Writable() { return nil, ErrNotFound } b, err = parent.CreateBucket(indexName) if err != nil { return nil, err } } return &UniqueIndex{ IndexBucket: b, Parent: parent, }, nil }
[ "func", "NewUniqueIndex", "(", "parent", "*", "bolt", ".", "Bucket", ",", "indexName", "[", "]", "byte", ")", "(", "*", "UniqueIndex", ",", "error", ")", "{", "var", "err", "error", "\n", "b", ":=", "parent", ".", "Bucket", "(", "indexName", ")", "\n...
// NewUniqueIndex loads a UniqueIndex
[ "NewUniqueIndex", "loads", "a", "UniqueIndex" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L11-L28
train
asdine/storm
index/unique.go
Add
func (idx *UniqueIndex) Add(value []byte, targetID []byte) error { if value == nil || len(value) == 0 { return ErrNilParam } if targetID == nil || len(targetID) == 0 { return ErrNilParam } exists := idx.IndexBucket.Get(value) if exists != nil { if bytes.Equal(exists, targetID) { return nil } return ErrAlreadyExists } return idx.IndexBucket.Put(value, targetID) }
go
func (idx *UniqueIndex) Add(value []byte, targetID []byte) error { if value == nil || len(value) == 0 { return ErrNilParam } if targetID == nil || len(targetID) == 0 { return ErrNilParam } exists := idx.IndexBucket.Get(value) if exists != nil { if bytes.Equal(exists, targetID) { return nil } return ErrAlreadyExists } return idx.IndexBucket.Put(value, targetID) }
[ "func", "(", "idx", "*", "UniqueIndex", ")", "Add", "(", "value", "[", "]", "byte", ",", "targetID", "[", "]", "byte", ")", "error", "{", "if", "value", "==", "nil", "||", "len", "(", "value", ")", "==", "0", "{", "return", "ErrNilParam", "\n", "...
// Add a value to the unique index
[ "Add", "a", "value", "to", "the", "unique", "index" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L37-L54
train
asdine/storm
index/unique.go
RemoveID
func (idx *UniqueIndex) RemoveID(id []byte) error { c := idx.IndexBucket.Cursor() for val, ident := c.First(); val != nil; val, ident = c.Next() { if bytes.Equal(ident, id) { return idx.Remove(val) } } return nil }
go
func (idx *UniqueIndex) RemoveID(id []byte) error { c := idx.IndexBucket.Cursor() for val, ident := c.First(); val != nil; val, ident = c.Next() { if bytes.Equal(ident, id) { return idx.Remove(val) } } return nil }
[ "func", "(", "idx", "*", "UniqueIndex", ")", "RemoveID", "(", "id", "[", "]", "byte", ")", "error", "{", "c", ":=", "idx", ".", "IndexBucket", ".", "Cursor", "(", ")", "\n", "for", "val", ",", "ident", ":=", "c", ".", "First", "(", ")", ";", "v...
// RemoveID removes an ID from the unique index
[ "RemoveID", "removes", "an", "ID", "from", "the", "unique", "index" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L62-L71
train
asdine/storm
index/unique.go
Get
func (idx *UniqueIndex) Get(value []byte) []byte { return idx.IndexBucket.Get(value) }
go
func (idx *UniqueIndex) Get(value []byte) []byte { return idx.IndexBucket.Get(value) }
[ "func", "(", "idx", "*", "UniqueIndex", ")", "Get", "(", "value", "[", "]", "byte", ")", "[", "]", "byte", "{", "return", "idx", ".", "IndexBucket", ".", "Get", "(", "value", ")", "\n", "}" ]
// Get the id corresponding to the given value
[ "Get", "the", "id", "corresponding", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L74-L76
train
asdine/storm
index/unique.go
All
func (idx *UniqueIndex) All(value []byte, opts *Options) ([][]byte, error) { id := idx.IndexBucket.Get(value) if id != nil { return [][]byte{id}, nil } return nil, nil }
go
func (idx *UniqueIndex) All(value []byte, opts *Options) ([][]byte, error) { id := idx.IndexBucket.Get(value) if id != nil { return [][]byte{id}, nil } return nil, nil }
[ "func", "(", "idx", "*", "UniqueIndex", ")", "All", "(", "value", "[", "]", "byte", ",", "opts", "*", "Options", ")", "(", "[", "]", "[", "]", "byte", ",", "error", ")", "{", "id", ":=", "idx", ".", "IndexBucket", ".", "Get", "(", "value", ")",...
// All returns all the ids corresponding to the given value
[ "All", "returns", "all", "the", "ids", "corresponding", "to", "the", "given", "value" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L79-L86
train
asdine/storm
index/unique.go
first
func (idx *UniqueIndex) first() []byte { c := idx.IndexBucket.Cursor() for val, ident := c.First(); val != nil; val, ident = c.Next() { return ident } return nil }
go
func (idx *UniqueIndex) first() []byte { c := idx.IndexBucket.Cursor() for val, ident := c.First(); val != nil; val, ident = c.Next() { return ident } return nil }
[ "func", "(", "idx", "*", "UniqueIndex", ")", "first", "(", ")", "[", "]", "byte", "{", "c", ":=", "idx", ".", "IndexBucket", ".", "Cursor", "(", ")", "\n", "for", "val", ",", "ident", ":=", "c", ".", "First", "(", ")", ";", "val", "!=", "nil", ...
// first returns the first ID of this index
[ "first", "returns", "the", "first", "ID", "of", "this", "index" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/index/unique.go#L176-L183
train
asdine/storm
codec/protobuf/protobuf.go
Marshal
func (c protobufCodec) Marshal(v interface{}) ([]byte, error) { message, ok := v.(proto.Message) if !ok { // toBytes() may need to encode non-protobuf type, if that occurs use json return json.Codec.Marshal(v) } return proto.Marshal(message) }
go
func (c protobufCodec) Marshal(v interface{}) ([]byte, error) { message, ok := v.(proto.Message) if !ok { // toBytes() may need to encode non-protobuf type, if that occurs use json return json.Codec.Marshal(v) } return proto.Marshal(message) }
[ "func", "(", "c", "protobufCodec", ")", "Marshal", "(", "v", "interface", "{", "}", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "message", ",", "ok", ":=", "v", ".", "(", "proto", ".", "Message", ")", "\n", "if", "!", "ok", "{", "return...
// Encode value with protocol buffer. // If type isn't a Protocol buffer Message, json encoder will be used instead.
[ "Encode", "value", "with", "protocol", "buffer", ".", "If", "type", "isn", "t", "a", "Protocol", "buffer", "Message", "json", "encoder", "will", "be", "used", "instead", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/codec/protobuf/protobuf.go#L23-L30
train
asdine/storm
storm.go
Open
func Open(path string, stormOptions ...func(*Options) error) (*DB, error) { var err error var opts Options for _, option := range stormOptions { if err = option(&opts); err != nil { return nil, err } } s := DB{ Bolt: opts.bolt, } n := node{ s: &s, codec: opts.codec, batchMode: opts.batchMode, rootBucket: opts.rootBucket, } if n.codec == nil { n.codec = defaultCodec } if opts.boltMode == 0 { opts.boltMode = 0600 } if opts.boltOptions == nil { opts.boltOptions = &bolt.Options{Timeout: 1 * time.Second} } s.Node = &n // skip if UseDB option is used if s.Bolt == nil { s.Bolt, err = bolt.Open(path, opts.boltMode, opts.boltOptions) if err != nil { return nil, err } } err = s.checkVersion() if err != nil { return nil, err } return &s, nil }
go
func Open(path string, stormOptions ...func(*Options) error) (*DB, error) { var err error var opts Options for _, option := range stormOptions { if err = option(&opts); err != nil { return nil, err } } s := DB{ Bolt: opts.bolt, } n := node{ s: &s, codec: opts.codec, batchMode: opts.batchMode, rootBucket: opts.rootBucket, } if n.codec == nil { n.codec = defaultCodec } if opts.boltMode == 0 { opts.boltMode = 0600 } if opts.boltOptions == nil { opts.boltOptions = &bolt.Options{Timeout: 1 * time.Second} } s.Node = &n // skip if UseDB option is used if s.Bolt == nil { s.Bolt, err = bolt.Open(path, opts.boltMode, opts.boltOptions) if err != nil { return nil, err } } err = s.checkVersion() if err != nil { return nil, err } return &s, nil }
[ "func", "Open", "(", "path", "string", ",", "stormOptions", "...", "func", "(", "*", "Options", ")", "error", ")", "(", "*", "DB", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "opts", "Options", "\n", "for", "_", ",", "option", ":=",...
// Open opens a database at the given path with optional Storm options.
[ "Open", "opens", "a", "database", "at", "the", "given", "path", "with", "optional", "Storm", "options", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/storm.go#L22-L71
train
asdine/storm
storm.go
toBytes
func toBytes(key interface{}, codec codec.MarshalUnmarshaler) ([]byte, error) { if key == nil { return nil, nil } switch t := key.(type) { case []byte: return t, nil case string: return []byte(t), nil case int: return numbertob(int64(t)) case uint: return numbertob(uint64(t)) case int8, int16, int32, int64, uint8, uint16, uint32, uint64: return numbertob(t) default: return codec.Marshal(key) } }
go
func toBytes(key interface{}, codec codec.MarshalUnmarshaler) ([]byte, error) { if key == nil { return nil, nil } switch t := key.(type) { case []byte: return t, nil case string: return []byte(t), nil case int: return numbertob(int64(t)) case uint: return numbertob(uint64(t)) case int8, int16, int32, int64, uint8, uint16, uint32, uint64: return numbertob(t) default: return codec.Marshal(key) } }
[ "func", "toBytes", "(", "key", "interface", "{", "}", ",", "codec", "codec", ".", "MarshalUnmarshaler", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "key", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "switch", "t", ...
// toBytes turns an interface into a slice of bytes
[ "toBytes", "turns", "an", "interface", "into", "a", "slice", "of", "bytes" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/storm.go#L105-L123
train
asdine/storm
options.go
BoltOptions
func BoltOptions(mode os.FileMode, options *bolt.Options) func(*Options) error { return func(opts *Options) error { opts.boltMode = mode opts.boltOptions = options return nil } }
go
func BoltOptions(mode os.FileMode, options *bolt.Options) func(*Options) error { return func(opts *Options) error { opts.boltMode = mode opts.boltOptions = options return nil } }
[ "func", "BoltOptions", "(", "mode", "os", ".", "FileMode", ",", "options", "*", "bolt", ".", "Options", ")", "func", "(", "*", "Options", ")", "error", "{", "return", "func", "(", "opts", "*", "Options", ")", "error", "{", "opts", ".", "boltMode", "=...
// BoltOptions used to pass options to BoltDB.
[ "BoltOptions", "used", "to", "pass", "options", "to", "BoltDB", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L12-L18
train
asdine/storm
options.go
Codec
func Codec(c codec.MarshalUnmarshaler) func(*Options) error { return func(opts *Options) error { opts.codec = c return nil } }
go
func Codec(c codec.MarshalUnmarshaler) func(*Options) error { return func(opts *Options) error { opts.codec = c return nil } }
[ "func", "Codec", "(", "c", "codec", ".", "MarshalUnmarshaler", ")", "func", "(", "*", "Options", ")", "error", "{", "return", "func", "(", "opts", "*", "Options", ")", "error", "{", "opts", ".", "codec", "=", "c", "\n", "return", "nil", "\n", "}", ...
// Codec used to set a custom encoder and decoder. The default is JSON.
[ "Codec", "used", "to", "set", "a", "custom", "encoder", "and", "decoder", ".", "The", "default", "is", "JSON", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L21-L26
train
asdine/storm
options.go
Batch
func Batch() func(*Options) error { return func(opts *Options) error { opts.batchMode = true return nil } }
go
func Batch() func(*Options) error { return func(opts *Options) error { opts.batchMode = true return nil } }
[ "func", "Batch", "(", ")", "func", "(", "*", "Options", ")", "error", "{", "return", "func", "(", "opts", "*", "Options", ")", "error", "{", "opts", ".", "batchMode", "=", "true", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// Batch enables the use of batch instead of update for read-write transactions.
[ "Batch", "enables", "the", "use", "of", "batch", "instead", "of", "update", "for", "read", "-", "write", "transactions", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L29-L34
train
asdine/storm
options.go
Root
func Root(root ...string) func(*Options) error { return func(opts *Options) error { opts.rootBucket = root return nil } }
go
func Root(root ...string) func(*Options) error { return func(opts *Options) error { opts.rootBucket = root return nil } }
[ "func", "Root", "(", "root", "...", "string", ")", "func", "(", "*", "Options", ")", "error", "{", "return", "func", "(", "opts", "*", "Options", ")", "error", "{", "opts", ".", "rootBucket", "=", "root", "\n", "return", "nil", "\n", "}", "\n", "}"...
// Root used to set the root bucket. See also the From method.
[ "Root", "used", "to", "set", "the", "root", "bucket", ".", "See", "also", "the", "From", "method", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L37-L42
train
asdine/storm
options.go
Limit
func Limit(limit int) func(*index.Options) { return func(opts *index.Options) { opts.Limit = limit } }
go
func Limit(limit int) func(*index.Options) { return func(opts *index.Options) { opts.Limit = limit } }
[ "func", "Limit", "(", "limit", "int", ")", "func", "(", "*", "index", ".", "Options", ")", "{", "return", "func", "(", "opts", "*", "index", ".", "Options", ")", "{", "opts", ".", "Limit", "=", "limit", "\n", "}", "\n", "}" ]
// Limit sets the maximum number of records to return
[ "Limit", "sets", "the", "maximum", "number", "of", "records", "to", "return" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L55-L59
train
asdine/storm
options.go
Skip
func Skip(offset int) func(*index.Options) { return func(opts *index.Options) { opts.Skip = offset } }
go
func Skip(offset int) func(*index.Options) { return func(opts *index.Options) { opts.Skip = offset } }
[ "func", "Skip", "(", "offset", "int", ")", "func", "(", "*", "index", ".", "Options", ")", "{", "return", "func", "(", "opts", "*", "index", ".", "Options", ")", "{", "opts", ".", "Skip", "=", "offset", "\n", "}", "\n", "}" ]
// Skip sets the number of records to skip
[ "Skip", "sets", "the", "number", "of", "records", "to", "skip" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/options.go#L62-L66
train
asdine/storm
store.go
Init
func (n *node) Init(data interface{}) error { v := reflect.ValueOf(data) cfg, err := extract(&v) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.init(tx, cfg) }) }
go
func (n *node) Init(data interface{}) error { v := reflect.ValueOf(data) cfg, err := extract(&v) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.init(tx, cfg) }) }
[ "func", "(", "n", "*", "node", ")", "Init", "(", "data", "interface", "{", "}", ")", "error", "{", "v", ":=", "reflect", ".", "ValueOf", "(", "data", ")", "\n", "cfg", ",", "err", ":=", "extract", "(", "&", "v", ")", "\n", "if", "err", "!=", ...
// Init creates the indexes and buckets for a given structure
[ "Init", "creates", "the", "indexes", "and", "buckets", "for", "a", "given", "structure" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L38-L48
train
asdine/storm
store.go
Save
func (n *node) Save(data interface{}) error { ref := reflect.ValueOf(data) if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct { return ErrStructPtrNeeded } cfg, err := extract(&ref) if err != nil { return err } if cfg.ID.IsZero { if !cfg.ID.IsInteger || !cfg.ID.Increment { return ErrZeroID } } return n.readWriteTx(func(tx *bolt.Tx) error { return n.save(tx, cfg, data, false) }) }
go
func (n *node) Save(data interface{}) error { ref := reflect.ValueOf(data) if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct { return ErrStructPtrNeeded } cfg, err := extract(&ref) if err != nil { return err } if cfg.ID.IsZero { if !cfg.ID.IsInteger || !cfg.ID.Increment { return ErrZeroID } } return n.readWriteTx(func(tx *bolt.Tx) error { return n.save(tx, cfg, data, false) }) }
[ "func", "(", "n", "*", "node", ")", "Save", "(", "data", "interface", "{", "}", ")", "error", "{", "ref", ":=", "reflect", ".", "ValueOf", "(", "data", ")", "\n", "if", "!", "ref", ".", "IsValid", "(", ")", "||", "ref", ".", "Kind", "(", ")", ...
// Save a structure
[ "Save", "a", "structure" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L138-L159
train
asdine/storm
store.go
Update
func (n *node) Update(data interface{}) error { return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error { numfield := ref.NumField() for i := 0; i < numfield; i++ { f := ref.Field(i) if ref.Type().Field(i).PkgPath != "" { continue } zero := reflect.Zero(f.Type()).Interface() actual := f.Interface() if !reflect.DeepEqual(actual, zero) { cf := current.Field(i) cf.Set(f) idxInfo, ok := cfg.Fields[ref.Type().Field(i).Name] if ok { idxInfo.Value = &cf } } } return nil }) }
go
func (n *node) Update(data interface{}) error { return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error { numfield := ref.NumField() for i := 0; i < numfield; i++ { f := ref.Field(i) if ref.Type().Field(i).PkgPath != "" { continue } zero := reflect.Zero(f.Type()).Interface() actual := f.Interface() if !reflect.DeepEqual(actual, zero) { cf := current.Field(i) cf.Set(f) idxInfo, ok := cfg.Fields[ref.Type().Field(i).Name] if ok { idxInfo.Value = &cf } } } return nil }) }
[ "func", "(", "n", "*", "node", ")", "Update", "(", "data", "interface", "{", "}", ")", "error", "{", "return", "n", ".", "update", "(", "data", ",", "func", "(", "ref", "*", "reflect", ".", "Value", ",", "current", "*", "reflect", ".", "Value", "...
// Update a structure
[ "Update", "a", "structure" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L258-L279
train
asdine/storm
store.go
UpdateField
func (n *node) UpdateField(data interface{}, fieldName string, value interface{}) error { return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error { f := current.FieldByName(fieldName) if !f.IsValid() { return ErrNotFound } tf, _ := current.Type().FieldByName(fieldName) if tf.PkgPath != "" { return ErrNotFound } v := reflect.ValueOf(value) if v.Kind() != f.Kind() { return ErrIncompatibleValue } f.Set(v) idxInfo, ok := cfg.Fields[fieldName] if ok { idxInfo.Value = &f idxInfo.IsZero = isZero(idxInfo.Value) idxInfo.ForceUpdate = true } return nil }) }
go
func (n *node) UpdateField(data interface{}, fieldName string, value interface{}) error { return n.update(data, func(ref *reflect.Value, current *reflect.Value, cfg *structConfig) error { f := current.FieldByName(fieldName) if !f.IsValid() { return ErrNotFound } tf, _ := current.Type().FieldByName(fieldName) if tf.PkgPath != "" { return ErrNotFound } v := reflect.ValueOf(value) if v.Kind() != f.Kind() { return ErrIncompatibleValue } f.Set(v) idxInfo, ok := cfg.Fields[fieldName] if ok { idxInfo.Value = &f idxInfo.IsZero = isZero(idxInfo.Value) idxInfo.ForceUpdate = true } return nil }) }
[ "func", "(", "n", "*", "node", ")", "UpdateField", "(", "data", "interface", "{", "}", ",", "fieldName", "string", ",", "value", "interface", "{", "}", ")", "error", "{", "return", "n", ".", "update", "(", "data", ",", "func", "(", "ref", "*", "ref...
// UpdateField updates a single field
[ "UpdateField", "updates", "a", "single", "field" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L282-L305
train
asdine/storm
store.go
Drop
func (n *node) Drop(data interface{}) error { var bucketName string v := reflect.ValueOf(data) if v.Kind() != reflect.String { info, err := extract(&v) if err != nil { return err } bucketName = info.Name } else { bucketName = v.Interface().(string) } return n.readWriteTx(func(tx *bolt.Tx) error { return n.drop(tx, bucketName) }) }
go
func (n *node) Drop(data interface{}) error { var bucketName string v := reflect.ValueOf(data) if v.Kind() != reflect.String { info, err := extract(&v) if err != nil { return err } bucketName = info.Name } else { bucketName = v.Interface().(string) } return n.readWriteTx(func(tx *bolt.Tx) error { return n.drop(tx, bucketName) }) }
[ "func", "(", "n", "*", "node", ")", "Drop", "(", "data", "interface", "{", "}", ")", "error", "{", "var", "bucketName", "string", "\n", "v", ":=", "reflect", ".", "ValueOf", "(", "data", ")", "\n", "if", "v", ".", "Kind", "(", ")", "!=", "reflect...
// Drop a bucket
[ "Drop", "a", "bucket" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L342-L360
train
asdine/storm
store.go
DeleteStruct
func (n *node) DeleteStruct(data interface{}) error { ref := reflect.ValueOf(data) if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct { return ErrStructPtrNeeded } cfg, err := extract(&ref) if err != nil { return err } id, err := toBytes(cfg.ID.Value.Interface(), n.codec) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.deleteStruct(tx, cfg, id) }) }
go
func (n *node) DeleteStruct(data interface{}) error { ref := reflect.ValueOf(data) if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct { return ErrStructPtrNeeded } cfg, err := extract(&ref) if err != nil { return err } id, err := toBytes(cfg.ID.Value.Interface(), n.codec) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.deleteStruct(tx, cfg, id) }) }
[ "func", "(", "n", "*", "node", ")", "DeleteStruct", "(", "data", "interface", "{", "}", ")", "error", "{", "ref", ":=", "reflect", ".", "ValueOf", "(", "data", ")", "\n", "if", "!", "ref", ".", "IsValid", "(", ")", "||", "ref", ".", "Kind", "(", ...
// DeleteStruct deletes a structure from the associated bucket
[ "DeleteStruct", "deletes", "a", "structure", "from", "the", "associated", "bucket" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/store.go#L372-L392
train
asdine/storm
kv.go
SetBytes
func (n *node) SetBytes(bucketName string, key interface{}, value []byte) error { if key == nil { return ErrNilParam } id, err := toBytes(key, n.codec) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.setBytes(tx, bucketName, id, value) }) }
go
func (n *node) SetBytes(bucketName string, key interface{}, value []byte) error { if key == nil { return ErrNilParam } id, err := toBytes(key, n.codec) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.setBytes(tx, bucketName, id, value) }) }
[ "func", "(", "n", "*", "node", ")", "SetBytes", "(", "bucketName", "string", ",", "key", "interface", "{", "}", ",", "value", "[", "]", "byte", ")", "error", "{", "if", "key", "==", "nil", "{", "return", "ErrNilParam", "\n", "}", "\n", "id", ",", ...
// SetBytes sets a raw value into a bucket.
[ "SetBytes", "sets", "a", "raw", "value", "into", "a", "bucket", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L61-L74
train
asdine/storm
kv.go
Get
func (n *node) Get(bucketName string, key interface{}, to interface{}) error { ref := reflect.ValueOf(to) if !ref.IsValid() || ref.Kind() != reflect.Ptr { return ErrPtrNeeded } id, err := toBytes(key, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { raw, err := n.getBytes(tx, bucketName, id) if err != nil { return err } return n.codec.Unmarshal(raw, to) }) }
go
func (n *node) Get(bucketName string, key interface{}, to interface{}) error { ref := reflect.ValueOf(to) if !ref.IsValid() || ref.Kind() != reflect.Ptr { return ErrPtrNeeded } id, err := toBytes(key, n.codec) if err != nil { return err } return n.readTx(func(tx *bolt.Tx) error { raw, err := n.getBytes(tx, bucketName, id) if err != nil { return err } return n.codec.Unmarshal(raw, to) }) }
[ "func", "(", "n", "*", "node", ")", "Get", "(", "bucketName", "string", ",", "key", "interface", "{", "}", ",", "to", "interface", "{", "}", ")", "error", "{", "ref", ":=", "reflect", ".", "ValueOf", "(", "to", ")", "\n", "if", "!", "ref", ".", ...
// Get a value from a bucket
[ "Get", "a", "value", "from", "a", "bucket" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L92-L112
train
asdine/storm
kv.go
Delete
func (n *node) Delete(bucketName string, key interface{}) error { id, err := toBytes(key, n.codec) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.delete(tx, bucketName, id) }) }
go
func (n *node) Delete(bucketName string, key interface{}) error { id, err := toBytes(key, n.codec) if err != nil { return err } return n.readWriteTx(func(tx *bolt.Tx) error { return n.delete(tx, bucketName, id) }) }
[ "func", "(", "n", "*", "node", ")", "Delete", "(", "bucketName", "string", ",", "key", "interface", "{", "}", ")", "error", "{", "id", ",", "err", ":=", "toBytes", "(", "key", ",", "n", ".", "codec", ")", "\n", "if", "err", "!=", "nil", "{", "r...
// Delete deletes a key from a bucket
[ "Delete", "deletes", "a", "key", "from", "a", "bucket" ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L129-L138
train
asdine/storm
kv.go
KeyExists
func (n *node) KeyExists(bucketName string, key interface{}) (bool, error) { id, err := toBytes(key, n.codec) if err != nil { return false, err } var exists bool return exists, n.readTx(func(tx *bolt.Tx) error { bucket := n.GetBucket(tx, bucketName) if bucket == nil { return ErrNotFound } v := bucket.Get(id) if v != nil { exists = true } return nil }) }
go
func (n *node) KeyExists(bucketName string, key interface{}) (bool, error) { id, err := toBytes(key, n.codec) if err != nil { return false, err } var exists bool return exists, n.readTx(func(tx *bolt.Tx) error { bucket := n.GetBucket(tx, bucketName) if bucket == nil { return ErrNotFound } v := bucket.Get(id) if v != nil { exists = true } return nil }) }
[ "func", "(", "n", "*", "node", ")", "KeyExists", "(", "bucketName", "string", ",", "key", "interface", "{", "}", ")", "(", "bool", ",", "error", ")", "{", "id", ",", "err", ":=", "toBytes", "(", "key", ",", "n", ".", "codec", ")", "\n", "if", "...
// KeyExists reports the presence of a key in a bucket.
[ "KeyExists", "reports", "the", "presence", "of", "a", "key", "in", "a", "bucket", "." ]
e0f77eada154c7c2670527a8566d3c045880224f
https://github.com/asdine/storm/blob/e0f77eada154c7c2670527a8566d3c045880224f/kv.go#L150-L170
train
gorilla/sessions
store.go
save
func (s *FilesystemStore) save(session *Session) error { encoded, err := securecookie.EncodeMulti(session.Name(), session.Values, s.Codecs...) if err != nil { return err } filename := filepath.Join(s.path, "session_"+session.ID) fileMutex.Lock() defer fileMutex.Unlock() return ioutil.WriteFile(filename, []byte(encoded), 0600) }
go
func (s *FilesystemStore) save(session *Session) error { encoded, err := securecookie.EncodeMulti(session.Name(), session.Values, s.Codecs...) if err != nil { return err } filename := filepath.Join(s.path, "session_"+session.ID) fileMutex.Lock() defer fileMutex.Unlock() return ioutil.WriteFile(filename, []byte(encoded), 0600) }
[ "func", "(", "s", "*", "FilesystemStore", ")", "save", "(", "session", "*", "Session", ")", "error", "{", "encoded", ",", "err", ":=", "securecookie", ".", "EncodeMulti", "(", "session", ".", "Name", "(", ")", ",", "session", ".", "Values", ",", "s", ...
// save writes encoded session.Values to a file.
[ "save", "writes", "encoded", "session", ".", "Values", "to", "a", "file", "." ]
12bd4761fc66ac946e16fcc2a32b1e0b066f6177
https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/store.go#L255-L265
train
gorilla/sessions
store.go
erase
func (s *FilesystemStore) erase(session *Session) error { filename := filepath.Join(s.path, "session_"+session.ID) fileMutex.RLock() defer fileMutex.RUnlock() err := os.Remove(filename) return err }
go
func (s *FilesystemStore) erase(session *Session) error { filename := filepath.Join(s.path, "session_"+session.ID) fileMutex.RLock() defer fileMutex.RUnlock() err := os.Remove(filename) return err }
[ "func", "(", "s", "*", "FilesystemStore", ")", "erase", "(", "session", "*", "Session", ")", "error", "{", "filename", ":=", "filepath", ".", "Join", "(", "s", ".", "path", ",", "\"session_\"", "+", "session", ".", "ID", ")", "\n", "fileMutex", ".", ...
// delete session file
[ "delete", "session", "file" ]
12bd4761fc66ac946e16fcc2a32b1e0b066f6177
https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/store.go#L284-L292
train
gorilla/sessions
sessions.go
GetRegistry
func GetRegistry(r *http.Request) *Registry { var ctx = r.Context() registry := ctx.Value(registryKey) if registry != nil { return registry.(*Registry) } newRegistry := &Registry{ request: r, sessions: make(map[string]sessionInfo), } *r = *r.WithContext(context.WithValue(ctx, registryKey, newRegistry)) return newRegistry }
go
func GetRegistry(r *http.Request) *Registry { var ctx = r.Context() registry := ctx.Value(registryKey) if registry != nil { return registry.(*Registry) } newRegistry := &Registry{ request: r, sessions: make(map[string]sessionInfo), } *r = *r.WithContext(context.WithValue(ctx, registryKey, newRegistry)) return newRegistry }
[ "func", "GetRegistry", "(", "r", "*", "http", ".", "Request", ")", "*", "Registry", "{", "var", "ctx", "=", "r", ".", "Context", "(", ")", "\n", "registry", ":=", "ctx", ".", "Value", "(", "registryKey", ")", "\n", "if", "registry", "!=", "nil", "{...
// GetRegistry returns a registry instance for the current request.
[ "GetRegistry", "returns", "a", "registry", "instance", "for", "the", "current", "request", "." ]
12bd4761fc66ac946e16fcc2a32b1e0b066f6177
https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L109-L121
train
gorilla/sessions
sessions.go
Get
func (s *Registry) Get(store Store, name string) (session *Session, err error) { if !isCookieNameValid(name) { return nil, fmt.Errorf("sessions: invalid character in cookie name: %s", name) } if info, ok := s.sessions[name]; ok { session, err = info.s, info.e } else { session, err = store.New(s.request, name) session.name = name s.sessions[name] = sessionInfo{s: session, e: err} } session.store = store return }
go
func (s *Registry) Get(store Store, name string) (session *Session, err error) { if !isCookieNameValid(name) { return nil, fmt.Errorf("sessions: invalid character in cookie name: %s", name) } if info, ok := s.sessions[name]; ok { session, err = info.s, info.e } else { session, err = store.New(s.request, name) session.name = name s.sessions[name] = sessionInfo{s: session, e: err} } session.store = store return }
[ "func", "(", "s", "*", "Registry", ")", "Get", "(", "store", "Store", ",", "name", "string", ")", "(", "session", "*", "Session", ",", "err", "error", ")", "{", "if", "!", "isCookieNameValid", "(", "name", ")", "{", "return", "nil", ",", "fmt", "."...
// Get registers and returns a session for the given name and session store. // // It returns a new session if there are no sessions registered for the name.
[ "Get", "registers", "and", "returns", "a", "session", "for", "the", "given", "name", "and", "session", "store", ".", "It", "returns", "a", "new", "session", "if", "there", "are", "no", "sessions", "registered", "for", "the", "name", "." ]
12bd4761fc66ac946e16fcc2a32b1e0b066f6177
https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L132-L145
train
gorilla/sessions
sessions.go
Save
func (s *Registry) Save(w http.ResponseWriter) error { var errMulti MultiError for name, info := range s.sessions { session := info.s if session.store == nil { errMulti = append(errMulti, fmt.Errorf( "sessions: missing store for session %q", name)) } else if err := session.store.Save(s.request, w, session); err != nil { errMulti = append(errMulti, fmt.Errorf( "sessions: error saving session %q -- %v", name, err)) } } if errMulti != nil { return errMulti } return nil }
go
func (s *Registry) Save(w http.ResponseWriter) error { var errMulti MultiError for name, info := range s.sessions { session := info.s if session.store == nil { errMulti = append(errMulti, fmt.Errorf( "sessions: missing store for session %q", name)) } else if err := session.store.Save(s.request, w, session); err != nil { errMulti = append(errMulti, fmt.Errorf( "sessions: error saving session %q -- %v", name, err)) } } if errMulti != nil { return errMulti } return nil }
[ "func", "(", "s", "*", "Registry", ")", "Save", "(", "w", "http", ".", "ResponseWriter", ")", "error", "{", "var", "errMulti", "MultiError", "\n", "for", "name", ",", "info", ":=", "range", "s", ".", "sessions", "{", "session", ":=", "info", ".", "s"...
// Save saves all sessions registered for the current request.
[ "Save", "saves", "all", "sessions", "registered", "for", "the", "current", "request", "." ]
12bd4761fc66ac946e16fcc2a32b1e0b066f6177
https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L148-L164
train
gorilla/sessions
sessions.go
Save
func Save(r *http.Request, w http.ResponseWriter) error { return GetRegistry(r).Save(w) }
go
func Save(r *http.Request, w http.ResponseWriter) error { return GetRegistry(r).Save(w) }
[ "func", "Save", "(", "r", "*", "http", ".", "Request", ",", "w", "http", ".", "ResponseWriter", ")", "error", "{", "return", "GetRegistry", "(", "r", ")", ".", "Save", "(", "w", ")", "\n", "}" ]
// Save saves all sessions used during the current request.
[ "Save", "saves", "all", "sessions", "used", "during", "the", "current", "request", "." ]
12bd4761fc66ac946e16fcc2a32b1e0b066f6177
https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/sessions.go#L173-L175
train
gorilla/sessions
cookie_go111.go
newCookieFromOptions
func newCookieFromOptions(name, value string, options *Options) *http.Cookie { return &http.Cookie{ Name: name, Value: value, Path: options.Path, Domain: options.Domain, MaxAge: options.MaxAge, Secure: options.Secure, HttpOnly: options.HttpOnly, SameSite: options.SameSite, } }
go
func newCookieFromOptions(name, value string, options *Options) *http.Cookie { return &http.Cookie{ Name: name, Value: value, Path: options.Path, Domain: options.Domain, MaxAge: options.MaxAge, Secure: options.Secure, HttpOnly: options.HttpOnly, SameSite: options.SameSite, } }
[ "func", "newCookieFromOptions", "(", "name", ",", "value", "string", ",", "options", "*", "Options", ")", "*", "http", ".", "Cookie", "{", "return", "&", "http", ".", "Cookie", "{", "Name", ":", "name", ",", "Value", ":", "value", ",", "Path", ":", "...
// newCookieFromOptions returns an http.Cookie with the options set.
[ "newCookieFromOptions", "returns", "an", "http", ".", "Cookie", "with", "the", "options", "set", "." ]
12bd4761fc66ac946e16fcc2a32b1e0b066f6177
https://github.com/gorilla/sessions/blob/12bd4761fc66ac946e16fcc2a32b1e0b066f6177/cookie_go111.go#L8-L20
train
nfnt/resize
ycc.go
SubImage
func (p *ycc) SubImage(r image.Rectangle) image.Image { r = r.Intersect(p.Rect) if r.Empty() { return &ycc{SubsampleRatio: p.SubsampleRatio} } i := p.PixOffset(r.Min.X, r.Min.Y) return &ycc{ Pix: p.Pix[i:], Stride: p.Stride, Rect: r, SubsampleRatio: p.SubsampleRatio, } }
go
func (p *ycc) SubImage(r image.Rectangle) image.Image { r = r.Intersect(p.Rect) if r.Empty() { return &ycc{SubsampleRatio: p.SubsampleRatio} } i := p.PixOffset(r.Min.X, r.Min.Y) return &ycc{ Pix: p.Pix[i:], Stride: p.Stride, Rect: r, SubsampleRatio: p.SubsampleRatio, } }
[ "func", "(", "p", "*", "ycc", ")", "SubImage", "(", "r", "image", ".", "Rectangle", ")", "image", ".", "Image", "{", "r", "=", "r", ".", "Intersect", "(", "p", ".", "Rect", ")", "\n", "if", "r", ".", "Empty", "(", ")", "{", "return", "&", "yc...
// SubImage returns an image representing the portion of the image p visible // through r. The returned value shares pixels with the original image.
[ "SubImage", "returns", "an", "image", "representing", "the", "portion", "of", "the", "image", "p", "visible", "through", "r", ".", "The", "returned", "value", "shares", "pixels", "with", "the", "original", "image", "." ]
83c6a9932646f83e3267f353373d47347b6036b2
https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L70-L82
train
nfnt/resize
ycc.go
newYCC
func newYCC(r image.Rectangle, s image.YCbCrSubsampleRatio) *ycc { w, h := r.Dx(), r.Dy() buf := make([]uint8, 3*w*h) return &ycc{Pix: buf, Stride: 3 * w, Rect: r, SubsampleRatio: s} }
go
func newYCC(r image.Rectangle, s image.YCbCrSubsampleRatio) *ycc { w, h := r.Dx(), r.Dy() buf := make([]uint8, 3*w*h) return &ycc{Pix: buf, Stride: 3 * w, Rect: r, SubsampleRatio: s} }
[ "func", "newYCC", "(", "r", "image", ".", "Rectangle", ",", "s", "image", ".", "YCbCrSubsampleRatio", ")", "*", "ycc", "{", "w", ",", "h", ":=", "r", ".", "Dx", "(", ")", ",", "r", ".", "Dy", "(", ")", "\n", "buf", ":=", "make", "(", "[", "]"...
// newYCC returns a new ycc with the given bounds and subsample ratio.
[ "newYCC", "returns", "a", "new", "ycc", "with", "the", "given", "bounds", "and", "subsample", "ratio", "." ]
83c6a9932646f83e3267f353373d47347b6036b2
https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L85-L89
train
nfnt/resize
ycc.go
YCbCr
func (p *ycc) YCbCr() *image.YCbCr { ycbcr := image.NewYCbCr(p.Rect, p.SubsampleRatio) switch ycbcr.SubsampleRatio { case ycbcrSubsampleRatio422: return p.ycbcr422(ycbcr) case ycbcrSubsampleRatio420: return p.ycbcr420(ycbcr) case ycbcrSubsampleRatio440: return p.ycbcr440(ycbcr) case ycbcrSubsampleRatio444: return p.ycbcr444(ycbcr) case ycbcrSubsampleRatio411: return p.ycbcr411(ycbcr) case ycbcrSubsampleRatio410: return p.ycbcr410(ycbcr) } return ycbcr }
go
func (p *ycc) YCbCr() *image.YCbCr { ycbcr := image.NewYCbCr(p.Rect, p.SubsampleRatio) switch ycbcr.SubsampleRatio { case ycbcrSubsampleRatio422: return p.ycbcr422(ycbcr) case ycbcrSubsampleRatio420: return p.ycbcr420(ycbcr) case ycbcrSubsampleRatio440: return p.ycbcr440(ycbcr) case ycbcrSubsampleRatio444: return p.ycbcr444(ycbcr) case ycbcrSubsampleRatio411: return p.ycbcr411(ycbcr) case ycbcrSubsampleRatio410: return p.ycbcr410(ycbcr) } return ycbcr }
[ "func", "(", "p", "*", "ycc", ")", "YCbCr", "(", ")", "*", "image", ".", "YCbCr", "{", "ycbcr", ":=", "image", ".", "NewYCbCr", "(", "p", ".", "Rect", ",", "p", ".", "SubsampleRatio", ")", "\n", "switch", "ycbcr", ".", "SubsampleRatio", "{", "case"...
// YCbCr converts ycc to a YCbCr image with the same subsample ratio // as the YCbCr image that ycc was generated from.
[ "YCbCr", "converts", "ycc", "to", "a", "YCbCr", "image", "with", "the", "same", "subsample", "ratio", "as", "the", "YCbCr", "image", "that", "ycc", "was", "generated", "from", "." ]
83c6a9932646f83e3267f353373d47347b6036b2
https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L104-L121
train
nfnt/resize
ycc.go
imageYCbCrToYCC
func imageYCbCrToYCC(in *image.YCbCr) *ycc { w, h := in.Rect.Dx(), in.Rect.Dy() p := ycc{ Pix: make([]uint8, 3*w*h), Stride: 3 * w, Rect: image.Rect(0, 0, w, h), SubsampleRatio: in.SubsampleRatio, } switch in.SubsampleRatio { case ycbcrSubsampleRatio422: return convertToYCC422(in, &p) case ycbcrSubsampleRatio420: return convertToYCC420(in, &p) case ycbcrSubsampleRatio440: return convertToYCC440(in, &p) case ycbcrSubsampleRatio444: return convertToYCC444(in, &p) case ycbcrSubsampleRatio411: return convertToYCC411(in, &p) case ycbcrSubsampleRatio410: return convertToYCC410(in, &p) } return &p }
go
func imageYCbCrToYCC(in *image.YCbCr) *ycc { w, h := in.Rect.Dx(), in.Rect.Dy() p := ycc{ Pix: make([]uint8, 3*w*h), Stride: 3 * w, Rect: image.Rect(0, 0, w, h), SubsampleRatio: in.SubsampleRatio, } switch in.SubsampleRatio { case ycbcrSubsampleRatio422: return convertToYCC422(in, &p) case ycbcrSubsampleRatio420: return convertToYCC420(in, &p) case ycbcrSubsampleRatio440: return convertToYCC440(in, &p) case ycbcrSubsampleRatio444: return convertToYCC444(in, &p) case ycbcrSubsampleRatio411: return convertToYCC411(in, &p) case ycbcrSubsampleRatio410: return convertToYCC410(in, &p) } return &p }
[ "func", "imageYCbCrToYCC", "(", "in", "*", "image", ".", "YCbCr", ")", "*", "ycc", "{", "w", ",", "h", ":=", "in", ".", "Rect", ".", "Dx", "(", ")", ",", "in", ".", "Rect", ".", "Dy", "(", ")", "\n", "p", ":=", "ycc", "{", "Pix", ":", "make...
// imageYCbCrToYCC converts a YCbCr image to a ycc image for resizing.
[ "imageYCbCrToYCC", "converts", "a", "YCbCr", "image", "to", "a", "ycc", "image", "for", "resizing", "." ]
83c6a9932646f83e3267f353373d47347b6036b2
https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/ycc.go#L124-L147
train
nfnt/resize
thumbnail.go
Thumbnail
func Thumbnail(maxWidth, maxHeight uint, img image.Image, interp InterpolationFunction) image.Image { origBounds := img.Bounds() origWidth := uint(origBounds.Dx()) origHeight := uint(origBounds.Dy()) newWidth, newHeight := origWidth, origHeight // Return original image if it have same or smaller size as constraints if maxWidth >= origWidth && maxHeight >= origHeight { return img } // Preserve aspect ratio if origWidth > maxWidth { newHeight = uint(origHeight * maxWidth / origWidth) if newHeight < 1 { newHeight = 1 } newWidth = maxWidth } if newHeight > maxHeight { newWidth = uint(newWidth * maxHeight / newHeight) if newWidth < 1 { newWidth = 1 } newHeight = maxHeight } return Resize(newWidth, newHeight, img, interp) }
go
func Thumbnail(maxWidth, maxHeight uint, img image.Image, interp InterpolationFunction) image.Image { origBounds := img.Bounds() origWidth := uint(origBounds.Dx()) origHeight := uint(origBounds.Dy()) newWidth, newHeight := origWidth, origHeight // Return original image if it have same or smaller size as constraints if maxWidth >= origWidth && maxHeight >= origHeight { return img } // Preserve aspect ratio if origWidth > maxWidth { newHeight = uint(origHeight * maxWidth / origWidth) if newHeight < 1 { newHeight = 1 } newWidth = maxWidth } if newHeight > maxHeight { newWidth = uint(newWidth * maxHeight / newHeight) if newWidth < 1 { newWidth = 1 } newHeight = maxHeight } return Resize(newWidth, newHeight, img, interp) }
[ "func", "Thumbnail", "(", "maxWidth", ",", "maxHeight", "uint", ",", "img", "image", ".", "Image", ",", "interp", "InterpolationFunction", ")", "image", ".", "Image", "{", "origBounds", ":=", "img", ".", "Bounds", "(", ")", "\n", "origWidth", ":=", "uint",...
// Thumbnail will downscale provided image to max width and height preserving // original aspect ratio and using the interpolation function interp. // It will return original image, without processing it, if original sizes // are already smaller than provided constraints.
[ "Thumbnail", "will", "downscale", "provided", "image", "to", "max", "width", "and", "height", "preserving", "original", "aspect", "ratio", "and", "using", "the", "interpolation", "function", "interp", ".", "It", "will", "return", "original", "image", "without", ...
83c6a9932646f83e3267f353373d47347b6036b2
https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/thumbnail.go#L27-L55
train
nfnt/resize
resize.go
kernel
func (i InterpolationFunction) kernel() (int, func(float64) float64) { switch i { case Bilinear: return 2, linear case Bicubic: return 4, cubic case MitchellNetravali: return 4, mitchellnetravali case Lanczos2: return 4, lanczos2 case Lanczos3: return 6, lanczos3 default: // Default to NearestNeighbor. return 2, nearest } }
go
func (i InterpolationFunction) kernel() (int, func(float64) float64) { switch i { case Bilinear: return 2, linear case Bicubic: return 4, cubic case MitchellNetravali: return 4, mitchellnetravali case Lanczos2: return 4, lanczos2 case Lanczos3: return 6, lanczos3 default: // Default to NearestNeighbor. return 2, nearest } }
[ "func", "(", "i", "InterpolationFunction", ")", "kernel", "(", ")", "(", "int", ",", "func", "(", "float64", ")", "float64", ")", "{", "switch", "i", "{", "case", "Bilinear", ":", "return", "2", ",", "linear", "\n", "case", "Bicubic", ":", "return", ...
// kernal, returns an InterpolationFunctions taps and kernel.
[ "kernal", "returns", "an", "InterpolationFunctions", "taps", "and", "kernel", "." ]
83c6a9932646f83e3267f353373d47347b6036b2
https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/resize.go#L55-L71
train
nfnt/resize
resize.go
calcFactors
func calcFactors(width, height uint, oldWidth, oldHeight float64) (scaleX, scaleY float64) { if width == 0 { if height == 0 { scaleX = 1.0 scaleY = 1.0 } else { scaleY = oldHeight / float64(height) scaleX = scaleY } } else { scaleX = oldWidth / float64(width) if height == 0 { scaleY = scaleX } else { scaleY = oldHeight / float64(height) } } return }
go
func calcFactors(width, height uint, oldWidth, oldHeight float64) (scaleX, scaleY float64) { if width == 0 { if height == 0 { scaleX = 1.0 scaleY = 1.0 } else { scaleY = oldHeight / float64(height) scaleX = scaleY } } else { scaleX = oldWidth / float64(width) if height == 0 { scaleY = scaleX } else { scaleY = oldHeight / float64(height) } } return }
[ "func", "calcFactors", "(", "width", ",", "height", "uint", ",", "oldWidth", ",", "oldHeight", "float64", ")", "(", "scaleX", ",", "scaleY", "float64", ")", "{", "if", "width", "==", "0", "{", "if", "height", "==", "0", "{", "scaleX", "=", "1.0", "\n...
// Calculates scaling factors using old and new image dimensions.
[ "Calculates", "scaling", "factors", "using", "old", "and", "new", "image", "dimensions", "." ]
83c6a9932646f83e3267f353373d47347b6036b2
https://github.com/nfnt/resize/blob/83c6a9932646f83e3267f353373d47347b6036b2/resize.go#L593-L611
train
gliderlabs/ssh
server.go
Shutdown
func (srv *Server) Shutdown(ctx context.Context) error { srv.mu.Lock() lnerr := srv.closeListenersLocked() srv.closeDoneChanLocked() srv.mu.Unlock() finished := make(chan struct{}, 1) go func() { srv.listenerWg.Wait() srv.connWg.Wait() finished <- struct{}{} }() select { case <-ctx.Done(): return ctx.Err() case <-finished: return lnerr } }
go
func (srv *Server) Shutdown(ctx context.Context) error { srv.mu.Lock() lnerr := srv.closeListenersLocked() srv.closeDoneChanLocked() srv.mu.Unlock() finished := make(chan struct{}, 1) go func() { srv.listenerWg.Wait() srv.connWg.Wait() finished <- struct{}{} }() select { case <-ctx.Done(): return ctx.Err() case <-finished: return lnerr } }
[ "func", "(", "srv", "*", "Server", ")", "Shutdown", "(", "ctx", "context", ".", "Context", ")", "error", "{", "srv", ".", "mu", ".", "Lock", "(", ")", "\n", "lnerr", ":=", "srv", ".", "closeListenersLocked", "(", ")", "\n", "srv", ".", "closeDoneChan...
// Shutdown gracefully shuts down the server without interrupting any // active connections. Shutdown works by first closing all open // listeners, and then waiting indefinitely for connections to close. // If the provided context expires before the shutdown is complete, // then the context's error is returned.
[ "Shutdown", "gracefully", "shuts", "down", "the", "server", "without", "interrupting", "any", "active", "connections", ".", "Shutdown", "works", "by", "first", "closing", "all", "open", "listeners", "and", "then", "waiting", "indefinitely", "for", "connections", "...
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/server.go#L154-L173
train
gliderlabs/ssh
server.go
Serve
func (srv *Server) Serve(l net.Listener) error { srv.ensureHandlers() defer l.Close() if err := srv.ensureHostSigner(); err != nil { return err } if srv.Handler == nil { srv.Handler = DefaultHandler } if srv.channelHandlers == nil { srv.channelHandlers = map[string]channelHandler{ "session": sessionHandler, "direct-tcpip": directTcpipHandler, } } var tempDelay time.Duration srv.trackListener(l, true) defer srv.trackListener(l, false) for { conn, e := l.Accept() if e != nil { select { case <-srv.getDoneChan(): return ErrServerClosed default: } if ne, ok := e.(net.Error); ok && ne.Temporary() { if tempDelay == 0 { tempDelay = 5 * time.Millisecond } else { tempDelay *= 2 } if max := 1 * time.Second; tempDelay > max { tempDelay = max } time.Sleep(tempDelay) continue } return e } go srv.handleConn(conn) } }
go
func (srv *Server) Serve(l net.Listener) error { srv.ensureHandlers() defer l.Close() if err := srv.ensureHostSigner(); err != nil { return err } if srv.Handler == nil { srv.Handler = DefaultHandler } if srv.channelHandlers == nil { srv.channelHandlers = map[string]channelHandler{ "session": sessionHandler, "direct-tcpip": directTcpipHandler, } } var tempDelay time.Duration srv.trackListener(l, true) defer srv.trackListener(l, false) for { conn, e := l.Accept() if e != nil { select { case <-srv.getDoneChan(): return ErrServerClosed default: } if ne, ok := e.(net.Error); ok && ne.Temporary() { if tempDelay == 0 { tempDelay = 5 * time.Millisecond } else { tempDelay *= 2 } if max := 1 * time.Second; tempDelay > max { tempDelay = max } time.Sleep(tempDelay) continue } return e } go srv.handleConn(conn) } }
[ "func", "(", "srv", "*", "Server", ")", "Serve", "(", "l", "net", ".", "Listener", ")", "error", "{", "srv", ".", "ensureHandlers", "(", ")", "\n", "defer", "l", ".", "Close", "(", ")", "\n", "if", "err", ":=", "srv", ".", "ensureHostSigner", "(", ...
// Serve accepts incoming connections on the Listener l, creating a new // connection goroutine for each. The connection goroutines read requests and then // calls srv.Handler to handle sessions. // // Serve always returns a non-nil error.
[ "Serve", "accepts", "incoming", "connections", "on", "the", "Listener", "l", "creating", "a", "new", "connection", "goroutine", "for", "each", ".", "The", "connection", "goroutines", "read", "requests", "and", "then", "calls", "srv", ".", "Handler", "to", "han...
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/server.go#L180-L223
train
gliderlabs/ssh
ssh.go
Serve
func Serve(l net.Listener, handler Handler, options ...Option) error { srv := &Server{Handler: handler} for _, option := range options { if err := srv.SetOption(option); err != nil { return err } } return srv.Serve(l) }
go
func Serve(l net.Listener, handler Handler, options ...Option) error { srv := &Server{Handler: handler} for _, option := range options { if err := srv.SetOption(option); err != nil { return err } } return srv.Serve(l) }
[ "func", "Serve", "(", "l", "net", ".", "Listener", ",", "handler", "Handler", ",", "options", "...", "Option", ")", "error", "{", "srv", ":=", "&", "Server", "{", "Handler", ":", "handler", "}", "\n", "for", "_", ",", "option", ":=", "range", "option...
// Serve accepts incoming SSH connections on the listener l, creating a new // connection goroutine for each. The connection goroutines read requests and // then calls handler to handle sessions. Handler is typically nil, in which // case the DefaultHandler is used.
[ "Serve", "accepts", "incoming", "SSH", "connections", "on", "the", "listener", "l", "creating", "a", "new", "connection", "goroutine", "for", "each", ".", "The", "connection", "goroutines", "read", "requests", "and", "then", "calls", "handler", "to", "handle", ...
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/ssh.go#L84-L92
train
gliderlabs/ssh
ssh.go
ListenAndServe
func ListenAndServe(addr string, handler Handler, options ...Option) error { srv := &Server{Addr: addr, Handler: handler} for _, option := range options { if err := srv.SetOption(option); err != nil { return err } } return srv.ListenAndServe() }
go
func ListenAndServe(addr string, handler Handler, options ...Option) error { srv := &Server{Addr: addr, Handler: handler} for _, option := range options { if err := srv.SetOption(option); err != nil { return err } } return srv.ListenAndServe() }
[ "func", "ListenAndServe", "(", "addr", "string", ",", "handler", "Handler", ",", "options", "...", "Option", ")", "error", "{", "srv", ":=", "&", "Server", "{", "Addr", ":", "addr", ",", "Handler", ":", "handler", "}", "\n", "for", "_", ",", "option", ...
// ListenAndServe listens on the TCP network address addr and then calls Serve // with handler to handle sessions on incoming connections. Handler is typically // nil, in which case the DefaultHandler is used.
[ "ListenAndServe", "listens", "on", "the", "TCP", "network", "address", "addr", "and", "then", "calls", "Serve", "with", "handler", "to", "handle", "sessions", "on", "incoming", "connections", ".", "Handler", "is", "typically", "nil", "in", "which", "case", "th...
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/ssh.go#L97-L105
train
gliderlabs/ssh
ssh.go
KeysEqual
func KeysEqual(ak, bk PublicKey) bool { //avoid panic if one of the keys is nil, return false instead if ak == nil || bk == nil { return false } a := ak.Marshal() b := bk.Marshal() return (len(a) == len(b) && subtle.ConstantTimeCompare(a, b) == 1) }
go
func KeysEqual(ak, bk PublicKey) bool { //avoid panic if one of the keys is nil, return false instead if ak == nil || bk == nil { return false } a := ak.Marshal() b := bk.Marshal() return (len(a) == len(b) && subtle.ConstantTimeCompare(a, b) == 1) }
[ "func", "KeysEqual", "(", "ak", ",", "bk", "PublicKey", ")", "bool", "{", "if", "ak", "==", "nil", "||", "bk", "==", "nil", "{", "return", "false", "\n", "}", "\n", "a", ":=", "ak", ".", "Marshal", "(", ")", "\n", "b", ":=", "bk", ".", "Marshal...
// KeysEqual is constant time compare of the keys to avoid timing attacks.
[ "KeysEqual", "is", "constant", "time", "compare", "of", "the", "keys", "to", "avoid", "timing", "attacks", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/ssh.go#L113-L123
train
gliderlabs/ssh
options.go
PasswordAuth
func PasswordAuth(fn PasswordHandler) Option { return func(srv *Server) error { srv.PasswordHandler = fn return nil } }
go
func PasswordAuth(fn PasswordHandler) Option { return func(srv *Server) error { srv.PasswordHandler = fn return nil } }
[ "func", "PasswordAuth", "(", "fn", "PasswordHandler", ")", "Option", "{", "return", "func", "(", "srv", "*", "Server", ")", "error", "{", "srv", ".", "PasswordHandler", "=", "fn", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// PasswordAuth returns a functional option that sets PasswordHandler on the server.
[ "PasswordAuth", "returns", "a", "functional", "option", "that", "sets", "PasswordHandler", "on", "the", "server", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L10-L15
train
gliderlabs/ssh
options.go
PublicKeyAuth
func PublicKeyAuth(fn PublicKeyHandler) Option { return func(srv *Server) error { srv.PublicKeyHandler = fn return nil } }
go
func PublicKeyAuth(fn PublicKeyHandler) Option { return func(srv *Server) error { srv.PublicKeyHandler = fn return nil } }
[ "func", "PublicKeyAuth", "(", "fn", "PublicKeyHandler", ")", "Option", "{", "return", "func", "(", "srv", "*", "Server", ")", "error", "{", "srv", ".", "PublicKeyHandler", "=", "fn", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// PublicKeyAuth returns a functional option that sets PublicKeyHandler on the server.
[ "PublicKeyAuth", "returns", "a", "functional", "option", "that", "sets", "PublicKeyHandler", "on", "the", "server", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L18-L23
train
gliderlabs/ssh
options.go
HostKeyFile
func HostKeyFile(filepath string) Option { return func(srv *Server) error { pemBytes, err := ioutil.ReadFile(filepath) if err != nil { return err } signer, err := gossh.ParsePrivateKey(pemBytes) if err != nil { return err } srv.AddHostKey(signer) return nil } }
go
func HostKeyFile(filepath string) Option { return func(srv *Server) error { pemBytes, err := ioutil.ReadFile(filepath) if err != nil { return err } signer, err := gossh.ParsePrivateKey(pemBytes) if err != nil { return err } srv.AddHostKey(signer) return nil } }
[ "func", "HostKeyFile", "(", "filepath", "string", ")", "Option", "{", "return", "func", "(", "srv", "*", "Server", ")", "error", "{", "pemBytes", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "filepath", ")", "\n", "if", "err", "!=", "nil", "{", ...
// HostKeyFile returns a functional option that adds HostSigners to the server // from a PEM file at filepath.
[ "HostKeyFile", "returns", "a", "functional", "option", "that", "adds", "HostSigners", "to", "the", "server", "from", "a", "PEM", "file", "at", "filepath", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L27-L43
train
gliderlabs/ssh
options.go
HostKeyPEM
func HostKeyPEM(bytes []byte) Option { return func(srv *Server) error { signer, err := gossh.ParsePrivateKey(bytes) if err != nil { return err } srv.AddHostKey(signer) return nil } }
go
func HostKeyPEM(bytes []byte) Option { return func(srv *Server) error { signer, err := gossh.ParsePrivateKey(bytes) if err != nil { return err } srv.AddHostKey(signer) return nil } }
[ "func", "HostKeyPEM", "(", "bytes", "[", "]", "byte", ")", "Option", "{", "return", "func", "(", "srv", "*", "Server", ")", "error", "{", "signer", ",", "err", ":=", "gossh", ".", "ParsePrivateKey", "(", "bytes", ")", "\n", "if", "err", "!=", "nil", ...
// HostKeyPEM returns a functional option that adds HostSigners to the server // from a PEM file as bytes.
[ "HostKeyPEM", "returns", "a", "functional", "option", "that", "adds", "HostSigners", "to", "the", "server", "from", "a", "PEM", "file", "as", "bytes", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L47-L58
train
gliderlabs/ssh
options.go
NoPty
func NoPty() Option { return func(srv *Server) error { srv.PtyCallback = func(ctx Context, pty Pty) bool { return false } return nil } }
go
func NoPty() Option { return func(srv *Server) error { srv.PtyCallback = func(ctx Context, pty Pty) bool { return false } return nil } }
[ "func", "NoPty", "(", ")", "Option", "{", "return", "func", "(", "srv", "*", "Server", ")", "error", "{", "srv", ".", "PtyCallback", "=", "func", "(", "ctx", "Context", ",", "pty", "Pty", ")", "bool", "{", "return", "false", "\n", "}", "\n", "retur...
// NoPty returns a functional option that sets PtyCallback to return false, // denying PTY requests.
[ "NoPty", "returns", "a", "functional", "option", "that", "sets", "PtyCallback", "to", "return", "false", "denying", "PTY", "requests", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L62-L69
train
gliderlabs/ssh
options.go
WrapConn
func WrapConn(fn ConnCallback) Option { return func(srv *Server) error { srv.ConnCallback = fn return nil } }
go
func WrapConn(fn ConnCallback) Option { return func(srv *Server) error { srv.ConnCallback = fn return nil } }
[ "func", "WrapConn", "(", "fn", "ConnCallback", ")", "Option", "{", "return", "func", "(", "srv", "*", "Server", ")", "error", "{", "srv", ".", "ConnCallback", "=", "fn", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// WrapConn returns a functional option that sets ConnCallback on the server.
[ "WrapConn", "returns", "a", "functional", "option", "that", "sets", "ConnCallback", "on", "the", "server", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/options.go#L72-L77
train
gliderlabs/ssh
context.go
applyConnMetadata
func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) { if ctx.Value(ContextKeySessionID) != nil { return } ctx.SetValue(ContextKeySessionID, hex.EncodeToString(conn.SessionID())) ctx.SetValue(ContextKeyClientVersion, string(conn.ClientVersion())) ctx.SetValue(ContextKeyServerVersion, string(conn.ServerVersion())) ctx.SetValue(ContextKeyUser, conn.User()) ctx.SetValue(ContextKeyLocalAddr, conn.LocalAddr()) ctx.SetValue(ContextKeyRemoteAddr, conn.RemoteAddr()) }
go
func applyConnMetadata(ctx Context, conn gossh.ConnMetadata) { if ctx.Value(ContextKeySessionID) != nil { return } ctx.SetValue(ContextKeySessionID, hex.EncodeToString(conn.SessionID())) ctx.SetValue(ContextKeyClientVersion, string(conn.ClientVersion())) ctx.SetValue(ContextKeyServerVersion, string(conn.ServerVersion())) ctx.SetValue(ContextKeyUser, conn.User()) ctx.SetValue(ContextKeyLocalAddr, conn.LocalAddr()) ctx.SetValue(ContextKeyRemoteAddr, conn.RemoteAddr()) }
[ "func", "applyConnMetadata", "(", "ctx", "Context", ",", "conn", "gossh", ".", "ConnMetadata", ")", "{", "if", "ctx", ".", "Value", "(", "ContextKeySessionID", ")", "!=", "nil", "{", "return", "\n", "}", "\n", "ctx", ".", "SetValue", "(", "ContextKeySessio...
// this is separate from newContext because we will get ConnMetadata // at different points so it needs to be applied separately
[ "this", "is", "separate", "from", "newContext", "because", "we", "will", "get", "ConnMetadata", "at", "different", "points", "so", "it", "needs", "to", "be", "applied", "separately" ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/context.go#L110-L120
train
gliderlabs/ssh
agent.go
NewAgentListener
func NewAgentListener() (net.Listener, error) { dir, err := ioutil.TempDir("", agentTempDir) if err != nil { return nil, err } l, err := net.Listen("unix", path.Join(dir, agentListenFile)) if err != nil { return nil, err } return l, nil }
go
func NewAgentListener() (net.Listener, error) { dir, err := ioutil.TempDir("", agentTempDir) if err != nil { return nil, err } l, err := net.Listen("unix", path.Join(dir, agentListenFile)) if err != nil { return nil, err } return l, nil }
[ "func", "NewAgentListener", "(", ")", "(", "net", ".", "Listener", ",", "error", ")", "{", "dir", ",", "err", ":=", "ioutil", ".", "TempDir", "(", "\"\"", ",", "agentTempDir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "...
// NewAgentListener sets up a temporary Unix socket that can be communicated // to the session environment and used for forwarding connections.
[ "NewAgentListener", "sets", "up", "a", "temporary", "Unix", "socket", "that", "can", "be", "communicated", "to", "the", "session", "environment", "and", "used", "for", "forwarding", "connections", "." ]
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/agent.go#L38-L48
train
gliderlabs/ssh
agent.go
ForwardAgentConnections
func ForwardAgentConnections(l net.Listener, s Session) { sshConn := s.Context().Value(ContextKeyConn).(gossh.Conn) for { conn, err := l.Accept() if err != nil { return } go func(conn net.Conn) { defer conn.Close() channel, reqs, err := sshConn.OpenChannel(agentChannelType, nil) if err != nil { return } defer channel.Close() go gossh.DiscardRequests(reqs) var wg sync.WaitGroup wg.Add(2) go func() { io.Copy(conn, channel) conn.(*net.UnixConn).CloseWrite() wg.Done() }() go func() { io.Copy(channel, conn) channel.CloseWrite() wg.Done() }() wg.Wait() }(conn) } }
go
func ForwardAgentConnections(l net.Listener, s Session) { sshConn := s.Context().Value(ContextKeyConn).(gossh.Conn) for { conn, err := l.Accept() if err != nil { return } go func(conn net.Conn) { defer conn.Close() channel, reqs, err := sshConn.OpenChannel(agentChannelType, nil) if err != nil { return } defer channel.Close() go gossh.DiscardRequests(reqs) var wg sync.WaitGroup wg.Add(2) go func() { io.Copy(conn, channel) conn.(*net.UnixConn).CloseWrite() wg.Done() }() go func() { io.Copy(channel, conn) channel.CloseWrite() wg.Done() }() wg.Wait() }(conn) } }
[ "func", "ForwardAgentConnections", "(", "l", "net", ".", "Listener", ",", "s", "Session", ")", "{", "sshConn", ":=", "s", ".", "Context", "(", ")", ".", "Value", "(", "ContextKeyConn", ")", ".", "(", "gossh", ".", "Conn", ")", "\n", "for", "{", "conn...
// ForwardAgentConnections takes connections from a listener to proxy into the // session on the OpenSSH channel for agent connections. It blocks and services // connections until the listener stop accepting.
[ "ForwardAgentConnections", "takes", "connections", "from", "a", "listener", "to", "proxy", "into", "the", "session", "on", "the", "OpenSSH", "channel", "for", "agent", "connections", ".", "It", "blocks", "and", "services", "connections", "until", "the", "listener"...
a9daacccc9f1368e52f390591d908470cee477d2
https://github.com/gliderlabs/ssh/blob/a9daacccc9f1368e52f390591d908470cee477d2/agent.go#L53-L83
train
aarzilli/nucular
masterwindow.go
PopupOpen
func (mw *masterWindowCommon) PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) { go func() { mw.ctx.mw.Lock() defer mw.ctx.mw.Unlock() mw.ctx.popupOpen(title, flags, rect, scale, updateFn) mw.ctx.mw.Changed() }() }
go
func (mw *masterWindowCommon) PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) { go func() { mw.ctx.mw.Lock() defer mw.ctx.mw.Unlock() mw.ctx.popupOpen(title, flags, rect, scale, updateFn) mw.ctx.mw.Changed() }() }
[ "func", "(", "mw", "*", "masterWindowCommon", ")", "PopupOpen", "(", "title", "string", ",", "flags", "WindowFlags", ",", "rect", "rect", ".", "Rect", ",", "scale", "bool", ",", "updateFn", "UpdateFn", ")", "{", "go", "func", "(", ")", "{", "mw", ".", ...
// Opens a popup window inside win. Will return true until the // popup window is closed. // The contents of the popup window will be updated by updateFn
[ "Opens", "a", "popup", "window", "inside", "win", ".", "Will", "return", "true", "until", "the", "popup", "window", "is", "closed", ".", "The", "contents", "of", "the", "popup", "window", "will", "be", "updated", "by", "updateFn" ]
64ec1eba91814ebb417978927206070dd1fc44e1
https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/masterwindow.go#L134-L141
train
aarzilli/nucular
masterwindow.go
drawChanged
func (w *masterWindowCommon) drawChanged() bool { contextAllCommands(w.ctx) w.ctx.Reset() cmds := w.ctx.cmds if len(cmds) != len(w.prevCmds) { return true } for i := range cmds { if cmds[i].Kind != w.prevCmds[i].Kind { return true } cmd := &cmds[i] pcmd := &w.prevCmds[i] switch cmds[i].Kind { case command.ScissorCmd: if *pcmd != *cmd { return true } case command.LineCmd: if *pcmd != *cmd { return true } case command.RectFilledCmd: if i == 0 { cmd.RectFilled.Color.A = 0xff } if *pcmd != *cmd { return true } case command.TriangleFilledCmd: if *pcmd != *cmd { return true } case command.CircleFilledCmd: if *pcmd != *cmd { return true } case command.ImageCmd: if *pcmd != *cmd { return true } case command.TextCmd: if *pcmd != *cmd { return true } default: panic(UnknownCommandErr) } } return false }
go
func (w *masterWindowCommon) drawChanged() bool { contextAllCommands(w.ctx) w.ctx.Reset() cmds := w.ctx.cmds if len(cmds) != len(w.prevCmds) { return true } for i := range cmds { if cmds[i].Kind != w.prevCmds[i].Kind { return true } cmd := &cmds[i] pcmd := &w.prevCmds[i] switch cmds[i].Kind { case command.ScissorCmd: if *pcmd != *cmd { return true } case command.LineCmd: if *pcmd != *cmd { return true } case command.RectFilledCmd: if i == 0 { cmd.RectFilled.Color.A = 0xff } if *pcmd != *cmd { return true } case command.TriangleFilledCmd: if *pcmd != *cmd { return true } case command.CircleFilledCmd: if *pcmd != *cmd { return true } case command.ImageCmd: if *pcmd != *cmd { return true } case command.TextCmd: if *pcmd != *cmd { return true } default: panic(UnknownCommandErr) } } return false }
[ "func", "(", "w", "*", "masterWindowCommon", ")", "drawChanged", "(", ")", "bool", "{", "contextAllCommands", "(", "w", ".", "ctx", ")", "\n", "w", ".", "ctx", ".", "Reset", "(", ")", "\n", "cmds", ":=", "w", ".", "ctx", ".", "cmds", "\n", "if", ...
// compares cmds to the last draw frame, returns true if there is a change
[ "compares", "cmds", "to", "the", "last", "draw", "frame", "returns", "true", "if", "there", "is", "a", "change" ]
64ec1eba91814ebb417978927206070dd1fc44e1
https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/masterwindow.go#L191-L255
train
aarzilli/nucular
shiny.go
NewMasterWindowSize
func NewMasterWindowSize(flags WindowFlags, title string, sz image.Point, updatefn UpdateFn) MasterWindow { ctx := &context{} wnd := &masterWindow{} wnd.masterWindowCommonInit(ctx, flags, updatefn, wnd) wnd.Title = title wnd.initialSize = sz clipboardMu.Lock() if !clipboardStarted { clipboardStarted = true clipboard.Start() } clipboardMu.Unlock() return wnd }
go
func NewMasterWindowSize(flags WindowFlags, title string, sz image.Point, updatefn UpdateFn) MasterWindow { ctx := &context{} wnd := &masterWindow{} wnd.masterWindowCommonInit(ctx, flags, updatefn, wnd) wnd.Title = title wnd.initialSize = sz clipboardMu.Lock() if !clipboardStarted { clipboardStarted = true clipboard.Start() } clipboardMu.Unlock() return wnd }
[ "func", "NewMasterWindowSize", "(", "flags", "WindowFlags", ",", "title", "string", ",", "sz", "image", ".", "Point", ",", "updatefn", "UpdateFn", ")", "MasterWindow", "{", "ctx", ":=", "&", "context", "{", "}", "\n", "wnd", ":=", "&", "masterWindow", "{",...
// Creates new master window
[ "Creates", "new", "master", "window" ]
64ec1eba91814ebb417978927206070dd1fc44e1
https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/shiny.go#L52-L69
train
aarzilli/nucular
shiny.go
Close
func (mw *masterWindow) Close() { mw.wnd.Send(lifecycle.Event{From: lifecycle.StageAlive, To: lifecycle.StageDead}) }
go
func (mw *masterWindow) Close() { mw.wnd.Send(lifecycle.Event{From: lifecycle.StageAlive, To: lifecycle.StageDead}) }
[ "func", "(", "mw", "*", "masterWindow", ")", "Close", "(", ")", "{", "mw", ".", "wnd", ".", "Send", "(", "lifecycle", ".", "Event", "{", "From", ":", "lifecycle", ".", "StageAlive", ",", "To", ":", "lifecycle", ".", "StageDead", "}", ")", "\n", "}"...
// Programmatically closes window.
[ "Programmatically", "closes", "window", "." ]
64ec1eba91814ebb417978927206070dd1fc44e1
https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/shiny.go#L293-L295
train
aarzilli/nucular
shiny.go
Closed
func (mw *masterWindow) Closed() bool { mw.uilock.Lock() defer mw.uilock.Unlock() return mw.closing }
go
func (mw *masterWindow) Closed() bool { mw.uilock.Lock() defer mw.uilock.Unlock() return mw.closing }
[ "func", "(", "mw", "*", "masterWindow", ")", "Closed", "(", ")", "bool", "{", "mw", ".", "uilock", ".", "Lock", "(", ")", "\n", "defer", "mw", ".", "uilock", ".", "Unlock", "(", ")", "\n", "return", "mw", ".", "closing", "\n", "}" ]
// Returns true if the window is closed.
[ "Returns", "true", "if", "the", "window", "is", "closed", "." ]
64ec1eba91814ebb417978927206070dd1fc44e1
https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/shiny.go#L298-L302
train
aarzilli/nucular
text.go
Delete
func (edit *TextEditor) Delete(where int, len int) { /* delete characters while updating undo */ edit.makeundoDelete(where, len) edit.Buffer = strDeleteText(edit.Buffer, where, len) edit.HasPreferredX = false }
go
func (edit *TextEditor) Delete(where int, len int) { /* delete characters while updating undo */ edit.makeundoDelete(where, len) edit.Buffer = strDeleteText(edit.Buffer, where, len) edit.HasPreferredX = false }
[ "func", "(", "edit", "*", "TextEditor", ")", "Delete", "(", "where", "int", ",", "len", "int", ")", "{", "edit", ".", "makeundoDelete", "(", "where", ",", "len", ")", "\n", "edit", ".", "Buffer", "=", "strDeleteText", "(", "edit", ".", "Buffer", ",",...
// Deletes a chunk of text in the editor.
[ "Deletes", "a", "chunk", "of", "text", "in", "the", "editor", "." ]
64ec1eba91814ebb417978927206070dd1fc44e1
https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L460-L466
train
aarzilli/nucular
text.go
DeleteSelection
func (edit *TextEditor) DeleteSelection() { /* delete the section */ edit.clamp() if edit.hasSelection() { if edit.SelectStart < edit.SelectEnd { edit.Delete(edit.SelectStart, edit.SelectEnd-edit.SelectStart) edit.Cursor = edit.SelectStart edit.SelectEnd = edit.Cursor } else { edit.Delete(edit.SelectEnd, edit.SelectStart-edit.SelectEnd) edit.Cursor = edit.SelectEnd edit.SelectStart = edit.Cursor } edit.HasPreferredX = false } }
go
func (edit *TextEditor) DeleteSelection() { /* delete the section */ edit.clamp() if edit.hasSelection() { if edit.SelectStart < edit.SelectEnd { edit.Delete(edit.SelectStart, edit.SelectEnd-edit.SelectStart) edit.Cursor = edit.SelectStart edit.SelectEnd = edit.Cursor } else { edit.Delete(edit.SelectEnd, edit.SelectStart-edit.SelectEnd) edit.Cursor = edit.SelectEnd edit.SelectStart = edit.Cursor } edit.HasPreferredX = false } }
[ "func", "(", "edit", "*", "TextEditor", ")", "DeleteSelection", "(", ")", "{", "edit", ".", "clamp", "(", ")", "\n", "if", "edit", ".", "hasSelection", "(", ")", "{", "if", "edit", ".", "SelectStart", "<", "edit", ".", "SelectEnd", "{", "edit", ".", ...
// Deletes selection.
[ "Deletes", "selection", "." ]
64ec1eba91814ebb417978927206070dd1fc44e1
https://github.com/aarzilli/nucular/blob/64ec1eba91814ebb417978927206070dd1fc44e1/text.go#L469-L486
train