30 lines
903 B
Go
30 lines
903 B
Go
package handlers
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func StartMainServer() {
|
|
// Initialize Gorilla router
|
|
router := mux.NewRouter()
|
|
router.HandleFunc("/", indexGetHandler).Methods("GET")
|
|
router.HandleFunc("/", newPasteHandler).Methods("POST")
|
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", viewPasteHandler).Methods("GET")
|
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/nr", viewPasteHandlerNoRedirect).Methods("GET")
|
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/meta", viewPasteHandlerMeta).Methods("GET")
|
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}", deletePasteHandler).Methods("DELETE")
|
|
router.HandleFunc("/{key:[A-Za-z0-9-_]{4,}}/delete", deletePasteHandler).Methods("POST")
|
|
|
|
srv := &http.Server{
|
|
Handler: router,
|
|
Addr: "127.0.0.1:8000",
|
|
WriteTimeout: 15 * time.Second,
|
|
ReadTimeout: 15 * time.Second,
|
|
}
|
|
log.Fatal(srv.ListenAndServe())
|
|
}
|