-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
38 lines (28 loc) · 982 Bytes
/
routes.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
package main
import (
"embed"
"github.com/darrelhong/micro-url/handlers"
"github.com/darrelhong/micro-url/store"
"github.com/darrelhong/micro-url/utils"
"github.com/gorilla/sessions"
"golang.org/x/oauth2"
"net/http"
)
//go:embed static
var static embed.FS
func addRoutes(mux *http.ServeMux,
urlStore store.UrlStore,
oauth2Conf *oauth2.Config,
sessionStore *sessions.CookieStore,
userStore store.UserStore,
tursoApiClient *utils.TursoApiClient,
userDbClient *utils.UserDbClient,
) {
mux.Handle("/",
handlers.HandleIndex(oauth2Conf, sessionStore))
mux.Handle("GET /github/callback", handlers.HandleGhCallback(oauth2Conf, sessionStore, userStore, tursoApiClient))
mux.Handle("GET /logout", handlers.HandleLogout(sessionStore))
mux.Handle("POST /shorten", handlers.HandleShorten(urlStore, sessionStore, userStore, userDbClient))
mux.Handle("GET /{shortUrlId}", handlers.HandleRedirect(urlStore))
mux.Handle("/static/", http.FileServer(http.FS(static)))
}