Updated article loader and added test entry to database
This commit is contained in:
27
main.go
27
main.go
@@ -15,6 +15,21 @@ func main() {
|
||||
r := mux.NewRouter()
|
||||
r.StrictSlash(true)
|
||||
|
||||
setupApi(r)
|
||||
setupFrontend(r)
|
||||
|
||||
db, err := database.NewSqlite3Connection(config.DatabaseFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
database.SetGlobDB(db)
|
||||
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%s", config.ServerPort), r); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func setupApi(r *mux.Router) {
|
||||
r.HandleFunc("/api/login", api.Login).Methods(http.MethodPost)
|
||||
|
||||
r.HandleFunc("/api/authors", api.Authors).Methods(http.MethodGet)
|
||||
@@ -26,7 +41,9 @@ func main() {
|
||||
r.HandleFunc("/api/article", api.Article).Methods(http.MethodPost, http.MethodPatch, http.MethodDelete)
|
||||
|
||||
r.HandleFunc("/api/assets", api.Assets).Methods(http.MethodGet, http.MethodPost, http.MethodDelete)
|
||||
}
|
||||
|
||||
func setupFrontend(r *mux.Router) {
|
||||
r.HandleFunc("/article/{article}", server.Article).Methods(http.MethodGet)
|
||||
|
||||
r.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -42,14 +59,4 @@ func main() {
|
||||
server.Error404(w, r)
|
||||
}
|
||||
})
|
||||
|
||||
db, err := database.NewSqlite3Connection(config.DatabaseFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
database.SetGlobDB(db)
|
||||
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%s", config.ServerPort), r); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user