IP cam shot.jpg is now streamed through the web server
This commit is contained in:
parent
e1fcf85910
commit
a8048c01f0
5 changed files with 27 additions and 14 deletions
33
main.go
33
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -13,17 +14,13 @@ type StreamURL struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func index(w http.ResponseWriter, r *http.Request) {
|
func index(w http.ResponseWriter, r *http.Request) {
|
||||||
indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
indexTemplate.Execute(w, nil)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func stream(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if r.FormValue("URL") == "" {
|
if r.FormValue("URL") == "" {
|
||||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
indexTemplate, err := template.ParseFiles(filepath.Join("templates", "index.html"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
indexTemplate.Execute(w, nil)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
streamURL := StreamURL{
|
streamURL := StreamURL{
|
||||||
URL: r.FormValue("URL"),
|
URL: r.FormValue("URL"),
|
||||||
|
@ -37,6 +34,22 @@ func stream(w http.ResponseWriter, r *http.Request) {
|
||||||
streamTemplate.Execute(w, streamURL)
|
streamTemplate.Execute(w, streamURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stream(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.FormValue("URL") == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
//w.Header().Set("Content-Type", "image/jpeg")
|
||||||
|
URL := r.FormValue("URL")
|
||||||
|
resp, err := http.Get(URL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
img, err := ioutil.ReadAll(resp.Body)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
w.Write([]byte(img))
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
staticFileServer := http.FileServer(http.Dir("./static"))
|
staticFileServer := http.FileServer(http.Dir("./static"))
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", staticFileServer))
|
http.Handle("/static/", http.StripPrefix("/static/", staticFileServer))
|
||||||
|
|
0
static/css/style.css
Executable file
0
static/css/style.css
Executable file
|
@ -1 +0,0 @@
|
||||||
alert("test");
|
|
|
@ -1,6 +1,6 @@
|
||||||
<html>
|
<html>
|
||||||
<h1>Stream URL</h1>
|
<h1>Stream URL</h1>
|
||||||
<form action="/stream" method="GET">
|
<form action="" method="GET">
|
||||||
<label>URL:</label>
|
<label>URL:</label>
|
||||||
<input type="text" name="URL" size="100">
|
<input type="text" name="URL" size="100">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<script src="/static/js/stream.js"></script>
|
||||||
|
<link rel="stylesheet" href="/static/css/style.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<img src="{{.URL}}">
|
<img src="/stream?URL={{.URL}}">
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Add table
Reference in a new issue