forked from WPFerg/services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (32 loc) · 945 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 (
"log"
"net/http"
"strconv"
"github.com/vvidovic/go-ws-example/httpHandlers"
"github.com/vvidovic/go-ws-example/storage"
"github.com/vvidovic/go-ws-example/structs"
)
const PORT = 8080
var messageId = 0
func createMessage(message string, sender string) structs.Message {
messageId++
return structs.Message{
ID: messageId,
Sender: sender,
Message: message,
}
}
func main() {
log.Println("Creating dummy messages")
storage.Add(createMessage("Testing", "1234"))
storage.Add(createMessage("Testing Again", "5678"))
storage.Add(createMessage("Testing A Third Time", "9012"))
log.Println("Attempting to start HTTP Server.")
http.HandleFunc("/messages", httpHandlers.HandleRequestCollection)
http.HandleFunc("/messages/", httpHandlers.HandleRequestEntity)
var err = http.ListenAndServe(":"+strconv.Itoa(PORT), nil)
if err != nil {
log.Panicln("Server failed starting. Error: ", err)
}
}