Skip to content

Instantly share code, notes, and snippets.

@andyleap andyleap/main.go forked from ThisIsSet-L/main.go
Last active Oct 6, 2017

Embed
What would you like to do?
liquidsoap controller so far
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os/exec"
)
var cmd *exec.Cmd
func startProcess(w http.ResponseWriter, r *http.Request) {
if cmd != nil {
fmt.Fprint(w, "Already running!")
log.Println("You called it twice!")
return
}
cmd = exec.Command("liquidsoap", "test.liq")
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Fprint(w, err)
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
fmt.Fprint(w, err)
log.Fatal(err)
}
b, _ := ioutil.ReadAll(stdout)
fmt.Fprint(w, string(b))
}
func killProcess(w http.ResponseWriter, r *http.Request) {
if cmd != nil {
cmd.Process.Kill()
cmd = nil
}
}
func main() {
http.HandleFunc("/start", startProcess)
http.HandleFunc("/stop", killProcess)
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.