Last active
October 6, 2017 05:20
-
-
Save ThisIsSet-L/9a81762abc57c7aa4298b172bce6c827 to your computer and use it in GitHub Desktop.
liquidsoap controller so far
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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