Skip to content

Instantly share code, notes, and snippets.

@sullrich
Created June 23, 2023 21:17
Show Gist options
  • Save sullrich/a19c5a72f86d8244409f9012d078667f to your computer and use it in GitHub Desktop.
Save sullrich/a19c5a72f86d8244409f9012d078667f to your computer and use it in GitHub Desktop.
Streaming app
package main
import (
"fmt"
"io"
"os/exec"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("/video_feed", func(c *gin.Context) {
cmd := exec.Command("your_application", "your_arguments") // replace with your application and arguments
pipeReader, pipeWriter := io.Pipe()
cmd.Stdout = pipeWriter
go func() {
defer pipeWriter.Close()
if err := cmd.Run(); err != nil {
fmt.Println("Error running command: ", err)
}
}()
c.Stream(http.StatusOK, "multipart/x-mixed-replace; boundary=frame", pipeReader)
})
r.Run(":8080") // replace with your preferred port
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment