Skip to content

Commit

Permalink
refactor: change log printer (slog -> fmt)
Browse files Browse the repository at this point in the history
  • Loading branch information
slowhigh committed May 29, 2024
1 parent 3e7a3fb commit ad16c3a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
6 changes: 3 additions & 3 deletions infra/config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

import (
"log/slog"
"fmt"
"path"
"runtime"

Expand Down Expand Up @@ -62,15 +62,15 @@ func NewConfig() (*Config, error) {

err := viper.ReadInConfig()
if err != nil {
slog.Error("Read config file.", "err", err)
fmt.Println("Read config file.", "err", err)
return nil, err
}

viper.AutomaticEnv()

err = viper.Unmarshal(&conf)
if err != nil {
slog.Error("Unmarshal config file.", "err", err)
fmt.Println("Unmarshal config file.", "err", err)
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions infra/router/middleware/middleware.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package middleware

import (
"log/slog"
"fmt"
"net/http"

"github.com/gin-contrib/cors"
Expand All @@ -21,7 +21,7 @@ func ErrorHandler(c *gin.Context) {
c.Next()

for _, err := range c.Errors {
slog.Error(err.Error())
fmt.Println(err.Error())
}

c.JSON(http.StatusInternalServerError, "")
Expand Down
7 changes: 3 additions & 4 deletions infra/router/util/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package util

import (
"fmt"
"log/slog"
"strconv"

"github.com/gin-gonic/gin"
Expand All @@ -12,7 +11,7 @@ func ValidateBody[T any](c *gin.Context) (*T, error) {
var input T

if err := c.ShouldBind(&input); err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, err
}

Expand All @@ -26,7 +25,7 @@ func ValidateQuery[T any](c *gin.Context) (*T, error) {
fmt.Println(values)

if err := c.ShouldBindQuery(&input); err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, err
}

Expand All @@ -38,7 +37,7 @@ func ValidateInt64Param(c *gin.Context, key string) (*int64, error) {
id, err := strconv.ParseInt(param, 10, 64)

if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions internal/usecase/item/item_ucase.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package item

import (
"log/slog"
"fmt"

"github.com/team-nerd-planet/api-server/internal/entity"
)
Expand All @@ -19,7 +19,7 @@ func NewItemUsecase(itemRepo entity.ItemRepo) ItemUsecase {
func (iu ItemUsecase) CountViewItem(company *string, companySizes *[]entity.CompanySizeType, jobTags, skillTags *[]int64) (*int64, bool) {
count, err := iu.itemRepo.CountView(company, companySizes, jobTags, skillTags)
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand All @@ -29,7 +29,7 @@ func (iu ItemUsecase) CountViewItem(company *string, companySizes *[]entity.Comp
func (mu ItemUsecase) FindAllViewItem(company *string, companySizes *[]entity.CompanySizeType, jobTags, skillTags *[]int64, perPage int, page int) (*[]entity.ItemView, bool) {
viewItems, err := mu.itemRepo.FindAllView(company, companySizes, jobTags, skillTags, perPage, page)
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand Down
13 changes: 6 additions & 7 deletions internal/usecase/subscription/subscriber_ucase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"html/template"
"log/slog"
"net/smtp"
"path"
"runtime"
Expand Down Expand Up @@ -34,7 +33,7 @@ func NewSubscriptionUsecase(
func (su SubscriptionUsecase) ApplySubscription(subscription entity.Subscription) (*entity.Subscription, bool) {
id, err := su.subscriptionRepo.ExistEmail(subscription.Email)
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand All @@ -50,7 +49,7 @@ func (su SubscriptionUsecase) ApplySubscription(subscription entity.Subscription

tokenStr, err := generateEmailToken(token, su.conf.Jwt.SecretKey)
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand Down Expand Up @@ -78,7 +77,7 @@ func (su SubscriptionUsecase) Subscribe(token string) (*entity.Subscription, boo

emailToken, err = verifyEmailToken(token, su.conf.Jwt.SecretKey)
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand All @@ -94,7 +93,7 @@ func (su SubscriptionUsecase) Subscribe(token string) (*entity.Subscription, boo
}

if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand All @@ -120,13 +119,13 @@ func sendSubscribeMail(host string, port int, userName, password, email, token s
configDirPath := path.Join(path.Dir(b))
t, err := template.ParseFiles(fmt.Sprintf("%s/template/subscription.html", configDirPath))
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return err
}

var body bytes.Buffer
if err := t.Execute(&body, data); err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/usecase/tag/job_tag_ucase.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tag

import (
"log/slog"
"fmt"

"github.com/team-nerd-planet/api-server/internal/entity"
)
Expand All @@ -19,7 +19,7 @@ func NewJobTagUsecase(jobTagRepo entity.JobTagRepo) JobTagUsecase {
func (stu JobTagUsecase) FindAll() (*[]entity.JobTag, bool) {
jobTags, err := stu.jobTagRepo.FindAll()
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand Down
4 changes: 2 additions & 2 deletions internal/usecase/tag/skill_tag_ucase.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tag

import (
"log/slog"
"fmt"

"github.com/team-nerd-planet/api-server/internal/entity"
)
Expand All @@ -19,7 +19,7 @@ func NewSkillTagUsecase(skillTagRepo entity.SkillTagRepo) SkillTagUsecase {
func (stu SkillTagUsecase) FindAll() (*[]entity.SkillTag, bool) {
skillTags, err := stu.skillTagRepo.FindAll()
if err != nil {
slog.Error(err.Error())
fmt.Println(err.Error())
return nil, false
}

Expand Down

0 comments on commit ad16c3a

Please sign in to comment.