Created
June 23, 2023 21:17
-
-
Save sullrich/a19c5a72f86d8244409f9012d078667f to your computer and use it in GitHub Desktop.
Streaming app
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 ( | |
"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