chore: refactroing of code

Commenting code for enhancing readability
This commit is contained in:
Jonas Kaninda
2024-11-19 18:18:58 +01:00
parent c54ae4bd34
commit 1c0097d8e4
15 changed files with 117 additions and 86 deletions

View File

@@ -20,6 +20,7 @@ package pkg
import (
"crypto/tls"
"fmt"
"github.com/jkaninda/goma-gateway/pkg/logger"
)
func (gatewayServer GatewayServer) initTLS() (*tls.Config, bool, error) {
@@ -34,3 +35,19 @@ func (gatewayServer GatewayServer) initTLS() (*tls.Config, bool, error) {
}
return tlsConfig, true, nil
}
// loadTLS loads TLS Certificate
func loadTLS(cert, key string) (*tls.Config, error) {
if cert == "" && key == "" {
return nil, fmt.Errorf("no certificate or key file provided")
}
serverCert, err := tls.LoadX509KeyPair(cert, key)
if err != nil {
logger.Error("Error loading server certificate: %v", err)
return nil, err
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{serverCert},
}
return tlsConfig, nil
}