This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.go
90 lines (76 loc) · 1.42 KB
/
main.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
package main
import (
"log"
"net"
"time"
"whapp-irc/config"
"whapp-irc/database"
"whapp-irc/files"
"whapp-irc/whapp"
"github.com/chromedp/chromedp"
)
var (
conf config.Config
fs *files.FileServer
userDb *database.Database
pool *chromedp.Pool
startTime = time.Now()
commit string
)
func main() {
var err error
conf, err = config.ReadEnvVars()
if err != nil {
panic(err)
}
userDb, err = database.MakeDatabase("db/users")
if err != nil {
panic(err)
}
fs, err = files.MakeFileServer(
conf.FileServerHost,
conf.FileServerPort,
"files",
conf.FileServerHTTPS,
)
if err != nil {
panic(err)
}
go func() {
if err := fs.Serve(); err != nil {
log.Fatalf("error while serving fileserver: %s", err)
}
}()
pool, err = func() (*chromedp.Pool, error) {
switch conf.LogLevel {
case whapp.LogLevelVerbose:
return chromedp.NewPool(chromedp.PoolLog(log.Printf, log.Printf, log.Printf))
default:
return chromedp.NewPool()
}
}()
if err != nil {
panic(err)
}
defer pool.Shutdown()
addr, err := net.ResolveTCPAddr("tcp", ":"+conf.IRCPort)
if err != nil {
panic(err)
}
listener, err := net.ListenTCP("tcp", addr)
if err != nil {
panic(err)
}
for {
socket, err := listener.AcceptTCP()
if err != nil {
log.Printf("error accepting TCP connection: %s", err)
continue
}
go func() {
if err := BindSocket(socket); err != nil {
log.Println(err)
}
}()
}
}