sentinel-group / sentinel-rust

Sentinel Rust version
Apache License 2.0
128 stars 21 forks source link

Functions' and fields' visibility should be the same with sentinel-golang #147

Open flearc opened 5 months ago

flearc commented 5 months ago

Compared to sentinel-golang, some functions and struct fields have different visibility in sentinel-rust.

For example, form_metric_filename in golang is public but in rust it is private.

    // Generate the metric file name from the service name.
    func FormMetricFileName(serviceName string, withPid bool) string {
    dot := "."
    separator := "-"
    if strings.Contains(serviceName, dot) {
        serviceName = strings.ReplaceAll(serviceName, dot, separator)
    }
    filename := serviceName + separator + MetricFileNameSuffix
    if withPid {
        pid := os.Getpid()
        filename = filename + ".pid" + strconv.Itoa(pid)
    }
    return filename
}
// Generate the metric file name from the service name.
fn form_metric_filename(service_name: &str, with_pid: bool) -> String {
    let separator = "-";
    let mut filename = if service_name.contains('.') {
        service_name.replace('.', separator)
    } else {
        service_name.to_string()
    };

    filename.push_str(&format!("{}{}", separator, METRIC_FILENAME_SUFFIX));

    if with_pid {
        let pid = std::process::id();
        filename.push_str(&format!(".pid{}", pid));
    }

    filename
}