Skip to content

Commit

Permalink
Fix ntfy panic
Browse files Browse the repository at this point in the history
  • Loading branch information
ahobsonsayers committed Oct 12, 2024
1 parent 8e4eadd commit b904024
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions cmd/twitchets/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ type renderMessageConfig struct {
includeFooter bool
}

func (c *renderMessageConfig) applyOptions(options ...RenderMessageOption) {
func newRenderMessageConfig(options ...RenderMessageOption) renderMessageConfig {
config := new(renderMessageConfig)
for _, option := range options {
option(c)
if option != nil {
option(config)
}
}
return *config
}

type RenderMessageOption func(*renderMessageConfig)
Expand All @@ -78,8 +82,7 @@ func WithFooter() RenderMessageOption {
}

func RenderMessage(ticket twickets.Ticket, options ...RenderMessageOption) (string, error) {
config := &renderMessageConfig{}
config.applyOptions(options...)
config := newRenderMessageConfig(options...)

templateData := MessageTemplateData{
Date: ticket.Event.Date.Format("Monday 2 January 2006"),
Expand Down
2 changes: 1 addition & 1 deletion cmd/twitchets/notification/ntfy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type NtfyClient struct {
var _ Client = NtfyClient{}

func (c NtfyClient) SendTicketNotification(ticket twickets.Ticket) error {
notificationMessage, err := RenderMessage(ticket, nil)
notificationMessage, err := RenderMessage(ticket)
if err != nil {
return err
}
Expand Down

0 comments on commit b904024

Please # to comment.