Updated deps, go.19 migration, nginx template work

This commit is contained in:
Jamie Curnow
2022-11-08 10:03:45 +10:00
parent 8d37f5df8d
commit c00b690ed3
23 changed files with 375 additions and 376 deletions

View File

@ -117,6 +117,21 @@ func getQueryVarInt(r *http.Request, varName string, required bool, defaultValue
return varInt, nil
}
/*
func getQueryVarBool(r *http.Request, varName string, required bool, defaultValue bool) (bool, error) {
queryValues := r.URL.Query()
varValue := queryValues.Get(varName)
if varValue == "" && required {
return false, fmt.Errorf("%v was not supplied in the request", varName)
} else if varValue == "" {
return defaultValue, nil
}
return varValue == "true" || varValue == "1" || varValue == "on", nil
}
*/
func getURLParamInt(r *http.Request, varName string) (int, error) {
required := true
defaultValue := 0

View File

@ -88,6 +88,8 @@ func UpdateHostTemplate() func(http.ResponseWriter, *http.Request) {
return
}
// reconfigure, _ := getQueryVarBool(r, "reconfigure", false, false)
hostTemplate, err := hosttemplate.GetByID(templateID)
if err != nil {
h.ResultErrorJSON(w, r, http.StatusBadRequest, err.Error(), nil)

View File

@ -2,7 +2,7 @@ package middleware
import (
"context"
"io/ioutil"
"io"
"net/http"
c "npm/internal/api/context"
@ -15,7 +15,7 @@ func BodyContext() func(http.Handler) http.Handler {
// Grab the Body Data
var body []byte
if r.Body != nil {
body, _ = ioutil.ReadAll(r.Body)
body, _ = io.ReadAll(r.Body)
}
// Add it to the context
ctx := r.Context()

View File

@ -38,12 +38,6 @@ var headersAllowedByCORS = []string{
"User-Agent",
"Cache-Control",
"Accept-Encoding",
"X-Jumbo-AppKey",
"X-Jumbo-SKey",
"X-Jumbo-SV",
"X-Jumbo-Timestamp",
"X-Jumbo-Version",
"X-Jumbo-Customer-Id",
}
// Cors handles cors headers

View File

@ -3,6 +3,7 @@ package api
import (
"fmt"
"net/http"
"time"
"npm/internal/logger"
)
@ -12,7 +13,14 @@ const httpPort = 3000
// StartServer creates a http server
func StartServer() {
logger.Info("Server starting on port %v", httpPort)
err := http.ListenAndServe(fmt.Sprintf(":%v", httpPort), NewRouter())
server := &http.Server{
Addr: fmt.Sprintf(":%v", httpPort),
Handler: NewRouter(),
ReadHeaderTimeout: 3 * time.Second,
}
err := server.ListenAndServe()
if err != nil {
logger.Error("HttpListenError", err)
}