summaryrefslogtreecommitdiff
path: root/generateInsert.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-09 09:30:17 -0500
committerJeff Carr <[email protected]>2025-03-09 09:30:17 -0500
commit4f881d17c02a9d239aa8b2320607318df1c0d2fa (patch)
treef8303c14d524ea08e250170162c07bb756d21db7 /generateInsert.go
parent7f03282acaf7a5f7746ee46a52ac5bafa818f876 (diff)
add InsertBy() functionsv0.0.64
Diffstat (limited to 'generateInsert.go')
-rw-r--r--generateInsert.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/generateInsert.go b/generateInsert.go
index 79eb6ad..eb1fc95 100644
--- a/generateInsert.go
+++ b/generateInsert.go
@@ -9,24 +9,29 @@ import (
)
// new idea. useful? TODO: look at this again in 1y
-func (msg *MsgName) insertBy(w io.Writer, FRUIT, APPLES, APPLE string, COLOR string) {
+// Mar 2025. yes. this is useful
+func (msg *MsgName) insertBy(w io.Writer, FRUITS, FRUIT, APPLE string, COLOR string) string {
LOCK := msg.getLockname("x")
- fmt.Fprintln(w, "// returns an "+APPLE+" if "+COLOR+" matches, otherwise create")
- fmt.Fprintln(w, "func (x *"+FRUIT+") InsertBy"+COLOR+" (y string) *"+APPLE+" {")
+ funcdef := "func (x *" + FRUITS + ") InsertBy" + APPLE + " (y " + COLOR + ") *" + FRUIT + " {"
+
+ fmt.Fprintln(w, "// returns a "+FRUIT+" if "+APPLE+" matches, otherwise create")
+ fmt.Fprintln(w, funcdef)
fmt.Fprintln(w, " "+LOCK+".Lock()")
fmt.Fprintln(w, " defer "+LOCK+".Unlock()")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, " for _, p := range x."+APPLES+" {")
- fmt.Fprintln(w, " if p."+COLOR+" == y {")
- fmt.Fprintln(w, " return p")
+ fmt.Fprintln(w, " for _, z := range x."+FRUITS+" {")
+ fmt.Fprintln(w, " if z."+APPLE+" == y {")
+ fmt.Fprintln(w, " return z")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, " }")
fmt.Fprintln(w, "")
- fmt.Fprintln(w, " z := new("+APPLE+")")
- fmt.Fprintln(w, " z."+COLOR+" = y")
- fmt.Fprintln(w, " x."+APPLES+" = append(x."+APPLES+", z)")
+ fmt.Fprintln(w, " z := new("+FRUIT+")")
+ fmt.Fprintln(w, " z."+APPLE+" = y")
+ fmt.Fprintln(w, " x."+FRUITS+" = append(x."+FRUITS+", z)")
fmt.Fprintln(w, " return z")
fmt.Fprintln(w, "}")
fmt.Fprintln(w, "")
+
+ return funcdef
}