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