Merge pull request #13 from jkaninda/refactor

Refactor
This commit is contained in:
2024-10-29 14:37:52 +01:00
committed by GitHub
4 changed files with 18 additions and 4 deletions

View File

@@ -153,6 +153,7 @@ type Gateway struct {
//Disable dispelling routes on start
DisableDisplayRouteOnStart bool `yaml:"disableDisplayRouteOnStart"`
InterceptErrors []int `yaml:"interceptErrors"`
EnableKeepAlive bool `yaml:"enableKeepAlive"`
// Cors contains the proxy global cors
Cors Cors `yaml:"cors"`
// Routes defines the proxy routes
@@ -243,6 +244,7 @@ func initConfig(configFile string) {
DisableRouteHealthCheckError: false,
DisableDisplayRouteOnStart: false,
RateLimiter: 0,
InterceptErrors: []int{405, 500},
Cors: Cors{
Origins: []string{"http://localhost:8080", "https://example.com"},
Headers: map[string]string{
@@ -253,8 +255,7 @@ func initConfig(configFile string) {
},
Routes: []Route{
{
Name: "HealthCheck",
Host: "localhost",
Name: "Public",
Path: "/public",
Destination: "http://localhost:80",
Rewrite: "/healthz",
@@ -282,19 +283,27 @@ func initConfig(configFile string) {
},
},
},
{
Name: "Hostname example",
Host: "example.com",
Path: "/",
Destination: "https://example.com",
Rewrite: "/",
HealthCheck: "",
},
},
},
Middlewares: []Middleware{
{
Name: "basic-auth",
Type: "basic",
Type: basicAuth,
Rule: BasicRule{
Username: "goma",
Password: "goma",
},
}, {
Name: "jwt",
Type: "jwt",
Type: jwtAuth,
Rule: JWTRuler{
URL: "https://www.googleapis.com/auth/userinfo.email",
RequiredHeaders: []string{

View File

@@ -57,6 +57,8 @@ func (intercept InterceptErrors) ErrorInterceptor(next http.Handler) http.Handle
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rec := newResponseRecorder(w)
next.ServeHTTP(rec, r)
//Set Server name
w.Header().Set("Server", "Goma")
if canIntercept(rec.statusCode, intercept.Errors) {
logger.Debug("Backend error intercepted")
logger.Debug("An error occurred in the backend, %d", rec.statusCode)

View File

@@ -39,6 +39,8 @@ func (gatewayServer GatewayServer) Start(ctx context.Context) error {
if !gatewayServer.gateway.DisableDisplayRouteOnStart {
printRoute(gatewayServer.gateway.Routes)
}
// Set KeepAlive
srv.SetKeepAlivesEnabled(gatewayServer.gateway.EnableKeepAlive)
go func() {
logger.Info("Started Goma Gateway server on %v", gatewayServer.gateway.ListenAddr)

View File

@@ -5,3 +5,4 @@ const accessControlAllowOrigin = "Access-Control-Allow-Origin"
const basicAuth = "basicAuth"
const jwtAuth = "jwtAuth"
const OAuth = "OAuth"
const serverName = "Goma"