Browse Source

sort arrays in configuration and API (#644)

pull/666/head
aler9 5 years ago
parent
commit
37f63434ac
  1. 11
      internal/conf/authmethod.go
  2. 3
      internal/conf/ipsornets.go
  3. 3
      internal/conf/logdestination.go
  4. 3
      internal/conf/protocol.go

11
internal/conf/authmethod.go

@ -3,6 +3,7 @@ package conf @@ -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 @@ -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)
}

3
internal/conf/ipsornets.go

@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net"
"sort"
"strings"
)
@ -18,6 +19,8 @@ func (d IPsOrNets) MarshalJSON() ([]byte, error) { @@ -18,6 +19,8 @@ func (d IPsOrNets) MarshalJSON() ([]byte, error) {
out[i] = v.(fmt.Stringer).String()
}
sort.Strings(out)
return json.Marshal(out)
}

3
internal/conf/logdestination.go

@ -3,6 +3,7 @@ package conf @@ -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) { @@ -34,6 +35,8 @@ func (d LogDestinations) MarshalJSON() ([]byte, error) {
i++
}
sort.Strings(out)
return json.Marshal(out)
}

3
internal/conf/protocol.go

@ -3,6 +3,7 @@ package conf @@ -3,6 +3,7 @@ package conf
import (
"encoding/json"
"fmt"
"sort"
"strings"
)
@ -42,6 +43,8 @@ func (d Protocols) MarshalJSON() ([]byte, error) { @@ -42,6 +43,8 @@ func (d Protocols) MarshalJSON() ([]byte, error) {
i++
}
sort.Strings(out)
return json.Marshal(out)
}

Loading…
Cancel
Save