Skip to content

Commit

Permalink
centralizing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberRoute committed Oct 31, 2023
1 parent df5ca11 commit bacded2
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/CyberRoute/bruter/pkg/models"
"github.com/CyberRoute/bruter/pkg/render"
"github.com/CyberRoute/bruter/pkg/ssl"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

// Repo used by the handlers
Expand Down Expand Up @@ -71,7 +69,7 @@ func (m *Repository) Home(args models.HomeArgs) http.HandlerFunc {
func (m *Repository) SSLInfo(args models.HomeArgs) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
sslinfo, err := ssl.FetchCrtData(m.App.Domain)
checkError(err)
m.checkError(err)
render.RenderTemplate(w, "ssl.page.html", &models.TemplateData{
SSLInfo: sslinfo,
})
Expand All @@ -87,24 +85,23 @@ func (m *Repository) Consumer(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
session_file := m.App.Domain + ".json"
file, err := os.OpenFile(session_file, os.O_CREATE|os.O_RDWR, 0644)
checkError(err)
m.checkError(err)
defer file.Close()

b, err := io.ReadAll(file)
checkError(err)
m.checkError(err)
var allUrls models.AllUrls
if len(b) > 0 {
err = json.Unmarshal(b, &allUrls.Urls)
checkError(err)
m.checkError(err)
}

err = json.NewEncoder(w).Encode(allUrls)
checkError(err)
m.checkError(err)
}

func checkError(err error) {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
func (m *Repository) checkError(err error) {
if err != nil {
log.Error().Err(err).Msg("CONSUMER")
m.App.ZeroLog.Error().Err(err).Msg("")
}
}

0 comments on commit bacded2

Please sign in to comment.