diff --git a/conf/config.yaml b/conf/config.yaml index 4e67e3d..61a9551 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -20,7 +20,8 @@ rustdesk: id-server: "192.168.1.66:21116" relay-server: "192.168.1.66:21117" api-server: "http://127.0.0.1:21114" - key: "123456789" + key: "" + key-file: "./conf/data/id_ed25519.pub" personal: 1 logger: path: "./runtime/log.txt" diff --git a/config/config.go b/config/config.go index 085809e..95a19e7 100644 --- a/config/config.go +++ b/config/config.go @@ -63,6 +63,7 @@ func Init(rowVal interface{}) *viper.Viper { if err := v.Unmarshal(rowVal); err != nil { fmt.Println(err) } + LoadKeyFile(&rowVal.(*Config).Rustdesk) return v } diff --git a/config/rustdesk.go b/config/rustdesk.go index 10f865d..59056d4 100644 --- a/config/rustdesk.go +++ b/config/rustdesk.go @@ -1,9 +1,30 @@ package config +import ( + "os" +) + type Rustdesk struct { IdServer string `mapstructure:"id-server"` RelayServer string `mapstructure:"relay-server"` ApiServer string `mapstructure:"api-server"` Key string `mapstructure:"key"` + KeyFile string `mapstructure:"key-file"` Personal int `mapstructure:"personal"` } + +func LoadKeyFile(rustdesk *Rustdesk) { + // Load key file + if rustdesk.Key != "" { + return + } + if rustdesk.KeyFile != "" { + // Load key from file + b, err := os.ReadFile(rustdesk.KeyFile) + if err != nil { + return + } + rustdesk.Key = string(b) + return + } +}