Compare commits
3 Commits
9670b7d717
...
fa3165d317
Author | SHA1 | Date | |
---|---|---|---|
|
fa3165d317 | ||
|
7cb36db3c2 | ||
|
eda5344685 |
3
main.go
3
main.go
@ -8,6 +8,7 @@ import (
|
|||||||
"GoWeb/routes"
|
"GoWeb/routes"
|
||||||
"context"
|
"context"
|
||||||
"embed"
|
"embed"
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -68,7 +69,7 @@ func main() {
|
|||||||
go func() {
|
go func() {
|
||||||
log.Println("Starting server and listening on " + appLoaded.Config.Listen.Ip + ":" + appLoaded.Config.Listen.Port)
|
log.Println("Starting server and listening on " + appLoaded.Config.Listen.Ip + ":" + appLoaded.Config.Listen.Port)
|
||||||
err := server.ListenAndServe()
|
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)
|
log.Fatalf("Could not listen on %s: %v\n", appLoaded.Config.Listen.Ip+":"+appLoaded.Config.Listen.Port, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"net/http"
|
"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) {
|
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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
_, err := security.VerifyCsrfToken(r)
|
_, err := security.VerifyCsrfToken(r)
|
||||||
|
@ -21,9 +21,17 @@ func SendRequest(url string, method string, headers map[string]string, body inte
|
|||||||
reqBody = &bytes.Buffer{}
|
reqBody = &bytes.Buffer{}
|
||||||
writer := multipart.NewWriter(reqBody)
|
writer := multipart.NewWriter(reqBody)
|
||||||
for key, value := range v {
|
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()
|
contentType = writer.FormDataContentType()
|
||||||
default:
|
default:
|
||||||
jsonBody, err := json.Marshal(body)
|
jsonBody, err := json.Marshal(body)
|
||||||
|
Loading…
Reference in New Issue
Block a user