mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
feat(cli): add migrate command, platform API, config management
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Config {
|
||||
pub api_base_url: String,
|
||||
pub sn: Option<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load(path: &Path) -> Self {
|
||||
if path.exists() {
|
||||
fs::read_to_string(path)
|
||||
.ok()
|
||||
.and_then(|s| serde_json::from_str(&s).ok())
|
||||
.unwrap_or_default()
|
||||
} else {
|
||||
Config::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save(&self, path: &Path) {
|
||||
if let Ok(json) = serde_json::to_string_pretty(self) {
|
||||
fs::write(path, json).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
api_base_url: "http://localhost:8080".to_string(),
|
||||
sn: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user