-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (43 loc) · 1.01 KB
/
main.go
File metadata and controls
53 lines (43 loc) · 1.01 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
48
49
50
51
52
53
package main
import(
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
// Cassandra config section
const(
cassandraHost string = "cassandra"
cassandraKeyspace string = "auth"
)
func main() {
// Config section
port := "8080"
cassandraUsers := map[string]string{
"john@example.com": "password",
"tom@example.com": "password",
"mary@example.com": "password",
}
// Migrations section
err := migrateCassandra(cassandraHost, cassandraKeyspace, cassandraUsers)
if err != nil {
log.Fatal("Migration failed! Reason:", err)
}
// HTTP Server section
r := mux.NewRouter()
users := r.PathPrefix("/users").Subrouter()
users.Methods("POST").
Path("/create").
HandlerFunc(registrationHandler)
users.Methods("POST").
Path("/signin").
HandlerFunc(signInHandler)
users.Methods("DELETE").
Path("/logout").
HandlerFunc(logOutHandler)
users.Methods("POST").
Path("/check").
HandlerFunc(checkHandler)
fmt.Println("Server running on port:", port)
http.ListenAndServe(":" + port, r)
}