-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
35 lines (26 loc) · 964 Bytes
/
setup.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
package main
import (
"net/http"
"time"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
)
//Setup initialize the http server
func Setup(bindAddress string, allowedOrigins []string) *http.Server {
router := mux.NewRouter()
origins := handlers.AllowedOrigins(allowedOrigins)
meths := handlers.AllowedMethods([]string{http.MethodGet, http.MethodOptions})
heads := handlers.AllowedHeaders([]string{"x-user-platform", "x-user-id", "Content-Type", "content-type", "Origin"})
// setting up routes
router.HandleFunc("/random", random).Methods(http.MethodGet, http.MethodOptions)
router.HandleFunc("/random/storage/{id}", servePost).Methods(http.MethodGet)
router.HandleFunc("/health", healthCheck).Methods(http.MethodGet)
srv := &http.Server{
Handler: handlers.CORS(meths, origins, heads)(router),
Addr: bindAddress,
WriteTimeout: time.Second * 15,
ReadTimeout: time.Second * 15,
IdleTimeout: time.Second * 60,
}
return srv
}