diff --git a/Makefile b/Makefile index 9562c0e..23d7038 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ VERSION = $(shell git describe --tags) BUILDTIME = $(shell date +%Y.%m.%d_%H%M) +hmm: test + simple: build # make -C example clean simpleMutexGlobal goimports vet make -C example clean simpleMutexProtoc goimports vet @@ -40,8 +42,8 @@ auto: # rm -f auto.sort.pb.go auto.newsort.pb.go # auto.marshal.pb.go test: - make -C example rawproto make -C example modproto + make -C example rawproto junk: cd example; rm -f go.* *.pb.go 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) } diff --git a/sort.go b/sort.go index e658ccf..e7f4946 100644 --- a/sort.go +++ b/sort.go @@ -47,6 +47,8 @@ func (pb *Files) makeNewSortfile(pf *File) error { pf.findFunc(wFind) */ + pf.specialBases(wSort, wFind) + // attempt to add sort functions for pf.Base if err := pf.processMessage(pf.Bases, wSort, wFind); err != nil { return err @@ -57,6 +59,15 @@ func (pb *Files) makeNewSortfile(pf *File) error { return nil } +func (pf *File) specialBases(wSort, wFind io.Writer) { + var FRUIT string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name) + var APPLES string = cases.Title(language.English, cases.NoLower).String(pf.Bases.Name) + var APPLE string = cases.Title(language.English, cases.NoLower).String(pf.Base.Name) + + pf.Bases.simpleAppend(wFind, FRUIT, APPLES, APPLE) + +} + // to simplify being able to read the code, FRUIT, APPLES and APPLE are used // FRUIT == the string name of the message in the protobuf file // APPLE == the type of the repeated variable @@ -93,7 +104,6 @@ func (pf *File) processMessage(msg *MsgName, wSort, wFind io.Writer) error { log.Printf("FOUND: %s %s for %s\n", APPLES, APPLE, FRUIT) - found.simpleAppend(wFind, FRUIT, APPLES, APPLE) found.addAppendByMsg(wFind, FRUIT, APPLES, APPLE) found.addDeleteByMsg(wFind, FRUIT, APPLES, APPLE) found.addInsertByMsg(wFind, FRUIT, APPLES, APPLE) // new idea diff --git a/sortNew.go b/sortNew.go index 9f6a829..b23f1aa 100644 --- a/sortNew.go +++ b/sortNew.go @@ -3,6 +3,8 @@ package main import ( "fmt" "io" + + "go.wit.com/log" ) func (msg *MsgName) getLockname(s string) string { @@ -18,6 +20,7 @@ func (msg *MsgName) getLockname(s string) string { func (msg *MsgName) simpleAppend(w io.Writer, FRUIT, APPLES, APPLE string) { LOCK := msg.getLockname("x") + log.Printf("\t\t(x %s) APPEND(%s)\n", FRUIT, APPLE) // append -- no check at all fmt.Fprintln(w, "// TESTING 2") fmt.Fprintln(w, "// just a simple Append() shortcut (but still uses the mutex lock)")