-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.go
43 lines (33 loc) · 954 Bytes
/
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
package main
import (
"net/http"
"os"
"log"
"fmt"
"strconv"
"github.com/gaurigshankar/golang-chat/chat"
"github.com/gaurigshankar/golang-chat/config"
)
var configuration config.Configuration
var serverHostName string
func init() {
configuration = config.LoadConfigAndSetUpLogging()
herokuConfigPort := os.Getenv("PORT")
if herokuConfigPort == "" {
serverHostName = fmt.Sprintf("%s:%s",configuration.Hostname,strconv.Itoa(configuration.Port))
} else {
serverHostName = fmt.Sprintf(":%s",herokuConfigPort)
}
log.Println("The serverHost url", serverHostName)
}
func main() {
// websocket server
server := chat.NewServer()
go server.Listen()
http.HandleFunc("/messages", handleHomePage)
http.HandleFunc("/", handleHomePage)
http.ListenAndServe(serverHostName, nil)
}
func handleHomePage(responseWriter http.ResponseWriter, request *http.Request) {
http.ServeFile(responseWriter, request, "chat.html")
}