mirror of
https://github.com/rjNemo/go-wiki
synced 2026-06-06 02:36:40 +00:00
homeHandler, new page form and handler
This commit is contained in:
parent
c184591bc9
commit
58ff4e0d17
3 changed files with 13 additions and 23 deletions
|
|
@ -3,11 +3,16 @@ package controllers
|
|||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
"github.com/rjNemo/go-wiki/data"
|
||||
)
|
||||
|
||||
// Router dispatch the request to the corresponding route handlers.
|
||||
func Router(ph PageHandler, hh HomeHandler) {
|
||||
// http.HandleFunc("/", loveHandler)
|
||||
func Router(ctx data.Context) {
|
||||
hh := HomeHandler{Ctx: ctx}
|
||||
ph := PageHandler{Ctx: ctx}
|
||||
// uh := UserHandler{Users: UserStore}
|
||||
|
||||
http.HandleFunc("/view/", makeHandler(ph.view))
|
||||
http.HandleFunc("/edit/", makeHandler(ph.edit))
|
||||
http.HandleFunc("/save/", makeHandler(ph.save))
|
||||
|
|
|
|||
13
data/db.go
13
data/db.go
|
|
@ -24,19 +24,6 @@ func NewDB(connection string) (*sql.DB, error) {
|
|||
|
||||
log.Println("Connection to database successfully established!")
|
||||
return db, nil
|
||||
|
||||
// store := NewUserStore(db)
|
||||
// store.CreateTable()
|
||||
|
||||
// u := models.TestUser()
|
||||
// store.Add(u)
|
||||
// log.Print(u)
|
||||
// u1 := models.NewUser(3, 20, "paul", "newman", "PdsNz@FDKML.COM")
|
||||
// store.Update(16, u1)
|
||||
// log.Println(store.Get(1))
|
||||
// store.Delete(8)
|
||||
// log.Println(store.GetAll())
|
||||
// log.Println(store.Find("first_name", "John"))
|
||||
}
|
||||
|
||||
// Context registers the application data stores
|
||||
|
|
|
|||
14
main.go
14
main.go
|
|
@ -22,16 +22,14 @@ func main() {
|
|||
|
||||
// Migrate db …
|
||||
ctx.Pages.CreateTable()
|
||||
// ctx.Users.CreateTable()
|
||||
ctx.Users.CreateTable()
|
||||
|
||||
// create handlers around context
|
||||
hh := controllers.HomeHandler{Ctx: ctx}
|
||||
ph := controllers.PageHandler{Ctx: ctx}
|
||||
// uh := controllers.UserHandler{Users: UserStore}
|
||||
|
||||
// startServer
|
||||
log.Printf("Start Go-wiki server on http://localhost:%s", settings.Port)
|
||||
port := ":" + settings.Port
|
||||
controllers.Router(ph, hh)
|
||||
|
||||
// create handlers around context
|
||||
controllers.Router(ctx)
|
||||
|
||||
// startServer
|
||||
log.Fatal(http.ListenAndServe(port, nil))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue