Skip to content

Instantly share code, notes, and snippets.

@ThisIsSet-L
Last active October 6, 2017 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThisIsSet-L/9a81762abc57c7aa4298b172bce6c827 to your computer and use it in GitHub Desktop.
Save ThisIsSet-L/9a81762abc57c7aa4298b172bce6c827 to your computer and use it in GitHub Desktop.
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