zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
use crate::prelude2::*;

use std::collections::HashMap;

// By default, struct field names are deserialized based on the position of
// a corresponding field in the CSV data's header record.
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[allow(dead_code)]
// #[serde(rename_all = "PascalCase")] // 首字母大写
pub struct Record {
    pub city: String,
    pub region: String,
    pub country: String,
    pub population: Option<u64>,
}

pub async fn read_csv_file(
    query: web::Form<HashMap<String, String>>,
    request: HttpRequest,
) -> impl Responder {
    let file_path = query
        .get("file_path")
        .ok_or_else(|| Error::invalid_request("Missing query string parameter: file_path"))?;

    let (list, _) = crate::core::csv::read_file::<Record>(file_path, ',', true)
        .map_err(|e| anyhow::anyhow!(e))?;

    request.json(200, R::ok(list))
}