-
Notifications
You must be signed in to change notification settings - Fork 4
/
helpers.go
51 lines (46 loc) · 1 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
// Here we create the small function that help us to lighten the rest of the code. Aka: helpers!
import (
"log"
"net/http"
)
// handleErrorHttp handles the logging of error messages and returns and error
// 500 to the client
//
// Parameters:
// - e (*error): the error to print out.
// - w (*http.ResponseWriter): the http response object to write to
//
// Returns: nothing.
//
func handleErrorHttp(e *error, w *http.ResponseWriter) {
if *e != nil {
logError(e)
http.Error(*w, http.StatusText(500), 500)
}
}
// logError handles the logging of error messages and that's it.
//
// Parameters:
// - e (*error): the error to print out.
//
// Returns: nothing.
//
func logError(e *error) {
if *e != nil {
log.Printf("[ERROR] %s", (*e).Error())
}
}
// logInfo handles the logging of informational messages and if the verbose mode
// is on.
//
// Parameters:
// - e (*error): the error to print out.
//
// Returns: nothing.
//
func logInfo(msg string) {
if *verbose {
log.Printf("[INFO] %s", msg)
}
}