_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q29300 | Next | train | func (f *FilterIterator) Next() interface{} {
for {
if value := f.iter.Next(); value == nil || !f.filter(value) {
return value
}
}
} | go | {
"resource": ""
} |
q29301 | render | train | func render() error {
tmpl, err := template.New("watch").Parse(source)
if err != nil {
return err
}
if err := tmpl.Execute(os.Stdout, make([]struct{}, aFew)); err != nil {
return err
}
return nil
} | go | {
"resource": ""
} |
q29302 | Validate | train | func (s *DBSchema) Validate() error {
if s == nil {
return fmt.Errorf("schema is nil")
}
if len(s.Tables) == 0 {
return fmt.Errorf("schema has no tables defined")
}
for name, table := range s.Tables {
if name != table.Name {
return fmt.Errorf("table name mis-match for '%s'", name)
}
if err := table... | go | {
"resource": ""
} |
q29303 | Validate | train | func (s *TableSchema) Validate() error {
if s.Name == "" {
return fmt.Errorf("missing table name")
}
if len(s.Indexes) == 0 {
return fmt.Errorf("missing table indexes for '%s'", s.Name)
}
if _, ok := s.Indexes["id"]; !ok {
return fmt.Errorf("must have id index")
}
if !s.Indexes["id"].Unique {
return f... | go | {
"resource": ""
} |
q29304 | NewMemDB | train | func NewMemDB(schema *DBSchema) (*MemDB, error) {
// Validate the schema
if err := schema.Validate(); err != nil {
return nil, err
}
// Create the MemDB
db := &MemDB{
schema: schema,
root: unsafe.Pointer(iradix.New()),
primary: true,
}
if err := db.initialize(); err != nil {
return nil, err
}
r... | go | {
"resource": ""
} |
q29305 | getRoot | train | func (db *MemDB) getRoot() *iradix.Tree {
root := (*iradix.Tree)(atomic.LoadPointer(&db.root))
return root
} | go | {
"resource": ""
} |
q29306 | Txn | train | func (db *MemDB) Txn(write bool) *Txn {
if write {
db.writer.Lock()
}
txn := &Txn{
db: db,
write: write,
rootTxn: db.getRoot().Txn(),
}
return txn
} | go | {
"resource": ""
} |
q29307 | Snapshot | train | func (db *MemDB) Snapshot() *MemDB {
clone := &MemDB{
schema: db.schema,
root: unsafe.Pointer(db.getRoot()),
primary: false,
}
return clone
} | go | {
"resource": ""
} |
q29308 | initialize | train | func (db *MemDB) initialize() error {
root := db.getRoot()
for tName, tableSchema := range db.schema.Tables {
for iName := range tableSchema.Indexes {
index := iradix.New()
path := indexPath(tName, iName)
root, _, _ = root.Insert(path, index)
}
}
db.root = unsafe.Pointer(root)
return nil
} | go | {
"resource": ""
} |
q29309 | IsIntType | train | func IsIntType(k reflect.Kind) (size int, okay bool) {
switch k {
case reflect.Int:
return binary.MaxVarintLen64, true
case reflect.Int8:
return 2, true
case reflect.Int16:
return binary.MaxVarintLen16, true
case reflect.Int32:
return binary.MaxVarintLen32, true
case reflect.Int64:
return binary.MaxVari... | go | {
"resource": ""
} |
q29310 | IsUintType | train | func IsUintType(k reflect.Kind) (size int, okay bool) {
switch k {
case reflect.Uint:
return binary.MaxVarintLen64, true
case reflect.Uint8:
return 2, true
case reflect.Uint16:
return binary.MaxVarintLen16, true
case reflect.Uint32:
return binary.MaxVarintLen32, true
case reflect.Uint64:
return binary.M... | go | {
"resource": ""
} |
q29311 | parseString | train | func (u *UUIDFieldIndex) parseString(s string, enforceLength bool) ([]byte, error) {
// Verify the length
l := len(s)
if enforceLength && l != 36 {
return nil, fmt.Errorf("UUID must be 36 characters")
} else if l > 36 {
return nil, fmt.Errorf("Invalid UUID length. UUID have 36 characters; got %d", l)
}
hyphe... | go | {
"resource": ""
} |
q29312 | fromBoolArgs | train | func fromBoolArgs(args []interface{}) ([]byte, error) {
if len(args) != 1 {
return nil, fmt.Errorf("must provide only a single argument")
}
if val, ok := args[0].(bool); !ok {
return nil, fmt.Errorf("argument must be a boolean type: %#v", args[0])
} else if val {
return []byte{1}, nil
}
return []byte{0}, ... | go | {
"resource": ""
} |
q29313 | watchFew | train | func watchFew(ctx context.Context, ch []<-chan struct{}) error {
select {
case <-ch[0]:
return nil
case <-ch[1]:
return nil
case <-ch[2]:
return nil
case <-ch[3]:
return nil
case <-ch[4]:
return nil
case <-ch[5]:
return nil
case <-ch[6]:
return nil
case <-ch[7]:
return nil
case <-ch[8... | go | {
"resource": ""
} |
q29314 | Add | train | func (w WatchSet) Add(watchCh <-chan struct{}) {
if w == nil {
return
}
if _, ok := w[watchCh]; !ok {
w[watchCh] = struct{}{}
}
} | go | {
"resource": ""
} |
q29315 | Watch | train | func (w WatchSet) Watch(timeoutCh <-chan time.Time) bool {
if w == nil {
return false
}
// Create a context that gets cancelled when the timeout is triggered
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
select {
case <-timeoutCh:
cancel()
case <-ctx.Done():
}
... | go | {
"resource": ""
} |
q29316 | WatchCtx | train | func (w WatchSet) WatchCtx(ctx context.Context) error {
if w == nil {
return nil
}
if n := len(w); n <= aFew {
idx := 0
chunk := make([]<-chan struct{}, aFew)
for watchCh := range w {
chunk[idx] = watchCh
idx++
}
return watchFew(ctx, chunk)
}
return w.watchMany(ctx)
} | go | {
"resource": ""
} |
q29317 | watchMany | train | func (w WatchSet) watchMany(ctx context.Context) error {
// Set up a goroutine for each watcher.
triggerCh := make(chan struct{}, 1)
watcher := func(chunk []<-chan struct{}) {
if err := watchFew(ctx, chunk); err == nil {
select {
case triggerCh <- struct{}{}:
default:
}
}
}
// Apportion the watch ... | go | {
"resource": ""
} |
q29318 | and | train | func (q *Query) and(r *Query) *Query {
return q.andOr(r, QAnd)
} | go | {
"resource": ""
} |
q29319 | or | train | func (q *Query) or(r *Query) *Query {
return q.andOr(r, QOr)
} | go | {
"resource": ""
} |
q29320 | implies | train | func (q *Query) implies(r *Query) bool {
if q.Op == QNone || r.Op == QAll {
// False implies everything.
// Everything implies True.
return true
}
if q.Op == QAll || r.Op == QNone {
// True implies nothing.
// Nothing implies False.
return false
}
if q.Op == QAnd || (q.Op == QOr && len(q.Trigram) == 1... | go | {
"resource": ""
} |
q29321 | maybeRewrite | train | func (q *Query) maybeRewrite(op QueryOp) {
if q.Op != QAnd && q.Op != QOr {
return
}
// AND/OR doing real work? Can't rewrite.
n := len(q.Sub) + len(q.Trigram)
if n > 1 {
return
}
// Nothing left in the AND/OR?
if n == 0 {
if q.Op == QAnd {
q.Op = QAll
} else {
q.Op = QNone
}
return
}
//... | go | {
"resource": ""
} |
q29322 | andTrigrams | train | func (q *Query) andTrigrams(t stringSet) *Query {
if t.minLen() < 3 {
// If there is a short string, we can't guarantee
// that any trigrams must be present, so use ALL.
// q AND ALL = q.
return q
}
//println("andtrigrams", strings.Join(t, ","))
or := noneQuery
for _, tt := range t {
var trig stringSet
... | go | {
"resource": ""
} |
q29323 | RegexpQuery | train | func RegexpQuery(re *syntax.Regexp) *Query {
info := analyze(re)
info.simplify(true)
info.addExact()
return info.match
} | go | {
"resource": ""
} |
q29324 | anyMatch | train | func anyMatch() regexpInfo {
return regexpInfo{
canEmpty: true,
prefix: []string{""},
suffix: []string{""},
match: allQuery,
}
} | go | {
"resource": ""
} |
q29325 | fold | train | func fold(f func(x, y regexpInfo) regexpInfo, sub []*syntax.Regexp, zero regexpInfo) regexpInfo {
if len(sub) == 0 {
return zero
}
if len(sub) == 1 {
return analyze(sub[0])
}
info := f(analyze(sub[0]), analyze(sub[1]))
for i := 2; i < len(sub); i++ {
info = f(info, analyze(sub[i]))
}
return info
} | go | {
"resource": ""
} |
q29326 | concat | train | func concat(x, y regexpInfo) (out regexpInfo) {
//println("concat", x.String(), "...", y.String())
//defer func() { println("->", out.String()) }()
var xy regexpInfo
xy.match = x.match.and(y.match)
if x.exact.have() && y.exact.have() {
xy.exact = x.exact.cross(y.exact, false)
} else {
if x.exact.have() {
x... | go | {
"resource": ""
} |
q29327 | alternate | train | func alternate(x, y regexpInfo) (out regexpInfo) {
//println("alternate", x.String(), "...", y.String())
//defer func() { println("->", out.String()) }()
var xy regexpInfo
if x.exact.have() && y.exact.have() {
xy.exact = x.exact.union(y.exact, false)
} else if x.exact.have() {
xy.prefix = x.exact.union(y.prefi... | go | {
"resource": ""
} |
q29328 | addExact | train | func (info *regexpInfo) addExact() {
if info.exact.have() {
info.match = info.match.andTrigrams(info.exact)
}
} | go | {
"resource": ""
} |
q29329 | simplify | train | func (info *regexpInfo) simplify(force bool) {
//println(" simplify", info.String(), " force=", force)
//defer func() { println(" ->", info.String()) }()
// If there are now too many exact strings,
// loop over them, adding trigrams and moving
// the relevant pieces into prefix and suffix.
info.exact.clean(fals... | go | {
"resource": ""
} |
q29330 | contains | train | func (s stringSet) contains(str string) bool {
for _, ss := range s {
if ss == str {
return true
}
}
return false
} | go | {
"resource": ""
} |
q29331 | clean | train | func (s *stringSet) clean(isSuffix bool) {
t := *s
if isSuffix {
sort.Sort((*bySuffix)(s))
} else {
sort.Sort((*byPrefix)(s))
}
w := 0
for _, str := range t {
if w == 0 || t[w-1] != str {
t[w] = str
w++
}
}
*s = t[:w]
} | go | {
"resource": ""
} |
q29332 | minLen | train | func (s stringSet) minLen() int {
if len(s) == 0 {
return 0
}
m := len(s[0])
for _, str := range s {
if m > len(str) {
m = len(str)
}
}
return m
} | go | {
"resource": ""
} |
q29333 | maxLen | train | func (s stringSet) maxLen() int {
if len(s) == 0 {
return 0
}
m := len(s[0])
for _, str := range s {
if m < len(str) {
m = len(str)
}
}
return m
} | go | {
"resource": ""
} |
q29334 | union | train | func (s stringSet) union(t stringSet, isSuffix bool) stringSet {
s = append(s, t...)
s.clean(isSuffix)
return s
} | go | {
"resource": ""
} |
q29335 | cross | train | func (s stringSet) cross(t stringSet, isSuffix bool) stringSet {
p := stringSet{}
for _, ss := range s {
for _, tt := range t {
p.add(ss + tt)
}
}
p.clean(isSuffix)
return p
} | go | {
"resource": ""
} |
q29336 | isSubsetOf | train | func (s stringSet) isSubsetOf(t stringSet) bool {
j := 0
for _, ss := range s {
for j < len(t) && t[j] < ss {
j++
}
if j >= len(t) || t[j] != ss {
return false
}
}
return true
} | go | {
"resource": ""
} |
q29337 | appendRange | train | func appendRange(r []rune, lo, hi rune) []rune {
// Expand last range or next to last range if it overlaps or abuts.
// Checking two ranges helps when appending case-folded
// alphabets, so that one range can be expanding A-Z and the
// other expanding a-z.
n := len(r)
for i := 2; i <= 4; i += 2 { // twice, using... | go | {
"resource": ""
} |
q29338 | appendFoldedRange | train | func appendFoldedRange(r []rune, lo, hi rune) []rune {
// Optimizations.
if lo <= minFold && hi >= maxFold {
// Range is full: folding can't add more.
return appendRange(r, lo, hi)
}
if hi < minFold || lo > maxFold {
// Range is outside folding possibilities.
return appendRange(r, lo, hi)
}
if lo < minFol... | go | {
"resource": ""
} |
q29339 | Compile | train | func Compile(expr string) (*Regexp, error) {
re, err := syntax.Parse(expr, syntax.Perl)
if err != nil {
return nil, err
}
sre := re.Simplify()
prog, err := syntax.Compile(sre)
if err != nil {
return nil, err
}
if err := toByteProg(prog); err != nil {
return nil, err
}
r := &Regexp{
Syntax: re,
expr:... | go | {
"resource": ""
} |
q29340 | Add | train | func (s *Set) Add(x uint32) {
v := s.sparse[x]
if v < uint32(len(s.dense)) && s.dense[v] == x {
return
}
n := len(s.dense)
s.sparse[x] = uint32(n)
s.dense = append(s.dense, x)
} | go | {
"resource": ""
} |
q29341 | Has | train | func (s *Set) Has(x uint32) bool {
v := s.sparse[x]
return v < uint32(len(s.dense)) && s.dense[v] == x
} | go | {
"resource": ""
} |
q29342 | stepEmpty | train | func (m *matcher) stepEmpty(runq, nextq *sparse.Set, flag syntax.EmptyOp) {
nextq.Reset()
for _, id := range runq.Dense() {
m.addq(nextq, id, flag)
}
} | go | {
"resource": ""
} |
q29343 | stepByte | train | func (m *matcher) stepByte(runq, nextq *sparse.Set, c int, flag syntax.EmptyOp) (match bool) {
nextq.Reset()
m.addq(nextq, uint32(m.prog.Start), flag)
for _, id := range runq.Dense() {
i := &m.prog.Inst[id]
switch i.Op {
default:
continue
case syntax.InstMatch:
match = true
continue
case instByteR... | go | {
"resource": ""
} |
q29344 | addq | train | func (m *matcher) addq(q *sparse.Set, id uint32, flag syntax.EmptyOp) {
if q.Has(id) {
return
}
q.Add(id)
i := &m.prog.Inst[id]
switch i.Op {
case syntax.InstCapture, syntax.InstNop:
m.addq(q, i.Out, flag)
case syntax.InstAlt, syntax.InstAltMatch:
m.addq(q, i.Out, flag)
m.addq(q, i.Arg, flag)
case synta... | go | {
"resource": ""
} |
q29345 | slice | train | func (ix *Index) slice(off uint32, n int) []byte {
o := int(off)
if uint32(o) != off || n >= 0 && o+n > len(ix.data.d) {
corrupt()
}
if n < 0 {
return ix.data.d[o:]
}
return ix.data.d[o : o+n]
} | go | {
"resource": ""
} |
q29346 | uint32 | train | func (ix *Index) uint32(off uint32) uint32 {
return binary.BigEndian.Uint32(ix.slice(off, 4))
} | go | {
"resource": ""
} |
q29347 | uvarint | train | func (ix *Index) uvarint(off uint32) uint32 {
v, n := binary.Uvarint(ix.slice(off, -1))
if n <= 0 {
corrupt()
}
return uint32(v)
} | go | {
"resource": ""
} |
q29348 | Paths | train | func (ix *Index) Paths() []string {
off := ix.pathData
var x []string
for {
s := ix.str(off)
if len(s) == 0 {
break
}
x = append(x, string(s))
off += uint32(len(s) + 1)
}
return x
} | go | {
"resource": ""
} |
q29349 | NameBytes | train | func (ix *Index) NameBytes(fileid uint32) []byte {
off := ix.uint32(ix.nameIndex + 4*fileid)
return ix.str(ix.nameData + off)
} | go | {
"resource": ""
} |
q29350 | Name | train | func (ix *Index) Name(fileid uint32) string {
return string(ix.NameBytes(fileid))
} | go | {
"resource": ""
} |
q29351 | listAt | train | func (ix *Index) listAt(off uint32) (trigram, count, offset uint32) {
d := ix.slice(ix.postIndex+off, postEntrySize)
trigram = uint32(d[0])<<16 | uint32(d[1])<<8 | uint32(d[2])
count = binary.BigEndian.Uint32(d[3:])
offset = binary.BigEndian.Uint32(d[3+4:])
return
} | go | {
"resource": ""
} |
q29352 | mmap | train | func mmap(file string) mmapData {
f, err := os.Open(file)
if err != nil {
log.Fatal(err)
}
return mmapFile(f)
} | go | {
"resource": ""
} |
q29353 | Create | train | func Create(file string) *IndexWriter {
return &IndexWriter{
trigram: sparse.NewSet(1 << 24),
nameData: bufCreate(""),
nameIndex: bufCreate(""),
postIndex: bufCreate(""),
main: bufCreate(file),
post: make([]postEntry, 0, npost),
inbuf: make([]byte, 16384),
}
} | go | {
"resource": ""
} |
q29354 | AddPaths | train | func (ix *IndexWriter) AddPaths(paths []string) {
ix.paths = append(ix.paths, paths...)
} | go | {
"resource": ""
} |
q29355 | Add | train | func (ix *IndexWriter) Add(name string, f io.Reader) {
ix.trigram.Reset()
var (
c = byte(0)
i = 0
buf = ix.inbuf[:0]
tv = uint32(0)
n = int64(0)
linelen = 0
)
for {
tv = (tv << 8) & (1<<24 - 1)
if i >= len(buf) {
n, err := f.Read(buf[:cap(buf)])
if n == 0 {
if er... | go | {
"resource": ""
} |
q29356 | Flush | train | func (ix *IndexWriter) Flush() {
ix.addName("")
var off [5]uint32
ix.main.writeString(magic)
off[0] = ix.main.offset()
for _, p := range ix.paths {
ix.main.writeString(p)
ix.main.writeString("\x00")
}
ix.main.writeString("\x00")
off[1] = ix.main.offset()
copyFile(ix.main, ix.nameData)
off[2] = ix.main.of... | go | {
"resource": ""
} |
q29357 | addName | train | func (ix *IndexWriter) addName(name string) uint32 {
if strings.Contains(name, "\x00") {
log.Fatalf("%q: file has NUL byte in name", name)
}
ix.nameIndex.writeUint32(ix.nameData.offset())
ix.nameData.writeString(name)
ix.nameData.writeByte(0)
id := ix.numName
ix.numName++
return uint32(id)
} | go | {
"resource": ""
} |
q29358 | flushPost | train | func (ix *IndexWriter) flushPost() {
w, err := ioutil.TempFile("", "csearch-index")
if err != nil {
log.Fatal(err)
}
if ix.Verbose {
log.Printf("flush %d entries to %s", len(ix.post), w.Name())
}
sortPost(ix.post)
// Write the raw ix.post array to disk as is.
// This process is the one reading it back in, ... | go | {
"resource": ""
} |
q29359 | mergePost | train | func (ix *IndexWriter) mergePost(out *bufWriter) {
var h postHeap
log.Printf("merge %d files + mem", len(ix.postFile))
for _, f := range ix.postFile {
h.addFile(f)
}
sortPost(ix.post)
h.addMem(ix.post)
npost := 0
e := h.next()
offset0 := out.offset()
for {
npost++
offset := out.offset() - offset0
tr... | go | {
"resource": ""
} |
q29360 | step | train | func (h *postHeap) step(ch *postChunk) bool {
old := ch.e
m := ch.m
if len(m) == 0 {
return false
}
ch.e = postEntry(m[0])
m = m[1:]
ch.m = m
if old >= ch.e {
panic("bad sort")
}
return true
} | go | {
"resource": ""
} |
q29361 | add | train | func (h *postHeap) add(ch *postChunk) {
if len(ch.m) > 0 {
ch.e = ch.m[0]
ch.m = ch.m[1:]
h.push(ch)
}
} | go | {
"resource": ""
} |
q29362 | next | train | func (h *postHeap) next() postEntry {
if len(h.ch) == 0 {
return makePostEntry(1<<24-1, 0)
}
ch := h.ch[0]
e := ch.e
m := ch.m
if len(m) == 0 {
h.pop()
} else {
ch.e = m[0]
ch.m = m[1:]
h.siftDown(0)
}
return e
} | go | {
"resource": ""
} |
q29363 | bufCreate | train | func bufCreate(name string) *bufWriter {
var (
f *os.File
err error
)
if name != "" {
f, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
} else {
f, err = ioutil.TempFile("", "csearch")
}
if err != nil {
log.Fatal(err)
}
return &bufWriter{
name: f.Name(),
buf: make([]byte, 0, 25... | go | {
"resource": ""
} |
q29364 | offset | train | func (b *bufWriter) offset() uint32 {
off, _ := b.file.Seek(0, 1)
off += int64(len(b.buf))
if int64(uint32(off)) != off {
log.Fatalf("index is larger than 4GB")
}
return uint32(off)
} | go | {
"resource": ""
} |
q29365 | finish | train | func (b *bufWriter) finish() *os.File {
b.flush()
f := b.file
f.Seek(0, 0)
return f
} | go | {
"resource": ""
} |
q29366 | validUTF8 | train | func validUTF8(c1, c2 uint32) bool {
switch {
case c1 < 0x80:
// 1-byte, must be followed by 1-byte or first of multi-byte
return c2 < 0x80 || 0xc0 <= c2 && c2 < 0xf8
case c1 < 0xc0:
// continuation byte, can be followed by nearly anything
return c2 < 0xf8
case c1 < 0xf8:
// first of multi-byte, must be f... | go | {
"resource": ""
} |
q29367 | newCCPolicyProvider | train | func newCCPolicyProvider(ctx context.Client, discovery fab.DiscoveryService, channelID string) (CCPolicyProvider, error) {
if channelID == "" {
return nil, errors.New("Must provide channel ID for cc policy provider")
}
cpp := ccPolicyProvider{
context: ctx,
channelID: channelID,
discovery: discovery,
cc... | go | {
"resource": ""
} |
q29368 | NewMockIdentity | train | func NewMockIdentity(err error) (msp.Identity, error) {
return &MockIdentity{Err: err}, nil
} | go | {
"resource": ""
} |
q29369 | Validate | train | func (id *MockIdentity) Validate() error {
if id.Err != nil && id.Err.Error() == "Validate" {
return id.Err
}
return nil
} | go | {
"resource": ""
} |
q29370 | NewStreamConnection | train | func NewStreamConnection(ctx fabcontext.Client, chConfig fab.ChannelCfg, streamProvider StreamProvider, url string, opts ...options.Opt) (*StreamConnection, error) {
conn, err := NewConnection(ctx, url, opts...)
if err != nil {
return nil, err
}
stream, err := streamProvider(conn.conn)
if err != nil {
conn.co... | go | {
"resource": ""
} |
q29371 | CreateConfigSignature | train | func CreateConfigSignature(ctx context.Client, config []byte) (*common.ConfigSignature, error) {
cfd, e := GetConfigSignatureData(ctx, config)
if e != nil {
return nil, e
}
signingMgr := ctx.SigningManager()
signature, err := signingMgr.Sign(cfd.SigningBytes, ctx.PrivateKey())
if err != nil {
return nil, err... | go | {
"resource": ""
} |
q29372 | ExtractChannelConfig | train | func ExtractChannelConfig(configEnvelope []byte) ([]byte, error) {
envelope := &common.Envelope{}
err := proto.Unmarshal(configEnvelope, envelope)
if err != nil {
return nil, errors.Wrap(err, "unmarshal config envelope failed")
}
payload := &common.Payload{}
err = proto.Unmarshal(envelope.Payload, payload)
i... | go | {
"resource": ""
} |
q29373 | CreateConfigEnvelope | train | func CreateConfigEnvelope(data []byte) (*common.ConfigEnvelope, error) {
envelope := &common.Envelope{}
if err := proto.Unmarshal(data, envelope); err != nil {
return nil, errors.Wrap(err, "unmarshal envelope from config block failed")
}
payload := &common.Payload{}
if err := proto.Unmarshal(envelope.Payload, p... | go | {
"resource": ""
} |
q29374 | GetLastConfigFromBlock | train | func GetLastConfigFromBlock(block *common.Block) (*common.LastConfig, error) {
if block.Metadata == nil {
return nil, errors.New("block metadata is nil")
}
metadata := &common.Metadata{}
err := proto.Unmarshal(block.Metadata.Metadata[common.BlockMetadataIndex_LAST_CONFIG], metadata)
if err != nil {
return nil,... | go | {
"resource": ""
} |
q29375 | ConfigFromBackend | train | func ConfigFromBackend(coreBackend ...core.ConfigBackend) core.CryptoSuiteConfig {
return &Config{backend: lookup.New(coreBackend...)}
} | go | {
"resource": ""
} |
q29376 | IsSecurityEnabled | train | func (c *Config) IsSecurityEnabled() bool {
val, ok := c.backend.Lookup("client.BCCSP.security.enabled")
if !ok {
return defEnabled
}
return cast.ToBool(val)
} | go | {
"resource": ""
} |
q29377 | SecurityAlgorithm | train | func (c *Config) SecurityAlgorithm() string {
val, ok := c.backend.Lookup("client.BCCSP.security.hashAlgorithm")
if !ok {
return defHashAlgorithm
}
return cast.ToString(val)
} | go | {
"resource": ""
} |
q29378 | SecurityLevel | train | func (c *Config) SecurityLevel() int {
val, ok := c.backend.Lookup("client.BCCSP.security.level")
if !ok {
return defLevel
}
return cast.ToInt(val)
} | go | {
"resource": ""
} |
q29379 | SecurityProvider | train | func (c *Config) SecurityProvider() string {
val, ok := c.backend.Lookup("client.BCCSP.security.default.provider")
if !ok {
return strings.ToLower(defProvider)
}
return strings.ToLower(cast.ToString(val))
} | go | {
"resource": ""
} |
q29380 | SecurityProviderLibPath | train | func (c *Config) SecurityProviderLibPath() string {
configuredLibs := c.backend.GetString("client.BCCSP.security.library")
libPaths := strings.Split(configuredLibs, ",")
logger.Debugf("Configured BCCSP Lib Paths %s", libPaths)
var lib string
for _, path := range libPaths {
if _, err := os.Stat(strings.TrimSpace(... | go | {
"resource": ""
} |
q29381 | KeyStorePath | train | func (c *Config) KeyStorePath() string {
keystorePath := pathvar.Subst(c.backend.GetString("client.credentialStore.cryptoStore.path"))
return filepath.Join(keystorePath, "keystore")
} | go | {
"resource": ""
} |
q29382 | NewDiscoveryFilterService | train | func NewDiscoveryFilterService(discoveryService fab.DiscoveryService, targetFilter fab.TargetFilter) fab.DiscoveryService {
return &filterService{discoveryService: discoveryService, targetFilter: targetFilter}
} | go | {
"resource": ""
} |
q29383 | GetPeers | train | func (fs *filterService) GetPeers() ([]fab.Peer, error) {
peers, err := fs.discoveryService.GetPeers()
if err != nil {
return nil, err
}
targets := filterTargets(peers, fs.targetFilter)
return targets, nil
} | go | {
"resource": ""
} |
q29384 | filterTargets | train | func filterTargets(peers []fab.Peer, filter fab.TargetFilter) []fab.Peer {
if filter == nil {
return peers
}
filteredPeers := []fab.Peer{}
for _, peer := range peers {
if filter.Accept(peer) {
filteredPeers = append(filteredPeers, peer)
}
}
return filteredPeers
} | go | {
"resource": ""
} |
q29385 | NewMockChannelProvider | train | func NewMockChannelProvider(ctx core.Providers) (*MockChannelProvider, error) {
// Create a mock client with the mock channel
cp := MockChannelProvider{
ctx: ctx,
}
return &cp, nil
} | go | {
"resource": ""
} |
q29386 | ChannelService | train | func (cp *MockChannelProvider) ChannelService(ctx fab.ClientContext, channelID string) (fab.ChannelService, error) {
if cp.customChannelService != nil {
return cp.customChannelService, nil
}
cs := MockChannelService{
provider: cp,
channelID: channelID,
transactor: &MockTransactor{},
discovery: NewMoc... | go | {
"resource": ""
} |
q29387 | EventService | train | func (cs *MockChannelService) EventService(opts ...options.Opt) (fab.EventService, error) {
return NewMockEventService(), nil
} | go | {
"resource": ""
} |
q29388 | Transactor | train | func (cs *MockChannelService) Transactor(reqCtx reqContext.Context) (fab.Transactor, error) {
if cs.transactor != nil {
return cs.transactor, nil
}
return &MockTransactor{ChannelID: cs.channelID, Ctx: reqCtx}, nil
} | go | {
"resource": ""
} |
q29389 | Membership | train | func (cs *MockChannelService) Membership() (fab.ChannelMembership, error) {
if cs.membership != nil {
return cs.membership, nil
}
return NewMockMembership(), nil
} | go | {
"resource": ""
} |
q29390 | ChannelConfig | train | func (cs *MockChannelService) ChannelConfig() (fab.ChannelCfg, error) {
return &MockChannelCfg{MockID: cs.channelID, MockOrderers: cs.mockOrderers}, nil
} | go | {
"resource": ""
} |
q29391 | NewMockConnection | train | func NewMockConnection(opts ...Opt) *MockConnection {
copts := &Opts{}
for _, opt := range opts {
opt(copts)
}
operations := copts.Operations
if operations == nil {
operations = make(map[Operation]ResultDesc)
}
if copts.Ledger == nil {
panic("ledger is nil")
}
sourceURL := copts.SourceURL
if sourceUR... | go | {
"resource": ""
} |
q29392 | Close | train | func (c *MockConnection) Close() {
if !atomic.CompareAndSwapInt32(&c.closed, 0, 1) {
// Already closed
return
}
c.producer.Close()
close(c.rcvch)
} | go | {
"resource": ""
} |
q29393 | Result | train | func (c *MockConnection) Result(operation Operation) (ResultDesc, bool) {
op, ok := c.operations[operation]
return op, ok
} | go | {
"resource": ""
} |
q29394 | Connection | train | func (cp *ProviderFactory) Connection() Connection {
cp.mtx.RLock()
defer cp.mtx.RUnlock()
return cp.connection
} | go | {
"resource": ""
} |
q29395 | Provider | train | func (cp *ProviderFactory) Provider(conn Connection) api.ConnectionProvider {
return func(context.Client, fab.ChannelCfg, fab.Peer) (api.Connection, error) {
return conn, nil
}
} | go | {
"resource": ""
} |
q29396 | FlakeyProvider | train | func (cp *ProviderFactory) FlakeyProvider(connAttemptResults ConnectAttemptResults, opts ...Opt) api.ConnectionProvider {
var connectAttempt Attempt
return func(ctx context.Client, cfg fab.ChannelCfg, peer fab.Peer) (api.Connection, error) {
connectAttempt++
result, ok := connAttemptResults[connectAttempt]
if ... | go | {
"resource": ""
} |
q29397 | NewConnectResult | train | func NewConnectResult(attempt Attempt, connFactory ConnectionFactory) ConnectResult {
return ConnectResult{Attempt: attempt, ConnFactory: connFactory}
} | go | {
"resource": ""
} |
q29398 | NewConnectResults | train | func NewConnectResults(results ...ConnectResult) ConnectAttemptResults {
mapResults := make(map[Attempt]ConnectResult)
for _, r := range results {
mapResults[r.Attempt] = r
}
return mapResults
} | go | {
"resource": ""
} |
q29399 | NewResult | train | func NewResult(operation Operation, result Result, errMsg ...string) *OperationResult {
msg := ""
if len(errMsg) > 0 {
msg = errMsg[0]
}
return &OperationResult{
Operation: operation,
Result: result,
ErrMessage: msg,
}
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.