Skip to content

Commit

Permalink
Merge pull request #64 from CoLearn-Dev/optional-feature
Browse files Browse the repository at this point in the history
optional feature storage_macro_dbc, add get_jwt
  • Loading branch information
stneng committed May 11, 2023
2 parents 5a0bc44 + bfbe10e commit cce2074
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
env:
COLINK_SERVER_MQ_URI: ${{ matrix.mq_uri }}
COLINK_SERVER_MQ_API: ${{ matrix.mq_api }}
run: cargo test
run: cargo test --features="storage_macro_dbc"
- name: Run tests (standalone)
if: ${{ matrix.mq == 'standalone' }}
run: cargo test
run: cargo test --features="storage_macro_dbc"
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "colink"
version = "0.3.8"
version = "0.3.9"
edition = "2021"
description = "CoLink Rust SDK"
license = "MIT"
Expand Down Expand Up @@ -50,4 +50,9 @@ variable_transfer = ["extensions", "remote_storage", "hyper", "jsonwebtoken", "r
registry = []
policy_module = []
instant_server = ["reqwest"]
storage_macro = ["async-recursion", "rdbc2"]
storage_macro = ["async-recursion"]
storage_macro_dbc = ["rdbc2"]

[[test]]
name = "test_storage_macro_dbc"
required-features = ["storage_macro_dbc"]
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ CoLink SDK helps both application and protocol developers access the functionali
Add this to your Cargo.toml:
```toml
[dependencies]
colink = "0.3.7"
colink = "0.3.9"
```

Enable more features in your Cargo.toml
```
# if you use storage macro dbc
colink = { version = "0.3.9", features = ["storage_macro_dbc"] }
```

## Getting Started
Expand Down
7 changes: 7 additions & 0 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ impl CoLink {
Ok(self.core_addr.clone())
}

pub fn get_jwt(&self) -> Result<String, String> {
if self.jwt.is_empty() {
return Err("jwt not found".to_string());
}
Ok(self.jwt.clone())
}

pub fn update_jwt(&mut self, new_jwt: &str) -> Result<(), String> {
self.jwt = new_jwt.to_string();
Ok(())
Expand Down
11 changes: 9 additions & 2 deletions src/extensions/storage_macro.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::StorageEntry;

mod append;
mod chunk;
#[cfg(feature = "storage_macro_dbc")]
mod dbc;
mod fs;
mod redis;
use crate::StorageEntry;

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

Expand Down Expand Up @@ -66,7 +66,14 @@ impl crate::application::CoLink {
match macro_type.as_str() {
"chunk" => self._read_entry_chunk(&string_before).await,
"redis" => self._read_entry_redis(&string_before, &string_after).await,
#[cfg(feature = "storage_macro_dbc")]
"dbc" => self._read_entry_dbc(&string_before, &string_after).await,
#[cfg(not(feature = "storage_macro_dbc"))]
"dbc" => Err(format!(
"Storage Macro DBC feature not enabled, but found $dbc in key name: {}",
key_name
)
.into()),
"fs" => self._read_entry_fs(&string_before, &string_after).await,
_ => Err(format!(
"invalid storage macro, found {} in key name {}",
Expand Down

0 comments on commit cce2074

Please sign in to comment.