summaryrefslogtreecommitdiff
path: root/example/main.go
blob: 90efe25f1e3da4929214984391da01838a876bb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//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

var pb *Fruits

func main() {
	// pb = NewFruits()
	pb = new(Fruits)
	pb.Uuid = "test"
	pb.Version = "v0.0.2"

	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) {
	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)
	}
	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)
		os.Exit(-1)
	} else {
		log.Info("AppendUnique() test2 failed ok", fruit.Brand, fruit.City)
	}
}