Notes added by 'git notes append'

This commit is contained in:
Jeff Carr 2025-01-11 06:17:21 -06:00
parent 0dfe02b11c
commit 8250d96976
1 changed files with 98 additions and 0 deletions

View File

@ -560,3 +560,101 @@ func file_forgeConfig_proto_init() {
} }
// `autogen:forgeConfig.sort.pb.go` // `autogen:forgeConfig.sort.pb.go`
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.40-19-gfed674d 2025.01.11_0448
// 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 forgepb
import (
"fmt"
"sort"
"sync"
)
type ForgeConfigIterator struct {
sync.RWMutex
things []*ForgeConfig
index int
}
// NewForgeConfigIterator initializes a new iterator.
func NewForgeConfigIterator(things []*ForgeConfig) *ForgeConfigIterator {
return &ForgeConfigIterator{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 *ForgeConfigIterator) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.index++
return true
}
// Next() returns the next thing in the array
func (it *ForgeConfigIterator) Next() *ForgeConfig {
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 (x *ForgeConfigs) All() *ForgeConfigIterator {
ForgeConfigPointers := x.selectAllForgeConfig()
iterator := NewForgeConfigIterator(ForgeConfigPointers)
return iterator
}
func (x *ForgeConfigs) Len() int {
x.Lock.RLock()
defer x.Lock.RUnlock()
return len(x.ForgeConfigs)
}
// safely returns a slice of pointers to the ForgeConfig protobufs
func (x *ForgeConfigs) selectAllForgeConfig() []*ForgeConfig {
x.Lock.RLock()
defer x.Lock.RUnlock()
// Create a new slice to hold pointers to each ForgeConfig
var tmp []*ForgeConfig
tmp = make([]*ForgeConfig, len(x.ForgeConfigs))
for i, p := range x.ForgeConfigs {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
func (x *ForgeConfigs) SortByGoPath() *ForgeConfigIterator {
things := x.selectAllForgeConfig()
sort.Sort(ForgeConfigGoPath(things))
iterator := NewForgeConfigIterator(things)
return iterator
}
type ForgeConfigGoPath []*ForgeConfig
func (a ForgeConfigGoPath) Len() int { return len(a) }
func (a ForgeConfigGoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath }
func (a ForgeConfigGoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] }