Compare commits

...

3 Commits

Author SHA1 Message Date
Maximilian
fa3165d317 Use proper error comparison 2023-08-03 12:13:37 -05:00
Maximilian
7cb36db3c2 Handle errors 2023-08-03 12:13:15 -05:00
Maximilian
eda5344685 Fix spelling 2023-08-03 12:11:01 -05:00
3 changed files with 13 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import (
"GoWeb/routes"
"context"
"embed"
"errors"
"log"
"net/http"
"os"
@ -68,7 +69,7 @@ func main() {
go func() {
log.Println("Starting server and listening on " + appLoaded.Config.Listen.Ip + ":" + appLoaded.Config.Listen.Port)
err := server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("Could not listen on %s: %v\n", appLoaded.Config.Listen.Ip+":"+appLoaded.Config.Listen.Port, err)
}
}()

View File

@ -6,7 +6,7 @@ import (
"net/http"
)
// Csrf validates the CSRF token and returns the handler function if it succeded
// Csrf validates the CSRF token and returns the handler function if it succeeded
func Csrf(f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
_, err := security.VerifyCsrfToken(r)

View File

@ -21,9 +21,17 @@ func SendRequest(url string, method string, headers map[string]string, body inte
reqBody = &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
for key, value := range v {
writer.WriteField(key, value)
err := writer.WriteField(key, value)
if err != nil {
return http.Response{}, err
}
writer.Close()
}
err := writer.Close()
if err != nil {
return http.Response{}, err
}
contentType = writer.FormDataContentType()
default:
jsonBody, err := json.Marshal(body)