Skip to content

Commit

Permalink
use log.Prints instead of fmt.Printf
Browse files Browse the repository at this point in the history
  • Loading branch information
stremovsky committed Aug 23, 2024
1 parent 8f9511e commit f31bde4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/email.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"
"net/smtp"
"strconv"
Expand Down Expand Up @@ -43,8 +42,8 @@ func adminEmailAlert(action string, adminEmail string, cfg Config) {
err := smtp.SendMail(cfg.SMTP.Server+":"+cfg.SMTP.Port,
auth, cfg.SMTP.User, dest, []byte(msg))
if err != nil {
fmt.Printf("smtp error: %s", err)
log.Printf("smtp error: %s", err)
return
}
fmt.Println("Mail sent successfully!")
log.Println("Mail sent successfully!")
}
8 changes: 4 additions & 4 deletions src/lbasis_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"encoding/json"
"fmt"
"log"
"strings"
"time"

Expand Down Expand Up @@ -41,7 +41,7 @@ func (dbobj dbcon) createLegalBasis(brief string, newbrief string, module string
bdoc["requiredflag"] = requiredflag
raw, err := dbobj.store.GetRecord(storage.TblName.Legalbasis, "brief", brief)
if err != nil {
fmt.Printf("error to find:%s", err)
log.Printf("error to find: %s\n", err)
return false, err
}
if raw != nil {
Expand All @@ -56,7 +56,7 @@ func (dbobj dbcon) createLegalBasis(brief string, newbrief string, module string
bdoc["creationtime"] = now
_, err = dbobj.store.CreateRecord(storage.TblName.Legalbasis, &bdoc)
if err != nil {
fmt.Printf("error to insert record: %s\n", err)
log.Printf("error to insert record: %s\n", err)
return false, err
}
return true, nil
Expand Down Expand Up @@ -188,7 +188,7 @@ func (dbobj dbcon) checkLegalBasis(brief string) (bool, error) {
func (dbobj dbcon) getLegalBasis(brief string) (bson.M, error) {
row, err := dbobj.store.GetRecord(storage.TblName.Legalbasis, "brief", brief)
if err != nil {
fmt.Printf("error to find:%s", err)
log.Printf("error to find: %s\n", err)
return nil, err
}
return row, err
Expand Down
2 changes: 1 addition & 1 deletion src/sharedrecords_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (e mainEnv) getRecord(w http.ResponseWriter, r *http.Request, ps httprouter
}
recordInfo, err := e.db.getSharedRecord(record)
if err != nil {
fmt.Printf("%d access denied for : %s\n", http.StatusForbidden, record)
log.Printf("%d access denied for : %s\n", http.StatusForbidden, record)
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("Access denied"))
return
Expand Down
7 changes: 3 additions & 4 deletions src/sms.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"
"net/http"
"net/url"
Expand All @@ -26,7 +25,7 @@ func sendCodeByPhoneDo(domain string, client *http.Client, code int32, identity
finalURL = strings.ReplaceAll(finalURL, "_FROM_", url.QueryEscape(cfg.Sms.From))
finalURL = strings.ReplaceAll(finalURL, "_TOKEN_", url.QueryEscape(cfg.Sms.Token))
finalURL = strings.ReplaceAll(finalURL, "_MSG_", url.QueryEscape(msg))
fmt.Printf("finalURL: %s\n", finalURL)
log.Printf("sendCodeByPhoneDo finalURL: %s\n", finalURL)
if len(cfg.Sms.Method) == 0 || strings.ToUpper(cfg.Sms.Method) == "GET" {
req, _ := http.NewRequest("GET", finalURL, nil)
if len(cfg.Sms.BasicAuth) > 0 && strings.Contains(cfg.Sms.BasicAuth, ":") {
Expand All @@ -42,7 +41,7 @@ func sendCodeByPhoneDo(domain string, client *http.Client, code int32, identity
}
}
resp, _ := client.Do(req)
fmt.Println(resp.Status)
log.Println(resp.Status)
return
}
body := cfg.Sms.Body
Expand Down Expand Up @@ -82,5 +81,5 @@ func sendCodeByPhoneDo(domain string, client *http.Client, code int32, identity
}
req.Header.Add("Content-Type", cType)
resp, _ := client.Do(req)
fmt.Println(resp.Status)
log.Println(resp.Status)
}
2 changes: 1 addition & 1 deletion src/storage/sqlite-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (dbobj *SQLiteDB) OpenDB(filepath *string) error {
if len(dbfile) >= 3 && dbfile[len(dbfile)-3:] != ".db" {
dbfile = dbfile + ".db"
}
fmt.Printf("Databunker db file is: %s\n", dbfile)
log.Printf("Databunker db file is: %s\n", dbfile)
// collect list of all tables
/*
if _, err := os.Stat(dbfile); !os.IsNotExist(err) {
Expand Down
7 changes: 4 additions & 3 deletions src/users_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"log"
"net/http"

"github.com/julienschmidt/httprouter"
Expand All @@ -17,7 +18,7 @@ func (e mainEnv) userCreate(w http.ResponseWriter, r *http.Request, ps httproute
if e.conf.Generic.CreateUserWithoutAccessToken == false {
// anonymous user can not create user record, check token
if e.enforceAuth(w, r, event) == "" {
fmt.Println("failed to create user, access denied, try to change Create_user_without_access_token")
log.Println("failed to create user, access denied, try to configure Create_user_without_access_token\n")
return
}
}
Expand Down Expand Up @@ -182,7 +183,7 @@ func (e mainEnv) userList(w http.ResponseWriter, r *http.Request, ps httprouter.
limit = atoi(value[0])
}
resultJSON, counter, _ := e.db.getUsers(offset, limit)
fmt.Printf("Total count of events: %d\n", counter)
log.Printf("Total count of events: %d\n", counter)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
if counter == 0 {
Expand Down Expand Up @@ -400,7 +401,7 @@ func (e mainEnv) userPrelogin(w http.ResponseWriter, r *http.Request, ps httprou
fmt.Fprintf(w, `{"status":"error","result":"record not found","captchaurl":"%s"}`, captcha)
return
}
fmt.Println("user record not found, still returning ok status")
log.Println("user record not found, returning ok status")
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
Expand Down
8 changes: 4 additions & 4 deletions src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func enforceUUID(w http.ResponseWriter, uuidCode string, event *auditEvent) bool
func getJSONPostMap(r *http.Request) (map[string]interface{}, error) {
cType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
fmt.Printf("ignoring empty content-type: %s\n", err)
log.Printf("ignoring empty content-type: %s\n", err)
return nil, nil
}
cType = strings.ToLower(cType)
Expand All @@ -492,7 +492,7 @@ func getJSONPostMap(r *http.Request) (map[string]interface{}, error) {
}
form, err := url.ParseQuery(body)
if err != nil {
fmt.Printf("error in http data parsing: %s\n", err)
log.Printf("error to parse HTTP data request: %s\n", err)
return nil, err
}
if len(form) == 0 {
Expand Down Expand Up @@ -529,7 +529,7 @@ func getJSONPostMap(r *http.Request) (map[string]interface{}, error) {
func getJSONPostData(r *http.Request) ([]byte, error) {
cType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
fmt.Printf("ignoring empty content-type: %s\n", err)
log.Printf("ignoring empty content-type: %s\n", err)
return nil, nil
}
cType = strings.ToLower(cType)
Expand All @@ -553,7 +553,7 @@ func getJSONPostData(r *http.Request) ([]byte, error) {
}
form, err := url.ParseQuery(body)
if err != nil {
fmt.Printf("error in http data parsing: %s\n", err)
log.Printf("error in HTTP data request: %s\n", err)
return nil, err
}
if len(form) == 0 {
Expand Down

0 comments on commit f31bde4

Please sign in to comment.