-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (67 loc) · 2.67 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"github.com/gorilla/mux"
"github.com/joaodias/hugito-app/infrastructure"
"github.com/joaodias/hugito-app/interfaces"
"github.com/joaodias/hugito-app/usecases"
"golang.org/x/oauth2"
githuboauth "golang.org/x/oauth2/github"
"net/http"
"os"
)
func main() {
dbHandler, err := infrastructure.NewRethinkDBSession()
if err != nil {
panic("Can't connect to the database")
}
sourceControl := &infrastructure.Github{}
buildEngine := &infrastructure.Hugo{}
userInteractor := usecases.UserInteractor{}
userInteractor.UserRepository = &interfaces.ExternalUserRepository{
SourceControl: sourceControl,
DatabaseHandler: dbHandler,
BuildEngine: buildEngine,
Logger: &infrastructure.Logger{},
}
contentInteractor := usecases.ContentInteractor{}
contentInteractor.ContentRepository = &interfaces.ExternalContentRepository{
SourceControl: sourceControl,
DatabaseHandler: dbHandler,
BuildEngine: buildEngine,
Logger: &infrastructure.Logger{},
}
repositoryInteractor := usecases.RepositoryInteractor{}
repositoryInteractor.RepositoryRepository = &interfaces.ExternalRepositoryRepository{
SourceControl: sourceControl,
DatabaseHandler: dbHandler,
Logger: &infrastructure.Logger{},
}
webHandler := &interfaces.WebHandler{
OauthConfiguration: &oauth2.Config{
ClientID: os.Getenv("CLIENTID"),
ClientSecret: os.Getenv("SECRET"),
Endpoint: githuboauth.Endpoint,
},
UserInteractor: &userInteractor,
ContentInteractor: &contentInteractor,
RepositoryInteractor: &repositoryInteractor,
Logger: &infrastructure.Logger{},
}
router := mux.NewRouter()
router.HandleFunc("/user", webHandler.ReadUser).Methods("POST")
router.HandleFunc("/auth", webHandler.Authenticate).Methods("POST")
router.HandleFunc("/auth", webHandler.AuthWebOptions).Methods("OPTIONS")
router.HandleFunc("/content", webHandler.CreateContent).Methods("POST")
router.HandleFunc("/content", webHandler.ContentWebOptions).Methods("OPTIONS")
router.HandleFunc("/content", webHandler.ListContent).Methods("GET")
router.HandleFunc("/content/{name}", webHandler.ReadContent).Methods("GET")
router.HandleFunc("/content", webHandler.SaveContent).Methods("PUT")
router.HandleFunc("/content", webHandler.RemoveContent).Methods("DELETE")
router.HandleFunc("/content/publish", webHandler.ContentWebOptions).Methods("OPTIONS")
router.HandleFunc("/content/publish", webHandler.PublishContent).Methods("POST")
router.HandleFunc("/repository", webHandler.ValidateRepository).Methods("GET")
port := os.Getenv("PORT")
logger := &infrastructure.Logger{}
logger.Log("Server running on port " + port)
http.ListenAndServe(port, router)
}