forked from ssproessig/go-webservice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
34 lines (27 loc) · 778 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
package main
import (
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
var todoChanged chan Todo
func main() {
port, ok := os.LookupEnv("PORT")
if !ok {
port = "8080"
}
port = ":" + port
log.Printf("Listening on port %s", port)
todoChanged = make(chan Todo)
go Connect2AMQPAndSetupQueue(GetAMQPUriToUse(), todoChanged)
// add one sample entry
todos = append(todos, Todo{Id: "1", Title: "First Todo"})
router := mux.NewRouter()
router.HandleFunc("/todo", GetTodos).Methods("GET")
router.HandleFunc("/todo/{id}", GetTodo).Methods("GET")
router.HandleFunc("/todo/{id}", AddReplaceTodo).Methods("POST")
router.HandleFunc("/todo/{id}", DeleteTodo).Methods("DELETE")
router.HandleFunc("/ws", ServeWebSocket)
log.Fatal(http.ListenAndServe(port, router))
}