summaryrefslogtreecommitdiff
path: root/sort.go
diff options
context:
space:
mode:
Diffstat (limited to 'sort.go')
-rw-r--r--sort.go32
1 files changed, 15 insertions, 17 deletions
diff --git a/sort.go b/sort.go
index 1d202a6..b098897 100644
--- a/sort.go
+++ b/sort.go
@@ -13,12 +13,7 @@ func (pb *Files) makeSortfile(pf *File) {
header(f, pf)
- 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)
- }
- iterTop(f, sortmap)
+ pf.iterTop(f, sortmap["base"])
iterNext(f, sortmap)
iterAppend(f, sortmap) // Append() enforce no unique keys
iterSortAll(f, sortmap)
@@ -60,25 +55,28 @@ func (pb *Files) makeSortfile(pf *File) {
iterEnd(f, sortmap)
}
-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?")
+func (pf *File) syncLock(w io.Writer, lock string) {
+ var LOCK string = lock
+
+ fmt.Fprintln(w, "// bad global lock until modifying the .pb.go file is tested")
fmt.Fprintln(w, "// sync.RWMutex or sync.Mutex?")
- fmt.Fprintln(w, "var "+names["lock"]+" sync.RWMutex")
+ fmt.Fprintln(w, "var "+LOCK+" sync.RWMutex")
fmt.Fprintln(w, "")
}
-func iterTop(w io.Writer, names map[string]string) {
- fmt.Fprintln(w, "type "+names["Base"]+"Iterator struct {")
+func (pf *File) iterTop(w io.Writer, base string) {
+ var BASE string = base
+
+ fmt.Fprintln(w, "type "+BASE+"Iterator struct {")
fmt.Fprintln(w, " sync.RWMutex")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, " things []*"+names["Base"])
+ fmt.Fprintln(w, " things []*"+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(things []*"+names["Base"]+") *"+names["Base"]+"Iterator {")
- fmt.Fprintln(w, " return &"+names["Base"]+"Iterator{things: things}")
+ fmt.Fprintln(w, "// New"+BASE+"Iterator initializes a new iterator.")
+ fmt.Fprintln(w, "func New"+BASE+"Iterator(things []*"+BASE+") *"+BASE+"Iterator {")
+ fmt.Fprintln(w, " return &"+BASE+"Iterator{things: things}")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
fmt.Fprintln(w, "// Scan moves to the next element and returns false if there are no more things.")
@@ -88,7 +86,7 @@ func iterTop(w io.Writer, names map[string]string) {
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, "func (it *"+BASE+"Iterator) Scan() bool {")
fmt.Fprintln(w, " if it.index >= len(it.things) {")
fmt.Fprintln(w, " return false")
fmt.Fprintln(w, " }")