-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InfoLog and ErrorLog, create helpers
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"runtime/debug" | ||
|
||
"github.com/abneed/bookings/internal/config" | ||
) | ||
|
||
var app *config.AppConfig | ||
|
||
// NewHelpers sets up app config for helpers | ||
func NewHelpers(a *config.AppConfig) { | ||
app = a | ||
} | ||
|
||
func ClientError(w http.ResponseWriter, status int) { | ||
app.InfoLog.Println("Client error with status of", status) | ||
http.Error(w, http.StatusText(status), status) | ||
} | ||
|
||
func ServerError(w http.ResponseWriter, err error) { | ||
trace := fmt.Sprintf("%s\n%s", err.Error(), debug.Stack()) | ||
app.ErrorLog.Println(trace) | ||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) | ||
} |
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