- add: function to get the service id if already ran, if not we now generate then store the id for future app runs (useful for docker containers)
This commit is contained in:
@@ -3,6 +3,8 @@ use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
use warp::Filter;
|
||||
|
||||
@@ -28,6 +30,27 @@ struct ConsulCheck {
|
||||
pub fn generate_service_id() -> String {
|
||||
Uuid::new_v4().to_string()
|
||||
}
|
||||
pub fn get_or_generate_service_id() -> String {
|
||||
let package_name = env!("CARGO_PKG_NAME");
|
||||
let file_name = format!("{}_service_id.txt", package_name);
|
||||
let path = Path::new(&file_name);
|
||||
|
||||
if path.exists() {
|
||||
// Read the service ID from the file
|
||||
if let Ok(service_id) = fs::read_to_string(path) {
|
||||
return service_id.trim().to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a new service ID and save it to disk
|
||||
let service_id = generate_service_id();
|
||||
if let Err(err) = fs::write(path, &service_id) {
|
||||
eprintln!("Failed to write service ID to disk: {}", err);
|
||||
}
|
||||
|
||||
service_id
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub async fn register_service(
|
||||
|
||||
Reference in New Issue
Block a user