-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
113 lines (89 loc) · 1.77 KB
/
app.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"fmt"
"log"
"strings"
)
type Web3 struct {
ChainID int
}
type EtherealFacade struct{}
type AppContainer struct {
Config AppConfig
}
type AppConfig struct {
Logging LoggingConfig
Etherscan EtherscanConfig
}
type LoggingConfig struct {
Loggers map[string]*Logger
}
type Logger struct {
Level string
}
type EtherscanConfig struct {
ChainID int
}
type Ethereal struct {
w3 *Web3
logLevel *string
facade *EtherealFacade
}
func NewEthereal(w3 *Web3, logLevel *string) *Ethereal {
return &Ethereal{
w3: w3,
logLevel: logLevel,
}
}
func (e *Ethereal) GetAttribute(name string) interface{} {
if name != "e" {
return e.w3
}
if e.facade == nil {
app, err := e.initApp()
if err != nil {
log.Fatalf("Error initializing Ethereal: %v", err)
}
e.facade = app.EtherealFacade(e.w3)
}
return e.facade
}
func (e *Ethereal) initApp() (*AppContainer, error) {
var logLevel string
if e.logLevel != nil {
logLevel = strings.ToUpper(*e.logLevel)
}
chainID := e.w3.ChainID
app := &AppContainer{
Config: AppConfig{
Logging: LoggingConfig{
Loggers: map[string]*Logger{
"root": {},
},
},
Etherscan: EtherscanConfig{},
},
}
if logLevel != "" {
app.Config.Logging.Loggers["root"].Level = logLevel
}
app.Config.Etherscan.ChainID = chainID
if err := app.InitResources(); err != nil {
return nil, err
}
return app, nil
}
func (app *AppContainer) EtherealFacade(w3 *Web3) *EtherealFacade {
return &EtherealFacade{}
}
func (app *AppContainer) InitResources() error {
fmt.Println("Initializing resources...")
return nil
}
func main() {
w3 := &Web3{ChainID: 1}
logLevel := "INFO"
ethereal := NewEthereal(w3, &logLevel)
facade := ethereal.GetAttribute("e")
fmt.Printf("Facade: %v\n", facade)
}