Skip to content

Commit

Permalink
refactor: update TLS certificate loading function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
arloor committed Jun 15, 2024
1 parent 07212d5 commit f7bee8f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Serve() error {
WriteTimeout: 31 * time.Second, // Set idle timeout
TLSConfig: &tls.Config{
GetCertificate: func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
return load_new_cert_if_need(globalConfig.Cert,globalConfig.PrivKey)
return load_new_cert_if_need(globalConfig.Cert, globalConfig.PrivKey)
},
},
}
Expand All @@ -63,18 +63,18 @@ func Serve() error {
return <-errors
}

func load_new_cert_if_need(cert_file,privkey string) (*tls.Certificate, error) {
func load_new_cert_if_need(cert_file, privkey string) (*tls.Certificate, error) {
now := time.Now()
if ssl_cert == nil || now.Sub(ssl_last_cert_update) > ssl_cert_update_interval {
cert, err := tls.LoadX509KeyPair(cert_file,privkey)
cert, err := tls.LoadX509KeyPair(cert_file, privkey)
if err != nil {
log.Println("Error loading certificate", err)
if ssl_cert != nil {
return ssl_cert, nil
}
return nil, err
} else {
log.Println("Loaded certificate", cert_file,privkey)
log.Println("Loaded certificate", cert_file, privkey)
}
ssl_cert = &cert
ssl_last_cert_update = now
Expand Down

0 comments on commit f7bee8f

Please sign in to comment.