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
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"sort"
"strings" "strings"
"github.com/aler9/gortsplib/pkg/headers" "github.com/aler9/gortsplib/pkg/headers"
@ -13,18 +14,20 @@ type AuthMethods []headers.AuthMethod
// MarshalJSON marshals a AuthMethods into JSON. // MarshalJSON marshals a AuthMethods into JSON.
func (d AuthMethods) MarshalJSON() ([]byte, error) { 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 { switch v {
case headers.AuthBasic: case headers.AuthBasic:
out = append(out, "basic") out[i] = "basic"
default: default:
out = append(out, "digest") out[i] = "digest"
} }
} }
sort.Strings(out)
return json.Marshal(out) return json.Marshal(out)
} }

3
internal/conf/ipsornets.go

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

3
internal/conf/logdestination.go

@ -3,6 +3,7 @@ package conf
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"sort"
"strings" "strings"
"github.com/aler9/rtsp-simple-server/internal/logger" "github.com/aler9/rtsp-simple-server/internal/logger"
@ -34,6 +35,8 @@ func (d LogDestinations) MarshalJSON() ([]byte, error) {
i++ i++
} }
sort.Strings(out)
return json.Marshal(out) return json.Marshal(out)
} }

3
internal/conf/protocol.go

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

Loading…
Cancel
Save