autogenpb/example/main.go

73 lines
1.4 KiB
Go
Raw Normal View History

2025-01-08 19:58:29 -06:00
//go:build go1.20
// +build go1.20
package main
2025-01-09 16:18:06 -06:00
import (
"os"
"go.wit.com/log"
)
2025-01-08 19:58:29 -06:00
// sent via -ldflags
var VERSION string
var BUILDTIME string
var sortmap map[string]string
var marshalKeys []string
var uniqueKeys []string
2025-01-09 12:54:04 -06:00
var pb *Fruits
2025-01-08 19:58:29 -06:00
func main() {
// pb = NewFruits()
pb = new(Fruits)
pb.Uuid = "test"
pb.Version = "v0.0.2"
2025-01-09 16:18:06 -06:00
fruit := &Fruit{
Brand: "mom",
City: "New NewYork",
}
x := new(Fruit)
x = &Fruit{
Brand: "dad",
City: "Germany",
}
appendByUPC(x)
appendByUPC(fruit)
testAppend(fruit)
testAppend(x)
}
func testAppend(fruit *Fruit) {
2025-01-09 16:18:06 -06:00
if pb.AppendUnique(fruit) {
log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City)
2025-01-09 16:18:06 -06:00
} else {
log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City)
2025-01-09 16:18:06 -06:00
os.Exit(-1)
}
if pb.AppendUnique(fruit) {
log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City)
os.Exit(-1)
} else {
log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City)
}
}
func appendByUPC(fruit *Fruit) {
if pb.AppendUniqueUPC(fruit) {
log.Info("AppendUnique() test1 ok", fruit.Brand, fruit.City)
} else {
log.Info("AppendUnique() test1 failed", fruit.Brand, fruit.City)
os.Exit(-1)
}
if pb.AppendUniqueUPC(fruit) {
log.Info("AppendUnique() test2 worked but should not have", fruit.Brand, fruit.City)
2025-01-09 16:18:06 -06:00
os.Exit(-1)
} else {
log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City)
2025-01-09 16:18:06 -06:00
}
2025-01-08 19:58:29 -06:00
}