All checks were successful
Implement a stateless Go service that routes /api/v1/send_push and /api/v1/ack by platform prefix to configured backends, enabling mixed official and custom mobile clients on a single PushNotificationServer URL. Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
703 B
Go
36 lines
703 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type routePayload struct {
|
|
Platform string `json:"platform"`
|
|
DeviceID string `json:"device_id"`
|
|
}
|
|
|
|
func extractPlatform(body []byte) (string, error) {
|
|
var msg routePayload
|
|
if err := json.Unmarshal(body, &msg); err != nil {
|
|
return "", fmt.Errorf("invalid JSON: %w", err)
|
|
}
|
|
|
|
if msg.Platform != "" {
|
|
return stripVersionSuffix(msg.Platform), nil
|
|
}
|
|
|
|
if idx := strings.Index(msg.DeviceID, ":"); idx > 0 {
|
|
return msg.DeviceID[:idx], nil
|
|
}
|
|
|
|
return "", fmt.Errorf("missing platform")
|
|
}
|
|
|
|
func stripVersionSuffix(platform string) string {
|
|
if idx := strings.Index(platform, "-v"); idx > 0 {
|
|
return platform[:idx]
|
|
}
|
|
return platform
|
|
}
|