-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
47 lines (35 loc) · 1.08 KB
/
server.go
File metadata and controls
47 lines (35 loc) · 1.08 KB
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
package main
import (
"encoding/json"
"fmt"
"net/http"
// this is the Router package
"github.com/gorilla/mux"
)
// Router this initializes the Router
var Router = mux.NewRouter()
func main() {
// port number
var port string = ":4000"
fmt.Println("http://localhost" + port)
Router.HandleFunc("/", MessagePost).Methods("POST")
Router.HandleFunc("/create", CreateUser).Methods("POST")
Router.HandleFunc("/signin", SignIn).Methods("POST")
Router.HandleFunc("/allusers", AllUsers).Methods("GET")
Router.HandleFunc("/allcontacts", AllUsers).Methods("GET")
Router.HandleFunc("/savemsg", SaveMessage).Methods("POST")
Router.HandleFunc("/addcontact", AddContact).Methods("POST")
// Websocket connection
Router.HandleFunc("/socket", SocketHandler)
go handleMessages()
// Testing if Server is up
Router.HandleFunc("/", Test).Methods("GET")
// Test connect to redis
// RedisTest()
// ExampleClient()
http.ListenAndServe(port, Router)
}
// Test if server is running: GET localhost:4000
func Test(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode("Go api is running")
}