sprechstunden-go/main.go

50 lines
1.4 KiB
Go
Raw Normal View History

2022-08-24 06:16:27 +00:00
package main
import (
"database/sql"
"log"
"log/syslog"
2022-08-24 06:16:27 +00:00
"net/http"
"os"
2022-08-29 20:58:19 +00:00
"sprechstundentool/controllers"
"sprechstundentool/repositories"
"sprechstundentool/sqldb"
"strings"
2022-08-24 06:16:27 +00:00
)
2022-08-29 20:58:19 +00:00
func main() {
logwriter, e := syslog.New(syslog.LOG_ERR, "sprechstunden")
if e == nil {
log.SetOutput(logwriter)
}
var db *sql.DB
switch os.Getenv("ohtDbType") {
case "mysql":
db = sqldb.ConnectMysql(os.Getenv("ohtDbMysqlConnection"))
default:
if os.Getenv("ohtDbFile") != "" && !strings.Contains(os.Getenv("ohtDbFile"), "/") {
db = sqldb.ConnectSQLite(os.Getenv("ohtDbFile"))
} else {
db = sqldb.ConnectSQLite("sprechstunden.db")
}
}
2022-08-24 06:16:27 +00:00
2022-08-29 20:58:19 +00:00
// Create repos
roomRepo := repositories.NewRoomRepo(db)
courseRepo := repositories.NewCourseRepo(db)
tutorRepo := repositories.NewTutorRepo(db)
officeHourRepo := repositories.NewOfficeHourRepo(db, roomRepo, tutorRepo, courseRepo)
requestRepo := repositories.NewRequestRepo(db, officeHourRepo)
h := controllers.NewBaseHandler(roomRepo, officeHourRepo, courseRepo, tutorRepo, requestRepo)
2022-08-24 06:16:27 +00:00
2022-08-29 20:58:19 +00:00
http.HandleFunc("/getByRoom", h.GetByRoomHandler)
http.HandleFunc("/getByCourse", h.GetByCourseHandler)
http.HandleFunc("/addOfficeHour", h.AddOfficeHourHandler)
http.HandleFunc("/confirmRequest", h.ConfirmRequestHandler)
2022-09-05 18:10:35 +00:00
http.HandleFunc("/deleteOfficeHour", h.DeleteOfficeHourHandler)
2022-08-29 20:58:19 +00:00
http.HandleFunc("/", h.RootHandler)
2022-08-24 06:16:27 +00:00
http.ListenAndServe(":8080", nil)
}