-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
42 lines (33 loc) · 845 Bytes
/
server.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
package main
import (
"fmt"
"net/http"
"GOssenger/chat"
"GOssenger/dashboard"
"github.com/gorilla/mux"
"github.com/rs/cors"
)
const (
siteHost = "127.0.0.1"
sitePort = 8080
)
func main() {
address := fmt.Sprintf("%s:%d", siteHost, sitePort)
fmt.Println(fmt.Sprintf("Starting server on port %s", address))
createServer(":8080")
}
func createServer(address string) {
router := mux.NewRouter()
router.HandleFunc("/{chat_id:[0-9]+}", chat.ChatHandler)
router.HandleFunc("/", chat.IndexHandler)
http.Handle("/", router)
dashboard.CreateRouter(router)
corsWrapper := cors.New(cors.Options{
AllowedMethods: []string{"GET", "POST", "DELETE"},
AllowedHeaders: []string{"Content-Type", "Origin", "Accept", "*"},
})
http.ListenAndServe(address, corsWrapper.Handler(router))
}
func Hello() string {
return "Just for test"
}