diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6fbde8..ae1192c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.22' diff --git a/cmd/server/main.go b/cmd/server/main.go index c376d59..25909e4 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -4,9 +4,11 @@ import ( "context" "fmt" "log/slog" + "net" "net/http" "os" "os/signal" + "strconv" "syscall" "time" @@ -241,7 +243,7 @@ func main() { } // Server configuration - addr := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port) + addr := net.JoinHostPort(cfg.Server.Host, strconv.Itoa(cfg.Server.Port)) httpServer := &http.Server{ Addr: addr, Handler: finalHandler, diff --git a/internal/connector/notifier/email/email.go b/internal/connector/notifier/email/email.go index f9955ac..fee00f9 100644 --- a/internal/connector/notifier/email/email.go +++ b/internal/connector/notifier/email/email.go @@ -8,6 +8,7 @@ import ( "log/slog" "net" "net/smtp" + "strconv" "strings" "time" @@ -56,7 +57,7 @@ func (c *Connector) ValidateConfig(ctx context.Context, rawConfig json.RawMessag "smtp_port", cfg.SMTPPort) // Test SMTP connectivity with timeout - addr := fmt.Sprintf("%s:%d", cfg.SMTPHost, cfg.SMTPPort) + addr := net.JoinHostPort(cfg.SMTPHost, strconv.Itoa(cfg.SMTPPort)) conn, err := net.DialTimeout("tcp", addr, 10*time.Second) if err != nil { return fmt.Errorf("failed to reach SMTP server %s: %w", addr, err) @@ -123,7 +124,7 @@ func (c *Connector) SendEvent(ctx context.Context, event notifier.Event) error { // sendEmail sends an email message using the configured SMTP server. // It handles both TLS and plain authentication modes. func (c *Connector) sendEmail(ctx context.Context, to, subject, body string) error { - addr := fmt.Sprintf("%s:%d", c.config.SMTPHost, c.config.SMTPPort) + addr := net.JoinHostPort(c.config.SMTPHost, strconv.Itoa(c.config.SMTPPort)) // Connect to SMTP server var auth smtp.Auth