httppb/httpRequest.sort.pb.go

189 lines
4.2 KiB
Go

// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
// This file was autogenerated with autogenpb v0.0.87 2025-09-09_22:14:39_UTC
// 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 httppb
import (
"fmt"
"iter"
"sync"
"google.golang.org/protobuf/proto"
)
// a simple global lock
var httpRequestMu sync.RWMutex
func (x *HttpRequests) fixUuid() {
if x == nil {
return
}
if x.Uuid == "1524ed43-e57d-4bf9-9449-1cdfdc498605" {
return
}
x.Uuid = "1524ed43-e57d-4bf9-9449-1cdfdc498605"
x.Version = "v0.0.1 go.wit.com/lib/protobuf/httppb"
}
func NewHttpRequests() *HttpRequests {
x := new(HttpRequests)
x.Uuid = "1524ed43-e57d-4bf9-9449-1cdfdc498605"
x.Version = "v0.0.1 go.wit.com/lib/protobuf/httppb"
return x
}
// START SORT
// DEFINE THE HttpRequests SCANNER.
// itializes a new scanner.
func newHttpRequestsScanner(things []*HttpRequests) *HttpRequestsScanner {
return &HttpRequestsScanner{things: things}
}
type HttpRequestsScanner struct {
sync.Mutex
things []*HttpRequests
index int
}
func (it *HttpRequestsScanner) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.Lock()
it.index++
it.Unlock()
return true
}
// Next() returns the next thing in the array
func (it *HttpRequestsScanner) Next() *HttpRequests {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in HttpRequestsScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// DEFINE THE HttpRequest SCANNER.
// itializes a new scanner.
func newHttpRequestScanner(things []*HttpRequest) *HttpRequestScanner {
return &HttpRequestScanner{things: things}
}
type HttpRequestScanner struct {
sync.Mutex
things []*HttpRequest
index int
}
func (it *HttpRequestScanner) Scan() bool {
if it.index >= len(it.things) {
return false
}
it.Lock()
it.index++
it.Unlock()
return true
}
// Next() returns the next thing in the array
func (it *HttpRequestScanner) Next() *HttpRequest {
if it.things[it.index-1] == nil {
fmt.Println("Next() error in HttpRequestScanner", it.index)
}
return it.things[it.index-1]
}
// END DEFINE THE SCANNER
// safely returns a slice of pointers to the FRUIT protobufs
func (x *HttpRequests) allHttpRequests() []*HttpRequest {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each FRUIT
var tmp []*HttpRequest
tmp = make([]*HttpRequest, len(x.HttpRequests))
for i, p := range x.HttpRequests {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// safely returns a slice of pointers to the HttpRequest protobufs
func (x *HttpRequests) selectAllHttpRequests() []*HttpRequest {
x.RLock()
defer x.RUnlock()
// Create a new slice to hold pointers to each HttpRequest
var tmp []*HttpRequest
tmp = make([]*HttpRequest, len(x.HttpRequests))
for i, p := range x.HttpRequests {
tmp[i] = p // Copy pointers for safe iteration
}
return tmp
}
// END SORT
func (x *HttpRequests) Len() int {
x.RLock()
defer x.RUnlock()
return len(x.HttpRequests)
}
// a Append() shortcut (that does Clone() with a mutex) notsure if it really works
func (x *HttpRequests) Append(y *HttpRequest) {
x.Lock()
defer x.Unlock()
x.HttpRequests = append(x.HttpRequests, proto.Clone(y).(*HttpRequest))
}
func (x *HttpRequests) All() *HttpRequestScanner {
HttpRequestPointers := x.selectAllHttpRequests()
scanner := newHttpRequestScanner(HttpRequestPointers)
return scanner
}
// Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'
func (x *HttpRequests) IterAll() iter.Seq[*HttpRequest] {
items := x.selectAllHttpRequests()
// log.Println("Made All() Iter.Seq[] with length", len(items))
return func(yield func(*HttpRequest) bool) {
for _, v := range items {
if !yield(v) {
return
}
}
}
}
func (x *HttpRequests) Delete(y *HttpRequest) bool {
x.Lock()
defer x.Unlock()
for i, _ := range x.HttpRequests {
if x.HttpRequests[i] == y {
x.HttpRequests[i] = x.HttpRequests[len(x.HttpRequests)-1]
x.HttpRequests = x.HttpRequests[:len(x.HttpRequests)-1]
return true
}
}
return false
}