Files
mediamtx/internal/conf/ip_networks.go
T
Alessandro RosandGitHub 75bf1af38c fix clearing lists with environment variables (#5410) (#5924)
MTX_AUTHINTERNALUSERS_0_IPS, MTX_LOGDESTINATIONS and MTX_RTSPTRANSPORTS
can now be used to clear their corresponding list by setting them to an
empty value.
2026-07-18 10:56:46 +02:00

43 lines
911 B
Go

package conf
import (
"encoding/json"
"net"
"strings"
"github.com/bluenviron/mediamtx/internal/conf/jsonwrapper"
)
// IPNetworks is a parameter that contains a list of IP networks.
type IPNetworks []IPNetwork
// UnmarshalEnv implements env.Unmarshaler.
func (d *IPNetworks) UnmarshalEnv(_ string, v string) error {
if v == "" {
*d = []IPNetwork{}
return nil
}
byts, _ := json.Marshal(strings.Split(v, ","))
return jsonwrapper.Unmarshal(byts, d)
}
// ToTrustedProxies converts IPNetworks into a string slice for SetTrustedProxies.
func (d *IPNetworks) ToTrustedProxies() []string {
ret := make([]string, len(*d))
for i, entry := range *d {
ret[i] = entry.String()
}
return ret
}
// Contains checks whether the IP is part of one of the networks.
func (d IPNetworks) Contains(ip net.IP) bool {
for _, network := range d {
if network.Contains(ip) {
return true
}
}
return false
}