2023-07-11 07:38:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2023-07-14 04:39:19 +00:00
|
|
|
"path"
|
2023-07-11 07:38:05 +00:00
|
|
|
"runtime/debug"
|
2023-07-14 04:39:19 +00:00
|
|
|
"strings"
|
2023-07-11 07:38:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (app *application) serverError(w http.ResponseWriter, err error) {
|
|
|
|
trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack())
|
|
|
|
app.errorLog.Print(trace)
|
|
|
|
|
|
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *application) clientError(w http.ResponseWriter, status int) {
|
|
|
|
http.Error(w, http.StatusText(status), status)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *application) notFound(w http.ResponseWriter) {
|
|
|
|
app.clientError(w, http.StatusNotFound)
|
|
|
|
}
|
2023-07-14 04:39:19 +00:00
|
|
|
|
|
|
|
func (app *application) cleanUrl(url string) string {
|
|
|
|
s, _ := strings.CutPrefix(url, "http://")
|
|
|
|
s, _ = strings.CutPrefix(s, "https://")
|
|
|
|
s = path.Base(path.Clean(s))
|
|
|
|
s = "http://" + s
|
|
|
|
return s
|
|
|
|
}
|