From 1284c926808247070e3a786f52a762c98c1db11d Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Sun, 18 Sep 2022 05:35:53 +0100 Subject: [PATCH] refactor hotkeys example. --- examples/hotkeys/main.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/hotkeys/main.go b/examples/hotkeys/main.go index fa51c8a..ae3b4e3 100644 --- a/examples/hotkeys/main.go +++ b/examples/hotkeys/main.go @@ -10,18 +10,13 @@ import ( func main() { if err := keyboard.Open(); err != nil { - panic(err) + log.Fatal(err) } defer func() { _ = keyboard.Close() }() - vm, err := voicemeeter.NewRemote("potato", 0) - if err != nil { - log.Fatal(err) - } - - err = vm.Login() + vm, err := vmConnect() if err != nil { log.Fatal(err) } @@ -55,3 +50,17 @@ Loop: } } } + +func vmConnect() (*voicemeeter.Remote, error) { + vm, err := voicemeeter.NewRemote("potato", 0) + if err != nil { + return nil, err + } + + err = vm.Login() + if err != nil { + return nil, err + } + + return vm, nil +}