package api import ( "dns_service/settings" "dns_service/utils" "encoding/json" "net/http" ) func Settings(w http.ResponseWriter, req *http.Request) { switch req.Method { case "GET": respSettings, err := settings.GetSettings() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } utils.RespondWithJSON(w, respSettings, http.StatusOK) case "POST": var newSettings map[string]any if err := json.NewDecoder(req.Body).Decode(&newSettings); err != nil { http.Error(w, "invalid JSON format", http.StatusBadRequest) return } respSettings, err := settings.SetSettings(newSettings) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } utils.RespondWithJSON(w, respSettings, http.StatusOK) default: http.Error(w, "method not allowed", http.StatusMethodNotAllowed) } }