Add server logging
This commit is contained in:
parent
976a6b4a8c
commit
cf096b9a16
3 changed files with 16 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
/dist
|
/dist
|
||||||
/tube
|
/tube
|
||||||
|
/.DS_Store
|
||||||
|
|
||||||
videos/*
|
videos/*
|
||||||
!videos/README.md
|
!videos/README.md
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -15,6 +14,7 @@ import (
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/wybiral/tube/media"
|
"github.com/wybiral/tube/media"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -146,7 +146,6 @@ func (a *App) indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// HTTP handler for /upload
|
// HTTP handler for /upload
|
||||||
func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
log.Printf("GET /upload")
|
|
||||||
ctx := &struct{}{}
|
ctx := &struct{}{}
|
||||||
a.render("upload", w, ctx)
|
a.render("upload", w, ctx)
|
||||||
} else if r.Method == "POST" {
|
} else if r.Method == "POST" {
|
||||||
|
@ -156,6 +155,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
file, handler, err := r.FormFile("video_file")
|
file, handler, err := r.FormFile("video_file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("error processing form: %w", err)
|
err := fmt.Errorf("error processing form: %w", err)
|
||||||
|
log.Error(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -168,6 +168,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
f, err := os.OpenFile(fn, os.O_RDWR|os.O_CREATE, 0755)
|
f, err := os.OpenFile(fn, os.O_RDWR|os.O_CREATE, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("error opening file for writing: %w", err)
|
err := fmt.Errorf("error opening file for writing: %w", err)
|
||||||
|
log.Error(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -176,6 +177,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
_, err = io.Copy(f, file)
|
_, err = io.Copy(f, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("error writing file: %w", err)
|
err := fmt.Errorf("error writing file: %w", err)
|
||||||
|
log.Error(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue