2022-09-17 19:19:45 +00:00
|
|
|
// Package conf contains the struct that holds the configuration of the software.
|
2020-10-13 22:50:08 +00:00
|
|
|
package conf
|
2020-07-12 11:16:33 +00:00
|
|
|
|
|
|
|
import (
|
2023-05-06 21:00:42 +00:00
|
|
|
"bytes"
|
2021-09-26 13:50:35 +00:00
|
|
|
"encoding/json"
|
2024-01-18 22:28:56 +00:00
|
|
|
"errors"
|
2020-07-12 11:16:33 +00:00
|
|
|
"fmt"
|
2024-03-04 13:20:34 +00:00
|
|
|
"net"
|
2020-07-12 11:16:33 +00:00
|
|
|
"os"
|
2023-10-07 21:32:15 +00:00
|
|
|
"reflect"
|
2022-12-12 10:49:11 +00:00
|
|
|
"sort"
|
2021-12-22 18:13:56 +00:00
|
|
|
"strings"
|
2020-07-12 11:16:33 +00:00
|
|
|
"time"
|
|
|
|
|
2024-10-03 17:38:54 +00:00
|
|
|
"github.com/bluenviron/gohlslib/v2"
|
2023-08-26 16:54:28 +00:00
|
|
|
"github.com/bluenviron/gortsplib/v4"
|
2024-05-15 08:28:12 +00:00
|
|
|
"github.com/bluenviron/gortsplib/v4/pkg/auth"
|
2020-10-13 21:36:27 +00:00
|
|
|
|
2023-05-16 14:14:20 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/conf/decrypt"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/conf/env"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/conf/yaml"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
2020-07-12 11:16:33 +00:00
|
|
|
)
|
|
|
|
|
2024-01-18 22:28:56 +00:00
|
|
|
// ErrPathNotFound is returned when a path is not found.
|
|
|
|
var ErrPathNotFound = errors.New("path not found")
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func sortedKeys(paths map[string]*OptionalPath) []string {
|
2023-05-06 21:00:42 +00:00
|
|
|
ret := make([]string, len(paths))
|
|
|
|
i := 0
|
|
|
|
for name := range paths {
|
|
|
|
ret[i] = name
|
|
|
|
i++
|
2021-01-16 14:42:54 +00:00
|
|
|
}
|
2023-05-06 21:00:42 +00:00
|
|
|
sort.Strings(ret)
|
|
|
|
return ret
|
2021-01-16 14:42:54 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:14:13 +00:00
|
|
|
func firstThatExists(paths []string) string {
|
|
|
|
for _, pa := range paths {
|
|
|
|
_, err := os.Stat(pa)
|
|
|
|
if err == nil {
|
|
|
|
return pa
|
2023-04-01 17:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-16 20:14:13 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2024-05-15 08:28:12 +00:00
|
|
|
func contains(list []auth.ValidateMethod, item auth.ValidateMethod) bool {
|
2023-07-19 11:33:05 +00:00
|
|
|
for _, i := range list {
|
|
|
|
if i == item {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func copyStructFields(dest interface{}, source interface{}) {
|
|
|
|
rvsource := reflect.ValueOf(source).Elem()
|
|
|
|
rvdest := reflect.ValueOf(dest)
|
|
|
|
nf := rvsource.NumField()
|
|
|
|
var zero reflect.Value
|
|
|
|
|
|
|
|
for i := 0; i < nf; i++ {
|
|
|
|
fnew := rvsource.Field(i)
|
|
|
|
f := rvdest.Elem().FieldByName(rvsource.Type().Field(i).Name)
|
|
|
|
if f == zero {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if fnew.Kind() == reflect.Pointer {
|
|
|
|
if !fnew.IsNil() {
|
|
|
|
if f.Kind() == reflect.Ptr {
|
|
|
|
f.Set(fnew)
|
|
|
|
} else {
|
|
|
|
f.Set(fnew.Elem())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
f.Set(fnew)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-04 13:20:34 +00:00
|
|
|
func mustParseCIDR(v string) net.IPNet {
|
|
|
|
_, ne, err := net.ParseCIDR(v)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if ipv4 := ne.IP.To4(); ipv4 != nil {
|
|
|
|
return net.IPNet{IP: ipv4, Mask: ne.Mask[len(ne.Mask)-4 : len(ne.Mask)]}
|
|
|
|
}
|
|
|
|
return *ne
|
|
|
|
}
|
|
|
|
|
2024-06-12 15:38:55 +00:00
|
|
|
func anyPathHasDeprecatedCredentials(pathDefaults Path, paths map[string]*OptionalPath) bool {
|
|
|
|
if pathDefaults.PublishUser != nil ||
|
|
|
|
pathDefaults.PublishPass != nil ||
|
|
|
|
pathDefaults.PublishIPs != nil ||
|
|
|
|
pathDefaults.ReadUser != nil ||
|
|
|
|
pathDefaults.ReadPass != nil ||
|
|
|
|
pathDefaults.ReadIPs != nil {
|
|
|
|
return true
|
|
|
|
}
|
2024-03-06 17:04:08 +00:00
|
|
|
|
2024-03-04 13:20:34 +00:00
|
|
|
for _, pa := range paths {
|
|
|
|
if pa != nil {
|
|
|
|
rva := reflect.ValueOf(pa.Values).Elem()
|
2024-06-12 15:38:55 +00:00
|
|
|
if rva.FieldByName("PublishUser").Interface().(*Credential) != nil ||
|
|
|
|
rva.FieldByName("PublishPass").Interface().(*Credential) != nil ||
|
|
|
|
rva.FieldByName("PublishIPs").Interface().(*IPNetworks) != nil ||
|
|
|
|
rva.FieldByName("ReadUser").Interface().(*Credential) != nil ||
|
|
|
|
rva.FieldByName("ReadPass").Interface().(*Credential) != nil ||
|
|
|
|
rva.FieldByName("ReadIPs").Interface().(*IPNetworks) != nil {
|
2024-03-04 13:20:34 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-06-12 15:38:55 +00:00
|
|
|
var defaultAuthInternalUsers = AuthInternalUsers{
|
|
|
|
{
|
|
|
|
User: "any",
|
|
|
|
Pass: "",
|
|
|
|
Permissions: []AuthInternalUserPermission{
|
|
|
|
{
|
|
|
|
Action: AuthActionPublish,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionRead,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionPlayback,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
User: "any",
|
|
|
|
Pass: "",
|
|
|
|
IPs: IPNetworks{mustParseCIDR("127.0.0.1/32"), mustParseCIDR("::1/128")},
|
|
|
|
Permissions: []AuthInternalUserPermission{
|
|
|
|
{
|
|
|
|
Action: AuthActionAPI,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionMetrics,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionPprof,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-09-26 13:50:35 +00:00
|
|
|
// Conf is a configuration.
|
2024-05-04 08:12:43 +00:00
|
|
|
// WARNING: Avoid using slices directly due to https://github.com/golang/go/issues/21092
|
2021-09-26 13:50:35 +00:00
|
|
|
type Conf struct {
|
2023-08-30 09:24:14 +00:00
|
|
|
// General
|
2024-03-04 13:20:34 +00:00
|
|
|
LogLevel LogLevel `json:"logLevel"`
|
|
|
|
LogDestinations LogDestinations `json:"logDestinations"`
|
|
|
|
LogFile string `json:"logFile"`
|
|
|
|
ReadTimeout StringDuration `json:"readTimeout"`
|
|
|
|
WriteTimeout StringDuration `json:"writeTimeout"`
|
|
|
|
ReadBufferCount *int `json:"readBufferCount,omitempty"` // deprecated
|
|
|
|
WriteQueueSize int `json:"writeQueueSize"`
|
|
|
|
UDPMaxPayloadSize int `json:"udpMaxPayloadSize"`
|
|
|
|
RunOnConnect string `json:"runOnConnect"`
|
|
|
|
RunOnConnectRestart bool `json:"runOnConnectRestart"`
|
|
|
|
RunOnDisconnect string `json:"runOnDisconnect"`
|
|
|
|
|
|
|
|
// Authentication
|
2024-05-04 08:12:43 +00:00
|
|
|
AuthMethod AuthMethod `json:"authMethod"`
|
|
|
|
AuthInternalUsers AuthInternalUsers `json:"authInternalUsers"`
|
|
|
|
AuthHTTPAddress string `json:"authHTTPAddress"`
|
|
|
|
ExternalAuthenticationURL *string `json:"externalAuthenticationURL,omitempty"` // deprecated
|
|
|
|
AuthHTTPExclude AuthInternalUserPermissions `json:"authHTTPExclude"`
|
|
|
|
AuthJWTJWKS string `json:"authJWTJWKS"`
|
2024-08-26 10:43:28 +00:00
|
|
|
AuthJWTClaimKey string `json:"authJWTClaimKey"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
2024-04-21 15:10:35 +00:00
|
|
|
// Control API
|
|
|
|
API bool `json:"api"`
|
|
|
|
APIAddress string `json:"apiAddress"`
|
|
|
|
APIEncryption bool `json:"apiEncryption"`
|
|
|
|
APIServerKey string `json:"apiServerKey"`
|
|
|
|
APIServerCert string `json:"apiServerCert"`
|
|
|
|
APIAllowOrigin string `json:"apiAllowOrigin"`
|
|
|
|
APITrustedProxies IPNetworks `json:"apiTrustedProxies"`
|
|
|
|
|
|
|
|
// Metrics
|
|
|
|
Metrics bool `json:"metrics"`
|
|
|
|
MetricsAddress string `json:"metricsAddress"`
|
|
|
|
MetricsEncryption bool `json:"metricsEncryption"`
|
|
|
|
MetricsServerKey string `json:"metricsServerKey"`
|
|
|
|
MetricsServerCert string `json:"metricsServerCert"`
|
|
|
|
MetricsAllowOrigin string `json:"metricsAllowOrigin"`
|
|
|
|
MetricsTrustedProxies IPNetworks `json:"metricsTrustedProxies"`
|
|
|
|
|
|
|
|
// PPROF
|
|
|
|
PPROF bool `json:"pprof"`
|
|
|
|
PPROFAddress string `json:"pprofAddress"`
|
|
|
|
PPROFEncryption bool `json:"pprofEncryption"`
|
|
|
|
PPROFServerKey string `json:"pprofServerKey"`
|
|
|
|
PPROFServerCert string `json:"pprofServerCert"`
|
|
|
|
PPROFAllowOrigin string `json:"pprofAllowOrigin"`
|
|
|
|
PPROFTrustedProxies IPNetworks `json:"pprofTrustedProxies"`
|
2024-01-23 19:52:05 +00:00
|
|
|
|
|
|
|
// Playback
|
2024-04-21 15:10:35 +00:00
|
|
|
Playback bool `json:"playback"`
|
|
|
|
PlaybackAddress string `json:"playbackAddress"`
|
|
|
|
PlaybackEncryption bool `json:"playbackEncryption"`
|
|
|
|
PlaybackServerKey string `json:"playbackServerKey"`
|
|
|
|
PlaybackServerCert string `json:"playbackServerCert"`
|
|
|
|
PlaybackAllowOrigin string `json:"playbackAllowOrigin"`
|
|
|
|
PlaybackTrustedProxies IPNetworks `json:"playbackTrustedProxies"`
|
2024-01-23 19:52:05 +00:00
|
|
|
|
2023-11-16 21:47:01 +00:00
|
|
|
// RTSP server
|
2024-03-04 13:20:34 +00:00
|
|
|
RTSP bool `json:"rtsp"`
|
|
|
|
RTSPDisable *bool `json:"rtspDisable,omitempty"` // deprecated
|
|
|
|
Protocols Protocols `json:"protocols"`
|
|
|
|
Encryption Encryption `json:"encryption"`
|
|
|
|
RTSPAddress string `json:"rtspAddress"`
|
|
|
|
RTSPSAddress string `json:"rtspsAddress"`
|
|
|
|
RTPAddress string `json:"rtpAddress"`
|
|
|
|
RTCPAddress string `json:"rtcpAddress"`
|
|
|
|
MulticastIPRange string `json:"multicastIPRange"`
|
|
|
|
MulticastRTPPort int `json:"multicastRTPPort"`
|
|
|
|
MulticastRTCPPort int `json:"multicastRTCPPort"`
|
|
|
|
ServerKey string `json:"serverKey"`
|
|
|
|
ServerCert string `json:"serverCert"`
|
|
|
|
AuthMethods *RTSPAuthMethods `json:"authMethods,omitempty"` // deprecated
|
|
|
|
RTSPAuthMethods RTSPAuthMethods `json:"rtspAuthMethods"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
2023-11-16 21:47:01 +00:00
|
|
|
// RTMP server
|
2023-08-06 19:40:08 +00:00
|
|
|
RTMP bool `json:"rtmp"`
|
2023-10-07 21:32:15 +00:00
|
|
|
RTMPDisable *bool `json:"rtmpDisable,omitempty"` // deprecated
|
2022-08-16 11:53:04 +00:00
|
|
|
RTMPAddress string `json:"rtmpAddress"`
|
|
|
|
RTMPEncryption Encryption `json:"rtmpEncryption"`
|
|
|
|
RTMPSAddress string `json:"rtmpsAddress"`
|
|
|
|
RTMPServerKey string `json:"rtmpServerKey"`
|
|
|
|
RTMPServerCert string `json:"rtmpServerCert"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
2023-11-16 21:47:01 +00:00
|
|
|
// HLS server
|
2023-08-06 19:40:08 +00:00
|
|
|
HLS bool `json:"hls"`
|
2024-04-08 07:29:42 +00:00
|
|
|
HLSDisable *bool `json:"hlsDisable,omitempty"` // deprecated
|
2021-09-26 13:50:35 +00:00
|
|
|
HLSAddress string `json:"hlsAddress"`
|
2022-12-15 23:50:47 +00:00
|
|
|
HLSEncryption bool `json:"hlsEncryption"`
|
|
|
|
HLSServerKey string `json:"hlsServerKey"`
|
|
|
|
HLSServerCert string `json:"hlsServerCert"`
|
2024-04-21 15:10:35 +00:00
|
|
|
HLSAllowOrigin string `json:"hlsAllowOrigin"`
|
|
|
|
HLSTrustedProxies IPNetworks `json:"hlsTrustedProxies"`
|
2021-09-26 13:50:35 +00:00
|
|
|
HLSAlwaysRemux bool `json:"hlsAlwaysRemux"`
|
2022-05-31 17:17:26 +00:00
|
|
|
HLSVariant HLSVariant `json:"hlsVariant"`
|
2021-09-26 13:50:35 +00:00
|
|
|
HLSSegmentCount int `json:"hlsSegmentCount"`
|
|
|
|
HLSSegmentDuration StringDuration `json:"hlsSegmentDuration"`
|
2022-05-31 17:17:26 +00:00
|
|
|
HLSPartDuration StringDuration `json:"hlsPartDuration"`
|
2022-01-29 15:10:08 +00:00
|
|
|
HLSSegmentMaxSize StringSize `json:"hlsSegmentMaxSize"`
|
2023-03-19 23:22:21 +00:00
|
|
|
HLSDirectory string `json:"hlsDirectory"`
|
2024-05-09 08:08:15 +00:00
|
|
|
HLSMuxerCloseAfter StringDuration `json:"hlsMuxerCloseAfter"`
|
2021-09-26 13:50:35 +00:00
|
|
|
|
2023-11-16 21:47:01 +00:00
|
|
|
// WebRTC server
|
2024-05-04 08:12:43 +00:00
|
|
|
WebRTC bool `json:"webrtc"`
|
|
|
|
WebRTCDisable *bool `json:"webrtcDisable,omitempty"` // deprecated
|
|
|
|
WebRTCAddress string `json:"webrtcAddress"`
|
|
|
|
WebRTCEncryption bool `json:"webrtcEncryption"`
|
|
|
|
WebRTCServerKey string `json:"webrtcServerKey"`
|
|
|
|
WebRTCServerCert string `json:"webrtcServerCert"`
|
|
|
|
WebRTCAllowOrigin string `json:"webrtcAllowOrigin"`
|
|
|
|
WebRTCTrustedProxies IPNetworks `json:"webrtcTrustedProxies"`
|
|
|
|
WebRTCLocalUDPAddress string `json:"webrtcLocalUDPAddress"`
|
|
|
|
WebRTCLocalTCPAddress string `json:"webrtcLocalTCPAddress"`
|
|
|
|
WebRTCIPsFromInterfaces bool `json:"webrtcIPsFromInterfaces"`
|
|
|
|
WebRTCIPsFromInterfacesList []string `json:"webrtcIPsFromInterfacesList"`
|
|
|
|
WebRTCAdditionalHosts []string `json:"webrtcAdditionalHosts"`
|
|
|
|
WebRTCICEServers2 WebRTCICEServers `json:"webrtcICEServers2"`
|
2024-05-30 11:36:58 +00:00
|
|
|
WebRTCHandshakeTimeout StringDuration `json:"webrtcHandshakeTimeout"`
|
|
|
|
WebRTCTrackGatherTimeout StringDuration `json:"webrtcTrackGatherTimeout"`
|
2024-05-04 08:12:43 +00:00
|
|
|
WebRTCICEUDPMuxAddress *string `json:"webrtcICEUDPMuxAddress,omitempty"` // deprecated
|
|
|
|
WebRTCICETCPMuxAddress *string `json:"webrtcICETCPMuxAddress,omitempty"` // deprecated
|
|
|
|
WebRTCICEHostNAT1To1IPs *[]string `json:"webrtcICEHostNAT1To1IPs,omitempty"` // deprecated
|
|
|
|
WebRTCICEServers *[]string `json:"webrtcICEServers,omitempty"` // deprecated
|
2022-12-15 23:50:47 +00:00
|
|
|
|
2023-11-16 21:47:01 +00:00
|
|
|
// SRT server
|
2023-07-31 19:20:09 +00:00
|
|
|
SRT bool `json:"srt"`
|
|
|
|
SRTAddress string `json:"srtAddress"`
|
|
|
|
|
2023-11-16 21:47:01 +00:00
|
|
|
// Record (deprecated)
|
2023-10-07 21:48:37 +00:00
|
|
|
Record *bool `json:"record,omitempty"` // deprecated
|
|
|
|
RecordPath *string `json:"recordPath,omitempty"` // deprecated
|
2023-10-14 20:52:10 +00:00
|
|
|
RecordFormat *RecordFormat `json:"recordFormat,omitempty"` // deprecated
|
2023-10-07 21:48:37 +00:00
|
|
|
RecordPartDuration *StringDuration `json:"recordPartDuration,omitempty"` // deprecated
|
|
|
|
RecordSegmentDuration *StringDuration `json:"recordSegmentDuration,omitempty"` // deprecated
|
|
|
|
RecordDeleteAfter *StringDuration `json:"recordDeleteAfter,omitempty"` // deprecated
|
2023-09-16 15:27:07 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
// Path defaults
|
|
|
|
PathDefaults Path `json:"pathDefaults"`
|
|
|
|
|
2023-08-30 09:24:14 +00:00
|
|
|
// Paths
|
2023-10-07 21:32:15 +00:00
|
|
|
OptionalPaths map[string]*OptionalPath `json:"paths"`
|
2023-10-28 09:52:31 +00:00
|
|
|
Paths map[string]*Path `json:"-"` // filled by Check()
|
2023-10-07 21:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (conf *Conf) setDefaults() {
|
|
|
|
// General
|
|
|
|
conf.LogLevel = LogLevel(logger.Info)
|
|
|
|
conf.LogDestinations = LogDestinations{logger.DestinationStdout}
|
|
|
|
conf.LogFile = "mediamtx.log"
|
|
|
|
conf.ReadTimeout = 10 * StringDuration(time.Second)
|
|
|
|
conf.WriteTimeout = 10 * StringDuration(time.Second)
|
|
|
|
conf.WriteQueueSize = 512
|
|
|
|
conf.UDPMaxPayloadSize = 1472
|
2024-03-04 13:20:34 +00:00
|
|
|
|
|
|
|
// Authentication
|
2024-06-12 15:38:55 +00:00
|
|
|
conf.AuthInternalUsers = defaultAuthInternalUsers
|
2024-03-04 13:20:34 +00:00
|
|
|
conf.AuthHTTPExclude = []AuthInternalUserPermission{
|
|
|
|
{
|
|
|
|
Action: AuthActionAPI,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionMetrics,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionPprof,
|
|
|
|
},
|
|
|
|
}
|
2024-08-26 10:43:28 +00:00
|
|
|
conf.AuthJWTClaimKey = "mediamtx_permissions"
|
2023-10-07 21:32:15 +00:00
|
|
|
|
2024-04-21 15:10:35 +00:00
|
|
|
// Control API
|
2024-03-04 13:20:34 +00:00
|
|
|
conf.APIAddress = ":9997"
|
2024-04-21 15:10:35 +00:00
|
|
|
conf.APIServerKey = "server.key"
|
|
|
|
conf.APIServerCert = "server.crt"
|
|
|
|
conf.APIAllowOrigin = "*"
|
|
|
|
|
|
|
|
// Metrics
|
|
|
|
conf.MetricsAddress = ":9998"
|
|
|
|
conf.MetricsServerKey = "server.key"
|
|
|
|
conf.MetricsServerCert = "server.crt"
|
|
|
|
conf.MetricsAllowOrigin = "*"
|
|
|
|
|
|
|
|
// PPROF
|
|
|
|
conf.PPROFAddress = ":9999"
|
|
|
|
conf.PPROFServerKey = "server.key"
|
|
|
|
conf.PPROFServerCert = "server.crt"
|
|
|
|
conf.PPROFAllowOrigin = "*"
|
2024-01-23 19:52:05 +00:00
|
|
|
|
|
|
|
// Playback server
|
|
|
|
conf.PlaybackAddress = ":9996"
|
2024-04-21 15:10:35 +00:00
|
|
|
conf.PlaybackServerKey = "server.key"
|
|
|
|
conf.PlaybackServerCert = "server.crt"
|
|
|
|
conf.PlaybackAllowOrigin = "*"
|
2024-01-23 19:52:05 +00:00
|
|
|
|
|
|
|
// RTSP server
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.RTSP = true
|
|
|
|
conf.Protocols = Protocols{
|
|
|
|
Protocol(gortsplib.TransportUDP): {},
|
|
|
|
Protocol(gortsplib.TransportUDPMulticast): {},
|
|
|
|
Protocol(gortsplib.TransportTCP): {},
|
|
|
|
}
|
|
|
|
conf.RTSPAddress = ":8554"
|
|
|
|
conf.RTSPSAddress = ":8322"
|
|
|
|
conf.RTPAddress = ":8000"
|
|
|
|
conf.RTCPAddress = ":8001"
|
|
|
|
conf.MulticastIPRange = "224.1.0.0/16"
|
|
|
|
conf.MulticastRTPPort = 8002
|
|
|
|
conf.MulticastRTCPPort = 8003
|
|
|
|
conf.ServerKey = "server.key"
|
|
|
|
conf.ServerCert = "server.crt"
|
2024-05-15 08:28:12 +00:00
|
|
|
conf.RTSPAuthMethods = RTSPAuthMethods{auth.ValidateMethodBasic}
|
2023-10-07 21:32:15 +00:00
|
|
|
|
2024-01-23 19:52:05 +00:00
|
|
|
// RTMP server
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.RTMP = true
|
|
|
|
conf.RTMPAddress = ":1935"
|
|
|
|
conf.RTMPSAddress = ":1936"
|
|
|
|
conf.RTMPServerKey = "server.key"
|
|
|
|
conf.RTMPServerCert = "server.crt"
|
|
|
|
|
|
|
|
// HLS
|
|
|
|
conf.HLS = true
|
|
|
|
conf.HLSAddress = ":8888"
|
|
|
|
conf.HLSServerKey = "server.key"
|
|
|
|
conf.HLSServerCert = "server.crt"
|
2024-04-21 15:10:35 +00:00
|
|
|
conf.HLSAllowOrigin = "*"
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.HLSVariant = HLSVariant(gohlslib.MuxerVariantLowLatency)
|
|
|
|
conf.HLSSegmentCount = 7
|
|
|
|
conf.HLSSegmentDuration = 1 * StringDuration(time.Second)
|
|
|
|
conf.HLSPartDuration = 200 * StringDuration(time.Millisecond)
|
|
|
|
conf.HLSSegmentMaxSize = 50 * 1024 * 1024
|
2024-05-09 08:08:15 +00:00
|
|
|
conf.HLSMuxerCloseAfter = 60 * StringDuration(time.Second)
|
2023-10-07 21:32:15 +00:00
|
|
|
|
2024-01-23 19:52:05 +00:00
|
|
|
// WebRTC server
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.WebRTC = true
|
|
|
|
conf.WebRTCAddress = ":8889"
|
|
|
|
conf.WebRTCServerKey = "server.key"
|
|
|
|
conf.WebRTCServerCert = "server.crt"
|
|
|
|
conf.WebRTCAllowOrigin = "*"
|
2023-11-12 22:55:28 +00:00
|
|
|
conf.WebRTCLocalUDPAddress = ":8189"
|
|
|
|
conf.WebRTCIPsFromInterfaces = true
|
|
|
|
conf.WebRTCIPsFromInterfacesList = []string{}
|
|
|
|
conf.WebRTCAdditionalHosts = []string{}
|
|
|
|
conf.WebRTCICEServers2 = []WebRTCICEServer{}
|
2024-05-30 11:36:58 +00:00
|
|
|
conf.WebRTCHandshakeTimeout = 10 * StringDuration(time.Second)
|
|
|
|
conf.WebRTCTrackGatherTimeout = 2 * StringDuration(time.Second)
|
2023-10-07 21:32:15 +00:00
|
|
|
|
2024-01-23 19:52:05 +00:00
|
|
|
// SRT server
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.SRT = true
|
|
|
|
conf.SRTAddress = ":8890"
|
|
|
|
|
|
|
|
conf.PathDefaults.setDefaults()
|
2021-09-26 13:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load loads a Conf.
|
2023-09-16 20:14:13 +00:00
|
|
|
func Load(fpath string, defaultConfPaths []string) (*Conf, string, error) {
|
2021-09-26 13:50:35 +00:00
|
|
|
conf := &Conf{}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
fpath, err := conf.loadFromFile(fpath, defaultConfPaths)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-16 20:14:13 +00:00
|
|
|
return nil, "", err
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 21:00:42 +00:00
|
|
|
err = env.Load("RTSP", conf) // legacy prefix
|
2023-04-01 17:31:23 +00:00
|
|
|
if err != nil {
|
2023-09-16 20:14:13 +00:00
|
|
|
return nil, "", err
|
2023-04-01 17:31:23 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 21:00:42 +00:00
|
|
|
err = env.Load("MTX", conf)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-16 20:14:13 +00:00
|
|
|
return nil, "", err
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2024-01-23 19:52:05 +00:00
|
|
|
err = conf.Validate()
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-16 20:14:13 +00:00
|
|
|
return nil, "", err
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2023-09-16 20:14:13 +00:00
|
|
|
return conf, fpath, nil
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func (conf *Conf) loadFromFile(fpath string, defaultConfPaths []string) (string, error) {
|
|
|
|
if fpath == "" {
|
|
|
|
fpath = firstThatExists(defaultConfPaths)
|
|
|
|
|
|
|
|
// when the configuration file is not explicitly set,
|
|
|
|
// it is optional.
|
|
|
|
if fpath == "" {
|
|
|
|
conf.setDefaults()
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
byts, err := os.ReadFile(fpath)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if key, ok := os.LookupEnv("RTSP_CONFKEY"); ok { // legacy format
|
|
|
|
byts, err = decrypt.Decrypt(key, byts)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if key, ok := os.LookupEnv("MTX_CONFKEY"); ok {
|
|
|
|
byts, err = decrypt.Decrypt(key, byts)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = yaml.Load(byts, conf)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return fpath, nil
|
|
|
|
}
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
// Clone clones the configuration.
|
|
|
|
func (conf Conf) Clone() *Conf {
|
|
|
|
enc, err := json.Marshal(conf)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var dest Conf
|
|
|
|
err = json.Unmarshal(enc, &dest)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &dest
|
|
|
|
}
|
|
|
|
|
2024-01-23 19:52:05 +00:00
|
|
|
// Validate checks the configuration for errors.
|
|
|
|
func (conf *Conf) Validate() error {
|
2023-08-30 09:24:14 +00:00
|
|
|
// General
|
|
|
|
|
2024-09-09 10:36:53 +00:00
|
|
|
if conf.ReadTimeout <= 0 {
|
|
|
|
return fmt.Errorf("'readTimeout' must be greater than zero")
|
|
|
|
}
|
|
|
|
if conf.WriteTimeout <= 0 {
|
|
|
|
return fmt.Errorf("'writeTimeout' must be greater than zero")
|
|
|
|
}
|
2023-10-07 21:32:15 +00:00
|
|
|
if conf.ReadBufferCount != nil {
|
|
|
|
conf.WriteQueueSize = *conf.ReadBufferCount
|
2023-08-26 11:25:21 +00:00
|
|
|
}
|
|
|
|
if (conf.WriteQueueSize & (conf.WriteQueueSize - 1)) != 0 {
|
|
|
|
return fmt.Errorf("'writeQueueSize' must be a power of two")
|
2023-03-31 09:53:49 +00:00
|
|
|
}
|
2023-04-15 11:45:20 +00:00
|
|
|
if conf.UDPMaxPayloadSize > 1472 {
|
|
|
|
return fmt.Errorf("'udpMaxPayloadSize' must be less than 1472")
|
2022-07-05 21:45:57 +00:00
|
|
|
}
|
2024-03-04 13:20:34 +00:00
|
|
|
|
|
|
|
// Authentication
|
2024-09-09 10:36:53 +00:00
|
|
|
|
2024-03-04 13:20:34 +00:00
|
|
|
if conf.ExternalAuthenticationURL != nil {
|
|
|
|
conf.AuthMethod = AuthMethodHTTP
|
|
|
|
conf.AuthHTTPAddress = *conf.ExternalAuthenticationURL
|
|
|
|
}
|
|
|
|
if conf.AuthHTTPAddress != "" &&
|
|
|
|
!strings.HasPrefix(conf.AuthHTTPAddress, "http://") &&
|
|
|
|
!strings.HasPrefix(conf.AuthHTTPAddress, "https://") {
|
|
|
|
return fmt.Errorf("'externalAuthenticationURL' must be a HTTP URL")
|
|
|
|
}
|
|
|
|
if conf.AuthJWTJWKS != "" &&
|
|
|
|
!strings.HasPrefix(conf.AuthJWTJWKS, "http://") &&
|
|
|
|
!strings.HasPrefix(conf.AuthJWTJWKS, "https://") {
|
|
|
|
return fmt.Errorf("'authJWTJWKS' must be a HTTP URL")
|
|
|
|
}
|
|
|
|
deprecatedCredentialsMode := false
|
2024-06-12 15:38:55 +00:00
|
|
|
if anyPathHasDeprecatedCredentials(conf.PathDefaults, conf.OptionalPaths) {
|
|
|
|
if conf.AuthInternalUsers != nil && !reflect.DeepEqual(conf.AuthInternalUsers, defaultAuthInternalUsers) {
|
|
|
|
return fmt.Errorf("authInternalUsers and legacy credentials " +
|
|
|
|
"(publishUser, publishPass, publishIPs, readUser, readPass, readIPs) cannot be used together")
|
|
|
|
}
|
|
|
|
|
2024-03-04 13:20:34 +00:00
|
|
|
conf.AuthInternalUsers = []AuthInternalUser{
|
|
|
|
{
|
|
|
|
User: "any",
|
|
|
|
Permissions: []AuthInternalUserPermission{
|
|
|
|
{
|
|
|
|
Action: AuthActionPlayback,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
User: "any",
|
|
|
|
IPs: IPNetworks{mustParseCIDR("127.0.0.1/32"), mustParseCIDR("::1/128")},
|
|
|
|
Permissions: []AuthInternalUserPermission{
|
|
|
|
{
|
|
|
|
Action: AuthActionAPI,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionMetrics,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Action: AuthActionPprof,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
deprecatedCredentialsMode = true
|
|
|
|
}
|
|
|
|
switch conf.AuthMethod {
|
|
|
|
case AuthMethodHTTP:
|
|
|
|
if conf.AuthHTTPAddress == "" {
|
|
|
|
return fmt.Errorf("'authHTTPAddress' is empty")
|
2021-12-22 18:13:56 +00:00
|
|
|
}
|
2023-05-08 15:04:14 +00:00
|
|
|
|
2024-03-04 13:20:34 +00:00
|
|
|
case AuthMethodJWT:
|
|
|
|
if conf.AuthJWTJWKS == "" {
|
|
|
|
return fmt.Errorf("'authJWTJWKS' is empty")
|
2023-05-08 15:04:14 +00:00
|
|
|
}
|
2024-08-26 10:43:28 +00:00
|
|
|
if conf.AuthJWTClaimKey == "" {
|
|
|
|
return fmt.Errorf("'authJWTClaimKey' is empty")
|
|
|
|
}
|
2021-12-22 18:13:56 +00:00
|
|
|
}
|
2021-03-27 10:21:30 +00:00
|
|
|
|
2022-12-15 23:50:47 +00:00
|
|
|
// RTSP
|
2023-08-30 09:24:14 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
if conf.RTSPDisable != nil {
|
|
|
|
conf.RTSP = !*conf.RTSPDisable
|
2023-08-06 19:40:08 +00:00
|
|
|
}
|
2021-09-27 08:36:28 +00:00
|
|
|
if conf.Encryption == EncryptionStrict {
|
2021-10-22 16:41:10 +00:00
|
|
|
if _, ok := conf.Protocols[Protocol(gortsplib.TransportUDP)]; ok {
|
2021-11-05 16:11:40 +00:00
|
|
|
return fmt.Errorf("strict encryption can't be used with the UDP transport protocol")
|
|
|
|
}
|
|
|
|
if _, ok := conf.Protocols[Protocol(gortsplib.TransportUDPMulticast)]; ok {
|
|
|
|
return fmt.Errorf("strict encryption can't be used with the UDP-multicast transport protocol")
|
2020-12-13 22:43:31 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-04 13:20:34 +00:00
|
|
|
if conf.AuthMethods != nil {
|
|
|
|
conf.RTSPAuthMethods = *conf.AuthMethods
|
|
|
|
}
|
2024-05-15 08:28:12 +00:00
|
|
|
if contains(conf.RTSPAuthMethods, auth.ValidateMethodDigestMD5) {
|
2024-03-04 13:20:34 +00:00
|
|
|
if conf.AuthMethod != AuthMethodInternal {
|
|
|
|
return fmt.Errorf("when RTSP digest is enabled, the only supported auth method is 'internal'")
|
|
|
|
}
|
|
|
|
for _, user := range conf.AuthInternalUsers {
|
|
|
|
if user.User.IsHashed() || user.Pass.IsHashed() {
|
|
|
|
return fmt.Errorf("when RTSP digest is enabled, hashed credentials cannot be used")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-15 23:50:47 +00:00
|
|
|
|
2023-08-06 19:40:08 +00:00
|
|
|
// RTMP
|
2023-08-30 09:24:14 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
if conf.RTMPDisable != nil {
|
|
|
|
conf.RTMP = !*conf.RTMPDisable
|
2023-08-06 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HLS
|
2023-08-30 09:24:14 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
if conf.HLSDisable != nil {
|
|
|
|
conf.HLS = !*conf.HLSDisable
|
2023-08-06 19:40:08 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 08:51:00 +00:00
|
|
|
// WebRTC
|
2023-08-30 09:24:14 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
if conf.WebRTCDisable != nil {
|
|
|
|
conf.WebRTC = !*conf.WebRTCDisable
|
|
|
|
}
|
2023-11-12 22:55:28 +00:00
|
|
|
if conf.WebRTCICEUDPMuxAddress != nil {
|
|
|
|
conf.WebRTCLocalUDPAddress = *conf.WebRTCICEUDPMuxAddress
|
|
|
|
}
|
|
|
|
if conf.WebRTCICETCPMuxAddress != nil {
|
|
|
|
conf.WebRTCLocalTCPAddress = *conf.WebRTCICETCPMuxAddress
|
|
|
|
}
|
|
|
|
if conf.WebRTCICEHostNAT1To1IPs != nil {
|
|
|
|
conf.WebRTCAdditionalHosts = *conf.WebRTCICEHostNAT1To1IPs
|
|
|
|
}
|
2023-10-07 21:32:15 +00:00
|
|
|
if conf.WebRTCICEServers != nil {
|
|
|
|
for _, server := range *conf.WebRTCICEServers {
|
|
|
|
parts := strings.Split(server, ":")
|
|
|
|
if len(parts) == 5 {
|
|
|
|
conf.WebRTCICEServers2 = append(conf.WebRTCICEServers2, WebRTCICEServer{
|
|
|
|
URL: parts[0] + ":" + parts[3] + ":" + parts[4],
|
|
|
|
Username: parts[1],
|
|
|
|
Password: parts[2],
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
conf.WebRTCICEServers2 = append(conf.WebRTCICEServers2, WebRTCICEServer{
|
|
|
|
URL: server,
|
|
|
|
})
|
|
|
|
}
|
2023-06-30 14:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, server := range conf.WebRTCICEServers2 {
|
|
|
|
if !strings.HasPrefix(server.URL, "stun:") &&
|
|
|
|
!strings.HasPrefix(server.URL, "turn:") &&
|
|
|
|
!strings.HasPrefix(server.URL, "turns:") {
|
|
|
|
return fmt.Errorf("invalid ICE server: '%s'", server.URL)
|
2023-05-15 08:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-12 22:55:28 +00:00
|
|
|
if conf.WebRTCLocalUDPAddress == "" &&
|
|
|
|
conf.WebRTCLocalTCPAddress == "" &&
|
|
|
|
len(conf.WebRTCICEServers2) == 0 {
|
|
|
|
return fmt.Errorf("at least one between 'webrtcLocalUDPAddress'," +
|
|
|
|
" 'webrtcLocalTCPAddress' or 'webrtcICEServers2' must be filled")
|
|
|
|
}
|
|
|
|
if conf.WebRTCLocalUDPAddress != "" || conf.WebRTCLocalTCPAddress != "" {
|
|
|
|
if !conf.WebRTCIPsFromInterfaces && len(conf.WebRTCAdditionalHosts) == 0 {
|
|
|
|
return fmt.Errorf("at least one between 'webrtcIPsFromInterfaces' or 'webrtcAdditionalHosts' must be filled")
|
|
|
|
}
|
|
|
|
}
|
2023-05-15 08:51:00 +00:00
|
|
|
|
2024-01-23 19:52:05 +00:00
|
|
|
// Record (deprecated)
|
2024-09-09 10:36:53 +00:00
|
|
|
|
2023-10-07 21:48:37 +00:00
|
|
|
if conf.Record != nil {
|
|
|
|
conf.PathDefaults.Record = *conf.Record
|
|
|
|
}
|
|
|
|
if conf.RecordPath != nil {
|
|
|
|
conf.PathDefaults.RecordPath = *conf.RecordPath
|
|
|
|
}
|
|
|
|
if conf.RecordFormat != nil {
|
|
|
|
conf.PathDefaults.RecordFormat = *conf.RecordFormat
|
|
|
|
}
|
|
|
|
if conf.RecordPartDuration != nil {
|
|
|
|
conf.PathDefaults.RecordPartDuration = *conf.RecordPartDuration
|
|
|
|
}
|
|
|
|
if conf.RecordSegmentDuration != nil {
|
|
|
|
conf.PathDefaults.RecordSegmentDuration = *conf.RecordSegmentDuration
|
|
|
|
}
|
|
|
|
if conf.RecordDeleteAfter != nil {
|
|
|
|
conf.PathDefaults.RecordDeleteAfter = *conf.RecordDeleteAfter
|
2023-09-16 15:27:07 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 16:13:44 +00:00
|
|
|
hasAllOthers := false
|
|
|
|
for name := range conf.OptionalPaths {
|
|
|
|
if name == "all" || name == "all_others" || name == "~^.*$" {
|
|
|
|
if hasAllOthers {
|
|
|
|
return fmt.Errorf("all_others, all and '~^.*$' are aliases")
|
|
|
|
}
|
|
|
|
hasAllOthers = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.Paths = make(map[string]*Path)
|
2020-07-12 11:16:33 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
for _, name := range sortedKeys(conf.OptionalPaths) {
|
|
|
|
optional := conf.OptionalPaths[name]
|
|
|
|
if optional == nil {
|
|
|
|
optional = &OptionalPath{
|
|
|
|
Values: newOptionalPathValues(),
|
|
|
|
}
|
2024-04-17 22:23:39 +00:00
|
|
|
conf.OptionalPaths[name] = optional
|
2020-07-13 09:51:17 +00:00
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
pconf := newPath(&conf.PathDefaults, optional)
|
|
|
|
conf.Paths[name] = pconf
|
|
|
|
|
2024-03-04 13:20:34 +00:00
|
|
|
err := pconf.validate(conf, name, deprecatedCredentialsMode)
|
2020-10-24 17:55:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-07-12 11:16:33 +00:00
|
|
|
}
|
2020-10-24 17:55:47 +00:00
|
|
|
}
|
2020-07-12 11:16:33 +00:00
|
|
|
|
2020-10-24 17:55:47 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-05-06 21:00:42 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
// UnmarshalJSON implements json.Unmarshaler.
|
2023-05-06 21:00:42 +00:00
|
|
|
func (conf *Conf) UnmarshalJSON(b []byte) error {
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.setDefaults()
|
2023-05-06 21:00:42 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
type alias Conf
|
|
|
|
d := json.NewDecoder(bytes.NewReader(b))
|
|
|
|
d.DisallowUnknownFields()
|
|
|
|
return d.Decode((*alias)(conf))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Global returns the global part of Conf.
|
|
|
|
func (conf *Conf) Global() *Global {
|
|
|
|
g := &Global{
|
|
|
|
Values: newGlobalValues(),
|
2023-05-06 21:00:42 +00:00
|
|
|
}
|
2023-10-07 21:32:15 +00:00
|
|
|
copyStructFields(g.Values, conf)
|
|
|
|
return g
|
|
|
|
}
|
2023-05-06 21:00:42 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
// PatchGlobal patches the global configuration.
|
|
|
|
func (conf *Conf) PatchGlobal(optional *OptionalGlobal) {
|
|
|
|
copyStructFields(conf, optional.Values)
|
|
|
|
}
|
2023-05-06 21:00:42 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
// PatchPathDefaults patches path default settings.
|
|
|
|
func (conf *Conf) PatchPathDefaults(optional *OptionalPath) {
|
|
|
|
copyStructFields(&conf.PathDefaults, optional.Values)
|
|
|
|
}
|
2023-05-06 21:00:42 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
// AddPath adds a path.
|
|
|
|
func (conf *Conf) AddPath(name string, p *OptionalPath) error {
|
|
|
|
if _, ok := conf.OptionalPaths[name]; ok {
|
|
|
|
return fmt.Errorf("path already exists")
|
|
|
|
}
|
2023-05-06 21:00:42 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
if conf.OptionalPaths == nil {
|
|
|
|
conf.OptionalPaths = make(map[string]*OptionalPath)
|
|
|
|
}
|
2023-07-31 19:20:09 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
conf.OptionalPaths[name] = p
|
|
|
|
return nil
|
|
|
|
}
|
2023-09-16 15:27:07 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
// PatchPath patches a path.
|
|
|
|
func (conf *Conf) PatchPath(name string, optional2 *OptionalPath) error {
|
|
|
|
optional, ok := conf.OptionalPaths[name]
|
|
|
|
if !ok {
|
2024-01-18 22:28:56 +00:00
|
|
|
return ErrPathNotFound
|
2023-10-07 21:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
copyStructFields(optional.Values, optional2.Values)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReplacePath replaces a path.
|
|
|
|
func (conf *Conf) ReplacePath(name string, optional2 *OptionalPath) error {
|
2024-05-19 12:40:50 +00:00
|
|
|
if conf.OptionalPaths == nil {
|
|
|
|
conf.OptionalPaths = make(map[string]*OptionalPath)
|
2023-10-07 21:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf.OptionalPaths[name] = optional2
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemovePath removes a path.
|
|
|
|
func (conf *Conf) RemovePath(name string) error {
|
|
|
|
if _, ok := conf.OptionalPaths[name]; !ok {
|
2024-01-18 22:28:56 +00:00
|
|
|
return ErrPathNotFound
|
2023-10-07 21:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete(conf.OptionalPaths, name)
|
|
|
|
return nil
|
2023-05-06 21:00:42 +00:00
|
|
|
}
|