2024-11-29 15:19:04 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2024-11-29 15:27:56 -06:00
|
|
|
"os"
|
|
|
|
"strings"
|
2024-11-29 15:19:04 -06:00
|
|
|
)
|
|
|
|
|
2024-11-29 15:27:56 -06:00
|
|
|
func makeSortfile() {
|
2024-12-11 13:50:38 -06:00
|
|
|
f, _ := os.OpenFile(sortmap["protobase"]+".sort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
2024-11-29 15:27:56 -06:00
|
|
|
|
|
|
|
header(f, sortmap)
|
2024-12-01 00:46:06 -06:00
|
|
|
|
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
// if the lock is set to 'all' this means the mutex was put in the protoc-gen-go struct
|
|
|
|
} else {
|
|
|
|
syncLock(f, sortmap)
|
|
|
|
}
|
2024-11-29 15:27:56 -06:00
|
|
|
iterTop(f, sortmap)
|
|
|
|
iterNext(f, sortmap)
|
2024-11-29 17:31:49 -06:00
|
|
|
iterAppend(f, sortmap) // Append() enforce no unique keys
|
|
|
|
iterSortAll(f, sortmap)
|
|
|
|
|
|
|
|
if argv.Append != "" {
|
2024-11-30 12:17:38 -06:00
|
|
|
sortmap["append"] = string(argv.Append)
|
|
|
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
2024-11-29 17:31:49 -06:00
|
|
|
}
|
|
|
|
|
2024-11-30 15:06:57 -06:00
|
|
|
for _, s := range uniqueKeys {
|
2024-12-01 22:21:09 -06:00
|
|
|
// log.Info("found unique key in .proto", s)
|
2024-11-30 15:06:57 -06:00
|
|
|
sortmap["sortBy"] = s
|
|
|
|
sortmap["sortKey"] = s
|
|
|
|
|
|
|
|
iterSortBy(f, sortmap)
|
|
|
|
|
|
|
|
sortmap["append"] = sortmap["sortKey"]
|
|
|
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
|
|
|
|
|
|
|
iterDelete(f, sortmap)
|
|
|
|
iterReplace(f, sortmap)
|
|
|
|
iterFind(f, sortmap)
|
|
|
|
}
|
|
|
|
|
2024-11-29 17:31:49 -06:00
|
|
|
for _, s := range argv.Sort {
|
|
|
|
sortparts := strings.Split(s, ",")
|
2024-11-29 15:27:56 -06:00
|
|
|
sortmap["sortBy"] = sortparts[0]
|
|
|
|
sortmap["sortKey"] = sortparts[1]
|
|
|
|
|
2024-11-29 17:31:49 -06:00
|
|
|
iterSortBy(f, sortmap)
|
2024-11-29 15:27:56 -06:00
|
|
|
|
|
|
|
sortmap["append"] = sortmap["sortKey"]
|
|
|
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
|
|
|
|
|
|
|
iterDelete(f, sortmap)
|
|
|
|
iterReplace(f, sortmap)
|
2024-11-29 17:45:17 -06:00
|
|
|
iterFind(f, sortmap)
|
2024-11-29 15:27:56 -06:00
|
|
|
}
|
|
|
|
iterEnd(f, sortmap)
|
|
|
|
}
|
|
|
|
|
2024-11-29 15:19:04 -06:00
|
|
|
func headerComment(w io.Writer) {
|
|
|
|
fmt.Fprintln(w, "")
|
2024-11-30 23:20:10 -06:00
|
|
|
fmt.Fprintln(w, "// This file was autogenerated with autogenpb.")
|
|
|
|
fmt.Fprintln(w, "// go install go.wit.com/apps/autogenpb@latest")
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "//")
|
2024-11-30 23:20:10 -06:00
|
|
|
fmt.Fprintln(w, "// You can use it on simple protobuf files")
|
|
|
|
fmt.Fprintln(w, "// The .proto file must have a singular and plural form of a message")
|
|
|
|
fmt.Fprintln(w, "// (for those of you that know ruby on rails, it's like that)")
|
|
|
|
fmt.Fprintln(w, "//")
|
|
|
|
fmt.Fprintln(w, "// You can mark which repos you want to auto generate sort.pb.go and marshal.pb.go files for")
|
|
|
|
fmt.Fprintln(w, "//")
|
|
|
|
fmt.Fprintln(w, "// For an example,")
|
|
|
|
fmt.Fprintln(w, "// go-clone go.wit.com/lib/protobuf/gitpb")
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "//")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func header(w io.Writer, names map[string]string) {
|
|
|
|
fmt.Fprintln(w, "package "+names["package"])
|
|
|
|
headerComment(w)
|
|
|
|
fmt.Fprintln(w, "import (")
|
|
|
|
fmt.Fprintln(w, " \"fmt\"")
|
|
|
|
fmt.Fprintln(w, " \"os\"")
|
|
|
|
fmt.Fprintln(w, " \"sort\"")
|
|
|
|
fmt.Fprintln(w, " \"sync\"")
|
|
|
|
fmt.Fprintln(w, ")")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func syncLock(w io.Writer, names map[string]string) {
|
|
|
|
fmt.Fprintln(w, "// bad global lock until I figure out some other plan")
|
|
|
|
fmt.Fprintln(w, "// redo/fix protoc-gen-go 1.35 and do it there?")
|
|
|
|
fmt.Fprintln(w, "// sync.RWMutex or sync.Mutex?")
|
|
|
|
fmt.Fprintln(w, "var "+names["lock"]+" sync.RWMutex")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func iterTop(w io.Writer, names map[string]string) {
|
|
|
|
fmt.Fprintln(w, "type "+names["Base"]+"Iterator struct {")
|
|
|
|
fmt.Fprintln(w, " sync.RWMutex")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " packs []*"+names["Base"])
|
|
|
|
fmt.Fprintln(w, " index int")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, "// New"+names["Base"]+"Iterator initializes a new iterator.")
|
|
|
|
fmt.Fprintln(w, "func New"+names["Base"]+"Iterator(packs []*"+names["Base"]+") *"+names["Base"]+"Iterator {")
|
|
|
|
fmt.Fprintln(w, " return &"+names["Base"]+"Iterator{packs: packs}")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, "// Scan moves to the next element and returns false if there are no more packs.")
|
|
|
|
fmt.Fprintln(w, "// Use Scan() in a loop, similar to a while loop")
|
|
|
|
fmt.Fprintln(w, "//")
|
|
|
|
fmt.Fprintln(w, "// for iterator.Scan() ")
|
|
|
|
fmt.Fprintln(w, "// d := iterator.Next(")
|
|
|
|
fmt.Fprintln(w, "// fmt.Println(\"found UUID:\", d.Uuid")
|
|
|
|
fmt.Fprintln(w, "// }")
|
|
|
|
fmt.Fprintln(w, "func (it *"+names["Base"]+"Iterator) Scan() bool {")
|
|
|
|
fmt.Fprintln(w, " if it.index >= len(it.packs) {")
|
|
|
|
fmt.Fprintln(w, " return false")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " it.index++")
|
|
|
|
fmt.Fprintln(w, " return true")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func iterNext(w io.Writer, names map[string]string) {
|
|
|
|
fmt.Fprintln(w, "// Next() returns the next thing in the array")
|
|
|
|
fmt.Fprintln(w, "func (it *"+names["Base"]+"Iterator) Next() *"+names["Base"]+" {")
|
|
|
|
fmt.Fprintln(w, " if it.packs[it.index-1] == nil {")
|
|
|
|
fmt.Fprintln(w, " for i, d := range it.packs {")
|
|
|
|
fmt.Fprintln(w, " fmt.Println(\"i =\", i, d)")
|
|
|
|
fmt.Fprintln(w, " }")
|
2024-12-14 16:27:29 -06:00
|
|
|
fmt.Fprintln(w, " // fmt.Println(\"protobuf autogenpb sort error len =\", len(it.packs))")
|
|
|
|
fmt.Fprintln(w, " // fmt.Println(\"protobuf autogenpb sort error next == nil\", it.index, it.index-1)")
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " return it.packs[it.index-1]")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
2024-11-29 17:31:49 -06:00
|
|
|
func iterSortAll(w io.Writer, names map[string]string) {
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") All() *"+names["Base"]+"Iterator {")
|
|
|
|
fmt.Fprintln(w, " "+names["base"]+"Pointers := all.selectAll"+names["Base"]+"()")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " iterator := New"+names["Base"]+"Iterator("+names["base"]+"Pointers)")
|
|
|
|
fmt.Fprintln(w, " return iterator")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
2024-11-29 17:31:49 -06:00
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") Len() int {")
|
2024-12-01 10:42:12 -06:00
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
|
|
|
}
|
2024-11-29 17:31:49 -06:00
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " return len(all."+names["Bases"]+")")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func iterSortBy(w io.Writer, names map[string]string) {
|
2024-11-30 15:06:57 -06:00
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") SortBy"+names["sortBy"]+"() *"+names["Base"]+"Iterator {")
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, " packs := all.selectAll"+names["Base"]+"()")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " sort.Sort("+names["Base"]+""+names["sortBy"]+"(packs))")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " iterator := New"+names["Base"]+"Iterator(packs)")
|
|
|
|
fmt.Fprintln(w, " return iterator")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
|
|
|
|
fmt.Fprintln(w, "type "+names["Base"]+""+names["sortBy"]+" []*"+names["Base"]+"")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, "func (a "+names["Base"]+""+names["sortBy"]+") Len() int { return len(a) }")
|
|
|
|
fmt.Fprintln(w, "func (a "+names["Base"]+""+names["sortBy"]+") Less(i, j int) bool { return a[i]."+names["sortKey"]+" < a[j]."+names["sortKey"]+" }")
|
|
|
|
fmt.Fprintln(w, "func (a "+names["Base"]+""+names["sortBy"]+") Swap(i, j int) { a[i], a[j] = a[j], a[i] }")
|
|
|
|
fmt.Fprintln(w, "")
|
2024-11-29 17:31:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func iterEnd(w io.Writer, names map[string]string) {
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "// safely returns a slice of pointers to the "+names["Base"]+" protobufs")
|
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") selectAll"+names["Base"]+"() []*"+names["Base"]+" {")
|
2024-12-01 10:42:12 -06:00
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
|
|
|
}
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " // Create a new slice to hold pointers to each "+names["Base"]+"")
|
|
|
|
fmt.Fprintln(w, " var aStuff []*"+names["Base"]+"")
|
|
|
|
fmt.Fprintln(w, " aStuff = make([]*"+names["Base"]+", len(all."+names["Bases"]+"))")
|
|
|
|
fmt.Fprintln(w, " for i, p := range all."+names["Bases"]+" {")
|
|
|
|
fmt.Fprintln(w, " aStuff[i] = p // Copy pointers for safe iteration")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " return aStuff")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
}
|
|
|
|
|
|
|
|
func iterAppend(w io.Writer, names map[string]string) {
|
|
|
|
if names["append"] == "" {
|
|
|
|
fmt.Fprintln(w, "// does not enforce any unique fields")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, "// enforces "+names["append"]+" is unique")
|
|
|
|
}
|
|
|
|
if names["append"] == "" {
|
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool {")
|
|
|
|
} else {
|
|
|
|
// fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool { // todo: make unique name here")
|
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") AppendUnique"+names["append"]+"(newP *"+names["Base"]+") bool {")
|
|
|
|
}
|
2024-12-01 10:42:12 -06:00
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
|
|
|
}
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
if names["append"] != "" {
|
|
|
|
fmt.Fprintln(w, " for _, p := range all."+names["Bases"]+" {")
|
|
|
|
fmt.Fprintln(w, " if p."+names["append"]+" == newP."+names["append"]+" {")
|
|
|
|
fmt.Fprintln(w, " return false")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
fmt.Fprintln(w, " all."+names["Bases"]+" = append(all."+names["Bases"]+", newP)")
|
|
|
|
fmt.Fprintln(w, " return true")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func iterReplace(w io.Writer, names map[string]string) {
|
|
|
|
if names["append"] == "" {
|
|
|
|
// can't continue without a key field
|
|
|
|
}
|
|
|
|
fmt.Fprintln(w, "// enforces "+names["append"]+" is unique")
|
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") Replace"+names["append"]+"(newP *"+names["Base"]+") bool { // todo: make unique name here")
|
|
|
|
|
2024-12-01 10:42:12 -06:00
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
|
|
|
}
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " for _, p := range all."+names["Bases"]+" {")
|
|
|
|
fmt.Fprintln(w, " if p."+names["append"]+" == newP."+names["append"]+" {")
|
|
|
|
fmt.Fprintln(w, " return false")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " all."+names["Bases"]+" = append(all."+names["Bases"]+", newP)")
|
|
|
|
fmt.Fprintln(w, " return true")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func iterDelete(w io.Writer, names map[string]string) {
|
2024-11-30 23:20:10 -06:00
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") DeleteBy"+names["append"]+"(s string) bool {")
|
2024-12-01 10:42:12 -06:00
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
|
|
|
}
|
2024-11-30 23:20:10 -06:00
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " for i, _ := range all."+names["Bases"]+" {")
|
|
|
|
fmt.Fprintln(w, " if all."+names["Bases"]+"[i]."+names["append"]+" == s {")
|
|
|
|
fmt.Fprintln(w, " all."+names["Bases"]+"[i] = all."+names["Bases"]+"[len(all."+names["Bases"]+")-1]")
|
|
|
|
fmt.Fprintln(w, " all."+names["Bases"]+" = all."+names["Bases"]+"[:len(all."+names["Bases"]+")-1]")
|
|
|
|
fmt.Fprintln(w, " return true")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " return false")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
// this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct
|
|
|
|
func iterDeleteWithCopy(w io.Writer, names map[string]string) {
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") DeleteBy"+names["append"]+"(s string) *"+names["Base"]+" {")
|
2024-12-01 10:42:12 -06:00
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
|
|
|
}
|
2024-11-29 15:19:04 -06:00
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " var newr "+names["Base"])
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " for i, _ := range all."+names["Bases"]+" {")
|
|
|
|
fmt.Fprintln(w, " if all."+names["Bases"]+"[i]."+names["append"]+" == s {")
|
|
|
|
fmt.Fprintln(w, " newr = *all."+names["Bases"]+"[i]")
|
|
|
|
fmt.Fprintln(w, " all."+names["Bases"]+"[i] = all."+names["Bases"]+"[len(all."+names["Bases"]+")-1]")
|
|
|
|
fmt.Fprintln(w, " all."+names["Bases"]+" = all."+names["Bases"]+"[:len(all."+names["Bases"]+")-1]")
|
|
|
|
fmt.Fprintln(w, " return &newr")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " return nil")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|
2024-11-29 17:45:17 -06:00
|
|
|
|
|
|
|
func iterFind(w io.Writer, names map[string]string) {
|
|
|
|
fmt.Fprintln(w, "// find a dependancy by the go path")
|
|
|
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") FindBy"+names["append"]+"(s string) *"+names["Base"]+" {")
|
2024-12-01 16:43:08 -06:00
|
|
|
fmt.Fprintln(w, " if all == nil {")
|
|
|
|
fmt.Fprintln(w, " return nil")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, "")
|
2024-12-01 10:42:12 -06:00
|
|
|
if sortmap["lock"] == "all" {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".Lock.RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".Lock.RUnlock()")
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, " "+names["lock"]+".RLock()")
|
|
|
|
fmt.Fprintln(w, " defer "+names["lock"]+".RUnlock()")
|
|
|
|
}
|
2024-11-29 17:45:17 -06:00
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
fmt.Fprintln(w, " for i, _ := range all."+names["Bases"]+" {")
|
|
|
|
fmt.Fprintln(w, " if all."+names["Bases"]+"[i]."+names["append"]+" == s {")
|
|
|
|
fmt.Fprintln(w, " return all."+names["Bases"]+"[i]")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " }")
|
|
|
|
fmt.Fprintln(w, " return nil")
|
|
|
|
fmt.Fprintln(w, "}")
|
|
|
|
fmt.Fprintln(w, "")
|
|
|
|
}
|