Notes added by 'git notes append'
This commit is contained in:
parent
aa50645306
commit
99410110fe
|
@ -98,3 +98,159 @@ func (v *ForgeConfigs) Unmarshal(data []byte) error {
|
|||
}
|
||||
|
||||
// `autogen:forgeConfig.newsort.pb.go`
|
||||
|
||||
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||
// This file was autogenerated with autogenpb v0.0.37-30-g805d3cd 2025.01.09_2100
|
||||
// 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"
|
||||
)
|
||||
|
||||
// bad global lock until modifying the .pb.go file is tested
|
||||
// sync.RWMutex or sync.Mutex?
|
||||
var forgeConfigMu sync.RWMutex
|
||||
|
||||
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]
|
||||
}
|
||||
|
||||
// safely returns a slice of pointers to the ForgeConfig protobufs
|
||||
func (all *ForgeConfigs) selectAllForgeConfig() []*ForgeConfig {
|
||||
forgeConfigMu.RLock()
|
||||
defer forgeConfigMu.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each ForgeConfig
|
||||
var tmp []*ForgeConfig
|
||||
tmp = make([]*ForgeConfig, len(all.ForgeConfigs))
|
||||
for i, p := range all.ForgeConfigs {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
||||
// just a simple Append() with no checking (but still uses the mutex lock)
|
||||
func (all *ForgeConfigs) Append(newP *ForgeConfig) bool {
|
||||
forgeConfigMu.RLock()
|
||||
defer forgeConfigMu.RUnlock()
|
||||
|
||||
all.ForgeConfigs = append(all.ForgeConfigs, newP)
|
||||
return true
|
||||
}
|
||||
|
||||
// enforces ForgeConfig is unique
|
||||
func (all *ForgeConfigs) AppendUniqueGoPath(newP *ForgeConfig) bool {
|
||||
forgeConfigMu.RLock()
|
||||
defer forgeConfigMu.RUnlock()
|
||||
|
||||
for _, p := range all.ForgeConfigs {
|
||||
if p.GoPath == newP.GoPath {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
all.ForgeConfigs = append(all.ForgeConfigs, newP)
|
||||
return true
|
||||
}
|
||||
|
||||
// enforces ForgeConfig is unique
|
||||
func (all *ForgeConfigs) AppendUnique(newP *ForgeConfig) bool {
|
||||
forgeConfigMu.RLock()
|
||||
defer forgeConfigMu.RUnlock()
|
||||
|
||||
for _, p := range all.ForgeConfigs {
|
||||
if p.GoPath == newP.GoPath {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
all.ForgeConfigs = append(all.ForgeConfigs, newP)
|
||||
return true
|
||||
}
|
||||
|
||||
func (all *ForgeConfigs) SortByGoPath() *ForgeConfigIterator {
|
||||
things := all.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] }
|
||||
|
||||
func (all *ForgeConfigs) All() *ForgeConfigIterator {
|
||||
ForgeConfigPointers := all.selectAllForgeConfig()
|
||||
|
||||
iterator := NewForgeConfigIterator(ForgeConfigPointers)
|
||||
return iterator
|
||||
}
|
||||
|
||||
func (all *ForgeConfigs) Len() int {
|
||||
forgeConfigMu.RLock()
|
||||
defer forgeConfigMu.RUnlock()
|
||||
|
||||
return len(all.ForgeConfigs)
|
||||
}
|
||||
|
||||
func (all *ForgeConfigs) DeleteByGoPath(s string) bool {
|
||||
forgeConfigMu.RLock()
|
||||
defer forgeConfigMu.RUnlock()
|
||||
|
||||
for i, _ := range all.ForgeConfigs {
|
||||
if all.ForgeConfigs[i].GoPath == s {
|
||||
all.ForgeConfigs[i] = all.ForgeConfigs[len(all.ForgeConfigs)-1]
|
||||
all.ForgeConfigs = all.ForgeConfigs[:len(all.ForgeConfigs)-1]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue