From ab23c67f3ca79e30d8a55df11b72cf9ba2f981f7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 18 Jan 2025 11:19:47 -0600 Subject: [PATCH] Notes removed by 'git notes remove' --- 54f4c4be3d35cc2c86706aed673392a01d5c7e45 | 1082 ---------------------- 1 file changed, 1082 deletions(-) delete mode 100644 54f4c4be3d35cc2c86706aed673392a01d5c7e45 diff --git a/54f4c4be3d35cc2c86706aed673392a01d5c7e45 b/54f4c4be3d35cc2c86706aed673392a01d5c7e45 deleted file mode 100644 index 171ee93..0000000 --- a/54f4c4be3d35cc2c86706aed673392a01d5c7e45 +++ /dev/null @@ -1,1082 +0,0 @@ -// `autogen:go.mod` - -module go.wit.com/lib/protobuf/zoopb - -go 1.21 - -toolchain go1.23.4 - -require ( - go.wit.com/log v0.22.9 - google.golang.org/protobuf v1.35.2 -) - -// `autogen:go.sum` - -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/log v0.22.9 h1:aBM6SI2kxlJcBfS/osFTomJqNhO0hfEo1gk+LCqLk7Y= -go.wit.com/log v0.22.9/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.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= -google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= - -// `autogen:machine.marshal.pb.go` - -package zoopb - -// This file was autogenerated with autogenpb v0.0.33 DO NOT EDIT -// go install go.wit.com/apps/autogenpb@latest -// -// You can use it on simple protobuf files -// The .proto file must have a singular and plural form of a message -// (for those of you that know ruby on rails, it's like that) -// -// You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for -// -// For an example, -// go-clone go.wit.com/lib/protobuf/gitpb -// - -import ( - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/encoding/prototext" - "google.golang.org/protobuf/proto" -) - -// human readable JSON -func (v *Machine) FormatJSON() string { - return protojson.Format(v) -} - -// marshal json -func (v *Machine) MarshalJSON() ([]byte, error) { - return protojson.Marshal(v) -} - -// unmarshal json -func (v *Machine) 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 so great for config files, I'm using it by default to try to fix the problems with it -func (v *Machine) FormatTEXT() string { - return prototext.Format(v) -} - -// unmarshalTEXT. This reads the .text config file back in after the user edits it -func (v *Machine) UnmarshalTEXT(data []byte) error { - return prototext.Unmarshal(data, v) -} - -// marshal to wire. This is called winning. -func (v *Machine) Marshal() ([]byte, error) { - return proto.Marshal(v) -} - -// unmarshal from wire. You have won. -func (v *Machine) Unmarshal(data []byte) error { - return proto.Unmarshal(data, v) -} - -// human readable JSON -func (v *Machines) FormatJSON() string { - return protojson.Format(v) -} - -// marshal json -func (v *Machines) MarshalJSON() ([]byte, error) { - return protojson.Marshal(v) -} - -// unmarshal json -func (v *Machines) 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 so great for config files, I'm using it by default to try to fix the problems with it -func (v *Machines) FormatTEXT() string { - return prototext.Format(v) -} - -// unmarshalTEXT. This reads the .text config file back in after the user edits it -func (v *Machines) UnmarshalTEXT(data []byte) error { - return prototext.Unmarshal(data, v) -} - -// marshal to wire. This is called winning. -func (v *Machines) Marshal() ([]byte, error) { - return proto.Marshal(v) -} - -// unmarshal from wire. You have won. -func (v *Machines) Unmarshal(data []byte) error { - return proto.Unmarshal(data, v) -} - -// `autogen:machine.pb.go` - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.35.2-devel -// protoc v3.21.12 -// source: machine.proto - -package zoopb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Machine struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Hostname string `protobuf:"bytes,1,opt,name=hostname,proto3" json:"hostname,omitempty"` // `autogenpb:unique` - Memory int64 `protobuf:"varint,2,opt,name=memory,proto3" json:"memory,omitempty"` - Cpus int64 `protobuf:"varint,3,opt,name=cpus,proto3" json:"cpus,omitempty"` - Distro string `protobuf:"bytes,4,opt,name=distro,proto3" json:"distro,omitempty"` - Packages *Packages `protobuf:"bytes,5,opt,name=packages,proto3" json:"packages,omitempty"` - Laststamp *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=laststamp,proto3" json:"laststamp,omitempty"` // the last time we heard anything from this machine - Installed *Packages `protobuf:"bytes,7,opt,name=installed,proto3" json:"installed,omitempty"` // packages that are installed - Available *Packages `protobuf:"bytes,8,opt,name=available,proto3" json:"available,omitempty"` // packages that are available - Wit *Packages `protobuf:"bytes,9,opt,name=wit,proto3" json:"wit,omitempty"` // packages that are available from mirrors.wit.com -} - -func (x *Machine) Reset() { - *x = Machine{} - mi := &file_machine_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Machine) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Machine) ProtoMessage() {} - -func (x *Machine) ProtoReflect() protoreflect.Message { - mi := &file_machine_proto_msgTypes[0] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Machine.ProtoReflect.Descriptor instead. -func (*Machine) Descriptor() ([]byte, []int) { - return file_machine_proto_rawDescGZIP(), []int{0} -} - -func (x *Machine) GetHostname() string { - if x != nil { - return x.Hostname - } - return "" -} - -func (x *Machine) GetMemory() int64 { - if x != nil { - return x.Memory - } - return 0 -} - -func (x *Machine) GetCpus() int64 { - if x != nil { - return x.Cpus - } - return 0 -} - -func (x *Machine) GetDistro() string { - if x != nil { - return x.Distro - } - return "" -} - -func (x *Machine) GetPackages() *Packages { - if x != nil { - return x.Packages - } - return nil -} - -func (x *Machine) GetLaststamp() *timestamppb.Timestamp { - if x != nil { - return x.Laststamp - } - return nil -} - -func (x *Machine) GetInstalled() *Packages { - if x != nil { - return x.Installed - } - return nil -} - -func (x *Machine) GetAvailable() *Packages { - if x != nil { - return x.Available - } - return nil -} - -func (x *Machine) GetWit() *Packages { - if x != nil { - return x.Wit - } - return nil -} - -type Machines struct { - Lock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb - - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // I guess why not just have this on each file - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // maybe can be used for protobuf schema change violations - Machines []*Machine `protobuf:"bytes,3,rep,name=machines,proto3" json:"machines,omitempty"` -} - -func (x *Machines) Reset() { - *x = Machines{} - mi := &file_machine_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Machines) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Machines) ProtoMessage() {} - -func (x *Machines) ProtoReflect() protoreflect.Message { - mi := &file_machine_proto_msgTypes[1] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Machines.ProtoReflect.Descriptor instead. -func (*Machines) Descriptor() ([]byte, []int) { - return file_machine_proto_rawDescGZIP(), []int{1} -} - -func (x *Machines) GetUuid() string { - if x != nil { - return x.Uuid - } - return "" -} - -func (x *Machines) GetVersion() string { - if x != nil { - return x.Version - } - return "" -} - -func (x *Machines) GetMachines() []*Machine { - if x != nil { - return x.Machines - } - return nil -} - -var File_machine_proto protoreflect.FileDescriptor - -var file_machine_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x05, 0x67, 0x69, 0x74, 0x70, 0x62, 0x1a, 0x0d, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd1, 0x02, 0x0a, 0x07, 0x4d, 0x61, 0x63, 0x68, 0x69, - 0x6e, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x68, 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, - 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, - 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x70, 0x75, 0x73, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x63, 0x70, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x69, - 0x73, 0x74, 0x72, 0x6f, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x64, 0x69, 0x73, 0x74, - 0x72, 0x6f, 0x12, 0x2b, 0x0a, 0x08, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x73, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x50, 0x61, 0x63, - 0x6b, 0x61, 0x67, 0x65, 0x73, 0x52, 0x08, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x73, 0x12, - 0x38, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, - 0x6c, 0x61, 0x73, 0x74, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2d, 0x0a, 0x09, 0x69, 0x6e, 0x73, - 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x67, - 0x69, 0x74, 0x70, 0x62, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x73, 0x52, 0x09, 0x69, - 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x12, 0x2d, 0x0a, 0x09, 0x61, 0x76, 0x61, 0x69, - 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x67, 0x69, - 0x74, 0x70, 0x62, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x73, 0x52, 0x09, 0x61, 0x76, - 0x61, 0x69, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x21, 0x0a, 0x03, 0x77, 0x69, 0x74, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x50, 0x61, 0x63, - 0x6b, 0x61, 0x67, 0x65, 0x73, 0x52, 0x03, 0x77, 0x69, 0x74, 0x22, 0x64, 0x0a, 0x08, 0x4d, 0x61, - 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x2a, 0x0a, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, - 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x67, 0x69, 0x74, 0x70, 0x62, 0x2e, 0x4d, - 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x52, 0x08, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x73, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_machine_proto_rawDescOnce sync.Once - file_machine_proto_rawDescData = file_machine_proto_rawDesc -) - -func file_machine_proto_rawDescGZIP() []byte { - file_machine_proto_rawDescOnce.Do(func() { - file_machine_proto_rawDescData = protoimpl.X.CompressGZIP(file_machine_proto_rawDescData) - }) - return file_machine_proto_rawDescData -} - -var file_machine_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_machine_proto_goTypes = []any{ - (*Machine)(nil), // 0: gitpb.Machine - (*Machines)(nil), // 1: gitpb.Machines - (*Packages)(nil), // 2: gitpb.Packages - (*timestamppb.Timestamp)(nil), // 3: google.protobuf.Timestamp -} -var file_machine_proto_depIdxs = []int32{ - 2, // 0: gitpb.Machine.packages:type_name -> gitpb.Packages - 3, // 1: gitpb.Machine.laststamp:type_name -> google.protobuf.Timestamp - 2, // 2: gitpb.Machine.installed:type_name -> gitpb.Packages - 2, // 3: gitpb.Machine.available:type_name -> gitpb.Packages - 2, // 4: gitpb.Machine.wit:type_name -> gitpb.Packages - 0, // 5: gitpb.Machines.machines:type_name -> gitpb.Machine - 6, // [6:6] is the sub-list for method output_type - 6, // [6:6] is the sub-list for method input_type - 6, // [6:6] is the sub-list for extension type_name - 6, // [6:6] is the sub-list for extension extendee - 0, // [0:6] is the sub-list for field type_name -} - -func init() { file_machine_proto_init() } -func file_machine_proto_init() { - if File_machine_proto != nil { - return - } - file_package_proto_init() - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_machine_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_machine_proto_goTypes, - DependencyIndexes: file_machine_proto_depIdxs, - MessageInfos: file_machine_proto_msgTypes, - }.Build() - File_machine_proto = out.File - file_machine_proto_rawDesc = nil - file_machine_proto_goTypes = nil - file_machine_proto_depIdxs = nil -} - -// `autogen:machine.sort.pb.go` - -package zoopb - -// This file was autogenerated with autogenpb v0.0.33 DO NOT EDIT -// go install go.wit.com/apps/autogenpb@latest -// -// You can use it on simple protobuf files -// The .proto file must have a singular and plural form of a message -// (for those of you that know ruby on rails, it's like that) -// -// You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for -// -// For an example, -// go-clone go.wit.com/lib/protobuf/gitpb -// - -import ( - "fmt" - "sort" - "sync" -) - -type MachineIterator struct { - sync.RWMutex - - packs []*Machine - index int -} - -// NewMachineIterator initializes a new iterator. -func NewMachineIterator(packs []*Machine) *MachineIterator { - return &MachineIterator{packs: packs} -} - -// Scan moves to the next element and returns false if there are no more packs. -// Use Scan() in a loop, similar to a while loop -// -// for iterator.Scan() -// d := iterator.Next( -// fmt.Println("found UUID:", d.Uuid -// } -func (it *MachineIterator) Scan() bool { - if it.index >= len(it.packs) { - return false - } - it.index++ - return true -} - -// Next() returns the next thing in the array -func (it *MachineIterator) Next() *Machine { - if it.packs[it.index-1] == nil { - for i, d := range it.packs { - fmt.Println("i =", i, d) - } - // fmt.Println("protobuf autogenpb sort error len =", len(it.packs)) - // fmt.Println("protobuf autogenpb sort error next == nil", it.index, it.index-1) - } - return it.packs[it.index-1] -} - -// does not enforce any unique fields -func (all *Machines) Append(newP *Machine) bool { - all.Lock.RLock() - defer all.Lock.RUnlock() - - all.Machines = append(all.Machines, newP) - return true -} - -func (all *Machines) All() *MachineIterator { - machinePointers := all.selectAllMachine() - - iterator := NewMachineIterator(machinePointers) - return iterator -} - -func (all *Machines) Len() int { - all.Lock.RLock() - defer all.Lock.RUnlock() - - return len(all.Machines) -} - -func (all *Machines) SortByHostname() *MachineIterator { - packs := all.selectAllMachine() - - sort.Sort(MachineHostname(packs)) - - iterator := NewMachineIterator(packs) - return iterator -} - -type MachineHostname []*Machine - -func (a MachineHostname) Len() int { return len(a) } -func (a MachineHostname) Less(i, j int) bool { return a[i].Hostname < a[j].Hostname } -func (a MachineHostname) Swap(i, j int) { a[i], a[j] = a[j], a[i] } - -// enforces Hostname is unique -func (all *Machines) AppendUniqueHostname(newP *Machine) bool { - all.Lock.RLock() - defer all.Lock.RUnlock() - - for _, p := range all.Machines { - if p.Hostname == newP.Hostname { - return false - } - } - - all.Machines = append(all.Machines, newP) - return true -} - -func (all *Machines) DeleteByHostname(s string) bool { - all.Lock.RLock() - defer all.Lock.RUnlock() - - for i, _ := range all.Machines { - if all.Machines[i].Hostname == s { - all.Machines[i] = all.Machines[len(all.Machines)-1] - all.Machines = all.Machines[:len(all.Machines)-1] - return true - } - } - return false -} - -// enforces Hostname is unique -func (all *Machines) ReplaceHostname(newP *Machine) bool { // todo: make unique name here - all.Lock.RLock() - defer all.Lock.RUnlock() - - for _, p := range all.Machines { - if p.Hostname == newP.Hostname { - return false - } - } - - all.Machines = append(all.Machines, newP) - return true -} - -// find a dependancy by the go path -func (all *Machines) FindByHostname(s string) *Machine { - if all == nil { - return nil - } - - all.Lock.RLock() - defer all.Lock.RUnlock() - - for i, _ := range all.Machines { - if all.Machines[i].Hostname == s { - return all.Machines[i] - } - } - return nil -} - -// safely returns a slice of pointers to the Machine protobufs -func (all *Machines) selectAllMachine() []*Machine { - all.Lock.RLock() - defer all.Lock.RUnlock() - - // Create a new slice to hold pointers to each Machine - var aStuff []*Machine - aStuff = make([]*Machine, len(all.Machines)) - for i, p := range all.Machines { - aStuff[i] = p // Copy pointers for safe iteration - } - - return aStuff -} - -// `autogen:package.marshal.pb.go` - -package zoopb - -// This file was autogenerated with autogenpb v0.0.33 DO NOT EDIT -// go install go.wit.com/apps/autogenpb@latest -// -// You can use it on simple protobuf files -// The .proto file must have a singular and plural form of a message -// (for those of you that know ruby on rails, it's like that) -// -// You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for -// -// For an example, -// go-clone go.wit.com/lib/protobuf/gitpb -// - -import ( - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/encoding/prototext" - "google.golang.org/protobuf/proto" -) - -// human readable JSON -func (v *Packages) FormatJSON() string { - return protojson.Format(v) -} - -// marshal json -func (v *Packages) MarshalJSON() ([]byte, error) { - return protojson.Marshal(v) -} - -// unmarshal json -func (v *Packages) 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 so great for config files, I'm using it by default to try to fix the problems with it -func (v *Packages) FormatTEXT() string { - return prototext.Format(v) -} - -// unmarshalTEXT. This reads the .text config file back in after the user edits it -func (v *Packages) UnmarshalTEXT(data []byte) error { - return prototext.Unmarshal(data, v) -} - -// marshal to wire. This is called winning. -func (v *Packages) Marshal() ([]byte, error) { - return proto.Marshal(v) -} - -// unmarshal from wire. You have won. -func (v *Packages) Unmarshal(data []byte) error { - return proto.Unmarshal(data, v) -} - -// `autogen:package.pb.go` - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.35.2-devel -// protoc v3.21.12 -// source: package.proto - -package zoopb - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Package struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // `autogenpb:unique` // name: zookeeper-go - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // version: 0.0.3 - Laststamp *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=laststamp,proto3" json:"laststamp,omitempty"` // the last time this package was seen (used to timeout entries) - SrcPath string `protobuf:"bytes,4,opt,name=srcPath,proto3" json:"srcPath,omitempty"` // path to the sources (go.wit.com/apps/zookeeper) - Installed bool `protobuf:"varint,5,opt,name=installed,proto3" json:"installed,omitempty"` // if installed on your machine, this should be set to true - PkgName string `protobuf:"bytes,6,opt,name=pkgName,proto3" json:"pkgName,omitempty"` // the apt filename pool/main/f/foo/foo_2.2.2_riscv64.deb -} - -func (x *Package) Reset() { - *x = Package{} - mi := &file_package_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Package) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Package) ProtoMessage() {} - -func (x *Package) ProtoReflect() protoreflect.Message { - mi := &file_package_proto_msgTypes[0] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Package.ProtoReflect.Descriptor instead. -func (*Package) Descriptor() ([]byte, []int) { - return file_package_proto_rawDescGZIP(), []int{0} -} - -func (x *Package) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Package) GetVersion() string { - if x != nil { - return x.Version - } - return "" -} - -func (x *Package) GetLaststamp() *timestamppb.Timestamp { - if x != nil { - return x.Laststamp - } - return nil -} - -func (x *Package) GetSrcPath() string { - if x != nil { - return x.SrcPath - } - return "" -} - -func (x *Package) GetInstalled() bool { - if x != nil { - return x.Installed - } - return false -} - -func (x *Package) GetPkgName() string { - if x != nil { - return x.PkgName - } - return "" -} - -type Packages struct { - Lock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb - - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // I guess why not just have this on each file - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // maybe can be used for protobuf schema change violations - Packages []*Package `protobuf:"bytes,3,rep,name=packages,proto3" json:"packages,omitempty"` -} - -func (x *Packages) Reset() { - *x = Packages{} - mi := &file_package_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Packages) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Packages) ProtoMessage() {} - -func (x *Packages) ProtoReflect() protoreflect.Message { - mi := &file_package_proto_msgTypes[1] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Packages.ProtoReflect.Descriptor instead. -func (*Packages) Descriptor() ([]byte, []int) { - return file_package_proto_rawDescGZIP(), []int{1} -} - -func (x *Packages) GetUuid() string { - if x != nil { - return x.Uuid - } - return "" -} - -func (x *Packages) GetVersion() string { - if x != nil { - return x.Version - } - return "" -} - -func (x *Packages) GetPackages() []*Package { - if x != nil { - return x.Packages - } - return nil -} - -var File_package_proto protoreflect.FileDescriptor - -var file_package_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x05, 0x67, 0x69, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, - 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc3, 0x01, 0x0a, 0x07, 0x50, 0x61, 0x63, 0x6b, - 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x12, 0x38, 0x0a, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x73, - 0x72, 0x63, 0x50, 0x61, 0x74, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x72, - 0x63, 0x50, 0x61, 0x74, 0x68, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, - 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, - 0x6c, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x6b, 0x67, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x6b, 0x67, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x64, 0x0a, - 0x08, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, - 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x2a, 0x0a, 0x08, 0x70, 0x61, 0x63, 0x6b, 0x61, - 0x67, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x67, 0x69, 0x74, 0x70, - 0x62, 0x2e, 0x50, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x52, 0x08, 0x70, 0x61, 0x63, 0x6b, 0x61, - 0x67, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_package_proto_rawDescOnce sync.Once - file_package_proto_rawDescData = file_package_proto_rawDesc -) - -func file_package_proto_rawDescGZIP() []byte { - file_package_proto_rawDescOnce.Do(func() { - file_package_proto_rawDescData = protoimpl.X.CompressGZIP(file_package_proto_rawDescData) - }) - return file_package_proto_rawDescData -} - -var file_package_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_package_proto_goTypes = []any{ - (*Package)(nil), // 0: gitpb.Package - (*Packages)(nil), // 1: gitpb.Packages - (*timestamppb.Timestamp)(nil), // 2: google.protobuf.Timestamp -} -var file_package_proto_depIdxs = []int32{ - 2, // 0: gitpb.Package.laststamp:type_name -> google.protobuf.Timestamp - 0, // 1: gitpb.Packages.packages:type_name -> gitpb.Package - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name -} - -func init() { file_package_proto_init() } -func file_package_proto_init() { - if File_package_proto != nil { - return - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_package_proto_rawDesc, - NumEnums: 0, - NumMessages: 2, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_package_proto_goTypes, - DependencyIndexes: file_package_proto_depIdxs, - MessageInfos: file_package_proto_msgTypes, - }.Build() - File_package_proto = out.File - file_package_proto_rawDesc = nil - file_package_proto_goTypes = nil - file_package_proto_depIdxs = nil -} - -// `autogen:package.sort.pb.go` - -package zoopb - -// This file was autogenerated with autogenpb v0.0.33 DO NOT EDIT -// go install go.wit.com/apps/autogenpb@latest -// -// You can use it on simple protobuf files -// The .proto file must have a singular and plural form of a message -// (for those of you that know ruby on rails, it's like that) -// -// You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for -// -// For an example, -// go-clone go.wit.com/lib/protobuf/gitpb -// - -import ( - "fmt" - "sort" - "sync" -) - -type PackageIterator struct { - sync.RWMutex - - packs []*Package - index int -} - -// NewPackageIterator initializes a new iterator. -func NewPackageIterator(packs []*Package) *PackageIterator { - return &PackageIterator{packs: packs} -} - -// Scan moves to the next element and returns false if there are no more packs. -// Use Scan() in a loop, similar to a while loop -// -// for iterator.Scan() -// d := iterator.Next( -// fmt.Println("found UUID:", d.Uuid -// } -func (it *PackageIterator) Scan() bool { - if it.index >= len(it.packs) { - return false - } - it.index++ - return true -} - -// Next() returns the next thing in the array -func (it *PackageIterator) Next() *Package { - if it.packs[it.index-1] == nil { - for i, d := range it.packs { - fmt.Println("i =", i, d) - } - // fmt.Println("protobuf autogenpb sort error len =", len(it.packs)) - // fmt.Println("protobuf autogenpb sort error next == nil", it.index, it.index-1) - } - return it.packs[it.index-1] -} - -// does not enforce any unique fields -func (all *Packages) Append(newP *Package) bool { - all.Lock.RLock() - defer all.Lock.RUnlock() - - all.Packages = append(all.Packages, newP) - return true -} - -func (all *Packages) All() *PackageIterator { - packagePointers := all.selectAllPackage() - - iterator := NewPackageIterator(packagePointers) - return iterator -} - -func (all *Packages) Len() int { - all.Lock.RLock() - defer all.Lock.RUnlock() - - return len(all.Packages) -} - -func (all *Packages) SortByName() *PackageIterator { - packs := all.selectAllPackage() - - sort.Sort(PackageName(packs)) - - iterator := NewPackageIterator(packs) - return iterator -} - -type PackageName []*Package - -func (a PackageName) Len() int { return len(a) } -func (a PackageName) Less(i, j int) bool { return a[i].Name < a[j].Name } -func (a PackageName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } - -// enforces Name is unique -func (all *Packages) AppendUniqueName(newP *Package) bool { - all.Lock.RLock() - defer all.Lock.RUnlock() - - for _, p := range all.Packages { - if p.Name == newP.Name { - return false - } - } - - all.Packages = append(all.Packages, newP) - return true -} - -func (all *Packages) DeleteByName(s string) bool { - all.Lock.RLock() - defer all.Lock.RUnlock() - - for i, _ := range all.Packages { - if all.Packages[i].Name == s { - all.Packages[i] = all.Packages[len(all.Packages)-1] - all.Packages = all.Packages[:len(all.Packages)-1] - return true - } - } - return false -} - -// enforces Name is unique -func (all *Packages) ReplaceName(newP *Package) bool { // todo: make unique name here - all.Lock.RLock() - defer all.Lock.RUnlock() - - for _, p := range all.Packages { - if p.Name == newP.Name { - return false - } - } - - all.Packages = append(all.Packages, newP) - return true -} - -// find a dependancy by the go path -func (all *Packages) FindByName(s string) *Package { - if all == nil { - return nil - } - - all.Lock.RLock() - defer all.Lock.RUnlock() - - for i, _ := range all.Packages { - if all.Packages[i].Name == s { - return all.Packages[i] - } - } - return nil -} - -// safely returns a slice of pointers to the Package protobufs -func (all *Packages) selectAllPackage() []*Package { - all.Lock.RLock() - defer all.Lock.RUnlock() - - // Create a new slice to hold pointers to each Package - var aStuff []*Package - aStuff = make([]*Package, len(all.Packages)) - for i, p := range all.Packages { - aStuff[i] = p // Copy pointers for safe iteration - } - - return aStuff -} - -// `autogen:`