summaryrefslogtreecommitdiff
path: root/small
diff options
context:
space:
mode:
Diffstat (limited to 'small')
-rw-r--r--small/Makefile49
-rw-r--r--small/fruit.New.go9
-rw-r--r--small/fruit.proto20
-rw-r--r--small/main.go60
4 files changed, 138 insertions, 0 deletions
diff --git a/small/Makefile b/small/Makefile
new file mode 100644
index 0000000..95a9c0c
--- /dev/null
+++ b/small/Makefile
@@ -0,0 +1,49 @@
+VERSION = $(shell git describe --tags)
+BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
+
+all: clean simpleMutexProtoc goimports build
+ ./small
+
+modproto: clean withMutex goimports vet build
+ ./small
+
+rawproto: clean withoutMutex goimports vet build
+ ./small
+
+vet:
+ @GO111MODULE=off go vet
+
+build:
+ GO111MODULE=off go build -v
+
+simpleMutexProtoc:
+ ../autogenpb --proto fruit.proto --package main
+
+# why does this fail to compile? I'm not sure. maybe someone smart can figure it out
+# basically, it just trys to return the deleted record but says something
+# about the RWmutex lock being copied and GO fails to compile
+# I'm don't grok what is going on. This autogenerated code should
+# provide as simple as one could hope for automated way to try to debug it though!
+simpleMutexProtocWithDeleteCopy:
+ ../autogenpb --proto fruit.proto --package main --delete
+
+simpleMutexGlobal:
+ ../autogenpb --proto fruit.proto --package main --mutex=false
+
+withMutex:
+ ../autogenpb --proto fruit.proto --package main
+ ../autogenpb --proto file.proto --package main
+ ../autogenpb --proto patchset.proto --package main
+
+withoutMutex:
+ ../autogenpb --proto fruit.proto --package main --mutex=false
+ ../autogenpb --proto file.proto --package main --mutex=false
+ ../autogenpb --proto patchset.proto --package main --mutex=false
+
+goimports:
+ goimports -w *.go
+
+clean:
+ -rm -f go.*
+ -rm -f *.pb.go
+ -rm -f small basket.pb
diff --git a/small/fruit.New.go b/small/fruit.New.go
new file mode 100644
index 0000000..0be9b07
--- /dev/null
+++ b/small/fruit.New.go
@@ -0,0 +1,9 @@
+package main
+
+func NewFruits() *Fruits {
+ x := new(Fruits)
+ x.Uuid = "test"
+ x.Version = "v0.0.2"
+ // x.Fruits =
+ return x
+}
diff --git a/small/fruit.proto b/small/fruit.proto
new file mode 100644
index 0000000..341617d
--- /dev/null
+++ b/small/fruit.proto
@@ -0,0 +1,20 @@
+syntax = "proto3";
+
+package fruit;
+
+import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
+
+// "Fruit" must exist. you can put anything in it
+message Fruit {
+ string brand = 1;
+ string UPC = 2;
+ string city = 3;
+}
+
+// "Fruits" MUST EXIST and start exactly this way
+// It must be "Fruit" + 's' and must match the name of this file: "fruit.proto"
+message Fruits { // `autogenpb:marshal`
+ string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
+ string version = 2; // `autogenpb:version:v0.0.1`
+ repeated Fruit Fruits = 3; // THIS MUST BE "Fruit" and then "Fruit" + "s"
+}
diff --git a/small/main.go b/small/main.go
new file mode 100644
index 0000000..f8e5d60
--- /dev/null
+++ b/small/main.go
@@ -0,0 +1,60 @@
+//go:build go1.20
+// +build go1.20
+
+package main
+
+import (
+ "os"
+
+ "go.wit.com/log"
+)
+
+// sent via -ldflags
+var VERSION string
+var BUILDTIME string
+
+var sortmap map[string]string
+var marshalKeys []string
+var uniqueKeys []string
+
+func main() {
+ var pb *Fruits
+ pb = new(Fruits)
+ // attempt to load basket.pb
+ fruit := &Fruit{
+ Brand: "mom",
+ City: "New NewYork",
+ UPC: "2000",
+ }
+ pb.Fruits = append(pb.Fruits, fruit)
+
+ a := &Fruit{
+ Brand: "fry",
+ City: "the moon",
+ UPC: "2001",
+ }
+ pb.Fruits = append(pb.Fruits, a)
+
+ pb.saveBasket()
+}
+
+func (pb *Fruits) saveBasket() error {
+ data, err := pb.Marshal()
+ if err != nil {
+ return err
+ }
+
+ w, err := os.OpenFile("basket.pb", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+ if err != nil {
+ return err
+ }
+ w.Write(data)
+ w.Close()
+ log.Info("saved basket.pb ok")
+ return nil
+}
+
+func badExit(err error) {
+ log.Info("autogenpb error:", err)
+ os.Exit(-1)
+}