-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (45 loc) · 1.32 KB
/
main.go
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
package main
import (
"log"
"github.com/guilhermegarcia86/go-patterns/builder"
"github.com/guilhermegarcia86/go-patterns/chain"
"github.com/guilhermegarcia86/go-patterns/proxy"
)
func main() {
//Build a PersonBuilder, set values and build a NaturalPerson
personBuilder := builder.GetBuilder("PF")
personBuilder.SetName("John Doe")
personBuilder.SetDocument("21368063004")
naturalPerson := personBuilder.Build()
//Build a PersonBuilder, set values and build a LegalPerson
personBuilder = builder.GetBuilder("PJ")
personBuilder.SetName("Cool Company")
personBuilder.SetDocument("47902850000149")
legalPerson := personBuilder.Build()
//Begin a Validation chain
validationName := &chain.ValidationName{}
validationType := &chain.ValidationType{}
validationType.SetNext(validationName)
validationType.Execute(naturalPerson)
validationType.Execute(legalPerson)
const (
url = "urlDatabase"
port = "3306"
user = "user"
pass = "pass"
)
//Open connection, heavy process
conn := proxy.OpenConnection(url, port, user, pass)
//Access database
msgI, err := conn.Access(url, port, user, pass)
if err != nil {
log.Fatalln("ERROR ", err)
}
log.Println(msgI)
//Do not open connection again
msgII, err := conn.Access(url, port, user, pass)
if err != nil {
log.Fatal("ERROR ", err)
}
log.Println(msgII)
}