-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
52 lines (42 loc) · 1.56 KB
/
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
44
45
46
47
48
49
50
51
52
package main
import (
"github.com/CertSysPoC/controllers"
"github.com/CertSysPoC/utils"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"log"
"net/http"
"time"
)
func init() {
//Create ipfs folder for the university
directory := utils.GetConfigs().Institution
//Create Account for the university
controllers.CreateUniversityProfile(directory)
//Create directory
utils.CreateDirIfNotExist(directory)
}
func main() {
//TODO:Add routes
r := mux.NewRouter()
r.HandleFunc("/results", controllers.GetResults).Methods(http.MethodPost, http.MethodOptions)
r.HandleFunc("/results/create", controllers.CreateResults).Methods(http.MethodPost, http.MethodOptions)
r.HandleFunc("/profile", controllers.CreateStudentProfile).Methods(http.MethodPost, http.MethodOptions)
r.HandleFunc("/transcript/{hash}", controllers.GetTranscript).Methods(http.MethodGet, http.MethodOptions)
http.Handle("/", r)
//TODO: Initialize API server
srv := &http.Server{
Handler: r,
Addr: "0.0.0.0:8001",
// Good practice: enforce timeouts for servers you create!
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With"})
originsOk := handlers.AllowedOrigins([]string{"*"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
// start server listen
// with error handling
log.Fatal(srv.ListenAndServe(), handlers.CORS(originsOk, headersOk, methodsOk)(r))
//log.Fatal(srv.ListenAndServe(":" + os.Getenv("PORT"), handlers.CORS(originsOk, headersOk, methodsOk)(r)))
}