Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions config/sample_xconfwebconfig.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ xconfwebconfig {
// SERVER CONFIGURATION
// =============================
server {
port = 9000 // HTTP server port
port = 9443 // HTTPS server port
https_enabled = true // Enable HTTPS
cert_file = "/etc/ssl/xconf/xconf.crt" // SSL certificate file
key_file = "/etc/ssl/xconf/xconf.key" // SSL private key file
read_timeout_in_secs = 5 // Maximum time to read request (seconds)
write_timeout_in_secs = 50 // Maximum time to write response (seconds)
metrics_enabled = true // Enable Prometheus metrics endpoint (/metrics)
Expand Down Expand Up @@ -270,9 +273,11 @@ xconfwebconfig {
// =============================
http_client {
enable_cert_validation = false // Enable/disable TLS certificate validation
ca_comodo_cert_file = "/etc/testpath/test_cert.crt" // Path to CA certificate file (PEM format)
cert_file = "/etc/testpath/test.pem" // Path to client certificate file (PEM format)
private_key_file = "/etc/testpath/test_client.pem" // Path to client private key file (PEM format)
ca_comodo_cert_file = "/etc/ssl/xconf/xconf.crt" // Path to CA certificate file (PEM format)
key_file = "/etc/ssl/xconf/xconf.key" // SSL private key file
cert_file = "/etc/ssl/xconf/xconf.crt" // Path to client certificate file (PEM format)
key_file = "/etc/ssl/xconf/xconf.key" // SSL private key file
private_key_file = "/etc/ssl/xconf/xconf.key" // Path to client private key file (PEM format)
}

// =============================
Expand Down
32 changes: 24 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,30 @@ func main() {
done <- true
}()

log.Infof("server is starting at %s, port %s", started, server.Addr)
go func() {
// goroutine 2 is running the server
if err := server.ListenAndServe(); err != nil {
log.Errorf("ListenAndServe Error %+v, exiting", err)
}
done <- true
}()
// Check if HTTPS is enabled
httpsEnabled := sc.GetBoolean("xconfwebconfig.server.https_enabled", false)
certFile := sc.GetString("xconfwebconfig.server.cert_file", "")
keyFile := sc.GetString("xconfwebconfig.server.key_file", "")

if httpsEnabled && certFile != "" && keyFile != "" {
log.Infof("server is starting with HTTPS at %s, port %s", started, server.Addr)
go func() {
// goroutine 2 is running the server with HTTPS
if err := server.ListenAndServeTLS(certFile, keyFile); err != nil {
log.Errorf("ListenAndServeTLS Error %+v, exiting", err)
}
done <- true
}()
} else {
log.Infof("server is starting with HTTP at %s, port %s", started, server.Addr)
go func() {
// goroutine 2 is running the server with HTTP
if err := server.ListenAndServe(); err != nil {
log.Errorf("ListenAndServe Error %+v, exiting", err)
}
done <- true
}()
}

// Waiting for either a kill signal or a ListenAndServe error
<-done
Expand Down
Loading