Add support/list endpoint with fallback data

This commit is contained in:
2025-11-25 18:54:23 +02:00
parent b323e6940d
commit faf0421b44

View File

@@ -25,32 +25,62 @@ func NewSupportHandler() *SupportHandler {
return &SupportHandler{}
}
// Default supporters data (used as fallback on Vercel)
var defaultSupporters = []Supporter{
{
ID: 1,
Name: "Sophron Ragozin",
Type: "service",
Description: "Покупка и продления основного домена neomovies.ru",
Contributions: []string{
"Домен neomovies.ru",
},
Year: 2025,
IsActive: true,
},
{
ID: 2,
Name: "Chernuha",
Type: "service",
Description: "Покупка домена neomovies.run",
Contributions: []string{
"Домен neomovies.run",
},
Year: 2025,
IsActive: true,
},
{
ID: 3,
Name: "Iwnuply",
Type: "code",
Description: "Создание докер контейнера для API и Frontend",
Contributions: []string{
"Docker",
},
Year: 2025,
IsActive: true,
},
}
func (h *SupportHandler) GetSupportersList(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
// Get the path to supporters-list.json
// It should be in the root of the project
// Try to read from file first
supportersPath := filepath.Join(".", "supporters-list.json")
// Try to read the file
data, err := os.ReadFile(supportersPath)
// If file not found or error reading, use default data
if err != nil {
// If file not found, return empty list
if os.IsNotExist(err) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode([]Supporter{})
return
}
// Other errors
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to read supporters list"})
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(defaultSupporters)
return
}
var supporters []Supporter
if err := json.Unmarshal(data, &supporters); err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "Failed to parse supporters list"})
// If parsing fails, use default data
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(defaultSupporters)
return
}