refactor: enhancement of logging, config and metrics

This commit is contained in:
Jonas Kaninda
2024-11-11 08:50:34 +01:00
parent e25bc218b5
commit 11c72e5e17
12 changed files with 97 additions and 65 deletions

View File

@@ -21,7 +21,6 @@ import (
"fmt"
"github.com/jkaninda/goma-gateway/util"
"gopkg.in/yaml.v3"
"log"
"os"
)
@@ -46,21 +45,21 @@ func CheckConfig(fileName string) error {
}
for index, route := range gateway.gateway.Routes {
if len(route.Name) == 0 {
log.Printf("Warning: route name is empty, index: [%d]", index)
fmt.Printf("Warning: route name is empty, index: [%d]", index)
}
if route.Destination == "" && len(route.Backends) == 0 {
log.Printf("Error: no destination or backends specified for route: %s | index: [%d] \n", route.Name, index)
fmt.Printf("Error: no destination or backends specified for route: %s | index: [%d] \n", route.Name, index)
}
}
//Check middleware
for index, mid := range c.Middlewares {
if util.HasWhitespace(mid.Name) {
log.Printf("Warning: Middleware contains whitespace: %s | index: [%d], please remove whitespace characters\n", mid.Name, index)
fmt.Printf("Warning: Middleware contains whitespace: %s | index: [%d], please remove whitespace characters\n", mid.Name, index)
}
}
log.Printf("Routes count=%d Middlewares count=%d\n", len(gateway.gateway.Routes), len(gateway.middlewares))
fmt.Printf("Routes count=%d Middlewares count=%d\n", len(gateway.gateway.Routes), len(gateway.middlewares))
return nil