Got rid of unneeded deferration of the body

This commit is contained in:
Arzumify 2024-10-05 10:19:23 +01:00
parent 677a89445a
commit d3b0aec1b9

16
main.go
View file

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"errors" "errors"
"io"
"net/url" "net/url"
"os" "os"
"time" "time"
@ -49,13 +48,6 @@ func logFunc(message string, messageType uint64, information library.ServiceInit
} }
} }
func deferBody(Body io.ReadCloser, information library.ServiceInitializationInformation) {
err := Body.Close()
if err != nil {
logFunc(err.Error(), 1, information)
}
}
func renderTemplate(statusCode int, w http.ResponseWriter, data map[string]interface{}, templatePath string, information library.ServiceInitializationInformation) { func renderTemplate(statusCode int, w http.ResponseWriter, data map[string]interface{}, templatePath string, information library.ServiceInitializationInformation) {
var err error var err error
var requestedTemplate *template.Template var requestedTemplate *template.Template
@ -267,7 +259,6 @@ func Main(information library.ServiceInitializationInformation) {
// Set up the API routes // Set up the API routes
router.Post("/api/packages/list", func(w http.ResponseWriter, r *http.Request) { router.Post("/api/packages/list", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
// Get the list of packages // Get the list of packages
rows, err := conn.Query("SELECT name FROM packages") rows, err := conn.Query("SELECT name FROM packages")
if err != nil { if err != nil {
@ -292,7 +283,6 @@ func Main(information library.ServiceInitializationInformation) {
}) })
router.Post("/api/packages/add", func(w http.ResponseWriter, r *http.Request) { router.Post("/api/packages/add", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
type packageData struct { type packageData struct {
Name string `json:"name"` Name string `json:"name"`
RepositoryPath string `json:"repositoryPath"` RepositoryPath string `json:"repositoryPath"`
@ -357,7 +347,6 @@ func Main(information library.ServiceInitializationInformation) {
}) })
router.Post("/api/packages/remove", func(w http.ResponseWriter, r *http.Request) { router.Post("/api/packages/remove", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
type packageData struct { type packageData struct {
Name string `json:"name"` Name string `json:"name"`
JwtToken string `json:"token"` JwtToken string `json:"token"`
@ -424,7 +413,6 @@ func Main(information library.ServiceInitializationInformation) {
}) })
router.Post("/api/packages/get", func(w http.ResponseWriter, r *http.Request) { router.Post("/api/packages/get", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
type packageData struct { type packageData struct {
Name string `json:"name"` Name string `json:"name"`
JwtToken string `json:"token"` JwtToken string `json:"token"`
@ -483,7 +471,6 @@ func Main(information library.ServiceInitializationInformation) {
}) })
router.Post("/api/packages/compile", func(w http.ResponseWriter, r *http.Request) { router.Post("/api/packages/compile", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
type packageData struct { type packageData struct {
Name string `json:"name"` Name string `json:"name"`
JwtToken string `json:"token"` JwtToken string `json:"token"`
@ -580,17 +567,14 @@ func Main(information library.ServiceInitializationInformation) {
// Set up the template routes // Set up the template routes
router.Get("/", func(w http.ResponseWriter, r *http.Request) { router.Get("/", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
renderTemplate(200, w, map[string]interface{}{}, "index.html", information) renderTemplate(200, w, map[string]interface{}{}, "index.html", information)
}) })
router.Get("/packages", func(w http.ResponseWriter, r *http.Request) { router.Get("/packages", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
renderTemplate(200, w, map[string]interface{}{}, "packages.html", information) renderTemplate(200, w, map[string]interface{}{}, "packages.html", information)
}) })
router.Get("/oauth", func(w http.ResponseWriter, r *http.Request) { router.Get("/oauth", func(w http.ResponseWriter, r *http.Request) {
defer deferBody(r.Body, information)
renderTemplate(200, w, map[string]interface{}{ renderTemplate(200, w, map[string]interface{}{
"ClientId": oauthResponse.AppID, "ClientId": oauthResponse.AppID,
}, "oauth.html", information) }, "oauth.html", information)