Przeglądaj źródła

add root file handler before StartPay

tags/v0.5
patrick 5 lat temu
rodzic
commit
412b491bfd
2 zmienionych plików z 37 dodań i 1 usunięć
  1. +34
    -0
      fs_wrapper_handler.go
  2. +3
    -1
      main.go

+ 34
- 0
fs_wrapper_handler.go Wyświetl plik

@@ -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)
}
}
}

+ 3
- 1
main.go Wyświetl plik

@@ -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")
}

Ładowanie…
Anuluj
Zapisz