1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00
mycorrhiza/handlers.go
2020-06-18 15:23:44 +05:00

69 lines
1.7 KiB
Go

package main
import (
"github.com/gorilla/mux"
"log"
"net/http"
)
// Boilerplate code present in many handlers. Good to have it.
func HandlerBase(w http.ResponseWriter, r *http.Request) (Revision, bool) {
vars := mux.Vars(r)
revno := RevInMap(vars)
return GetRevision(hyphae, vars["hypha"], revno, w)
}
func HandlerGetBinary(w http.ResponseWriter, r *http.Request) {
if rev, ok := HandlerBase(w, r); ok {
rev.ActionGetBinary(w)
}
}
func HandlerRaw(w http.ResponseWriter, r *http.Request) {
if rev, ok := HandlerBase(w, r); ok {
rev.ActionRaw(w)
}
}
func HandlerZen(w http.ResponseWriter, r *http.Request) {
if rev, ok := HandlerBase(w, r); ok {
rev.ActionZen(w)
}
}
func HandlerView(w http.ResponseWriter, r *http.Request) {
if rev, ok := HandlerBase(w, r); ok {
rev.ActionView(w, HyphaPage)
}
}
func HandlerHistory(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
log.Println("Attempt to access an unimplemented thing")
}
func HandlerEdit(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
ActionEdit(vars["hypha"], w)
}
func HandlerRewind(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
log.Println("Attempt to access an unimplemented thing")
}
func HandlerDelete(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
log.Println("Attempt to access an unimplemented thing")
}
func HandlerRename(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
log.Println("Attempt to access an unimplemented thing")
}
func HandlerUpdate(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
log.Println("Attempt to access an unimplemented thing")
}