diff --git a/fs_wrapper_handler.go b/fs_wrapper_handler.go new file mode 100644 index 0000000..2c13e33 --- /dev/null +++ b/fs_wrapper_handler.go @@ -0,0 +1,34 @@ +package main + +import ( + "net/http" +) + +type NotFoundRedirectRespWr struct { + http.ResponseWriter // We embed http.ResponseWriter + status int +} + +func (w *NotFoundRedirectRespWr) WriteHeader(status int) { + w.status = status // Store the status for our own use + if status != http.StatusNotFound { + w.ResponseWriter.WriteHeader(status) + } +} + +func (w *NotFoundRedirectRespWr) Write(p []byte) (int, error) { + if w.status != http.StatusNotFound { + return w.ResponseWriter.Write(p) + } + return len(p), nil // Lie that we successfully written it +} + +func wrapHandler(h http.Handler) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/" { + StartPay(w, r) + } else { + h.ServeHTTP(w, r) + } + } +} diff --git a/main.go b/main.go index 21d19d8..f7ee44b 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( func main() { //readConfig() readConfigForTest() - http.HandleFunc("/", StartPay) + http.HandleFunc("/choosePayment", choosePayment) http.HandleFunc("/rpnNameAndCard", rpnNameAndCard) // http.HandleFunc("/", Index) @@ -18,6 +18,8 @@ func main() { // http.HandleFunc("/insert", Insert) // http.HandleFunc("/update", Update) // http.HandleFunc("/delete", Delete) + fs := wrapHandler(http.FileServer(http.Dir("./PG"))) + http.HandleFunc("/", fs) http.ListenAndServe(":8080", nil) log.Println("Server started on: http://localhost:8080") }