MG-1963 - Remove TCP config from CoAP server (#2139)

Signed-off-by: 1998-felix <felix.gateru@gmail.com>
This commit is contained in:
Felix Gateru
2024-04-11 22:53:59 +03:00
committed by GitHub
parent 76788d3ae2
commit cdf18dc972
+4 -21
View File
@@ -5,7 +5,6 @@ package coap
import (
"context"
"crypto/tls"
"fmt"
"log/slog"
"time"
@@ -44,26 +43,10 @@ func New(ctx context.Context, cancel context.CancelFunc, name string, config ser
func (s *Server) Start() error {
errCh := make(chan error)
s.Logger.Info(fmt.Sprintf("%s service started using http, exposed port %s", s.Name, s.Address))
switch {
case s.Config.CertFile != "" || s.Config.KeyFile != "":
s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s with TLS cert %s and key %s", s.Name, s.Protocol, s.Address, s.Config.CertFile, s.Config.KeyFile))
certificate, err := tls.LoadX509KeyPair(s.Config.CertFile, s.Config.KeyFile)
if err != nil {
return fmt.Errorf("failed to load auth certificates: %w", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{certificate},
}
go func() {
errCh <- gocoap.ListenAndServeTCPTLS("udp", s.Address, tlsConfig, s.handler)
}()
default:
s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s without TLS", s.Name, s.Protocol, s.Address))
go func() {
errCh <- gocoap.ListenAndServe("udp", s.Address, s.handler)
}()
}
s.Logger.Info(fmt.Sprintf("%s service %s server listening at %s without TLS", s.Name, s.Protocol, s.Address))
go func() {
errCh <- gocoap.ListenAndServe("udp", s.Address, s.handler)
}()
select {
case <-s.Ctx.Done():