Add comprehensive documentation comments

This commit is contained in:
Oliver Jakoubek 2025-11-18 18:36:48 +01:00
commit 9db82f92c5
6 changed files with 128 additions and 26 deletions

View file

@ -1,17 +1,23 @@
package sendamatic
// SendResponse repräsentiert die Antwort auf einen Send-Request
// SendResponse represents the response from a send email request.
// It contains the overall HTTP status code and per-recipient delivery information
// including individual status codes and message IDs.
type SendResponse struct {
StatusCode int
Recipients map[string][2]interface{} // Email -> [StatusCode, MessageID]
Recipients map[string][2]interface{} // Email address -> [status code, message ID]
}
// IsSuccess prüft, ob die gesamte Sendung erfolgreich war
// IsSuccess returns true if the email send request was successful (HTTP 200).
// Note that this checks the overall request status; individual recipients
// may still have failed. Use GetStatus to check per-recipient delivery status.
func (r *SendResponse) IsSuccess() bool {
return r.StatusCode == 200
}
// GetMessageID gibt die Message-ID für einen Empfänger zurück
// GetMessageID returns the message ID for a specific recipient email address.
// The message ID can be used to track the email in logs or with the email provider.
// Returns the message ID and true if found, or empty string and false if not found.
func (r *SendResponse) GetMessageID(email string) (string, bool) {
if info, ok := r.Recipients[email]; ok && len(info) >= 2 {
if msgID, ok := info[1].(string); ok {
@ -21,10 +27,14 @@ func (r *SendResponse) GetMessageID(email string) (string, bool) {
return "", false
}
// GetStatus gibt den Status-Code für einen Empfänger zurück
// GetStatus returns the delivery status code for a specific recipient email address.
// The status code indicates whether the email was accepted for delivery to that recipient.
// Returns the status code and true if found, or 0 and false if not found.
//
// Note: The API returns status codes as JSON numbers which are decoded as float64,
// so this method performs the necessary type conversion to int.
func (r *SendResponse) GetStatus(email string) (int, bool) {
if info, ok := r.Recipients[email]; ok && len(info) >= 1 {
// Die API gibt float64 zurück, da JSON numbers als float64 dekodiert werden
if status, ok := info[0].(float64); ok {
return int(status), true
}