test: prepare

This commit is contained in:
2023-12-09 08:40:07 +00:00
parent d5eb872b13
commit dd66cb9f1e
12 changed files with 221 additions and 35 deletions

View File

@@ -0,0 +1,40 @@
package main
import (
"log"
"os/exec"
"time"
"github.com/spf13/viper"
)
const (
EnvPrefix = "WINGMATE"
EnvOneShotPath = "ONESHOT_PATH"
OneShotPath = "/usr/local/bin/wmoneshot"
)
func main() {
var (
cmd *exec.Cmd
err error
t *time.Ticker
)
viper.SetEnvPrefix(EnvPrefix)
viper.BindEnv(EnvOneShotPath)
viper.SetDefault(EnvOneShotPath, OneShotPath)
exePath := viper.GetString(EnvOneShotPath)
t = time.NewTicker(time.Second * 5)
for {
cmd = exec.Command(exePath)
if err = cmd.Run(); err != nil {
log.Printf("failed to run %s: %+v\n", exePath, err)
} else {
log.Printf("%s executed\n", exePath)
}
<-t.C
}
}