1
0
forked from baron/baron-sso

slog 통합

This commit is contained in:
2026-01-21 12:51:00 +09:00
parent 03c8c14aa1
commit c39857c66c
5 changed files with 127 additions and 121 deletions

View File

@@ -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
}
}