-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
156 lines (136 loc) · 3.78 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"fmt"
"github.com/common-nighthawk/go-figure"
"github.com/maxoulfou/CX-20-speed-config/api"
"github.com/maxoulfou/CX-20-speed-config/entity"
"github.com/maxoulfou/CX-20-speed-config/format"
"github.com/maxoulfou/CX-20-speed-config/logs"
"github.com/maxoulfou/CX-20-speed-config/route"
"github.com/maxoulfou/CX-20-speed-config/services"
"os"
"runtime"
"strconv"
)
var YamlEnv entity.YmlConfig
var BarcoConfig entity.Barco
func Init() {
logs.WriteLogs("info", "App is started\n", true)
AsciiWelcome()
InitConfig()
InitLogs()
// Prettying yml and json config
InitPrettyYamlConfig()
InitLoadConfiguration()
InitApiChecking()
// Main program TODO : make args treatment
InitCliTool()
// InitProg()
os.Exit(0)
}
func InitCliTool() {
var Arguments []string
Arguments = os.Args[1:]
if len(Arguments) == 0 {
fmt.Println("There is no argument, please execute './cx-20-api.exe help'\n")
} else if len(Arguments) == 1 {
switch Arguments[0] {
case "help":
services.Help()
break
case "reboot":
services.Reboot()
break
case "personalization":
services.Personalization()
break
case "airplay":
services.Airplay()
break
case "google-cast":
services.GoogleCast()
break
case "wallpaper-upload":
services.WallpaperUpload()
break
case "change-wallpaper":
services.ChangeWallpaper()
break
case "hostname":
services.UpdateHostname()
break
case "wifi":
services.UpdateSsid()
break
case "all":
services.All()
break
default:
fmt.Printf("\nPlease refer you to services argument")
}
} else if len(Arguments) > 1 {
fmt.Printf("There is too much arguments, please refer you to services argument\n")
}
}
// AsciiWelcome will displaying welcome message - ascii art
func AsciiWelcome() {
myFigure := figure.NewFigure("CX-20 API", "", true)
myFigure.Print()
fmt.Printf("Version: %+v\n", entity.VERSION)
}
// InitApiChecking check if CX-20 station's API is reachable
func InitApiChecking() {
if api.CheckIfBarcoCxApiIsReachable() {
if YamlEnv.Env == "debug" {
fmt.Print("it is ok")
}
} else {
if YamlEnv.Env == "debug" {
fmt.Print("it is not ok")
}
return
}
}
// InitConfig will load env and CX-20 station's configuration
func InitConfig() {
YamlEnv.GetConfig()
BarcoConfig.GetConfig()
}
// InitLoadConfiguration prettify JSON configuration
func InitLoadConfiguration() {
config, _ := format.PrettyStruct(BarcoConfig)
// TODO : remake stacktrace export function
_, file, line, _ := runtime.Caller(1)
logs.WriteLogs("info", "("+file+" : "+strconv.Itoa(line)+") Loaded configuration:\n"+config, true)
fmt.Printf("\n------------------------------------------------------------------------------")
logs.WriteLogs("info", "--- End loaded configuration ---", false)
}
// InitLogs init test log function
func InitLogs() {
if YamlEnv.Env == "debug" {
_, file, line, _ := runtime.Caller(1)
// TODO : if in yaml file, env is set up to debug, not prod
logs.WriteLogs("error", "("+file+" : "+strconv.Itoa(line)+") TEST ERROR LOG", false)
logs.WriteLogs("warn", "("+file+" : "+strconv.Itoa(line)+") TEST WARN LOG", false)
logs.WriteLogs("info", "("+file+" : "+strconv.Itoa(line)+") TEST INFO LOG", false)
logs.WriteLogs("debug", "("+file+" : "+strconv.Itoa(line)+") TEST DEBUG LOG", false)
}
}
// InitPrettyYamlConfig prettify yml configuration file
func InitPrettyYamlConfig() {
prettyCfg, _ := format.PrettyStruct(YamlEnv)
logs.WriteLogs("info", "yml config: \n"+prettyCfg+"", true)
}
// InitProg is main function - procedural
func InitProg() {
api.Reboot()
api.Personalization()
fmt.Println("Get Wallpaper List")
api.GetWallpaperList()
api.ChangeWallpaper()
api.UpdateAirplayService()
api.UpdateGoogleCastService()
api.UploadWallpaper()
route.RoutesDictionary(true)
api.UpdateWifiSettings()
}