Big refactoring of PARCOURSMOB - Initial commit
This commit is contained in:
94
main.go
Normal file
94
main.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/api"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/application"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/handlers/auth"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/cache"
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := ReadConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var (
|
||||
address = cfg.GetString("server.listen")
|
||||
service_name = cfg.GetString("service_name")
|
||||
templates_public_dir = cfg.GetString("templates.public_dir")
|
||||
)
|
||||
|
||||
svc, err := services.NewServicesHandler(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
idp, err := identification.NewIdentificationProvider(cfg, svc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cache, err := cache.NewCacheHandler(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
apiHandler, _ := api.NewAPIHandler(cfg, idp, svc, cache)
|
||||
applicationHandler, _ := application.NewApplicationHandler(cfg, svc, cache)
|
||||
authHandler, _ := auth.NewAuthHandler(cfg, idp, svc, cache)
|
||||
|
||||
fmt.Println("Running", service_name, ":")
|
||||
|
||||
r := mux.NewRouter()
|
||||
|
||||
r.PathPrefix("/public/").Handler(http.StripPrefix("/public/", http.FileServer(http.Dir(templates_public_dir))))
|
||||
|
||||
r.HandleFunc("/auth/groups/", authHandler.Groups)
|
||||
r.HandleFunc("/auth/groups/switch", authHandler.GroupSwitch)
|
||||
|
||||
api_router := r.PathPrefix("/api").Subrouter()
|
||||
api_router.HandleFunc("/", apiHandler.NotFound)
|
||||
api_router.HandleFunc("/geo/autocomplete", apiHandler.GeoAutocomplete)
|
||||
api_router.HandleFunc("/cache/{cacheid}", apiHandler.GetCache)
|
||||
api_router.HandleFunc("/oauth2/callback", apiHandler.OAuth2Callback)
|
||||
|
||||
application := r.PathPrefix("/app").Subrouter()
|
||||
application.HandleFunc("/", applicationHandler.Dashboard)
|
||||
application.HandleFunc("/beneficiaries/", applicationHandler.BeneficiariesList)
|
||||
application.HandleFunc("/beneficiaries/create", applicationHandler.BeneficiaryCreate)
|
||||
application.HandleFunc("/beneficiaries/{beneficiaryid}", applicationHandler.BeneficiaryDisplay)
|
||||
application.HandleFunc("/beneficiaries/{beneficiaryid}/update", applicationHandler.BeneficiaryUpdate)
|
||||
application.HandleFunc("/beneficiaries/{beneficiaryid}/picture", applicationHandler.BeneficiaryPicture)
|
||||
application.HandleFunc("/vehicles-management/", applicationHandler.VehiclesManagementOverview)
|
||||
application.HandleFunc("/vehicles-management/fleet/add", applicationHandler.VehiclesFleetAdd)
|
||||
//TODO Subrouters with middlewares checking security for each module ?
|
||||
application.Use(idp.Middleware)
|
||||
application.Use(idp.GroupsMiddleware)
|
||||
|
||||
appAdmin := application.PathPrefix("/administration").Subrouter()
|
||||
appAdmin.HandleFunc("/", applicationHandler.Administration)
|
||||
appAdmin.HandleFunc("/groups/", applicationHandler.AdministrationCreateGroup)
|
||||
appAdmin.HandleFunc("/groups/{groupid}", applicationHandler.AdministrationGroupDisplay)
|
||||
//TODO Secure with Middleware checking for modules
|
||||
|
||||
fmt.Println("-> HTTP server listening on", address)
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: r,
|
||||
Addr: address,
|
||||
WriteTimeout: 15 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
}
|
||||
|
||||
log.Fatal(srv.ListenAndServe())
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user