Skip to content

Commit cce2074

Browse files
authored
Merge pull request #64 from CoLearn-Dev/optional-feature
optional feature storage_macro_dbc, add get_jwt
2 parents 5a0bc44 + bfbe10e commit cce2074

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

.github/workflows/check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
env:
6969
COLINK_SERVER_MQ_URI: ${{ matrix.mq_uri }}
7070
COLINK_SERVER_MQ_API: ${{ matrix.mq_api }}
71-
run: cargo test
71+
run: cargo test --features="storage_macro_dbc"
7272
- name: Run tests (standalone)
7373
if: ${{ matrix.mq == 'standalone' }}
74-
run: cargo test
74+
run: cargo test --features="storage_macro_dbc"

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "colink"
3-
version = "0.3.8"
3+
version = "0.3.9"
44
edition = "2021"
55
description = "CoLink Rust SDK"
66
license = "MIT"
@@ -50,4 +50,9 @@ variable_transfer = ["extensions", "remote_storage", "hyper", "jsonwebtoken", "r
5050
registry = []
5151
policy_module = []
5252
instant_server = ["reqwest"]
53-
storage_macro = ["async-recursion", "rdbc2"]
53+
storage_macro = ["async-recursion"]
54+
storage_macro_dbc = ["rdbc2"]
55+
56+
[[test]]
57+
name = "test_storage_macro_dbc"
58+
required-features = ["storage_macro_dbc"]

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ CoLink SDK helps both application and protocol developers access the functionali
99
Add this to your Cargo.toml:
1010
```toml
1111
[dependencies]
12-
colink = "0.3.7"
12+
colink = "0.3.9"
13+
```
14+
15+
Enable more features in your Cargo.toml
16+
```
17+
# if you use storage macro dbc
18+
colink = { version = "0.3.9", features = ["storage_macro_dbc"] }
1319
```
1420

1521
## Getting Started

src/application.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ impl CoLink {
119119
Ok(self.core_addr.clone())
120120
}
121121

122+
pub fn get_jwt(&self) -> Result<String, String> {
123+
if self.jwt.is_empty() {
124+
return Err("jwt not found".to_string());
125+
}
126+
Ok(self.jwt.clone())
127+
}
128+
122129
pub fn update_jwt(&mut self, new_jwt: &str) -> Result<(), String> {
123130
self.jwt = new_jwt.to_string();
124131
Ok(())

src/extensions/storage_macro.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::StorageEntry;
2-
31
mod append;
42
mod chunk;
3+
#[cfg(feature = "storage_macro_dbc")]
54
mod dbc;
65
mod fs;
76
mod redis;
7+
use crate::StorageEntry;
88

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

@@ -66,7 +66,14 @@ impl crate::application::CoLink {
6666
match macro_type.as_str() {
6767
"chunk" => self._read_entry_chunk(&string_before).await,
6868
"redis" => self._read_entry_redis(&string_before, &string_after).await,
69+
#[cfg(feature = "storage_macro_dbc")]
6970
"dbc" => self._read_entry_dbc(&string_before, &string_after).await,
71+
#[cfg(not(feature = "storage_macro_dbc"))]
72+
"dbc" => Err(format!(
73+
"Storage Macro DBC feature not enabled, but found $dbc in key name: {}",
74+
key_name
75+
)
76+
.into()),
7077
"fs" => self._read_entry_fs(&string_before, &string_after).await,
7178
_ => Err(format!(
7279
"invalid storage macro, found {} in key name {}",

0 commit comments

Comments
 (0)