Notes added by 'git notes append'
This commit is contained in:
parent
36ed89a606
commit
c1fafebee7
|
@ -778,3 +778,86 @@ func file_file_proto_init() {
|
|||
}
|
||||
|
||||
// `autogen:file.sort.pb.go`
|
||||
|
||||
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||
// This file was autogenerated with autogenpb v0.0.40-9-gf329702 2025.01.10_2318
|
||||
// go install go.wit.com/apps/autogenpb@latest
|
||||
//
|
||||
// define which structs (messages) you want to use in the .proto file
|
||||
// Then sort.pb.go and marshal.pb.go files are autogenerated
|
||||
//
|
||||
// autogenpb uses it and has an example .proto file with instructions
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type FileIterator struct {
|
||||
sync.RWMutex
|
||||
|
||||
things []*File
|
||||
index int
|
||||
}
|
||||
|
||||
// NewFileIterator initializes a new iterator.
|
||||
func NewFileIterator(things []*File) *FileIterator {
|
||||
return &FileIterator{things: things}
|
||||
}
|
||||
|
||||
// Scan moves to the next element and returns false if there are no more things.
|
||||
// Use Scan() in a loop, similar to a while loop
|
||||
//
|
||||
// for iterator.Scan()
|
||||
// d := iterator.Next(
|
||||
// fmt.Println("found UUID:", d.Uuid
|
||||
// }
|
||||
func (it *FileIterator) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.index++
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *FileIterator) Next() *File {
|
||||
if it.things[it.index-1] == nil {
|
||||
for i, d := range it.things {
|
||||
fmt.Println("i =", i, d)
|
||||
}
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
func (all *Files) All() *FileIterator {
|
||||
FilePointers := all.selectAllFile()
|
||||
|
||||
iterator := NewFileIterator(FilePointers)
|
||||
return iterator
|
||||
}
|
||||
|
||||
func (all *Files) Len() int {
|
||||
all.Lock.RLock()
|
||||
defer all.Lock.RUnlock()
|
||||
|
||||
return len(all.Files)
|
||||
}
|
||||
|
||||
// safely returns a slice of pointers to the File protobufs
|
||||
func (all *Files) selectAllFile() []*File {
|
||||
all.Lock.RLock()
|
||||
defer all.Lock.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each File
|
||||
var tmp []*File
|
||||
tmp = make([]*File, len(all.Files))
|
||||
for i, p := range all.Files {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue