rustdesk.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. WsHost string `mapstructure:"ws-host"`
  23. }
  24. func (rd *Rustdesk) LoadKeyFile() {
  25. // Load key file
  26. if rd.Key != "" {
  27. return
  28. }
  29. if rd.KeyFile != "" {
  30. // Load key from file
  31. b, err := os.ReadFile(rd.KeyFile)
  32. if err != nil {
  33. return
  34. }
  35. rd.Key = string(b)
  36. return
  37. }
  38. }
  39. func (rd *Rustdesk) ParsePort() {
  40. // Parse port
  41. idres := strings.Split(rd.IdServer, ":")
  42. if len(idres) == 1 {
  43. rd.IdServerPort = DefaultIdServerPort
  44. } else if len(idres) == 2 {
  45. rd.IdServerPort, _ = strconv.Atoi(idres[1])
  46. }
  47. relayres := strings.Split(rd.RelayServer, ":")
  48. if len(relayres) == 1 {
  49. rd.RelayServerPort = DefaultRelayServerPort
  50. } else if len(relayres) == 2 {
  51. rd.RelayServerPort, _ = strconv.Atoi(relayres[1])
  52. }
  53. }