Use the logger
Replace fmt.Print[f|ln]() with the logger equivalent.
This commit is contained in:
parent
4e35418a79
commit
6b48322626
@ -454,7 +454,7 @@ var commands = &CommandControl{
|
|||||||
return "Unable to generate new pin: " + err.Error()
|
return "Unable to generate new pin: " + err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("New room access pin: ", pin)
|
common.LogInfoln("New room access pin: ", pin)
|
||||||
return "New access pin: " + pin
|
return "New access pin: " + pin
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -470,7 +470,7 @@ var commands = &CommandControl{
|
|||||||
switch AccessMode(strings.ToLower(args[0])) {
|
switch AccessMode(strings.ToLower(args[0])) {
|
||||||
case AccessOpen:
|
case AccessOpen:
|
||||||
settings.RoomAccess = AccessOpen
|
settings.RoomAccess = AccessOpen
|
||||||
fmt.Println("[access] Room set to open")
|
common.LogInfoln("[access] Room set to open")
|
||||||
return "Room access set to open"
|
return "Room access set to open"
|
||||||
|
|
||||||
case AccessPin:
|
case AccessPin:
|
||||||
@ -482,17 +482,17 @@ var commands = &CommandControl{
|
|||||||
} else {
|
} else {
|
||||||
_, err := settings.generateNewPin()
|
_, err := settings.generateNewPin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error generating new access pin: ", err.Error())
|
common.LogErrorln("Error generating new access pin: ", err.Error())
|
||||||
return "Unable to generate a new pin, access unchanged: " + err.Error()
|
return "Unable to generate a new pin, access unchanged: " + err.Error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
settings.RoomAccess = AccessPin
|
settings.RoomAccess = AccessPin
|
||||||
fmt.Println("[access] Room set to pin: " + settings.RoomAccessPin)
|
common.LogInfoln("[access] Room set to pin: " + settings.RoomAccessPin)
|
||||||
return "Room access set to Pin: " + settings.RoomAccessPin
|
return "Room access set to Pin: " + settings.RoomAccessPin
|
||||||
|
|
||||||
case AccessRequest:
|
case AccessRequest:
|
||||||
settings.RoomAccess = AccessRequest
|
settings.RoomAccess = AccessRequest
|
||||||
fmt.Println("[access] Room set to request")
|
common.LogInfoln("[access] Room set to request")
|
||||||
return "Room access set to request. WARNING: this isn't implemented yet."
|
return "Room access set to request. WARNING: this isn't implemented yet."
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
21
handlers.go
21
handlers.go
@ -160,7 +160,7 @@ func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool {
|
|||||||
session, err := sstore.Get(r, "moviesession")
|
session, err := sstore.Get(r, "moviesession")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Don't return as server error here, just make a new session.
|
// Don't return as server error here, just make a new session.
|
||||||
fmt.Printf("Unable to get session for client %s: %v\n", r.RemoteAddr, err)
|
common.LogErrorf("Unable to get session for client %s: %v\n", r.RemoteAddr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if settings.RoomAccess == AccessPin {
|
if settings.RoomAccess == AccessPin {
|
||||||
@ -171,12 +171,12 @@ func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool {
|
|||||||
// Check for correct pin
|
// Check for correct pin
|
||||||
err = r.ParseForm()
|
err = r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error parsing form")
|
common.LogErrorf("Error parsing form")
|
||||||
http.Error(w, "Unable to get session data", http.StatusInternalServerError)
|
http.Error(w, "Unable to get session data", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
postPin := r.Form.Get("txtInput")
|
postPin := r.Form.Get("txtInput")
|
||||||
fmt.Printf("Received pin: %s\n", postPin)
|
common.LogDebugf("Received pin: %s\n", postPin)
|
||||||
if postPin == settings.RoomAccessPin {
|
if postPin == settings.RoomAccessPin {
|
||||||
// Pin is correct. Save it to session and return true.
|
// Pin is correct. Save it to session and return true.
|
||||||
session.Values["pin"] = settings.RoomAccessPin
|
session.Values["pin"] = settings.RoomAccessPin
|
||||||
@ -220,7 +220,7 @@ func checkRoomAccess(w http.ResponseWriter, r *http.Request) bool {
|
|||||||
func handlePinTemplate(w http.ResponseWriter, r *http.Request, errorMessage string) {
|
func handlePinTemplate(w http.ResponseWriter, r *http.Request, errorMessage string) {
|
||||||
t, err := template.ParseFiles("./static/base.html", "./static/thedoor.html")
|
t, err := template.ParseFiles("./static/base.html", "./static/thedoor.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error parsing template file: %v", err)
|
common.LogErrorf("Error parsing template file: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ func handlePinTemplate(w http.ResponseWriter, r *http.Request, errorMessage stri
|
|||||||
|
|
||||||
err = t.Execute(w, data)
|
err = t.Execute(w, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error executing file, %v", err)
|
common.LogErrorf("Error executing file, %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ func handleHelpTemplate(w http.ResponseWriter, r *http.Request) {
|
|||||||
func handlePin(w http.ResponseWriter, r *http.Request) {
|
func handlePin(w http.ResponseWriter, r *http.Request) {
|
||||||
session, err := sstore.Get(r, "moviesession")
|
session, err := sstore.Get(r, "moviesession")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Unable to get session: %v\n", err)
|
common.LogDebugf("Unable to get session: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
val := session.Values["pin"]
|
val := session.Values["pin"]
|
||||||
@ -289,21 +289,20 @@ func handlePin(w http.ResponseWriter, r *http.Request) {
|
|||||||
fmt.Fprintf(w, "unable to save session: %v", err)
|
fmt.Fprintf(w, "unable to save session: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Fprint(w, "Pin was not set")
|
fmt.Fprint(w, "Pin was not set")
|
||||||
fmt.Println("pin was not set")
|
common.LogDebugln("pin was not set")
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(w, "pin set: %v", val)
|
fmt.Fprintf(w, "pin set: %v", val)
|
||||||
fmt.Printf("pin is set: %v\n", val)
|
common.LogDebugf("pin is set: %v\n", val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleIndexTemplate(w http.ResponseWriter, r *http.Request) {
|
func handleIndexTemplate(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Printf("RoomAcces: %s\n", settings.RoomAccess)
|
|
||||||
if settings.RoomAccess != AccessOpen {
|
if settings.RoomAccess != AccessOpen {
|
||||||
if !checkRoomAccess(w, r) {
|
if !checkRoomAccess(w, r) {
|
||||||
fmt.Println("Denied access")
|
common.LogDebugln("Denied access")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Println("Granted access")
|
common.LogDebugln("Granted access")
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := template.ParseFiles("./static/base.html", "./static/main.html")
|
t, err := template.ParseFiles("./static/base.html", "./static/main.html")
|
||||||
|
4
main.go
4
main.go
@ -74,8 +74,8 @@ func main() {
|
|||||||
common.LogInfoln("Stream key: ", settings.GetStreamKey())
|
common.LogInfoln("Stream key: ", settings.GetStreamKey())
|
||||||
common.LogInfoln("Admin password: ", settings.AdminPassword)
|
common.LogInfoln("Admin password: ", settings.AdminPassword)
|
||||||
common.LogInfoln("Listen and serve ", addr)
|
common.LogInfoln("Listen and serve ", addr)
|
||||||
fmt.Println("RoomAccess: ", settings.RoomAccess)
|
common.LogInfoln("RoomAccess: ", settings.RoomAccess)
|
||||||
fmt.Println("RoomAccessPin: ", settings.RoomAccessPin)
|
common.LogInfoln("RoomAccessPin: ", settings.RoomAccessPin)
|
||||||
|
|
||||||
go startServer()
|
go startServer()
|
||||||
go startRmtpServer()
|
go startRmtpServer()
|
||||||
|
Loading…
Reference in New Issue
Block a user