Files
ntfy-discord/main.go
Billy D. 1c1a9cc35f
Some checks failed
CI / Lint (push) Successful in 58s
CI / Test (push) Successful in 1m15s
CI / Release (push) Successful in 6s
CI / Docker Build & Push (push) Failing after 23s
CI / Notify (push) Successful in 1s
fix: add golangci-lint config and fix all lint errors
- Add .golangci.yml with v2 config (errcheck, govet, staticcheck, misspell, etc.)
- Fix 32 errcheck issues across config, discord, ntfy, server packages
- Fix misspelling: cancelled → canceled
- Fix staticcheck: use append(slice...) instead of loop
- Fix staticcheck: remove empty error branch
- Use t.Setenv instead of os.Setenv/Unsetenv in tests
- Update CI workflow: add lint job, release tagging, ntfy notifications
2026-02-14 09:15:01 -05:00

60 lines
1.3 KiB
Go

package main
import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"
"git.daviestechlabs.io/daviestechlabs/ntfy-discord/internal/bridge"
"git.daviestechlabs.io/daviestechlabs/ntfy-discord/internal/config"
"git.daviestechlabs.io/daviestechlabs/ntfy-discord/internal/server"
)
func main() {
// Setup structured logging
logLevel := slog.LevelInfo
if os.Getenv("LOG_LEVEL") == "debug" {
logLevel = slog.LevelDebug
}
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel}))
slog.SetDefault(logger)
slog.Info("starting ntfy-discord bridge")
// Create context with cancellation
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Load configuration (may connect to Vault)
cfg, err := config.Load(ctx)
if err != nil {
slog.Error("failed to load config", "error", err)
os.Exit(1)
}
defer func() { _ = cfg.Close() }()
// Start the bridge
b := bridge.New(cfg)
// Start HTTP server for health/metrics
srv := server.New(cfg.HTTPPort, b)
go srv.Start()
// Start watching secrets for hot reload (Vault and/or file-based)
cfg.WatchSecrets(ctx)
// Start the bridge
go b.Run(ctx)
// Wait for shutdown signal
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
slog.Info("shutting down")
cancel()
srv.Shutdown(ctx)
}