Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #762: Remove calls to log.Fatal #763

Merged
merged 3 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 8 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
"log"
"math/rand"
"net"
Expand Down Expand Up @@ -276,8 +277,7 @@ func loadPrivateKey(filename string) (*rsa.PrivateKey, error) {
// It also detects and sets the ApplicationURI from the URI within the certificate.
func Certificate(cert []byte) Option {
return func(cfg *Config) error {
setCertificate(cert, cfg)
return nil
return setCertificate(cert, cfg)
}
}

Expand All @@ -294,8 +294,7 @@ func CertificateFile(filename string) Option {
if err != nil {
return err
}
setCertificate(cert, cfg)
return nil
return setCertificate(cert, cfg)
}
}

Expand All @@ -316,23 +315,23 @@ func loadCertificate(filename string) ([]byte, error) {
return block.Bytes, nil
}

func setCertificate(cert []byte, cfg *Config) {
func setCertificate(cert []byte, cfg *Config) error {
cfg.sechan.Certificate = cert

// Extract the application URI from the certificate.
x509cert, err := x509.ParseCertificate(cert)
if err != nil {
log.Fatalf("Failed to parse certificate: %s", err)
return
return fmt.Errorf("failed to parse certificate: %s", err)
}
if len(x509cert.URIs) == 0 {
return
return nil
}
appURI := x509cert.URIs[0].String()
if appURI == "" {
return
return nil
}
cfg.session.ClientDescription.ApplicationURI = appURI
return nil
}

// SecurityFromEndpoint sets the server-related security parameters from
Expand Down
15 changes: 12 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ func New(opts ...Option) *Server {
for _, opt := range opts {
opt(cfg)
}
url := ""
if len(cfg.endpoints) == 0 {
log.Fatalf("No endpoints defined!")
log.Printf("No endpoints defined!")
magiconair marked this conversation as resolved.
Show resolved Hide resolved
} else {
url = cfg.endpoints[0]
}

s := &Server{
url: cfg.endpoints[0],
url: url,
cfg: cfg,
cb: newChannelBroker(cfg.logger),
sb: newSessionBroker(cfg.logger),
Expand Down Expand Up @@ -148,7 +152,8 @@ func New(opts ...Option) *Server {
n0, ok := s.namespaces[0].(*NodeNameSpace)
n0.srv = s
if !ok {
log.Fatalf("not a node namespace!")
// this should never happen because we just set namespace 0 to be a node namespace
log.Panic("Namespace 0 is not a node namespace!")
}
s.ImportNodeSet(&nodes)

Expand Down Expand Up @@ -237,6 +242,10 @@ func (s *Server) URLs() []string {
func (s *Server) Start(ctx context.Context) error {
var err error

if len(s.cfg.endpoints) == 0 {
return fmt.Errorf("cannot start server: no endpoints defined")
}

// Register all service handlers
s.initHandlers()

Expand Down
Loading