-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatserver.go
46 lines (36 loc) · 959 Bytes
/
chatserver.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
package chat_application
import (
"fmt"
"os"
"sync"
)
func ChatServerStart() {
// Initialize the commands which a user can send to the server
// by the server. See commands.go.
RegisterCommands()
err := ParseConfigFile()
if err != nil {
fmt.Printf("Error parsing config file: %v\n", err)
os.Exit(1)
}
if chatConfig.LogFile != "" {
fmt.Printf("Log file for messages: %s\n", chatConfig.LogFile)
}
// When we start up, create a room #default
// that everyone joins by default.
defaultRoom, err := NewRoom("#default")
if err != nil {
fmt.Printf("Error creating room: %v\n", err)
os.Exit(1)
}
go defaultRoom.Loop()
var wg sync.WaitGroup
wg.Add(2)
// This goroutine accepts incoming telnet connections.
// This is the core dispatch loop for the chat server.
go TelnetServer(&wg)
// This goroutine accepts incoming HTTP connections.
// This will be the dispatch loop of the REST API.
go RestAPIServer(&wg)
wg.Wait()
}