Skip to content

Commit bc57eb5

Browse files
committed
chore(Config): added configurable webserver host and port
1 parent f32521b commit bc57eb5

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

config.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ version: 1.2.1
77
additionalConfigs:
88
- config_env.yaml # For tokens and access keys
99
- database/connection_env.yaml # Connection data for mySQL databse
10+
- webserver/config.yaml # Config for the webserver
1011

1112
# The language translation files to search for in 'data/lang/'
1213
# The first one in this list will also be the fallback when trying to
@@ -109,9 +110,6 @@ event:
109110
#id:
110111
#animated: true
111112

112-
webserver:
113-
favicon: webserver/favicon.png
114-
115113
twitch:
116114
name: c4e_bot
117115
channels:

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ func main() {
100100
}
101101

102102
log.Println("Starting webserver...")
103-
addr := ":8080"
104-
webserver.Run(addr, webChan)
103+
webserver.Run(webChan)
105104

106105
// Wait to end the bot
107106
log.Println("Press Ctrl+C to exit")

webserver/config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
webserver:
2+
# The host on which the webserver is bound to
3+
#host:
4+
# The port on which the webserver listens
5+
port: 8080
6+
# The path to the favicon for the webserver
7+
favicon: webserver/favicon.png

webserver/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"cake4everybot/webserver/twitch"
1919
"cake4everybot/webserver/youtube"
2020
logger "log"
21+
"net"
2122
"net/http"
2223
"time"
2324

@@ -42,9 +43,10 @@ func initHTTP() http.Handler {
4243
}
4344

4445
// Run starts the webserver at the given address
45-
func Run(addr string, webChan chan struct{}) {
46+
func Run(webChan chan struct{}) {
4647
handler := initHTTP()
4748

49+
var addr string = net.JoinHostPort(viper.GetString("webserver.host"), viper.GetString("webserver.port"))
4850
var err error
4951

5052
go func() {

0 commit comments

Comments
 (0)