diff --git a/Cargo.lock b/Cargo.lock index 0df16d7..b9e390a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1238,7 +1238,7 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "salvo-cli" -version = "0.1.37" +version = "0.1.38" dependencies = [ "ansi_term", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 8ba311c..433cdcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "salvo-cli" -version = "0.1.37" +version = "0.1.38" edition = "2021" authors = ["Fankai Liu liufankai137@outlook.com","mrxiaozhuox mrxzx.info@gmail.com"] keywords = ["salvo", "cli","template"] diff --git a/src/template/config/config.hbs b/src/template/config/config.hbs index c14d952..df150ff 100644 --- a/src/template/config/config.hbs +++ b/src/template/config/config.hbs @@ -1,60 +1,65 @@ -[server] -name = "{{project_name}}" -address = "0.0.0.0:5800" -ssl = false -cors_allow_origin=["https://salvo.rs"] +server: + name: "{{project_name}}" + address: "0.0.0.0:5800" + ssl: false + cors_allow_origin: + - "https://salvo.rs" + {{#if need_db_conn}} -[database] -{{#if is_sea_orm_or_sqlx}} -{{#if is_postgres}} -database_url="postgresql://liufankai:1@localhost/salvo_demo" -{{/if}} -{{#if is_sqlite}} -database_url="sqlite:data/demo.db" -{{/if}} -{{#if is_mysql}} -database_url="mysql://root:981109@localhost/salvo_demo" -{{/if}} -{{/if}} -{{#if is_diesel}} -{{#if is_postgres}} -database_url="postgres://liufankai:1@localhost/diesel_example" -{{/if}} -{{#if is_sqlite}} -database_url="file:data/test.db" -{{/if}} -{{#if is_mysql}} -database_url="mysql://root:123@127.0.0.1:3306/diesel_example" -{{/if}} -{{/if}} -{{#if is_rbatis}} -{{#if is_postgres}} -database_url="postgres://liufankai:1@localhost/rbatis_example" -{{/if}} -{{#if is_sqlite}} -database_url="data/rbatis_sqlite.db" -{{/if}} -{{#if is_mysql}} -database_url="mysql://root:123@127.0.0.1:3306/rbatis_example" -{{/if}} -{{#if is_mssql}} -database_url="mssql://SA:TestPass!123456@localhost:1433/rbatis_example" -{{/if}} -{{/if}} +database: + {{#if is_sea_orm_or_sqlx}} + {{#if is_postgres}} + database_url: "postgresql://liufankai:1@localhost/salvo_demo" + {{/if}} + {{#if is_sqlite}} + database_url: "sqlite:data/demo.db" + {{/if}} + {{#if is_mysql}} + database_url: "mysql://root:981109@localhost/salvo_demo" + {{/if}} + {{/if}} + {{#if is_diesel}} + {{#if is_postgres}} + database_url: "postgres://liufankai:1@localhost/diesel_example" + {{/if}} + {{#if is_sqlite}} + database_url: "file:data/test.db" + {{/if}} + {{#if is_mysql}} + database_url: "mysql://root:123@127.0.0.1:3306/diesel_example" + {{/if}} + {{/if}} + {{#if is_rbatis}} + {{#if is_postgres}} + database_url: "postgres://liufankai:1@localhost/rbatis_example" + {{/if}} + {{#if is_sqlite}} + database_url: "data/rbatis_sqlite.db" + {{/if}} + {{#if is_mysql}} + database_url: "mysql://root:123@127.0.0.1:3306/rbatis_example" + {{/if}} + {{#if is_mssql}} + database_url: "mssql://SA:TestPass!123456@localhost:1433/rbatis_example" + {{/if}} + {{/if}} {{/if}} {{#if is_mongodb}} -database_url="mongodb://localhost:27017" +database_url: "mongodb://localhost:27017" {{/if}} -[jwt] -jwt_secret = "secret" -jwt_exp = 6000 -[cert] -cert = "config/certs/cert.pem" -key = "config/certs/key.pem" -[log] -filter_level = "info" # "debug" "info" "warn" "error" -with_ansi = true -to_stdout = true -directory = "./logs" -file_name = "my-service.log" -rolling = "daily" # "minutely" "hourly" "daily" "never" + +jwt: + jwt_secret: "secret" + jwt_exp: 6000 + +cert: + cert: "config/certs/cert.pem" + key: "config/certs/key.pem" + +log: + filter_level: "info" # Available options: "debug", "info", "warn", "error" + with_ansi: true + to_stdout: true + directory: "./logs" + file_name: "my-service.log" + rolling: "daily" # Available options: "minutely", "hourly", "daily", "never" \ No newline at end of file diff --git a/src/template/src/config_template.hbs b/src/template/src/config_template.hbs index d8ed2be..ed012ec 100644 --- a/src/template/src/config_template.hbs +++ b/src/template/src/config_template.hbs @@ -51,7 +51,7 @@ pub struct Cert { pub key: String, } -const CONFIG_FILE: &str = "config/config.toml"; +const CONFIG_FILE: &str = "config/config.yml"; pub static CFG: Lazy = Lazy::new(self::Configs::init); @@ -69,7 +69,7 @@ impl Configs { Ok(s) => s, Err(e) => panic!("{{config_error_read}}", e), }; - match toml::from_str(&cfg_contents){ + match serde_yaml::from_str(&cfg_contents){ Ok(c) => c, Err(e) => panic!("{{config_error_parse}}", e), } diff --git a/src/utils/create_project.rs b/src/utils/create_project.rs index ed2cd84..b4d4ceb 100644 --- a/src/utils/create_project.rs +++ b/src/utils/create_project.rs @@ -94,7 +94,7 @@ pub fn write_project_file( "version": "1", "features": ["full"] }, - "toml": "0.8.0", + "serde_yaml": "0.8.26", "tracing": "0.1" }, "is_web_site":is_web_site, @@ -527,7 +527,7 @@ fn create_basic_file( ), //config ( - "config/config.toml", + "config/config.yml", include_str!("../template/config/config.hbs"), ), (