From 37f63434ac982c50fef8d9452d06f890b5d63909 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 17 Oct 2021 15:40:17 +0200 Subject: [PATCH] sort arrays in configuration and API (#644) --- internal/conf/authmethod.go | 11 +++++++---- internal/conf/ipsornets.go | 3 +++ internal/conf/logdestination.go | 3 +++ internal/conf/protocol.go | 3 +++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/conf/authmethod.go b/internal/conf/authmethod.go index 5866fcbc..6c0d2257 100644 --- a/internal/conf/authmethod.go +++ b/internal/conf/authmethod.go @@ -3,6 +3,7 @@ package conf import ( "encoding/json" "fmt" + "sort" "strings" "github.com/aler9/gortsplib/pkg/headers" @@ -13,18 +14,20 @@ type AuthMethods []headers.AuthMethod // MarshalJSON marshals a AuthMethods into JSON. func (d AuthMethods) MarshalJSON() ([]byte, error) { - var out []string + out := make([]string, len(d)) - for _, v := range d { + for i, v := range d { switch v { case headers.AuthBasic: - out = append(out, "basic") + out[i] = "basic" default: - out = append(out, "digest") + out[i] = "digest" } } + sort.Strings(out) + return json.Marshal(out) } diff --git a/internal/conf/ipsornets.go b/internal/conf/ipsornets.go index cf5c5799..81c7df53 100644 --- a/internal/conf/ipsornets.go +++ b/internal/conf/ipsornets.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net" + "sort" "strings" ) @@ -18,6 +19,8 @@ func (d IPsOrNets) MarshalJSON() ([]byte, error) { out[i] = v.(fmt.Stringer).String() } + sort.Strings(out) + return json.Marshal(out) } diff --git a/internal/conf/logdestination.go b/internal/conf/logdestination.go index d324ef0a..5715d667 100644 --- a/internal/conf/logdestination.go +++ b/internal/conf/logdestination.go @@ -3,6 +3,7 @@ package conf import ( "encoding/json" "fmt" + "sort" "strings" "github.com/aler9/rtsp-simple-server/internal/logger" @@ -34,6 +35,8 @@ func (d LogDestinations) MarshalJSON() ([]byte, error) { i++ } + sort.Strings(out) + return json.Marshal(out) } diff --git a/internal/conf/protocol.go b/internal/conf/protocol.go index c09df72c..0843b011 100644 --- a/internal/conf/protocol.go +++ b/internal/conf/protocol.go @@ -3,6 +3,7 @@ package conf import ( "encoding/json" "fmt" + "sort" "strings" ) @@ -42,6 +43,8 @@ func (d Protocols) MarshalJSON() ([]byte, error) { i++ } + sort.Strings(out) + return json.Marshal(out) }