259 lines
7.5 KiB
Plaintext
259 lines
7.5 KiB
Plaintext
// `autogen:go.mod`
|
|
|
|
module go.wit.com/lib/protobuf/forgepb
|
|
|
|
go 1.21
|
|
|
|
toolchain go1.23.4
|
|
|
|
require (
|
|
github.com/destel/rill v0.6.0
|
|
go.wit.com/lib/gui/shell v0.22.20
|
|
go.wit.com/lib/protobuf/gitpb v0.0.47
|
|
go.wit.com/lib/protobuf/zoopb v0.0.21
|
|
go.wit.com/log v0.22.10
|
|
google.golang.org/protobuf v1.36.2
|
|
)
|
|
|
|
require github.com/go-cmd/cmd v1.4.3 // indirect
|
|
|
|
// `autogen:go.sum`
|
|
|
|
github.com/destel/rill v0.6.0 h1:8MQRzS6k0akKmwNZFahKIhG1dkBeNxMoWKSfOxkaJNw=
|
|
github.com/destel/rill v0.6.0/go.mod h1:srKuXzvGqINUEGYR5b/iwvW+L9/S35RxVHWGYbXNoO4=
|
|
github.com/go-cmd/cmd v1.4.3 h1:6y3G+3UqPerXvPcXvj+5QNPHT02BUw7p6PsqRxLNA7Y=
|
|
github.com/go-cmd/cmd v1.4.3/go.mod h1:u3hxg/ry+D5kwh8WvUkHLAMe2zQCaXd00t35WfQaOFk=
|
|
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
|
|
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
go.wit.com/lib/gui/shell v0.22.20 h1:iVPXL1h1Qri1WrymjfgTy0gRGEepj6+w2e6kSVaBtUk=
|
|
go.wit.com/lib/gui/shell v0.22.20/go.mod h1:zduuMSWq+EE7w0xbXn+vkoGZ4HJhURVJpvXw8oK9WAU=
|
|
go.wit.com/lib/protobuf/gitpb v0.0.47 h1:tE9aNiZqLBUfiQGqhv9ZOHSe5MZkE5XdxiMMET4c4qw=
|
|
go.wit.com/lib/protobuf/gitpb v0.0.47/go.mod h1:HvJ8tvVDy2sQRfUiOT17mMWKOlEoQJPqkt+9kMuw4hs=
|
|
go.wit.com/lib/protobuf/zoopb v0.0.21 h1:ZCgEB6wEv9VLW4DbBGwwS1nGZLWXcQ1lMhrRhztO/Fk=
|
|
go.wit.com/lib/protobuf/zoopb v0.0.21/go.mod h1:Sw47KomE+5nzioBTC/Gf8iV3p8gidB7uVoeyAtPvWi4=
|
|
go.wit.com/log v0.22.10 h1:rlSgaYjvxbpcmi9UBQO3ESmbd/jiyFdRQFoGOvpCEUc=
|
|
go.wit.com/log v0.22.10/go.mod h1:4uNPFBqhsAh8zNF+zxVEmC3c/9AZ8JeTfUUvRpddvLQ=
|
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
|
|
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
|
|
|
// `autogen:forgeConfig.marshal.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 (
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
"google.golang.org/protobuf/encoding/prototext"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// human readable JSON
|
|
func (v *ForgeConfigs) FormatJSON() string {
|
|
return protojson.Format(v)
|
|
}
|
|
|
|
// marshal json
|
|
func (v *ForgeConfigs) MarshalJSON() ([]byte, error) {
|
|
return protojson.Marshal(v)
|
|
}
|
|
|
|
// unmarshal json
|
|
func (v *ForgeConfigs) UnmarshalJSON(data []byte) error {
|
|
return protojson.Unmarshal(data, v)
|
|
}
|
|
|
|
// apparently this isn't stable, but it's awesomely better
|
|
// https://protobuf.dev/reference/go/faq/#unstable-text
|
|
// it's brilliant for config files!
|
|
func (v *ForgeConfigs) FormatTEXT() string {
|
|
return prototext.Format(v)
|
|
}
|
|
|
|
// unmarshalTEXT. This reads the .text config file back in after the user edits it
|
|
func (v *ForgeConfigs) UnmarshalTEXT(data []byte) error {
|
|
return prototext.Unmarshal(data, v)
|
|
}
|
|
|
|
// marshal to wire. This is called winning.
|
|
func (v *ForgeConfigs) Marshal() ([]byte, error) {
|
|
return proto.Marshal(v)
|
|
}
|
|
|
|
// unmarshal from wire. You have won.
|
|
func (v *ForgeConfigs) Unmarshal(data []byte) error {
|
|
return proto.Unmarshal(data, v)
|
|
}
|
|
|
|
// `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
|
|
}
|
|
|
|
// `autogen:forgeConfig.pb.go`
|