| 1 | package gotify |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | // MessageRequest is the actual payload being sent to the Gotify API. |
| 6 | // This struct represents the JSON request body sent to the Gotify message endpoint, |
| 7 | // containing all notification data including message content, metadata, and custom extras. |
| 8 | type MessageRequest struct { |
| 9 | Message string `json:"message"` // The main notification message text content |
| 10 | Title string `json:"title"` // Notification title displayed in the Gotify interface |
| 11 | Priority int `json:"priority"` // Priority level (-2-10) affecting notification behavior; negative values have special meanings in some clients |
| 12 | Date *string `json:"date,omitempty"` // Optional custom timestamp in ISO 8601 format for the notification |
| 13 | Extras map[string]any `json:"extras"` // Additional custom key-value pairs for extended functionality |
| 14 | } |
| 15 | |
| 16 | // messageResponse represents the successful response from the Gotify API. |
| 17 | // This struct captures the server's confirmation of message acceptance, |
| 18 | // including the assigned ID and metadata about the created notification. |
| 19 | type messageResponse struct { |
| 20 | Message string `json:"message"` // Echo of the sent message content |
| 21 | Title string `json:"title"` // Echo of the notification title |
| 22 | Priority int `json:"priority"` // Echo of the priority level set |
| 23 | Extras map[string]any `json:"extras"` // Echo of any extras sent with the message |
| 24 | ID uint64 `json:"id"` // Unique identifier assigned by Gotify to this message |
| 25 | AppID uint64 `json:"appid"` // Application ID that sent the message |
| 26 | Date string `json:"date"` // ISO 8601 timestamp of when the message was created |
| 27 | } |
| 28 | |
| 29 | // responseError represents an error response from the Gotify API. |
| 30 | // This struct captures structured error information returned by the server |
| 31 | // when a request fails, providing detailed error context. |
| 32 | type responseError struct { |
| 33 | Name string `json:"error"` // Error name/type identifier |
| 34 | Code uint64 `json:"errorCode"` // Numeric error code for programmatic handling |
| 35 | Description string `json:"errorDescription"` // Human-readable error description |
| 36 | } |
| 37 | |
| 38 | // Error implements the error interface for responseError. |
| 39 | // This method formats the error information into a consistent error message |
| 40 | // that can be returned as a standard Go error. |
| 41 | func (er *responseError) Error() string { |
| 42 | return fmt.Sprintf("server responded with %v (%v): %v", er.Name, er.Code, er.Description) |
| 43 | } |