MCPcopy
hub / github.com/OpenNHP/opennhp / loadBaseConfig

Method loadBaseConfig

endpoints/server/config.go:88–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86}
87
88func (s *UdpServer) loadBaseConfig() error {
89 // config.toml
90 fileName := filepath.Join(ExeDirPath, "etc", "config.toml")
91 content, err := s.loadConfigFile(fileName)
92 if err != nil {
93 log.Error("load base config err: %v", err)
94 return err
95 }
96 // pelletier/go-toml/v2 silently drops unknown sections, so a stale
97 // [webrtc] block in an upgraded config.toml would otherwise produce
98 // no signal that the transport is gone. Warn loudly once at load.
99 if strings.Contains(string(content), "[webrtc]") {
100 log.Warning("[loadBaseConfig] [webrtc] section in config.toml is ignored: " +
101 "the WebRTC transport was removed; delete the section to silence this warning")
102 }
103
104 var config Config
105 if err := toml.Unmarshal(content, &config); err != nil {
106 log.Error("failed to unmarshal base config: %v", err)
107 }
108 if err = s.updateBaseConfig(config); err != nil {
109 // report base config error
110 return err
111 }
112
113 baseConfigWatch = utils.WatchFile(fileName, func() {
114 log.Info("base config: %s has been updated", fileName)
115 if content, err = s.loadConfigFile(fileName); err == nil {
116 if err = toml.Unmarshal(content, &config); err == nil {
117 _ = s.updateBaseConfig(config)
118 }
119
120 }
121 })
122 return nil
123}
124
125func (s *UdpServer) loadHttpConfig() error {
126 // http.toml

Callers 1

StartMethod · 0.95

Calls 3

loadConfigFileMethod · 0.95
updateBaseConfigMethod · 0.95
ErrorMethod · 0.65

Tested by

no test coverage detected