7
7
"log"
8
8
"net/http"
9
9
"os"
10
+ "path/filepath"
10
11
"strconv"
11
12
"time"
12
13
@@ -39,6 +40,7 @@ type Stats struct {
39
40
var h Team = Team {"Blue Team" , PlaceholderImage , 1 , 1 , Stats {1 , 1 , 1 , 1 }}
40
41
var a Team = Team {"Gold Team" , PlaceholderImage , 1 , 1 , Stats {1 , 1 , 1 , 1 }}
41
42
var s Scoreboard = Scoreboard {& h , & a , 0 , 0 , 0 , 0 }
43
+ var logoPath string
42
44
43
45
func setupLogs () {
44
46
f , err := os .OpenFile ("./output.log" , os .O_APPEND | os .O_CREATE | os .O_RDWR , 0666 )
@@ -57,6 +59,9 @@ func main() {
57
59
// Configure log output to file
58
60
setupLogs ()
59
61
62
+ // Create Directory For Logos
63
+ SetupLogoDirectory ()
64
+
60
65
// Setup HTTP handler and websocket handler
61
66
StartHTTPServer ()
62
67
@@ -151,24 +156,30 @@ type IGLApiResponse struct {
151
156
} `json:"data"`
152
157
}
153
158
154
- // OLD JSON parser
155
- // results := result["data"].([]interface{})
156
- // teams := []Team{}
157
- // for _, v := range results {
158
- // t := v.(map[string]interface{})["team"]
159
- // s := v.(map[string]interface{})["stats"]
160
- // team := Team{}
161
- // team.Name = t.(map[string]interface{})["formattedName"].(string)
162
- // team.Tier = int(t.(map[string]interface{})["tier"].(float64))
163
- // team.Div = int(t.(map[string]interface{})["div"].(float64))
164
- // if t.(map[string]interface{})["logo"] != nil {
165
- // team.Img = t.(map[string]interface{})["logo"].(string)
166
- // } else {
167
- // team.Img = KQBAvatarImage
168
- // }
169
- // team.Stats.GamesWon, _ = strconv.Atoi(s.(map[string]interface{})["Games Won"].(string))
170
- // team.Stats.GamesLost, _ = strconv.Atoi(s.(map[string]interface{})["Games Lost"].(string))
171
- // team.Stats.MatchesWon, _ = strconv.Atoi(s.(map[string]interface{})["Matches Won"].(string))
172
- // team.Stats.MatchesLost, _ = strconv.Atoi(s.(map[string]interface{})["Matches Lost"].(string))
173
- // teams = append(teams, team)
174
- // }
159
+ // SetupLogoDirectory creates a directory to cache the local logo files
160
+ func SetupLogoDirectory () {
161
+
162
+ // Get Current Working Directory
163
+ path , err := os .Getwd ()
164
+ if err != nil {
165
+ log .Println (err )
166
+ }
167
+ fmt .Println (path )
168
+
169
+ // Set Logo Path
170
+ logoPath = filepath .Join (path , "logo" )
171
+ fmt .Println (logoPath )
172
+
173
+ // Create directory if it doesn't exist
174
+ if _ , err := os .Stat (logoPath ); os .IsNotExist (err ) {
175
+ os .Mkdir (logoPath , 0755 )
176
+ }
177
+ }
178
+
179
+ func tidyUp () {
180
+
181
+ // Remove logopath directory and files
182
+ os .RemoveAll (logoPath )
183
+ os .Remove ("./output.log" )
184
+ log .Println ("Exiting..." )
185
+ }
0 commit comments