mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
47 lines
922 B
Plaintext
47 lines
922 B
Plaintext
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gorilla/mux"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func RegexForHypha(s string) string {
|
|
return s + ":[^\\s\\d:/?&\\\\][^:?&\\\\]*}"
|
|
}
|
|
|
|
func EditFillHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
}
|
|
|
|
func HyphaHandler(w http.ResponseWriter, r *http.Request) {
|
|
vars := mux.Vars(r)
|
|
fmt.Fprintf(w, "Accessing hypha %v\n", vars["hypha"])
|
|
fmt.Fprintf(w, "Request at %v", r)
|
|
}
|
|
|
|
func main() {
|
|
r := mux.NewRouter()
|
|
r.Queries(
|
|
"action", "edit",
|
|
"fill", "{templateName}").
|
|
Path(RegexForHypha("/{hypha")).
|
|
HandlerFunc(EditFillHandler)
|
|
|
|
r.HandleFunc(RegexForHypha("/{hypha"), HyphaHandler)
|
|
r.HandleFunc("/kek", HyphaHandler)
|
|
http.Handle("/", r)
|
|
|
|
srv := &http.Server{
|
|
Handler: r,
|
|
Addr: "127.0.0.1:8000",
|
|
// Good practice: enforce timeouts for servers you create!
|
|
WriteTimeout: 15 * time.Second,
|
|
ReadTimeout: 15 * time.Second,
|
|
}
|
|
|
|
log.Fatal(srv.ListenAndServe())
|
|
}
|