summaryrefslogtreecommitdiff
path: root/example/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-10 23:55:12 -0600
committerJeff Carr <[email protected]>2025-01-10 23:55:12 -0600
commit51a326c5d75ac1635de92bf2636f5050326b459e (patch)
tree23ff99a7f6601e50f24733935669c287afd45ea7 /example/main.go
parentf3297022a8ed73db93842311d4b1429e8f69e8c7 (diff)
still testing
Diffstat (limited to 'example/main.go')
-rw-r--r--example/main.go39
1 files changed, 23 insertions, 16 deletions
diff --git a/example/main.go b/example/main.go
index 9fdf1ca..a248fed 100644
--- a/example/main.go
+++ b/example/main.go
@@ -29,13 +29,16 @@ func main() {
fruit := &Fruit{
Brand: "mom",
City: "New NewYork",
+ UPC: "2000",
}
testAppend(fruit)
- appendByUPC(fruit)
+ appendByUPC()
+ }
+ if err := pb.saveBasket(); err != nil {
+ badExit(err)
}
if pb == nil {
- log.Info("This should not have happened")
- os.Exit(-1)
+ badExit(fmt.Errorf("pb == nil This should not have happened"))
}
pb.printTable()
pb.addThings()
@@ -44,6 +47,11 @@ func main() {
pb.sortTable(100)
}
+func badExit(err error) {
+ log.Info("autogenpb error:", err)
+ os.Exit(-1)
+}
+
/*
x := new(Fruit)
x = &Fruit{
@@ -112,8 +120,7 @@ func (pb *Fruits) addThings() {
if pb.AppendUniqueByBrand(tmp) {
// log.Printf("AppendUniqueBrand() ok len=%s %s %d\n", tmp.Brand, tmp.City, pb.Len())
} else {
- log.Printf("AppendUniqueByBrand() ERROR len=%s %s %d\n", tmp.Brand, tmp.City, pb.Len())
- os.Exit(-1)
+ badExit(fmt.Errorf("AppendUniqueByBrand() ERROR len=%s %s %d\n", tmp.Brand, tmp.City, pb.Len()))
}
pb.Append(tmp)
added += 1
@@ -127,27 +134,27 @@ func testAppend(fruit *Fruit) {
if pb.AppendUnique(fruit) {
log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City)
} else {
- log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City)
- os.Exit(-1)
+ badExit(fmt.Errorf("AppendUnique test1 failed %s %s %d\n", fruit.Brand, fruit.City, pb.Len()))
}
if pb.AppendUnique(fruit) {
- log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City)
- os.Exit(-1)
+ badExit(fmt.Errorf("AppendUnique() test2 worked but should not have %s %s", fruit.Brand, fruit.City))
} else {
log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City)
}
}
-func appendByUPC(fruit *Fruit) {
- if pb.AppendUniqueUPC(fruit) {
+func appendByUPC() {
+ fruit := new(Fruit)
+ fruit.UPC = "blah331"
+ fruit.City = "fry"
+ fruit.City = "paris"
+ if pb.AppendUniqueByUPC(fruit) {
log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City)
} else {
- log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City)
- os.Exit(-1)
+ badExit(fmt.Errorf("AppendUniqueByUPC test1 failed %s %s %d\n", fruit.Brand, fruit.City, pb.Len()))
}
- if pb.AppendUniqueUPC(fruit) {
- log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City)
- os.Exit(-1)
+ if pb.AppendUniqueByUPC(fruit) {
+ badExit(fmt.Errorf("AppendUniqueByUPC() test2 worked but should not have %s %s", fruit.Brand, fruit.City))
} else {
log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City)
}