Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
liquidsoap controller so far
package main
import (
"bufio"
"fmt"
"log"
"net/http"
"os/exec"
)
var cmd *exec.Cmd
var kill = make(chan bool)
func startProcess(w http.ResponseWriter, r *http.Request) {
cmd = exec.Command("liquidsoap", "test.liq")
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Fprint(w, err)
log.Fatal(err)
}
go runCmd()
in := bufio.NewScanner(stdout)
for in.Scan() {
fmt.Fprint(w, in.Text())
}
if err := in.Err(); err != nil {
fmt.Fprint(w, "hahaha no I quit.")
}
}
func runCmd() {
cmd.Start()
<-kill
cmd.Process.Kill()
}
func killProcess(w http.ResponseWriter, r *http.Request) {
kill <- true
}
func main() {
http.HandleFunc("/start", startProcess)
http.HandleFunc("/stop", killProcess)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "test.html") })
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.