rustdesk.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package config
  2. import (
  3. "os"
  4. "strconv"
  5. "strings"
  6. )
  7. const (
  8. DefaultIdServerPort = 21116
  9. DefaultRelayServerPort = 21117
  10. )
  11. type Rustdesk struct {
  12. IdServer string `mapstructure:"id-server"`
  13. IdServerPort int `mapstructure:"-"`
  14. RelayServer string `mapstructure:"relay-server"`
  15. RelayServerPort int `mapstructure:"-"`
  16. ApiServer string `mapstructure:"api-server"`
  17. Key string `mapstructure:"key"`
  18. KeyFile string `mapstructure:"key-file"`
  19. Personal int `mapstructure:"personal"`
  20. //webclient-magic-queryonline
  21. WebclientMagicQueryonline int `mapstructure:"webclient-magic-queryonline"`
  22. }
  23. func (rd *Rustdesk) LoadKeyFile() {
  24. // Load key file
  25. if rd.Key != "" {
  26. return
  27. }
  28. if rd.KeyFile != "" {
  29. // Load key from file
  30. b, err := os.ReadFile(rd.KeyFile)
  31. if err != nil {
  32. return
  33. }
  34. rd.Key = string(b)
  35. return
  36. }
  37. }
  38. func (rd *Rustdesk) ParsePort() {
  39. // Parse port
  40. idres := strings.Split(rd.IdServer, ":")
  41. if len(idres) == 1 {
  42. rd.IdServerPort = DefaultIdServerPort
  43. } else if len(idres) == 2 {
  44. rd.IdServerPort, _ = strconv.Atoi(idres[1])
  45. }
  46. relayres := strings.Split(rd.RelayServer, ":")
  47. if len(relayres) == 1 {
  48. rd.RelayServerPort = DefaultRelayServerPort
  49. } else if len(relayres) == 2 {
  50. rd.RelayServerPort, _ = strconv.Atoi(relayres[1])
  51. }
  52. }