()
| 325 | } |
| 326 | |
| 327 | func (s *UdpServer) initRemoteConn() error { |
| 328 | // remote.toml |
| 329 | fileName := filepath.Join(ExeDirPath, "etc", "remote.toml") |
| 330 | |
| 331 | _, e := os.Stat(fileName) |
| 332 | if os.IsNotExist(e) { |
| 333 | //remote.toml file not found,use local config |
| 334 | return nil |
| 335 | } |
| 336 | |
| 337 | content, err := os.ReadFile(fileName) |
| 338 | if err != nil { |
| 339 | log.Error("failed to read remote config: %v", err) |
| 340 | return err |
| 341 | } |
| 342 | |
| 343 | var conf RemoteConfig |
| 344 | if err = toml.Unmarshal(content, &conf); err != nil { |
| 345 | log.Error("failed to unmarshal remote config: %v", err) |
| 346 | return err |
| 347 | } |
| 348 | |
| 349 | if strings.EqualFold(conf.Provider, "etcd") { |
| 350 | if len(conf.Endpoints) == 0 { |
| 351 | log.Error("remote config has no endpoints,open nhp server will startup with local configuration") |
| 352 | return nil |
| 353 | } |
| 354 | |
| 355 | if len(conf.Key) == 0 { |
| 356 | log.Error("remote config has no key,open nhp server will startup with local configuration") |
| 357 | return nil |
| 358 | } |
| 359 | |
| 360 | s.etcdConn = &etcd.EtcdConn{ |
| 361 | Endpoints: conf.Endpoints, |
| 362 | Username: conf.Username, |
| 363 | Password: conf.Password, |
| 364 | Key: conf.Key, |
| 365 | } |
| 366 | |
| 367 | err = s.etcdConn.InitClient() |
| 368 | return err |
| 369 | } else { |
| 370 | return errors.New("unknown remote provider") |
| 371 | } |
| 372 | |
| 373 | } |
| 374 | |
| 375 | func (s *UdpServer) loadRemoteBaseConfig() error { |
| 376 | var serverEtcdConfig ServerEtcdConfig |
no test coverage detected