forked from baron/baron-sso
slog 통합
This commit is contained in:
@@ -3,7 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"baron-sso-backend/internal/domain"
|
||||
@@ -26,16 +26,15 @@ func NewEmailService() domain.EmailService {
|
||||
sender := os.Getenv("AWS_SES_SENDER")
|
||||
|
||||
if region == "" || accessKey == "" || secretKey == "" {
|
||||
log.Println("[EmailService] AWS configuration missing, email service will not work")
|
||||
slog.Warn("[EmailService] AWS configuration missing, email service will not work")
|
||||
return nil
|
||||
}
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(context.TODO(),
|
||||
config.WithRegion(region),
|
||||
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")),
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("[EmailService] Failed to load AWS config: %v", err)
|
||||
slog.Error("Failed to load AWS config", "error", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -71,9 +70,9 @@ func (s *SesServiceImpl) SendEmail(to, subject, body string) error {
|
||||
|
||||
_, err := s.client.SendEmail(context.TODO(), input)
|
||||
if err != nil {
|
||||
log.Printf("[EmailService] Failed to send email to %s: %v", to, err)
|
||||
slog.Error("[EmailService] Failed to send email", "to", to, "error", err)
|
||||
} else {
|
||||
log.Printf("[EmailService] Email sent successfully to %s", to)
|
||||
slog.Info("[EmailService] Email sent successfully", "to", to)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
"baron-sso-backend/internal/domain"
|
||||
)
|
||||
|
||||
type SmsServiceImpl struct {
|
||||
accessKey string
|
||||
secretKey string
|
||||
@@ -28,7 +29,7 @@ func NewSmsService() domain.SmsService {
|
||||
// Sanitize sender phone number right after reading from env
|
||||
rawSenderPhone := os.Getenv("NAVER_SENDER_PHONE_NUMBER")
|
||||
sanitizedSenderPhone := strings.ReplaceAll(rawSenderPhone, "-", "")
|
||||
log.Printf("[서비스 초기화] 발신자 번호 처리: 원본='%s', 정제 후='%s'", rawSenderPhone, sanitizedSenderPhone)
|
||||
slog.Info("[서비스 초기화] 발신자 번호 처리", "원본", rawSenderPhone, "정제후", sanitizedSenderPhone)
|
||||
|
||||
return &SmsServiceImpl{
|
||||
accessKey: os.Getenv("NAVER_CLOUD_ACCESS_KEY"),
|
||||
@@ -41,7 +42,7 @@ func NewSmsService() domain.SmsService {
|
||||
func (s *SmsServiceImpl) SendSms(to, content string) error {
|
||||
timestamp := strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
|
||||
apiURL := fmt.Sprintf("https://sens.apigw.ntruss.com/sms/v2/services/%s/messages", s.serviceID)
|
||||
log.Printf("Requesting SENS API URL: %s", apiURL)
|
||||
slog.Info("[SmsService] Requesting SENS API URL", "url", apiURL)
|
||||
|
||||
// Naver SENS API requires phone number without '+'
|
||||
sanitizedTo := strings.Replace(to, "+", "", 1)
|
||||
@@ -92,11 +93,11 @@ func (s *SmsServiceImpl) SendSms(to, content string) error {
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 300 {
|
||||
log.Printf("error response from naver cloud sms api: %s", string(respBody))
|
||||
slog.Error("[SmsService] error response from naver cloud sms api", "body", string(respBody))
|
||||
return fmt.Errorf("error sending sms: status code %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
log.Printf("sms sent successfully: %s", string(respBody))
|
||||
slog.Info("[SmsService] sms sent successfully", "body", string(respBody))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -112,4 +113,4 @@ func (s *SmsServiceImpl) makeSignature(method, url, timestamp string) (string, e
|
||||
}
|
||||
|
||||
return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user