diff --git a/go.mod b/go.mod index 050cdc6..56290b1 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/alecthomas/chroma/v2 v2.13.0 - golang.org/x/oauth2 v0.19.0 + golang.org/x/oauth2 v0.20.0 ) require ( @@ -19,15 +19,15 @@ require ( github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect - golang.org/x/image v0.15.0 // indirect - golang.org/x/net v0.24.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/image v0.16.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/text v0.15.0 // indirect golang.org/x/time v0.5.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) require ( - github.com/aws/aws-sdk-go v1.51.30 + github.com/aws/aws-sdk-go v1.52.5 github.com/clerkinc/clerk-sdk-go v1.49.0 github.com/disintegration/imaging v1.6.2 github.com/fatih/color v1.16.0 @@ -38,11 +38,11 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/redis/go-redis/v9 v9.5.1 github.com/stripe/stripe-go/v76 v76.25.0 - github.com/svix/svix-webhooks v1.21.0 + github.com/svix/svix-webhooks v1.24.0 github.com/yuin/goldmark v1.7.1 github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc github.com/zmb3/spotify v1.3.0 - golang.org/x/crypto v0.22.0 // indirect - golang.org/x/sys v0.19.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/sys v0.20.0 // indirect gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index 3467db3..f5b8c14 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/aws/aws-sdk-go v1.51.27 h1:ZprksHovT4rFfNBHB+Bc/0p4PTntAnTlZP39DMA/Qp github.com/aws/aws-sdk-go v1.51.27/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aws/aws-sdk-go v1.51.30 h1:RVFkjn9P0JMwnuZCVH0TlV5k9zepHzlbc4943eZMhGw= github.com/aws/aws-sdk-go v1.51.30/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.52.5 h1:m2lty5v9sHm1J3lhA43hJql+yKZudF09qzab0Ag9chM= +github.com/aws/aws-sdk-go v1.52.5/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/brianvoe/gofakeit/v6 v6.19.0/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= @@ -88,6 +90,8 @@ github.com/stripe/stripe-go/v76 v76.25.0 h1:kmDoOTvdQSTQssQzWZQQkgbAR2Q8eXdMWbN/ github.com/stripe/stripe-go/v76 v76.25.0/go.mod h1:rw1MxjlAKKcZ+3FOXgTHgwiOa2ya6CPq6ykpJ0Q6Po4= github.com/svix/svix-webhooks v1.21.0 h1:ZxoPU2SJGjmRy1qMaeHY1VdZhTaEkHuh3ruy4CrxW3Y= github.com/svix/svix-webhooks v1.21.0/go.mod h1:qGeiECF5WRQElyfF0i2CqUtWk2GQJTgL+EJZ/WRCxok= +github.com/svix/svix-webhooks v1.24.0 h1:NL8WVC+GpXXJdt0JJ4jfUsCK0CjYxZiU2bM2nRvXaW0= +github.com/svix/svix-webhooks v1.24.0/go.mod h1:MPOB9jpp6jPh652WuKeuKIV5m2APqXXOjLxxOe4mDmM= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= @@ -107,9 +111,13 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw= +golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -124,9 +132,13 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= +golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= +golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -146,6 +158,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -161,6 +175,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/lib/email.go b/lib/email.go index 5d8e54a..f016d87 100644 --- a/lib/email.go +++ b/lib/email.go @@ -8,7 +8,7 @@ import ( ) func SendEmail(to_email string, from_email string, from_name string, html string, subject string) { - log.Println("Starting email sending process") + LogInfo.Println("Starting email sending process") // Set up authentication information. auth := smtp.PlainAuth( @@ -18,7 +18,7 @@ func SendEmail(to_email string, from_email string, from_name string, html string os.Getenv("SMTP_HOST"), ) - log.Println("Authentication set up") + LogSuccess.Println("Authentication set up") // Connect to the server, authenticate, set the sender and recipient, // and send the email all in one step. @@ -34,69 +34,69 @@ func SendEmail(to_email string, from_email string, from_name string, html string ServerName: os.Getenv("SMTP_HOST"), } - log.Println("TLS configuration set up") + LogSuccess.Println("TLS configuration set up") c, err := smtp.Dial(os.Getenv("SMTP_HOST") + ":587") if err != nil { - log.Println("Error dialing SMTP server:", err) + LogError.Println("Error dialing SMTP server:", err) return } - log.Println("Connected to SMTP server") + LogSuccess.Println("Connected to SMTP server") if err = c.StartTLS(tlsconfig); err != nil { - log.Println("Error starting TLS:", err) + LogError.Println("Error starting TLS:", err) return } - log.Println("TLS started") + LogInfo.Println("TLS started") if err = c.Auth(auth); err != nil { - log.Println("Error authenticating with SMTP server:", err) + LogError.Println("Error authenticating with SMTP server:", err) return } - log.Println("Authenticated with SMTP server") + LogSuccess.Println("Authenticated with SMTP server") if err = c.Mail(from_email); err != nil { - log.Println("Error setting sender address:", err) + LogError.Println("Error setting sender address:", err) return } - log.Println("Sender address set") + LogSuccess.Println("Sender address set") if err = c.Rcpt(to_email); err != nil { - log.Println("Error setting recipient address:", err) + LogError.Println("Error setting recipient address:", err) return } - log.Println("Recipient address set") + LogSuccess.Println("Recipient address set") w, err := c.Data() if err != nil { - log.Println("Error getting write closer:", err) + LogError.Println("Error getting write closer:", err) return } - log.Println("Got write closer") + LogSuccess.Println("Got write closer") _, err = w.Write(msg) if err != nil { - log.Println("Error writing message:", err) + LogError.Println("Error writing message:", err) return } - log.Println("Message written") + LogSuccess.Println("Message written") err = w.Close() if err != nil { - log.Println("Error closing write closer:", err) + LogError.Println("Error closing write closer:", err) return } - log.Println("Write closer closed") + LogSuccess.Println("Write closer closed") c.Quit() - log.Println("Email sent successfully") + LogSuccess.Println("Email sent successfully") } diff --git a/lib/sse.go b/lib/sse.go index f848311..34b81e9 100644 --- a/lib/sse.go +++ b/lib/sse.go @@ -3,7 +3,6 @@ package lib import ( "context" "fmt" - "log" "net/http" "sync" @@ -58,7 +57,8 @@ func (s *SSEServerType) ClientCount(channel string) int { } func SendSSE(ctx context.Context, messageBroker pubsub.PubSub, channel string, message string) error { - log.Printf("Sending SSE message to channel %s", channel) + LogInfo.Printf("Sending SSE message to channel %s", channel) + errCh := make(chan error, 1) go func() { @@ -73,11 +73,13 @@ func SendSSE(ctx context.Context, messageBroker pubsub.PubSub, channel string, m err := <-errCh if err != nil { - log.Printf("Error sending SSE message: %v", err) + LogError.Printf("Error sending SSE message: %v", err) + return err } - log.Println("SSE message sent successfully") + LogSuccess.Printf("SSE message sent successfully") + return nil } @@ -89,7 +91,8 @@ func SetSSEHeaders(c echo.Context) { func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client chan string) { if c.Response().Writer == nil { - log.Println("Cannot handle incoming messages: ResponseWriter is nil") + LogError.Printf("Cannot handle incoming messages: ResponseWriter is nil") + return } @@ -110,7 +113,8 @@ func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client default: msg, err := pubsub.ReceiveMessage(ctx) if err != nil { - log.Printf("Failed to receive message: %v", err) + LogError.Printf("Failed to receive message: %v", err) + return } @@ -120,7 +124,7 @@ func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client if c.Response().Writer != nil { _, err = c.Response().Write([]byte(data)) if err != nil { - log.Printf("Failed to write message: %v", err) + LogError.Printf("Failed to write message: %v", err) mutex.Unlock() return } @@ -129,10 +133,10 @@ func HandleIncomingMessages(c echo.Context, pubsub pubsub.PubSubMessage, client if ok { flusher.Flush() } else { - log.Println("Failed to flush: ResponseWriter does not implement http.Flusher") + LogError.Println("Failed to flush: ResponseWriter does not implement http.Flusher") } } else { - log.Println("Failed to write: ResponseWriter is nil") + LogError.Println("Failed to write: ResponseWriter is nil") } mutex.Unlock() } diff --git a/lib/stripe.go b/lib/stripe.go index 72704fb..f85cdbb 100644 --- a/lib/stripe.go +++ b/lib/stripe.go @@ -34,7 +34,7 @@ func CreateCheckoutSession(w http.ResponseWriter, r *http.Request, successUrl st s, err := session.New(params) if err != nil { - log.Printf("session.New: %v", err) + LogError.Printf("session.New: %v", err) } http.Redirect(w, r, s.URL, http.StatusSeeOther) diff --git a/lib/templates.go b/lib/templates.go index 5d2968e..bf41d5d 100644 --- a/lib/templates.go +++ b/lib/templates.go @@ -28,14 +28,14 @@ func RenderTemplate(w http.ResponseWriter, layout string, partials []string, pro // Parse the templates ts, err := template.ParseFS(templatefs.FS, templates...) if err != nil { - log.Print(err.Error()) + LogError.Print(err.Error()) return err } // Execute the layout template err = ts.ExecuteTemplate(w, layout, props) if err != nil { - log.Print(err.Error()) + LogError.Print(err.Error()) return err } diff --git a/main.go b/main.go index 2f6cff1..fc1b538 100755 --- a/main.go +++ b/main.go @@ -125,5 +125,5 @@ func main() { Handler: e, } e.Logger.Fatal(e.StartServer(s)) - log.Println("Server started on port", *port) + lib.LogSuccess.Println("Server started on port", *port) } diff --git a/pages/blog.go b/pages/blog.go index 7411462..fcc0e12 100644 --- a/pages/blog.go +++ b/pages/blog.go @@ -22,7 +22,7 @@ func Blog(c echo.Context) error { files, err := fs.ReadDir(contentfs.FS, ".") if err != nil { - log.Println(err) + lib.LogError.Println(err) http.Error(c.Response().Writer, "There was an issue finding posts!", http.StatusInternalServerError) return nil } @@ -31,7 +31,7 @@ func Blog(c echo.Context) error { if !file.IsDir() && strings.HasSuffix(file.Name(), ".md") { frontMatter, err := lib.ExtractFrontMatter(file, contentfs.FS) if err != nil { - log.Println(err) + lib.LogError.Println(err) http.Error(c.Response().Writer, "There was an issue rendering the posts!", http.StatusInternalServerError) return nil }