From 95405dcc22a51a174f17ae4f49557a46d03f38ae Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:01:45 +0100 Subject: [PATCH] simplify configuration parser --- internal/conf/encryption.go | 5 +---- internal/conf/hls_variant.go | 5 +---- internal/conf/log_destination.go | 5 +---- internal/conf/log_level.go | 5 +---- internal/conf/protocol.go | 5 +---- internal/conf/rtsp_auth_methods.go | 5 +---- internal/conf/rtsp_range_type.go | 5 +---- internal/conf/rtsp_transport.go | 5 +---- 8 files changed, 8 insertions(+), 32 deletions(-) diff --git a/internal/conf/encryption.go b/internal/conf/encryption.go index d7ff4177..039fb009 100644 --- a/internal/conf/encryption.go +++ b/internal/conf/encryption.go @@ -26,11 +26,8 @@ func (d Encryption) MarshalJSON() ([]byte, error) { case EncryptionOptional: out = "optional" - case EncryptionStrict: - out = "strict" - default: - return nil, fmt.Errorf("invalid encryption: %v", d) + out = "strict" } return json.Marshal(out) diff --git a/internal/conf/hls_variant.go b/internal/conf/hls_variant.go index 9d0dfc05..d9f970a4 100644 --- a/internal/conf/hls_variant.go +++ b/internal/conf/hls_variant.go @@ -21,11 +21,8 @@ func (d HLSVariant) MarshalJSON() ([]byte, error) { case HLSVariant(gohlslib.MuxerVariantFMP4): out = "fmp4" - case HLSVariant(gohlslib.MuxerVariantLowLatency): - out = "lowLatency" - default: - return nil, fmt.Errorf("invalid HLS variant: %v", d) + out = "lowLatency" } return json.Marshal(out) diff --git a/internal/conf/log_destination.go b/internal/conf/log_destination.go index cb369f00..29c4c72d 100644 --- a/internal/conf/log_destination.go +++ b/internal/conf/log_destination.go @@ -26,11 +26,8 @@ func (d LogDestinations) MarshalJSON() ([]byte, error) { case logger.DestinationFile: v = "file" - case logger.DestinationSyslog: - v = "syslog" - default: - return nil, fmt.Errorf("invalid log destination: %v", p) + v = "syslog" } out[i] = v diff --git a/internal/conf/log_level.go b/internal/conf/log_level.go index 2231067c..36ff866b 100644 --- a/internal/conf/log_level.go +++ b/internal/conf/log_level.go @@ -24,11 +24,8 @@ func (d LogLevel) MarshalJSON() ([]byte, error) { case LogLevel(logger.Info): out = "info" - case LogLevel(logger.Debug): - out = "debug" - default: - return nil, fmt.Errorf("invalid log level: %v", d) + out = "debug" } return json.Marshal(out) diff --git a/internal/conf/protocol.go b/internal/conf/protocol.go index e2e46c94..74713061 100644 --- a/internal/conf/protocol.go +++ b/internal/conf/protocol.go @@ -30,11 +30,8 @@ func (d Protocols) MarshalJSON() ([]byte, error) { case Protocol(gortsplib.TransportUDPMulticast): v = "multicast" - case Protocol(gortsplib.TransportTCP): - v = "tcp" - default: - return nil, fmt.Errorf("invalid protocol: %v", p) + v = "tcp" } out[i] = v diff --git a/internal/conf/rtsp_auth_methods.go b/internal/conf/rtsp_auth_methods.go index 797fbbaa..c77f9fc3 100644 --- a/internal/conf/rtsp_auth_methods.go +++ b/internal/conf/rtsp_auth_methods.go @@ -21,11 +21,8 @@ func (d RTSPAuthMethods) MarshalJSON() ([]byte, error) { case headers.AuthBasic: out[i] = "basic" - case headers.AuthDigestMD5: - out[i] = "digest" - default: - return nil, fmt.Errorf("invalid authentication method: %v", v) + out[i] = "digest" } } diff --git a/internal/conf/rtsp_range_type.go b/internal/conf/rtsp_range_type.go index 2a6decd2..1760e388 100644 --- a/internal/conf/rtsp_range_type.go +++ b/internal/conf/rtsp_range_type.go @@ -30,11 +30,8 @@ func (d RTSPRangeType) MarshalJSON() ([]byte, error) { case RTSPRangeTypeSMPTE: out = "smpte" - case RTSPRangeTypeUndefined: - out = "" - default: - return nil, fmt.Errorf("invalid rtsp range type: %v", d) + out = "" } return json.Marshal(out) diff --git a/internal/conf/rtsp_transport.go b/internal/conf/rtsp_transport.go index cb49a11c..6cc6b223 100644 --- a/internal/conf/rtsp_transport.go +++ b/internal/conf/rtsp_transport.go @@ -26,11 +26,8 @@ func (d RTSPTransport) MarshalJSON() ([]byte, error) { case gortsplib.TransportUDPMulticast: out = "multicast" - case gortsplib.TransportTCP: - out = "tcp" - default: - return nil, fmt.Errorf("invalid protocol: %v", d.Transport) + out = "tcp" } }