mirror of
https://github.com/aclindsa/moneygo.git
synced 2025-07-02 20:28:38 -04:00
First pass at reorganizing go code into sub-packages
This commit is contained in:
31
internal/handlers/handlers.go
Normal file
31
internal/handlers/handlers.go
Normal file
@ -0,0 +1,31 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"gopkg.in/gorp.v1"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Create a closure over db, allowing the handlers to look like a
|
||||
// http.HandlerFunc
|
||||
type DB = gorp.DbMap
|
||||
type DBHandler func(http.ResponseWriter, *http.Request, *DB)
|
||||
|
||||
func DBHandlerFunc(h DBHandler, db *DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
h(w, r, db)
|
||||
}
|
||||
}
|
||||
|
||||
func GetHandler(db *DB) *http.ServeMux {
|
||||
servemux := http.NewServeMux()
|
||||
servemux.HandleFunc("/session/", DBHandlerFunc(SessionHandler, db))
|
||||
servemux.HandleFunc("/user/", DBHandlerFunc(UserHandler, db))
|
||||
servemux.HandleFunc("/security/", DBHandlerFunc(SecurityHandler, db))
|
||||
servemux.HandleFunc("/securitytemplate/", SecurityTemplateHandler)
|
||||
servemux.HandleFunc("/account/", DBHandlerFunc(AccountHandler, db))
|
||||
servemux.HandleFunc("/transaction/", DBHandlerFunc(TransactionHandler, db))
|
||||
servemux.HandleFunc("/import/gnucash", DBHandlerFunc(GnucashImportHandler, db))
|
||||
servemux.HandleFunc("/report/", DBHandlerFunc(ReportHandler, db))
|
||||
|
||||
return servemux
|
||||
}
|
Reference in New Issue
Block a user