summaryrefslogtreecommitdiff
path: root/generateInsert.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-19 02:36:32 -0600
committerJeff Carr <[email protected]>2025-01-19 02:36:32 -0600
commit35f8270d5423ca1767ac4593afa39e93b4848daa (patch)
tree780c41bcdba0bfee6726d3449b67014ca3c18116 /generateInsert.go
parentace99c8aa8ad8b95aa13d7716d8d61f38a18acdf (diff)
add Delete()v0.0.47
Diffstat (limited to 'generateInsert.go')
-rw-r--r--generateInsert.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/generateInsert.go b/generateInsert.go
new file mode 100644
index 0000000..e84d7db
--- /dev/null
+++ b/generateInsert.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "fmt"
+ "io"
+)
+
+// new idea. useful? TODO: look at this again in 1y
+func (msg *MsgName) insertBy(w io.Writer, FRUIT, APPLES, APPLE string, COLOR 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+" {")
+ 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, " }")
+ 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, " return z")
+ fmt.Fprintln(w, "}")
+ fmt.Fprintln(w, "")
+}