Mercurial > public > pacobot
comparison cmd/config.go @ 6:4deabe76bd7f
cmd: add CMD package
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 12 Mar 2025 14:13:24 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:8cf3011fc949 | 6:4deabe76bd7f |
---|---|
1 package cmd | |
2 | |
3 import ( | |
4 "encoding/json" | |
5 "io" | |
6 "log" | |
7 "os" | |
8 ) | |
9 | |
10 type Config struct { | |
11 ClientId string `json:"client_id"` | |
12 ClientSecret string `json:"client_secret"` | |
13 BroadcasterUserId string `json:"broadcaster_user_id"` | |
14 } | |
15 | |
16 func readConfig() Config { | |
17 file, err := os.Open(".config.json") | |
18 | |
19 if err != nil { | |
20 log.Fatalf("Error opening file: %v", err) | |
21 } | |
22 | |
23 defer file.Close() | |
24 | |
25 bytes, err := io.ReadAll(file) | |
26 | |
27 if err != nil { | |
28 log.Fatalf("Error reading file: %v", err) | |
29 } | |
30 | |
31 var config Config | |
32 | |
33 err = json.Unmarshal(bytes, &config) | |
34 if err != nil { | |
35 log.Fatalf("Error decoding JSON: %v", err) | |
36 } | |
37 | |
38 return config | |
39 } |